|
2
|
1 |
<?php |
|
|
2 |
|
|
|
3 |
namespace IRI\Bundle\WikiTagBundle\Entity; |
|
|
4 |
|
|
|
5 |
use Doctrine\ORM\EntityRepository; |
|
3
|
6 |
use IRI\Bundle\WikiTagBundle\Model\DocumentInterface; |
|
2
|
7 |
|
|
|
8 |
/** |
|
|
9 |
* DocumentRepository |
|
|
10 |
* |
|
|
11 |
* This class was generated by the Doctrine ORM. Add your own custom |
|
|
12 |
* repository methods below. |
|
|
13 |
*/ |
|
|
14 |
class DocumentRepository extends EntityRepository |
|
|
15 |
{ |
|
3
|
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 |
|
|
2
|
44 |
} |