/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Event::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, 'plugin_id' => $this->plugin_id, 'app_id' => $this->app_id, 'status' => $this->status]); $query->andFilterWhere(['like', 'trigger_class', $this->trigger_class])->andFilterWhere(['like', 'trigger_event', $this->trigger_event])->andFilterWhere(['like', 'handler_method', $this->handler_method]); return $dataProvider; }
/** * finds and creates app event manager from its settings * @param Application $app yii app * @return EventManager app event manager component * @throws Exception Define event manager */ public function getEventManager($app) { if ($this->_eventManager) { return $this->_eventManager; } foreach ($app->components as $name => $config) { $class = is_string($config) ? $config : @$config['class']; // if eventManager component in config if ($class == str_replace('Bootstrap', 'Manager', get_called_class())) { $this->_eventManager = $app->{$name}->events; } // this class. set $appId from config if ($class == str_replace('Manager', 'Bootstrap', get_called_class())) { if ($app->{$name}->appId) { $this->appId = $app->{$name}->appId; } } } $events = ModelEvent::eventList($this->appId); // merge config events with plugins $this->_eventManager = array_merge_recursive($events, $this->_eventManager); $app->setComponents(['eventManager' => ['class' => 'lo\\plugins\\components\\EventManager', 'events' => $this->_eventManager]]); return $this->_eventManager = $app->eventManager; }
/** * Finds the Event model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Event the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Event::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * @return \yii\db\ActiveQuery */ public function getEvents() { return $this->hasMany(Event::className(), ['plugin_id' => 'id']); }
/** * Delete events * @param array $data * @return bool */ protected function deleteEvent($data) { foreach (Event::find()->where($data)->all() as $event) { $event->delete(); } }