/**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Item::find();
     $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;
     }
     $query->andFilterWhere(['id' => $this->id, 'status' => $this->status]);
     $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'handler_class', $this->handler_class])->andFilterWhere(['like', 'url', $this->url])->andFilterWhere(['like', 'version', $this->version])->andFilterWhere(['like', 'text', $this->text])->andFilterWhere(['like', 'author', $this->author])->andFilterWhere(['like', 'author_url', $this->author_url]);
     return $dataProvider;
 }
 /**
  * eventList for BootstrapManager
  * @return array
  */
 public static function eventList($appId = 'frontend')
 {
     // (frontentd and common) or (backend and common) events
     $cond = $appId == 'backend' ? '>=' : '<=';
     $attributes = ['trigger_class', 'trigger_event', 'plugin_id', 'pos', 'handler_method'];
     // handler_class
     $order = array_combine($attributes, array_fill(0, count($attributes), SORT_ASC));
     $allEvents = self::find()->select('t.*')->from(self::tableName() . 'AS t')->joinWith(['plugin'])->where(['t.status' => self::STATUS_ACTIVE, Item::tableName() . '.status' => Item::STATUS_ACTIVE])->andWhere([$cond, 't.app_id', App::APP_COMMON])->orderBy($order)->all();
     $result = [];
     foreach ($allEvents as $data) {
         if ($data->data) {
             $handler = [[$data->plugin->handler_class, $data->handler_method], json_decode($data->data, true)];
         } else {
             $handler = [$data->plugin->handler_class, $data->handler_method];
         }
         $result[$data->trigger_class][$data->trigger_event][] = $handler;
     }
     return $result;
 }
 /**
  * Include Plugins
  * Include all active plugins that are in the database
  *
  */
 protected function includePlugins()
 {
     if (self::$plugins_active and !empty(self::$plugins_active)) {
         // Validate and include our found plugins
         foreach (self::$plugins_active as $handlerClass => $value) {
             // The plugin information being added to the database
             $data['Item'] = ["handler_class" => $handlerClass, "name" => trim(self::$plugins_pool[$handlerClass]['plugin_info']['name']), "url" => trim(self::$plugins_pool[$handlerClass]['plugin_info']['url']), "version" => trim(self::$plugins_pool[$handlerClass]['plugin_info']['version']), "text" => trim(self::$plugins_pool[$handlerClass]['plugin_info']['text']), "author" => trim(self::$plugins_pool[$handlerClass]['plugin_info']['author']), "author_url" => trim(self::$plugins_pool[$handlerClass]['plugin_info']['author_url'])];
             $model = Item::findOne(['handler_class' => $handlerClass]);
             if ($model->load($data) && $model->save()) {
                 // here install events to Event
                 $this->includeEvents($model->id, $handlerClass);
             }
         }
     }
 }