HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
File: D:/HostingSpaces/SBogers85/equichecker.com/app/KommaApp/Kms/Core/Attributes/KmsMultiSelect.php
<?php
/**
 *
 *
 * @author      Komma <info@komma.pro>
 * @copyright   (c) 2012-2016, Komma Mediadesign
 */

namespace KommaApp\Kms\Core\Attributes;

use View;

class KmsMultiSelect extends KmsAttribute
{

    public $label;
    public $placeholder;
    protected $data = [];
    protected $exclude;
    public $foreach = '';

    function __construct($key, $value, array $options = [], array $errors = [], $siteId = null, $languageId = null, $section = null, $foreach = null)
    {
        parent::__construct($key, $value, $options, $errors, $siteId, $languageId, $section, $foreach);

        $this->label = $this->getOption('label', $key);
        $this->placeholder = $this->getOption('placeholder', $key);
        $this->exclude = $this->getOption('exclude');
        $this->setData($this->getOption('data', $key));
        $this->foreach = $foreach;
    }

    public function setData($data)
    {

        if (is_string($data)) {
            $data = explode('@', $data);
            $method = array_pop($data);
            $class = $data[0];
            $this->data = \App::make($class)->{$method}($this->siteId, $this->languageId, $this->exclude);

            return $this->data;
        }

        return $this->data = $data;
    }

    public function getData($type = null)
    {

        if($type == 'JSON') return json_encode($this->data);

        return $this->data;
    }

    public function getSelected()
    {
        foreach ($this->data as $dataElement) {
            if ($dataElement['value'] == $this->getValue()) {
                return '{value}';
            }
        }
    }

    /**
     * Set the value for displaying
     * @return mixed
     */
    public function setValue($value)
    {

        $this->value = $value;
        $this->setData($this->getOption('data', $this->getKey()));

        return $value;
    }

    public function getValue($post = false)
    {

        $sessionVar = \Form::getValueAttribute($this->key);
        if ($sessionVar) return str_replace('"', "'", $sessionVar);

        if ($this->value) return $this->value;
        return '[]';
    }

    /**
     * Ths getter is used for the value in the form.
     *
     * @return mixed|string
     */
    public function getFormValue(){

        return $this->getValue();

        $sessionVar = \Form::getValueAttribute($this->key);
        if ($sessionVar) return str_replace('"', "'", $sessionVar);

        //If the foreach is set and is allsites, and the siteid is an existing kery in the value return valuep[{site_id}]
        if ($this->foreach == 'AllSites' && isset($this->value[$this->siteId])) return $this->value[$this->siteId];

        if ($this->value) return $this->value;
        return '[]';
    }

    public function render()
    {
        return View::make('kms/attributes.multiSelect', [
            'attribute' => $this
        ]);
    }
}