コード例 #1
0
 /**
  * Update a book
  *
  * @param $book_id
  * @return Response
  */
 public function update($book_id)
 {
     $input = Input::only('isbn13', 'title', 'author', 'price');
     $book = Book::find($book_id);
     $book->update($input);
     return Response::json(['data' => $book]);
 }
コード例 #2
0
 public function queryWithoutConstraints()
 {
     $books = Book::find(1);
     //$books = Book::first();
     //$books = Book::all();
     Book::pretty_debug($books);
 }
コード例 #3
0
ファイル: ModelTest.php プロジェクト: julien-c/mongovel
 public function testCanGetResultsAsArrayOfModels()
 {
     self::insertFixture();
     $books = Book::find()->all();
     $this->assertEquals("My life", $books[0]->title);
     $this->assertEquals("My life, II", $books[1]->title);
 }
コード例 #4
0
 public static function sandbox()
 {
     // Testaa koodiasi täällä
     //View::make('helloworld.html');
     $torakat = Book::find(1);
     $books = Book::all();
     Kint::dump($books);
     Kint::dump($torakat);
 }
コード例 #5
0
 public function edit($bid)
 {
     $_action = 'edit';
     $_viewtype = 'book/manage';
     $_viewdata = array('env' => $this->_env, 'action' => $_action, 'book_id' => $bid);
     $book = Book::find($bid);
     $_viewdata['book'] = $book;
     return View::make($_viewtype, $_viewdata);
 }
コード例 #6
0
ファイル: BookTest.php プロジェクト: umamiMike/library-1
 function testFind()
 {
     $title = "Anathem";
     $test_book = new Book($title);
     $test_book->save();
     $title2 = "Snow Crash";
     $test_book2 = new Book($title2);
     $test_book2->save();
     $result = Book::find($test_book->getId());
     $this->assertEquals($result, $test_book);
 }
コード例 #7
0
ファイル: BookTest.php プロジェクト: juliocesardiaz/Library
 function test_find()
 {
     $title = "Three Blind Mice";
     $test_book = new Book($title);
     $test_book->save();
     $title2 = "Chicken Dog";
     $test_book2 = new Book($title2);
     $test_book2->save();
     $result = Book::find($test_book->getId());
     $this->assertEquals($test_book, $result);
 }
コード例 #8
0
 /** */
 public function testHasOne()
 {
     $books = Book::find();
     foreach ($books as $book) {
         $this->assertIsA($book->author, 'Author');
         $this->assertIsA($book, 'Book');
     }
     $this->assertEqual($book->author->name, 'Andrei Cristescu');
     // TBD. This is not supported right now!
     // $book->author->delete();
     // $this->assertEqual(sizeof(Book::find()), 0);
 }
コード例 #9
0
 public function delete($id)
 {
     $exist = Book::where('id', $id)->count();
     if ($exist == 0) {
         Session::put('msgfail', 'Failed to delete book.');
         return Redirect::back()->withInput();
     }
     $book = Book::find($id);
     unlink(public_path() . "/uploads/book/" . $book->file);
     Book::where('id', $id)->delete();
     Session::put('msgsuccess', 'Successfully deleted book.');
     return Redirect::back();
 }
コード例 #10
0
 public function saveBook()
 {
     $book = Input::get('book');
     $chapters = Input::get('chapters');
     $bookMdl = Book::find($book['id']);
     $bookMdl->name = iconv('UTF-8', 'ASCII//TRANSLIT//IGNORE', $book['name']);
     $bookMdl->urlname = str_replace(' ', '-', iconv('UTF-8', 'ASCII//TRANSLIT//IGNORE', $book['name']));
     $bookMdl->save();
     foreach ($chapters as $key => $chapter) {
         if ($chapter['id']) {
             $chapMdl = Chapter::find($chapter['id']);
         } else {
             $chapMdl = new Chapter();
         }
         if ($chapter['id'] && $chapter['isDeleted']) {
             $chapMdl->delete();
         } else {
             $chapMdl->book_id = $chapter['book_id'];
             $chapMdl->title = $chapter['title'];
             $chapMdl->markerdata = count($chapter['markerdata']) ? json_encode($chapter['markerdata']) : null;
             $chapMdl->order = $chapter['order'];
             $chapMdl->save();
             if (count($chapter['elements'])) {
                 foreach ($chapter['elements'] as $key => $element) {
                     if ($element['id']) {
                         $elementMdl = Element::find($element['id']);
                     } else {
                         $elementMdl = new Element();
                     }
                     if ($element['id'] && $element['isDeleted']) {
                         $elementMdl->delete();
                     } else {
                         $elementMdl->chapter_id = $chapMdl->id ?: $element['chapter_id'];
                         $elementMdl->order = $element['order'];
                         $elementMdl->type = $element['type'];
                         if ($element['type'] == 4 || $element['type'] == 5) {
                             $elementMdl->content = json_encode($element['content']);
                         } else {
                             $elementMdl->content = $element['content'];
                         }
                         $elementMdl->note = $element['note'];
                         $elementMdl->save();
                     }
                 }
             }
         }
     }
     echo json_encode(['ok']);
 }
コード例 #11
0
ファイル: BookTest.php プロジェクト: jtorrespdx/library
 function test_find()
 {
     //Arrange
     $title = "The Cat in the Hat";
     $test_book = new Book($title);
     $test_book->save();
     $title2 = "Misery";
     $test_book2 = new Book($title2);
     $test_book2->save();
     //Act
     $id = $test_book->getId();
     $result = Book::find($id);
     //Assert
     $this->assertEquals($test_book, $result);
 }
コード例 #12
0
 function testFind()
 {
     //Arrange
     $id = null;
     $name = "A Series of Unfortunate Events";
     $test_book = new Book($id, $name);
     $test_book->save();
     $name2 = "Fresh Off the Boat";
     $test_book2 = new Book($id, $name2);
     $test_book2->save();
     //Act
     $result = Book::find($test_book->getId());
     //Assert
     $this->assertEquals($test_book, $result);
 }
コード例 #13
0
 public function getPrev($chid)
 {
     $_action = 'show';
     $chapter = Chapter::find($chid);
     $book = Book::find($chapter->book_id);
     $firstTextElement = Element::where('chapter_id', '=', $chid)->where('type', '!=', '2')->first();
     $firstImage = Element::where('chapter_id', '=', $chid)->where('type', '=', '2')->first();
     $tmpELement = ['id' => $firstTextElement['id'], 'chapter_id' => $firstTextElement['chapter_id'], 'order' => $firstTextElement['order'], 'type' => $firstTextElement['type'], 'content' => $firstTextElement['content'], 'note' => $firstTextElement['note']];
     if ($firstTextElement['type'] == 4 || $firstTextElement['type'] == 5) {
         $tmpELement['content'] = json_decode($firstTextElement['content'], true);
         //dd($element['content']);
     }
     $prevInfo = ['chapter' => $chapter, 'book' => $book, 'info' => $tmpELement ?: null, 'img' => $firstImage ?: null];
     echo json_encode($prevInfo, JSON_NUMERIC_CHECK);
 }
コード例 #14
0
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store(Request $request)
 {
     $data = Request::all();
     $rules = ['isbn1' => 'required|numeric', 'isbn2' => 'numeric', 'title' => 'required|alpha', 'publication' => 'required|alpha', 'author' => 'required|numeric', 'subject' => 'required|numeric', 'onstock' => 'required|numeric', 'orderquantity' => 'required|numeric', 'orderlevel' => 'required|numeric', 'price' => 'required|numeric', 'year' => 'required|numeric'];
     $message = ['isbn1' => 'ISBN 1 should not be empty.', 'isbn1' => 'ISBN 1 may contain numbers only.', 'isbn2' => 'ISBN 2 may contain numbers only.', 'title' => 'Title should not be empty.', 'title' => 'Title may contain letters only.', 'publicaiton' => 'Publication should not be empty.', 'publicaiton' => 'Publication may contain letters only.', 'author' => 'Author should not be empty.', 'author' => 'Author may contain numbers only.', 'subject' => 'Subject should not be empty.', 'subject' => 'Subect may contain numbers only.', 'onstock' => 'On Stock should not be empty.', 'onstock' => 'On Stock may contain numbers only.', 'orderquantity' => 'Order Quantity should not be empty.', 'orderquantity' => 'Order Quantity may contain numbers only.', 'orderlevel' => 'Order Level should not be empty.', 'orderlevel' => 'Order Level may contain numbers only.', 'price' => 'Price should not be empty.', 'price' => 'Price may contain numbers only.', 'year' => 'Year should not be empty.', 'year' => 'Year may not contain numbers only.'];
     $validation = Validator::make($data, $rules, $message);
     if ($validation->passes()) {
         if (Book::find($data['authorcode'])) {
             return back()->withInput();
         } else {
         }
     } else {
         return Redirect::back()->withInput()->withErrors($validation);
     }
 }
コード例 #15
0
ファイル: BookTest.php プロジェクト: kevintokheim/Library
 function testFind()
 {
     //Arrange
     $book_name = "Intro to Art";
     $test_book = new Book($book_name);
     $test_book->save();
     $book_name2 = "Intro to Spanish";
     $test_book2 = new Book($book_name2);
     $test_book2->save();
     //Act
     $search_id = $test_book->getId();
     $result = Book::find($search_id);
     //Assert
     $this->assertEquals($test_book, $result);
 }
コード例 #16
0
ファイル: BookTest.php プロジェクト: bborealis/library
 function testFind()
 {
     //Arrange
     $title = "Harry Potter";
     $id = 1;
     $test_book = new Book($title, $id);
     $test_book->save();
     $title2 = "Moby Dick";
     $id2 = 2;
     $test_book2 = new Book($title, $id);
     $test_book2->save();
     //Act
     $result = Book::find($test_book2->getId());
     //Assert
     $this->assertEquals($test_book2, $result);
 }
コード例 #17
0
 public function postAddToCart()
 {
     //validation
     $rules = ['amount' => 'required|numeric', 'book' => 'required|numeric|exists:books,id'];
     //inputs, rules
     $validator = Validator::make(Input::all(), $rules);
     if ($validator->fails()) {
         return Redirect::route('index')->with('error', 'The book could not be added to your cart');
     }
     $member_id = Auth::user()->id;
     $book_id = Input::get('book');
     $amount = Input::get('amount');
     $book = Book::find($book_id);
     $total = $amount * $book->price;
     //checking existing in the cart
     $count = Cart::where('book_id', '=', $book_id)->where('member_id', '=', $member_id)->count();
     if ($count) {
         return Redirect::route('index')->with('error', 'The book already exists in your cart.');
     }
     Cart::create(['member_id' => $member_id, 'book_id' => $book_id, 'amount' => $amount, 'total' => $total]);
     return Redirect::route('cart');
 }
コード例 #18
0
 /**
  * Searches for book
  */
 public function searchAction()
 {
     $numberPage = 1;
     if ($this->request->isPost()) {
         $query = Criteria::fromInput($this->di, "Book", $_POST);
         $this->persistent->parameters = $query->getParams();
     } else {
         $numberPage = $this->request->getQuery("page", "int");
     }
     $parameters = $this->persistent->parameters;
     if (!is_array($parameters)) {
         $parameters = array();
     }
     $parameters["order"] = "id";
     $book = Book::find($parameters);
     if (count($book) == 0) {
         $this->flash->notice("The search did not find any book");
         return $this->dispatcher->forward(array("controller" => "book", "action" => "index"));
     }
     $paginator = new Paginator(array("data" => $book, "limit" => 10, "page" => $numberPage));
     $this->view->page = $paginator->getPaginate();
 }
コード例 #19
0
 public function testFindAllHashWithOrder()
 {
     $books = Book::find('all', array('conditions' => array('author_id' => 1), 'order' => 'name DESC'));
     $this->assertTrue(count($books) > 0);
 }
コード例 #20
0
 public function test_find_all_hash_with_order()
 {
     $books = Book::find('all', array('conditions' => array('author_id' => 1), 'order' => 'name DESC'));
     $this->assert_true(count($books) > 0);
 }
コード例 #21
0
ファイル: books.php プロジェクト: interfacesweb15-16/s4_mars
    // Creamos un objeto collection + json con el libro pasado como parámetro
    // Obtenemos el objeto request, que representa la petición HTTP
    $req = $app->request;
    // Obtenemos la ruta absoluta de este recurso
    $absUrl = $req->getScheme() . "://" . $req->getHost() . $req->getRootUri() . $req->getResourceUri();
    // Obtenemos el libro de la base de datos a partir de su id y la convertimos del formato Json (el devuelto por Eloquent) a un array PHP
    $p = \book::find($name);
    $libro = json_decode($p);
    $app->view()->setData(array('url' => preg_replace('/' . preg_quote('/' . $name, '/') . '$/', '', $absUrl), 'item' => $libro));
    // Mostramos la vista
    $app->render('book_template.php');
});
/* Borrado de un libro en concreto */
$app->delete('/books/:name', function ($name) use($app) {
    // Obtenemos el libro de la base de datos a partir de su id y lo borramos
    $p = \Book::find($name);
    $p->delete();
});
/* Añadido de un libro */
$app->post('/books', function () use($app) {
    $body = $app->request->getBody();
    $template = json_decode($app->request->getBody(), true);
    $datos = $template['template']['data'];
    foreach ($datos as $item) {
        switch ($item['name']) {
            case 'name':
                $name = $item['value'];
                break;
            case 'description':
                $description = $item['value'];
                break;
コード例 #22
0
 public function test_save_blank_value()
 {
     // oracle doesn't do blanks. probably an option to enable?
     if ($this->conn instanceof ActiveRecord\OciAdapter) {
         return;
     }
     $book = Book::find(1);
     $book->name = '';
     $book->save();
     $this->assert_same('', Book::find(1)->name);
 }
コード例 #23
0
ファイル: BookTest.php プロジェクト: kevintokheim/Liberry
 function test_updateTitle()
 {
     //Arrange
     $title = "Revenge of the Martians";
     $test_book = new Book($title);
     $test_book->save();
     $title2 = "Star Wars";
     $test_book2 = new Book($title2);
     $test_book2->save();
     //Act
     $test_book2->updateTitle($title);
     $result = Book::find($test_book2->getId());
     //Assert
     $this->assertEquals($test_book->getTitle(), $result->getTitle());
 }
コード例 #24
0
 public function test_save_blank_value()
 {
     $book = Book::find(1);
     $book->name = '';
     $book->save();
     $this->assert_same('', Book::find(1)->name);
 }
コード例 #25
0
 public function currentBook()
 {
     return Session::has('book_id') ? Book::find(Session::get('book_id')) : null;
 }
コード例 #26
0
 public function test_cast_when_loading()
 {
     $book = Book::find(1);
     $this->assert_same(1, $book->book_id);
     $this->assert_same('Ancient Art of Main Tanking', $book->name);
 }
コード例 #27
0
 public function test_gh_23_relationships_with_joins_to_same_table_should_alias_table_name()
 {
     $old = Book::$belongs_to;
     Book::$belongs_to = array(array('from_', 'class_name' => 'Author', 'foreign_key' => 'author_id'), array('to', 'class_name' => 'Author', 'foreign_key' => 'secondary_author_id'), array('another', 'class_name' => 'Author', 'foreign_key' => 'secondary_author_id'));
     $c = ActiveRecord\Table::load('Book')->conn;
     $select = "books.*, authors.name as to_author_name, {$c->quote_name('from_')}.name as from_author_name, {$c->quote_name('another')}.name as another_author_name";
     $book = Book::find(2, array('joins' => array('to', 'from_', 'another'), 'select' => $select));
     $this->assert_not_null($book->from_author_name);
     $this->assert_not_null($book->to_author_name);
     $this->assert_not_null($book->another_author_name);
     Book::$belongs_to = $old;
 }
コード例 #28
0
 public function test_to_csv_with_custom_enclosure()
 {
     $book = Book::find(1);
     ActiveRecord\CsvSerializer::$delimiter = ',';
     ActiveRecord\CsvSerializer::$enclosure = "'";
     $this->assert_equals("1,1,2,'Ancient Art of Main Tanking',0,0", $book->to_csv());
 }
コード例 #29
0
ファイル: app.php プロジェクト: kevintokheim/Library
    $book = Book::find($id);
    $book_copies = $book->getCopies();
    $new_copies = $_POST['new_copies'];
    if ($new_copies < 1000) {
        foreach ($book_copies as $copy) {
            $copy->delete();
        }
        $book->addCopies($new_copies);
    }
    $book->update($_POST['title']);
    $authors = $book->getAuthors();
    return $app['twig']->render("book.html.twig", array('book' => $book, 'authors' => $authors, 'copies' => count($book->getCopies())));
});
//delete book info
$app->delete("/book/{id}", function ($id) use($app) {
    $book = Book::find($id);
    $book->delete();
    return $app['twig']->render("main_admin.html.twig", array('books' => Book::getAll()));
});
//INDIVIDUAL AUTHOR PAGE
$app->get("/author/{id}", function ($id) use($app) {
    $author = Author::find($id);
    $books = $author->getBooks();
    return $app['twig']->render('author.html.twig', array('author' => $author, "books" => $books));
});
//Add book on the individual author page
$app->post("/author/{id}/add_book", function ($id) use($app) {
    $find_author = Author::find($id);
    $title = $_POST['title'];
    $new_book = new Book($title);
    $new_book->save();
コード例 #30
0
ファイル: app.php プロジェクト: jlbethel/Library
    $new_book->save();
    return $app['twig']->render('books.html.twig', array('books' => Book::getAll()));
});
$app->post("/authors", function () use($app) {
    $new_author = new Author($_POST['name']);
    $new_author->save();
    return $app['twig']->render('authors.html.twig', array('authors' => Author::getAll()));
});
$app->post("/patrons", function () use($app) {
    $new_patron = new Patron($_POST['name']);
    $new_patron->save();
    return $app['twig']->render('patrons.html.twig', array('patrons' => Patron::getAll()));
});
$app->post("/add_author", function () use($app) {
    $book = Book::find($_POST['book_id']);
    $author = Author::find($_POST['author_id']);
    $book->addAuthor($author);
    return $app['twig']->render('book.html.twig', array('copies' => $book->getCopies(), 'book' => $book, 'authors' => $book->getAuthors(), 'all_authors' => Author::getAll()));
});
$app->post("/add_book", function () use($app) {
    $book = Book::find($_POST['book_id']);
    $author = Author::find($_POST['author_id']);
    $author->addBook($book);
    return $app['twig']->render('author.html.twig', array('author' => $author, 'books' => $author->getBooks(), 'all_books' => Book::getAll()));
});
$app->post("/add_copy", function () use($app) {
    $book = Book::find($_POST['book_id']);
    $book->addCopy();
    return $app['twig']->render('book.html.twig', array('copies' => $book->getCopies(), 'book' => $book, 'authors' => $book->getAuthors(), 'all_authors' => Author::getAll()));
});
return $app;