diff -r e854d8cb376c -r 186c4121c7b3 Services/DocumentService.php --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Services/DocumentService.php Tue Dec 06 14:53:12 2011 +0100 @@ -0,0 +1,81 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ +namespace IRI\Bundle\WikiTagBundle\Services; + +use Symfony\Component\DependencyInjection\ContainerAware; +use Symfony\Component\DependencyInjection\ContainerInterface; + +class DocumentService extends ContainerAware +{ + /** + * Get the container associated with this service. + * @return ContainerInterface + */ + public function getContainer() + { + return $this->container; + } + + /** + * Public constructor with container as parameter for contruct injection. + * @param ContainerInterface $container + */ + public function __construct(ContainerInterface $container) + { + $this->setContainer($container); + } + + private $doctrine; + + public function getDoctrine() + { + if(is_null($this->doctrine)) + { + $this->doctrine = $this->getContainer()->get('doctrine'); + } + return $this->doctrine; + } + + + /** + * Copy the list of tags of one document to another. + * + * @param mixed $id_doc_src the source document id + * @param mixed $id_doc_tgt the target document id + */ + public function copyTags($id_doc_src, $id_doc_tgt) + { + + $doctrine = $this->getDoctrine(); + $em = $doctrine->getEntityManager(); + + $doc_rep = $em->getRepository("WikiTagBundle:Document"); + + $src_doc = $doc_rep->findOneByExternalId($id_doc_src); + if(is_null($src_doc)) + { + throw new Exception("cloneTags: no source doc"); + } + + $tgt_doc = $doc_rep->findOneByExternalId($id_doc_tgt); + if(is_null($tgt_doc)) + { + throw new Exception("cloneTags: no target doc"); + } + + + $doc_rep->copyTags($src_doc, $tgt_doc); + + $em->flush(); + + } + + +} \ No newline at end of file