--- 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
--- 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.
--- 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
--- /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 @@
+<?php
+
+namespace Company\BaseBundle\Entity;
+
+use Doctrine\ORM\Mapping as ORM;
+
+/**
+ * Company\BaseBundle\Entity\Category
+ *
+ * @ORM\Table()
+ * @ORM\Entity(repositoryClass="Company\BaseBundle\Entity\CategoryRepository")
+ */
+class Category
+{
+ /**
+ * @var integer $id
+ *
+ * @ORM\Column(name="id", type="integer")
+ * @ORM\Id
+ * @ORM\GeneratedValue(strategy="AUTO")
+ */
+ private $id;
+
+ /**
+ * @var string $name
+ *
+ * @ORM\Column(name="name", type="string", length=1024)
+ */
+ private $name;
+
+
+ /**
+ * Get id
+ *
+ * @return integer
+ */
+ public function getId()
+ {
+ return $this->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
--- /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 @@
+<?php
+
+namespace Company\BaseBundle\Entity;
+
+use Doctrine\ORM\EntityRepository;
+
+/**
+ * CategoryRepository
+ *
+ * This class was generated by the Doctrine ORM. Add your own custom
+ * repository methods below.
+ */
+class CategoryRepository extends EntityRepository
+{
+}
\ No newline at end of file
--- a/src/Company/BaseBundle/Entity/Document.php Wed Dec 14 23:55:33 2011 +0100
+++ b/src/Company/BaseBundle/Entity/Document.php Mon Dec 19 17:50:05 2011 +0100
@@ -3,7 +3,7 @@
namespace Company\BaseBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
-use IRI\Bundle\WikiTagBundle\Model\DocumentInterface;
+use Doctrine\Common\Collections\ArrayCollection;
/**
* Company\BaseBundle\Entity\Document
@@ -36,6 +36,18 @@
* @ORM\Column(name="description", type="text")
*/
private $description;
+
+ /**
+ * @ORM\ManyToMany(targetEntity="Category")
+ * @ORM\JoinTable(name="documents_categories",
+ * joinColumns={@ORM\JoinColumn(name="document_id", referencedColumnName="id")},
+ * inverseJoinColumns={@ORM\JoinColumn(name="category_id", referencedColumnName="id")}
+ * )
+ * @ORM\OrderBy({"name" = "ASC"})
+ *
+ * @var \Doctrine\Common\Collections\ArrayCollection
+ */
+ private $categories;
/**
@@ -88,4 +100,33 @@
{
return $this->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