# HG changeset patch # User ymh # Date 1324313405 -3600 # Node ID 9f427e7c88f9975e05f5cd62cb9ede96c321dde0 # Parent c8790bc6417af889a544de7c3eaf1cdeaaa4701e Correct event mamangement in hdabo_sf diff -r c8790bc6417a -r 9f427e7c88f9 .hgsubstate --- a/.hgsubstate Wed Dec 14 23:55:33 2011 +0100 +++ b/.hgsubstate Mon Dec 19 17:50:05 2011 +0100 @@ -1,1 +1,1 @@ -caeb4c8b54878ca264a3346eb08261a8b3c28592 vendor/bundles/IRI/Bundle/WikiTagBundle +ba6b8e38d90eccefe10c03f92ae66ae2f494f1ae vendor/bundles/IRI/Bundle/WikiTagBundle diff -r c8790bc6417a -r 9f427e7c88f9 app/config/config.yml --- a/app/config/config.yml Wed Dec 14 23:55:33 2011 +0100 +++ b/app/config/config.yml Mon Dec 19 17:50:05 2011 +0100 @@ -76,6 +76,10 @@ description: type: text weight: 0.5 + categories: + type: text + accessor: getCategoriesStr + weight: 1.5 # reactive_selectors is a list of jQuery selectors meant to let appear tag context search by selecting text. # Example of list : [ '.any_class', '#any_div .p_class', '#another_selector' ]. Write [ 'document' ] if you want the whole document/page to be reactive. # Do not define reactive_selectors if you want nothing to be reactive. diff -r c8790bc6417a -r 9f427e7c88f9 src/Company/BaseBundle/DataFixtures/ORM/LoadDocumentData.php --- a/src/Company/BaseBundle/DataFixtures/ORM/LoadDocumentData.php Wed Dec 14 23:55:33 2011 +0100 +++ b/src/Company/BaseBundle/DataFixtures/ORM/LoadDocumentData.php Mon Dec 19 17:50:05 2011 +0100 @@ -13,6 +13,7 @@ use Symfony\Component\DependencyInjection\ContainerAwareInterface; use Doctrine\Common\DataFixtures\FixtureInterface; use Company\BaseBundle\Entity\Document; +use Company\BaseBundle\Entity\Category; class LoadDocumentData implements FixtureInterface, ContainerAwareInterface { @@ -25,32 +26,55 @@ public function load($manager) { + # create new categories + $cat_def_list = array('cat1' => null, 'cat2' => null, 'cat3'=> null); + + foreach(array_keys($cat_def_list) as $cat_name) { + $newcat = new Category(); + $newcat->setName($cat_name); + $manager->persist($newcat); + $cat_def_list[$cat_name] = $newcat; + } + # 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()), + array('title'=>'Title 1', 'description'=>'Description 1', 'tags' => array('tag1', 'tag2', 'tag3', 'tag4'), 'categories' => array_values($cat_def_list)), + array('title'=>'Title 2', 'description'=>'Description 2', 'tags' => array('tag2', 'tag3', 'tag4'), 'categories' => array($cat_def_list['cat1'], $cat_def_list['cat2'])), + array('title'=>'Title 3', 'description'=>'Description 3', 'tags' => array('tag3', 'tag4'), 'categories' => array($cat_def_list['cat1'])), + array('title'=>'Title 4', 'description'=>'Description 4', 'tags' => array(), 'categories' => array()), + array('title'=>'Title 5', 'description'=>'Description 5', 'tags' => array('tag2', 'tag3', 'tag4'), 'categories' => array($cat_def_list['cat1'], $cat_def_list['cat2'])), + array('title'=>'Title 10', 'description'=>'Description 10', 'tags' => array('tag1', 'tag2', 'tag3', 'tag4'), 'categories' => array()), ); + + $newdocs = array(); + foreach ($doc_def_list as $doc_def) { $newdoc = new Document(); $newdoc->setTitle($doc_def['title']); $newdoc->setDescription($doc_def['description']); - + + foreach($doc_def['categories'] as $cat) { + $newdoc->getCategories()->add($cat); + } + $manager->persist($newdoc); - $manager->flush(); + $newdocs[] = array($newdoc, $doc_def['tags']); - $this->container->get('wiki_tag.document')->addTags($newdoc->getId(), $doc_def['tags']); } - # add tags - $manager->flush(); + foreach ($newdocs as $newdoc_array) { + $newdoc = $newdoc_array[0]; + $tags = $newdoc_array[1]; + $this->container->get('wiki_tag.document')->addTags($newdoc->getId(), $tags); + $manager->flush(); + } + + $manager->flush(); } } \ No newline at end of file diff -r c8790bc6417a -r 9f427e7c88f9 src/Company/BaseBundle/Entity/Category.php --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/Company/BaseBundle/Entity/Category.php Mon Dec 19 17:50:05 2011 +0100 @@ -0,0 +1,61 @@ +id; + } + + /** + * Set name + * + * @param string $name + */ + public function setName($name) + { + $this->name = $name; + } + + /** + * Get name + * + * @return string + */ + public function getName() + { + return $this->name; + } +} \ No newline at end of file diff -r c8790bc6417a -r 9f427e7c88f9 src/Company/BaseBundle/Entity/CategoryRepository.php --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/Company/BaseBundle/Entity/CategoryRepository.php Mon Dec 19 17:50:05 2011 +0100 @@ -0,0 +1,15 @@ +description; } + + /** + * Get categories list + * + * @return \Doctrine\Common\Collections\ArrayCollection + */ + public function getCategories() + { + return $this->categories; + } + + /** + * get the list of categories as string + * + */ + public function getCategoriesStr() + { + $res = array(); + foreach($this->getCategories() as $cat) { + $res[] = $cat->getName(); + } + return implode(",", $res); + } + + + public function __construct() { + $this->categories = new \Doctrine\Common\Collections\ArrayCollection(); + } + } \ No newline at end of file