Services/DocumentService.php
author ymh <ymh.work@gmail.com>
Mon, 19 Dec 2011 17:50:04 +0100
changeset 65 ba6b8e38d90e
parent 63 774ba82dca59
child 67 989d9e117586
permissions -rw-r--r--
Correct event mamangement in hdabo_sf
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
57
186c4121c7b3 add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff changeset
     1
<?php
186c4121c7b3 add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff changeset
     2
/*
186c4121c7b3 add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff changeset
     3
 * This file is part of the WikiTagBundle package.
186c4121c7b3 add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff changeset
     4
 *
186c4121c7b3 add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff changeset
     5
 * (c) IRI <http://www.iri.centrepompidou.fr/>
186c4121c7b3 add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff changeset
     6
 *
186c4121c7b3 add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff changeset
     7
 * For the full copyright and license information, please view the LICENSE
186c4121c7b3 add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff changeset
     8
 * file that was distributed with this source code.
186c4121c7b3 add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff changeset
     9
 */
186c4121c7b3 add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff changeset
    10
namespace IRI\Bundle\WikiTagBundle\Services;
186c4121c7b3 add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff changeset
    11
 
63
774ba82dca59 add tests and fixtures
ymh <ymh.work@gmail.com>
parents: 57
diff changeset
    12
use IRI\Bundle\WikiTagBundle\Entity\DocumentTag;
57
186c4121c7b3 add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff changeset
    13
use Symfony\Component\DependencyInjection\ContainerAware;
186c4121c7b3 add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff changeset
    14
use Symfony\Component\DependencyInjection\ContainerInterface;
63
774ba82dca59 add tests and fixtures
ymh <ymh.work@gmail.com>
parents: 57
diff changeset
    15
use IRI\Bundle\WikiTagBundle\Utils\WikiTagUtils;
57
186c4121c7b3 add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff changeset
    16
186c4121c7b3 add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff changeset
    17
class DocumentService extends ContainerAware
186c4121c7b3 add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff changeset
    18
{
186c4121c7b3 add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff changeset
    19
    /**
186c4121c7b3 add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff changeset
    20
     * Get the container associated with this service.
186c4121c7b3 add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff changeset
    21
     * @return ContainerInterface
186c4121c7b3 add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff changeset
    22
     */
186c4121c7b3 add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff changeset
    23
    public function getContainer()
186c4121c7b3 add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff changeset
    24
    {
186c4121c7b3 add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff changeset
    25
        return $this->container;
186c4121c7b3 add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff changeset
    26
    }
186c4121c7b3 add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff changeset
    27
    
186c4121c7b3 add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff changeset
    28
    /**
186c4121c7b3 add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff changeset
    29
     * Public constructor with container as parameter for contruct injection.
186c4121c7b3 add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff changeset
    30
     * @param ContainerInterface $container
186c4121c7b3 add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff changeset
    31
     */
186c4121c7b3 add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff changeset
    32
    public function __construct(ContainerInterface $container)
186c4121c7b3 add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff changeset
    33
    {
186c4121c7b3 add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff changeset
    34
        $this->setContainer($container);
186c4121c7b3 add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff changeset
    35
    }
186c4121c7b3 add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff changeset
    36
    
186c4121c7b3 add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff changeset
    37
    private $doctrine;
186c4121c7b3 add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff changeset
    38
    
186c4121c7b3 add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff changeset
    39
    public function getDoctrine()
186c4121c7b3 add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff changeset
    40
    {
186c4121c7b3 add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff changeset
    41
        if(is_null($this->doctrine))
186c4121c7b3 add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff changeset
    42
        {
186c4121c7b3 add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff changeset
    43
            $this->doctrine = $this->getContainer()->get('doctrine');
186c4121c7b3 add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff changeset
    44
        }
186c4121c7b3 add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff changeset
    45
        return $this->doctrine;
186c4121c7b3 add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff changeset
    46
    }
186c4121c7b3 add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff changeset
    47
    
186c4121c7b3 add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff changeset
    48
186c4121c7b3 add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff changeset
    49
    /**
186c4121c7b3 add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff changeset
    50
     * Copy the list of tags of one document to another.
63
774ba82dca59 add tests and fixtures
ymh <ymh.work@gmail.com>
parents: 57
diff changeset
    51
     * The ids are the ids of the "host" document.
57
186c4121c7b3 add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff changeset
    52
	 *
186c4121c7b3 add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff changeset
    53
     * @param mixed $id_doc_src the source document id
186c4121c7b3 add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff changeset
    54
     * @param mixed $id_doc_tgt the target document id
186c4121c7b3 add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff changeset
    55
     */
186c4121c7b3 add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff changeset
    56
    public function copyTags($id_doc_src, $id_doc_tgt)
186c4121c7b3 add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff changeset
    57
    {
186c4121c7b3 add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff changeset
    58
        
186c4121c7b3 add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff changeset
    59
        $doctrine = $this->getDoctrine();
186c4121c7b3 add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff changeset
    60
        $em = $doctrine->getEntityManager();
186c4121c7b3 add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff changeset
    61
        
186c4121c7b3 add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff changeset
    62
        $doc_rep = $em->getRepository("WikiTagBundle:Document");
186c4121c7b3 add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff changeset
    63
        
186c4121c7b3 add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff changeset
    64
        $src_doc = $doc_rep->findOneByExternalId($id_doc_src);
186c4121c7b3 add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff changeset
    65
        if(is_null($src_doc))
186c4121c7b3 add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff changeset
    66
        {
186c4121c7b3 add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff changeset
    67
            throw new Exception("cloneTags: no source doc");
186c4121c7b3 add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff changeset
    68
        }
186c4121c7b3 add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff changeset
    69
        
186c4121c7b3 add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff changeset
    70
        $tgt_doc = $doc_rep->findOneByExternalId($id_doc_tgt);
186c4121c7b3 add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff changeset
    71
        if(is_null($tgt_doc))
186c4121c7b3 add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff changeset
    72
        {
186c4121c7b3 add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff changeset
    73
            throw new Exception("cloneTags: no target doc");
186c4121c7b3 add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff changeset
    74
        }
186c4121c7b3 add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff changeset
    75
        
186c4121c7b3 add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff changeset
    76
        
186c4121c7b3 add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff changeset
    77
        $doc_rep->copyTags($src_doc, $tgt_doc);
186c4121c7b3 add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff changeset
    78
        
186c4121c7b3 add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff changeset
    79
        $em->flush();
186c4121c7b3 add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff changeset
    80
        
186c4121c7b3 add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff changeset
    81
    }
186c4121c7b3 add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff changeset
    82
    
63
774ba82dca59 add tests and fixtures
ymh <ymh.work@gmail.com>
parents: 57
diff changeset
    83
    /**
774ba82dca59 add tests and fixtures
ymh <ymh.work@gmail.com>
parents: 57
diff changeset
    84
     *
774ba82dca59 add tests and fixtures
ymh <ymh.work@gmail.com>
parents: 57
diff changeset
    85
     * Add a new tag to a "host" document.
774ba82dca59 add tests and fixtures
ymh <ymh.work@gmail.com>
parents: 57
diff changeset
    86
     * If the label already exists, an exception is raised.
774ba82dca59 add tests and fixtures
ymh <ymh.work@gmail.com>
parents: 57
diff changeset
    87
     *
65
ba6b8e38d90e Correct event mamangement in hdabo_sf
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
    88
     * @param mixed $doc
63
774ba82dca59 add tests and fixtures
ymh <ymh.work@gmail.com>
parents: 57
diff changeset
    89
     * @param string|array $tag_label : the label of the new tag
774ba82dca59 add tests and fixtures
ymh <ymh.work@gmail.com>
parents: 57
diff changeset
    90
     */
65
ba6b8e38d90e Correct event mamangement in hdabo_sf
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
    91
    public function addTags($doc, $tag_labels)
63
774ba82dca59 add tests and fixtures
ymh <ymh.work@gmail.com>
parents: 57
diff changeset
    92
    {
774ba82dca59 add tests and fixtures
ymh <ymh.work@gmail.com>
parents: 57
diff changeset
    93
        // We get the DocumentTags
774ba82dca59 add tests and fixtures
ymh <ymh.work@gmail.com>
parents: 57
diff changeset
    94
        $em = $this->getDoctrine()->getEntityManager();
65
ba6b8e38d90e Correct event mamangement in hdabo_sf
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
    95
ba6b8e38d90e Correct event mamangement in hdabo_sf
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
    96
        $class = $this->getContainer()->getParameter("wiki_tag.document_class");
63
774ba82dca59 add tests and fixtures
ymh <ymh.work@gmail.com>
parents: 57
diff changeset
    97
        
65
ba6b8e38d90e Correct event mamangement in hdabo_sf
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
    98
        if(! is_a($doc,"\IRI\Bundle\WikiTagBundle\Model\DocumentInterface")) {
ba6b8e38d90e Correct event mamangement in hdabo_sf
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
    99
            if(is_a($doc, $class)) {
ba6b8e38d90e Correct event mamangement in hdabo_sf
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
   100
                $doc_id = $doc->getId();
ba6b8e38d90e Correct event mamangement in hdabo_sf
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
   101
            }
ba6b8e38d90e Correct event mamangement in hdabo_sf
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
   102
            else {
ba6b8e38d90e Correct event mamangement in hdabo_sf
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
   103
                $doc_id = $doc;
ba6b8e38d90e Correct event mamangement in hdabo_sf
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
   104
            }
ba6b8e38d90e Correct event mamangement in hdabo_sf
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
   105
            $doc = $this->getDoctrine()->getRepository('WikiTagBundle:Document')->findOneByExternalId($doc_id);
ba6b8e38d90e Correct event mamangement in hdabo_sf
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
   106
        }
63
774ba82dca59 add tests and fixtures
ymh <ymh.work@gmail.com>
parents: 57
diff changeset
   107
        
774ba82dca59 add tests and fixtures
ymh <ymh.work@gmail.com>
parents: 57
diff changeset
   108
        
774ba82dca59 add tests and fixtures
ymh <ymh.work@gmail.com>
parents: 57
diff changeset
   109
        if(!is_array($tag_labels)) {
774ba82dca59 add tests and fixtures
ymh <ymh.work@gmail.com>
parents: 57
diff changeset
   110
            $tag_labels = array($tag_labels);
774ba82dca59 add tests and fixtures
ymh <ymh.work@gmail.com>
parents: 57
diff changeset
   111
        }
774ba82dca59 add tests and fixtures
ymh <ymh.work@gmail.com>
parents: 57
diff changeset
   112
        
774ba82dca59 add tests and fixtures
ymh <ymh.work@gmail.com>
parents: 57
diff changeset
   113
        foreach ($tag_labels as $tag_label) {
774ba82dca59 add tests and fixtures
ymh <ymh.work@gmail.com>
parents: 57
diff changeset
   114
        
774ba82dca59 add tests and fixtures
ymh <ymh.work@gmail.com>
parents: 57
diff changeset
   115
            $normalized_tag_label = WikiTagUtils::normalizeTag($tag_label);
774ba82dca59 add tests and fixtures
ymh <ymh.work@gmail.com>
parents: 57
diff changeset
   116
            
774ba82dca59 add tests and fixtures
ymh <ymh.work@gmail.com>
parents: 57
diff changeset
   117
            $query = $em->createQuery("SELECT COUNT(dt.id) FROM WikiTagBundle:DocumentTag dt JOIN dt.tag t WHERE dt.document = :id_doc AND t.normalizedLabel = :label");
65
ba6b8e38d90e Correct event mamangement in hdabo_sf
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
   118
            $query->setParameters(array("id_doc"=>$doc, "label"=>$normalized_tag_label));
63
774ba82dca59 add tests and fixtures
ymh <ymh.work@gmail.com>
parents: 57
diff changeset
   119
            
774ba82dca59 add tests and fixtures
ymh <ymh.work@gmail.com>
parents: 57
diff changeset
   120
            $nb_tags = $query->getSingleScalarResult();
774ba82dca59 add tests and fixtures
ymh <ymh.work@gmail.com>
parents: 57
diff changeset
   121
            
774ba82dca59 add tests and fixtures
ymh <ymh.work@gmail.com>
parents: 57
diff changeset
   122
            // If the label was found, we sent a bad request
774ba82dca59 add tests and fixtures
ymh <ymh.work@gmail.com>
parents: 57
diff changeset
   123
            if($nb_tags > 0){
774ba82dca59 add tests and fixtures
ymh <ymh.work@gmail.com>
parents: 57
diff changeset
   124
                throw new WikiTagServiceException(sprintf("Le tag %s existe déjà pour cette fiche.", $tag_label), 400, null, "duplicate_tag");
774ba82dca59 add tests and fixtures
ymh <ymh.work@gmail.com>
parents: 57
diff changeset
   125
            }
774ba82dca59 add tests and fixtures
ymh <ymh.work@gmail.com>
parents: 57
diff changeset
   126
            // returns array($tag, $revision_id, $created)
774ba82dca59 add tests and fixtures
ymh <ymh.work@gmail.com>
parents: 57
diff changeset
   127
            try {
774ba82dca59 add tests and fixtures
ymh <ymh.work@gmail.com>
parents: 57
diff changeset
   128
                $ar = $this->getDoctrine()->getRepository('WikiTagBundle:Tag')->getOrCreateTag($tag_label);
774ba82dca59 add tests and fixtures
ymh <ymh.work@gmail.com>
parents: 57
diff changeset
   129
            }
774ba82dca59 add tests and fixtures
ymh <ymh.work@gmail.com>
parents: 57
diff changeset
   130
            catch (\Exception $e){
774ba82dca59 add tests and fixtures
ymh <ymh.work@gmail.com>
parents: 57
diff changeset
   131
                throw new WikiTagServiceException($e->getMessage(), 500 , $e, "wikipedia_request_failed");
774ba82dca59 add tests and fixtures
ymh <ymh.work@gmail.com>
parents: 57
diff changeset
   132
            }
774ba82dca59 add tests and fixtures
ymh <ymh.work@gmail.com>
parents: 57
diff changeset
   133
            
774ba82dca59 add tests and fixtures
ymh <ymh.work@gmail.com>
parents: 57
diff changeset
   134
            $tag = $ar[0];
774ba82dca59 add tests and fixtures
ymh <ymh.work@gmail.com>
parents: 57
diff changeset
   135
            $revision_id = $ar[1];
774ba82dca59 add tests and fixtures
ymh <ymh.work@gmail.com>
parents: 57
diff changeset
   136
            $created = $ar[2];
774ba82dca59 add tests and fixtures
ymh <ymh.work@gmail.com>
parents: 57
diff changeset
   137
            
65
ba6b8e38d90e Correct event mamangement in hdabo_sf
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
   138
            if(!$created) {
ba6b8e38d90e Correct event mamangement in hdabo_sf
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
   139
                $query = $em->createQuery("SELECT COUNT(dt.id) FROM WikiTagBundle:DocumentTag dt WHERE dt.document = :id_doc AND dt.tag = :tag");
ba6b8e38d90e Correct event mamangement in hdabo_sf
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
   140
                $query->setParameters(array("id_doc"=>$doc, "tag"=>$tag));
ba6b8e38d90e Correct event mamangement in hdabo_sf
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
   141
                $nb_tags = $query->getSingleScalarResult();
ba6b8e38d90e Correct event mamangement in hdabo_sf
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
   142
            }
ba6b8e38d90e Correct event mamangement in hdabo_sf
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
   143
                        
ba6b8e38d90e Correct event mamangement in hdabo_sf
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
   144
            if($created || $nb_tags==0){
ba6b8e38d90e Correct event mamangement in hdabo_sf
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
   145
                $new_order_ar = $this->getDoctrine()->getRepository('WikiTagBundle:DocumentTag')->getMaxOrder($doc);
63
774ba82dca59 add tests and fixtures
ymh <ymh.work@gmail.com>
parents: 57
diff changeset
   146
                // The result is a double array. And reset(reset($newOrderAr)) is not allowed. And a string is returned.
774ba82dca59 add tests and fixtures
ymh <ymh.work@gmail.com>
parents: 57
diff changeset
   147
                $a1 = reset($new_order_ar);
774ba82dca59 add tests and fixtures
ymh <ymh.work@gmail.com>
parents: 57
diff changeset
   148
                $new_order = intval(reset($a1)) + 1;
774ba82dca59 add tests and fixtures
ymh <ymh.work@gmail.com>
parents: 57
diff changeset
   149
                $new_DT = new DocumentTag();
65
ba6b8e38d90e Correct event mamangement in hdabo_sf
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
   150
                $new_DT->setDocument($doc);
63
774ba82dca59 add tests and fixtures
ymh <ymh.work@gmail.com>
parents: 57
diff changeset
   151
                $new_DT->setTag($tag);
774ba82dca59 add tests and fixtures
ymh <ymh.work@gmail.com>
parents: 57
diff changeset
   152
                $new_DT->setOriginalOrder($new_order);
774ba82dca59 add tests and fixtures
ymh <ymh.work@gmail.com>
parents: 57
diff changeset
   153
                $new_DT->setTagOrder($new_order);
774ba82dca59 add tests and fixtures
ymh <ymh.work@gmail.com>
parents: 57
diff changeset
   154
                $new_DT->setWikipediaRevisionId($revision_id);
774ba82dca59 add tests and fixtures
ymh <ymh.work@gmail.com>
parents: 57
diff changeset
   155
                $em->persist($new_DT);
774ba82dca59 add tests and fixtures
ymh <ymh.work@gmail.com>
parents: 57
diff changeset
   156
            }
774ba82dca59 add tests and fixtures
ymh <ymh.work@gmail.com>
parents: 57
diff changeset
   157
        }
65
ba6b8e38d90e Correct event mamangement in hdabo_sf
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
   158
                
63
774ba82dca59 add tests and fixtures
ymh <ymh.work@gmail.com>
parents: 57
diff changeset
   159
    }
774ba82dca59 add tests and fixtures
ymh <ymh.work@gmail.com>
parents: 57
diff changeset
   160
    
774ba82dca59 add tests and fixtures
ymh <ymh.work@gmail.com>
parents: 57
diff changeset
   161
    public function getTagLabels($id_doc)
774ba82dca59 add tests and fixtures
ymh <ymh.work@gmail.com>
parents: 57
diff changeset
   162
    {
774ba82dca59 add tests and fixtures
ymh <ymh.work@gmail.com>
parents: 57
diff changeset
   163
        $rep = $this->getDoctrine()->getRepository('WikiTagBundle:Document');
774ba82dca59 add tests and fixtures
ymh <ymh.work@gmail.com>
parents: 57
diff changeset
   164
        $doc = $rep->findOneByExternalId($id_doc);
774ba82dca59 add tests and fixtures
ymh <ymh.work@gmail.com>
parents: 57
diff changeset
   165
        
774ba82dca59 add tests and fixtures
ymh <ymh.work@gmail.com>
parents: 57
diff changeset
   166
        if(is_null($doc)) {
774ba82dca59 add tests and fixtures
ymh <ymh.work@gmail.com>
parents: 57
diff changeset
   167
            throw new WikiTagServiceException("Unknown document id");
774ba82dca59 add tests and fixtures
ymh <ymh.work@gmail.com>
parents: 57
diff changeset
   168
        }
774ba82dca59 add tests and fixtures
ymh <ymh.work@gmail.com>
parents: 57
diff changeset
   169
        
774ba82dca59 add tests and fixtures
ymh <ymh.work@gmail.com>
parents: 57
diff changeset
   170
        return $rep->getTagsStr($doc);
774ba82dca59 add tests and fixtures
ymh <ymh.work@gmail.com>
parents: 57
diff changeset
   171
774ba82dca59 add tests and fixtures
ymh <ymh.work@gmail.com>
parents: 57
diff changeset
   172
    }
774ba82dca59 add tests and fixtures
ymh <ymh.work@gmail.com>
parents: 57
diff changeset
   173
    
57
186c4121c7b3 add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff changeset
   174
        
186c4121c7b3 add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff changeset
   175
}