| author | cavaliet |
| Thu, 20 Oct 2011 18:35:33 +0200 | |
| changeset 8 | 7d2fb5d7c9ff |
| parent 5 | 45378793512a |
| child 18 | 6f16b9fd6a17 |
| permissions | -rwxr-xr-x |
| 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 |
{ |
|
|
5
45378793512a
Correct tag insert + external id on doc
ymh <ymh.work@gmail.com>
parents:
3
diff
changeset
|
16 |
function findOneByExternalId($external_id) |
|
45378793512a
Correct tag insert + external id on doc
ymh <ymh.work@gmail.com>
parents:
3
diff
changeset
|
17 |
{ |
|
45378793512a
Correct tag insert + external id on doc
ymh <ymh.work@gmail.com>
parents:
3
diff
changeset
|
18 |
return $this->findOneBy(array("externalId" => strval($external_id))); |
|
45378793512a
Correct tag insert + external id on doc
ymh <ymh.work@gmail.com>
parents:
3
diff
changeset
|
19 |
} |
| 3 | 20 |
|
21 |
function writeDocument(DocumentInterface $document) |
|
22 |
{ |
|
23 |
# get document from id |
|
|
5
45378793512a
Correct tag insert + external id on doc
ymh <ymh.work@gmail.com>
parents:
3
diff
changeset
|
24 |
$baseDocument = $this->findOneByExternalId($document->getId()); |
| 3 | 25 |
|
26 |
if(is_null($baseDocument)) |
|
27 |
{ |
|
28 |
$baseDocument = new Document(); |
|
|
5
45378793512a
Correct tag insert + external id on doc
ymh <ymh.work@gmail.com>
parents:
3
diff
changeset
|
29 |
$baseDocument->setExternalId(strval($document->getId())); |
| 3 | 30 |
} |
31 |
$baseDocument->setDescription($document->getDescription()); |
|
32 |
$baseDocument->setTitle($document->getTitle()); |
|
33 |
||
34 |
$this->getEntityManager()->persist($baseDocument); |
|
35 |
$this->getEntityManager()->flush(); |
|
36 |
return $baseDocument; |
|
37 |
||
38 |
} |
|
39 |
||
40 |
function removeDocument(DocumentInterface $document) |
|
41 |
{ |
|
|
5
45378793512a
Correct tag insert + external id on doc
ymh <ymh.work@gmail.com>
parents:
3
diff
changeset
|
42 |
$baseDocument = $this->findOneByExternalId($document->getId()); |
|
45378793512a
Correct tag insert + external id on doc
ymh <ymh.work@gmail.com>
parents:
3
diff
changeset
|
43 |
if(!is_null($baseDocument)) |
|
45378793512a
Correct tag insert + external id on doc
ymh <ymh.work@gmail.com>
parents:
3
diff
changeset
|
44 |
{ |
| 3 | 45 |
$this->getEntityManager()->remove($baseDocument); |
46 |
} |
|
47 |
} |
|
48 |
||
| 2 | 49 |
} |