/** * Lists all Books models. * @return mixed */ public function actionIndex() { //Yii::$app->user->isGuest; $authors = Authors::find()->all(); $get = Yii::$app->request->get()['Filter']; $dataProvider; $query = Books::find(); if (isset(Yii::$app->request->get()['Filter'])) { if ($get["author_id"] != 0) { $query->andWhere(['author_id' => $get["author_id"]]); } if ($get["title"] != "") { //$query->andWhere(['name' => $post["title"]]); $query->andWhere(['like', 'name', $get["title"]]); } if ($get["dateMin"] != "") { $query->andWhere('date > :dateMin', [':dateMin' => $get["dateMin"]]); } if ($get["dateMax"] != "") { $query->andWhere('date < :dateMax', [':dateMax' => $get["dateMax"]]); } } $dataProvider = new ActiveDataProvider(['query' => $query]); return $this->render('index', ['dataProvider' => $dataProvider, 'authors' => $authors]); }
public function search($params) { Yii::$app->session['BooksSearch'] = $params; $query = Books::find(); $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 5]]); $dataProvider->setSort(['attributes' => ['id', 'name', 'preview', 'authorfullname' => ['asc' => ['authors.firstname' => SORT_ASC, 'authors.lasttname' => SORT_ASC], 'desc' => ['authors.firstname' => SORT_DESC, 'authors.lasttname' => SORT_DESC], 'label' => Yii::t('app', 'Author'), 'default' => SORT_ASC], 'date', 'date_create']]); $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'); $query->joinWith(['author']); return $dataProvider; } $query->andFilterWhere(['like', 'name', $this->name]); if ($this->date_from) { $query->andFilterWhere(['>=', 'date', $this->date_from]); } if ($this->date_to) { $query->andFilterWhere(['<=', 'date', $this->date_to]); } if ($this->author_id) { $query->andFilterWhere(['author_id' => $this->author_id]); } $query->joinWith(['author']); return $dataProvider; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Books::find()->with('authors'); $dataProvider = new ActiveDataProvider(['query' => $query]); $dataProvider->setSort(['attributes' => ['id', 'name', 'authorFullName' => ['asc' => ['authors.firstname' => SORT_ASC, 'authors.lastname' => SORT_ASC], 'desc' => ['authors.firstname' => SORT_DESC, 'authors.lastname' => SORT_DESC], 'label' => 'Автор'], 'date_update', 'date_create', 'date']]); $this->load($params); // валидация if (!$this->validate()) { $query->joinWith(['authors']); return $dataProvider; } // Фильтр по Автору $query->joinWith(['authors' => function ($q) { $this->authorFullName = trim($this->authorFullName); if ($this->authorFullName) { $Asearch = str_replace(" ", "|", $this->authorFullName); $q->where('`authors`.`firstname` RLIKE "' . $Asearch . '" ' . 'OR `authors`.`lastname` RLIKE "' . $Asearch . '"'); } }]); /* $query->andFilterWhere([ 'name' => $this->name, 'authors.firstname' => $this->authorFullName, ]);*/ $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['BETWEEN', 'date', $this->date_1, $this->date_2]); 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; } if ($this->author_id) { $query->andFilterWhere(['author_id' => $this->author_id]); } if ($this->date_from) { if ($this->date_till) { $query->andFilterWhere(['date' => ['between', $this->date_from, $this->date_till]]); } else { $query->andFilterWhere(['>=', 'date', $this->date_from]); } } elseif ($this->date_till) { $query->andFilterWhere(['<=', 'date', $this->date_till]); } if ($this->name) { $query->andFilterWhere(['like', 'name', $this->name]); } return $dataProvider; }
/** * Lists all Books models. * @return mixed */ public function actionIndex() { $searchModel = new BooksSearch(); // $dataProvider = $searchModel->search(Yii::$app->request->queryParams); $dataProvider = new ActiveDataProvider(['query' => Books::find()]); return $this->render('index', ['dataProvider' => $dataProvider, 'searchModel' => $searchModel]); }
/** * Get query for book search * @return [QueryInterface] */ public function getSearchQuery() { $query = Books::find(); //Author $query = $query->filterWhere(['author_id' => $this->author_id]); //Name if (!empty($this->name)) { $query = $query->andWhere(['like', 'name', $this->name]); } //Date if ($this->firstTimestamp != 0 && $this->secondTimestamp != 0) { if ($this->firstTimestamp == $this->secondTimestamp) { $query = $query->andWhere(['=', 'date', $this->firstTimestamp]); } else { $query = $query->andWhere(['between', 'date', $this->firstTimestamp, $this->secondTimestamp]); } } else { if ($this->firstTimestamp != 0) { $query = $query->andWhere(['>=', 'date', $this->firstTimestamp]); } else { if ($this->secondTimestamp != 0) { $query = $query->andWhere(['<=', 'date', $this->secondTimestamp]); } } } return $query; }
public function actionRemove($id) { if (Yii::$app->request->isAjax) { $model = Books::find()->where(['id' => $id])->one(); $model->delete(); Yii::$app->response->format = Response::FORMAT_JSON; return array('result' => true); } return $this->redirect('index.php?r=site%2Fbooks'); }
public function actionIndex($order = false, $order_type = false, $search_key = false) { $order_field = $order ? $order : 'id'; $order_type = $order_type ? $order_type == 'DESC' ? SORT_DESC : SORT_ASC : SORT_ASC; if ($search_key) { $query = Books::find()->andFilterWhere(['or', ['like', 'author', $search_key], ['like', 'name', $search_key]]); } else { $query = Books::find(); } return new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => [$order_field => $order_type]]]); }
public static function getAuthorBooks($author_id, $return_count = true) { $author_id = (int) $author_id; $data = Books::find()->where('authors LIKE "%,' . $author_id . '" OR authors LIKE "%' . $author_id . '," OR authors LIKE "' . $author_id . '"'); if ($return_count) { $data = (int) $data->count(); } else { $data = $data->all(); } return $data; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Books::find()->addSelect([$this->tableName() . ".*", "CONCAT(authors.firstname, ' ', authors.lastname) AS author_fullname"])->joinWith(['author']); $dataProvider = new ActiveDataProvider(['query' => $query]); $dataProvider->sort->attributes['author'] = ['asc' => ['authors.firstname' => SORT_ASC], 'desc' => ['authors.firstname' => 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(['like', 'books.name', $this->name]); // поиск по дате от/до if (!empty($this->book_date_from) and !empty($this->book_date_to)) { // конвертирую в корректный формат времени и добавляю четкие временные границы $book_date_from = Yii::$app->formatter->asDatetime(str_replace("/", "-", $this->book_date_from), 'dd-MM-yyyy 00:00:00'); $book_date_to = Yii::$app->formatter->asDatetime(str_replace("/", "-", $this->book_date_to), 'dd-MM-yyyy 23:59:59'); $book_date_from = Yii::$app->formatter->asTimestamp($book_date_from); $book_date_to = Yii::$app->formatter->asTimestamp($book_date_to); $query->andFilterWhere(['between', 'books.date', $book_date_from, $book_date_to]); } // поиск по автору if ($this->author_fullname == 7 or in_array(trim(mb_strtolower($this->author)), array('без', 'без привязки', 'без привязки к автору'))) { // для книг без привязки к автору - из books $query->andFilterWhere(['=', 'author_id', 0]); } else { // из authors $query->andFilterWhere(['like', 'authors.firstname', $this->author]); $query->andFilterWhere(['=', 'authors.id', $this->author_fullname]); } /////////////////////// доп параметры для filterModel (если раскомменчены filterModel и Pjax в books/index.php) $query->andFilterWhere(['=', 'books.id', $this->id])->andFilterWhere(['like', 'books.preview', $this->preview]); // дата Выхода книги if (!empty($this->date)) { // конвертирую в корректный формат времени и добавляю четкие временные границы $book_date_from = Yii::$app->formatter->asDatetime(str_replace("/", "-", $this->date), 'dd-MM-yyyy 00:00:00'); $book_date_to = Yii::$app->formatter->asDatetime(str_replace("/", "-", $this->date), 'dd-MM-yyyy 23:59:59'); $book_date_from = Yii::$app->formatter->asTimestamp($book_date_from); $book_date_to = Yii::$app->formatter->asTimestamp($book_date_to); $query->andFilterWhere(['between', 'books.date', $book_date_from, $book_date_to]); } // дата Добавления книги if (!empty($this->date_create)) { // конвертирую в корректный формат времени и добавляю четкие временные границы $book_date_from = Yii::$app->formatter->asDatetime(str_replace("/", "-", $this->date_create), 'dd-MM-yyyy 00:00:00'); $book_date_to = Yii::$app->formatter->asDatetime(str_replace("/", "-", $this->date_create), 'dd-MM-yyyy 23:59:59'); $book_date_from = Yii::$app->formatter->asTimestamp($book_date_from); $book_date_to = Yii::$app->formatter->asTimestamp($book_date_to); $query->andFilterWhere(['between', 'books.date_create', $book_date_from, $book_date_to]); } /////////////////// return $dataProvider; }
public function search($params) { $query = Books::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { return $dataProvider; } $query->andFilterWhere(['author_id' => $this->author_id]); $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['<=', 'date', $this->date_to])->andFilterWhere(['>=', 'date', $this->date_from]); return $dataProvider; }
public function dashboard() { // Check Author authentication Session if (!Auth::check('default')) { return $this->redirect('Authors::login'); } // Retrieve current Author ID $author_id = Auth::check('default')->data['id']; // Retrieve Books from the current Author $conditions = array('Books.author_id' => Auth::check('default')->data['id']); $books = Books::find('all', compact('conditions')); return compact('books', 'author_id'); }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Books::find()->joinWith('bookAuthors')->asArray(); $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]); $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'issue_year', $this->issue_year])->andFilterWhere(['like', 'category', $this->category])->andFilterWhere(['like', 'annotation', $this->annotation]); 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, 'author_id' => $this->author_id != 0 ? $this->author_id : ''])->andFilterWhere(['between', 'date', $this->date_start, $this->date_end]); $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'preview', $this->preview]); return $dataProvider; }
public function delete() { // Check Author authentication Session if (!Auth::check('default')) { return $this->redirect('Authors::login'); } $book = Books::find($this->request->id); if ($book && $book->delete()) { Session::write('message', 'Book deleted'); $this->redirect(array('Authors::dashboard')); } else { Session::write('message', 'Book can not be deleted'); } }
/** * 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, 'is_published' => $this->is_published, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]); $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'link', $this->link]); 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]); $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['>=', 'date', self::dateFormating($this->firstDate)])->andFilterWhere(['<=', 'date', self::dateFormating($this->secondDate)]); 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); $query->andFilterWhere(['id' => $this->id, 'date_create' => $this->date_create, 'date_update' => $this->date_update, 'date' => $this->date, 'author_id' => $this->author_id]); if (strtotime($this->date_from)) { $query->andFilterWhere(['>=', 'date', strtotime($this->date_from)]); } if (strtotime($this->date_to)) { $query->andFilterWhere(['<=', 'date', strtotime($this->date_to)]); } $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'preview', $this->preview]); return $dataProvider; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Books::find(); // add conditions that should always apply here $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(['like', 'name', $this->name])->andFilterWhere(['author_id' => $this->author_id])->andFilterWhere(['>=', 'date', $this->date_from])->andFilterWhere(['<=', 'date', $this->date_to]); /*->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; }
/** * 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); $dataProvider->setSort(['attributes' => ['id', 'name', 'date_create', 'date_update', 'date', 'authorName' => ['asc' => ['authors.last_name' => SORT_ASC], 'desc' => ['authors.last_name' => SORT_DESC], 'label' => 'Автор']]]); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); $query->joinWith(['author']); return $dataProvider; } $query->andFilterWhere(['books.id' => $this->id, 'date_create' => $this->date_create, 'date_update' => $this->date_update, 'date' => $this->date]); // $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere([ // 'like', // 'preview_image', // $this->preview_image // ]); if ($this->author_id) { $query->andFilterWhere(['author_id' => $this->author_id]); } if ($this->name) { $query->andFilterWhere(['like', 'name', $this->name]); } if ($this->date_start && $this->date_end) { $ts1 = strtotime($this->date_start); $ts2 = strtotime($this->date_end); $query->andFilterWhere(['between', 'date', $ts1, $ts2]); } elseif ($this->date_start) { $ts = strtotime($this->date_start); $query->andWhere('date >= :TS', [":TS" => $ts]); } elseif ($this->date_end) { $ts = strtotime($this->date_end); $query->andWhere('date <= :TS', [":TS" => $ts]); } // if ($this->authorName) { // // filter by author name // $query->innerJoinWith([ // 'author' => function ($q) { // $q->where('authors.first_name LIKE "%' . $this->authorName . '%" OR authors.last_name LIKE "%' . $this->authorName . '%"'); // } // ]); // } else { // $query->innerJoinWith(['author']); // } return $dataProvider; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params, $group = null) { $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, 'book_category_id' => $this->book_category_id, 'views' => $this->views, 'year' => $this->year, 'created_at' => $this->created_at]); $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'annotation', $this->annotation])->andFilterWhere(['like', 'authors', $this->authors]); if (!empty($group)) { $query->groupBy([$group]); } return $dataProvider; }
/** * 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]); $dataProvider->setSort(['attributes' => ['id', 'name', 'date', 'date_create', 'author.fullName' => ['asc' => ['authors.firstname' => SORT_ASC, 'authors.lastname' => SORT_ASC], 'desc' => ['authors.firstname' => SORT_DESC, 'authors.lastname' => SORT_DESC], 'label' => 'Full Name', 'default' => SORT_ASC]]]); $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(['>=', 'date', $this->dateFrom]); $query->andFilterWhere(['<=', 'date', $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()->joinWith('author'); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { return $dataProvider; } $query->andFilterWhere(['author_id' => $this->author_id]); $query->andFilterWhere(['like', 'name', $this->name]); if (!empty($this->dateStart)) { $query->andFilterWhere(['>=', 'date', $this->dateStart]); } if (!empty($this->dateEnd)) { $query->andFilterWhere(['<=', 'date', $this->dateEnd]); } 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]); $query->joinWith(['author' => function ($query) { $query->from(['author' => 'authors']); }]); $dataProvider->sort->attributes['author.FullName'] = ['asc' => ['author.firstname' => SORT_ASC], 'desc' => ['author.firstname' => SORT_DESC]]; $this->load($params); if (!$this->validate()) { 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]); $query->andFilterWhere(['>=', 'date_create', $this->from_date]); $query->andFilterWhere(['<=', 'date_create', $this->to_date]); $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, 'author_id' => $this->author_id]); $query->andFilterWhere(['like', 'books.name', $this->name]); $query->joinWith('author'); $dataProvider->sort->attributes['author.name'] = ['asc' => ['vauthors.name' => SORT_ASC], 'desc' => ['vauthors.name' => SORT_DESC]]; if (!(is_null($this->startDate) || is_null($this->endDate) || $this->startDate == '' || $this->endDate == '')) { $query->andFilterWhere(['between', 'date', Yii::$app->formatter->asDatetime($this->startDate, 'yyyy-M-d'), Yii::$app->formatter->asDatetime($this->endDate, 'yyyy-M-d')]); } return $dataProvider; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { //$this->datefilterstart = date_create_from_format("Y-m-d", $this->datefilterstart)->getTimestamp(); //$this->datefilterend = date_create_from_format("Y-m-d", $this->datefilterstart)->getTimestamp(); $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(['author_id' => $this->author_id]); if (!empty($this->datefilterstart) && !empty($this->datefilterend)) { $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['between', 'date', strtotime($this->datefilterstart), strtotime($this->datefilterend)]); } elseif (empty($this->datefilterend)) { $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['between', 'date', strtotime($this->datefilterstart), time()]); } 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, 'author_id' => $this->author_id, 'date_create' => $this->date_create, 'date_update' => $this->date_update, 'date' => $this->date]); $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'preview', $this->preview]); if (!empty($this->date_start)) { $query->andFilterWhere(['>=', 'date', date('Y-m-d', strtotime($this->date_start))]); } if (!empty($this->date_end)) { $query->andFilterWhere(['<=', 'date', date('Y-m-d', strtotime($this->date_end))]); } 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]); if (!($this->load($params) && $this->validate())) { return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'date_update' => $this->date_update, 'date' => $this->date, 'author_id' => $this->author_id]); $query->andFilterWhere(['like', 'name', $this->name]); if ($this->min_date != '01/01/1970' && $this->min_date != '1970-01-01') { $query->andFilterWhere(['>=', 'date_create', date('Y-m-d', strtotime(str_replace('/', '-', $this->min_date)))]); } //if ($this->max_date != '01/01/1970') $query->andFilterWhere(['<', 'date_create', date('Y-m-d', strtotime(str_replace('/', '-', $this->max_date)))]); if ($this->max_date != '01/01/1970' && $this->max_date != '1970-01-01' && $this->max_date != '01-01-1970') { if (date('Y-m-d', strtotime(str_replace('/', '-', $this->max_date))) != '1970-01-01') { $query->andFilterWhere(['<', 'date_create', date('Y-m-d', strtotime(str_replace('/', '-', $this->max_date)))]); } } 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; } if (!empty($this->date_ot)) { $query->andFilterWhere(['>=', 'date', $this->date_ot]); } if (!empty($this->date_do)) { $query->andFilterWhere(['<=', 'date', $this->date_do]); } $query->andFilterWhere(['author_id' => $this->author_id]); $query->andFilterWhere(['like', 'name', $this->name]); //print_r($query);exit; return $dataProvider; }
public function actionBooks() { $session = Yii::$app->session; $search = new SearchForm(); if ($search->load(Yii::$app->request->post()) && $search->validate()) { $session['search'] = Yii::$app->request->post(); } elseif (!empty($session['search']['SearchForm'])) { $search->load($session['search']); } if (empty($session['search']['SearchForm'])) { $books = Books::find()->all(); } else { $books = Books::findWithFilters($session['search']['SearchForm']); } $authors = Authors::find()->all(); $selected_authors = array(); foreach ($authors as $author) { $selected_authors[$author->id] = $author['firstname'] . " " . $author['lastname']; } return $this->render('books', ['model' => $search, 'authors' => $selected_authors, 'books' => $books]); }