/**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Term::find()->joinWith('translations')->roots();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['name' => $this->name]);
     return $dataProvider;
 }
 /**
  * Returns a structured list of terms, formatted for usage in a dropdownlist
  *
  * @param   int     $root       The id of the root category
  * @return  array
  */
 public static function getDropDownListItems($root = null)
 {
     $items = [];
     // Load the provided root category and check if it exists
     $model = Term::findOne($root);
     if (!$model) {
         return $items;
     }
     // Load all leaves
     $terms = $model->leaves()->all();
     foreach ($terms as $k => $term) {
         $arrow = '';
         if ($term->level > 0) {
             $arrow = str_repeat("—", $term->{$model->depthAttribute} * 2);
             $arrow .= "> ";
         }
         $items[$term->id] = $arrow . $term->name;
     }
     return $items;
 }
 /**
  * Saves the new sort order
  * @return mixed
  */
 public function actionSort()
 {
     try {
         $post = Yii::$app->request->post();
         //if(!isset($post['ids']))
         //throw new Exception(Yii::t('infoweb/menu', 'Invalid items'));
         // The term you dragged to change it's position
         $term = Term::findOne($post['term']);
         // The parent or target of the term after your dragged it
         $parent = Term::findOne($post['parent']);
         // Direction: move the term before, after or first (=new list) the new parent
         if ($post['direction'] == 'before') {
             $term->moveBefore($parent);
         } elseif ($post['direction'] == 'first') {
             $term->moveAsFirst($parent);
         } else {
             $term->moveAfter($parent);
         }
         $data['status'] = 1;
     } catch (Exception $e) {
         Yii::error($e->getMessage());
         $data['status'] = 0;
     }
     Yii::$app->response->format = 'json';
     return $data;
 }
 /**
  * Finds the Page model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param string $id
  * @return Page the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Term::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException(Yii::t('app', 'The requested item does not exist'));
     }
 }
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getTerm()
 {
     return $this->hasOne(Term::className(), ['id' => 'term_id']);
 }