Entity/DocumentRepository.php
changeset 3 976d922e52f0
parent 2 13f43f53d0ba
child 5 45378793512a
--- a/Entity/DocumentRepository.php	Sun Oct 16 14:50:48 2011 +0200
+++ b/Entity/DocumentRepository.php	Mon Oct 17 13:51:50 2011 +0200
@@ -3,6 +3,7 @@
 namespace IRI\Bundle\WikiTagBundle\Entity;
 
 use Doctrine\ORM\EntityRepository;
+use IRI\Bundle\WikiTagBundle\Model\DocumentInterface;
 
 /**
  * DocumentRepository
@@ -12,4 +13,32 @@
  */
 class DocumentRepository extends EntityRepository
 {
+    
+    function writeDocument(DocumentInterface $document)
+    {
+        # get document from id
+        $baseDocument = $this->findOneBy(array("externalId" => $document->getId()));
+    
+        if(is_null($baseDocument))
+        {
+            $baseDocument = new Document();
+            $baseDocument->setExternalId($document->getId());
+        }
+        $baseDocument->setDescription($document->getDescription());
+        $baseDocument->setTitle($document->getTitle());
+        
+        $this->getEntityManager()->persist($baseDocument);
+        $this->getEntityManager()->flush();
+        return $baseDocument;
+    
+    }
+    
+    function removeDocument(DocumentInterface $document)
+    {
+        $baseDocument = $this->findOneBy(array("externalId" => $document->getId()));
+        if(!is_null($baseDocument)) {
+            $this->getEntityManager()->remove($baseDocument);
+        }
+    }
+    
 }
\ No newline at end of file