vendor/pimcore/pimcore/models/Document/Editable/Checkbox.php line 25

Open in your IDE?
  1. <?php
  2. /**
  3.  * Pimcore
  4.  *
  5.  * This source file is available under two different licenses:
  6.  * - GNU General Public License version 3 (GPLv3)
  7.  * - Pimcore Enterprise License (PEL)
  8.  * Full copyright and license information is available in
  9.  * LICENSE.md which is distributed with this source code.
  10.  *
  11.  * @category   Pimcore
  12.  * @package    Document
  13.  *
  14.  * @copyright  Copyright (c) Pimcore GmbH (http://www.pimcore.org)
  15.  * @license    http://www.pimcore.org/license     GPLv3 and PEL
  16.  */
  17. namespace Pimcore\Model\Document\Editable;
  18. use Pimcore\Model;
  19. /**
  20.  * @method \Pimcore\Model\Document\Editable\Dao getDao()
  21.  */
  22. class Checkbox extends Model\Document\Editable
  23. {
  24.     /**
  25.      * Contains the checkbox value
  26.      *
  27.      * @var bool
  28.      */
  29.     public $value false;
  30.     /**
  31.      * @see EditableInterface::getType
  32.      *
  33.      * @return string
  34.      */
  35.     public function getType()
  36.     {
  37.         return 'checkbox';
  38.     }
  39.     /**
  40.      * @see EditableInterface::getData
  41.      *
  42.      * @return mixed
  43.      */
  44.     public function getData()
  45.     {
  46.         return $this->value;
  47.     }
  48.     /**
  49.      * @see EditableInterface::frontend
  50.      *
  51.      * @return string
  52.      */
  53.     public function frontend()
  54.     {
  55.         return (string)$this->value;
  56.     }
  57.     /**
  58.      * @see EditableInterface::setDataFromResource
  59.      *
  60.      * @param mixed $data
  61.      *
  62.      * @return $this
  63.      */
  64.     public function setDataFromResource($data)
  65.     {
  66.         $this->value = (bool) $data;
  67.         return $this;
  68.     }
  69.     /**
  70.      * @see EditableInterface::setDataFromEditmode
  71.      *
  72.      * @param mixed $data
  73.      *
  74.      * @return $this
  75.      */
  76.     public function setDataFromEditmode($data)
  77.     {
  78.         $this->value = (bool) $data;
  79.         return $this;
  80.     }
  81.     /**
  82.      * @return bool
  83.      */
  84.     public function isEmpty()
  85.     {
  86.         return !$this->value;
  87.     }
  88.     /**
  89.      * @return bool
  90.      */
  91.     public function isChecked()
  92.     {
  93.         return $this->value;
  94.     }
  95.     /**
  96.      * @deprecated
  97.      *
  98.      * @param Model\Webservice\Data\Document\Element $wsElement
  99.      * @param Model\Document\PageSnippet $document
  100.      * @param array $params
  101.      * @param Model\Webservice\IdMapperInterface|null $idMapper
  102.      *
  103.      * @throws \Exception
  104.      *
  105.      */
  106.     public function getFromWebserviceImport($wsElement$document null$params = [], $idMapper null)
  107.     {
  108.         $data $this->sanitizeWebserviceData($wsElement->value);
  109.         if ($data->bool === null || is_bool($data)) {
  110.             $this->value = (bool) $data->value;
  111.         } else {
  112.             throw new \Exception('cannot get values from web service import - invalid data');
  113.         }
  114.     }
  115. }
  116. class_alias(Checkbox::class, 'Pimcore\Model\Document\Tag\Checkbox');