<?php
namespace Roothirsch\ShopBundle\Entity\Estimate;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Roothirsch\CoreBundle\Behaviors\Attributable\AttributableAwareInterface;
use Roothirsch\CoreBundle\Behaviors\Attributable\AttributableInterface;
use Roothirsch\CoreBundle\Behaviors\Attributable\Attribute\AttributeAwareTrait;
use Roothirsch\CoreBundle\Behaviors\Attributable\Attribute\AttributeInterface;
use Roothirsch\CoreBundle\Behaviors\Attributable\AttributeOption\AttributeOptionAwareTrait;
use Roothirsch\CoreBundle\Behaviors\Attributable\MappedSuperclass\AbstractAttributeValue;
use Roothirsch\ShopBundle\Entity\Estimate\EstimateAttributeOption;
use Roothirsch\ShopBundle\Entity\Estimate\EstimateAttribute;
use Roothirsch\ShopBundle\Entity\Estimate;
use Roothirsch\ShopBundle\Repository\AttributeValueRepository;
/**
* @ORM\Entity(repositoryClass=EstimateAttributeValueRepository::class)
* @ORM\Table(name="shop_estimate_attribute_value")
*/
class EstimateAttributeValue extends AbstractAttributeValue
{
use AttributeAwareTrait;
use AttributeOptionAwareTrait;
/**
* @ORM\ManyToOne(targetEntity=Estimate::class, inversedBy="attributeValues")
* @ORM\JoinColumn(nullable=false)
*/
private $estimate;
/**
* @ORM\ManyToOne(targetEntity=EstimateAttribute::class, inversedBy="attributeValues")
* @ORM\JoinColumn(nullable=false)
*/
private $attribute;
/**
* @ORM\ManyToMany(targetEntity=EstimateAttributeOption::class, cascade={"persist"})
* @ORM\JoinTable(name="shop_estimate_attribute_value_estimate_attribute_option")
*/
private $attributeOptions;
public function __construct(AttributeInterface $attribute)
{
$this->attributeOptions = new ArrayCollection();
$this->attribute = $attribute;
}
public function __clone() {
$this->id = null;
// $this->setCreatedAt(new \DateTime());
// $this->setUpdatedAt(new \DateTime());
//
// $oldAttributes = $this->attributes;
// $this->attributes = new ArrayCollection();
// foreach($oldAttributes as $oldAttribute) {
// $this->attributes->add(clone $oldAttribute);
// }
}
function resolveExpression(): array
{
return [
"estimate" => $this->getAttributable()
];
}
public function getAttributable(): AttributableInterface
{
return $this->estimate;
}
public function setAttributable(AttributableInterface $attributable): AttributableAwareInterface
{
$this->estimate = $attributable;
return $this;
}
}