Example #1
0
 /**
  * Returns the book title for the current Loan
  * Executed whenever the property "book_title" is accessed
  */
 function get_book_title()
 {
     if (empty($this->book)) {
         $item = Item::newFromBarcode($this->barcode);
         $this->book = new Book($item->book_id);
     }
     return $this->book->title;
 }
Example #2
0
 /**
  * method onSave()
  * Executed whenever the user clicks at the save button
  */
 function onSave()
 {
     try {
         // open a transaction with database 'library'
         TTransaction::open('library');
         // get the form data into an active record Loan
         $data = $this->form->getData('Loan');
         $msg = '';
         $persisted_objects = TSession::getValue('checkin_objects');
         if ($persisted_objects) {
             // iterate the collection of active records
             foreach ($persisted_objects as $object) {
                 // add the object inside the datagrid
                 $this->datagrid->addItem($object);
                 $item = Item::newFromBarcode($object->barcode);
                 if ($item->status_id == '2') {
                     $loan = Loan::getFromBarcode($item->barcode);
                     $loan->arrive_date = date('Y-m-d');
                     // store the item
                     $item->status_id = '1';
                     $item->store();
                     // stores the loan
                     $loan->store();
                     $msg .= "{$item->barcode} - " . _t('Success') . "<br>";
                 } else {
                     $msg .= "{$item->barcode} - " . _t('Not checked out') . "<br>";
                 }
             }
             TSession::setValue('checkin_objects', NULL);
             // set the data back to the form
             $this->form->setData($object);
             // shows the success message
             new TMessage('info', $msg);
         }
         // close the transaction
         TTransaction::close();
         // reload the listing
         $this->onReload();
     } catch (Exception $e) {
         // shows the exception error message
         new TMessage('error', '<b>Error</b> ' . $e->getMessage());
         // undo all pending operations
         TTransaction::rollback();
     }
 }