vendor/roothirsch/shop-bundle/Entity/Estimate/EstimateAttributeValue.php line 23

Open in your IDE?
  1. <?php
  2. namespace Roothirsch\ShopBundle\Entity\Estimate;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\Common\Collections\Collection;
  5. use Doctrine\ORM\Mapping as ORM;
  6. use Roothirsch\CoreBundle\Behaviors\Attributable\AttributableAwareInterface;
  7. use Roothirsch\CoreBundle\Behaviors\Attributable\AttributableInterface;
  8. use Roothirsch\CoreBundle\Behaviors\Attributable\Attribute\AttributeAwareTrait;
  9. use Roothirsch\CoreBundle\Behaviors\Attributable\Attribute\AttributeInterface;
  10. use Roothirsch\CoreBundle\Behaviors\Attributable\AttributeOption\AttributeOptionAwareTrait;
  11. use Roothirsch\CoreBundle\Behaviors\Attributable\MappedSuperclass\AbstractAttributeValue;
  12. use Roothirsch\ShopBundle\Entity\Estimate\EstimateAttributeOption;
  13. use Roothirsch\ShopBundle\Entity\Estimate\EstimateAttribute;
  14. use Roothirsch\ShopBundle\Entity\Estimate;
  15. use Roothirsch\ShopBundle\Repository\AttributeValueRepository;
  16. /**
  17. * @ORM\Entity(repositoryClass=EstimateAttributeValueRepository::class)
  18. * @ORM\Table(name="shop_estimate_attribute_value")
  19. */
  20. class EstimateAttributeValue extends AbstractAttributeValue
  21. {
  22. use AttributeAwareTrait;
  23. use AttributeOptionAwareTrait;
  24. /**
  25. * @ORM\ManyToOne(targetEntity=Estimate::class, inversedBy="attributeValues")
  26. * @ORM\JoinColumn(nullable=false)
  27. */
  28. private $estimate;
  29. /**
  30. * @ORM\ManyToOne(targetEntity=EstimateAttribute::class, inversedBy="attributeValues")
  31. * @ORM\JoinColumn(nullable=false)
  32. */
  33. private $attribute;
  34. /**
  35. * @ORM\ManyToMany(targetEntity=EstimateAttributeOption::class, cascade={"persist"})
  36. * @ORM\JoinTable(name="shop_estimate_attribute_value_estimate_attribute_option")
  37. */
  38. private $attributeOptions;
  39. public function __construct(AttributeInterface $attribute)
  40. {
  41. $this->attributeOptions = new ArrayCollection();
  42. $this->attribute = $attribute;
  43. }
  44. public function __clone() {
  45. $this->id = null;
  46. // $this->setCreatedAt(new \DateTime());
  47. // $this->setUpdatedAt(new \DateTime());
  48. //
  49. // $oldAttributes = $this->attributes;
  50. // $this->attributes = new ArrayCollection();
  51. // foreach($oldAttributes as $oldAttribute) {
  52. // $this->attributes->add(clone $oldAttribute);
  53. // }
  54. }
  55. function resolveExpression(): array
  56. {
  57. return [
  58. "estimate" => $this->getAttributable()
  59. ];
  60. }
  61. public function getAttributable(): AttributableInterface
  62. {
  63. return $this->estimate;
  64. }
  65. public function setAttributable(AttributableInterface $attributable): AttributableAwareInterface
  66. {
  67. $this->estimate = $attributable;
  68. return $this;
  69. }
  70. }