Entity/DocumentRepository.php
changeset 3 976d922e52f0
parent 2 13f43f53d0ba
child 5 45378793512a
equal deleted inserted replaced
2:13f43f53d0ba 3:976d922e52f0
     1 <?php
     1 <?php
     2 
     2 
     3 namespace IRI\Bundle\WikiTagBundle\Entity;
     3 namespace IRI\Bundle\WikiTagBundle\Entity;
     4 
     4 
     5 use Doctrine\ORM\EntityRepository;
     5 use Doctrine\ORM\EntityRepository;
       
     6 use IRI\Bundle\WikiTagBundle\Model\DocumentInterface;
     6 
     7 
     7 /**
     8 /**
     8  * DocumentRepository
     9  * DocumentRepository
     9  *
    10  *
    10  * This class was generated by the Doctrine ORM. Add your own custom
    11  * This class was generated by the Doctrine ORM. Add your own custom
    11  * repository methods below.
    12  * repository methods below.
    12  */
    13  */
    13 class DocumentRepository extends EntityRepository
    14 class DocumentRepository extends EntityRepository
    14 {
    15 {
       
    16     
       
    17     function writeDocument(DocumentInterface $document)
       
    18     {
       
    19         # get document from id
       
    20         $baseDocument = $this->findOneBy(array("externalId" => $document->getId()));
       
    21     
       
    22         if(is_null($baseDocument))
       
    23         {
       
    24             $baseDocument = new Document();
       
    25             $baseDocument->setExternalId($document->getId());
       
    26         }
       
    27         $baseDocument->setDescription($document->getDescription());
       
    28         $baseDocument->setTitle($document->getTitle());
       
    29         
       
    30         $this->getEntityManager()->persist($baseDocument);
       
    31         $this->getEntityManager()->flush();
       
    32         return $baseDocument;
       
    33     
       
    34     }
       
    35     
       
    36     function removeDocument(DocumentInterface $document)
       
    37     {
       
    38         $baseDocument = $this->findOneBy(array("externalId" => $document->getId()));
       
    39         if(!is_null($baseDocument)) {
       
    40             $this->getEntityManager()->remove($baseDocument);
       
    41         }
       
    42     }
       
    43     
    15 }
    44 }