Permalink
Browse files

Add attributes to cateogry object using Single Table inheritance.

  • Loading branch information...
1 parent 672db00 commit 878d00b3d5a0905cd8cf3ccd4432b815515fb8c2 @craigh committed Feb 17, 2012
@@ -0,0 +1,112 @@
+<?php
+/**
+ * Copyright Zikula Foundation 2009 - Zikula Application Framework
+ *
+ * This work is contributed to the Zikula Foundation under one or more
+ * Contributor Agreements and licensed to You under the following license:
+ *
+ * @license GNU/LGPLv3 (or at your option, any later version).
+ * @package Zikula_Form
+ *
+ * Please see the NOTICE file distributed with this source code for further
+ * information regarding copyright and licensing.
+ */
+
+use Doctrine\ORM\Mapping as ORM;
+
+/**
+ * Attribute doctrine2 entity.
+ *
+ * @ORM\Entity
+ * @ORM\InheritanceType("SINGLE_TABLE")
+ * @ORM\DiscriminatorColumn(name="object_type", type="string")
+ * @ORM\DiscriminatorMap({"categories_category" = "Zikula_Doctrine2_Entity_CategoryAttribute"})
+ * @ORM\Table(name="objectdata_attributes")
+ */
+abstract class Zikula_Doctrine2_Entity_AbstractAttribute extends Zikula_EntityAccess {
+ /**
+ * @ORM\Id
+ * @ORM\Column(type="integer")
+ * @ORM\GeneratedValue
+ * @var integer
+ */
+ private $id;
+ /**
+ * @ORM\Column(type="string", length=80, name="attribute_name")
+ * @var string
+ */
+ private $name;
+ /**
+ * @ORM\Column(type="text")
+ * @var string
+ */
+ private $value;
+ /**
+ * @ORM\Column(type="string", length=1, name="obj_status")
+ * @var string
+ */
+ private $objectStatus;
+
+ public function __construct($objectId, $objectType, $objectStatus, $name, $value)
+ {
+ $this->SetObjectID($objectId);
+ $this->objectType = $objectType;
+ $this->objectStatus = $objectStatus;
+ $this->name = $name;
+ $this->value = $value;
+ }
+
+ public function getId()
+ {
+ return $this->id;
+ }
+
+ public function setId($id)
+ {
+ $this->id = $id;
+ }
+
+ public function getName()
+ {
+ return $this->name;
+ }
+
+ public function setName($name)
+ {
+ $this->name = $name;
+ }
+
+ public function getValue()
+ {
+ return $this->value;
+ }
+
+ public function setValue($value)
+ {
+ $this->value = $value;
+ }
+
+ public function getObjectStatus()
+ {
+ return $this->objectStatus;
+ }
+
+ public function setObjectStatus($objectStatus)
+ {
+ $this->objectStatus = $objectStatus;
+ }
+
+ public function getObjectType()
+ {
+ return $this->objectType;
+ }
+
+ public function setObjectType($objectType)
+ {
+ $this->objectType = $objectType;
+ }
+
+ abstract public function getObjectId();
+
+ abstract public function setObjectId($objectId);
+}
@@ -13,6 +13,7 @@
*/
use Doctrine\ORM\Mapping as ORM;
+use Doctrine\Common\Collections\ArrayCollection;
/**
* Category doctrine2 entity.
@@ -102,6 +103,20 @@ class Zikula_Doctrine2_Entity_Category extends Zikula_EntityAccess {
*/
private $status;
+ /**
+ * @ORM\OneToMany(targetEntity="Zikula_Doctrine2_Entity_CategoryAttribute",
+ * mappedBy="objectId", cascade={"all"},
+ * orphanRemoval=true, indexBy="name")
+ *
+ * @var ArrayCollection
+ */
+ private $attributes;
+
+ public function __construct()
+ {
+ $this->attributes = new ArrayCollection();
+ }
+
public function getId()
{
return $this->id;
@@ -231,4 +246,23 @@ public function setStatus($status)
{
$this->status = $status;
}
+
+ public function getAttributes()
+ {
+ return $this->attributes;
+ }
+
+ public function setAttribute($name, $value)
+ {
+ if(isset($this->attributes[$name])) {
+ if($value == null) {
+ $this->attributes->remove($name);
+ } else {
+ $this->attributes[$name]->setValue($value);
+ }
+ } else {
+ $this->attributes[$name] = new Zikula_Doctrine2_Entity_CategoryAttribute($this->getId(), 'A', $name, $value);
+ }
+ }
+
}
@@ -0,0 +1,45 @@
+<?php
+/**
+ * Copyright Zikula Foundation 2009 - Zikula Application Framework
+ *
+ * This work is contributed to the Zikula Foundation under one or more
+ * Contributor Agreements and licensed to You under the following license:
+ *
+ * @license GNU/LGPLv3 (or at your option, any later version).
+ * @package Zikula_Form
+ *
+ * Please see the NOTICE file distributed with this source code for further
+ * information regarding copyright and licensing.
+ */
+
+use Doctrine\ORM\Mapping as ORM;
+
+/**
+ * CategoryAttribute doctrine2 entity.
+ *
+ * @ORM\Entity
+ */
+class Zikula_Doctrine2_Entity_CategoryAttribute extends Zikula_Doctrine2_Entity_AbstractAttribute {
+ /**
+ * @ORM\ManyToOne(targetEntity="Zikula_Doctrine2_Entity_Category", inversedBy="attributes")
+ * @ORM\JoinColumn(name="object_id", referencedColumnName="id")
+ * @var integer
+ */
+ private $objectId;
+
+ public function __construct($objectId, $objectStatus, $name, $value)
+ {
+ parent::__construct($objectId, 'categories_category', $objectStatus, $name, $value);
+ }
+
+ public function getObjectId()
+ {
+ return $this->objectId;
+ }
+
+ public function setObjectId($objectId)
+ {
+ $this->objectId = $objectId;
+ }
+
+}

0 comments on commit 878d00b

Please sign in to comment.