classes/XLite/Model/AttributeValue/AttributeValueCheckbox.php line 120

Open in your IDE?
  1. <?php
  2. /**
  3.  * Copyright (c) 2011-present Qualiteam software Ltd. All rights reserved.
  4.  * See https://www.x-cart.com/license-agreement.html for license details.
  5.  */
  6. namespace XLite\Model\AttributeValue;
  7. use ApiPlatform\Core\Annotation as ApiPlatform;
  8. use Doctrine\ORM\Mapping as ORM;
  9. use XLite\API\Endpoint\AttributeValue\Checkbox\DTO\AttributeValueCheckboxInput as Input;
  10. use XLite\API\Endpoint\AttributeValue\Checkbox\DTO\AttributeValueCheckboxOutput as Output;
  11. use XLite\Controller\API\AttributeValue\Checkbox\Post as PostController;
  12. use XLite\Core\Translation\Label;
  13. /**
  14.  * Attribute value (checkbox)
  15.  *
  16.  * @ORM\Entity
  17.  * @ORM\Table (name="attribute_values_checkbox",
  18.  *      indexes={
  19.  *          @ORM\Index (name="product_id", columns={"product_id"}),
  20.  *          @ORM\Index (name="attribute_id", columns={"attribute_id"}),
  21.  *          @ORM\Index (name="value", columns={"value"})
  22.  *      }
  23.  * )
  24.  * @ApiPlatform\ApiResource(
  25.  *     attributes={"pagination_enabled": false},
  26.  *     shortName="Yes/No Attribute Value",
  27.  *     itemOperations={
  28.  *          "get"={
  29.  *              "method"="GET",
  30.  *              "path"="/products/{product_id}/attributes_checkbox/{attribute_id}/values/{id}.{_format}",
  31.  *              "identifiers"={"id"},
  32.  *              "input"=Input::class,
  33.  *              "output"=Output::class,
  34.  *              "requirements"={"product_id"="\d+", "attribute_id"="\d+", "id"="\d+"},
  35.  *              "identifiers"={"product_id", "attribute_id", "id"},
  36.  *              "openapi_context"={
  37.  *                  "summary"="Retrieve a value from a product yes/no attribute",
  38.  *                  "parameters"={
  39.  *                     {"name"="product_id", "in"="path", "required"=true, "schema"={"type"="integer"}},
  40.  *                     {"name"="attribute_id", "in"="path", "required"=true, "schema"={"type"="integer"}},
  41.  *                     {"name"="id", "in"="path", "required"=true, "schema"={"type"="integer"}}
  42.  *                  }
  43.  *              }
  44.  *          },
  45.  *          "put"={
  46.  *              "method"="PUT",
  47.  *              "path"="/products/{product_id}/attributes_checkbox/{attribute_id}/values/{id}.{_format}",
  48.  *              "identifiers"={"id"},
  49.  *              "input"=Input::class,
  50.  *              "output"=Output::class,
  51.  *              "requirements"={"product_id"="\d+", "attribute_id"="\d+", "id"="\d+"},
  52.  *              "identifiers"={"product_id", "attribute_id", "id"},
  53.  *              "openapi_context"={
  54.  *                  "summary"="Update a value of a product yes/no attribute",
  55.  *                  "parameters"={
  56.  *                     {"name"="product_id", "in"="path", "required"=true, "schema"={"type"="integer"}},
  57.  *                     {"name"="attribute_id", "in"="path", "required"=true, "schema"={"type"="integer"}},
  58.  *                     {"name"="id", "in"="path", "required"=true, "schema"={"type"="integer"}}
  59.  *                  }
  60.  *              }
  61.  *          },
  62.  *          "delete"={
  63.  *              "method"="DELETE",
  64.  *              "path"="/products/{product_id}/attributes_checkbox/{attribute_id}/values/{id}.{_format}",
  65.  *              "identifiers"={"id"},
  66.  *              "input"=Input::class,
  67.  *              "output"=Output::class,
  68.  *              "requirements"={"product_id"="\d+", "attribute_id"="\d+", "id"="\d+"},
  69.  *              "identifiers"={"product_id", "attribute_id", "id"},
  70.  *              "openapi_context"={
  71.  *                  "summary"="Delete a value from a product yes/no attribute",
  72.  *                  "parameters"={
  73.  *                     {"name"="product_id", "in"="path", "required"=true, "schema"={"type"="integer"}},
  74.  *                     {"name"="attribute_id", "in"="path", "required"=true, "schema"={"type"="integer"}},
  75.  *                     {"name"="id", "in"="path", "required"=true, "schema"={"type"="integer"}}
  76.  *                  }
  77.  *              }
  78.  *          }
  79.  *     },
  80.  *     collectionOperations={
  81.  *          "get"={
  82.  *              "method"="GET",
  83.  *              "path"="/products/{product_id}/attributes_checkbox/{attribute_id}/values.{_format}",
  84.  *              "identifiers"={"id"},
  85.  *              "input"=Input::class,
  86.  *              "output"=Output::class,
  87.  *              "requirements"={"product_id"="\d+", "attribute_id"="\d+"},
  88.  *              "openapi_context"={
  89.  *                  "summary"="Retrieve a list of values from a product yes/no attribute",
  90.  *                  "parameters"={
  91.  *                     {"name"="product_id", "in"="path", "required"=true, "schema"={"type"="integer"}},
  92.  *                     {"name"="attribute_id", "in"="path", "required"=true, "schema"={"type"="integer"}},
  93.  *                  }
  94.  *              },
  95.  *          },
  96.  *          "post"={
  97.  *              "method"="POST",
  98.  *              "path"="/products/{product_id}/attributes_checkbox/{attribute_id}/values.{_format}",
  99.  *              "identifiers"={"id"},
  100.  *              "input"=Input::class,
  101.  *              "output"=Output::class,
  102.  *              "controller"=PostController::class,
  103.  *              "requirements"={"product_id"="\d+", "attribute_id"="\d+"},
  104.  *              "identifiers"={"product_id", "attribute_id"},
  105.  *              "openapi_context"={
  106.  *                  "summary"="Add a value to a product yes/no attribute",
  107.  *                  "parameters"={
  108.  *                     {"name"="product_id", "in"="path", "required"=true, "schema"={"type"="integer"}},
  109.  *                     {"name"="attribute_id", "in"="path", "required"=true, "schema"={"type"="integer"}},
  110.  *                  }
  111.  *              }
  112.  *          }
  113.  *     }
  114.  * )
  115.  */
  116. class AttributeValueCheckbox extends \XLite\Model\AttributeValue\Multiple
  117. {
  118.     /**
  119.      * @var \XLite\Model\Product
  120.      *
  121.      * @ORM\ManyToOne (targetEntity="XLite\Model\Product", inversedBy="attributeValueC")
  122.      * @ORM\JoinColumn (name="product_id", referencedColumnName="product_id", onDelete="CASCADE")
  123.      */
  124.     protected $product;
  125.     /**
  126.      * Value
  127.      *
  128.      * @var boolean
  129.      *
  130.      * @ORM\Column (type="boolean")
  131.      */
  132.     protected $value false;
  133.     /**
  134.      * @var \Doctrine\Common\Collections\Collection
  135.      *
  136.      * @ORM\OneToMany (targetEntity="XLite\Model\AttributeValue\AttributeValueCheckboxTranslation", mappedBy="owner", cascade={"all"})
  137.      */
  138.     protected $translations;
  139.     /**
  140.      * Return attribute value as string
  141.      *
  142.      * @return string|Label
  143.      */
  144.     public function asString()
  145.     {
  146.         return static::t($this->getValue() ? 'Yes' 'No');
  147.     }
  148.     /**
  149.      * @return \XLite\Model\Product
  150.      */
  151.     public function getProduct()
  152.     {
  153.         return $this->product;
  154.     }
  155.     /**
  156.      * @param \XLite\Model\Product $product
  157.      */
  158.     public function setProduct(\XLite\Model\Product $product null)
  159.     {
  160.         $this->product $product;
  161.     }
  162.     /**
  163.      * @return boolean
  164.      */
  165.     public function getValue()
  166.     {
  167.         return $this->value;
  168.     }
  169.     /**
  170.      * @param mixed $value
  171.      */
  172.     public function setValue($value)
  173.     {
  174.         if ($value === 'Y' || $value === 1) {
  175.             $value true;
  176.         } elseif ($value === 'N' || $value === 0) {
  177.             $value false;
  178.         }
  179.         $this->value $value;
  180.     }
  181. }