/**
  * @inheritdoc
  */
 public function bootstrap($app)
 {
     if (!Module::isEnabled()) {
         return true;
     }
     $events = Yii::$app->db->getTableSchema(Item::tableName()) ? (new Item())->moduleEventList() : [];
     EventManagerBootstrap::getEventManager($app)->attachEvents($events);
     return $this;
 }
Exemplo n.º 2
0
 public function moduleEventList()
 {
     $attributes = ['trigger_class', 'trigger_event', 'handler_class', 'handler_method'];
     $order = array_combine($attributes, array_fill(0, count($attributes), SORT_ASC));
     $allEvents = Item::find()->where(['active' => 1])->select($attributes)->orderBy($order)->asArray()->all();
     $result = [];
     foreach ($allEvents as $data) {
         $result[$data['trigger_class']][$data['trigger_event']][] = [$data['handler_class'], $data['handler_method']];
     }
     return $result;
 }
Exemplo n.º 3
0
 /**
  * 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]);
     $dataProvider->sort->defaultOrder = ['trigger_class' => SORT_ASC, 'trigger_event' => SORT_ASC, 'handler_class' => SORT_ASC, 'handler_method' => SORT_ASC];
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id]);
     $query->andFilterWhere(['like', 'trigger_class', $this->trigger_class])->andFilterWhere(['like', 'trigger_event', $this->trigger_event])->andFilterWhere(['like', 'handler_class', $this->handler_class])->andFilterWhere(['like', 'handler_method', $this->handler_method]);
     return $dataProvider;
 }
 public function down()
 {
     return $this->dropTable(Item::tableName());
 }
 /**
  * Finds the Item model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Item the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Item::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }