use Symfony\Component\Validator\Constraints as Assert;
/**
- * @ORM\Entity
+ * @ORM\Entity(repositoryClass="ResourceRepository")
* @ORM\InheritanceType(value="JOINED")
* @ORM\DiscriminatorColumn(name="type", type="text", length=30)
* @ORM\DiscriminatorMap({
*/
protected $description;
- protected $type;
-
/**
* @ORM\Column(type="integer")
*/
public function getType()
{
- return $this->type;
- }
+ if ($this instanceof ResourceZone) {
+ return self::TYPE_ZONE;
+ } elseif ($this instanceof ResourcePlace) {
+ return self::TYPE_PLACE;
+ } elseif ($this instanceof ResourceComputer) {
+ return self::TYPE_COMPUTER;
+ }
- public function setType($type)
- {
- $this->type = $type;
+ throw new \LogicException(sprintf('Unable to guess type from "%s"', get_class($this)));
}
public function getStatus()
throw new \InvalidArgumentException(sprintf('No resource type named "%s"', $type));
}
}
+
+ public function isParentRequired()
+ {
+ return $this->getType() === self::TYPE_COMPUTER;
+ }
+
+ public function getAllowedParentTypes()
+ {
+ $type = $this->getType();
+
+ if ($type === Resource::TYPE_ZONE) {
+ return array(Resource::TYPE_ZONE);
+ } elseif ($type == Resource::TYPE_PLACE) {
+ return array(Resource::TYPE_ZONE, Resource::TYPE_PLACE);
+ } elseif ($type == Resource::TYPE_COMPUTER) {
+ return array(Resource::TYPE_PLACE);
+ }
+
+ throw new \InvalidArgumentException(sprintf('No parent types defined for "%s"', $type));
+ }
}