Example #1
0
 /**
  * Finds the Books model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Books the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Books::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Example #2
0
 /**
  * Returns ActiveDataProvider with sort and filters
  * @param array
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Books::find()->joinWith('author');
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $dataProvider->setSort(['attributes' => ['id', 'name', 'preview', 'date', 'date_create', 'fullName' => ['asc' => ['authors.lastname' => SORT_ASC, 'authors.firstname' => SORT_ASC], 'desc' => ['authors.lastname' => SORT_DESC, 'authors.firstname' => SORT_DESC], 'label' => 'fullName']]]);
     if (!($this->load($params) && $this->validate())) {
         //$query->joinWith(['author']);
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'author_id' => $this->author_id, 'preview' => $this->preview, 'date' => $this->date]);
     $query->andFilterWhere(['between', 'date', $this->dateFrom, $this->dateTo]);
     $query->andFilterWhere(['like', 'name', $this->name]);
     return $dataProvider;
 }
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Books::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, 'date_create' => $this->date_create, 'date_update' => $this->date_update, 'date' => $this->date, 'author_id' => $this->author_id]);
     // adding some extra filters for search purposes
     $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'preview', $this->preview]);
     $query->andFilterWhere(['>=', 'date', $this->date_from ? strtotime($this->date_from . ' 00:00:00') : null])->andFilterWhere(['<=', 'date', $this->date_to ? strtotime($this->date_to . ' 23:59:59') : null]);
     return $dataProvider;
 }
Example #4
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Books::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $dataProvider->setSort(['class' => 'yii\\data\\Sort', 'attributes' => ['id', 'name', 'preview', 'author_id' => ['asc' => ['authors.lastname' => SORT_ASC, 'authors.firstname' => SORT_ASC], 'desc' => ['authors.lastname' => SORT_DESC, 'authors.firstname' => SORT_DESC]], 'date', 'date_create']]);
     $this->load($params);
     $query->joinWith(['author']);
     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, 'date_create' => $this->date_create, 'date_update' => $this->date_update, 'date' => $this->date, 'author_id' => $this->author_id]);
     if (!empty($this->date_from)) {
         $query->andFilterWhere(['>=', 'date', strtotime($this->date_from . ' 00:00:01')]);
     }
     if (!empty($this->date_to)) {
         $query->andFilterWhere(['<=', 'date', strtotime($this->date_to . ' 23:59:59')]);
     }
     $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'preview', $this->preview]);
     return $dataProvider;
 }
Example #5
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Books::find()->joinWith('author');
     $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['attributes' => ['id', 'name', 'preview', 'date', 'date_create', 'author.lastname' => ['asc' => ['author.lastname' => SORT_ASC], 'desc' => ['author.lastname' => SORT_DESC]]]]]);
     $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, 'author_id' => $this->author_id]);
     $query->andFilterWhere(['like', 'name', $this->name]);
     if (!empty($this->dateFrom) && !empty($this->dateTo)) {
         $dateFrom = explode('/', $this->dateFrom);
         krsort($dateFrom);
         $dateFrom = implode('-', $dateFrom);
         $dateTo = explode('/', $this->dateTo);
         krsort($dateTo);
         $dateTo = implode('-', $dateTo);
         $query->andFilterWhere(['between', 'date', $dateFrom, $dateTo]);
     }
     return $dataProvider;
 }
Example #6
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getBooks()
 {
     return $this->hasMany(Books::className(), ['author_id' => 'id']);
 }