本文整理汇总了PHP中app\models\Book类的典型用法代码示例。如果您正苦于以下问题:PHP Book类的具体用法?PHP Book怎么用?PHP Book使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Book类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: searchISBN
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
}
示例2: search
/**
* 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;
}
示例3: destroy
/**
* 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();
}
示例4: actionForm
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]);
}
示例5: loadModel
/**
* @param $id
* @return null|Book
* @throws NotFoundHttpException
*/
private function loadModel($id)
{
$model = Book::findOne($id);
if (null == $model) {
throw new NotFoundHttpException('Книга не найдена');
}
return $model;
}
示例6: loadModel
private function loadModel($id)
{
$model = Book::find($id)->one();
if (!$model) {
throw new HttpException(404, 'Not Found');
}
return $model;
}
示例7: bookItemWithTransformer
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();
}
示例8: run
/**
* 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()]);
}
}
示例9: actionDelete
public function actionDelete($id)
{
$book = Book::findOne(['id' => $id]);
if ($book) {
$book->delete();
}
$this->redirect(Url::to(['books/index']));
}
示例10: findModel
protected function findModel($id)
{
if (($model = Book::findOne($id)) !== null) {
return $model;
} else {
throw new NotFoundHttpException('The requested page does not exist.');
}
}
示例11: runJoinSearch
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();
}
示例12: actionDelete
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];
}
示例13: runJoinSearch
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();
}
示例14: coverStore
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'));
}
示例15: run
/**
* 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]);
}
}