Permalink
Browse files

working on day6

  • Loading branch information...
1 parent b00d5fc commit 40a9b18c6ae8057f57fd6d4cba86ba336cb86eea @romaninsh romaninsh committed Oct 14, 2011
Showing with 39 additions and 1 deletion.
  1. +23 −0 lib/Model/DVD.php
  2. +6 −0 lib/Model/Movie.php
  3. +10 −1 page/video.php
View
@@ -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;
+ }
}
View
@@ -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();
}
}
View
@@ -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.