/** * Creates data provider instance with search query applied * @param array $params * @return ActiveDataProvider */ public function search($params) { $query = Book::find(); $query->joinWith('author'); $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 10]]); $dataProvider->sort->attributes['author.name'] = ['asc' => ['{{%author.name}}' => SORT_ASC], 'desc' => ['{{%author.name}}' => SORT_DESC]]; if (!($this->load($params) && $this->validate())) { return $dataProvider; } if ($this->author_id) { $query->andFilterWhere(['{{%book.author_id}}' => $this->author_id]); } if ($this->name) { $query->andFilterWhere(['like', '{{%book.name}}', $this->name]); } if ($this->date_from) { $query->andWhere('{{%book.date}} > :date_from', ['date_from' => strtotime($this->date_from)]); } if ($this->date_to) { $query->andWhere('{{%book.date}} < :date_to', ['date_to' => strtotime($this->date_to)]); } // $query // ->andFilterWhere(['{{%book.author_id}}' => $this->author_id]) // ->andFilterWhere(['like', '{{%book.name}}', $this->name]) // ->andWhere('{{%book.date}} > :date_from', ['date_from' => strtotime($this->date_from)]) // ->andWhere('{{%book.date}} < :date_to', ['date_to' => strtotime($this->date_to)]); return $dataProvider; }
/** * Remove the specified resource from storage. * * @param int $id * @return \Illuminate\Http\Response */ public function destroy($id) { Book::find($id)->delete(); \Session::flash('flash_message', 'Deleted Successfully!'); \Session::flash('flash_message_level', 'success'); return Redirect::back(); }
/** * Страница изменения информации книги. * * @param int $id * @return string|\yii\web\Response */ public function actionUpdate($id) { /** @var Book $modelBook */ $modelBook = Book::find()->with(['authors', 'tags'])->where(['id' => $id])->one(); $this->_saveBook($modelBook); return $this->render('/back/book/update', ['modelBook' => $modelBook]); }
private function loadModel($id) { $model = Book::find($id)->one(); if (!$model) { throw new HttpException(404, 'Not Found'); } return $model; }
public function runJoinSearch($i) { $book = \app\models\Book::find()->from('Book b')->with('author')->where('b.title = ?', ['Hello' . $i])->limit(1)->scalar(); // $book = $this->em->createQuery( // 'SELECT b, a FROM Book b JOIN b.author a WHERE b.title = ?1' // )->setParameter(1, 'Hello' . $i) // ->setMaxResults(1) // ->getScalarResult(); }
public function coverStore(Request $request, $id) { $book = Book::find($id); if (Gate::denies('manageBook', $book)) { abort(403, 'voce não é o dono desse livro'); } $bookService = app()->make(BookService::class); $bookService->storeCover($book, $request->file('file')); }
public function runJoinSearch($i) { $book = Book::find()->from('Book b')->with('author')->where('b.title = :t', [':t' => 'Hello' . $i])->one(); // $book = $this->em->createQuery( // 'SELECT b, a FROM Book b JOIN b.author a WHERE b.title = ?1' // )->setParameter(1, 'Hello' . $i) // ->setMaxResults(1) // ->getResult(); }
/** * @Get("/search/{name}") * * @param $name * * @return Response */ public function searchAction($name) { /** @var Book[] $books */ $books = Book::find(["name LIKE '%{$name}%'"]); $response = new Response(); $data = []; foreach ($books as $book) { $data[] = ['id' => $book->getId(), 'name' => $book->getName()]; } return $response->setJsonContent($data); }
public function actionIndex() { $dataProvider = new ArrayDataProvider(['allModels' => Book::find()->orderBy('rank')->limit(3)->asArray()->all()]); //$test = Book::getDb()->cache(function($db){ // Book::find()->orderBy('rank'); //}); //$result = $db->cache(function ($db) { // return $db->createCommand('SELECT * FROM user WHERE id=4')->queryOne(); //}); return $this->render('index', ['dataProvider' => $dataProvider]); }
/** * Download book by id. * * @return Response */ public function downloadSample($idbook) { $fileBooks = Book::find($idbook)->filebooks()->where('is_sample', 1)->get(); if (count($fileBooks) >= 1) { $files = array(); foreach ($fileBooks as $key => $value) { array_push($files, base_path() . '/book/' . $idbook . '/' . $value->link); } Zipper::make(base_path() . '/book/' . $idbook . '/sample.zip')->add($files); } $pathDownload = base_path() . "/book/" . $idbook . '/sample.zip'; return response()->download($pathDownload); }
public function actionIndex() { $books = Book::find()->all(); $data = array(); foreach ($books as $book) { $dataBook = array(); $dataBook['label'] = substr($book->name, 0, strpos($book->name, ':')); $listChapter = Chapter::find()->where(['book_id' => $book->id])->all(); $dataBook['content'] = $this->renderPartial('list', ['book' => $book, 'listChapter' => $listChapter]); $data[] = $dataBook; } return $this->render('index', ['data' => $data]); }
public function search() { $query = Book::find(); $this->addCondition($query, 'title', true); $this->addCondition($query, 'author_id'); if ($this->date_created_from) { $query->andWhere(['>=', 'date_created', $this->date_created_from]); } if ($this->date_created_to) { $query->andWhere(['<=', 'date_created', $this->date_created_to]); } return new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 20]]); }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Book::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $query->joinWith(['author']); $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(['>', 'date', $this->published_from])->andFilterWhere(['<', 'date', $this->published_to])->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['=', 'author_id', $this->author_id]); return $dataProvider; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Book::find()->joinWith('author')->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, 'date_update' => $this->date_update, 'date_create' => $this->date_create, 'date' => $this->date, 'author_id' => $this->author_id]); $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 = Book::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, 'published_date' => $this->published_date]); $query->andFilterWhere(['like', 'title', $this->title]); return $dataProvider; }
/** * Return a book * * @param int $id * @return \Illuminate\Http\Response */ public function returnBook($id) { $book = Book::find($id); if (count($book) == 0) { abort(404); } try { $book->status = 'returned'; $book->returned_at = new \DateTime(); $book->save(); } catch (\Exception $e) { return redirect()->back()->withErrors(['An unknown error has occurred while attempting to save this record']); } return redirect(action('BookController@index'))->with('success', ['Thankyou, the book has been returned.']); }
public function actionDelete($id = NULL) { if ($id === NULL) { Yii::$app->session->setFlash('PostDeletedError'); Yii::$app->getResponse()->redirect(array('site/index')); } $book = Book::find()->where(['id' => $id])->one(); if ($book === NULL) { Yii::$app->session->setFlash('PostDeletedError'); Yii::$app->getResponse()->redirect(array('site/index')); } $book->delete(); Yii::$app->session->setFlash('PostDeleted'); Yii::$app->getResponse()->redirect(array('site/index')); }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Book::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; } // grid filtering conditions $query->andFilterWhere(['id' => $this->id, 'date_create' => $this->date_create, 'date_from' => $this->date_from, 'date_to' => $this->date_to, 'price' => $this->price, 'room_id' => $this->room_id, 'id_card' => $this->id_card]); $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 = Book::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; } // grid filtering conditions $query->andFilterWhere(['book_id' => $this->book_id, 'author_id' => $this->author_id, 'pages_amount' => $this->pages_amount, 'publication' => $this->publication]); $query->andFilterWhere(['like', 'name', $this->name]); return $dataProvider; }
/** * Initialize the dataprovider by filling allModels */ public function init() { //Get all all authors with their articles $query = Book::find()->with('tour'); foreach ($query->all() as $book) { //print '<pre>'; print_r($book->tour); die(); //Get the last published date if there are articles for the author /*if (count($author->articles)) { $lastPublished = $query->max('Published'); } else { $lastPublished = null; }*/ //Add rows with the Author, # of articles and last publishing date $this->allModels[] = ['date' => $book->date, 'title' => $book->tour->title, 'id' => $book->id]; } }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Book::find(); $query->leftJoin('authors', 'authors.id = books.author_id'); $dataProvider = new ActiveDataProvider(['query' => $query]); $dataProvider->setSort(['attributes' => ['id', 'name', 'date_published', 'date_create', 'preview', 'author.fullname' => ['asc' => ['authors.lastname' => SORT_ASC], 'desc' => ['authors.lastname' => SORT_DESC], 'label' => 'Author']]]); $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])->andFilterWhere(['>', 'date_published', $this->date_published_from])->andFilterWhere(['<', 'date_published', $this->date_published_to]); return $dataProvider; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Book::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]); if (isset($this->from_date) && isset($this->to_date)) { $query->andFilterWhere(['between', 'date_release', \Yii::$app->formatter->asDate($this->from_date, 'php:U'), \Yii::$app->formatter->asDate($this->to_date, 'php:U')]); } $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 = Book::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $dataProvider->setSort(['attributes' => ['id', 'name', 'preview', 'date', 'date_create', 'authFullName' => ['asc' => ['authors.firstname' => SORT_ASC], 'desc' => ['authors.lastname' => SORT_DESC], 'label' => 'Автор']]]); if (!($this->load($params) && $this->validate())) { $query->joinWith(['author']); return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'date_create' => $this->date_create, 'date_update' => $this->date_update, 'author_id' => $this->author_id]); $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'preview', $this->preview]); $query->joinWith(['author' => function ($q) { $q->where('authors.firstname LIKE "%' . $this->authFullName . '%"'); }]); $query->andFilterWhere(['between', 'books.date', $this->beginDate, $this->endDate]); return $dataProvider; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Book::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]); if ($this->date_from && $this->date_to) { $query->andFilterWhere(['between', 'date', $this->date_from, $this->date_to]); } $query->andFilterWhere(['like', 'name', $this->name]); Url::remember(); return $dataProvider; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Book::find(); $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pagesize' => 15]]); $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(['{{books}}.id' => $this->id, 'author_id' => $this->author_id]); $query->andFilterWhere(['>', 'date', $this->date_min]); $query->andFilterWhere(['<', 'date', $this->date_max]); $query->andFilterWhere(['like', 'name', $this->name]); $query->joinWith('author')->select(['{{books}}.*', "CONCAT({{authors}}.firstname, ' ', {{authors}}.lastname) as author_fullname"])->asArray(); $dataProvider->sort->attributes['author_fullname'] = ['asc' => ['author_fullname' => SORT_ASC], 'desc' => ['author_fullname' => SORT_DESC]]; return $dataProvider; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Book::find(); $query->joinWith(['author']); $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; } $dataProvider->sort->attributes['author'] = ['asc' => ['{{%author}}.firstname, lastname' => SORT_ASC], 'desc' => ['{{%author}}.firstname, lastname' => SORT_DESC]]; $query->andFilterWhere(['id' => $this->id, 'released_at' => $this->released_at, '{{%author}}.id' => $this->author, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]); $from_date = !empty($this->released_from) ? strtotime($this->released_from) : $this->released_from; $to_date = !empty($this->released_to) ? strtotime($this->released_to) : $this->released_to; $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'image', $this->image])->andFilterWhere(['>', 'released_at', $from_date])->andFilterWhere(['<', 'released_at', $to_date]); return $dataProvider; }
/** * Creates data provider instance with search query applied * * @param array $params * @return ActiveDataProvider */ public function search($params) { $query = Book::find()->joinWith('author'); $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['attributes' => ['id', 'name', 'author' => ['asc' => ['author.firstname' => SORT_ASC, 'author.lastname' => SORT_ASC], 'desc' => ['author.firstname' => SORT_DESC, 'author.lastname' => SORT_DESC]], 'date', 'date_create']]]); $this->load($params); if (!$this->validate()) { return $dataProvider; } $query->andFilterWhere(['author_id' => $this->author_id])->andFilterWhere(['like', 'name', $this->name]); if (!empty($this->from)) { $from = \DateTime::createFromFormat('d.m.Y', $this->from); $query->andFilterWhere(['>=', 'date', $from->format('Y-m-d')]); } if (!empty($this->to)) { $to = \DateTime::createFromFormat('d.m.Y', $this->to); $query->andFilterWhere(['<=', 'date', $to->format('Y-m-d')]); } return $dataProvider; }
public function search($params) { $query = Book::find(); $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['name' => SORT_ASC]]]); // join with relation `whose` that is a relation to the table `user` // and set the table alias to be `whose` $query->joinWith(['author' => function ($query) { $query->from(['author' => 'tz_author']); }]); // enable sorting for the related column $dataProvider->sort->attributes['author.last_name'] = ['asc' => ['author.last_name' => SORT_ASC], 'desc' => ['author.last_name' => SORT_DESC]]; // load the search form data and validate if (!($this->load($params) && $this->validate())) { return $dataProvider; } // adjust the query by adding the filters $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'author.last_name', $this->getAttribute('author.last_name')])->andFilterWhere(['between', 'date', $this->date ? Book::getIntDate($this->date) : $this->date, $this->after_date ? Book::getIntDate($this->after_date) : $this->after_date]); return $dataProvider; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Book::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' => $this->date, 'status' => Book::STATUS_ENABLED]); $query->andFilterWhere(['like', 'name', $this->name]); if (!empty($this->date_start)) { $query->andFilterWhere(['>', 'date', $this->date_start]); } if (!empty($this->date_finish)) { $query->andFilterWhere(['<', 'date', $this->date_finish]); } return $dataProvider; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Book::find(); $query->with('user'); $query->joinWith('user'); $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; } /** * @todo : add table alias to columns */ $tableName = 'Book'; $query->andFilterWhere([$tableName . '.bookId' => $this->bookId, $tableName . '.year' => $this->year, $tableName . '.userId' => $this->userId]); $query->andFilterWhere(['like', 'name', $this->name]); return $dataProvider; }