Example #1
0
 public function testCanBeCreated()
 {
     \Utility\Database::getInstance()->setDSN('mysql:host=localhost;dbname=biblio', "root", "");
     $loader = new \DBMappers\BookItem();
     $book = $loader->getById(1);
     $this->assertInstanceOf('\\Application\\BookItem', $book);
     $this->assertEquals(1, $book->getId());
 }
Example #2
0
 public function returnBooks($params)
 {
     //error_log("\nparams:" . print_r($params, true), 3, "my_errors.txt");
     $entryMapper = new \DBMappers\BookIssueEntry();
     $bookMapper = new \DBMappers\BookItem();
     $readerMapper = new \DBMappers\UserItem();
     \Utility\Database::getInstance()->beginTransaction();
     try {
         $reader = $readerMapper->getById($params['user']['id']);
         foreach ($params['bookIssueList'] as $bookIssueEntryData) {
             $book = $bookMapper->getById($bookIssueEntryData['book']['id']);
             $issues = $this->getSortedBookIssues($reader->getId(), $entryMapper);
             $changes = $this->getEntriesToChange($book->getId(), $bookIssueEntryData['amount'], $issues);
             $reader->setHoldCount($reader->getHoldCount() - $changes->amountToWithdraw);
             foreach ($changes->toDelete as $deleteEntry) {
                 $entryMapper->deleteById($deleteEntry->getId());
             }
             foreach ($changes->toChange as $changeEntry) {
                 $entryMapper->update($changeEntry);
             }
             $book->setStoreCount($book->getStoreCount() + $changes->amountToWithdraw);
             $bookMapper->save($book);
         }
         $readerMapper->save($reader);
         if (!\Utility\Database::getInstance()->commit()) {
             throw new \Exception(\Utility\Database::getInstance()->getLastError());
         }
     } catch (\Exception $e) {
         \Utility\Database::getInstance()->rollback();
         throw $e;
     }
 }