# HG changeset patch # User ymh # Date 1318852310 -7200 # Node ID 976d922e52f08664d7a710878d117933fed01ee4 # Parent 13f43f53d0bafefe81871b01764b0f8a8a9d179c link document lifecycle diff -r 13f43f53d0ba -r 976d922e52f0 Entity/DocumentRepository.php --- 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 diff -r 13f43f53d0ba -r 976d922e52f0 Model/Document.php --- 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; + } } diff -r 13f43f53d0ba -r 976d922e52f0 Model/DocumentInterface.php --- 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(); diff -r 13f43f53d0ba -r 976d922e52f0 Resources/config/doctrine/Document.orm.yml --- 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: { } diff -r 13f43f53d0ba -r 976d922e52f0 Resources/config/services.yml --- 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%]