Skip to content
This repository has been archived by the owner on Jul 25, 2022. It is now read-only.

Commit

Permalink
working on day6
Browse files Browse the repository at this point in the history
  • Loading branch information
Romans Malinovskis committed Oct 14, 2011
1 parent b00d5fc commit 40a9b18
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
23 changes: 23 additions & 0 deletions lib/Model/DVD.php
Expand Up @@ -6,9 +6,32 @@ function init(){

$this->addField('movie_id')->refModel('Model_Movie');
$this->addField('code');

$this->addfield('is_rented')
->type('boolean')
->calculated(true);
}
function toStringSQL($source_field, $dest_fieldname){
return 'concat("DVD#",id,": ",(select name
from movie m,dvd d where m.id=d.movie_id and d.id='.$source_field.')) as '.$dest_fieldname;
}
function calculate_is_rented(){
$select=$this->add('Model_Rental')
->dsql()
->field('id')
->where('rental.dvd_id=dvd.id')
->where('is_returned!=','Y')
->select()
;

return "if(($select) is null,'N','Y')";
}
function rent($customer_id){
$m=$this->add('Model_Rental')
->set('dvd_id',$this->get('id'))
->set('customer_id',$customer_id)
;
$m->update();
return $m;
}
}
6 changes: 6 additions & 0 deletions lib/Model/Movie.php
Expand Up @@ -7,5 +7,11 @@ function init(){
$this->addField('name');
$this->addField('year')->type('int');
$this->addField('imdb')->caption('IMDB Link');

$this->addField('available')->calculated(true);
}
function calculate_available(){
return $this->add('Model_DVD_InStore')
->dsql_count()->select();
}
}
11 changes: 10 additions & 1 deletion page/video.php
Expand Up @@ -4,6 +4,15 @@ function init(){
parent::init();
$this->api->auth->check();

$this->add('MVCGrid')->setModel('Movie');
$grid=$this->add('MVCGrid');
$grid->setModel('Movie_Available');
$grid->addColumn('button','rent');
if($_GET['rent']){
$rental = $grid->getModel()->loadData($_GET['rent'])->rent($this->api->auth->get('id'));

$grid->js(null,
$this->js()->reload())->univ()->successMessage('Rented successfully #'.$rental->get('id'));
}

}
}

0 comments on commit 40a9b18

Please sign in to comment.