src/Company/BaseBundle/DataFixtures/ORM/LoadDocumentData.php
changeset 58 624e5900f5a4
child 61 9f427e7c88f9
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/Company/BaseBundle/DataFixtures/ORM/LoadDocumentData.php	Wed Dec 14 23:28:58 2011 +0100
@@ -0,0 +1,56 @@
+<?php
+/*
+ * This file is part of the WikiTagBundle package.
+ *
+ * (c) IRI <http://www.iri.centrepompidou.fr/>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+namespace Company\BaseBundle\DataFixures\ORM;
+
+use Symfony\Component\DependencyInjection\ContainerInterface;
+use Symfony\Component\DependencyInjection\ContainerAwareInterface;
+use Doctrine\Common\DataFixtures\FixtureInterface;
+use Company\BaseBundle\Entity\Document;
+
+class LoadDocumentData implements FixtureInterface, ContainerAwareInterface
+{
+    private $container;
+
+    public function setContainer(ContainerInterface $container = null)
+    {
+        $this->container = $container;
+    }
+    
+    public function load($manager) {
+        
+        # create new document
+        
+        $doc_def_list = array(
+            array('title'=>'Title 1', 'description'=>'Description 1', 'tags' => array('tag1', 'tag2', 'tag3', 'tag4')),
+            array('title'=>'Title 2', 'description'=>'Description 2', 'tags' => array('tag2', 'tag3', 'tag4')),
+            array('title'=>'Title 3', 'description'=>'Description 3', 'tags' => array('tag3', 'tag4')),
+            array('title'=>'Title 4', 'description'=>'Description 4', 'tags' => array()),
+        );
+        
+        foreach ($doc_def_list as $doc_def) {
+            
+            $newdoc = new Document();
+            $newdoc->setTitle($doc_def['title']);
+            $newdoc->setDescription($doc_def['description']);
+                       
+            $manager->persist($newdoc);
+            
+            $manager->flush();
+            
+            $this->container->get('wiki_tag.document')->addTags($newdoc->getId(), $doc_def['tags']);
+        }
+        
+        # add tags
+        
+        $manager->flush();
+        
+    }
+ 
+}
\ No newline at end of file