Controller/WikiTagController.php
author cavaliet
Fri, 24 Jan 2014 17:43:38 +0100
changeset 112 14653baf4f6b
parent 104 af79031ee002
child 129 65c12455ce74
permissions -rwxr-xr-x
first change for wikipedia and dbpedia lang configuration
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
/*
74
901463f9b11c add headers for public repository release
ymh <ymh.work@gmail.com>
parents: 68
diff changeset
     3
 * This file is part of the WikiTagBundle package.
901463f9b11c add headers for public repository release
ymh <ymh.work@gmail.com>
parents: 68
diff changeset
     4
 *
901463f9b11c add headers for public repository release
ymh <ymh.work@gmail.com>
parents: 68
diff changeset
     5
 * (c) IRI <http://www.iri.centrepompidou.fr/>
901463f9b11c add headers for public repository release
ymh <ymh.work@gmail.com>
parents: 68
diff changeset
     6
 *
901463f9b11c add headers for public repository release
ymh <ymh.work@gmail.com>
parents: 68
diff changeset
     7
 * For the full copyright and license information, please view the LICENSE
901463f9b11c add headers for public repository release
ymh <ymh.work@gmail.com>
parents: 68
diff changeset
     8
 * file that was distributed with this source code.
901463f9b11c add headers for public repository release
ymh <ymh.work@gmail.com>
parents: 68
diff changeset
     9
 */
2
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;
63
774ba82dca59 add tests and fixtures
ymh <ymh.work@gmail.com>
parents: 61
diff changeset
    19
use IRI\Bundle\WikiTagBundle\Services\WikiTagServiceException;
9
cc32af725176 first step for tag list and add Pagerfanta for paginator
cavaliet
parents: 8
diff changeset
    20
use Pagerfanta\Pagerfanta;
cc32af725176 first step for tag list and add Pagerfanta for paginator
cavaliet
parents: 8
diff changeset
    21
use Pagerfanta\Adapter\ArrayAdapter;
cc32af725176 first step for tag list and add Pagerfanta for paginator
cavaliet
parents: 8
diff changeset
    22
use Pagerfanta\Adapter\DoctrineORMAdapter;
2
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    23
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    24
use Symfony\Component\HttpFoundation\Response;
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    25
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    26
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    27
class WikiTagController extends Controller
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    28
{
10
a1234ceba912 add first letter list. It works but searching ' bugs.
cavaliet
parents: 9
diff changeset
    29
    private static $SEARCH_STAR_CHARACTER = "*";
a1234ceba912 add first letter list. It works but searching ' bugs.
cavaliet
parents: 9
diff changeset
    30
    
2
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    31
    /**
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    32
     * Fake index action
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    33
     */
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    34
    public function indexAction()
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    35
    {
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    36
        return new Response('<html><body>Nothing to see here.</body></html>');
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
    /**
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    40
     * Renders the little html to add the css
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    41
     */
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    42
    public function addCssAction()
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    43
    {
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    44
        return $this->render('WikiTagBundle:WikiTag:css.html.twig');
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
    /**
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    48
     * Renders the little html to add the javascript
43
54f204bceb28 Correct migration
ymh <ymh.work@gmail.com>
parents: 42
diff changeset
    49
     *
54f204bceb28 Correct migration
ymh <ymh.work@gmail.com>
parents: 42
diff changeset
    50
     * @param unknown_type $tags_list
54f204bceb28 Correct migration
ymh <ymh.work@gmail.com>
parents: 42
diff changeset
    51
     * @return \Symfony\Bundle\FrameworkBundle\Controller\Response
2
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    52
     */
102
d1af10ee0aa5 Correct read only configuration
cavaliet
parents: 98
diff changeset
    53
    public function addJavascriptAction($tags_list=false, $profile_name=null, $read_only=false)
2
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    54
    {
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    55
        $cats = $this->getDoctrine()->getRepository('WikiTagBundle:Category')->findOrderedCategories();
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    56
        // $cats is {"Label":"Créateur"},{"Label":"Datation"},...
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    57
        $nbCats = count($cats);
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    58
        $ar = array('' => '');
43
54f204bceb28 Correct migration
ymh <ymh.work@gmail.com>
parents: 42
diff changeset
    59
        for($i=0;$i<$nbCats;$i++) {
7
7a877de630fd add files to all tags list.
tcavalie
parents: 5
diff changeset
    60
            $temp = array($cats[$i]["label"] => $cats[$i]["label"]);
2
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    61
            $ar = array_merge($ar, $temp);
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    62
        }
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    63
        // ... so we create is json like {"":""},{"Créateur":"Créateur"},{"Datation":"Datation"},...
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    64
        $categories = json_encode($ar);
53
22377c9e2eae First step of column management in document tag list. Little debug on js for move up down.
cavaliet
parents: 52
diff changeset
    65
        // Management of profiles for the list of displayed columns and reorder tag button
22377c9e2eae First step of column management in document tag list. Little debug on js for move up down.
cavaliet
parents: 52
diff changeset
    66
        $profile_array = $this->container->getParameter("wiki_tag.document_list_profile");
22377c9e2eae First step of column management in document tag list. Little debug on js for move up down.
cavaliet
parents: 52
diff changeset
    67
        $columns_array = null;
22377c9e2eae First step of column management in document tag list. Little debug on js for move up down.
cavaliet
parents: 52
diff changeset
    68
        if($profile_array!=null && $profile_name!=null && $profile_name!=""){
22377c9e2eae First step of column management in document tag list. Little debug on js for move up down.
cavaliet
parents: 52
diff changeset
    69
            $columns_array = $profile_array[$profile_name];
22377c9e2eae First step of column management in document tag list. Little debug on js for move up down.
cavaliet
parents: 52
diff changeset
    70
        }
102
d1af10ee0aa5 Correct read only configuration
cavaliet
parents: 98
diff changeset
    71
        
112
14653baf4f6b first change for wikipedia and dbpedia lang configuration
cavaliet
parents: 104
diff changeset
    72
        return $this->render('WikiTagBundle:WikiTag:javascript.html.twig', 
14653baf4f6b first change for wikipedia and dbpedia lang configuration
cavaliet
parents: 104
diff changeset
    73
        		array('wikipedia_api_url' => $this->container->getParameter("wiki_tag.url_templates")["wikipedia_api"], 
14653baf4f6b first change for wikipedia and dbpedia lang configuration
cavaliet
parents: 104
diff changeset
    74
        				'categories' => $categories, 
14653baf4f6b first change for wikipedia and dbpedia lang configuration
cavaliet
parents: 104
diff changeset
    75
        				'tags_list' => $tags_list, 
14653baf4f6b first change for wikipedia and dbpedia lang configuration
cavaliet
parents: 104
diff changeset
    76
        				'columns' => $columns_array, 
14653baf4f6b first change for wikipedia and dbpedia lang configuration
cavaliet
parents: 104
diff changeset
    77
        				'read_only' => $read_only));
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
    78
    }
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
    79
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
    80
    /**
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
    81
     * 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
    82
     */
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
    83
    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
    84
    {
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
    85
        // 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
    86
        // 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
    87
        // 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
    88
        // We add the reactive selectors
36
540607cf3447 Context search v1 is finished. Context allowing various configuration is set. Css and templates are clearly set.
cavaliet
parents: 35
diff changeset
    89
        $reac_sel_array = $this->container->getParameter("wiki_tag.reactive_selectors");
540607cf3447 Context search v1 is finished. Context allowing various configuration is set. Css and templates are clearly set.
cavaliet
parents: 35
diff changeset
    90
        $reactive_selectors = null;
540607cf3447 Context search v1 is finished. Context allowing various configuration is set. Css and templates are clearly set.
cavaliet
parents: 35
diff changeset
    91
        if(array_key_exists($context_name, $reac_sel_array)){
540607cf3447 Context search v1 is finished. Context allowing various configuration is set. Css and templates are clearly set.
cavaliet
parents: 35
diff changeset
    92
            if($reac_sel_array[$context_name][0]=='document'){
540607cf3447 Context search v1 is finished. Context allowing various configuration is set. Css and templates are clearly set.
cavaliet
parents: 35
diff changeset
    93
                $reactive_selectors = 'document';
540607cf3447 Context search v1 is finished. Context allowing various configuration is set. Css and templates are clearly set.
cavaliet
parents: 35
diff changeset
    94
            }
540607cf3447 Context search v1 is finished. Context allowing various configuration is set. Css and templates are clearly set.
cavaliet
parents: 35
diff changeset
    95
            else{
540607cf3447 Context search v1 is finished. Context allowing various configuration is set. Css and templates are clearly set.
cavaliet
parents: 35
diff changeset
    96
                $reactive_selectors = '"'.join('","',$reac_sel_array[$context_name]).'"';
540607cf3447 Context search v1 is finished. Context allowing various configuration is set. Css and templates are clearly set.
cavaliet
parents: 35
diff changeset
    97
            }
540607cf3447 Context search v1 is finished. Context allowing various configuration is set. Css and templates are clearly set.
cavaliet
parents: 35
diff changeset
    98
        }
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
    99
        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
   100
    }
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   101
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   102
    /**
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   103
     * Display a list of ordered tag for a document
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   104
     * @param integer $id_doc
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   105
     */
46
6f643fc1de26 commit changes before update.
cavaliet
parents: 37
diff changeset
   106
    public function documentTagsAction($id_doc, $profile_name="")
2
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   107
    {
46
6f643fc1de26 commit changes before update.
cavaliet
parents: 37
diff changeset
   108
        // Management of profiles for the list of displayed columns and reorder tag button
6f643fc1de26 commit changes before update.
cavaliet
parents: 37
diff changeset
   109
        $profile_array = $this->container->getParameter("wiki_tag.document_list_profile");
6f643fc1de26 commit changes before update.
cavaliet
parents: 37
diff changeset
   110
        $columns_array = null;
6f643fc1de26 commit changes before update.
cavaliet
parents: 37
diff changeset
   111
        if($profile_array!=null && $profile_name!=null && $profile_name!=""){
6f643fc1de26 commit changes before update.
cavaliet
parents: 37
diff changeset
   112
            $columns_array = $profile_array[$profile_name];
6f643fc1de26 commit changes before update.
cavaliet
parents: 37
diff changeset
   113
        }
6f643fc1de26 commit changes before update.
cavaliet
parents: 37
diff changeset
   114
        
2
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   115
        $ordered_tags = $this->getDoctrine()->getRepository('WikiTagBundle:DocumentTag')->findOrderedTagsForDoc($id_doc);
76
bb7808e180c3 Add configuration to enable curl request with proxy or any other CURLOPT
cavaliet
parents: 68
diff changeset
   116
        //$ordered_tags = null;
112
14653baf4f6b first change for wikipedia and dbpedia lang configuration
cavaliet
parents: 104
diff changeset
   117
        return $this->render('WikiTagBundle:WikiTag:documentTags.html.twig', 
14653baf4f6b first change for wikipedia and dbpedia lang configuration
cavaliet
parents: 104
diff changeset
   118
        		array('ordered_tags' => $ordered_tags, 
14653baf4f6b first change for wikipedia and dbpedia lang configuration
cavaliet
parents: 104
diff changeset
   119
        				'doc_id' => $id_doc, 
14653baf4f6b first change for wikipedia and dbpedia lang configuration
cavaliet
parents: 104
diff changeset
   120
        				'columns' => $columns_array, 
14653baf4f6b first change for wikipedia and dbpedia lang configuration
cavaliet
parents: 104
diff changeset
   121
        				'profile_name' => $profile_name,
14653baf4f6b first change for wikipedia and dbpedia lang configuration
cavaliet
parents: 104
diff changeset
   122
        				'wikipedia_opensearch_url' => $this->container->getParameter("wiki_tag.url_templates")["wikipedia_opensearch"]));
2
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   123
    }
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   124
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   125
    /**
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   126
     *
42
0e57c730bb18 Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents: 37
diff changeset
   127
     * The action called when a tag is moved in a document tag list.
0e57c730bb18 Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents: 37
diff changeset
   128
     *
2
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   129
     * @return \Symfony\Bundle\FrameworkBundle\Controller\Response
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   130
     */
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   131
    public function tagUpDownAction()
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   132
    {
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   133
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   134
        $req = $this->getRequest()->request;
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   135
        $id_doc = $req->get('wikitag_document_id');
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   136
        // 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
   137
        // NB : it is different from the DocumentTag.order in the database.
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   138
        $new_order = intval($req->get('new_order')) - 1;
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   139
        $old_order = intval($req->get('old_order')) - 1;
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   140
        // First we get the DocumentTags
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   141
        $em = $this->getDoctrine()->getEntityManager();
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   142
        $ordered_tags = $this->getDoctrine()->getRepository('WikiTagBundle:DocumentTag')->findOrderedTagsForDoc($id_doc);
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   143
        // We change the moved DocumentTag's order
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   144
        $new_dt_order = $ordered_tags[$new_order]->getTagOrder();
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   145
        $moved_dt = $ordered_tags[$old_order];
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   146
        $moved_dt->setTagOrder($new_dt_order);
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   147
        // We move the TaggedSheets's order
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   148
        if($new_order > $old_order){
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   149
            // And we decrease the other ones
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   150
            for ($i=($old_order+1); $i <= ($new_order); $i++){
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   151
                $dt = $ordered_tags[$i];
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   152
                $dt->setTagOrder($dt->getTagOrder() - 1);
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   153
            }
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   154
        }
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   155
        else{
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   156
            // And we increase the other ones
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   157
            for ($i=$new_order; $i <= ($old_order-1); $i++){
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   158
                $dt = $ordered_tags[$i];
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   159
                $dt->setTagOrder($dt->getTagOrder() + 1);
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   160
            }
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   161
        }
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   162
        // Save datas.
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   163
        $em->flush();
104
af79031ee002 correct document profile propagation in ajax call
cavaliet
parents: 102
diff changeset
   164
        
49
e854d8cb376c Finalise to implement the document profile with the list of columns.
cavaliet
parents: 47
diff changeset
   165
        return $this->renderDocTags($id_doc, $req->get('wikitag_document_profile'));
2
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   166
    }
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   167
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   168
    /**
43
54f204bceb28 Correct migration
ymh <ymh.work@gmail.com>
parents: 42
diff changeset
   169
     * Action to remove a tag from a document tag list
2
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   170
     * @return \Symfony\Bundle\FrameworkBundle\Controller\Response
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   171
     */
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   172
    public function removeTagFromListAction()
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   173
    {
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   174
        $id_doc = $this->getRequest()->request->get('wikitag_document_id');
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   175
        $id_tag = $this->getRequest()->request->get('tag_id');
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   176
        // We get the DocumentTag meant to be deleted, and remove it.
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   177
        $em = $this->getDoctrine()->getEntityManager();
37
9ba15af20acc make sure that we use external ids in the controller
ymh <ymh.work@gmail.com>
parents: 36
diff changeset
   178
        
9ba15af20acc make sure that we use external ids in the controller
ymh <ymh.work@gmail.com>
parents: 36
diff changeset
   179
        $dt = $this->getDoctrine()->getRepository('WikiTagBundle:DocumentTag')->findOneByDocumentExternalId($id_doc, array('tag' => $id_tag));
2
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   180
        $em->remove($dt);
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   181
        $em->flush();
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   182
49
e854d8cb376c Finalise to implement the document profile with the list of columns.
cavaliet
parents: 47
diff changeset
   183
        return $this->renderDocTags($id_doc, $this->getRequest()->request->get('wikitag_document_profile'));
2
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   184
    }
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   185
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   186
    /**
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
   187
     * 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
   188
     *
2
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   189
     */
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   190
    public function modifyDocumentTagAction()
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   191
    {
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   192
        $id_doc = $this->getRequest()->request->get('wikitag_document_id');
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   193
        $tag_label = $this->getRequest()->request->get('value');
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   194
        $id_moved_tag = $this->getRequest()->request->get('id');
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   195
        $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
   196
        if($tag_label!=$moved_tag->getLabel()){
2
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   197
            // We get the DocumentTags
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   198
            $em = $this->getDoctrine()->getEntityManager();
37
9ba15af20acc make sure that we use external ids in the controller
ymh <ymh.work@gmail.com>
parents: 36
diff changeset
   199
            
9ba15af20acc make sure that we use external ids in the controller
ymh <ymh.work@gmail.com>
parents: 36
diff changeset
   200
            $tags = $this->getDoctrine()->getRepository('WikiTagBundle:DocumentTag')->findByDocumentExternalId($id_doc);
2
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   201
            $found = false;
37
9ba15af20acc make sure that we use external ids in the controller
ymh <ymh.work@gmail.com>
parents: 36
diff changeset
   202
            foreach ($tags as $dt)
9ba15af20acc make sure that we use external ids in the controller
ymh <ymh.work@gmail.com>
parents: 36
diff changeset
   203
            {
9ba15af20acc make sure that we use external ids in the controller
ymh <ymh.work@gmail.com>
parents: 36
diff changeset
   204
                if($dt->getTag()->getLabel()===$tag_label)
9ba15af20acc make sure that we use external ids in the controller
ymh <ymh.work@gmail.com>
parents: 36
diff changeset
   205
                {
2
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   206
                    $found = true;
37
9ba15af20acc make sure that we use external ids in the controller
ymh <ymh.work@gmail.com>
parents: 36
diff changeset
   207
                    break;
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
            }
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   210
            // If the label was found, we sent a bad request
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   211
            if($found==true){
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   212
                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
   213
            }
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   214
            // We create the new tag or get the already existing tag. $tag, $revision_id, $created
50
e967654e90cb First step of error management when Wikipedia request fails. Set up in whole list and document list.
cavaliet
parents: 49
diff changeset
   215
            try {
68
e7384fb35f7a improve search test and documentation
ymh <ymh.work@gmail.com>
parents: 67
diff changeset
   216
                $ar = $this->getDoctrine()->getRepository('WikiTagBundle:Tag')->getOrCreateTag($tag_label, $this->container->getParameter('wiki_tag.ignore_wikipedia_error'), $this->container->get('logger'));
50
e967654e90cb First step of error management when Wikipedia request fails. Set up in whole list and document list.
cavaliet
parents: 49
diff changeset
   217
            }
e967654e90cb First step of error management when Wikipedia request fails. Set up in whole list and document list.
cavaliet
parents: 49
diff changeset
   218
            catch (\Exception $e){
e967654e90cb First step of error management when Wikipedia request fails. Set up in whole list and document list.
cavaliet
parents: 49
diff changeset
   219
                return new Response(json_encode(array('error' => 'wikipedia_request_failed', 'message' => $e->getMessage())),400);
e967654e90cb First step of error management when Wikipedia request fails. Set up in whole list and document list.
cavaliet
parents: 49
diff changeset
   220
            }
2
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   221
            $tag = $ar[0];
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   222
            $revision_id = $ar[1];
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   223
            $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
   224
            
2
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   225
            // We get the DocumentTag and change its tag
37
9ba15af20acc make sure that we use external ids in the controller
ymh <ymh.work@gmail.com>
parents: 36
diff changeset
   226
            
9ba15af20acc make sure that we use external ids in the controller
ymh <ymh.work@gmail.com>
parents: 36
diff changeset
   227
            $dt = $this->getDoctrine()->getRepository('WikiTagBundle:DocumentTag')->findOneByDocumentExternalId($id_doc, array('tag' => $id_moved_tag));
2
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   228
            $dt->setTag($tag);
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   229
            $dt->setWikipediaRevisionId($revision_id);
34
21fab44f46fe add event on tag changed
ymh <ymh.work@gmail.com>
parents: 30
diff changeset
   230
            
37
9ba15af20acc make sure that we use external ids in the controller
ymh <ymh.work@gmail.com>
parents: 36
diff changeset
   231
            $score_res = $this->container->get('wiki_tag.search')->search($tag_label, array("externalId"=>$id_doc));
34
21fab44f46fe add event on tag changed
ymh <ymh.work@gmail.com>
parents: 30
diff changeset
   232
            
21fab44f46fe add event on tag changed
ymh <ymh.work@gmail.com>
parents: 30
diff changeset
   233
            if(count($score_res)>0)
21fab44f46fe add event on tag changed
ymh <ymh.work@gmail.com>
parents: 30
diff changeset
   234
            {
21fab44f46fe add event on tag changed
ymh <ymh.work@gmail.com>
parents: 30
diff changeset
   235
                $score = floatval($score_res[0]['score']);
21fab44f46fe add event on tag changed
ymh <ymh.work@gmail.com>
parents: 30
diff changeset
   236
            }
21fab44f46fe add event on tag changed
ymh <ymh.work@gmail.com>
parents: 30
diff changeset
   237
            else
21fab44f46fe add event on tag changed
ymh <ymh.work@gmail.com>
parents: 30
diff changeset
   238
            {
21fab44f46fe add event on tag changed
ymh <ymh.work@gmail.com>
parents: 30
diff changeset
   239
                $score = 0.0;
21fab44f46fe add event on tag changed
ymh <ymh.work@gmail.com>
parents: 30
diff changeset
   240
            }
21fab44f46fe add event on tag changed
ymh <ymh.work@gmail.com>
parents: 30
diff changeset
   241
            $dt->setIndexNote($score);
21fab44f46fe add event on tag changed
ymh <ymh.work@gmail.com>
parents: 30
diff changeset
   242
            
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
   243
            // 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
   244
            $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
   245
            $doc->setManualOrder(true);
2
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   246
            // We save the datas
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   247
            $em->flush();
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   248
        }
32
38dcd2db04e4 Debug case sentive tag modification.
cavaliet
parents: 30
diff changeset
   249
        // We render the document's tags
49
e854d8cb376c Finalise to implement the document profile with the list of columns.
cavaliet
parents: 47
diff changeset
   250
        return $this->renderDocTags($id_doc, $this->getRequest()->request->get('wikitag_document_profile'));
2
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   251
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   252
    }
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   253
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   254
    /**
42
0e57c730bb18 Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents: 37
diff changeset
   255
     * The action called to reorder the the tags of a document. The tags are reordered according to the indexation score of the tag label on the document.
0e57c730bb18 Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents: 37
diff changeset
   256
     * The fields taken into account for calculating the score are defined in the wikitag configuration.
2
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   257
     */
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   258
    public function reorderTagDocumentAction()
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   259
    {
30
d2fba1e3b94b correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents: 29
diff changeset
   260
        $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
   261
        $res = $this->getDoctrine()->getRepository('WikiTagBundle:Document');
37
9ba15af20acc make sure that we use external ids in the controller
ymh <ymh.work@gmail.com>
parents: 36
diff changeset
   262
        
30
d2fba1e3b94b correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents: 29
diff changeset
   263
        $doc = $res->findOneByExternalId($id_doc);
d2fba1e3b94b correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents: 29
diff changeset
   264
        $doc->setManualOrder(false);
d2fba1e3b94b correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents: 29
diff changeset
   265
        $this->getDoctrine()->getEntityManager()->persist($doc);
d2fba1e3b94b correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents: 29
diff changeset
   266
        
68
e7384fb35f7a improve search test and documentation
ymh <ymh.work@gmail.com>
parents: 67
diff changeset
   267
        $doc_service = $this->get('wiki_tag.document')->reorderTags($doc);
30
d2fba1e3b94b correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents: 29
diff changeset
   268
        
d2fba1e3b94b correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents: 29
diff changeset
   269
        $this->getDoctrine()->getEntityManager()->flush();
d2fba1e3b94b correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents: 29
diff changeset
   270
49
e854d8cb376c Finalise to implement the document profile with the list of columns.
cavaliet
parents: 47
diff changeset
   271
        return $this->renderDocTags($id_doc, $this->getRequest()->request->get('wikitag_document_profile'));
2
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   272
    }
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   273
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   274
    /**
42
0e57c730bb18 Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents: 37
diff changeset
   275
     * The action called to add a new tag (especially from the completion box)
2
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   276
     */
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   277
    public function addTagAction()
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   278
    {
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   279
        $id_doc = $this->getRequest()->request->get('wikitag_document_id');
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   280
        $tag_label = $this->getRequest()->request->get('value');
63
774ba82dca59 add tests and fixtures
ymh <ymh.work@gmail.com>
parents: 61
diff changeset
   281
        
774ba82dca59 add tests and fixtures
ymh <ymh.work@gmail.com>
parents: 61
diff changeset
   282
        
774ba82dca59 add tests and fixtures
ymh <ymh.work@gmail.com>
parents: 61
diff changeset
   283
        try
774ba82dca59 add tests and fixtures
ymh <ymh.work@gmail.com>
parents: 61
diff changeset
   284
        {
65
ba6b8e38d90e Correct event mamangement in hdabo_sf
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
   285
            $this->get('wiki_tag.document')->addTags($id_doc, $tag_label);
50
e967654e90cb First step of error management when Wikipedia request fails. Set up in whole list and document list.
cavaliet
parents: 49
diff changeset
   286
        }
63
774ba82dca59 add tests and fixtures
ymh <ymh.work@gmail.com>
parents: 61
diff changeset
   287
        catch (WikiTagServiceException $e)
774ba82dca59 add tests and fixtures
ymh <ymh.work@gmail.com>
parents: 61
diff changeset
   288
        {
774ba82dca59 add tests and fixtures
ymh <ymh.work@gmail.com>
parents: 61
diff changeset
   289
            return new Response(json_encode(array('error' => $e->getErrorCode(), 'message' => $e->getMessage())),$e->getCode());
2
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   290
        }
65
ba6b8e38d90e Correct event mamangement in hdabo_sf
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
   291
        $this->getDoctrine()->getEntityManager()->flush();
2
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   292
65
ba6b8e38d90e Correct event mamangement in hdabo_sf
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
   293
        
49
e854d8cb376c Finalise to implement the document profile with the list of columns.
cavaliet
parents: 47
diff changeset
   294
        return $this->renderDocTags($id_doc, $this->getRequest()->request->get('wikitag_document_profile'));
2
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   295
    }
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   296
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   297
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   298
    /**
43
54f204bceb28 Correct migration
ymh <ymh.work@gmail.com>
parents: 42
diff changeset
   299
     * Action to remove the wikipedia link form a tag. This action create a copy of the original tag with all the link to wikipedia set to null.
2
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   300
     *
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   301
     * @return \Symfony\Bundle\FrameworkBundle\Controller\Response
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   302
     */
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   303
    public function removeWpLinkAction()
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   304
    {
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   305
        $id_doc = $this->getRequest()->request->get('wikitag_document_id');
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   306
        $id_tag = $this->getRequest()->request->get('tag_id');
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   307
        $tag = $this->getDoctrine()->getRepository('WikiTagBundle:Tag')->find($id_tag);
58
87bf6ec8af90 add unsemantized status
ymh <ymh.work@gmail.com>
parents: 49
diff changeset
   308
 
2
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   309
        $em = $this->getDoctrine()->getEntityManager();
58
87bf6ec8af90 add unsemantized status
ymh <ymh.work@gmail.com>
parents: 49
diff changeset
   310
        $query = $em->createQuery("SELECT t FROM WikiTagBundle:Tag t WHERE t.label = :label AND (t.urlStatus = :status_null OR t.urlStatus = :status_unsemantized)");
87bf6ec8af90 add unsemantized status
ymh <ymh.work@gmail.com>
parents: 49
diff changeset
   311
        $query->setParameters(array("label"=>$tag->getLabel(),"status_null"=>Tag::$TAG_URL_STATUS_DICT['null_result'],"status_unsemantized"=>Tag::$TAG_URL_STATUS_DICT['unsemantized']));
87bf6ec8af90 add unsemantized status
ymh <ymh.work@gmail.com>
parents: 49
diff changeset
   312
        $un_tag = null;
87bf6ec8af90 add unsemantized status
ymh <ymh.work@gmail.com>
parents: 49
diff changeset
   313
        $un_tags = $query->getResult();
87bf6ec8af90 add unsemantized status
ymh <ymh.work@gmail.com>
parents: 49
diff changeset
   314
        if(count($un_tags)>0) {
87bf6ec8af90 add unsemantized status
ymh <ymh.work@gmail.com>
parents: 49
diff changeset
   315
            $un_tag = $un_tags[0];
87bf6ec8af90 add unsemantized status
ymh <ymh.work@gmail.com>
parents: 49
diff changeset
   316
        }
87bf6ec8af90 add unsemantized status
ymh <ymh.work@gmail.com>
parents: 49
diff changeset
   317
        $un_tag_created = false;
2
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   318
        if(!$un_tag){
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   319
            // Create another tag almost identical, without the W info
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   320
            $un_tag = new Tag();
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   321
            $un_tag->setLabel($tag->getLabel());
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   322
            $un_tag->setOriginalLabel($tag->getOriginalLabel());
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   323
            $un_tag->setWikipediaUrl(null);
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   324
            $un_tag->setWikipediaPageId(null);
43
54f204bceb28 Correct migration
ymh <ymh.work@gmail.com>
parents: 42
diff changeset
   325
            $un_tag->setAlternativeWikipediaUrl(null);
54f204bceb28 Correct migration
ymh <ymh.work@gmail.com>
parents: 42
diff changeset
   326
            $un_tag->setAlternativeWikipediaPageId(null);
54f204bceb28 Correct migration
ymh <ymh.work@gmail.com>
parents: 42
diff changeset
   327
            $un_tag->setAlternativeLabel(null);
2
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   328
            $un_tag->setDbpediaUri(null);
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   329
            $un_tag->setCategory($tag->getCategory());
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   330
            $un_tag->setAlias($tag->getAlias());
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   331
            $un_tag->setPopularity($tag->getPopularity());
58
87bf6ec8af90 add unsemantized status
ymh <ymh.work@gmail.com>
parents: 49
diff changeset
   332
            $un_tag->setUrlStatus(Tag::$TAG_URL_STATUS_DICT['unsemantized']);
43
54f204bceb28 Correct migration
ymh <ymh.work@gmail.com>
parents: 42
diff changeset
   333
            $un_tag_created = true;
58
87bf6ec8af90 add unsemantized status
ymh <ymh.work@gmail.com>
parents: 49
diff changeset
   334
            $em->persist($un_tag);
2
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   335
        }
58
87bf6ec8af90 add unsemantized status
ymh <ymh.work@gmail.com>
parents: 49
diff changeset
   336
        elseif($un_tag->getUrlStatus()==Tag::$TAG_URL_STATUS_DICT['null_result'])
87bf6ec8af90 add unsemantized status
ymh <ymh.work@gmail.com>
parents: 49
diff changeset
   337
        {
87bf6ec8af90 add unsemantized status
ymh <ymh.work@gmail.com>
parents: 49
diff changeset
   338
            $un_tag->setUrlStatus(Tag::$TAG_URL_STATUS_DICT['unsemantized']);
87bf6ec8af90 add unsemantized status
ymh <ymh.work@gmail.com>
parents: 49
diff changeset
   339
            $un_tag_created = true;
87bf6ec8af90 add unsemantized status
ymh <ymh.work@gmail.com>
parents: 49
diff changeset
   340
            $em->persist($un_tag);
87bf6ec8af90 add unsemantized status
ymh <ymh.work@gmail.com>
parents: 49
diff changeset
   341
        }
87bf6ec8af90 add unsemantized status
ymh <ymh.work@gmail.com>
parents: 49
diff changeset
   342
        
87bf6ec8af90 add unsemantized status
ymh <ymh.work@gmail.com>
parents: 49
diff changeset
   343
        
2
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   344
        
13
c288952a089f Remove WP link from tag list now works.
cavaliet
parents: 12
diff changeset
   345
        if($id_doc && $id_doc!=""){
c288952a089f Remove WP link from tag list now works.
cavaliet
parents: 12
diff changeset
   346
            // We associate the unsemantized tag to the DocumentTag and save datas
37
9ba15af20acc make sure that we use external ids in the controller
ymh <ymh.work@gmail.com>
parents: 36
diff changeset
   347
            $dt = $this->getDoctrine()->getRepository('WikiTagBundle:DocumentTag')->findOneByDocumentExternalId($id_doc, array('tag' => $id_tag));
13
c288952a089f Remove WP link from tag list now works.
cavaliet
parents: 12
diff changeset
   348
            $dt->setTag($un_tag);
c288952a089f Remove WP link from tag list now works.
cavaliet
parents: 12
diff changeset
   349
            $em->flush();
49
e854d8cb376c Finalise to implement the document profile with the list of columns.
cavaliet
parents: 47
diff changeset
   350
            return $this->renderDocTags($id_doc, $this->getRequest()->request->get('wikitag_document_profile'));
13
c288952a089f Remove WP link from tag list now works.
cavaliet
parents: 12
diff changeset
   351
        }
c288952a089f Remove WP link from tag list now works.
cavaliet
parents: 12
diff changeset
   352
        else{
c288952a089f Remove WP link from tag list now works.
cavaliet
parents: 12
diff changeset
   353
            // Here we are in the context of tag list.
58
87bf6ec8af90 add unsemantized status
ymh <ymh.work@gmail.com>
parents: 49
diff changeset
   354
            if($un_tag_created==true){
13
c288952a089f Remove WP link from tag list now works.
cavaliet
parents: 12
diff changeset
   355
                $em->flush();
61
1bc0ec8ed05b add relaunch wp
ymh <ymh.work@gmail.com>
parents: 60
diff changeset
   356
                return $this->renderAllTags();
13
c288952a089f Remove WP link from tag list now works.
cavaliet
parents: 12
diff changeset
   357
            }
c288952a089f Remove WP link from tag list now works.
cavaliet
parents: 12
diff changeset
   358
            else{
c288952a089f Remove WP link from tag list now works.
cavaliet
parents: 12
diff changeset
   359
                // 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
   360
                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
   361
            }
c288952a089f Remove WP link from tag list now works.
cavaliet
parents: 12
diff changeset
   362
        }
2
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   363
    }
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   364
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   365
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   366
    /**
43
54f204bceb28 Correct migration
ymh <ymh.work@gmail.com>
parents: 42
diff changeset
   367
     * Action to update a tag category.
54f204bceb28 Correct migration
ymh <ymh.work@gmail.com>
parents: 42
diff changeset
   368
     * @return \Symfony\Bundle\FrameworkBundle\Controller\Response
2
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   369
     */
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   370
    public function updateTagCategoryAction()
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   371
    {
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   372
        $id_doc = $this->getRequest()->request->get('wikitag_document_id');
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   373
        $id_tag = $this->getRequest()->request->get('id');
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   374
        $cat_label = $this->getRequest()->request->get('value');
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   375
        // We get the Tag and update its category.
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   376
        $em = $this->getDoctrine()->getEntityManager();
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   377
        $tag = $this->getDoctrine()->getRepository('WikiTagBundle:Tag')->find($id_tag);
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   378
        if($cat_label==''){
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   379
            $cat = null;
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   380
            $tag->nullCategory();
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   381
        }
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   382
        else{
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   383
            $cat = $this->getDoctrine()->getRepository('WikiTagBundle:Category')->findOneBy(array('label' => $cat_label));
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   384
            $tag->setCategory($cat);
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   385
        }
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   386
        $em->flush();
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   387
11
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   388
        if($id_doc && $id_doc!=""){
49
e854d8cb376c Finalise to implement the document profile with the list of columns.
cavaliet
parents: 47
diff changeset
   389
            return $this->renderDocTags($id_doc, $this->getRequest()->request->get('wikitag_document_profile'));
11
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   390
        }
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   391
        else{
61
1bc0ec8ed05b add relaunch wp
ymh <ymh.work@gmail.com>
parents: 60
diff changeset
   392
            return $this->renderAllTags();
11
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   393
        }
2
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   394
    }
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   395
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   396
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   397
    /**
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   398
     *
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   399
     * Generic render partial template
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   400
     * @param unknown_type $id_doc
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   401
     */
104
af79031ee002 correct document profile propagation in ajax call
cavaliet
parents: 102
diff changeset
   402
    public function renderDocTags($id_doc, $profile_name="")
2
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   403
    {
104
af79031ee002 correct document profile propagation in ajax call
cavaliet
parents: 102
diff changeset
   404
        // Management of profiles for the list of displayed columns and reorder tag button
af79031ee002 correct document profile propagation in ajax call
cavaliet
parents: 102
diff changeset
   405
        $profile_array = $this->container->getParameter("wiki_tag.document_list_profile");
af79031ee002 correct document profile propagation in ajax call
cavaliet
parents: 102
diff changeset
   406
        $columns_array = null;
af79031ee002 correct document profile propagation in ajax call
cavaliet
parents: 102
diff changeset
   407
        if($profile_array!=null && $profile_name!=null && $profile_name!=""){
af79031ee002 correct document profile propagation in ajax call
cavaliet
parents: 102
diff changeset
   408
            $columns_array = $profile_array[$profile_name];
af79031ee002 correct document profile propagation in ajax call
cavaliet
parents: 102
diff changeset
   409
        }
2
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   410
        $ordered_tags = $this->getDoctrine()->getRepository('WikiTagBundle:DocumentTag')->findOrderedTagsForDoc($id_doc);
112
14653baf4f6b first change for wikipedia and dbpedia lang configuration
cavaliet
parents: 104
diff changeset
   411
        return $this->render('WikiTagBundle:WikiTag:tagTable.html.twig', 
14653baf4f6b first change for wikipedia and dbpedia lang configuration
cavaliet
parents: 104
diff changeset
   412
        		array('ordered_tags' => $ordered_tags, 
14653baf4f6b first change for wikipedia and dbpedia lang configuration
cavaliet
parents: 104
diff changeset
   413
        				'doc_id' => $id_doc, 
14653baf4f6b first change for wikipedia and dbpedia lang configuration
cavaliet
parents: 104
diff changeset
   414
        				'columns' => $columns_array, 
14653baf4f6b first change for wikipedia and dbpedia lang configuration
cavaliet
parents: 104
diff changeset
   415
        				'profile_name' => $profile_name,
14653baf4f6b first change for wikipedia and dbpedia lang configuration
cavaliet
parents: 104
diff changeset
   416
        				'wikipedia_opensearch_url' => $this->container->getParameter("wiki_tag.url_templates")["wikipedia_opensearch"]));
2
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   417
    }
7
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
7a877de630fd add files to all tags list.
tcavalie
parents: 5
diff changeset
   420
    /**
43
54f204bceb28 Correct migration
ymh <ymh.work@gmail.com>
parents: 42
diff changeset
   421
     * Action to update the tag alias.
54f204bceb28 Correct migration
ymh <ymh.work@gmail.com>
parents: 42
diff changeset
   422
	 *
7
7a877de630fd add files to all tags list.
tcavalie
parents: 5
diff changeset
   423
     * @return \Symfony\Bundle\FrameworkBundle\Controller\Response
7a877de630fd add files to all tags list.
tcavalie
parents: 5
diff changeset
   424
     */
7a877de630fd add files to all tags list.
tcavalie
parents: 5
diff changeset
   425
    public function updateTagAliasAction()
7a877de630fd add files to all tags list.
tcavalie
parents: 5
diff changeset
   426
    {
12
81cc9274c20a Update Tag alias.
cavaliet
parents: 11
diff changeset
   427
        $id_tag = $this->getRequest()->request->get('id');
81cc9274c20a Update Tag alias.
cavaliet
parents: 11
diff changeset
   428
        $alias = $this->getRequest()->request->get('value');
81cc9274c20a Update Tag alias.
cavaliet
parents: 11
diff changeset
   429
        // We get the Tag and update its category.
81cc9274c20a Update Tag alias.
cavaliet
parents: 11
diff changeset
   430
        $em = $this->getDoctrine()->getEntityManager();
81cc9274c20a Update Tag alias.
cavaliet
parents: 11
diff changeset
   431
        $tag = $this->getDoctrine()->getRepository('WikiTagBundle:Tag')->find($id_tag);
81cc9274c20a Update Tag alias.
cavaliet
parents: 11
diff changeset
   432
        $tag->setAlias($alias);
81cc9274c20a Update Tag alias.
cavaliet
parents: 11
diff changeset
   433
        $em->flush();
81cc9274c20a Update Tag alias.
cavaliet
parents: 11
diff changeset
   434
        
7
7a877de630fd add files to all tags list.
tcavalie
parents: 5
diff changeset
   435
        $id_doc = $this->getRequest()->request->get('wikitag_document_id');
12
81cc9274c20a Update Tag alias.
cavaliet
parents: 11
diff changeset
   436
        if($id_doc && $id_doc!=""){
81cc9274c20a Update Tag alias.
cavaliet
parents: 11
diff changeset
   437
            // In case we changed the alias from the document view
49
e854d8cb376c Finalise to implement the document profile with the list of columns.
cavaliet
parents: 47
diff changeset
   438
            return $this->renderDocTags($id_doc, $this->getRequest()->request->get('wikitag_document_profile'));
12
81cc9274c20a Update Tag alias.
cavaliet
parents: 11
diff changeset
   439
        }
81cc9274c20a Update Tag alias.
cavaliet
parents: 11
diff changeset
   440
        else{
81cc9274c20a Update Tag alias.
cavaliet
parents: 11
diff changeset
   441
            // In case we changed the alias from the tag list.
61
1bc0ec8ed05b add relaunch wp
ymh <ymh.work@gmail.com>
parents: 60
diff changeset
   442
            return $this->renderAllTags();
12
81cc9274c20a Update Tag alias.
cavaliet
parents: 11
diff changeset
   443
        }
7
7a877de630fd add files to all tags list.
tcavalie
parents: 5
diff changeset
   444
    }
7a877de630fd add files to all tags list.
tcavalie
parents: 5
diff changeset
   445
    
7a877de630fd add files to all tags list.
tcavalie
parents: 5
diff changeset
   446
    /**
43
54f204bceb28 Correct migration
ymh <ymh.work@gmail.com>
parents: 42
diff changeset
   447
     * List all tags, with pagination and search.
54f204bceb28 Correct migration
ymh <ymh.work@gmail.com>
parents: 42
diff changeset
   448
     *
54f204bceb28 Correct migration
ymh <ymh.work@gmail.com>
parents: 42
diff changeset
   449
     * @return \Symfony\Bundle\FrameworkBundle\Controller\Response
7
7a877de630fd add files to all tags list.
tcavalie
parents: 5
diff changeset
   450
     */
7a877de630fd add files to all tags list.
tcavalie
parents: 5
diff changeset
   451
    public function allTagsAction()
7a877de630fd add files to all tags list.
tcavalie
parents: 5
diff changeset
   452
    {
7a877de630fd add files to all tags list.
tcavalie
parents: 5
diff changeset
   453
        // $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
   454
        // Searched string
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   455
        $searched = NULL;
9
cc32af725176 first step for tag list and add Pagerfanta for paginator
cavaliet
parents: 8
diff changeset
   456
        if(array_key_exists('searched', $_GET)){
cc32af725176 first step for tag list and add Pagerfanta for paginator
cavaliet
parents: 8
diff changeset
   457
            $searched = $_GET['searched'];
7
7a877de630fd add files to all tags list.
tcavalie
parents: 5
diff changeset
   458
        }
9
cc32af725176 first step for tag list and add Pagerfanta for paginator
cavaliet
parents: 8
diff changeset
   459
        // Number of tags per page
8
7d2fb5d7c9ff debug addtag for document
cavaliet
parents: 7
diff changeset
   460
        $nb_by_page = 50;
9
cc32af725176 first step for tag list and add Pagerfanta for paginator
cavaliet
parents: 8
diff changeset
   461
        if(array_key_exists('nb_by_page', $_GET)){
cc32af725176 first step for tag list and add Pagerfanta for paginator
cavaliet
parents: 8
diff changeset
   462
            $nb_by_page = intval($_GET['nb_by_page']);
cc32af725176 first step for tag list and add Pagerfanta for paginator
cavaliet
parents: 8
diff changeset
   463
        }
cc32af725176 first step for tag list and add Pagerfanta for paginator
cavaliet
parents: 8
diff changeset
   464
        // Current page number
cc32af725176 first step for tag list and add Pagerfanta for paginator
cavaliet
parents: 8
diff changeset
   465
        $num_page = 1;
cc32af725176 first step for tag list and add Pagerfanta for paginator
cavaliet
parents: 8
diff changeset
   466
        if(array_key_exists('num_page', $_GET)){
cc32af725176 first step for tag list and add Pagerfanta for paginator
cavaliet
parents: 8
diff changeset
   467
            $num_page = intval($_GET['num_page']);
cc32af725176 first step for tag list and add Pagerfanta for paginator
cavaliet
parents: 8
diff changeset
   468
        }
11
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   469
        // Sorting criteria
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   470
        $sort = NULL;
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   471
        if(array_key_exists('sort', $_GET)){
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   472
            $sort = $_GET['sort'];
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   473
        }
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   474
        
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   475
        // 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
   476
        $ar = $this->getAllTags($num_page, $nb_by_page, $sort, $searched);
16
876df98c9208 Debug search with simple quote.
cavaliet
parents: 15
diff changeset
   477
        //return new Response($ar);
11
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   478
        $tags = $ar[0];
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   479
        $num_page = $ar[1];
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   480
        $nb_by_page = $ar[2];
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   481
        $searched = $ar[3];
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   482
        $sort = $ar[4];
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   483
        $reverse_sort = $ar[5];
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   484
        $pagerfanta = $ar[6];
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
        // 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
   487
        $last_page = $pagerfanta->getNbPages();
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   488
        $nb_total = $pagerfanta->getNbResults();
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   489
        $prev_page = 1;
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   490
        if($pagerfanta->hasPreviousPage()){
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   491
            $prev_page = $pagerfanta->getPreviousPage();
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   492
        }
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   493
        $next_page = $last_page;
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   494
        if($pagerfanta->hasNextPage()){
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   495
            $next_page = $pagerfanta->getNextPage();
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   496
        }
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   497
        // 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
   498
        $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
   499
        $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
   500
        
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   501
        // 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
   502
        $conn = $this->getDoctrine()->getEntityManager()->getConnection();
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   503
        $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
   504
        $letters = $conn->query($sql)->fetchAll();
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   505
        $search_def = array();
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   506
        foreach ($letters as $l){
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   507
            $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
   508
        }
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   509
        
21
780ef37e63b9 add route parameter
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   510
        return $this->render('WikiTagBundle:WikiTag:TagList.html.twig',
112
14653baf4f6b first change for wikipedia and dbpedia lang configuration
cavaliet
parents: 104
diff changeset
   511
            array('tags' => $tags, 
14653baf4f6b first change for wikipedia and dbpedia lang configuration
cavaliet
parents: 104
diff changeset
   512
            		'searched' => $searched, 
14653baf4f6b first change for wikipedia and dbpedia lang configuration
cavaliet
parents: 104
diff changeset
   513
            		'search_def' => $search_def, 
14653baf4f6b first change for wikipedia and dbpedia lang configuration
cavaliet
parents: 104
diff changeset
   514
            		'nb_by_page' => $nb_by_page, 
14653baf4f6b first change for wikipedia and dbpedia lang configuration
cavaliet
parents: 104
diff changeset
   515
            		'sort' => $sort,
14653baf4f6b first change for wikipedia and dbpedia lang configuration
cavaliet
parents: 104
diff changeset
   516
            		'start_index' => $start_index, 
14653baf4f6b first change for wikipedia and dbpedia lang configuration
cavaliet
parents: 104
diff changeset
   517
            		'end_index' => $end_index, 
14653baf4f6b first change for wikipedia and dbpedia lang configuration
cavaliet
parents: 104
diff changeset
   518
            		'nb_total' => $nb_total, 
14653baf4f6b first change for wikipedia and dbpedia lang configuration
cavaliet
parents: 104
diff changeset
   519
            		'num_page' => $num_page, 
14653baf4f6b first change for wikipedia and dbpedia lang configuration
cavaliet
parents: 104
diff changeset
   520
            		'last_page' => $last_page,
14653baf4f6b first change for wikipedia and dbpedia lang configuration
cavaliet
parents: 104
diff changeset
   521
        			'prev_page' => $prev_page, 
14653baf4f6b first change for wikipedia and dbpedia lang configuration
cavaliet
parents: 104
diff changeset
   522
            		'next_page' => $next_page, 
14653baf4f6b first change for wikipedia and dbpedia lang configuration
cavaliet
parents: 104
diff changeset
   523
            		'reverse_sort' => $reverse_sort, 
14653baf4f6b first change for wikipedia and dbpedia lang configuration
cavaliet
parents: 104
diff changeset
   524
            		'route_for_documents_by_tag' => $this->container->getParameter("wiki_tag.route_for_documents_by_tag"),
14653baf4f6b first change for wikipedia and dbpedia lang configuration
cavaliet
parents: 104
diff changeset
   525
            		'wikipedia_opensearch_url' => $this->container->getParameter("wiki_tag.url_templates")["wikipedia_opensearch"]));
11
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   526
    }
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   527
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
   528
    /**
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
     * 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
   530
     */
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
    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
   532
    {
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
        $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
   534
        $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
   535
        $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
   536
        // We update the tag label and its wikipedia info with the new label.
50
e967654e90cb First step of error management when Wikipedia request fails. Set up in whole list and document list.
cavaliet
parents: 49
diff changeset
   537
        try {
e967654e90cb First step of error management when Wikipedia request fails. Set up in whole list and document list.
cavaliet
parents: 49
diff changeset
   538
            $this->updateTagWithNewLabel($moved_tag, $tag_label);
e967654e90cb First step of error management when Wikipedia request fails. Set up in whole list and document list.
cavaliet
parents: 49
diff changeset
   539
        }
e967654e90cb First step of error management when Wikipedia request fails. Set up in whole list and document list.
cavaliet
parents: 49
diff changeset
   540
        catch (\Exception $e){
63
774ba82dca59 add tests and fixtures
ymh <ymh.work@gmail.com>
parents: 61
diff changeset
   541
            return new Response(json_encode(array('error' => 'wikipedia_request_failed', 'message' => $e->getMessage())),500);
50
e967654e90cb First step of error management when Wikipedia request fails. Set up in whole list and document list.
cavaliet
parents: 49
diff changeset
   542
        }
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
   543
        // We render the tag list.
61
1bc0ec8ed05b add relaunch wp
ymh <ymh.work@gmail.com>
parents: 60
diff changeset
   544
        return $this->renderAllTags();
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
   545
    }
58
87bf6ec8af90 add unsemantized status
ymh <ymh.work@gmail.com>
parents: 49
diff changeset
   546
        
87bf6ec8af90 add unsemantized status
ymh <ymh.work@gmail.com>
parents: 49
diff changeset
   547
        
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
   548
    /**
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
     * 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
   550
     *
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
   551
     */
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
    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
   553
    {
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
        $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
   555
        $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
   556
        // We update the tag label and its wikipedia info with the original label.
50
e967654e90cb First step of error management when Wikipedia request fails. Set up in whole list and document list.
cavaliet
parents: 49
diff changeset
   557
        try {
e967654e90cb First step of error management when Wikipedia request fails. Set up in whole list and document list.
cavaliet
parents: 49
diff changeset
   558
            $this->updateTagWithNewLabel($moved_tag, $moved_tag->getOriginalLabel());
e967654e90cb First step of error management when Wikipedia request fails. Set up in whole list and document list.
cavaliet
parents: 49
diff changeset
   559
        }
e967654e90cb First step of error management when Wikipedia request fails. Set up in whole list and document list.
cavaliet
parents: 49
diff changeset
   560
        catch (\Exception $e){
63
774ba82dca59 add tests and fixtures
ymh <ymh.work@gmail.com>
parents: 61
diff changeset
   561
            return new Response(json_encode(array('error' => 'wikipedia_request_failed', 'message' => $e->getMessage())),500);
50
e967654e90cb First step of error management when Wikipedia request fails. Set up in whole list and document list.
cavaliet
parents: 49
diff changeset
   562
        }
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
   563
        
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
   564
        // We render the tag list.
61
1bc0ec8ed05b add relaunch wp
ymh <ymh.work@gmail.com>
parents: 60
diff changeset
   565
        return $this->renderAllTags();
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
   566
    }
61
1bc0ec8ed05b add relaunch wp
ymh <ymh.work@gmail.com>
parents: 60
diff changeset
   567
    
1bc0ec8ed05b add relaunch wp
ymh <ymh.work@gmail.com>
parents: 60
diff changeset
   568
    /**
1bc0ec8ed05b add relaunch wp
ymh <ymh.work@gmail.com>
parents: 60
diff changeset
   569
     * Redo a Wikipedia search
1bc0ec8ed05b add relaunch wp
ymh <ymh.work@gmail.com>
parents: 60
diff changeset
   570
     * @return \Symfony\Component\HttpFoundation\Response|\Symfony\Bundle\FrameworkBundle\Controller\Response
1bc0ec8ed05b add relaunch wp
ymh <ymh.work@gmail.com>
parents: 60
diff changeset
   571
     */
1bc0ec8ed05b add relaunch wp
ymh <ymh.work@gmail.com>
parents: 60
diff changeset
   572
    public function relaunchWpSearchAction()
1bc0ec8ed05b add relaunch wp
ymh <ymh.work@gmail.com>
parents: 60
diff changeset
   573
    {
1bc0ec8ed05b add relaunch wp
ymh <ymh.work@gmail.com>
parents: 60
diff changeset
   574
        $id_tag = $this->getRequest()->request->get('tag_id');
1bc0ec8ed05b add relaunch wp
ymh <ymh.work@gmail.com>
parents: 60
diff changeset
   575
        $tag = $this->getDoctrine()->getRepository('WikiTagBundle:Tag')->findOneBy(array('id' => $id_tag));
1bc0ec8ed05b add relaunch wp
ymh <ymh.work@gmail.com>
parents: 60
diff changeset
   576
        // We update the tag label and its wikipedia info with the original label.
1bc0ec8ed05b add relaunch wp
ymh <ymh.work@gmail.com>
parents: 60
diff changeset
   577
        try {
1bc0ec8ed05b add relaunch wp
ymh <ymh.work@gmail.com>
parents: 60
diff changeset
   578
            $this->updateTagWithNewLabel($tag, $tag->getLabel());
1bc0ec8ed05b add relaunch wp
ymh <ymh.work@gmail.com>
parents: 60
diff changeset
   579
        }
1bc0ec8ed05b add relaunch wp
ymh <ymh.work@gmail.com>
parents: 60
diff changeset
   580
        catch (\Exception $e){
63
774ba82dca59 add tests and fixtures
ymh <ymh.work@gmail.com>
parents: 61
diff changeset
   581
            return new Response(json_encode(array('error' => 'wikipedia_request_failed', 'message' => $e->getMessage())),500);
61
1bc0ec8ed05b add relaunch wp
ymh <ymh.work@gmail.com>
parents: 60
diff changeset
   582
        }
1bc0ec8ed05b add relaunch wp
ymh <ymh.work@gmail.com>
parents: 60
diff changeset
   583
    
1bc0ec8ed05b add relaunch wp
ymh <ymh.work@gmail.com>
parents: 60
diff changeset
   584
        // We render the tag list.
1bc0ec8ed05b add relaunch wp
ymh <ymh.work@gmail.com>
parents: 60
diff changeset
   585
        return $this->renderAllTags();
1bc0ec8ed05b add relaunch wp
ymh <ymh.work@gmail.com>
parents: 60
diff changeset
   586
    }
1bc0ec8ed05b add relaunch wp
ymh <ymh.work@gmail.com>
parents: 60
diff changeset
   587
    
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
   588
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
   589
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
   590
    /**
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
   591
     * 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
   592
     */
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
   593
    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
   594
    {
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
   595
        if($tag!=null && $label!=null){
61
1bc0ec8ed05b add relaunch wp
ymh <ymh.work@gmail.com>
parents: 60
diff changeset
   596
            // We get the Wikipedia informations for the sent label
1bc0ec8ed05b add relaunch wp
ymh <ymh.work@gmail.com>
parents: 60
diff changeset
   597
            $tag_label_normalized = WikiTagUtils::normalizeTag($label);
68
e7384fb35f7a improve search test and documentation
ymh <ymh.work@gmail.com>
parents: 67
diff changeset
   598
            $wp_response = WikiTagUtils::getWikipediaInfo($tag_label_normalized, null, $this->container->getParameter('wiki_tag.ignore_wikipedia_error'), $this->container->get('logger'));
61
1bc0ec8ed05b add relaunch wp
ymh <ymh.work@gmail.com>
parents: 60
diff changeset
   599
            $tag->setWikipediaInfo($wp_response);
1bc0ec8ed05b add relaunch wp
ymh <ymh.work@gmail.com>
parents: 60
diff changeset
   600
            // Save datas.
1bc0ec8ed05b add relaunch wp
ymh <ymh.work@gmail.com>
parents: 60
diff changeset
   601
            $em = $this->getDoctrine()->getEntityManager();
1bc0ec8ed05b add relaunch wp
ymh <ymh.work@gmail.com>
parents: 60
diff changeset
   602
            $em->persist($tag);
1bc0ec8ed05b add relaunch wp
ymh <ymh.work@gmail.com>
parents: 60
diff changeset
   603
            $em->flush();
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
   604
        }
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
   605
    }
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
   606
11
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   607
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   608
    /**
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   609
     * 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
   610
     */
61
1bc0ec8ed05b add relaunch wp
ymh <ymh.work@gmail.com>
parents: 60
diff changeset
   611
    public function renderAllTags($num_page=null, $nb_by_page=null, $sort=null, $searched=null)
11
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   612
    {
61
1bc0ec8ed05b add relaunch wp
ymh <ymh.work@gmail.com>
parents: 60
diff changeset
   613
        if(is_null($num_page)) {
1bc0ec8ed05b add relaunch wp
ymh <ymh.work@gmail.com>
parents: 60
diff changeset
   614
            $num_page = $this->getRequest()->request->get('num_page');
1bc0ec8ed05b add relaunch wp
ymh <ymh.work@gmail.com>
parents: 60
diff changeset
   615
        }
1bc0ec8ed05b add relaunch wp
ymh <ymh.work@gmail.com>
parents: 60
diff changeset
   616
        if(is_null($nb_by_page)) {
1bc0ec8ed05b add relaunch wp
ymh <ymh.work@gmail.com>
parents: 60
diff changeset
   617
            $nb_by_page = $this->getRequest()->request->get('nb_by_page');
1bc0ec8ed05b add relaunch wp
ymh <ymh.work@gmail.com>
parents: 60
diff changeset
   618
        }
1bc0ec8ed05b add relaunch wp
ymh <ymh.work@gmail.com>
parents: 60
diff changeset
   619
        if(is_null($sort)) {
1bc0ec8ed05b add relaunch wp
ymh <ymh.work@gmail.com>
parents: 60
diff changeset
   620
            $sort = $this->getRequest()->request->get('sort');
1bc0ec8ed05b add relaunch wp
ymh <ymh.work@gmail.com>
parents: 60
diff changeset
   621
        }
1bc0ec8ed05b add relaunch wp
ymh <ymh.work@gmail.com>
parents: 60
diff changeset
   622
        if(is_null($searched)) {
1bc0ec8ed05b add relaunch wp
ymh <ymh.work@gmail.com>
parents: 60
diff changeset
   623
            $searched = $this->getRequest()->request->get('searched');
1bc0ec8ed05b add relaunch wp
ymh <ymh.work@gmail.com>
parents: 60
diff changeset
   624
        }
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
   625
        //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
   626
        $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
   627
        $tags = $ar[0];
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   628
        $num_page = $ar[1];
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   629
        $nb_by_page = $ar[2];
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   630
        $searched = $ar[3];
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   631
        $sort = $ar[4];
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   632
        $reverse_sort = $ar[5];
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   633
        
21
780ef37e63b9 add route parameter
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   634
        return $this->render('WikiTagBundle:WikiTag:TagListTable.html.twig',
112
14653baf4f6b first change for wikipedia and dbpedia lang configuration
cavaliet
parents: 104
diff changeset
   635
            array('tags' => $tags, 
14653baf4f6b first change for wikipedia and dbpedia lang configuration
cavaliet
parents: 104
diff changeset
   636
            		'searched' => $searched, 
14653baf4f6b first change for wikipedia and dbpedia lang configuration
cavaliet
parents: 104
diff changeset
   637
            		'nb_by_page' => $nb_by_page, 
14653baf4f6b first change for wikipedia and dbpedia lang configuration
cavaliet
parents: 104
diff changeset
   638
            		'sort' => $sort, 
14653baf4f6b first change for wikipedia and dbpedia lang configuration
cavaliet
parents: 104
diff changeset
   639
            		'num_page' => $num_page,
14653baf4f6b first change for wikipedia and dbpedia lang configuration
cavaliet
parents: 104
diff changeset
   640
        			'reverse_sort' => $reverse_sort, 
14653baf4f6b first change for wikipedia and dbpedia lang configuration
cavaliet
parents: 104
diff changeset
   641
            		'route_for_documents_by_tag' => $this->container->getParameter("wiki_tag.route_for_documents_by_tag"),
14653baf4f6b first change for wikipedia and dbpedia lang configuration
cavaliet
parents: 104
diff changeset
   642
            		'wikipedia_opensearch_url' => $this->container->getParameter("wiki_tag.url_templates")["wikipedia_opensearch"]));
11
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   643
    }
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   644
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   645
    /**
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   646
     * 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
   647
     */
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   648
    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
   649
    {
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   650
        // 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
   651
        // Searched string
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   652
        if($searched==NULL){
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   653
            $searched = "";
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   654
        }
54
ec51b9f4695f Upgrade column management with possibility to return to the initial columns. Little debug in all tag list.
cavaliet
parents: 53
diff changeset
   655
        $searched = urldecode($searched);
11
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   656
        // Number of tags per page
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   657
        if($nb_by_page==NULL){
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   658
            $nb_by_page = 50;
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   659
        }
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   660
        // Current page number
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   661
        if($num_page==NULL){
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   662
            $num_page = 1;
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   663
        }
9
cc32af725176 first step for tag list and add Pagerfanta for paginator
cavaliet
parents: 8
diff changeset
   664
        // We build the query.
cc32af725176 first step for tag list and add Pagerfanta for paginator
cavaliet
parents: 8
diff changeset
   665
        $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
   666
        $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
   667
        $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
   668
        $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
   669
        $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
   670
        
16
876df98c9208 Debug search with simple quote.
cavaliet
parents: 15
diff changeset
   671
        // We add the search string if necessary
876df98c9208 Debug search with simple quote.
cavaliet
parents: 15
diff changeset
   672
        if($searched!=""){
876df98c9208 Debug search with simple quote.
cavaliet
parents: 15
diff changeset
   673
            // We replace "*" by "%", and doctrine wants ' to be ''.
46
6f643fc1de26 commit changes before update.
cavaliet
parents: 37
diff changeset
   674
            $qb->where($qb->expr()->orx($qb->expr()->like('t.normalizedLabel', "'".str_replace("'", "''", str_replace("*", "%", str_replace("+", " ", $searched)))."'")));
9
cc32af725176 first step for tag list and add Pagerfanta for paginator
cavaliet
parents: 8
diff changeset
   675
        }
16
876df98c9208 Debug search with simple quote.
cavaliet
parents: 15
diff changeset
   676
        //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
   677
        
10
a1234ceba912 add first letter list. It works but searching ' bugs.
cavaliet
parents: 9
diff changeset
   678
        // We add the sorting criteria
11
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   679
        if($sort==NULL){
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   680
            $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
   681
            $reverse_sort = "popa";
9
cc32af725176 first step for tag list and add Pagerfanta for paginator
cavaliet
parents: 8
diff changeset
   682
        }
26
9eab3e86db7d Add sort tags list by number of documents.
cavaliet
parents: 22
diff changeset
   683
        //$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
   684
        switch($sort){
cc32af725176 first step for tag list and add Pagerfanta for paginator
cavaliet
parents: 8
diff changeset
   685
            case "popd":
cc32af725176 first step for tag list and add Pagerfanta for paginator
cavaliet
parents: 8
diff changeset
   686
                $qb->addOrderBy('t.popularity','DESC');
26
9eab3e86db7d Add sort tags list by number of documents.
cavaliet
parents: 22
diff changeset
   687
                $qb->addOrderBy('nb_docs','DESC');
9
cc32af725176 first step for tag list and add Pagerfanta for paginator
cavaliet
parents: 8
diff changeset
   688
                $qb->addOrderBy('t.normalizedLabel','ASC');
cc32af725176 first step for tag list and add Pagerfanta for paginator
cavaliet
parents: 8
diff changeset
   689
                $qb->addOrderBy('t.label','ASC');
cc32af725176 first step for tag list and add Pagerfanta for paginator
cavaliet
parents: 8
diff changeset
   690
                $reverse_sort = "popa";
cc32af725176 first step for tag list and add Pagerfanta for paginator
cavaliet
parents: 8
diff changeset
   691
                break;
cc32af725176 first step for tag list and add Pagerfanta for paginator
cavaliet
parents: 8
diff changeset
   692
            case "popa":
cc32af725176 first step for tag list and add Pagerfanta for paginator
cavaliet
parents: 8
diff changeset
   693
                $qb->addOrderBy('t.popularity','ASC');
26
9eab3e86db7d Add sort tags list by number of documents.
cavaliet
parents: 22
diff changeset
   694
                $qb->addOrderBy('nb_docs','DESC');
9
cc32af725176 first step for tag list and add Pagerfanta for paginator
cavaliet
parents: 8
diff changeset
   695
                $qb->addOrderBy('t.normalizedLabel','ASC');
cc32af725176 first step for tag list and add Pagerfanta for paginator
cavaliet
parents: 8
diff changeset
   696
                $qb->addOrderBy('t.label','ASC');
cc32af725176 first step for tag list and add Pagerfanta for paginator
cavaliet
parents: 8
diff changeset
   697
                $reverse_sort = "popd";
cc32af725176 first step for tag list and add Pagerfanta for paginator
cavaliet
parents: 8
diff changeset
   698
                break;
cc32af725176 first step for tag list and add Pagerfanta for paginator
cavaliet
parents: 8
diff changeset
   699
            case "labd":
cc32af725176 first step for tag list and add Pagerfanta for paginator
cavaliet
parents: 8
diff changeset
   700
                $qb->addOrderBy('t.normalizedLabel','DESC');
cc32af725176 first step for tag list and add Pagerfanta for paginator
cavaliet
parents: 8
diff changeset
   701
                $qb->addOrderBy('t.label','DESC');
cc32af725176 first step for tag list and add Pagerfanta for paginator
cavaliet
parents: 8
diff changeset
   702
                $reverse_sort = "laba";
cc32af725176 first step for tag list and add Pagerfanta for paginator
cavaliet
parents: 8
diff changeset
   703
                break;
cc32af725176 first step for tag list and add Pagerfanta for paginator
cavaliet
parents: 8
diff changeset
   704
            case "laba":
cc32af725176 first step for tag list and add Pagerfanta for paginator
cavaliet
parents: 8
diff changeset
   705
                $qb->addOrderBy('t.normalizedLabel','ASC');
cc32af725176 first step for tag list and add Pagerfanta for paginator
cavaliet
parents: 8
diff changeset
   706
                $qb->addOrderBy('t.label','ASC');
cc32af725176 first step for tag list and add Pagerfanta for paginator
cavaliet
parents: 8
diff changeset
   707
                $reverse_sort = "labd";
52
e804ae133f27 icon images in css, little debug, update document profile configuration
cavaliet
parents: 50
diff changeset
   708
                break;
26
9eab3e86db7d Add sort tags list by number of documents.
cavaliet
parents: 22
diff changeset
   709
            case "nbd":
9eab3e86db7d Add sort tags list by number of documents.
cavaliet
parents: 22
diff changeset
   710
                $qb->addOrderBy('nb_docs','DESC');
9eab3e86db7d Add sort tags list by number of documents.
cavaliet
parents: 22
diff changeset
   711
                $qb->addOrderBy('t.popularity','DESC');
9eab3e86db7d Add sort tags list by number of documents.
cavaliet
parents: 22
diff changeset
   712
                $qb->addOrderBy('t.normalizedLabel','ASC');
9eab3e86db7d Add sort tags list by number of documents.
cavaliet
parents: 22
diff changeset
   713
                $qb->addOrderBy('t.label','ASC');
9eab3e86db7d Add sort tags list by number of documents.
cavaliet
parents: 22
diff changeset
   714
                $reverse_sort = "nba";
9eab3e86db7d Add sort tags list by number of documents.
cavaliet
parents: 22
diff changeset
   715
                break;
9eab3e86db7d Add sort tags list by number of documents.
cavaliet
parents: 22
diff changeset
   716
            case "nba":
9eab3e86db7d Add sort tags list by number of documents.
cavaliet
parents: 22
diff changeset
   717
                $qb->addOrderBy('nb_docs','ASC');
9eab3e86db7d Add sort tags list by number of documents.
cavaliet
parents: 22
diff changeset
   718
                $qb->addOrderBy('t.popularity','DESC');
9eab3e86db7d Add sort tags list by number of documents.
cavaliet
parents: 22
diff changeset
   719
                $qb->addOrderBy('t.normalizedLabel','ASC');
9eab3e86db7d Add sort tags list by number of documents.
cavaliet
parents: 22
diff changeset
   720
                $qb->addOrderBy('t.label','ASC');
9eab3e86db7d Add sort tags list by number of documents.
cavaliet
parents: 22
diff changeset
   721
                $reverse_sort = "nbd";
9
cc32af725176 first step for tag list and add Pagerfanta for paginator
cavaliet
parents: 8
diff changeset
   722
                break;
cc32af725176 first step for tag list and add Pagerfanta for paginator
cavaliet
parents: 8
diff changeset
   723
        }
cc32af725176 first step for tag list and add Pagerfanta for paginator
cavaliet
parents: 8
diff changeset
   724
        
cc32af725176 first step for tag list and add Pagerfanta for paginator
cavaliet
parents: 8
diff changeset
   725
        // We paginate
cc32af725176 first step for tag list and add Pagerfanta for paginator
cavaliet
parents: 8
diff changeset
   726
        $adapter = new DoctrineORMAdapter($qb);
cc32af725176 first step for tag list and add Pagerfanta for paginator
cavaliet
parents: 8
diff changeset
   727
        $pagerfanta = new Pagerfanta($adapter);
cc32af725176 first step for tag list and add Pagerfanta for paginator
cavaliet
parents: 8
diff changeset
   728
        $pagerfanta->setMaxPerPage($nb_by_page); // 10 by default
cc32af725176 first step for tag list and add Pagerfanta for paginator
cavaliet
parents: 8
diff changeset
   729
        $pagerfanta->setCurrentPage($num_page); // 1 by default
cc32af725176 first step for tag list and add Pagerfanta for paginator
cavaliet
parents: 8
diff changeset
   730
        $nb_total = $pagerfanta->getNbResults();
cc32af725176 first step for tag list and add Pagerfanta for paginator
cavaliet
parents: 8
diff changeset
   731
        $tags = $pagerfanta->getCurrentPageResults();
cc32af725176 first step for tag list and add Pagerfanta for paginator
cavaliet
parents: 8
diff changeset
   732
        $pagerfanta->haveToPaginate(); // whether the number of results if higher than the max per page
15
ab71cf8bff55 ChangesetTagBranchUserDateSummary
cavaliet
parents: 14
diff changeset
   733
        
11
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 10
diff changeset
   734
        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
   735
    }
2
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   736
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   737
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   738
}