[virtualcommons-svn] SF.net SVN: virtualcommons:[20] vcweb/trunk/virtualcommons
Status: Beta
Brought to you by:
alllee
From: <al...@us...> - 2008-08-02 00:15:47
|
Revision: 20 http://virtualcommons.svn.sourceforge.net/virtualcommons/?rev=20&view=rev Author: alllee Date: 2008-08-02 00:15:56 +0000 (Sat, 02 Aug 2008) Log Message: ----------- TODO: teacher dashboard, give Group a Game reference, and then add forestry student records Modified Paths: -------------- vcweb/trunk/virtualcommons/experiment/experiment.inc vcweb/trunk/virtualcommons/experiment/experiment.module vcweb/trunk/virtualcommons/games/forestry_v2/forestry_v2.module vcweb/trunk/virtualcommons/games/teacher_dashboard/teacher_dashboard.install vcweb/trunk/virtualcommons/games/teacher_dashboard/teacher_dashboard.module Modified: vcweb/trunk/virtualcommons/experiment/experiment.inc =================================================================== --- vcweb/trunk/virtualcommons/experiment/experiment.inc 2008-08-01 01:19:07 UTC (rev 19) +++ vcweb/trunk/virtualcommons/experiment/experiment.inc 2008-08-02 00:15:56 UTC (rev 20) @@ -1,71 +1,92 @@ <?php -class Game -{ +class Session { + public static function store($ses_var, $object) { + if( ! isset($_SESSION[$ses_var]) ) { + $_SESSION[$ses_var] = serialize($object); + } + } + public static function load($ses_var) { + if( isset($_SESSION[$ses_var]) ) { + return unserialize($_SESSION[$ses_var]); + } + else return false; + } + + public static function remove($ses_var) { + unset($_SESSION[$ses_var]); + } +} + + +class Game { private $game_id; - private $exp_id; - private $game_name; private $teacher_id; private $experiment_id; - private $stage_id; - private $round_no; - private $no_of_student; + private $current_stage_no; + private $current_round_no; + private $no_of_students; + private $experiment_name; - // FIXME: perhaps this should return a list of games eventually - public function getGameID() - { - $this->game_id=db_result(db_query("Select max(id) from vc_game where users_id=%d",$this->teacher_id)); - return $this->game_id; + public function __construct($experiment_id, $teacher_id, $no_of_students) { + $this->game_id = db_next_id('{vc_game}_id'); + $this->experiment_id = $experiment_id; + $this->teacher_id = $teacher_id; + $this->no_of_students = $no_of_students; + $this->current_stage_no = 1; + $this->current_round_no = 1; + $this->experiment_name = db_result(db_query("select e.name from vc_experiment e where e.id=%d", $experiment_id)); } - public function setExpId($exp_id) - { - $this->exp_id=$exp_id; + public function getNumberOfRounds() { + return db_result(db_query("select s.no_of_rounds from vc_stage s, vc_game g where s.id=g.id and g.id=%d",$this->game_id)); + } + public function getNumberOfStudents() { + return $this->no_of_students; } - - public function setTeacherId($teacher_id) - { - $this->teacher_id=$teacher_id; - + public function getCurrentStageId() { + return db_result(db_query("select id from vc_stage where vc_experiment_id=%d and stage_no=%d",$this->experiment_id,$this->current_stage_no)); } - public function setStageId($stage_no) - { - $this->stage_id=db_result(db_query("select id from vc_stage where vc_experiment_id =%d and stage_no=%d",$this->exp_id,$stage_no)); - - + // FIXME: perhaps this should return a list of games eventually + public function getGameID() { + return $this->game_id; } - public function setNoOfStudent($no_of_student) - { - $this->no_of_student=$no_of_student; - + public static function findLatestGame($teacher_id) { + // FIXME: return actual Game object if necessary + $game = new Game(); + $game->game_id = db_result(db_query("SELECT id from vc_game where users_id=%d ORDER BY date_created DESC LIMIT 1" ,$this->teacher_id)); + return $game; } - - public function setRoundNo($round_no) - { - $this->round_no=$round_no; + public function getExperimentName() { + return $this->experiment_name; } - - public function saveGame() - { - - //$this->exp_id=db_result(db_query("Select id from {vc_experiment} where name LIKE '%s'",$this->game_name)); - - + public function save() { //insert into game table - drupal_set_message(t('game name:'.$this->game_name)); - db_query("Insert into {vc_game} (users_id, vc_experiment_id, no_of_students,vc_stage_id,current_round_no ) values(%d,%d,%d,%d,%d)",$this->teacher_id,$this->exp_id,$this->no_of_student,$this->stage_id,$this->round_no); + drupal_set_message(t('students:' . $this->no_of_students)); + db_query("INSERT INTO {vc_game} (id, users_id, vc_experiment_id, no_of_students,vc_stage_id,current_round_no) VALUES (%d,%d,%d,%d,%d,%d)", + $this->game_id, + $this->teacher_id, + $this->experiment_id, + $this->no_of_students, + $this->getCurrentStageId(), + $this->current_round_no); + } + public function getExperimentId() { + return db_result(db_query("select vc_experiment_id from vc_game where id=%d",$this->game_id)); } + public function setCurrentStageNo($current_stage_no) { + $this->current_stage_no = $current_stage_no; + } - public function saveGroupStudent($student_array) - { + public function saveGroupStudent($student_array) { $turn=array(1,2,3,4,5); // $prev_group_no=0; // $temp=-1; @@ -86,38 +107,36 @@ } } - - } -// FIXME: figure out if we can move to forestry at some point + // FIXME: figure out if we can move to forestry at some point public function initForestry() { $result_group=db_query(" select count(s.vc_group_id) as cnt, s.vc_group_id as group_id from vc_group g, vc_student s where s.vc_group_id=g.id and g.vc_game_id=%d group by s.vc_group_id;",$this->game_id); - while($data=db_fetch_object($result_group)) - { - $no_of_student=$data->cnt; - $group_no=$data->group_id; - //drupal_set_message(t($no_of_student.' '. $group_no)); - if($no_of_student == 5) - { - db_query("Insert into {vc_forestry_common_resource_pool} (vc_group_id,common_resource_pool,vc_game_id, harvest_decision,max_harvest_decision) values(%d,%d,%d,%d,%d)",$group_no,100,$this->game_id,0,100); + while($data=db_fetch_object($result_group)) + { + $no_of_student=$data->cnt; + $group_no=$data->group_id; + //drupal_set_message(t($no_of_student.' '. $group_no)); + if($no_of_student == 5) + { + db_query("Insert into {vc_forestry_common_resource_pool} (vc_group_id,common_resource_pool,vc_game_id, harvest_decision,max_harvest_decision) values(%d,%d,%d,%d,%d)",$group_no,100,$this->game_id,0,100); - } + } - else if($no_of_student == 4) - { - db_query("Insert into {vc_forestry_common_resource_pool} (vc_group_id,common_resource_pool,vc_game_id, harvest_decision,max_harvest_decision) values(%d,%d,%d,%d,%d)",$group_no,80,$this->game_id,0,80); - } + else if($no_of_student == 4) + { + db_query("Insert into {vc_forestry_common_resource_pool} (vc_group_id,common_resource_pool,vc_game_id, harvest_decision,max_harvest_decision) values(%d,%d,%d,%d,%d)",$group_no,80,$this->game_id,0,80); + } - else if($no_of_student == 3) - { - db_query("Insert into {vc_forestry_common_resource_pool} (vc_group_id,common_resource_pool,vc_game_id,harvest_decision,max_harvest_decision) values(%d,%d,%d,%d,%d)",$group_no,60,$this->game_id,0,60); - } + else if($no_of_student == 3) + { + db_query("Insert into {vc_forestry_common_resource_pool} (vc_group_id,common_resource_pool,vc_game_id,harvest_decision,max_harvest_decision) values(%d,%d,%d,%d,%d)",$group_no,60,$this->game_id,0,60); + } - } + } } @@ -127,7 +146,28 @@ db_query("update vc_student set start_flag=%d where vc_group_id in (select id from vc_group where vc_game_id=%d)",$flag,$this->game_id); } + public function getAllGroupRoundInfo() { + $result=db_query("SELECT round_no, vc_group_id, total_harvest_decision, resources_before, resources_after, vc_rules_id, dice + FROM {vc_forestry_group_round_info} + WHERE vc_game_id=%d and vc_stage_id=%d", + $this->game_id, $this->getCurrentStageId()); + $stage_data = array(); + while($data = db_fetch_object($result)) { + $round_no=$data->round_no; + $group_id=$data->vc_group_id; + $total_harvest_decision=$data->total_harvest_decision; + $resources_before=$data->resources_before; + $resources_after=$data->resources_after; + $group_round_data = array($round_no,$group_no,$total_harvest_decision,$resource_before,$resource_after); + if ( $data->vc_rules_id ) { + array_push($group_round_data, $data->vc_rules_id, $data->dice); + } + $stage_data[] = $group_round_data; + } + return $stage_data; + } + }//end of class Game class Group { @@ -135,6 +175,7 @@ private $group_id; private $group_no; private $no_of_students; + private $experiment_id; public function getNumberOfStudents() { return $this->no_of_students; @@ -148,6 +189,11 @@ return $this->game_id; } + public function getExperimentId() + { + return db_result(db_query("select vc_experiment_id from vc_game where id=%d",$this->game_id)); + + } public function getStartFlag($student_id) { return db_result(db_query("SELECT start_flag FROM {vc_student} WHERE id='%s'",$student_id)); } @@ -160,6 +206,19 @@ return db_result(db_query("SELECT r.rule_no FROM {vc_rules r, vc_group g} WHERE r.id=g.vc_selected_rules_id AND g.id=%d", $this->group_id)); } + + public static function findByStudentId($studentId) { + $fetch_object = db_fetch_object(db_query("SELECT g.id AS group_id, g.vc_game_id AS game_id from {vc_student s, vc_group g} where s.id='%s' AND s.vc_group_id=g.id",$studentId)); + if ($fetch_object) { + $group = new Group(); + $group->game_id = $fetch_object->game_id; + $group->group_id = $fetch_object->group_id; + $group->no_of_students = db_result(db_query("SELECT count(*) FROM vc_student WHERE vc_group_id=%d", $group->group_id)); + return $group; + } + return false; + } + public static function checkStudentId($studentId) { $fetch_object = db_fetch_object(db_query("SELECT g.id AS group_id, g.vc_game_id AS game_id from {vc_student s, vc_group g} where s.id='%s' AND s.vc_group_id=g.id",$studentId)); if ($fetch_object) { @@ -172,30 +231,91 @@ return false; } -} + public function getNoOfRounds() + { + return db_result(db_query("select s.no_of_rounds from vc_stage s, vc_game g where s.id=g.id and g.id=%d",$this->game_id)); + } + public function getCurrentStageId() + { + return db_result(db_query("select vc_stage_id from vc_game where id=%d",$this->game_id)); + } +}//end of Group +/** + * FIXME: Fill in documentation here, Seema. + */ +class ForestryStudent +{ + private $round_no; + private $stud_id; + private $stage_id; + private $harvest_decision; + private $turn_no; -/*class Student - { - private $teacher_id; - private $stud_id; - private $start_flag; - private $group_id; - private $turn_no; - function public getStartFlag() - { - return $this->start_flag; - } + public function getLatestResource($group_id,$game_id) + { + return db_result(db_query("Select common_resource_pool from vc_forestry_common_resource_pool where vc_group_id=%d and vc_game_id=%d",$group_id,$game_id)); + } - function public getTurnNo() - { - return $this->turn_no; - } + public function getTurnNo() + { + return $this->turn_no; + } + public function setStudentId($stud_id) + { + $this->stud_id=$stud_id; + } + public function setStageId($stage_id) + { + $this->stage_id=$stage_id; + } - }*/ + public function getRoundNo() + { + return $this->round_no; + } + + public function getForestryStudentInfo($group_id,$game_id) + { + $student_decision=db_query("select round_no,harvest_decision from vc_forestry_student where vc_student_id= '%s' ",$this->stud_id); + while($student_data=db_fetch_object($student_decision)) + { + $round_no=$student_data->round_no; + $harvest_decision=$student_data->harvest_decision; + $round_no=(int)$round_no; + //get the resource info from vc_forestry_group_round_information + $resource_info= db_query("select resources_before,resources_after from vc_forestry_group_round_info where vc_group_id=%d and vc_game_id=%d and round_no=%d",$group_id,$game_id,$round_no); + while($data_resource=db_fetch_object($resource_info)) + { + $resources_before=$data_resource->resources_before; + $resources_after=$data_resource->resources_after; + } + $final_row[]=array($round_no,$harvest_decision,$resources_before,$resources_after); + } + $this->round_no=$round_no; + return $final_row; + + } + + public function saveForestryStudentInfo($round_no,$stud_harvest_decision) + { + db_query("Insert into {vc_forestry_student} (round_no,vc_student_id,vc_stage_id,harvest_decision) values(%d,'%s',%d,%d)",$round_no,$this->stud_id,$this->stage_id,$stud_harvest_decision); + } + + public function updateStartFlag($flag) + { + db_query("update vc_student set start_flag=%d where id ='%s' ",$flag,$this->stud_id); + } + + public function updateStageId($stage_no,$experiment_id) + { + db_query("update vc_game set vc_stage_id=(select id from vc_stage where stage_no= %d and vc_experiment_id=%d) where id=%d;",$stage_no,$experiment_id); + } + +} Modified: vcweb/trunk/virtualcommons/experiment/experiment.module =================================================================== --- vcweb/trunk/virtualcommons/experiment/experiment.module 2008-08-01 01:19:07 UTC (rev 19) +++ vcweb/trunk/virtualcommons/experiment/experiment.module 2008-08-02 00:15:56 UTC (rev 20) @@ -15,7 +15,7 @@ function experiment_perm() { - return array('Only Teachers'); + return array('Only Teachers'); } @@ -24,98 +24,98 @@ * Implementation of hook_menu(). */ function experiment_menu($may_cache) { - $items = array(); - if ($may_cache) { - $items[] = array( - 'path' => 'experiment', - 'title' => t('Experiments'), - 'callback' => 'experiment_page', - 'type'=>MENU_CALLBACK, - 'access' => user_access('Only Teachers') - ); - $items[] = array( - 'path' => 'studentgroup', - 'title' => t('Student Information'), - 'callback' => 'drupal_get_form', - 'callback arguments'=>array(studentgroup), - 'type'=>MENU_CALLBACK, - 'access' => user_access('Only Teachers') - ); - /* $items[]=array( 'path' => 'game_start', - // 'title' => t('Forestry Game - Stage 1'), - 'callback'=>'game_start', - // 'callback argument' => array('forestry_game_stage1_part2'), - 'type'=>MENU_CALLBACK, - 'access' => user_access('Only Teachers') - );*/ - } - return $items; + $items = array(); + if ($may_cache) { + $items[] = array( + 'path' => 'experiment', + 'title' => t('Experiments'), + 'callback' => 'experiment_page', + 'type'=>MENU_CALLBACK, + 'access' => user_access('Only Teachers') + ); + $items[] = array( + 'path' => 'studentgroup', + 'title' => t('Student Information'), + 'callback' => 'drupal_get_form', + 'callback arguments'=>array(studentgroup), + 'type'=>MENU_CALLBACK, + 'access' => user_access('Only Teachers') + ); + /* $items[]=array( 'path' => 'game_start', + // 'title' => t('Forestry Game - Stage 1'), + 'callback'=>'game_start', + // 'callback argument' => array('forestry_game_stage1_part2'), + 'type'=>MENU_CALLBACK, + 'access' => user_access('Only Teachers') + );*/ + } + return $items; } /** * Called when user goes to example.com/?q=experiment */ function experiment_page() { - $output = t('Please submit the following form in order to conduct the experiments in the class.'); - // Return the HTML generated from the $form data structure. - $output .= drupal_get_form('experiment_nameform'); - return $output; + $output = t('Please submit the following form in order to conduct the experiments in the class.'); + // Return the HTML generated from the $form data structure. + $output .= drupal_get_form('experiment_nameform'); + return $output; } /** * Defines a form. */ function experiment_nameform() { - $form['#method']='post'; - //+$form['#action']='http://localhost/drupal/?q=studentgroup'; - $form['#id']='experiment'; - $form['no_student'] = array( - '#title' => t('How many Students are participating'), - '#type' => 'textfield', - '#description' => t('Depending on the number of students groups will be formed.'), - '#required'=>TRUE + $form['#method']='post'; + //+$form['#action']='http://localhost/drupal/?q=studentgroup'; + $form['#id']='experiment'; + $form['no_student'] = array( + '#title' => t('How many Students are participating'), + '#type' => 'textfield', + '#description' => t('Depending on the number of students groups will be formed.'), + '#required'=>TRUE - ); + ); - $form['games']=array( - '#type'=>'select', - '#title'=>'Select the Game from the following experiments', - '#default_value'=>variable_get('games',0), - '#options'=> array(t('Choose One '),t('Fishery Game'),t('Forestry Game'),t('Water Irrigation Game')), - '#required'=>TRUE + $form['games']=array( + '#type'=>'select', + '#title'=>'Select the Game from the following experiments', + '#default_value'=>variable_get('games',0), + '#options'=> array(t('Choose One '),t('Fishery Game'),t('Forestry Game'),t('Water Irrigation Game')), + '#required'=>TRUE - ); + ); - $form['terms_usage']=array( - '#type'=>'fieldset', - //'#title'=>t('Terms of Usage') - ); + $form['terms_usage']=array( + '#type'=>'fieldset', + //'#title'=>t('Terms of Usage') + ); - $form['terms_usage']['info']=array( + $form['terms_usage']['info']=array( - '#type'=>'item', - '#title'=>t('Terms and conditions'), - '#description'=>t('<p>Material on this site is used only for educational purpose. None of the material on this site may be used for any other purpose. <br/>All rights reserved and granted by Dr Marco Janssen.</p>') - ); + '#type'=>'item', + '#title'=>t('Terms and conditions'), + '#description'=>t('<p>Material on this site is used only for educational purpose. None of the material on this site may be used for any other purpose. <br/>All rights reserved and granted by Dr Marco Janssen.</p>') + ); - $form['terms_usage']['agree'] = array( - '#type' => 'radios', - '#options' => array(t('I Agree'),t('I Disagree')), - '#title'=>t('By selecting the "I Agree" option, you certifiy that you are agree above terms of use'), - '#default_value'=>variable_get('agree',1), + $form['terms_usage']['agree'] = array( + '#type' => 'radios', + '#options' => array(t('I Agree'),t('I Disagree')), + '#title'=>t('By selecting the "I Agree" option, you certifiy that you are agree above terms of use'), + '#default_value'=>variable_get('agree',1), - ); - $form['submit'] = array( - '#type' => 'submit', - '#value' => t('Submit') - ); + ); + $form['submit'] = array( + '#type' => 'submit', + '#value' => t('Submit') + ); - return $form; + return $form; } /** * Validate the form. @@ -123,22 +123,22 @@ function experiment_nameform_validate($form_id, $form_values) { - // We notify the form API that this field has failed validation. - if ($form_values['games'] == 0) - { - form_set_error('games', - t('Please choose the game.')); - } - if($form_values['agree']==1) - { - form_set_error('agree',t('You have to agree the terms before you play any game.')); - } + // We notify the form API that this field has failed validation. + if ($form_values['games'] == 0) + { + form_set_error('games', + t('Please choose the game.')); + } + if($form_values['agree']==1) + { + form_set_error('agree',t('You have to agree the terms before you play any game.')); + } - //To Check for numbers. - if(preg_match('/[^0-9]+/',$form_values['no_student'])) - { - form_set_error('no_student',t('Number of experiments can not be alphabets. ')); - } + //To Check for numbers. + if(preg_match('/[^0-9]+/',$form_values['no_student'])) + { + form_set_error('no_student',t('Number of experiments can not be alphabets. ')); + } } /** @@ -146,58 +146,42 @@ */ function experiment_nameform_submit($form_id, $form_values) { - $teacher_id=$GLOBALS['user']->uid; - $game_name=$form_values['games']; - $no_student=(int) $form_values['no_student']; - - $game=new Game(); - $game->setExpId($game_name); - $game->setTeacherId($teacher_id); - $game->setStageId(1); - $game->setNoOfStudent($no_student); - $game->setRoundNo(1); - $game->saveGame(); - - if(!isset($_SESSION['no_of_student'])) - { - $_SESSION['no_student']=$no_student; - } + $teacher_id=$GLOBALS['user']->uid; + $experiment_id=$form_values['games']; + $no_student=(int) $form_values['no_student']; + $game=new Game($experiment_id, $teacher_id, $no_student); + $game->save(); + Session::store('game', $game); - if(!isset($_SESSION['game_name'])) - { - $_SESSION['game_name']=$game_name; - } + /* //Fishery + if($game_name==1) + { + $result=db_result(db_query("Select id from {virtualcommons_experiments} where exp_name LIKE '%%Fishery%%' ")); + } + //Forestry + else if($game_name==2) + { + $result=db_result(db_query("Select id from {virtualcommons_experiments} where exp_name LIKE '%%Forestry%%' ")); + } + //Water Irrigation + else if($game_name==3) + { + $result=db_result(db_query("Select id from {virtualcommons_experiments} where exp_name LIKE '%%Water%%' ")); + } - /* //Fishery - if($game_name==1) - { - $result=db_result(db_query("Select id from {virtualcommons_experiments} where exp_name LIKE '%%Fishery%%' ")); - } - //Forestry - else if($game_name==2) - { - $result=db_result(db_query("Select id from {virtualcommons_experiments} where exp_name LIKE '%%Forestry%%' ")); - } + /*$teacher=new Teacher($result,'talele'); + $fname=$teacher->getfname(); + $lname=$teacher->getlname();*/ - //Water Irrigation - else if($game_name==3) - { - $result=db_result(db_query("Select id from {virtualcommons_experiments} where exp_name LIKE '%%Water%%' ")); - } - /*$teacher=new Teacher($result,'talele'); - $fname=$teacher->getfname(); - $lname=$teacher->getlname();*/ + drupal_set_message(t('Thanks for filling out the form. Your Game will start soon. ')); + //db_query("Insert into {virtualcommons_conducts} (users_id, virtualcommons_experiments_id ,date, no_of_students ) values(%d,%d,NOW(),%d)",$teacher_id,$result,$no_student); - drupal_set_message(t('Thanks for filling out the form. Your Game will start soon. ')); - - //db_query("Insert into {virtualcommons_conducts} (users_id, virtualcommons_experiments_id ,date, no_of_students ) values(%d,%d,NOW(),%d)",$teacher_id,$result,$no_student); - - //echo 'Thanks for filling out the form. Your Game will start soon,'. $fname; - return 'studentgroup'; + //echo 'Thanks for filling out the form. Your Game will start soon,'. $fname; + return 'studentgroup'; } /** Old studentgroup module code cut'n'paste job */ @@ -208,176 +192,168 @@ function studentgroup() { - $form['#id']='studentgroup'; - $exp_name=$_SESSION['game_name']; - $no=$_SESSION['no_student']; - //unset($_SESSION['game_name']); - unset($_SESSION['no_student']); + $form['#id']='studentgroup'; + $game=Session::load('game'); + $exp_name = $game->getExperimentName(); + drupal_set_message(t("experiment name: " . $exp_name)); - //drupal_set_message(t('Game name is %exp_name .<br> No of Students are %no',array('%exp_name'=>$exp_name,'%no'=>$no))); - if($exp_name==1) - $exp_name="Fishery Game"; - else if($exp_name==2) - $exp_name="Forestry Game"; - else if($exp_name==3) - $exp_name="Water Irrigation Game"; + $no_of_student = $game->getNumberOfStudents(); + drupal_set_message(t("num students: " . $no_of_student)); + $no_of_groups=0; + $groups_3=0; + $groups_4=0; + $groups_5=0; + $header = array('Group ID', 'Student ID'); - //$no=$_POST['no_student']; - $no_of_student=(int)$no; - $no_of_groups=0; - $groups_3=0; - $groups_4=0; - $groups_5=0; - $header = array('Group ID', 'Student ID'); + // FIXME: seema will fix this later + //no of groups + $groups_5=((int)($no_of_student/5)); - //no of groups - $groups_5=((int)($no_of_student/5)); + $x= $no_of_student%5; - $x= $no_of_student%5; + if($x==0) + { + $no_of_groups=$groups_5; + } + else if($x==1) + { + $groups_5=$groups_5-1; + $groups_3=2; + $no_of_groups=$groups_5 + $groups_3; + } - if($x==0) - { - $no_of_groups=$groups_5; - } - else if($x==1) - { - $groups_5=$groups_5-1; - $groups_3=2; - $no_of_groups=$groups_5 + $groups_3; - } + else if($x==2) + { + $groups_5=$groups_5-1; + $groups_3=1; + $groups_4=1; + $no_of_groups=$groups_5 + $groups_3 + $groups_4; + } + else if($x==3) + { - else if($x==2) - { - $groups_5=$groups_5-1; - $groups_3=1; - $groups_4=1; - $no_of_groups=$groups_5 + $groups_3 + $groups_4; - } - else if($x==3) - { + $groups_3=1; + $no_of_groups=$groups_3 + $groups_5; + } - $groups_3=1; - $no_of_groups=$groups_3 + $groups_5; - } + else if($x==4) + { - else if($x==4) - { + $groups_4=1; + $no_of_groups=$groups_4 + $groups_5; + } - $groups_4=1; - $no_of_groups=$groups_4 + $groups_5; - } + $no_student5=5*$groups_5; + $no_student4=4*$groups_4; + $no_student3=3*$groups_3; - $no_student5=5*$groups_5; - $no_student4=4*$groups_4; - $no_student3=3*$groups_3; + $var=10; + $group_no=1; - $var=10; - $group_no=1; - - // FIXME: duplicated algorithm for generating student ids - if($groups_5 <> 0) + // FIXME: duplicated algorithm for generating student ids + if($groups_5 <> 0) + { + for($i=0;$i<$groups_5;$i++) { - for($i=0;$i<$groups_5;$i++) - { - $groupArray = array(); - for($j=0;$j<5;$j++) - { - $stud_id=uniqid(rand(0,9), false); - $row[]=array('Group '.$group_no,$stud_id); - $groupArray[] = $stud_id; + $groupArray = array(); + for($j=0;$j<5;$j++) + { + $stud_id=uniqid(rand(0,9), false); + $row[]=array('Group '.$group_no,$stud_id); + $groupArray[] = $stud_id; -// $row_submit[]=array($group_no,$stud_id); + // $row_submit[]=array($group_no,$stud_id); - } - $row_submit[$group_no++] = $groupArray; - } + } + $row_submit[$group_no++] = $groupArray; } - if($groups_4 <> 0) + } + if($groups_4 <> 0) + { + for($i=0;$i<$groups_4;$i++) { - for($i=0;$i<$groups_4;$i++) - { - $groupArray = array(); - for($j=0;$j<4;$j++) - { - $stud_id=uniqid(rand(0,9),false); - $row[]=array('Group '.$group_no,$stud_id); - $groupArray[] = $stud_id; -// $row_submit[]=array($group_no,$stud_id); + $groupArray = array(); + for($j=0;$j<4;$j++) + { + $stud_id=uniqid(rand(0,9),false); + $row[]=array('Group '.$group_no,$stud_id); + $groupArray[] = $stud_id; + // $row_submit[]=array($group_no,$stud_id); - } + } - $row_submit[$group_no++] = $groupArray; - } + $row_submit[$group_no++] = $groupArray; } - if($groups_3 <> 0) + } + if($groups_3 <> 0) + { + for($i=0;$i<$groups_3;$i++) { - for($i=0;$i<$groups_3;$i++) - { - $groupArray = array(); - for($j=0;$j<3;$j++) - { - $stud_id=uniqid(rand(0,9), false); - $row[]=array('Group '.$group_no,$stud_id); - $groupArray[] = $stud_id; -// $row_submit[]=array($group_no,$stud_id); - } - $row_submit[$group_no++] = $groupArray; - } + $groupArray = array(); + for($j=0;$j<3;$j++) + { + $stud_id=uniqid(rand(0,9), false); + $row[]=array('Group '.$group_no,$stud_id); + $groupArray[] = $stud_id; + // $row_submit[]=array($group_no,$stud_id); + } + $row_submit[$group_no++] = $groupArray; } + } - if(!isset($_SESSION['student_info'])) - { - $_SESSION['student_info']=$row_submit; - /*foreach ($_SESSION['student_info'] as $key=>$value) - { - drupal_set_message(t('Key is: %key<br>',array('%key'=>$key))); - foreach ($value as $key=>$value) - { - drupal_set_message(t('Key inner is: %key<br> Value inner is: %value',array('%key'=>$key,'%value'=>$value))); - } - }*/ - } + if(!isset($_SESSION['student_info'])) + { + $_SESSION['student_info']=$row_submit; + /*foreach ($_SESSION['student_info'] as $key=>$value) + { + drupal_set_message(t('Key is: %key<br>',array('%key'=>$key))); + foreach ($value as $key=>$value) + { + drupal_set_message(t('Key inner is: %key<br> Value inner is: %value',array('%key'=>$key,'%value'=>$value))); + } + }*/ + } - $form['game_info']=array( - '#type'=>'fieldset', - '#title'=>t('Experiment Information'), - '#tree' => TRUE - ); + $form['game_info']=array( + '#type'=>'fieldset', + '#title'=>t('Experiment Information'), + '#tree' => TRUE + ); - $form['game_info']['info']=array( - '#title'=>t('Please note the following information carefully.'), - '#type'=>'item', - '#description'=>t('<h3>Name of Experiments: '.$exp_name.'<br/>No of Students: '.$no_of_student.'<br/>No of Groups: '.$no_of_groups.'</h3>') - ); + $form['game_info']['info']=array( + '#title'=>t('Please note the following information carefully.'), + '#type'=>'item', + '#description'=>t('<h3>Name of Experiments: '.$exp_name.'<br/>No of Students: '.$no_of_student.'<br/>No of Groups: '.$no_of_groups.'</h3>') + ); - $form['group_info']=array( - '#type'=>'fieldset', - '#title'=>t('Group Information'), - '#tree' => TRUE - ); + $form['group_info']=array( + '#type'=>'fieldset', + '#title'=>t('Group Information'), + '#tree' => TRUE + ); - $form['group_info']['info1']=array( - '#title'=>t('Please assign the following Student IDs to the students.Please do not tell Group IDs to them. After assigning Student IDs, you can tell students to sign using Student Login Page.'), - '#description'=>t('<h3>Number of group of 3 Students: '.$groups_3.'<br/>Number of group of 4 Students: '.$groups_4.'<br/>Number of group of 5 Students: '.$groups_5.'</h3>'), - '#type'=>'item' + $form['group_info']['info1']=array( + '#title'=>t('Please assign the following Student IDs to the students.Please do not tell Group IDs to them. After assigning Student IDs, you can tell students to sign using Student Login Page.'), + '#description'=>t('<h3>Number of group of 3 Students: '.$groups_3.'<br/>Number of group of 4 Students: '.$groups_4.'<br/>Number of group of 5 Students: '.$groups_5.'</h3>'), + '#type'=>'item' - ); + ); - $form['group_info']['table_info']=array( + $form['group_info']['table_info']=array( - '#type'=>'markup', - '#value'=>theme('table',$header,$row) - ); + '#type'=>'markup', + '#value'=>theme('table',$header,$row) + ); - $form['submit'] = array( - '#type' => 'submit', - '#value' => t('Start Game!!!') - ); + $form['submit'] = array( + '#type' => 'submit', + '#value' => t('Start Game!!!') + ); - return $form; + return $form; } @@ -385,73 +361,71 @@ // "start game" function studentgroup_submit($form_id, $form_values) { - //put it in the database student + //put it in the database student - $id=$GLOBALS['user']->uid; - $table=$_SESSION['student_info']; + $id=$GLOBALS['user']->uid; + $table=$_SESSION['student_info']; - $game=new Game(); - $game->setTeacherId($id); - $virtual_conduct_id=$game->getGameID(); - $game->saveGroupStudent($table); + $game = Session::load('game'); + $game->saveGroupStudent($table); - - //depending upon the experiment game, assign the resource table to each group. - $exp_name=$_SESSION['game_name']; - if($exp_name==1) - { - //$exp_name="Fishery Game"; - } + //depending upon the experiment game, assign the resource table to each group. + $exp_name = $game->getExperimentId(); + if($exp_name==1) + { + //$exp_name="Fishery Game"; - else if($exp_name==2) - { - //$exp_name="Forestry Game"; - $game->initForestry(); - } - - else if($exp_name==3) - { - $exp_name="Water Irrigation Game"; - } + } - unset($_SESSION['student_info']); - unset($_SESSION['game_name']); - - //set flag=1 in vc_student and allow them to play - $flag=1; - $game->updateStartFlag($flag); + else if($exp_name==2) + { + //$exp_name="Forestry Game"; + $game->initForestry(); + } - return 'teacher_dashboard'; + else if($exp_name==3) + { + $exp_name="Water Irrigation Game"; + } + unset($_SESSION['student_info']); + unset($_SESSION['game_name']); + + //set flag=1 in vc_student and allow them to play + $flag=1; + $game->updateStartFlag($flag); + + return 'teacher_dashboard'; + } /*function game_start() -{ - $output=t('Please click the Start Game button.'); - $output.=drupal_get_form('game_start_form'); - return $output; -} + { + $output=t('Please click the Start Game button.'); + $output.=drupal_get_form('game_start_form'); + return $output; + } -function game_start_form() -{ - $form['submit'] = array( - '#type' => 'submit', - '#value' => t('Start Game!!!') - ); - return $form; -} + function game_start_form() + { + $form['submit'] = array( + '#type' => 'submit', + '#value' => t('Start Game!!!') + ); + return $form; + } -function game_start_form_submit($form_id,$form_values) -{ - $teacher_id=$GLOBALS['user']->uid; - $virtual_conduct_id=db_result(db_query("select max(id),users_id from {virtualcommons_conducts} where users_id=%d group by users_id",$teacher_id)); + function game_start_form_submit($form_id,$form_values) + { + $teacher_id=$GLOBALS['user']->uid; + $virtual_conduct_id=db_result(db_query("select max(id),users_id from {virtualcommons_conducts} where users_id=%d group by users_id",$teacher_id)); - db_query("update virtualcommons_student set start_flag=true where virtualcommons_conducts_id=%d",$virtual_conduct_id); - return 'teacher_dashboard'; -}*/ + db_query("update virtualcommons_student set start_flag=true where virtualcommons_conducts_id=%d",$virtual_conduct_id); + return 'teacher_dashboard'; + }*/ Modified: vcweb/trunk/virtualcommons/games/forestry_v2/forestry_v2.module =================================================================== --- vcweb/trunk/virtualcommons/games/forestry_v2/forestry_v2.module 2008-08-01 01:19:07 UTC (rev 19) +++ vcweb/trunk/virtualcommons/games/forestry_v2/forestry_v2.module 2008-08-02 00:15:56 UTC (rev 20) @@ -4,25 +4,10 @@ include_once('./' . drupal_get_path('module', 'experiment') . '/experiment.inc'); -/* -function __autoload($class_name) { - drupal_set_message(t('Trying to load ' . $class_name)); - require_once('./' . drupal_get_path('module', 'experiment') . '/experiment.inc'); -} -*/ - /** * implement the _user hook. **/ - - -/*function forestry_v2_perm() - { - return array('Only Teachers'); - - }*/ - // $Id$ /** * Implementation of hook_menu(). @@ -37,10 +22,42 @@ 'access' => TRUE//user_access('Only Teachers') ); +//forestry stage 1 menu +$items[]=array( 'path' => 'forestry_stage1', + 'title' => t('Forestry Game - Stage 1'), + 'callback' => 'forestry_game_stage1', + //'callback arguments'=>array(forestry_game_stage1_multiform), + 'type'=>MENU_CALLBACK, + 'access' => TRUE//user_access('Only Teachers') + ); +$items[]=array( 'path' => 'forestry_stage1_part2', + 'title' => t('Forestry Game - Stage 1'), + 'callback'=>'forestry_game_stage1_part2', + // 'callback argument' => array('forestry_game_stage1_part2'), + 'type'=>MENU_CALLBACK, + 'access' => TRUE//user_access('Only Teachers') + ); + } +else +{ + forestry_v2_load(); +} + return $items; } + +function forestry_v2_load() { + static $loaded = FALSE; + + if (!$loaded) { + $path = drupal_get_path('module', 'forestry_v2'); + drupal_add_css($path .'/form.css'); + $loaded = TRUE; + } +} + /** * Called when user goes to example.com/?q=forestry */ @@ -119,6 +136,8 @@ $game_id = $group->getGameId(); if($flag) { $current_stage_no = $group->getCurrentStageNumber(); + $current_stage_no = (int) $current_stage_no; + drupal_set_message(t('current stage is: '. $current_stage_no)); if($current_stage_no==1) return 'forestry_stage1'; else if($current_stage_no==2) @@ -140,5 +159,370 @@ } } +//Forestry Stage 1 Begins +function forestry_game_stage1() { + drupal_set_message(t('reosurce available ')); + // Return the HTML generated from the $form data structure. + $output = drupal_get_form('forestry_game_stage1_multiform'); + return $output; +} + + + +function forestry_game_stage1_multiform() +{ + + $form['#id']='forestry_game_stage1_multiform'; + $group = unserialize($_SESSION['group']); + $student=new ForestryStudent(); + + $form['#tree'] = TRUE; + $resource_after=0; + $resource_before=0; + + $stud_id=$_SESSION['student_id']; + $resource_available=0; + $round_no=0; + $student->setStudentId($stud_id); + //get the availble resource from the database + + $group_id=$group->getGroupId(); + $game_id=$group->getGameId(); + drupal_set_message(t('group id : '. $group_id . ' Game id'. $game_id)); + $resource_available= $student->getLatestResource($group_id,$game_id); + + drupal_set_message(t('reosurce available : '. $resource_available)); + $resource_available =(int) $resource_available; + if(!isset($_SESSION['prev_resource'])) + { + $_SESSION['prev_resource']=$resource_available; + drupal_set_message(t('PREV resource is NOW set to : ' . $resource_available)); + } + $_SESSION['prev_resource']=$resource_available; + $header=array("Round Number","Your Harvest Decision","Resources Before","Resources After"); + + $final_row=$student->getForestryStudentInfo($group_id,$game_id); + + /*$result=db_query("select round_no,harvest_decision from virtualcommons_forestry_student where virtualcommons_student_id= '%s' ",$stud_id); + while($data=db_fetch_object($result)) + { + $round_no=$data->round_no; + $harvest_decision=$data->harvest_decision; + $round_no=(int)$round_no; + //$resources_before=$data->resources_before; + //$resources_after=$data->resources_after; + $resource_info= db_query("select resources_before,resources_after from virtualcommons_forestry_group_information where virtualcommons_student_group_no=%d and virtualcommons_conducts_id=%d and round_no=%d",$group_no,$conducts_id,$round_no); + while($data_resource=db_fetch_object($resource_info)) + { + $resources_before=$data_resource->resources_before; + $resources_after=$data_resource->resources_after; + } + $final_row[]=array($round_no,$harvest_decision,$resources_before,$resources_after); + }*/ + $round_no=$student->getRoundNo(); + $round_no=$round_no+1; + drupal_set_message(t('round no: ' .$round_no .' '. gettype($round_no) )); + + +//store the round no in hidden field + +$form['round_no']=array( + '#type'=>'hidden', + '#value'=>$round_no + ); + + +$no_rounds=$group->getNoOfRounds(); +//db_result(db_query("Select no_of_rounds from virtualcommons_stage where stage_no=1 and virtualcommons_experiments_id=2")); +$no_rounds=(int) $no_rounds; +drupal_set_message(t('no of rounds are: '.$no_rounds)); +if($round_no <= $no_rounds) +{ + + $form['resources_available']=array( + + '#type'=>'item', + '#title'=>t('Resources Available'), + '#value'=>$resource_available + ); + + $form['indicator']=array( + '#type'=>'fieldset', + '#title'=>t('<b>Round @number</b>',array('@number'=>$round_no)) + ); + + $form['indicator']['harvest_decision']=array( + '#type'=>'textfield', + '#title'=>t('Your Harvest Decision'), + '#default_value'=>'0', + '#size'=>2, + '#maxlength'=>2, + '#required'=>TRUE + ); + $form['indicator']['submit'] = array( + '#type' => 'submit', + '#value' => t('Next') + ); +} +else +{ + $stage_no=$group->getCurrentStageNumber(); + $stage_no=(int) $stage_no; + $form['indicator']['submit'] = array( + '#type' => 'submit', + '#value' => t('Stage '.$stage_no+1) + ); + +} + + $form['resource']=array( + + '#type'=>'fieldset', + '#title'=>t('<b>Resources</b>'), + + ); + $form['resource']['table']=array( + '#type'=>'markup', + '#value'=>theme('table',$header,$final_row) + ); + + +return $form; + +} + + + +function forestry_game_stage1_multiform_validate($form_id,$form_values) +{ +$harvest_decision=$form_values['indicator']['harvest_decision']; +$resource=(int) $_SESSION['prev_resource']; +//$resource=100; +$flag=FALSE; + +if(preg_match('/[^0-9]+/',$harvest_decision)) +{ + form_set_error('harvest_decision',t('Harvest Decison can not be alphabet or special character.')); +} +else +{ + + $harvest_table= $_SESSION['harvest_table']; + + foreach($harvest_table as $key=> $value) + { + + if(!$flag) + { + foreach($value as $key=>$value) + { + + if($key==0) + { + //get min and maximum value of the resource + $harvest_tbl=explode("-",$value); + $min_resource=(int) $harvest_tbl[0]; + $max_resource=(int) $harvest_tbl[1]; + + } + else if($key==1) + { + //get the maximum units player can invest + $harvest_units=(int) $value; + /*drupal_set_message(t('Min : '.$min_resource)); + drupal_set_message(t('Max : '.$max_resource)); + drupal_set_message(t('Units can harvest: '.$harvest_units)); + drupal_set_message(t('Resource can harvest: '.$resource)); + drupal_set_message(t('comparision: '. ($harvest_decision > $harvest_units)));*/ + if(($resource >= $min_resource) && ($resource <= $max_resource)) + { + //depending upon the resource available player can invest units. e.g in group of 5 and resource available=100 then player can invest max 5 units. + //drupal_set_message(t('resource condition successful: ')); + $harvest_decision=(int) $harvest_decision; + if($harvest_decision > $harvest_units) + { + if($harvest_units ==0 ) + form_set_error('harvest_decision',t('Current Resource Level is very low. You can not harvest anything. <br><b>GAME OVER!!!</b>')); + else + form_set_error('harvest_decision',t('Harvest Decison can not be more than %harvest_units.',array('%harvest_units'=>$harvest_units))); + $flag=TRUE; + } + else + $flag=FALSE; + + } + + } + }//end of for1 + + }// end of if(flag) + +if($flag) + break; + + }//end of for 2 + +} + + +return; + +} + + +function forestry_game_stage1_multiform_submit($form_id,$form_values) +{ + $group = unserialize($_SESSION['group']); + + $harvest_table=$_SESSION['harvest_table']; + //$harvest_tbl=explode("-",$harvest_table); + $temp_max_resource= $harvest_table[0][0]; + $temp_max_resource=explode("-",$temp_max_resource); + $max_resource=$temp_max_resource[1]; + drupal_set_message(t('max resource : '. $max_resource)); + + $stud_harvest_decision=(int) $form_values['indicator']['harvest_decision']; + + + $round_no=$form_values['round_no']; + $round_no=(int) $round_no; + + //get the student and set it + $stud_id=$_SESSION['student_id']; + $student=new ForestryStudent(); + $student->setStudentId($stud_id); + $stage_id=$group->getCurrentStageId(); + $resources_before=(int) $_SESSION['prev_resource']; + + drupal_set_message(t('resource_before:'. $resources_before)); + + //insert into the database virtualcommons_forestry_student + // $group_id;$group->getGroupId(); +// $group_no=db_result(db_query(" select group_no from virtualcommons_student where id='%s'",$stud_id)); + $student->setStageId($stage_id); + $student->saveForestryStudentInfo($round_no,$stud_harvest_decision); +//db_query("Insert into {virtualcommons_forestry_student} (round_no,virtualcommons_student_id,virtualcommons_stage_no,virtualcommons_student_group_no,harvest_decision,date) values(%d,'%s',%d,%d,%d,NOW())",$round_no,$stud_id,1,$group_no,$stud_harvest_decision); + + //check whether everybody has made decision about harvesting + +/*$virtual_conducts_id=db_result(db_query(" select virtualcommons_conducts_id from virtualcommons_student where id='%s'",$stud_id)); + +$db_harvest_decision=db_result(db_query("select harvest_decision from virtualcommons_forestry_common_resource_pool where virtualcommons_student_group_no=%d and virtualcommons_conducts_id=%d",$group_no,$virtual_conducts_id)); + $harvest_decision=$stud_harvest_decision; + + $db_harvest_decision=(int) $db_harvest_decision; + $temp_harvest_decision=$harvest_decision + $db_harvest_decision; + + db_query(" update virtualcommons_forestry_common_resource_pool set harvest_decision=%d where virtualcommons_student_group_no=%d and virtualcommons_conducts_id=%d",$temp_harvest_decision,$group_no,$virtual_conducts_id);*/ + +//disable for next round until teacher clicks the button +//db_query("update virtualcommons_student set start_flag=false where id='%s'",$stud_id); + $flag=false; + $student->updateStartFlag($flag); + $no_rounds=$group->getNoOfRounds(); + //$no_rounds=db_result(db_query("Select no_of_rounds from virtualcommons_stage where stage_no=1 and virtualcommons_experiments_id=2")); + $no_rounds=(int) $no_rounds; + drupal_set_message(t('$actual_no_rounds' . $no_rounds . '$current_round_no' . $round_no)); +if($form_values['indicator']['submit']=="Stage 2") +{ + $stage_no=2; + $exp_id=$group->getExperimentId(); + $student->updateStageId($stage_no,$exp_id); + //db_query("update virtualcommons_conducts set virtualcommons_stage_no=%d where id=%d",2,$virtual_conducts_id); + unset($_SESSION['prev_resource']); + + return 'rules'; +} +else + return 'forestry_stage1_part2'; + + +} + +function theme_forestry_game_stage1_multiform($form) +{ +$output='<div class="indicator"><table style="text-align: center; width: 100%;" border="0" + cellpadding="0" cellspacing="0"> + <tbody> + <tr> + <td style="width: 80%;"> </td> + + <td nowrap>'; +$output.=drupal_render($form ['resources_available']); +$output.='</td> + </tr> + + + <tr> + <td style="width: 30%;" colspan="2" rowspan="1">'; +$output.= drupal_render($form['indicator']); + + +$output.= drupal_render($form['indicator']['harvest_decision']); +$output.='</td>'; + //<td style="text-align: center;" colspan="2" rowspan="1">'; +$output.=drupal_render($form['indicator']['submit']); +$output.=' + </tr><tr> <td> </td> </tr> +<tr> + <td colspan="2" rowspan="1">'; + +$output.=drupal_render($form['resource']); + +$output.=drupal_render($form['resource']['table']); +$output.=' + </td> + </tr> + </tbody> + </table> +</div>'; +$output.=drupal_render($form); +return $output; + +} + + +function forestry_game_stage1_part2() +{ + +$output=t('Please click the Next button for next round'); +$output.=drupal_get_form('forestry_game_stage1_part2form'); +return $output; +} + +function forestry_game_stage1_part2form() +{ + + $form['submit'] = array( + '#type' => 'submit', + '#value' => t('Next Round') + ); +return $form; +} + + + +function forestry_game_stage1_part2form_submit($form_id,$form_values) +{ + $stud_id=$_SESSION['student_id']; + $round_no=db_result(db_query(" select max(round_no) from virtualcommons_forestry_student where virtualcommons_student_id='%s'",$stud_id)); + $round_no=(int) $round_no; + drupal_set_message(t('curr round'.$round_no)); + $flag=db_result(db_query("Select start_flag from virtualcommons_student where id='%s'",$stud_id)); + $no_rounds=db_result(db_query("Select no_of_rounds from virtualcommons_stage where stage_no=1 and virtualcommons_experiments_id=2")); + $no_rounds=(int) $no_rounds; + drupal_set_message(t('flag'.$flag)); + //if($round_no >= $no_rounds) { } + if($flag) + return 'forestry_stage1'; + else if(!($flag)) + return 'forestry_stage1_part2'; + +} + + + + + Modified: vcweb/trunk/virtualcommons/games/teacher_dashboard/teacher_dashboard.install =================================================================== --- vcweb/trunk/virtualcommons/games/teacher_dashboard/teacher_dashboard.install 2008-08-01 01:19:07 UTC (rev 19) +++ vcweb/trunk/virtualcommons/games/teacher_dashboard/teacher_dashboard.install 2008-08-02 00:15:56 UTC (rev 20) @@ -16,13 +16,13 @@ round_no int NOT NULL, vc_game_id int NOT NULL, vc_group_id int NOT NULL, + vc_stage_id int NOT NULL, total_harvest_decision int NOT NULL, resources_before int NOT NULL, resources_after int NOT NULL, vc_rules_id int NOT NULL, dice int default 0, - PRIMARY KEY(id), FOREIGN KEY(vc_game_id) REFERENCES vc_game(id) @@ -31,6 +31,8 @@ FOREIGN KEY(vc_group_id) REFERENCES vc_group(id) ON DELETE CASCADE, + FOREIGN KEY(vc_stage_id) REFERENCES vc_stage(id) ON DELETE CASCADE, + FOREIGN KEY(vc_rules_id) REFERENCES vc_rules(id) ON DELETE CASCADE @@ -87,7 +89,6 @@ function teacher_dashboard_uninstall() { - db_query("DROP TABLE {vc_forestry_group_round_info}"); drupal_set_message(t('Forestry Group Round Information is successfully deleted from the database. We hope.')); } Modified: vcweb/trunk/virtualcommons/games/teacher_dashboard/teacher_dashboard.module =================================================================== --- vcweb/trunk/virtualcommons/games/teacher_dashboard/teacher_dashboard.module 2008-08-01 01:19:07 UTC (rev 19) +++ vcweb/trunk/virtualcommons/games/teacher_dashboard/teacher_dashboard.module 2008-08-02 00:15:56 UTC (rev 20) @@ -1,28 +1,30 @@ <?php +// vim:sts=2:sw=2:filetype=php + function teacher_dashboard_menu($may_cache) { $items = array(); if ($may_cache) - { - - $items[]=array( 'path' => 'teacher_dashboard', - 'title' => t('Teacher Dashboard'), - 'callback' => 'teacher_dashboard', - 'type'=>MENU_CALLBACK, - 'access' => user_access('Only Teachers') - ); - - $items[]=array( 'path' => 'teacher_dashboard_part2', - 'title' => t('Teacher Dashboard'), - 'callback'=>'teacher_dashboard_part2', - // 'callback argument' => array('forestry_game_stage1_part2'), - 'type'=>MENU_CALLBACK, - 'access' => user_access('Only Teachers') - ); + { + + $items[]=array( 'path' => 'teacher_dashboard', + 'title' => t('Teacher Dashboard'), + 'callback' => 'teacher_dashboard', + 'type'=>MENU_CALLBACK, + 'access' => user_access('Only Teachers') + ); + + $items[]=array( 'path' => 'teacher_dashboard_part2', + 'title' => t('Teacher Dashboard'), + 'callback'=>'teacher_dashboard_part2', + // 'callback argument' => array('forestry_game_stage1_part2'), + 'type'=>MENU_CALLBACK, + 'access' => user_access('Only Teachers') + ); } -/*else { - teacher_load(); - }*/ + /*else { + teacher_load(); + }*/ return $items; } @@ -30,12 +32,14 @@ { // Return the HTML generated from the $form data structure. -$teacher_id=$GLOBALS['user']->uid; -//db_query( - //drupal_set_message(t($teacher_id)); - $virtual_conduct_id=db_result(db_query("select max(id) from {virtualcommons_conducts} where users_id=%d group by users_id",$teacher_id)); - $exp_name=db_result(db_query("select exp_name from virtualcommons_experiments where id =(select virtualcommons_experiments_id from virtualcommons_conducts where id=%d)",$virtual_conduct_id)); - $output=t('<br> <h2>'. $exp_name . '</h2>'); + $teacher_id=$GLOBALS['user']->uid; + //db_query( + //drupal_set_message(t($teacher_id)); +// $virtual_conduct_id=db_result(db_query("select max(id) from {virtualcommons_conducts} where users_id=%d group by users_id",$teacher_id)); + // $exp_name=db_result(db_query("select exp_name from virtualcommons_experiments where id =(select virtualcommons_experiments_id from virtualcommons_conducts where id=%d)",$virtual_conduct_id)); + $game = Session::load('game'); + $exp_name=$game->getExperimentName(); + $output=t('<br> <h2>'. $exp_name . '</h2>'); $output .= drupal_get_form('teacher_dashboard_multiform'); return $output; } @@ -44,126 +48,111 @@ function teacher_dashboard_multiform($form_values=NULL) { - $form['#id']='teacher_dashboard_multiform'; - $form['#multistep']=TRUE; - $teacher_id=$GLOBALS['user']->uid; - $round_no=0; - $stage_flag=FALSE; - - $virtual_conduct_id=db_result(db_query("select max(id),users_id from {virtualcommons_conducts} where users_id=%d group by users_id",$teacher_id)); - - //retrive values for stage 1 - - $header_stage1=array('Round No','Group No', 'Group Harvest Decision','Resources Before','Resources After'); - $result=db_query(" select round_no,virtualcommons_student_group_no,total_harvest_decision,resources_after,resources_before from {virtualcommons_forestry_group_information} where virtualcommons_conducts_id=%d and virtualcommons_stage_no=%d",$virtual_conduct_id,1); + $form['#id']='teacher_dashboard_multiform'; + $form['#multistep']=TRUE; + $game = Session::load('game'); + // $teacher_id=$GLOBALS['user']->uid; + $round_no=0; + $stage_flag=FALSE; - while($data=db_fetch_object($result)) - { - $round_no=$data->round_no; - $group_no=$data->virtualcommons_student_group_no; - $total_harvest_decision=$data->total_harvest_decision; - $resource_before=$data->resources_before; - $resource_after=$data->resources_after; - $row_stage1[]=array($round_no,$group_no,$total_harvest_decision,$resource_before,$resource_after); - } - - + //$virtual_conduct_id=db_result(db_query("select max(id),users_id from {virtualcommons_conducts} where users_id=%d group by users_id",$teacher_id)); - if(!isset($form_values)) - { //$round_no=(int) $round_no; - $step=0; - drupal_set_message(t('step when form values are null: '.$step)); - } - else - { - $step=(int) $form_values['step']; - $step++; - drupal_set_message(t('step when form values are not null: '.$step)); - } - -$no_rounds=db_result(db_query("Select no_of_rounds from virtualcommons_stage where stage_no=1 and virtualcommons_experiments_id=2")); -$no_rounds=(int) $no_rounds; -drupal_set_message(t('no of rounds are: '.$no_rounds)); -if($round_no==$no_rounds) -{ - if(isset($_SESSION['next_stage'])) - { - $stage_flag=FALSE; - unset($_SESSION['next_stage']); - } - else - $stage_flag=TRUE; -} - - // $_SESSION['step']=$step; + //retrive values for stage 1 - //$form['#redirect']=FALSE; + $header_stage1=array('Round No','Group No', 'Group Harvest Decision','Resources Before','Resources After'); + $row_stage1 = $game->getAllGroupRoundInfo(); - $form['round_no']=array('#type'=>'hidden','#value'=>$round_no); - $form['game_id']=array('#type'=>'hidden','#value'=>$virtual_conduct_id); - //$form['exp_name']=array('#type'=>'hidden','#value'=>$exp_name); - //$form['step']=array('#type'=>'hidden','#value'=>$step); - $form['stage1']=array( - '#type'=>'fieldset', - '#title'=>t('<b>Stage 1</b>') - ); + if(!isset($form_values)) + { //$round_no=(int) $round_no; + $step=0; + drupal_set_message(t('step when form values are null: '.$step)); + } + else + { + $step=(int) $form_values['step']; + $step++; + drupal_set_message(t('step when form values are not null: '.$step)); + } + $no_rounds= $game->getNumberOfRounds(); +// $no_rounds=(int) $no_rounds; + drupal_set_message(t('no of rounds are: '.$no_rounds)); + if($round_no==$no_rounds) + { + if(isset($_SESSION['next_stage'])) + { + $stage_flag=FALSE; + unset($_SESSION['next_stage']); + } + else + $stage_flag=TRUE; + } - $form['stage1']['table']=array( - '#type'=>'markup', - '#value'=>theme('table',$header_stage1,$row_stage1) - ); + // $_SESSION['step']=$step; - $form['stage2']=array( - '#type'=>'fieldset', - '#title'=>t('<b>Stage 2</b>') - ); + //$form['#redirect']=FALSE; + $form['round_no']=array('#type'=>'hidden','#value'=>$round_no); + $form['game_id']=array('#type'=>'hidden','#value'=>$virtual_conduct_id); + //$form['exp_name']=array('#type'=>'hidden','#value'=>$exp_name); + //$form['step']=array('#type'=>'hidden','#value'=>$step); + $form['stage1']=array( + '#type'=>'fieldset', + '#title'=>t('<b>Stage 1</b>') + ); - $form['stage2']['table']=array( - '#type'=>'markup', - '#value'=>theme('table',$header_stage2,$row_stage2) - ); - if($stage_flag) - { - $form['submit'] = array( - '#type' => 'submit', - '#value' => t('Go to Stage 2') - ); - $stage_flag=FALSE; - } - else - { - $form['submit'] = array( - '#type' => 'submit', - '#value' => t('Next Round') - ); - } + $form['stage1']['table']=array( + '#type'=>'markup', + '#value'=>theme('table',$header_stage1,$row_stage1) + ... [truncated message content] |