Controller/WikiTagController.php
author cavaliet
Tue, 15 Nov 2011 12:27:02 +0100
changeset 33 6c87166b819c
parent 32 38dcd2db04e4
child 35 92ddb5488eb4
permissions -rwxr-xr-x
First step to add context search to a page. Works fine but needs to be improved with several list of selectors.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
     1
<?php
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
     2
/*
21
780ef37e63b9 add route parameter
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
     3
* This file is part of the WikiTagBundle package.
2
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
     4
*
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
     5
* (c) IRI <http://www.iri.centrepompidou.fr/>
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
     6
*
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
     7
* For the full copyright and license information, please view the LICENSE
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
     8
* file that was distributed with this source code.
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
     9
*/
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    10
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    11
namespace IRI\Bundle\WikiTagBundle\Controller;
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    12
10
a1234ceba912 add first letter list. It works but searching ' bugs.
cavaliet
parents: 9
diff changeset
    13
use Doctrine\ORM\Query\ResultSetMapping;
a1234ceba912 add first letter list. It works but searching ' bugs.
cavaliet
parents: 9
diff changeset
    14
use Doctrine\DBAL\DriverManager;
a1234ceba912 add first letter list. It works but searching ' bugs.
cavaliet
parents: 9
diff changeset
    15
2
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    16
use IRI\Bundle\WikiTagBundle\Entity\DocumentTag;
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    17
use IRI\Bundle\WikiTagBundle\Entity\Tag;
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    18
use IRI\Bundle\WikiTagBundle\Utils\WikiTagUtils;
9
cc32af725176 first step for tag list and add Pagerfanta for paginator
cavaliet
parents: 8
diff changeset
    19
use Pagerfanta\Pagerfanta;
cc32af725176 first step for tag list and add Pagerfanta for paginator
cavaliet
parents: 8
diff changeset
    20
use Pagerfanta\Adapter\ArrayAdapter;
cc32af725176 first step for tag list and add Pagerfanta for paginator
cavaliet
parents: 8
diff changeset
    21
use Pagerfanta\Adapter\DoctrineORMAdapter;
2
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    22
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    23
use Symfony\Component\HttpFoundation\Response;
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    24
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    25
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    26
class WikiTagController extends Controller
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    27
{
10
a1234ceba912 add first letter list. It works but searching ' bugs.
cavaliet
parents: 9
diff changeset
    28
    private static $SEARCH_STAR_CHARACTER = "*";
a1234ceba912 add first letter list. It works but searching ' bugs.
cavaliet
parents: 9
diff changeset
    29
    
2
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    30
    /**
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    31
     * Fake index action
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    32
     */
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    33
    public function indexAction()
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    34
    {
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    35
        return new Response('<html><body>Nothing to see here.</body></html>');
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    36
    }
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    37
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    38
    /**
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    39
     * Renders the little html to add the css
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    40
     */
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    41
    public function addCssAction()
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    42
    {
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    43
        return $this->render('WikiTagBundle:WikiTag:css.html.twig');
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    44
    }
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    45
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    46
    /**
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    47
     * Renders the little html to add the javascript
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    48
     * TODO: review why this injection in javascript, t10n?
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    49
     */
22
99c15cfe420b Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents: 21
diff changeset
    50
    public function addJavascriptAction($tags_list=FALSE)
2
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    51
    {
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    52
        $cats = $this->getDoctrine()->getRepository('WikiTagBundle:Category')->findOrderedCategories();
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    53
        // $cats is {"Label":"Créateur"},{"Label":"Datation"},...
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    54
        $nbCats = count($cats);
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    55
        $ar = array('' => '');
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    56
        for($i=0;$i<$nbCats;$i++){
7
7a877de630fd add files to all tags list.
tcavalie
parents: 5
diff changeset
    57
            $temp = array($cats[$i]["label"] => $cats[$i]["label"]);
2
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    58
            $ar = array_merge($ar, $temp);
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    59
        }
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    60
        // ... so we create is json like {"":""},{"Créateur":"Créateur"},{"Datation":"Datation"},...
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    61
        $categories = json_encode($ar);
33
6c87166b819c First step to add context search to a page. Works fine but needs to be improved with several list of selectors.
cavaliet
parents: 32
diff changeset
    62
        return $this->render('WikiTagBundle:WikiTag:javascript.html.twig', array('categories' => $categories, 'tags_list' => $tags_list));
6c87166b819c First step to add context search to a page. Works fine but needs to be improved with several list of selectors.
cavaliet
parents: 32
diff changeset
    63
    }
6c87166b819c First step to add context search to a page. Works fine but needs to be improved with several list of selectors.
cavaliet
parents: 32
diff changeset
    64
6c87166b819c First step to add context search to a page. Works fine but needs to be improved with several list of selectors.
cavaliet
parents: 32
diff changeset
    65
    /**
6c87166b819c First step to add context search to a page. Works fine but needs to be improved with several list of selectors.
cavaliet
parents: 32
diff changeset
    66
     * Renders the little html to add the javascript for context search
6c87166b819c First step to add context search to a page. Works fine but needs to be improved with several list of selectors.
cavaliet
parents: 32
diff changeset
    67
     */
6c87166b819c First step to add context search to a page. Works fine but needs to be improved with several list of selectors.
cavaliet
parents: 32
diff changeset
    68
    public function addJavascriptForContextSearchAction($context_name)
6c87166b819c First step to add context search to a page. Works fine but needs to be improved with several list of selectors.
cavaliet
parents: 32
diff changeset
    69
    {
6c87166b819c First step to add context search to a page. Works fine but needs to be improved with several list of selectors.
cavaliet
parents: 32
diff changeset
    70
        // WARNING : PREREQUISITE : the request to add a tag needs the external document id,
6c87166b819c First step to add context search to a page. Works fine but needs to be improved with several list of selectors.
cavaliet
parents: 32
diff changeset
    71
        // which is gotten by the jQuery call $('#wikitag_document_id').val() in the page.
6c87166b819c First step to add context search to a page. Works fine but needs to be improved with several list of selectors.
cavaliet
parents: 32
diff changeset
    72
        // So the page holding this context search MUST have a input value with this id.
6c87166b819c First step to add context search to a page. Works fine but needs to be improved with several list of selectors.
cavaliet
parents: 32
diff changeset
    73
        // We add the reactive selectors
6c87166b819c First step to add context search to a page. Works fine but needs to be improved with several list of selectors.
cavaliet
parents: 32
diff changeset
    74
        $reactive_selectors = $this->container->getParameter("wiki_tag.reactive_selectors");
6c87166b819c First step to add context search to a page. Works fine but needs to be improved with several list of selectors.
cavaliet
parents: 32
diff changeset
    75
        return $this->render('WikiTagBundle:WikiTag:javascriptForContextSearch.html.twig', array('reactive_selectors' => $reactive_selectors));
2
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    76
    }
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    77
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    78
    /**
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    79
     * Display a list of ordered tag for a document
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    80
     * @param integer $id_doc
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    81
     */
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    82
    public function documentTagsAction($id_doc)
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    83
    {
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    84
        $ordered_tags = $this->getDoctrine()->getRepository('WikiTagBundle:DocumentTag')->findOrderedTagsForDoc($id_doc);
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    85
        return $this->render('WikiTagBundle:WikiTag:documentTags.html.twig', array('ordered_tags' => $ordered_tags, 'doc_id' => $id_doc));
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    86
    }
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    87
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    88
    /**
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    89
     *
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    90
     * TODO : Enter description here ...
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    91
     * @return \Symfony\Bundle\FrameworkBundle\Controller\Response
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    92
     */
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    93
    public function tagUpDownAction()
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    94
    {
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    95
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    96
        $req = $this->getRequest()->request;
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    97
        $id_doc = $req->get('wikitag_document_id');
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    98
        // post vars new_order and old_order indicate the position (from 1) of the tag in the list.
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    99
        // NB : it is different from the DocumentTag.order in the database.
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   100
        $new_order = intval($req->get('new_order')) - 1;
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   101
        $old_order = intval($req->get('old_order')) - 1;
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   102
        // First we get the DocumentTags
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   103
        $em = $this->getDoctrine()->getEntityManager();
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   104
        $ordered_tags = $this->getDoctrine()->getRepository('WikiTagBundle:DocumentTag')->findOrderedTagsForDoc($id_doc);
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   105
        // We change the moved DocumentTag's order
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   106
        $new_dt_order = $ordered_tags[$new_order]->getTagOrder();
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   107
        $moved_dt = $ordered_tags[$old_order];
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   108
        $moved_dt->setTagOrder($new_dt_order);
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   109
        // We move the TaggedSheets's order
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   110
        if($new_order > $old_order){
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   111
            // And we decrease the other ones
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   112
            for ($i=($old_order+1); $i <= ($new_order); $i++){
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   113
                $dt = $ordered_tags[$i];
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   114
                $dt->setTagOrder($dt->getTagOrder() - 1);
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   115
            }
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   116
        }
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   117
        else{
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   118
            // And we increase the other ones
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   119
            for ($i=$new_order; $i <= ($old_order-1); $i++){
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   120
                $dt = $ordered_tags[$i];
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   121
                $dt->setTagOrder($dt->getTagOrder() + 1);
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   122
            }
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   123
        }
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   124
        // Save datas.
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   125
        $em->flush();
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   126
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   127
        return $this->renderDocTags($id_doc);
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   128
    }
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   129
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   130
    /**
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   131
     *
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   132
     * TODO: Enter description here ...
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   133
     * @return \Symfony\Bundle\FrameworkBundle\Controller\Response
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   134
     */
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   135
    public function removeTagFromListAction()
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   136
    {
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   137
        $id_doc = $this->getRequest()->request->get('wikitag_document_id');
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   138
        $id_tag = $this->getRequest()->request->get('tag_id');
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   139
        // We get the DocumentTag meant to be deleted, and remove it.
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   140
        $em = $this->getDoctrine()->getEntityManager();
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   141
        $dt = $this->getDoctrine()->getRepository('WikiTagBundle:DocumentTag')->findOneBy(array('tag' => $id_tag, 'document' => $id_doc));
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   142
        $em->remove($dt);
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   143
        $em->flush();
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   144
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   145
        return $this->renderDocTags($id_doc);
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   146
    }
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   147
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   148
    /**
22
99c15cfe420b Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents: 21
diff changeset
   149
     * Modify the tag in the context of a tag list for one document
29
7496254cfead correct add tag
ymh <ymh.work@gmail.com>
parents: 26
diff changeset
   150
     *
2
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   151
     */
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   152
    public function modifyDocumentTagAction()
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   153
    {
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   154
        $id_doc = $this->getRequest()->request->get('wikitag_document_id');
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   155
        $tag_label = $this->getRequest()->request->get('value');
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   156
        $id_moved_tag = $this->getRequest()->request->get('id');
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   157
        $moved_tag = $this->getDoctrine()->getRepository('WikiTagBundle:Tag')->findOneBy(array('id' => $id_moved_tag));
11
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   158
        if($tag_label!=$moved_tag->getLabel()){
2
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   159
            // We get the DocumentTags
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   160
            $em = $this->getDoctrine()->getEntityManager();
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   161
            $tags = $this->getDoctrine()->getRepository('WikiTagBundle:DocumentTag')->findBy(array('document' => $id_doc));
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   162
            $nb_tags = count($tags);
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   163
            $found = false;
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   164
            $i = 0;
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   165
            while($i<$nb_tags && $found==false){
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   166
                $dt = $tags[$i];
32
38dcd2db04e4 Debug case sentive tag modification.
cavaliet
parents: 30
diff changeset
   167
                if($dt->getTag()->getLabel()==$tag_label){
2
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   168
                    $found = true;
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   169
                }
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   170
                $i++;
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   171
            }
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   172
            // If the label was found, we sent a bad request
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   173
            if($found==true){
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   174
                return new Response(json_encode(array('error' => 'duplicate_tag', 'message' => sprintf("Le tag %s existe déjà pour cette fiche.", $tag_label))),400);
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   175
            }
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   176
            // We create the new tag or get the already existing tag. $tag, $revision_id, $created
32
38dcd2db04e4 Debug case sentive tag modification.
cavaliet
parents: 30
diff changeset
   177
            $ar = WikiTagUtils::getOrCreateTag($tag_label, $this->getDoctrine());
2
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   178
            $tag = $ar[0];
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   179
            $revision_id = $ar[1];
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   180
            $created = $ar[2];
22
99c15cfe420b Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents: 21
diff changeset
   181
            
2
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   182
            // We get the DocumentTag and change its tag
11
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   183
            $dt = $this->getDoctrine()->getRepository('WikiTagBundle:DocumentTag')->findOneBy(array('document' => $id_doc, 'tag' => $id_moved_tag));
2
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   184
            $dt->setTag($tag);
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   185
            $dt->setWikipediaRevisionId($revision_id);
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   186
            //
30
d2fba1e3b94b correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents: 29
diff changeset
   187
            // TODO: HERE QUERY TO GET A INDEX_NOTE/SCORE for the tag. Here is python code :
2
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   188
            //kwargs = {DJANGO_ID + "__exact": unicode(ds_id)}
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   189
            //results = SearchQuerySet().filter(title=tag_label).filter_or(description=tag_label).filter(**kwargs)
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   190
            //if len(results) > 0:
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   191
            //    ts.index_note = results[0].score
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   192
            //
22
99c15cfe420b Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents: 21
diff changeset
   193
            // We set ManualOrder = true for the current document
99c15cfe420b Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents: 21
diff changeset
   194
            $doc = $this->getDoctrine()->getRepository('WikiTagBundle:Document')->findOneBy(array('externalId' => $id_doc));
99c15cfe420b Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents: 21
diff changeset
   195
            $doc->setManualOrder(true);
2
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   196
            // We save the datas
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   197
            $em->flush();
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   198
        }
32
38dcd2db04e4 Debug case sentive tag modification.
cavaliet
parents: 30
diff changeset
   199
        // We render the document's tags
38dcd2db04e4 Debug case sentive tag modification.
cavaliet
parents: 30
diff changeset
   200
        return $this->renderDocTags($id_doc);
2
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   201
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   202
    }
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   203
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   204
    /**
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   205
     *
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   206
     * TODO : Enter description here ...
7
7a877de630fd add files to all tags list.
tcavalie
parents: 5
diff changeset
   207
     * TODO : implement
2
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   208
     */
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   209
    public function reorderTagDocumentAction()
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   210
    {
30
d2fba1e3b94b correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents: 29
diff changeset
   211
        $id_doc = $this->getRequest()->request->get('wikitag_document_id');
d2fba1e3b94b correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents: 29
diff changeset
   212
        $res = $this->getDoctrine()->getRepository('WikiTagBundle:Document');
d2fba1e3b94b correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents: 29
diff changeset
   213
        $doc = $res->findOneByExternalId($id_doc);
d2fba1e3b94b correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents: 29
diff changeset
   214
        $doc->setManualOrder(false);
d2fba1e3b94b correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents: 29
diff changeset
   215
        $this->getDoctrine()->getEntityManager()->persist($doc);
d2fba1e3b94b correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents: 29
diff changeset
   216
        
d2fba1e3b94b correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents: 29
diff changeset
   217
        $search_service = $this->get('wiki_tag.search');
d2fba1e3b94b correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents: 29
diff changeset
   218
        
d2fba1e3b94b correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents: 29
diff changeset
   219
        $search_service->reorderTagsForDocument($doc);
d2fba1e3b94b correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents: 29
diff changeset
   220
        
d2fba1e3b94b correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents: 29
diff changeset
   221
        $this->getDoctrine()->getEntityManager()->flush();
d2fba1e3b94b correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents: 29
diff changeset
   222
2
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   223
        return $this->renderDocTags($id_doc);
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   224
    }
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   225
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   226
    /**
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   227
     *
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   228
     * TODO: Enter description here ...
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   229
     */
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   230
    public function addTagAction()
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   231
    {
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   232
        $id_doc = $this->getRequest()->request->get('wikitag_document_id');
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   233
        $tag_label = $this->getRequest()->request->get('value');
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   234
        // We get the DocumentTags
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   235
        $em = $this->getDoctrine()->getEntityManager();
5
45378793512a Correct tag insert + external id on doc
ymh <ymh.work@gmail.com>
parents: 2
diff changeset
   236
        $tags = $this->getDoctrine()->getRepository('WikiTagBundle:DocumentTag')->findByDocumentExternalId($id_doc);
2
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   237
        $nb_tags = count($tags);
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   238
        $found = false;
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   239
        $i = 0;
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   240
        while($i<$nb_tags && $found==false){
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   241
            $dt = $tags[$i];
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   242
            if(strtolower($dt->getTag()->getLabel())==strtolower($tag_label)){
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   243
                $found = true;
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   244
            }
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   245
            $i++;
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   246
        }
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   247
        // If the label was found, we sent a bad request
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   248
        if($found==true){
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   249
            //TODO : translation
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   250
            return new Response(json_encode(array('error' => 'duplicate_tag', 'message' => sprintf("Le tag %s existe déjà pour cette fiche.", $tag_label))),400);
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   251
        }
8
7d2fb5d7c9ff debug addtag for document
cavaliet
parents: 7
diff changeset
   252
        // returns array($tag, $revision_id, $created)
2
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   253
        $ar = WikiTagUtils::getOrCreateTag($tag_label, $this->getDoctrine());// tag, revision_id, created = get_or_create_tag(tag_label)
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   254
        $tag = $ar[0];
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   255
        $revision_id = $ar[1];
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   256
        $created = $ar[2];
8
7d2fb5d7c9ff debug addtag for document
cavaliet
parents: 7
diff changeset
   257
        
5
45378793512a Correct tag insert + external id on doc
ymh <ymh.work@gmail.com>
parents: 2
diff changeset
   258
        $tags = $this->getDoctrine()->getRepository('WikiTagBundle:DocumentTag')->findByDocumentExternalId($id_doc, array('tag'=>$tag->getId()));
2
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   259
        $nb_tags = count($tags);
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   260
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   261
        if($created==true || $nb_tags==0){
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   262
            $new_order_ar = $this->getDoctrine()->getRepository('WikiTagBundle:DocumentTag')->getMaxOrder($id_doc);
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   263
            // The result is a double array. And reset(reset($newOrderAr)) is not allowed. And a string is returned.
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   264
            $a1 = reset($new_order_ar);
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   265
            $new_order = intval(reset($a1)) + 1;
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   266
            // TODO: use a factory that returns an DocumentTagInterface
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   267
            $new_DT = new DocumentTag();
5
45378793512a Correct tag insert + external id on doc
ymh <ymh.work@gmail.com>
parents: 2
diff changeset
   268
            $new_DT->setDocument($this->getDoctrine()->getRepository('WikiTagBundle:Document')->findOneByExternalId($id_doc));
2
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   269
            $new_DT->setTag($tag);
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   270
            $new_DT->setOriginalOrder($new_order);
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   271
            $new_DT->setTagOrder($new_order);
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   272
            $new_DT->setWikipediaRevisionId($revision_id);
30
d2fba1e3b94b correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents: 29
diff changeset
   273
            //TODO ; calculate score
2
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   274
            $em->persist($new_DT);
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   275
            $em->flush();
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   276
        }
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   277
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   278
        return $this->renderDocTags($id_doc);
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   279
    }
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   280
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   281
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   282
    /**
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   283
     *
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   284
     * TODO: Enter description here ...
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   285
     * @return \Symfony\Bundle\FrameworkBundle\Controller\Response
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   286
     */
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   287
    public function removeWpLinkAction()
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   288
    {
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   289
        $id_doc = $this->getRequest()->request->get('wikitag_document_id');
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   290
        $id_tag = $this->getRequest()->request->get('tag_id');
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   291
        $tag = $this->getDoctrine()->getRepository('WikiTagBundle:Tag')->find($id_tag);
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   292
        //return new Response(var_dump(array($tag)));
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   293
        // We search if the unsemantized version of the tag already exist.
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   294
        $un_tag = $this->getDoctrine()->getRepository('WikiTagBundle:Tag')->findOneBy(array('label'=>$tag->getLabel(), 'urlStatus'=>Tag::$TAG_URL_STATUS_DICT['null_result']));
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   295
        $em = $this->getDoctrine()->getEntityManager();
13
c288952a089f Remove WP link from tag list now works.
cavaliet
parents: 12
diff changeset
   296
        $un_tag_created = FALSE;
2
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   297
        if(!$un_tag){
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   298
            // Create another tag almost identical, without the W info
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   299
            // TODO: use a factory that return a TagInterface
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   300
            $un_tag = new Tag();
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   301
            $un_tag->setLabel($tag->getLabel());
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   302
            $un_tag->setOriginalLabel($tag->getOriginalLabel());
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   303
            $un_tag->setUrlStatus(Tag::$TAG_URL_STATUS_DICT['null_result']);
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   304
            $un_tag->setWikipediaUrl(null);
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   305
            $un_tag->setWikipediaPageId(null);
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   306
            $un_tag->setDbpediaUri(null);
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   307
            $un_tag->setCategory($tag->getCategory());
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   308
            $un_tag->setAlias($tag->getAlias());
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   309
            $un_tag->setPopularity($tag->getPopularity());
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   310
            $em->persist($un_tag);
13
c288952a089f Remove WP link from tag list now works.
cavaliet
parents: 12
diff changeset
   311
            $un_tag_created = TRUE;
2
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   312
        }
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   313
        
13
c288952a089f Remove WP link from tag list now works.
cavaliet
parents: 12
diff changeset
   314
        if($id_doc && $id_doc!=""){
c288952a089f Remove WP link from tag list now works.
cavaliet
parents: 12
diff changeset
   315
            // We associate the unsemantized tag to the DocumentTag and save datas
c288952a089f Remove WP link from tag list now works.
cavaliet
parents: 12
diff changeset
   316
            // TODO: do the request on external id of document
c288952a089f Remove WP link from tag list now works.
cavaliet
parents: 12
diff changeset
   317
            $dt = $this->getDoctrine()->getRepository('WikiTagBundle:DocumentTag')->findOneBy(array('document' => $id_doc, 'tag' => $id_tag));
c288952a089f Remove WP link from tag list now works.
cavaliet
parents: 12
diff changeset
   318
            $dt->setTag($un_tag);
c288952a089f Remove WP link from tag list now works.
cavaliet
parents: 12
diff changeset
   319
            $em->flush();
c288952a089f Remove WP link from tag list now works.
cavaliet
parents: 12
diff changeset
   320
            return $this->renderDocTags($id_doc);
c288952a089f Remove WP link from tag list now works.
cavaliet
parents: 12
diff changeset
   321
        }
c288952a089f Remove WP link from tag list now works.
cavaliet
parents: 12
diff changeset
   322
        else{
c288952a089f Remove WP link from tag list now works.
cavaliet
parents: 12
diff changeset
   323
            // Here we are in the context of tag list.
c288952a089f Remove WP link from tag list now works.
cavaliet
parents: 12
diff changeset
   324
            if($un_tag_created==TRUE){
c288952a089f Remove WP link from tag list now works.
cavaliet
parents: 12
diff changeset
   325
                $em->flush();
c288952a089f Remove WP link from tag list now works.
cavaliet
parents: 12
diff changeset
   326
                $num_page = $this->getRequest()->request->get('num_page');
c288952a089f Remove WP link from tag list now works.
cavaliet
parents: 12
diff changeset
   327
                $nb_by_page = $this->getRequest()->request->get('nb_by_page');
c288952a089f Remove WP link from tag list now works.
cavaliet
parents: 12
diff changeset
   328
                $sort = $this->getRequest()->request->get('sort');
c288952a089f Remove WP link from tag list now works.
cavaliet
parents: 12
diff changeset
   329
                $searched = $this->getRequest()->request->get('searched');
c288952a089f Remove WP link from tag list now works.
cavaliet
parents: 12
diff changeset
   330
                return $this->renderAllTags($num_page, $nb_by_page, $sort, $searched);
c288952a089f Remove WP link from tag list now works.
cavaliet
parents: 12
diff changeset
   331
            }
c288952a089f Remove WP link from tag list now works.
cavaliet
parents: 12
diff changeset
   332
            else{
c288952a089f Remove WP link from tag list now works.
cavaliet
parents: 12
diff changeset
   333
                // The unsemantized version of the tag already exist, so we send an error.
c288952a089f Remove WP link from tag list now works.
cavaliet
parents: 12
diff changeset
   334
                return new Response(json_encode(array('error' => 'duplicate_tag', 'message' => sprintf("La version désémantisée du tag %s (%s) existe déjà.", $un_tag->getLabel(), $un_tag->getOriginalLabel()))),400);
c288952a089f Remove WP link from tag list now works.
cavaliet
parents: 12
diff changeset
   335
            }
c288952a089f Remove WP link from tag list now works.
cavaliet
parents: 12
diff changeset
   336
        }
2
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   337
    }
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   338
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   339
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   340
    /**
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   341
     *
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   342
     * TODO: Enter description here ...
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   343
     */
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   344
    public function updateTagCategoryAction()
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   345
    {
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   346
        $id_doc = $this->getRequest()->request->get('wikitag_document_id');
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   347
        $id_tag = $this->getRequest()->request->get('id');
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   348
        $cat_label = $this->getRequest()->request->get('value');
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   349
        // We get the Tag and update its category.
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   350
        $em = $this->getDoctrine()->getEntityManager();
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   351
        $tag = $this->getDoctrine()->getRepository('WikiTagBundle:Tag')->find($id_tag);
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   352
        if($cat_label==''){
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   353
            $cat = null;
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   354
            $tag->nullCategory();
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   355
        }
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   356
        else{
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   357
            $cat = $this->getDoctrine()->getRepository('WikiTagBundle:Category')->findOneBy(array('label' => $cat_label));
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   358
            $tag->setCategory($cat);
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   359
        }
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   360
        $em->flush();
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   361
11
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   362
        if($id_doc && $id_doc!=""){
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   363
            return $this->renderDocTags($id_doc);
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   364
        }
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   365
        else{
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   366
            $num_page = $this->getRequest()->request->get('num_page');
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   367
            $nb_by_page = $this->getRequest()->request->get('nb_by_page');
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   368
            $sort = $this->getRequest()->request->get('sort');
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   369
            $searched = $this->getRequest()->request->get('searched');
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   370
            return $this->renderAllTags($num_page, $nb_by_page, $sort, $searched);
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   371
        }
2
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   372
    }
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   373
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   374
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   375
    /**
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   376
     *
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   377
     * Generic render partial template
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   378
     * @param unknown_type $id_doc
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   379
     */
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   380
    public function renderDocTags($id_doc)
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   381
    {
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   382
        $ordered_tags = $this->getDoctrine()->getRepository('WikiTagBundle:DocumentTag')->findOrderedTagsForDoc($id_doc);
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   383
        return $this->render('WikiTagBundle:WikiTag:tagTable.html.twig', array('ordered_tags' => $ordered_tags, 'doc_id' => $id_doc));
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   384
    }
7
7a877de630fd add files to all tags list.
tcavalie
parents: 5
diff changeset
   385
7a877de630fd add files to all tags list.
tcavalie
parents: 5
diff changeset
   386
7a877de630fd add files to all tags list.
tcavalie
parents: 5
diff changeset
   387
    /**
7a877de630fd add files to all tags list.
tcavalie
parents: 5
diff changeset
   388
     *
7a877de630fd add files to all tags list.
tcavalie
parents: 5
diff changeset
   389
     * TODO : Enter description here ...
7a877de630fd add files to all tags list.
tcavalie
parents: 5
diff changeset
   390
     * TODO : implement
7a877de630fd add files to all tags list.
tcavalie
parents: 5
diff changeset
   391
     * @return \Symfony\Bundle\FrameworkBundle\Controller\Response
7a877de630fd add files to all tags list.
tcavalie
parents: 5
diff changeset
   392
     */
7a877de630fd add files to all tags list.
tcavalie
parents: 5
diff changeset
   393
    public function updateTagAliasAction()
7a877de630fd add files to all tags list.
tcavalie
parents: 5
diff changeset
   394
    {
12
81cc9274c20a Update Tag alias.
cavaliet
parents: 11
diff changeset
   395
        $id_tag = $this->getRequest()->request->get('id');
81cc9274c20a Update Tag alias.
cavaliet
parents: 11
diff changeset
   396
        $alias = $this->getRequest()->request->get('value');
81cc9274c20a Update Tag alias.
cavaliet
parents: 11
diff changeset
   397
        // We get the Tag and update its category.
81cc9274c20a Update Tag alias.
cavaliet
parents: 11
diff changeset
   398
        $em = $this->getDoctrine()->getEntityManager();
81cc9274c20a Update Tag alias.
cavaliet
parents: 11
diff changeset
   399
        $tag = $this->getDoctrine()->getRepository('WikiTagBundle:Tag')->find($id_tag);
81cc9274c20a Update Tag alias.
cavaliet
parents: 11
diff changeset
   400
        $tag->setAlias($alias);
81cc9274c20a Update Tag alias.
cavaliet
parents: 11
diff changeset
   401
        $em->flush();
81cc9274c20a Update Tag alias.
cavaliet
parents: 11
diff changeset
   402
        
7
7a877de630fd add files to all tags list.
tcavalie
parents: 5
diff changeset
   403
        $id_doc = $this->getRequest()->request->get('wikitag_document_id');
12
81cc9274c20a Update Tag alias.
cavaliet
parents: 11
diff changeset
   404
        if($id_doc && $id_doc!=""){
81cc9274c20a Update Tag alias.
cavaliet
parents: 11
diff changeset
   405
            // In case we changed the alias from the document view
81cc9274c20a Update Tag alias.
cavaliet
parents: 11
diff changeset
   406
            return $this->renderDocTags($id_doc);
81cc9274c20a Update Tag alias.
cavaliet
parents: 11
diff changeset
   407
        }
81cc9274c20a Update Tag alias.
cavaliet
parents: 11
diff changeset
   408
        else{
81cc9274c20a Update Tag alias.
cavaliet
parents: 11
diff changeset
   409
            // In case we changed the alias from the tag list.
81cc9274c20a Update Tag alias.
cavaliet
parents: 11
diff changeset
   410
            $num_page = $this->getRequest()->request->get('num_page');
81cc9274c20a Update Tag alias.
cavaliet
parents: 11
diff changeset
   411
            $nb_by_page = $this->getRequest()->request->get('nb_by_page');
81cc9274c20a Update Tag alias.
cavaliet
parents: 11
diff changeset
   412
            $sort = $this->getRequest()->request->get('sort');
81cc9274c20a Update Tag alias.
cavaliet
parents: 11
diff changeset
   413
            $searched = $this->getRequest()->request->get('searched');
81cc9274c20a Update Tag alias.
cavaliet
parents: 11
diff changeset
   414
            return $this->renderAllTags($num_page, $nb_by_page, $sort, $searched);
81cc9274c20a Update Tag alias.
cavaliet
parents: 11
diff changeset
   415
        }
7
7a877de630fd add files to all tags list.
tcavalie
parents: 5
diff changeset
   416
    }
7a877de630fd add files to all tags list.
tcavalie
parents: 5
diff changeset
   417
    
7a877de630fd add files to all tags list.
tcavalie
parents: 5
diff changeset
   418
    /**
7a877de630fd add files to all tags list.
tcavalie
parents: 5
diff changeset
   419
     * List of all tags
7a877de630fd add files to all tags list.
tcavalie
parents: 5
diff changeset
   420
     * TODO: Enter description here ...
7a877de630fd add files to all tags list.
tcavalie
parents: 5
diff changeset
   421
     */
7a877de630fd add files to all tags list.
tcavalie
parents: 5
diff changeset
   422
    public function allTagsAction()
7a877de630fd add files to all tags list.
tcavalie
parents: 5
diff changeset
   423
    {
7a877de630fd add files to all tags list.
tcavalie
parents: 5
diff changeset
   424
        // $this->getRequest()->query->get('foo') does not work "because" we are a second controller. So we have to use $_GET.
11
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   425
        // Searched string
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   426
        $searched = NULL;
9
cc32af725176 first step for tag list and add Pagerfanta for paginator
cavaliet
parents: 8
diff changeset
   427
        if(array_key_exists('searched', $_GET)){
cc32af725176 first step for tag list and add Pagerfanta for paginator
cavaliet
parents: 8
diff changeset
   428
            $searched = $_GET['searched'];
7
7a877de630fd add files to all tags list.
tcavalie
parents: 5
diff changeset
   429
        }
9
cc32af725176 first step for tag list and add Pagerfanta for paginator
cavaliet
parents: 8
diff changeset
   430
        // Number of tags per page
8
7d2fb5d7c9ff debug addtag for document
cavaliet
parents: 7
diff changeset
   431
        $nb_by_page = 50;
9
cc32af725176 first step for tag list and add Pagerfanta for paginator
cavaliet
parents: 8
diff changeset
   432
        if(array_key_exists('nb_by_page', $_GET)){
cc32af725176 first step for tag list and add Pagerfanta for paginator
cavaliet
parents: 8
diff changeset
   433
            $nb_by_page = intval($_GET['nb_by_page']);
cc32af725176 first step for tag list and add Pagerfanta for paginator
cavaliet
parents: 8
diff changeset
   434
        }
cc32af725176 first step for tag list and add Pagerfanta for paginator
cavaliet
parents: 8
diff changeset
   435
        // Current page number
cc32af725176 first step for tag list and add Pagerfanta for paginator
cavaliet
parents: 8
diff changeset
   436
        $num_page = 1;
cc32af725176 first step for tag list and add Pagerfanta for paginator
cavaliet
parents: 8
diff changeset
   437
        if(array_key_exists('num_page', $_GET)){
cc32af725176 first step for tag list and add Pagerfanta for paginator
cavaliet
parents: 8
diff changeset
   438
            $num_page = intval($_GET['num_page']);
cc32af725176 first step for tag list and add Pagerfanta for paginator
cavaliet
parents: 8
diff changeset
   439
        }
11
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   440
        // Sorting criteria
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   441
        $sort = NULL;
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   442
        if(array_key_exists('sort', $_GET)){
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   443
            $sort = $_GET['sort'];
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   444
        }
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   445
        
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   446
        // We get the needed datas in an array($tags, $num_page, $nb_by_page, $searched, $sort, $reverse_sort, $pagerfanta);
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   447
        $ar = $this->getAllTags($num_page, $nb_by_page, $sort, $searched);
16
876df98c9208 Debug search with simple quote.
cavaliet
parents: 15
diff changeset
   448
        //return new Response($ar);
11
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   449
        $tags = $ar[0];
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   450
        $num_page = $ar[1];
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   451
        $nb_by_page = $ar[2];
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   452
        $searched = $ar[3];
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   453
        $sort = $ar[4];
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   454
        $reverse_sort = $ar[5];
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   455
        $pagerfanta = $ar[6];
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   456
        
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   457
        // We get the needed vars : number totals of tags, previous and next page number
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   458
        $last_page = $pagerfanta->getNbPages();
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   459
        $nb_total = $pagerfanta->getNbResults();
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   460
        $prev_page = 1;
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   461
        if($pagerfanta->hasPreviousPage()){
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   462
            $prev_page = $pagerfanta->getPreviousPage();
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   463
        }
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   464
        $next_page = $last_page;
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   465
        if($pagerfanta->hasNextPage()){
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   466
            $next_page = $pagerfanta->getNextPage();
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   467
        }
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   468
        // We calculate start_index and end_index (number of tags in the whole list)
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   469
        $start_index = 1 + (($num_page - 1) * $nb_by_page);
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   470
        $end_index = min($nb_total, $start_index + $nb_by_page - 1);
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   471
        
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   472
        // We build the list of tags's first letters to make quick search.
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   473
        $conn = $this->getDoctrine()->getEntityManager()->getConnection();
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   474
        $sql = "SELECT UPPER(SUBSTRING(normalized_label,1,1)) as fl FROM wikitag_tag GROUP BY fl ORDER BY fl";
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   475
        $letters = $conn->query($sql)->fetchAll();
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   476
        $search_def = array();
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   477
        foreach ($letters as $l){
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   478
            $search_def[$l[0]] = $l[0].WikiTagController::$SEARCH_STAR_CHARACTER;
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   479
        }
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   480
        
21
780ef37e63b9 add route parameter
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   481
        return $this->render('WikiTagBundle:WikiTag:TagList.html.twig',
780ef37e63b9 add route parameter
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   482
            array('tags' => $tags, 'searched' => $searched, 'search_def' => $search_def, 'nb_by_page' => $nb_by_page, 'sort' => $sort,
780ef37e63b9 add route parameter
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   483
            'start_index' => $start_index, 'end_index' => $end_index, 'nb_total' => $nb_total, 'num_page' => $num_page, 'last_page' => $last_page,
780ef37e63b9 add route parameter
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   484
        	'prev_page' => $prev_page, 'next_page' => $next_page, 'reverse_sort' => $reverse_sort, 'route_for_documents_by_tag' => $this->container->getParameter("wiki_tag.route_for_documents_by_tag")));
11
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   485
    }
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   486
22
99c15cfe420b Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents: 21
diff changeset
   487
    /**
99c15cfe420b Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents: 21
diff changeset
   488
     * Modify the tag in the context of all tags list.
99c15cfe420b Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents: 21
diff changeset
   489
     */
99c15cfe420b Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents: 21
diff changeset
   490
    public function modifyTagAction()
99c15cfe420b Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents: 21
diff changeset
   491
    {
99c15cfe420b Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents: 21
diff changeset
   492
        $tag_label = $this->getRequest()->request->get('value');
99c15cfe420b Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents: 21
diff changeset
   493
        $id_moved_tag = $this->getRequest()->request->get('id');
99c15cfe420b Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents: 21
diff changeset
   494
        $moved_tag = $this->getDoctrine()->getRepository('WikiTagBundle:Tag')->findOneBy(array('id' => $id_moved_tag));
99c15cfe420b Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents: 21
diff changeset
   495
        // We update the tag label and its wikipedia info with the new label.
99c15cfe420b Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents: 21
diff changeset
   496
        $this->updateTagWithNewLabel($moved_tag, $tag_label);
99c15cfe420b Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents: 21
diff changeset
   497
        
99c15cfe420b Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents: 21
diff changeset
   498
        // We render the tag list.
99c15cfe420b Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents: 21
diff changeset
   499
        $num_page = $this->getRequest()->request->get('num_page');
99c15cfe420b Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents: 21
diff changeset
   500
        $nb_by_page = $this->getRequest()->request->get('nb_by_page');
99c15cfe420b Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents: 21
diff changeset
   501
        $sort = $this->getRequest()->request->get('sort');
99c15cfe420b Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents: 21
diff changeset
   502
        $searched = $this->getRequest()->request->get('searched');
99c15cfe420b Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents: 21
diff changeset
   503
        return $this->renderAllTags($num_page, $nb_by_page, $sort, $searched);
99c15cfe420b Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents: 21
diff changeset
   504
    }
99c15cfe420b Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents: 21
diff changeset
   505
    
99c15cfe420b Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents: 21
diff changeset
   506
    /**
99c15cfe420b Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents: 21
diff changeset
   507
     *
99c15cfe420b Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents: 21
diff changeset
   508
     * Resemantize the tag with its original label. Kind of undo if we changed the tag's label.
29
7496254cfead correct add tag
ymh <ymh.work@gmail.com>
parents: 26
diff changeset
   509
     *
22
99c15cfe420b Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents: 21
diff changeset
   510
     */
99c15cfe420b Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents: 21
diff changeset
   511
    public function resetWpInfoAction()
99c15cfe420b Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents: 21
diff changeset
   512
    {
99c15cfe420b Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents: 21
diff changeset
   513
        $id_moved_tag = $this->getRequest()->request->get('tag_id');
99c15cfe420b Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents: 21
diff changeset
   514
        $moved_tag = $this->getDoctrine()->getRepository('WikiTagBundle:Tag')->findOneBy(array('id' => $id_moved_tag));
99c15cfe420b Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents: 21
diff changeset
   515
        // We update the tag label and its wikipedia info with the original label.
99c15cfe420b Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents: 21
diff changeset
   516
        $this->updateTagWithNewLabel($moved_tag, $moved_tag->getOriginalLabel());
99c15cfe420b Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents: 21
diff changeset
   517
        
99c15cfe420b Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents: 21
diff changeset
   518
        // We render the tag list.
99c15cfe420b Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents: 21
diff changeset
   519
        $num_page = $this->getRequest()->request->get('num_page');
99c15cfe420b Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents: 21
diff changeset
   520
        $nb_by_page = $this->getRequest()->request->get('nb_by_page');
99c15cfe420b Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents: 21
diff changeset
   521
        $sort = $this->getRequest()->request->get('sort');
99c15cfe420b Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents: 21
diff changeset
   522
        $searched = $this->getRequest()->request->get('searched');
99c15cfe420b Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents: 21
diff changeset
   523
        return $this->renderAllTags($num_page, $nb_by_page, $sort, $searched);
99c15cfe420b Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents: 21
diff changeset
   524
    }
99c15cfe420b Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents: 21
diff changeset
   525
99c15cfe420b Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents: 21
diff changeset
   526
99c15cfe420b Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents: 21
diff changeset
   527
    /**
99c15cfe420b Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents: 21
diff changeset
   528
     * Generic render partial template for tag list
99c15cfe420b Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents: 21
diff changeset
   529
     */
99c15cfe420b Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents: 21
diff changeset
   530
    private function updateTagWithNewLabel($tag, $label)
99c15cfe420b Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents: 21
diff changeset
   531
    {
99c15cfe420b Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents: 21
diff changeset
   532
        if($tag!=null && $label!=null){
99c15cfe420b Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents: 21
diff changeset
   533
            if($label!=$tag->getLabel()){
99c15cfe420b Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents: 21
diff changeset
   534
                // We get the Wikipedia informations for the sent label
99c15cfe420b Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents: 21
diff changeset
   535
                $tag_label_normalized = WikiTagUtils::normalizeTag($label);
99c15cfe420b Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents: 21
diff changeset
   536
                $wp_response = WikiTagUtils::getWikipediaInfo($tag_label_normalized);
99c15cfe420b Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents: 21
diff changeset
   537
                $new_label = $wp_response['new_label'];
99c15cfe420b Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents: 21
diff changeset
   538
                $status = $wp_response['status'];
99c15cfe420b Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents: 21
diff changeset
   539
                $url = $wp_response['wikipedia_url'];
99c15cfe420b Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents: 21
diff changeset
   540
                $pageid = $wp_response['pageid'];
99c15cfe420b Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents: 21
diff changeset
   541
                $dbpedia_uri = $wp_response["dbpedia_uri"];
99c15cfe420b Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents: 21
diff changeset
   542
                $wikipedia_revision_id = $wp_response['revision_id'];
99c15cfe420b Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents: 21
diff changeset
   543
                // We save the datas : we DO NOT create a new tag, we change the current tag's informations
99c15cfe420b Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents: 21
diff changeset
   544
                if($new_label!=null){
99c15cfe420b Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents: 21
diff changeset
   545
                    $tag->setLabel($new_label);
99c15cfe420b Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents: 21
diff changeset
   546
                }
99c15cfe420b Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents: 21
diff changeset
   547
                if($status!=null){
99c15cfe420b Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents: 21
diff changeset
   548
                    $tag->setUrlStatus($status);
99c15cfe420b Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents: 21
diff changeset
   549
                }
99c15cfe420b Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents: 21
diff changeset
   550
                $tag->setWikipediaUrl($url);
99c15cfe420b Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents: 21
diff changeset
   551
                $tag->setWikipediaPageId($pageid);
99c15cfe420b Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents: 21
diff changeset
   552
                $tag->setDbpediaUri($dbpedia_uri);
99c15cfe420b Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents: 21
diff changeset
   553
                // Save datas.
99c15cfe420b Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents: 21
diff changeset
   554
                $em = $this->getDoctrine()->getEntityManager();
99c15cfe420b Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents: 21
diff changeset
   555
                $em->persist($tag);
99c15cfe420b Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents: 21
diff changeset
   556
                $em->flush();
99c15cfe420b Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents: 21
diff changeset
   557
            }
99c15cfe420b Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents: 21
diff changeset
   558
        }
99c15cfe420b Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents: 21
diff changeset
   559
    }
99c15cfe420b Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents: 21
diff changeset
   560
11
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   561
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   562
    /**
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   563
     * Generic render partial template for tag list
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   564
     */
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   565
    public function renderAllTags($num_page=NULL, $nb_by_page=NULL, $sort=NULL, $searched=NULL)
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   566
    {
14
673b2766024e Update ORM configuration to allow JOIN between Tag and DocumentTag. TagList template has now the number of documents by tag.
cavaliet
parents: 13
diff changeset
   567
        
673b2766024e Update ORM configuration to allow JOIN between Tag and DocumentTag. TagList template has now the number of documents by tag.
cavaliet
parents: 13
diff changeset
   568
        //We get the needed datas in an array($tags, $num_page, $nb_by_page, $searched, $sort, $reverse_sort, $pagerfanta);
11
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   569
        $ar = $this->getAllTags($num_page, $nb_by_page, $sort, $searched);
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   570
        $tags = $ar[0];
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   571
        $num_page = $ar[1];
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   572
        $nb_by_page = $ar[2];
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   573
        $searched = $ar[3];
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   574
        $sort = $ar[4];
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   575
        $reverse_sort = $ar[5];
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   576
        
21
780ef37e63b9 add route parameter
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   577
        return $this->render('WikiTagBundle:WikiTag:TagListTable.html.twig',
780ef37e63b9 add route parameter
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   578
            array('tags' => $tags, 'searched' => $searched, 'nb_by_page' => $nb_by_page, 'sort' => $sort, 'num_page' => $num_page,
22
99c15cfe420b Add ModifyTag from tag list. Add Reset Wikipedia info from tag list. Enable boolean from addJavascript controller/template to switch from list or document context.
cavaliet
parents: 21
diff changeset
   579
        	'reverse_sort' => $reverse_sort, 'route_for_documents_by_tag' => $this->container->getParameter("wiki_tag.route_for_documents_by_tag")));
14
673b2766024e Update ORM configuration to allow JOIN between Tag and DocumentTag. TagList template has now the number of documents by tag.
cavaliet
parents: 13
diff changeset
   580
        
673b2766024e Update ORM configuration to allow JOIN between Tag and DocumentTag. TagList template has now the number of documents by tag.
cavaliet
parents: 13
diff changeset
   581
        return $this->getAllTags();
11
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   582
    }
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   583
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   584
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   585
    /**
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   586
     * Generic to get all tags with the context (pagination number, nb by page, searched string, sort)
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   587
     */
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   588
    private function getAllTags($num_page=NULL, $nb_by_page=NULL, $sort=NULL, $searched=NULL)
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   589
    {
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   590
        // We get/set all the parameters for the search and pagination.
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   591
        // Searched string
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   592
        if($searched==NULL){
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   593
            $searched = "";
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   594
        }
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   595
        // Number of tags per page
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   596
        if($nb_by_page==NULL){
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   597
            $nb_by_page = 50;
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   598
        }
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   599
        // Current page number
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   600
        if($num_page==NULL){
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   601
            $num_page = 1;
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   602
        }
9
cc32af725176 first step for tag list and add Pagerfanta for paginator
cavaliet
parents: 8
diff changeset
   603
        
cc32af725176 first step for tag list and add Pagerfanta for paginator
cavaliet
parents: 8
diff changeset
   604
        // We build the query.
cc32af725176 first step for tag list and add Pagerfanta for paginator
cavaliet
parents: 8
diff changeset
   605
        $qb = $this->getDoctrine()->getEntityManager()->createQueryBuilder();
14
673b2766024e Update ORM configuration to allow JOIN between Tag and DocumentTag. TagList template has now the number of documents by tag.
cavaliet
parents: 13
diff changeset
   606
        $qb->select('t', 'COUNT( dt.id ) AS nb_docs');
673b2766024e Update ORM configuration to allow JOIN between Tag and DocumentTag. TagList template has now the number of documents by tag.
cavaliet
parents: 13
diff changeset
   607
        $qb->from('WikiTagBundle:Tag','t');
673b2766024e Update ORM configuration to allow JOIN between Tag and DocumentTag. TagList template has now the number of documents by tag.
cavaliet
parents: 13
diff changeset
   608
        $qb->leftJoin('t.documents', 'dt', 'WITH', 't = dt.tag');
673b2766024e Update ORM configuration to allow JOIN between Tag and DocumentTag. TagList template has now the number of documents by tag.
cavaliet
parents: 13
diff changeset
   609
        $qb->addGroupBy('t.id');
673b2766024e Update ORM configuration to allow JOIN between Tag and DocumentTag. TagList template has now the number of documents by tag.
cavaliet
parents: 13
diff changeset
   610
        
16
876df98c9208 Debug search with simple quote.
cavaliet
parents: 15
diff changeset
   611
        // We add the search string if necessary
876df98c9208 Debug search with simple quote.
cavaliet
parents: 15
diff changeset
   612
        if($searched!=""){
876df98c9208 Debug search with simple quote.
cavaliet
parents: 15
diff changeset
   613
            // We replace "*" by "%", and doctrine wants ' to be ''.
876df98c9208 Debug search with simple quote.
cavaliet
parents: 15
diff changeset
   614
            $qb->where($qb->expr()->orx($qb->expr()->like('t.normalizedLabel', "'".str_replace("'", "''", str_replace("*", "%", $searched))."'")));
9
cc32af725176 first step for tag list and add Pagerfanta for paginator
cavaliet
parents: 8
diff changeset
   615
        }
16
876df98c9208 Debug search with simple quote.
cavaliet
parents: 15
diff changeset
   616
        //return $qb->getDql();
14
673b2766024e Update ORM configuration to allow JOIN between Tag and DocumentTag. TagList template has now the number of documents by tag.
cavaliet
parents: 13
diff changeset
   617
        
10
a1234ceba912 add first letter list. It works but searching ' bugs.
cavaliet
parents: 9
diff changeset
   618
        // We add the sorting criteria
11
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   619
        if($sort==NULL){
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   620
            $sort = "popd"; // sort by descendent popularity by default.
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   621
            $reverse_sort = "popa";
9
cc32af725176 first step for tag list and add Pagerfanta for paginator
cavaliet
parents: 8
diff changeset
   622
        }
26
9eab3e86db7d Add sort tags list by number of documents.
cavaliet
parents: 22
diff changeset
   623
        //$sort_query = "nb_docs DESC t.popularity DESC t.normalizedLabel ASC t.label ASC";
9
cc32af725176 first step for tag list and add Pagerfanta for paginator
cavaliet
parents: 8
diff changeset
   624
        switch($sort){
cc32af725176 first step for tag list and add Pagerfanta for paginator
cavaliet
parents: 8
diff changeset
   625
            case "popd":
cc32af725176 first step for tag list and add Pagerfanta for paginator
cavaliet
parents: 8
diff changeset
   626
                $qb->addOrderBy('t.popularity','DESC');
26
9eab3e86db7d Add sort tags list by number of documents.
cavaliet
parents: 22
diff changeset
   627
                $qb->addOrderBy('nb_docs','DESC');
9
cc32af725176 first step for tag list and add Pagerfanta for paginator
cavaliet
parents: 8
diff changeset
   628
                $qb->addOrderBy('t.normalizedLabel','ASC');
cc32af725176 first step for tag list and add Pagerfanta for paginator
cavaliet
parents: 8
diff changeset
   629
                $qb->addOrderBy('t.label','ASC');
cc32af725176 first step for tag list and add Pagerfanta for paginator
cavaliet
parents: 8
diff changeset
   630
                $reverse_sort = "popa";
cc32af725176 first step for tag list and add Pagerfanta for paginator
cavaliet
parents: 8
diff changeset
   631
                break;
cc32af725176 first step for tag list and add Pagerfanta for paginator
cavaliet
parents: 8
diff changeset
   632
            case "popa":
cc32af725176 first step for tag list and add Pagerfanta for paginator
cavaliet
parents: 8
diff changeset
   633
                $qb->addOrderBy('t.popularity','ASC');
26
9eab3e86db7d Add sort tags list by number of documents.
cavaliet
parents: 22
diff changeset
   634
                $qb->addOrderBy('nb_docs','DESC');
9
cc32af725176 first step for tag list and add Pagerfanta for paginator
cavaliet
parents: 8
diff changeset
   635
                $qb->addOrderBy('t.normalizedLabel','ASC');
cc32af725176 first step for tag list and add Pagerfanta for paginator
cavaliet
parents: 8
diff changeset
   636
                $qb->addOrderBy('t.label','ASC');
cc32af725176 first step for tag list and add Pagerfanta for paginator
cavaliet
parents: 8
diff changeset
   637
                $reverse_sort = "popd";
cc32af725176 first step for tag list and add Pagerfanta for paginator
cavaliet
parents: 8
diff changeset
   638
                break;
cc32af725176 first step for tag list and add Pagerfanta for paginator
cavaliet
parents: 8
diff changeset
   639
            case "labd":
cc32af725176 first step for tag list and add Pagerfanta for paginator
cavaliet
parents: 8
diff changeset
   640
                $qb->addOrderBy('t.normalizedLabel','DESC');
cc32af725176 first step for tag list and add Pagerfanta for paginator
cavaliet
parents: 8
diff changeset
   641
                $qb->addOrderBy('t.label','DESC');
cc32af725176 first step for tag list and add Pagerfanta for paginator
cavaliet
parents: 8
diff changeset
   642
                $reverse_sort = "laba";
cc32af725176 first step for tag list and add Pagerfanta for paginator
cavaliet
parents: 8
diff changeset
   643
                break;
cc32af725176 first step for tag list and add Pagerfanta for paginator
cavaliet
parents: 8
diff changeset
   644
            case "laba":
cc32af725176 first step for tag list and add Pagerfanta for paginator
cavaliet
parents: 8
diff changeset
   645
                $qb->addOrderBy('t.normalizedLabel','ASC');
cc32af725176 first step for tag list and add Pagerfanta for paginator
cavaliet
parents: 8
diff changeset
   646
                $qb->addOrderBy('t.label','ASC');
cc32af725176 first step for tag list and add Pagerfanta for paginator
cavaliet
parents: 8
diff changeset
   647
                $reverse_sort = "labd";
26
9eab3e86db7d Add sort tags list by number of documents.
cavaliet
parents: 22
diff changeset
   648
            case "nbd":
9eab3e86db7d Add sort tags list by number of documents.
cavaliet
parents: 22
diff changeset
   649
                $qb->addOrderBy('nb_docs','DESC');
9eab3e86db7d Add sort tags list by number of documents.
cavaliet
parents: 22
diff changeset
   650
                $qb->addOrderBy('t.popularity','DESC');
9eab3e86db7d Add sort tags list by number of documents.
cavaliet
parents: 22
diff changeset
   651
                $qb->addOrderBy('t.normalizedLabel','ASC');
9eab3e86db7d Add sort tags list by number of documents.
cavaliet
parents: 22
diff changeset
   652
                $qb->addOrderBy('t.label','ASC');
9eab3e86db7d Add sort tags list by number of documents.
cavaliet
parents: 22
diff changeset
   653
                $reverse_sort = "nba";
9eab3e86db7d Add sort tags list by number of documents.
cavaliet
parents: 22
diff changeset
   654
                break;
9eab3e86db7d Add sort tags list by number of documents.
cavaliet
parents: 22
diff changeset
   655
            case "nba":
9eab3e86db7d Add sort tags list by number of documents.
cavaliet
parents: 22
diff changeset
   656
                $qb->addOrderBy('nb_docs','ASC');
9eab3e86db7d Add sort tags list by number of documents.
cavaliet
parents: 22
diff changeset
   657
                $qb->addOrderBy('t.popularity','DESC');
9eab3e86db7d Add sort tags list by number of documents.
cavaliet
parents: 22
diff changeset
   658
                $qb->addOrderBy('t.normalizedLabel','ASC');
9eab3e86db7d Add sort tags list by number of documents.
cavaliet
parents: 22
diff changeset
   659
                $qb->addOrderBy('t.label','ASC');
9eab3e86db7d Add sort tags list by number of documents.
cavaliet
parents: 22
diff changeset
   660
                $reverse_sort = "nbd";
9
cc32af725176 first step for tag list and add Pagerfanta for paginator
cavaliet
parents: 8
diff changeset
   661
                break;
cc32af725176 first step for tag list and add Pagerfanta for paginator
cavaliet
parents: 8
diff changeset
   662
        }
cc32af725176 first step for tag list and add Pagerfanta for paginator
cavaliet
parents: 8
diff changeset
   663
        
cc32af725176 first step for tag list and add Pagerfanta for paginator
cavaliet
parents: 8
diff changeset
   664
        // We paginate
cc32af725176 first step for tag list and add Pagerfanta for paginator
cavaliet
parents: 8
diff changeset
   665
        $adapter = new DoctrineORMAdapter($qb);
cc32af725176 first step for tag list and add Pagerfanta for paginator
cavaliet
parents: 8
diff changeset
   666
        $pagerfanta = new Pagerfanta($adapter);
cc32af725176 first step for tag list and add Pagerfanta for paginator
cavaliet
parents: 8
diff changeset
   667
        $pagerfanta->setMaxPerPage($nb_by_page); // 10 by default
cc32af725176 first step for tag list and add Pagerfanta for paginator
cavaliet
parents: 8
diff changeset
   668
        $pagerfanta->setCurrentPage($num_page); // 1 by default
cc32af725176 first step for tag list and add Pagerfanta for paginator
cavaliet
parents: 8
diff changeset
   669
        $nb_total = $pagerfanta->getNbResults();
cc32af725176 first step for tag list and add Pagerfanta for paginator
cavaliet
parents: 8
diff changeset
   670
        $tags = $pagerfanta->getCurrentPageResults();
cc32af725176 first step for tag list and add Pagerfanta for paginator
cavaliet
parents: 8
diff changeset
   671
        $pagerfanta->haveToPaginate(); // whether the number of results if higher than the max per page
15
ab71cf8bff55 ChangesetTagBranchUserDateSummary
cavaliet
parents: 14
diff changeset
   672
        
11
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   673
        return array($tags, $num_page, $nb_by_page, $searched, $sort, $reverse_sort, $pagerfanta);
7
7a877de630fd add files to all tags list.
tcavalie
parents: 5
diff changeset
   674
    }
2
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   675
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   676
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   677
}