<commit_before><?php
/**
 * SelectTree
 *
 * @author <NAME> <<EMAIL>>
 * @link http://skeeks.com/
 * @copyright 2010-2014 SkeekS (Sx)
 * @date 13.11.2014
 * @since 1.0.0
 */

namespace skeeks\cms\widgets\formInputs\selectTree;

use skeeks\cms\Exception;
use skeeks\cms\helpers\UrlHelper;
use skeeks\cms\models\CmsTree;
use skeeks\cms\models\Tree;
use skeeks\cms\modules\admin\Module;
use skeeks\cms\modules\admin\widgets\ActiveForm;
use skeeks\cms\widgets\formInputs\selectTree\assets\SelectTreeInputWidgetAsset;
use skeeks\cms\widgets\Pjax;
use yii\helpers\ArrayHelper;
use yii\helpers\Html;
use yii\helpers\Json;
use yii\widgets\InputWidget;
use Yii;

/**
 *
 *
 *  <?= $form->field($model, 'treeIds')->widget(
 * \skeeks\cms\widgets\formInputs\selectTree\SelectTreeInputWidget::class,
 * [
 * 'multiple' => true
 * ]
 * ); ?>
 *
 *
 * @property CmsTree[] $sections
 *
 * Class SelectTreeInputWidget
 *
 * @package skeeks\cms\widgets\formInputs\selectTree
 */
class SelectTreeInputWidget extends InputWidget
{
    public static $autoIdPrefix = 'SelectTreeInputWidget';

    /**
     * @var array
     */
    public $clientOptions = [];
    /**
     * @var array
     */
    public $wrapperOptions = [];

    /**
     * @see skeeks\cms\widgets\tree\CmsTreeWidget options
     *
     * @var array
     */
    public $treeWidgetOptions = [];
    public $treeWidgetClass = 'skeeks\cms\widgets\tree\CmsTreeWidget';

    /**
     * @var bool
     */
    public $multiple = false;

    /**
     * @var null|callable
     */
    public $isAllowNodeSelectCallback = null;

    public function init()
    {
        $this->treeWidgetOptions = ArrayHelper::merge([
            "models" => [],
            "sessionName" => 'select-' . (int)$this->multiple,
            "viewNodeContentFile" => '@skeeks/cms/widgets/formInputs/selectTree/views/_tree-node',

            'pjaxOptions' =>
                [
                    'enablePushState' => false,
                ],

            'contextData' => [
                'selectTreeInputWidget' => $this
            ]
        ], $this->treeWidgetOptions);

        $this->wrapperOptions['id'] = $this->id . "-wrapper";

        $this->clientOptions['id'] = $this->id;
        $this->clientOptions['wrapperid'] = $this->wrapperOptions['id'];

        parent::init();
    }

    /**
     * @inheritdoc
     */
    public function run()
    {
        $value = $this->model->{$this->attribute};
        $items = $value;
        if ($value && is_string($value) || is_int($value)) {
            $items = [$value => $value];
        } else if (is_array($value)) {
            $newValue = [];
            foreach ($value as $k => $v) {
                $newValue[$v] = $v;
            }
            $items = $newValue;
        }

        if (!$items) {
            $items = [];
        }

        if (is_array($items)) {
            $tmpItems = [];
            foreach ($items as $key => $item) {
                if ($item instanceof CmsTree) {
                    $tmpItems[$item->id] = $item->id;
                }
            }

            if ($tmpItems) {
                $items = $tmpItems;
            }

        }

        $this->options['multiple'] = $this->multiple;
        Html::addCssClass($this->options, 'sx-widget-element');

        $select = Html::activeListBox($this->model, $this->attribute, $items, $this->options);

        $this->clientOptions['value'] = $value;
        $this->clientOptions['multiple'] = (int)$this->multiple;<commit_msg>Copy elements<commit_after><?php
/**
 * SelectTree
 *
 * @author <NAME> <<EMAIL>@skeeks.com>
 * @link http://skeeks.com/
 * @copyright 2010-2014 SkeekS (Sx)
 * @date 13.11.2014
 * @since 1.0.0
 */

namespace skeeks\cms\widgets\formInputs\selectTree;

use skeeks\cms\Exception;
use skeeks\cms\helpers\UrlHelper;
use skeeks\cms\models\CmsTree;
use skeeks\cms\models\Tree;
use skeeks\cms\modules\admin\Module;
use skeeks\cms\modules\admin\widgets\ActiveForm;
use skeeks\cms\widgets\formInputs\selectTree\assets\SelectTreeInputWidgetAsset;
use skeeks\cms\widgets\Pjax;
use yii\helpers\ArrayHelper;
use yii\helpers\Html;
use yii\helpers\Json;
use yii\widgets\InputWidget;
use Yii;

/**
 *
 *
 *  <?= $form->field($model, 'treeIds')->widget(
 * \skeeks\cms\widgets\formInputs\selectTree\SelectTreeInputWidget::class,
 * [
 * 'multiple' => true
 * ]
 * ); ?>
 *
 *
 * @property CmsTree[] $sections
 *
 * Class SelectTreeInputWidget
 *
 * @package skeeks\cms\widgets\formInputs\selectTree
 */
class SelectTreeInputWidget extends InputWidget
{
    public static $autoIdPrefix = 'SelectTreeInputWidget';

    /**
     * @var array
     */
    public $clientOptions = [];
    /**
     * @var array
     */
    public $wrapperOptions = [];

    /**
     * @see skeeks\cms\widgets\tree\CmsTreeWidget options
     *
     * @var array
     */
    public $treeWidgetOptions = [];
    public $treeWidgetClass = 'skeeks\cms\widgets\tree\CmsTreeWidget';

    /**
     * @var bool
     */
    public $multiple = false;

    /**
     * @var null|callable
     */
    public $isAllowNodeSelectCallback = null;

    public function init()
    {
        $this->treeWidgetOptions = ArrayHelper::merge([
            "models" => [],
            "sessionName" => 'select-' . (int)$this->multiple,
            "viewNodeContentFile" => '@skeeks/cms/widgets/formInputs/selectTree/views/_tree-node',

            'pjaxOptions' =>
                [
                    'enablePushState' => false,
                ],

            'contextData' => [
                'selectTreeInputWidget' => $this
            ]
        ], $this->treeWidgetOptions);

        $this->wrapperOptions['id'] = $this->id . "-wrapper";

        $this->clientOptions['id'] = $this->id;
        $this->clientOptions['wrapperid'] = $this->wrapperOptions['id'];

        parent::init();
    }

    /**
     * @inheritdoc
     */
    public function run()
    {
        $value = $this->model->{$this->attribute};
        $items = $value;
        if ($value && is_string($value) || is_int($value)) {
            $items = [$value => $value];
        } else if (is_array($value)) {
            $newValue = [];
            foreach ($value as $k => $v) {
                if ($v instanceof CmsTree) {
                    $newValue[$v->id] = $v->id;
                } else {
                    $newValue[$v] = $v;
                }
            }
            $items = $newValue;
        }

        if (!$items) {
            $items = [];
        }

        if (is_array($items)) {
            $tmpItems = [];
            foreach ($items as $key => $item) {
                if ($item instanceof CmsTree) {
                    $tmpItems[$item->id] = $item->id;
                }
            }

            if ($tmpItems) {
                $items = $tmpItems;
            }

        }

        $this->options['multiple'] = $this->multiple;
        Html::addCssClass($this->options, 'sx-widget-element');

        $select = Html::activeListBox($this->model, $this->attribute, $items, $this->options);

        $this->clientOptions['value'] = $value;
        $this->clientOptions['multiple'] = (int)$this->multiple;
{'fraction_non_alphanumeric': 0.16351142897209367, 'fraction_numerical': 0.005328845884167719, 'mean_word_length': 2.0439607341015793, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 85, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4625276', 'n_tokens_mistral': 2306, 'n_tokens_neox': 2183, 'n_words': 365}