/** * @param Book|null $book * @return boolean whether the book successfully edited */ public function update($book) { if ($book) { if ($this->validate()) { $book->name = $this->name; $book->author_id = $this->author_id; $book->date = $this->date; if ($this->imageFile || $this->deleteImage) { if (!empty($book->preview)) { $imageToDelete = Yii::getAlias('@webroot') . Book::IMAGE_FOLDER . $book->preview; if (file_exists($imageToDelete)) { unlink($imageToDelete); } $book->preview = ''; } } if ($this->imageFile) { $imageName = Yii::$app->security->generateRandomString() . '.' . $this->imageFile->extension; if (!$this->imageFile->saveAs(Yii::getAlias('@webroot') . Book::IMAGE_FOLDER . $imageName)) { return false; } $book->preview = $imageName; } return $book->save(); } } return false; }
/** * 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(); }
public function actionForm($book_id) { $product = Book::findOne($book_id); $productImage = new BookImage(); if (!empty($_FILES['BookImage'])) { $img = $_FILES['BookImage']['name']['url']; $ext = end(explode(".", $img)); $name = microtime(); $name = str_replace(' ', '', $name); $name = str_replace('.', '', $name); $name = $name . '.' . $ext; $tmp = $_FILES['BookImage']['tmp_name']['url']; $productImage->url = $name; move_uploaded_file($tmp, '../uploads/' . $name); } if (!empty($_POST)) { $productImage->name = $_POST['BookImage']['name']; $productImage->product_id = $book_id; if ($productImage->save()) { $session = new Session(); $session->open(); $session->setFlash('message', 'Data Saved.'); return $this->redirect(['index', 'book_id' => $book_id]); } } return $this->render('//BookImage/Form', ['product' => $product, 'productImage' => $productImage]); }
public function searchISBN() { if (\Request::ajax()) { $data = array(); $isbn = \Input::get('isbn'); if (is_numeric($isbn)) { $book = Book::where('isbn', $isbn)->first(); if ($book) { $product = \Auth::user()->organization->products->find($book->id); if ($product) { // το βιβλίο υπάρχει στον οργανισμό και μπορούμε να το κάνουμε μόνο EDIT $data['find'] = true; $data['id'] = $book->id; $data['title'] = $book->product->title; $data['barcode'] = $book->product->barcode; $data['notify'] = '<p>Το βιβλίο με το συγκεκριμένο ISBN <strong> υπάρχει ήδη. </strong> </p> <p>Μπορείτε να το τροποποιήσετε κάνοντας κλικ στον τίτλο:</p>'; } else { // το βιβλίο υπάρχει σε άλλον οργανισμό και μπορούμε να το προσθέσουμε μόνο ως item $data['find'] = true; $data['external'] = true; $data['id'] = $book->id; $data['title'] = $book->product->title; $data['barcode'] = $book->product->barcode; $data['notify'] = '<p>Το βιβλίο με το συγκεκριμένο ISBN είναι καταχωρημένο από άλλο οργανισμό. Θέλετε να το προσθέσετε?</p>'; } } // else σημαίνει ότι όλα ΟΚ για create_book } return $data; } // END If }
/** * 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; }
public function bookItemWithTransformer() { $fractal = new Manager(); $book = Book::all()->random(1); //$book = Book::find(1); $resource = new Item($book, new BookTransformer()); return $fractal->createData($resource)->toJson(); }
/** * Run the database seeds. * * @return void */ public function run() { DB::table('books')->truncate(); $faker = \Faker\Factory::create(); for ($count = 0; $count < 500; $count++) { Book::create(['title' => $faker->sentence(), 'desc' => $faker->text(), 'cover' => $faker->imageUrl()]); } }
/** * @param $id * @return null|Book * @throws NotFoundHttpException */ private function loadModel($id) { $model = Book::findOne($id); if (null == $model) { throw new NotFoundHttpException('Книга не найдена'); } return $model; }
protected function findModel($id) { if (($model = Book::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
public function actionDelete($id) { $book = Book::findOne(['id' => $id]); if ($book) { $book->delete(); } $this->redirect(Url::to(['books/index'])); }
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 actionDelete() { $id = (int) Yii::$app->request->get('id'); /** @var Book $book */ $book = Book::findOne(['id' => $id]); $result = $book ? $book->delete() : false; Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; return ['result' => (bool) $result]; }
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(); }
/** * Run the database seeds. * * @return void */ public function run() { Model::unguard(); DB::statement('SET FOREIGN_KEY_CHECKS = 0'); Book::truncate(); $faker = Faker::create(); for ($i = 1; $i <= 30; $i++) { Book::create(['title' => $faker->sentence(), 'description' => $faker->sentence(), 'author' => $faker->name]); } }
function index() { $terbaru = Book::orderBy('BookID', 'desc')->skip(0)->take(6)->get(); $data['categories'] = $this->categories; $data['terbaru'] = $terbaru; if (Auth::member() != null) { $data['member'] = Auth::member(); } $this->view->render('home', $data); $this->view->data = "asu"; }
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]); }
/** * Run the database seeds. * * @return void */ public function run() { $tolkien = Author::create(['name' => 'J.R.R. Tolkien', 'date_of_birth' => '1892-01-03']); Book::create(['title' => 'The Hobbit', 'publication_date' => '1937-09-21', 'isbn' => '9780582186552', 'author_id' => $tolkien->id]); Book::create(['title' => 'The Silmarillion', 'publication_date' => '1977-09-15', 'isbn' => '9780345325815', 'author_id' => $tolkien->id]); $karpyshyn = Author::create(['name' => 'Drew Karpyshyn', 'date_of_birth' => '1971-07-28']); Book::create(['title' => 'The Old Republic: Revan', 'publication_date' => '2011-11-15', 'isbn' => '9780857689009', 'author_id' => $karpyshyn->id]); Book::create(['title' => 'The Old Republic: Annihilation', 'publication_date' => '2012-11-13', 'isbn' => '9780345529411', 'author_id' => $karpyshyn->id]); $salvatore = Author::create(['name' => 'R.A. Salvatore', 'date_of_birth' => '1959-01-20']); Book::create(['title' => 'Homeland', 'publication_date' => '2004-03-01', 'isbn' => '9780786931231', 'author_id' => $salvatore->id]); Book::create(['title' => 'Attack of the Clones', 'publication_date' => '2003-04-01', 'isbn' => '9780345428820', 'author_id' => $salvatore->id]); }
public function create($request) { \DB::beginTransaction(); $user = \Auth::user(); $book = Book::create($request->all()); $book->product()->create($request->all()); $book->product->organizations()->attach($user->organization->id, ['dewey_code' => $request['dewey_code'], 'quantity' => $request['quantity'], 'cat_id' => $request['cat_id'], 'user_id' => $user->id, 'edited_by' => $user->id]); $book->authors()->attach($request['author-list']); $item = Item::find($book->product->orgcreate()->first()->pivot->id); $item->tags()->attach($request['tag-list']); \DB::commit(); }
/** * Search for books * * @param string $terms * @param array $advancedQueries @see self::$advancedQueryOptions for more information * @param array $options @see self::$optionSettings for more information * * @return \App\Models\Book[] */ public function search($terms, array $advancedQueries = [], $options = []) { if (!$this->areAdvancedQueriesValid($advancedQueries)) { return false; } $this->setDefaultOptions($options); $query = $this->book->order($options['orderBy'], $options['order'])->page($options['page'], $options['limit']); if ($terms) { $query->searchFor($terms); } foreach ($advancedQueries as $key => $value) { $method = $this->advanceQuerySettings[$key]['method']; if ($key === 'range') { list($from, $to) = $value; $this->book->{$method}($from, $to); } else { $this->book->{$method}($value); } } return $query->get(); }
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]]); }
/** * 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]); }
/** * 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; }
/** * 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; }
private function queryAdvanced(array $queries = []) { $this->book->order($this->defaultOptions['orderBy'], $this->defaultOptions['order'])->page($this->defaultOptions['page'], $this->defaultOptions['limit']); $queriesList = ['q' => 'searchFor', 'title' => 'searchTitle', 'author' => 'searchAuthor', 'isbn' => 'searchIsbn', 'date' => 'searchDate', 'range' => 'searchDateRange', 'rate' => 'searchRate']; foreach ($queries as $key => $value) { if ($key === 'range') { list($from, $to) = $value; $this->book->{$queriesList[$key]}($from, $to); } else { $this->book->{$queriesList[$key]}($value); } } return $this->book->get()->toArray(); }
/** * 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; }
/** * 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.']); }
/** * @inheritdoc */ public function beforeValidate() { if (!parent::beforeValidate()) { return false; } if ($this->image) { $content = file_get_contents($this->image->tempName); $extension = $this->image->getExtension(); if (!($preview = Yii::$app->preview->save($content, $extension))) { return false; } $this->preview = $preview; } return true; }