link document lifecycle
authorymh <ymh.work@gmail.com>
Mon, 17 Oct 2011 13:51:50 +0200
changeset 3 976d922e52f0
parent 2 13f43f53d0ba
child 4 e63ac93fdbde
link document lifecycle
Entity/DocumentRepository.php
Model/Document.php
Model/DocumentInterface.php
Resources/config/doctrine/Document.orm.yml
Resources/config/services.yml
--- 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
--- a/Model/Document.php	Sun Oct 16 14:50:48 2011 +0200
+++ b/Model/Document.php	Mon Oct 17 13:51:50 2011 +0200
@@ -10,7 +10,7 @@
 
 namespace IRI\Bundle\WikiTagBundle\Model;
 
-abstract class Document implements DocumentInterface {
+abstract class Document implements BaseDocumentInterface {
     
     /**
     * @var integer $id
@@ -30,7 +30,12 @@
     /**
      * @var boolean $manualOrder
      */
-    protected $manualOrder;
+    protected $manualOrder = false;
+    
+    /**
+     * @var string $externalId
+     */
+    protected $externalId;
     
     
     /**
@@ -103,5 +108,22 @@
         return $this->manualOrder;
     }
     
+    /**
+     * TODO: (non-PHPdoc)
+     * @see IRI\Bundle\WikiTagBundle\Model.BaseDocumentInterface::setExternalId()
+     */
+    function setExternalId($externalId)
+    {
+        $this->externalId = $externalId;
+    }
+    
+    /**
+     * TODO: (non-PHPdoc)
+     * @see IRI\Bundle\WikiTagBundle\Model.BaseDocumentInterface::getExternalId()
+     */
+    function getExternalId()
+    {
+        return $this->externalId;
+    }
     
 }
--- a/Model/DocumentInterface.php	Sun Oct 16 14:50:48 2011 +0200
+++ b/Model/DocumentInterface.php	Mon Oct 17 13:51:50 2011 +0200
@@ -47,20 +47,6 @@
      * @return text
      */
     function getDescription();
-
-    /**
-     * Set manualOrder
-     *
-     * @param boolean $manualOrder
-     */
-    function setManualOrder($manualOrder);
-    
-    /**
-     * Get manualOrder
-     *
-     * @return boolean
-     */
-    function getManualOrder();
     
     
     
--- a/Resources/config/doctrine/Document.orm.yml	Sun Oct 16 14:50:48 2011 +0200
+++ b/Resources/config/doctrine/Document.orm.yml	Mon Oct 17 13:51:50 2011 +0200
@@ -16,4 +16,7 @@
     manualOrder:
       type: boolean
       column: manual_order
+    externalId:
+      type: string
+      length: '1024'
   lifecycleCallbacks: {  }
--- a/Resources/config/services.yml	Sun Oct 16 14:50:48 2011 +0200
+++ b/Resources/config/services.yml	Mon Oct 17 13:51:50 2011 +0200
@@ -1,7 +1,13 @@
 parameters:
 #    wiki_tag.example.class: IRI\Bundle\WikiTagBundle\Example
+    wiki_tag.document_listener.class: IRI\Bundle\WikiTagBundle\Entity\DocumentListener
 
 services:
+    wiki_tag.document_listener:
+        class: %wiki_tag.document_listener.class%
+        arguments: [@service_container]
+        tags:
+            - { name: doctrine.event_subscriber, connection: default }
 #    wiki_tag.example:
 #        class: %wiki_tag.example.class%
 #        arguments: [@service_id, "plain_value", %parameter%]