23 $this->container = $container; |
24 $this->container = $container; |
24 } |
25 } |
25 |
26 |
26 public function load($manager) { |
27 public function load($manager) { |
27 |
28 |
|
29 # create new categories |
|
30 $cat_def_list = array('cat1' => null, 'cat2' => null, 'cat3'=> null); |
|
31 |
|
32 foreach(array_keys($cat_def_list) as $cat_name) { |
|
33 $newcat = new Category(); |
|
34 $newcat->setName($cat_name); |
|
35 $manager->persist($newcat); |
|
36 $cat_def_list[$cat_name] = $newcat; |
|
37 } |
|
38 |
28 # create new document |
39 # create new document |
|
40 $doc_def_list = array( |
|
41 array('title'=>'Title 1', 'description'=>'Description 1', 'tags' => array('tag1', 'tag2', 'tag3', 'tag4'), 'categories' => array_values($cat_def_list)), |
|
42 array('title'=>'Title 2', 'description'=>'Description 2', 'tags' => array('tag2', 'tag3', 'tag4'), 'categories' => array($cat_def_list['cat1'], $cat_def_list['cat2'])), |
|
43 array('title'=>'Title 3', 'description'=>'Description 3', 'tags' => array('tag3', 'tag4'), 'categories' => array($cat_def_list['cat1'])), |
|
44 array('title'=>'Title 4', 'description'=>'Description 4', 'tags' => array(), 'categories' => array()), |
|
45 array('title'=>'Title 5', 'description'=>'Description 5', 'tags' => array('tag2', 'tag3', 'tag4'), 'categories' => array($cat_def_list['cat1'], $cat_def_list['cat2'])), |
|
46 array('title'=>'Title 10', 'description'=>'Description 10', 'tags' => array('tag1', 'tag2', 'tag3', 'tag4'), 'categories' => array()), |
|
47 ); |
29 |
48 |
30 $doc_def_list = array( |
49 |
31 array('title'=>'Title 1', 'description'=>'Description 1', 'tags' => array('tag1', 'tag2', 'tag3', 'tag4')), |
50 $newdocs = array(); |
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 |
51 |
37 foreach ($doc_def_list as $doc_def) { |
52 foreach ($doc_def_list as $doc_def) { |
38 |
53 |
39 $newdoc = new Document(); |
54 $newdoc = new Document(); |
40 $newdoc->setTitle($doc_def['title']); |
55 $newdoc->setTitle($doc_def['title']); |
41 $newdoc->setDescription($doc_def['description']); |
56 $newdoc->setDescription($doc_def['description']); |
42 |
57 |
|
58 foreach($doc_def['categories'] as $cat) { |
|
59 $newdoc->getCategories()->add($cat); |
|
60 } |
|
61 |
43 $manager->persist($newdoc); |
62 $manager->persist($newdoc); |
44 |
63 |
45 $manager->flush(); |
64 $newdocs[] = array($newdoc, $doc_def['tags']); |
46 |
65 |
47 $this->container->get('wiki_tag.document')->addTags($newdoc->getId(), $doc_def['tags']); |
|
48 } |
66 } |
49 |
|
50 # add tags |
|
51 |
67 |
52 $manager->flush(); |
68 $manager->flush(); |
53 |
69 |
|
70 foreach ($newdocs as $newdoc_array) { |
|
71 $newdoc = $newdoc_array[0]; |
|
72 $tags = $newdoc_array[1]; |
|
73 $this->container->get('wiki_tag.document')->addTags($newdoc->getId(), $tags); |
|
74 $manager->flush(); |
|
75 } |
|
76 |
|
77 $manager->flush(); |
54 } |
78 } |
55 |
79 |
56 } |
80 } |