/**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = OptionsList::find();
     // add conditions that should always apply here
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     // grid filtering conditions
     $query->andFilterWhere(['id' => $this->id, 'is_required' => $this->is_required, 'type_id' => $this->type_id, 'active' => $this->active, 'sort' => $this->sort, 'minLenght' => $this->minLenght, 'maxLenght' => $this->maxLenght]);
     $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'alias', $this->alias])->andFilterWhere(['like', 'model', $this->model]);
     return $dataProvider;
 }
 /** Render widget */
 public function run()
 {
     if (count($this->options_alias_array) == 0) {
         $options_array = $this->behavior->getOptionsList();
     } else {
         $options_array = OptionsList::find()->where(['IN', 'alias', $this->options_alias_array])->all();
     }
     $r_arr = [];
     /**
      * @var $opt OptionsList
      */
     foreach ($options_array as $i => $opt) {
         $r_arr[$i]['name'] = $opt->name;
         $r_arr[$i]['value'] = $this->behavior->getOptionValueByAlias($opt->alias);
     }
     return $this->render('optionsFrontWidget', ['options_array' => $r_arr]);
 }
Exemple #3
0
/**
 * Получаем массив моделей которые есть в OptionsList
 *
 * @return array
 */
function getOps()
{
    $ops = [];
    $options = OptionsList::find()->all();
    foreach ($options as $option) {
        /*$mn = MyHelper::ADMIN_MODEL_NAMESPACE.$option->model;
          $m = new $mn();*/
        if ($option->model) {
            $pattern = '/\\-/';
            if (!preg_match($pattern, $option->model)) {
                $ops[$option->model] = MyHelper::getModelFrontName($option->model);
            } else {
                $ops[$option->model] = MyHelper::getComplexModelChildName($option->model);
            }
        }
    }
    return $ops;
    //return \yii\helpers\ArrayHelper::map($options, 'model', 'name');
}
 /**
  * Получаем значение параметра конкретной модели по алиасу
  *
  * @param $alias                string string
  * @param $relations_model_name string
  *
  * @return mixed
  */
 public function getChildOptionValueByAlias($alias, $relations_model_name = 'Cats-Items')
 {
     /**
      * @var $optionList OptionsList
      * @var $option     Options
      */
     $optionList = OptionsList::find()->where(['alias' => $alias])->one();
     $option = ChildOptions::find()->where(['model_id' => $this->owner->id, 'model' => $relations_model_name, 'option_id' => $optionList->id])->one();
     if (in_array($optionList->type->alias, MyHelper::TYPES_WITH_PRESET_ARRAY)) {
         $return = $optionList->preset->value($option->value);
     } elseif (in_array($optionList->type->alias, MyHelper::TYPES_WITH_MULTIPLE_PRESET_ARRAY)) {
         $optionM = ChildOptionMultiple::find()->where(['value' => $option->value])->one();
         $return = $optionList->preset->value($optionM->value);
     } else {
         $return = $option->value;
     }
     return $return;
 }
 public function actionCommonOptionsList($model_name)
 {
     $CommonOptionsList = OptionsList::find()->where(['model' => $model_name])->all();
     return $CommonOptionsList;
 }
 public function actionIndex()
 {
     $cats = Cats::find()->all();
     $optionsList = OptionsList::find()->all();
     $db = Yii::$app->db;
     $sql = $db->createCommand('SELECT model_id, GROUP_CONCAT(DISTINCT option_id) AS option_ids  FROM models_options_list GROUP BY model_id');
     $q = $sql->queryAll();
     $original_array = [];
     // изначальный массив для начала работы
     foreach ($q as $arr) {
         $original_array[] = [[$arr['model_id']], explode(',', $arr['option_ids'])];
     }
     foreach ($original_array as $index => $block_arr) {
         if ($index != 0) {
             foreach ($block_arr[1] as $option_id) {
                 foreach ($original_array as $sec_indx => $second_loop) {
                     $compare_index = $sec_indx;
                     $compare_arr = $original_array[$compare_index][1];
                     if (in_array($option_id, $compare_arr)) {
                         //array_push($original_array[ $compare_index ][1], $option_id);
                         if (!in_array($block_arr[0][0], $original_array[$compare_index][0])) {
                             array_push($original_array[$compare_index][0], $block_arr[0][0]);
                         }
                         array_slice($original_array[$index][1], $option_id);
                     }
                 }
             }
         }
     }
     $uniqModelsCats_id = ModelsOptionsList::find()->select('model_id')->distinct()->asArray()->all();
     $modelCats = ModelsOptionsList::find()->all();
     $i = 0;
     $return_array = [];
     $model_id_array = [];
     /*foreach ($modelCats as $modelCat) {
     				$m_id = $modelCat->model_id;
     				$o_id = $modelCat->option_id;
     				if (count($return_array) == 0) {
     					$i                  = $i + 1;
     					$return_array[ $i ] = [[$m_id], [$o_id]];
     				} else {
     					$inModelArray  = $this->in_arrays($m_id, $return_array, 0);
     					$inOptionArray = $this->in_arrays($o_id, $return_array, 1);
     					$indxM2        = $this->in_arrays_index($m_id, $return_array, 0);
     					$indxO2        = $this->in_arrays_index($o_id, $return_array, 1);
     					print $indxM2 . '-' . $indxO2 . '___' . $inModelArray . '-' . $inOptionArray . '<br>';
     
     					if ($inModelArray AND !$inOptionArray) {
     						array_push($return_array[ $i ][1], $o_id);
     					} elseif (!$inModelArray AND $inOptionArray) {
     						array_push($return_array[ $i ][0], $m_id);
     					}
     					elseif (!$inModelArray AND !$inOptionArray) {
     						$i                  = $i + 1;
     						$return_array[ $i ] = [[$m_id], [$o_id]];
     					}
     					print_r($return_array);
     				}
     			}*/
     /*foreach ($uniqModelsCats_id as $model_id) {
     			$curent_model_option_id_array = ModelsOptionsList::find()->select('option_id')->where(['model_id'=>$model_id])->distinct()->asArray()->all();
     			$model_id_array[] = $model_id;
     			$return_array[] = [$model_id_array, $curent_model_option_id_array];
     		}*/
     return $this->render('index', ['cats' => $cats, 'optionsList' => $optionsList, 'uniqModelsId' => $uniqModelsCats_id, 'return_array' => $original_array]);
 }
 /**
  * @return OptionsList[]
  */
 public function getOptionsList()
 {
     $model_name = MyHelper::modelFromNamespace($this->model_name);
     $options = OptionsList::find()->where(['model' => $model_name, 'active' => 1])->orderBy('sort')->all();
     return $options;
 }
 /**
  * Finds the OptionsList model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  *
  * @param integer $id
  *
  * @return OptionsList the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = OptionsList::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }