Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

return works now multiple times... however, the view doesn't show the…

… correct user lending a book.... new bug introduced
  • Loading branch information...
commit 3206101167ea04726367c6c8b51fd49f8d1bdbab 1 parent d57a270
bmejias authored
47 src/app/controllers/books_controller.php
View
@@ -11,31 +11,31 @@ function index()
function add()
{
- if (!empty($this->data))
+ }
+
+ function do_add()
+ {
+ if ($this->Book->save($this->data))
{
- if ($this->Book->save($this->data))
+ $book_id = $this->Book->id;
+ $copies = 1;
+ if ($this->data['Book']['copies'] > 1)
+ $copies = $this->data['Book']['copies'];
+ Controller::loadModel('Material');
+ for ($i = 1; $i <= $copies; $i++)
{
- $book_id = $this->Book->id;
- $copies = 1;
- if ($this->data['Book']['copies'] > 1)
- $copies = $this->data['Book']['copies'];
- Controller::loadModel('Material');
- for ($i = 1; $i <= $copies; $i++)
- {
- $new_material = array('Material'=>
- array('book_id'=>$book_id,
- 'status'=>'available',
- 'code'=>$i));
- $this->Material->create();
- $result = $this->Material->save($new_material);
- $this->debug("Saving material returned ".print_r($result,
- true));
- }
- $this->Session->setFlash('The book has been saved.');
- $this->redirect(array('action' => 'index'));
+ $new_material = array('Material' =>
+ array('book_id' => $book_id,
+ 'status' => 'available',
+ 'code' => $i));
+ $this->Material->create();
+ $result = $this->Material->save($new_material);
+ $this->debug("Saving material returned ".print_r($result, true));
}
+ $this->Session->setFlash('The book has been saved.');
$this->redirect(array('action' => 'index'));
}
+ $this->redirect(array('action' => 'index'));
}
function view()
@@ -94,7 +94,7 @@ function lend()
$this->set('users', $users);
}
- function perform_lend()
+ function do_lend()
{
if ($this->data['Book']['do'] == 'lend')
{
@@ -124,7 +124,7 @@ function perform_lend()
$this->redirect('view?book_id='.$this->data['Book']['book']);
}
- function perform_return()
+ function do_return()
{
Controller::loadModel('Material');
Controller::loadModel('User');
@@ -134,7 +134,8 @@ function perform_return()
$this->Material->id = $copy_id;
$this->Material->saveField('status', 'available');
- $loan = $this->Loan->findByMaterial_id($copy_id);
+ $query = array('Loan.material_id' => $copy_id, 'Loan.status' => 'lent');
+ $loan = $this->Loan->find('first', array('conditions' => $query));
$this->Loan->id = $loan['Loan']['id'];
$this->Loan->set(array('date_in' => date('Y-m-d'),
'status' => 'returned',
25 src/app/views/books/add.ctp
View
@@ -3,26 +3,27 @@
<h2>Add Book</h2>
<?php
- echo $this->Form->create('Book');
- echo $this->Form->input('title', array('type'=>'text', 'size'=>'30'));
- echo $this->Form->input('author', array('type'=>'text', 'size'=>'30'));
- echo $this->Form->input('cd', array('type'=>'checkbox', 'label'=>'CD'));
- echo $this->Form->input('level', array('type'=>'text', 'size'=>'7'));
+ echo $this->Form->create('Book', array('type' => 'post',
+ 'action' => 'do_add'));
+ echo $this->Form->input('title', array('type' => 'text', 'size' => '30'));
+ echo $this->Form->input('author', array('type' => 'text', 'size' => '30'));
+ echo $this->Form->input('cd', array('type' => 'checkbox', 'label' => 'CD'));
+ echo $this->Form->input('level', array('type' => 'text', 'size' => '7'));
?>
<label for="BookLang">Language</label>
<?php
echo $this->Form->select('lang',
- array('nl'=>'Nederlands',
- 'en'=>'English',
- 'fr'=>'Français',
- 'es'=>'Español',
- 'de'=>'Deutsch'),
+ array('nl' => 'Nederlands',
+ 'en' => 'English',
+ 'fr' => 'Français',
+ 'es' => 'Español',
+ 'de' => 'Deutsch'),
'nl',
array(),
array(),
false);
- echo $this->Form->input('isbn', array('type'=>'text', 'size'=>'13'));
- echo $this->Form->input('copies', array('type'=>'text', 'size'=>'3'));
+ echo $this->Form->input('isbn', array('type' => 'text', 'size' => '13'));
+ echo $this->Form->input('copies', array('type' => 'text', 'size' => '3'));
echo $this->Form->end('Submit Book');
?>
2  src/app/views/books/lend.ctp
View
@@ -14,7 +14,7 @@
</table>
<?php
- echo $this->Form->create('Book', array('type'=>'post', 'action'=>'perform_lend'));
+ echo $this->Form->create('Book', array('type'=>'post', 'action'=>'do_lend'));
?>
<table>
<tr>
2  src/app/views/books/view.ctp
View
@@ -39,7 +39,7 @@
}
elseif ($copy['status'] == 'lent')
{
- $action = 'perform_return';
+ $action = 'do_return';
$submit_label = 'return';
}
echo $this->Form->create('Book',
Please sign in to comment.
Something went wrong with that request. Please try again.