Пример #1
0
 function testGetBook()
 {
     $title = "Carrie";
     $test_book = new Book($title);
     $test_book->save();
     $book_id = $test_book->getId();
     $test_copy = new Copy($book_id);
     $test_copy->save();
     $result = $test_copy->getBook();
     $this->assertEquals($test_book, $result);
 }
Пример #2
0
 public function __invoke($data, $context = null)
 {
     if ($this->walk) {
         return parent::__invoke($context);
     }
     return $context;
 }
Пример #3
0
 function test_getAll()
 {
     //Arrange
     $copy_id = 1;
     $id = 11;
     $copy_id2 = 2;
     $id2 = 22;
     $test_copy = new Copy($copy_id, $id);
     $test_copy->save();
     $test_copy2 = new Copy($copy_id2, $id2);
     $test_copy2->save();
     //Act
     $result = Copy::getAll();
     //Assert
     $this->assertEquals([$test_copy, $test_copy2], $result);
 }
Пример #4
0
 protected function tearDown()
 {
     Book::deleteAll();
     Copy::deleteAll();
     Author::deleteAll();
     Patron::deleteAll();
 }
Пример #5
0
 function testAddCheckout()
 {
     $title = "Three Blind Mice";
     $test_book = new Book($title);
     $test_book->save();
     $test_copy = new Copy($amount = 1, $test_book->getId());
     $test_copy->save();
     $name = "Joe Bongtana";
     $test_patron = new Patron($name);
     $test_patron->save();
     $due_date = "01-01-2016";
     $status = 1;
     $test_checkout = new Checkout($test_copy->getId(), $test_patron->getId(), $due_date, $status);
     $test_checkout->save();
     $test_patron->addCheckout($test_checkout);
     $result = Checkout::getAll();
     $this->assertEquals($test_checkout, $result);
 }
Пример #6
0
 function testDeleteAll()
 {
     //Arrange
     $book_id = 1;
     $due_date = '0000-00-00';
     $id = 1;
     $test_copy = new Copy($book_id, $due_date, $id);
     $test_copy->save();
     $book_id2 = 2;
     $due_date2 = '0000-00-00';
     $id2 = 2;
     $test_copy2 = new Copy($book_id2, $due_date2, $id2);
     $test_copy2->save();
     //Act
     Copy::deleteALl();
     //Assert
     $result = Copy::getAll();
     $this->assertEquals([], $result);
 }
Пример #7
0
 static function findCopies($search_book_id)
 {
     $found_copies = array();
     $copies = Copy::getAll();
     foreach ($copies as $copy) {
         $book_id = $copy->getBookId();
         if ($book_id == $search_book_id) {
             array_push($found_copies, $copy);
         }
     }
     return $found_copies;
 }
Пример #8
0
 static function findBook($search_book_id)
 {
     $found_copy = null;
     $copies = Copy::getAll();
     foreach ($copies as $copy) {
         $book_id = $copy->getBookId();
         if ($book_id == $search_book_id) {
             $found_copy = $copy;
         }
     }
     return $found_copy;
 }
Пример #9
0
 static function find($search_id)
 {
     $found = null;
     $copies = Copy::getAll();
     foreach ($copies as $copy) {
         $copy_id = $copy->getId();
         if ($copy_id == $search_id) {
             $found = $copy;
         }
     }
     return $found;
 }
Пример #10
0
 /**
  * Perform a bulk operation.
  *
  * @param array $ids    IDs to process
  * @param int   $listID Target list
  * limit).
  *
  * @return void
  */
 protected function processRecords($ids, $listID)
 {
     global $user;
     // First copy the records
     if (!parent::processRecords($ids, $listID)) {
         return false;
     }
     // Copy successful, now delete
     $list = User_list::staticGet($_REQUEST['listID']);
     if ($user->id != $list->user_id) {
         $this->errorMsg = 'list_access_denied';
         return false;
     }
     $list->removeResourcesById($ids);
     $this->infoMsg = 'records_moved';
     return true;
 }
Пример #11
0
 function testGetCheckouts()
 {
     //Arrange
     $name = "Jim Bob";
     $id = 1;
     $test_patron = new Patron($name, $id);
     $test_patron->save();
     $book_id = 1;
     $id = 1;
     $test_copy = new Copy($book_id, $id);
     $test_copy->save();
     $book_id2 = 2;
     $id2 = 2;
     $test_copy2 = new Copy($book_id2, $id2);
     $test_copy2->save();
     $copy_id = $test_copy->getId();
     $patron_id = $test_patron->getId();
     $id = null;
     $due_date = "2015-09-30";
     $test_checkout = new Checkout($copy_id, $patron_id, $due_date, $id);
     $test_checkout->save();
     // $copy_id2 = $test_copy2->getId();
     // $patron_id2 = $test_patron->getId();
     // $id2 = null;
     // $due_date2 = "2015-09-30";
     // $test_checkout2 = new Checkout($copy_id2, $patron_id2, $id2, $due_date2);
     $copy_id2 = $test_copy2->getId();
     $patron_id2 = $test_patron->getId();
     $id2 = null;
     $due_date2 = "2015-04-20";
     $test_checkout2 = new Checkout($copy_id2, $patron_id2, $due_date2, $id2);
     $test_checkout2->save();
     // var_dump($test_checkout);
     // var_dump($test_checkout2);
     //Act
     // $test_patron->addCheckout($test_checkout);
     // $test_patron->addCheckout($test_checkout2);
     $result = $test_patron->getCheckouts();
     // var_dump($result);
     //Assert
     $this->assertEquals(2, count($test_patron->getCheckouts()));
 }
Пример #12
0
 function testFindBookCopy()
 {
     $title = "Three Blind Mice";
     $test_book = new Book($title);
     $test_book->save();
     $test_copy = new Copy($amount = 1, $test_book->getId());
     $test_copy->save();
     $title2 = "Chicken Dog";
     $test_book2 = new Book($title2);
     $test_book2->save();
     $test_copy2 = new Copy($amount2 = 2, $test_book2->getId());
     $test_copy2->save();
     $result = Copy::findBookCopy($test_book->getId());
     $this->assertEquals($test_copy, $result);
 }
Пример #13
0
 function testDelete()
 {
     //Arrange
     $due_date = "2015-10-10";
     $book_id = 1;
     $id = 1;
     $test_copy = new Copy($due_date, $book_id, $id);
     $test_copy->save();
     $name = "Jim Bob";
     $id = 1;
     $test_patron = new Patron($name, $id);
     $test_patron->save();
     //Act
     $test_patron->addCopy($test_copy);
     $test_patron->delete();
     //Assert
     $this->assertEquals([], $test_copy->getPatrons());
 }
Пример #14
0
 function testGetCopy()
 {
     //Arrange
     $copy_id = 1;
     $test_copy = new Copy($copy_id);
     $test_copy->save();
     $copy_id2 = 2;
     $id2 = 2;
     $test_copy2 = new Copy($copy_id2);
     $test_copy2->save();
     $name = "Ping Pong";
     $id2 = 1;
     $test_patron = new Patron($name);
     $test_patron->save();
     //Act
     $test_patron->addCopy($test_copy->getId());
     $test_patron->addCopy($test_copy2->getId());
     //Assert
     $this->assertEquals($test_patron->getCopy(), [$test_copy, $test_copy2]);
 }
Пример #15
0
 /**
  * move 执行入口
  * @param bool $isPath - Use path to move if true ,or use id. 
  */
 public function invoke($isPath = true)
 {
     // 初始化入口
     $device = new UserDevice();
     $device = $device->findByUserIdAndType($this->_userId, CConst::DEVICE_WEB);
     $this->_deviceId = $device["id"];
     $this->_deviceName = $device["user_device_name"];
     $user = User::model()->findByPk($this->_userId);
     $this->_userNick = $user["user_name"];
     $this->master = $this->_userId;
     //
     // 空间检查
     //
     $this->handleSpace();
     if ($isPath) {
         $this->fromPath = CUtils::convertStandardPath($this->fromPath);
         $this->toPath = CUtils::convertStandardPath($this->toPath);
         $this->initByPath();
     } else {
         $this->initById();
     }
     //
     // 判断是否是共享
     //
     $from_share_filter = MSharesFilter::init();
     $from_share_filter->handlerCheckByFile($this->_userId, $this->from);
     $this->rename = false;
     if ($from_share_filter->_is_shared_path && $this->toParent['id'] == 0) {
         $this->rename = true;
     } elseif ($from_share_filter->is_shared) {
         $this->master = $from_share_filter->master;
         $this->fromPath = '/' . $this->master . $from_share_filter->_path;
         $this->from = UserFile::model()->findByAttributes(array('is_deleted' => 0, 'file_path' => $this->fromPath));
         if (!$this->from) {
             throw new ApiException("Not found");
         }
     }
     //
     // 检查移动原路径与目标路径是否一致,一致则返回成功
     //
     if ($this->fromPath === $this->toPath) {
         $this->handleResult(false, 0, "已存在同名的文件");
         return;
     }
     //
     // 检查是否移动到其子目录下
     //
     if (strpos($this->toPath, $this->fromPath . "/") === 0) {
         $this->result["msg"] = "不能移动到子目录";
         return;
     }
     if ($this->toPath == "/{$this->_userId}" || $this->toPath == "/{$this->_userId}/") {
         $this->result["msg"] = "目标目录不存在";
         return;
     }
     //
     // 命名检查
     //
     if (CUtils::checkNameInvalid($this->toPath) != 0 || CUtils::checkNameInvalid($this->toPath) != 0) {
         $this->result["msg"] = "命名不能包含下列字符串: ^|?*\\<\":>";
         return;
     }
     //
     // 存在同名的则,拒绝
     //
     $target = UserFile::model()->findByAttributes(array("user_id" => $this->_userId, "file_path" => $this->toPath, "is_deleted" => 0));
     if ($target) {
         $this->handleResult(false, 0, "已存在同名的文件");
         return;
     }
     $index = strlen("/{$this->from['user_id']}");
     $fpath = substr_replace($this->fromPath, "", 0, $index);
     $index = strlen("/{$this->toParent['user_id']}");
     $tpath = substr_replace($this->toPath, "", 0, $index);
     //
     // 检查移动方式
     //
     if ($isPath == false && $this->rename == false && ($from_share_filter->handlerCheckMove($from_share_filter->master, $this->to_share_filter->master, $fpath, $tpath) || $this->to_share_filter->is_shared)) {
         //
         // 先copy再删除,如果是移动共享文件夹则只copy,再执行shareManager取消共享
         //
         $copy = new Copy();
         $copy->_userId = $this->_userId;
         $copy->toId = $this->toParent['id'];
         $copy->fromId = $this->from['id'];
         try {
             $copy->invoke(false);
         } catch (Exception $e) {
             $this->result["msg"] = "操作失败";
             return;
         }
         if ($this->from['file_type'] == 2 && $this->from['user_id'] != $this->to_share_filter->operator) {
             $file_meta = FileMeta::model()->findByAttributes(array('meta_key' => 'shared_folders', 'file_path' => $this->from['file_path']));
             if (!$file_meta) {
                 $this->result["msg"] = "操作失败";
                 return;
             }
             $meta_value = unserialize($file_meta['meta_value']);
             $slaves = $meta_value['slaves'];
             $this->from = UserFile::model()->findByAttributes(array('file_path' => $slaves[$this->to_share_filter->operator], 'is_deleted' => 0));
             if (!$this->from) {
                 $this->result["msg"] = "操作失败";
                 return;
             }
         }
         $del = new Delete();
         $del->_userId = $this->from['user_id'];
         try {
             $del->invoke($this->from['id']);
             $trash = new Trash();
             $trash->_userId = $this->master;
             $trash->fromIds = $this->from['id'];
             $trash->invoke(Trash::DELETE);
         } catch (Exception $e) {
             $this->result["msg"] = "操作失败";
             return;
         }
         if ($copy->result['state'] && $del->result['state']) {
             $this->handleResult(true, 0, "操作成功");
             $this->result["data"][$this->fromId]["state"] = true;
         }
         return;
     }
     // 文件直接进行移动
     if ($this->from["file_type"] == 0) {
         $this->handleMoveFile($this->fromPath, $this->toPath);
     } else {
         // 文件夹涉及子对象
         $this->handleMoveFolder($this->fromPath, $this->toPath);
     }
     $this->handleResult(true, 0, "操作成功");
     $this->result["data"][$this->fromId]["state"] = true;
 }
Пример #16
0
 function test_getCopies()
 {
     //Arrange
     $book_name = "The Martian";
     $test_book = new Book($book_name);
     $test_book->save();
     //Act
     $test_book->addCopies(4);
     $test_copies = $test_book->getCopies();
     $result = Copy::getAll();
     //Assert
     $this->assertEquals($test_copies, $result);
 }
Пример #17
0
 function test_addCopy()
 {
     $title = "Three Blind Mice";
     $test_book = new Book($title);
     $test_book->save();
     $test_copy = new Copy($amount = 1, $test_book->getId());
     $test_copy->save();
     $title2 = "Chicken Dog";
     $test_book2 = new Book($title2);
     $test_book2->save();
     $test_book->addCopies(1);
     $result = $test_copy->getAmount();
     $this->assertEquals(2, $result);
 }
Пример #18
0
    Book::deleteAll();
    return $app['twig']->render('books.html.twig', array('books' => Book::getAll()));
});
$app->patch("/book/{id}", function ($id) use($app) {
    $book = Book::find($id);
    $title = $_POST['title'];
    $book->update($title);
    $authors = $book->getAuthors();
    $copies = Copy::findCopies($id);
    return $app['twig']->render('book.html.twig', array('book' => $book, 'authors' => $authors, 'all_authors' => Author::getAll(), 'copies' => $copies));
});
$app->post("/add_authors", function () use($app) {
    $book = Book::find($_POST['book_id']);
    $author = Author::find($_POST['author_id']);
    $book->addAuthor($author);
    $copies = Copy::findCopies($_POST['book_id']);
    return $app['twig']->render('book.html.twig', array('book' => $book, 'authors' => $book->getAuthors(), 'all_authors' => Author::getAll(), 'copies' => $copies));
});
//book search result page
$app->get("/search_books", function () use($app) {
    $search = Book::search($_GET['search']);
    return $app['twig']->render('search_books.html.twig', array('search' => $search, 'search_book' => $_GET['search']));
});
//author search result page
$app->get("/search_authors", function () use($app) {
    $search = Author::search($_GET['search']);
    return $app['twig']->render('search_authors.html.twig', array('search' => $search, 'search_author' => $_GET['search']));
});
//authors
$app->get("/authors", function () use($app) {
    return $app['twig']->render('authors.html.twig', array('authors' => Author::getAll()));
Пример #19
0
    $author->save();
    $book = Book::find($_POST['book_id']);
    $book->addAuthor($author);
    return $app['twig']->render('book.html.twig', array('book' => $book, 'author' => $author, 'copies' => Copy::getAll(), 'patrons' => Patron::getAll(), 'checkouts' => Checkout::getAll()));
});
$app->get("/book/{id}", function ($id) use($app) {
    $book = Book::find($id);
    $author = $book->getAuthors();
    $copies = Copy::findCopies($id);
    return $app['twig']->render('book.html.twig', array('book' => $book, 'author' => $author, 'copies' => $copies, 'patrons' => Patron::getAll(), 'checkouts' => Checkout::getAll()));
});
$app->post("/add_copy", function () use($app) {
    $book_id = $_POST['book_id'];
    $book = Book::find($book_id);
    $author = $book->getAuthors();
    $copy = new Copy($book_id);
    $copy->save();
    $copies = Copy::findCopies($book_id);
    return $app['twig']->render('book.html.twig', array('book' => $book, 'author' => $author, 'copies' => $copies, 'patrons' => Patron::getAll(), 'checkouts' => Checkout::getAll()));
});
$app->patch("/checkout_copy/{id}", function ($id) use($app) {
    $checkout = new Checkout($_POST['copy_id'], $_POST['patron_id'], $_POST['due_date']);
    $checkout->save();
    $book_id = $_POST['book_id'];
    $book = Book::find($book_id);
    $author = $book->getAuthors();
    return $app['twig']->render('book.html.twig', array('book' => $book, 'author' => $author, 'copies' => Copy::getAll(), 'patrons' => Patron::getAll(), 'checkouts' => Checkout::getAll()));
});
// $app->patch("/checkout_copy/{id}", function($id) use ($app) {
//     $book = Book::find($id);
//     $author = $book->getAuthors();
Пример #20
0
 function test_getCopy()
 {
     //Arrange
     $book_id = 1;
     $test_copy = new Copy($book_id);
     $test_copy->save();
     $checked_in_status = 0;
     $due_date = "2000 BC";
     $patron_id = 1;
     $test_checkout = new Checkout($checked_in_status, $due_date, $test_copy->getId(), $patron_id);
     $test_checkout->save();
     //Act
     $result = $test_checkout->getCopy();
     //Assert
     $this->assertEquals($test_copy, $result);
 }
Пример #21
0
 function test_addCheckout()
 {
     //Arrange
     $book_id = 4;
     $test_copy = new Copy($book_id);
     $test_copy->save();
     $name = "Phyllis the kind Grandma";
     $test_patron = new Patron($name);
     $test_patron->save();
     //Act
     $test_copy->addCheckout($test_patron);
     $result = $test_copy->getCheckout();
     //Assert
     $this->assertEquals($test_copy->getId(), $result->getCopyId());
 }
Пример #22
0
 function testGetPatron()
 {
     //Arrange
     $book_id = 1;
     $id = 1;
     $test_copy = new Copy($book_id, $id);
     $test_copy->save();
     $name = "Ping Pong";
     $id2 = 1;
     $test_patron = new Patron($name, $id2);
     $test_patron->save();
     $name2 = "Ding Dong";
     $id3 = 2;
     $test_patron2 = new Patron($name2, $id3);
     $test_patron2->save();
     //Act
     $test_copy->addPatron($test_patron->getId());
     $test_copy->addPatron($test_patron2->getId());
     //Assert
     $this->assertEquals($test_copy->getPatron(), [$test_patron, $test_patron2]);
 }
Пример #23
0
 function test_addCheckout()
 {
     //Arrange
     $name = "Jerald the crotchety grandpa";
     $test_patron = new Patron($name);
     $test_patron->save();
     $book_id = 8;
     $test_copy = new Copy($book_id);
     $test_copy->save();
     //Act
     $test_patron->addCheckout($test_copy);
     $result = $test_patron->getCheckouts();
     //Assert
     $this->assertEquals($test_patron->getId(), $result[0]->getPatronId());
 }
Пример #24
0
 function test_delete()
 {
     //Arrange
     $available = true;
     $book_id = 4;
     $test_copy = new Copy($available, $book_id);
     $test_copy->save();
     $available2 = true;
     $book_id2 = 5;
     $test_copy2 = new Copy($available2, $book_id2);
     $test_copy2->save();
     //Act
     $test_copy->delete();
     $result = Copy::getAll();
     //Assert
     $this->assertEquals([$test_copy2], $result);
 }
Пример #25
0
 function testFindCopies()
 {
     //Arrange
     $due_date = '2015-10-10';
     $book_id = 1;
     $id = 1;
     $test_copy = new Copy($due_date, $book_id, $id);
     $test_copy->save();
     $due_date2 = '2015-11-11';
     $book_id2 = 1;
     $id2 = 2;
     $test_copy2 = new Copy($due_date2, $book_id2, $id2);
     $test_copy2->save();
     $title = "Harry Potter";
     $id = 1;
     $test_book = new Book($title, $id);
     $test_book->save();
     //Act
     $result = Copy::findCopies($book_id);
     //var_dump($result);
     //Assert
     $this->assertEquals([$test_copy, $test_copy2], $result);
 }
Пример #26
0
 function addCopies($number_added)
 {
     $copy = Copy::findBook($this->getId());
     $new_amount = $copy->getAmount() + $number_added;
     $copy->update($new_amount);
 }
Пример #27
0
 protected function tearDown()
 {
     Patron::deleteAll();
     Copy::deleteAll();
     Checkout::deleteAll();
 }
Пример #28
0
 function testFind()
 {
     $book_title = "Snow Crash";
     $id = null;
     $amount = 1;
     $test_book = new Book($book_title, $id);
     $test_book->save();
     $book_title2 = "Dune";
     $id2 = null;
     $amount2 = 2;
     $test_book2 = new Book($book_title2, $id2);
     $test_book2->save();
     $test_copy = new Copy($amount, $test_book->getId());
     $test_copy->save();
     $test_copy2 = new Copy($amount2, $test_book2->getId());
     $test_copy2->save();
     $result = Copy::find($test_copy->getId());
     $this->assertEquals($test_copy, $result);
 }