vendor/pimcore/pimcore/models/Document/Editable/Multiselect.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 Multiselect extends Model\Document\Editable
  23. {
  24.     /**
  25.      * Contains the current selected values
  26.      *
  27.      * @var array
  28.      */
  29.     public $values = [];
  30.     /**
  31.      * @see EditableInterface::getType
  32.      *
  33.      * @return string
  34.      */
  35.     public function getType()
  36.     {
  37.         return 'multiselect';
  38.     }
  39.     /**
  40.      * @see EditableInterface::getData
  41.      *
  42.      * @return array
  43.      */
  44.     public function getData()
  45.     {
  46.         return $this->values;
  47.     }
  48.     /**
  49.      * @see EditableInterface::frontend
  50.      *
  51.      * @return string
  52.      */
  53.     public function frontend()
  54.     {
  55.         return implode(','$this->values);
  56.     }
  57.     /**
  58.      * @return array
  59.      */
  60.     public function getDataEditmode()
  61.     {
  62.         return $this->values;
  63.     }
  64.     /**
  65.      * @see EditableInterface::setDataFromResource
  66.      *
  67.      * @param string $data
  68.      *
  69.      * @return $this
  70.      */
  71.     public function setDataFromResource($data)
  72.     {
  73.         $this->values = \Pimcore\Tool\Serialize::unserialize($data);
  74.         return $this;
  75.     }
  76.     /**
  77.      * @see EditableInterface::setDataFromEditmode
  78.      *
  79.      * @param mixed $data
  80.      *
  81.      * @return $this
  82.      */
  83.     public function setDataFromEditmode($data)
  84.     {
  85.         if (empty($data)) {
  86.             $this->values = [];
  87.         } elseif (is_string($data)) {
  88.             $this->values explode(','$data);
  89.         } elseif (is_array($data)) {
  90.             $this->values $data;
  91.         }
  92.         return $this;
  93.     }
  94.     /**
  95.      * @return bool
  96.      */
  97.     public function isEmpty()
  98.     {
  99.         return empty($this->values);
  100.     }
  101.     /**
  102.      * @deprecated
  103.      *
  104.      * @param Model\Webservice\Data\Document\Element $wsElement
  105.      * @param Model\Document\PageSnippet $document
  106.      * @param array $params
  107.      * @param Model\Webservice\IdMapperInterface|null $idMapper
  108.      *
  109.      * @throws \Exception
  110.      */
  111.     public function getFromWebserviceImport($wsElement$document null$params = [], $idMapper null)
  112.     {
  113.         $data $this->sanitizeWebserviceData($wsElement->value);
  114.         if ($data->values === null) {
  115.             $this->values = [];
  116.         } elseif ($data->values instanceof  \stdClass) {
  117.             $this->values get_object_vars($data->values);
  118.         } else {
  119.             throw new \Exception('cannot get values from web service import - invalid data');
  120.         }
  121.     }
  122. }
  123. class_alias(Multiselect::class, 'Pimcore\Model\Document\Tag\Multiselect');