|
58
|
1 |
<?php |
|
|
2 |
/* |
|
|
3 |
* This file is part of the WikiTagBundle package. |
|
|
4 |
* |
|
|
5 |
* (c) IRI <http://www.iri.centrepompidou.fr/> |
|
|
6 |
* |
|
|
7 |
* For the full copyright and license information, please view the LICENSE |
|
|
8 |
* file that was distributed with this source code. |
|
|
9 |
*/ |
|
|
10 |
namespace Company\BaseBundle\DataFixures\ORM; |
|
|
11 |
|
|
|
12 |
use Symfony\Component\DependencyInjection\ContainerInterface; |
|
|
13 |
use Symfony\Component\DependencyInjection\ContainerAwareInterface; |
|
|
14 |
use Doctrine\Common\DataFixtures\FixtureInterface; |
|
|
15 |
use Company\BaseBundle\Entity\Document; |
|
|
16 |
|
|
|
17 |
class LoadDocumentData implements FixtureInterface, ContainerAwareInterface |
|
|
18 |
{ |
|
|
19 |
private $container; |
|
|
20 |
|
|
|
21 |
public function setContainer(ContainerInterface $container = null) |
|
|
22 |
{ |
|
|
23 |
$this->container = $container; |
|
|
24 |
} |
|
|
25 |
|
|
|
26 |
public function load($manager) { |
|
|
27 |
|
|
|
28 |
# create new document |
|
|
29 |
|
|
|
30 |
$doc_def_list = array( |
|
|
31 |
array('title'=>'Title 1', 'description'=>'Description 1', 'tags' => array('tag1', 'tag2', 'tag3', 'tag4')), |
|
|
32 |
array('title'=>'Title 2', 'description'=>'Description 2', 'tags' => array('tag2', 'tag3', 'tag4')), |
|
|
33 |
array('title'=>'Title 3', 'description'=>'Description 3', 'tags' => array('tag3', 'tag4')), |
|
|
34 |
array('title'=>'Title 4', 'description'=>'Description 4', 'tags' => array()), |
|
|
35 |
); |
|
|
36 |
|
|
|
37 |
foreach ($doc_def_list as $doc_def) { |
|
|
38 |
|
|
|
39 |
$newdoc = new Document(); |
|
|
40 |
$newdoc->setTitle($doc_def['title']); |
|
|
41 |
$newdoc->setDescription($doc_def['description']); |
|
|
42 |
|
|
|
43 |
$manager->persist($newdoc); |
|
|
44 |
|
|
|
45 |
$manager->flush(); |
|
|
46 |
|
|
|
47 |
$this->container->get('wiki_tag.document')->addTags($newdoc->getId(), $doc_def['tags']); |
|
|
48 |
} |
|
|
49 |
|
|
|
50 |
# add tags |
|
|
51 |
|
|
|
52 |
$manager->flush(); |
|
|
53 |
|
|
|
54 |
} |
|
|
55 |
|
|
|
56 |
} |