[virtualcommons-svn] SF.net SVN: virtualcommons:[38] vcweb/trunk/virtualcommons/experiment
Status: Beta
Brought to you by:
alllee
From: <see...@us...> - 2008-08-11 23:16:28
|
Revision: 38 http://virtualcommons.svn.sourceforge.net/virtualcommons/?rev=38&view=rev Author: seematalele Date: 2008-08-11 23:16:36 +0000 (Mon, 11 Aug 2008) Log Message: ----------- written code for rule 1 in forestry_v2 module. Modified Paths: -------------- vcweb/trunk/virtualcommons/experiment/experiment.inc vcweb/trunk/virtualcommons/experiment/experiment.module vcweb/trunk/virtualcommons/experiment/games/forestry_v2/forestry_v2.module vcweb/trunk/virtualcommons/experiment/teacher_dashboard/teacher_dashboard.module Modified: vcweb/trunk/virtualcommons/experiment/experiment.inc =================================================================== --- vcweb/trunk/virtualcommons/experiment/experiment.inc 2008-08-09 01:56:09 UTC (rev 37) +++ vcweb/trunk/virtualcommons/experiment/experiment.inc 2008-08-11 23:16:36 UTC (rev 38) @@ -214,6 +214,7 @@ public function isStageOver() { + drupal_set_message(t('Current round no is: ' .$this->getCurrentRoundNo() . ' and no of rounds are: ' .$this->getNumberOfRounds())); return ($this->getCurrentRoundNo() - 1 == $this->getNumberOfRounds()); } @@ -226,14 +227,16 @@ public function getValidStudentIds($group_id) { $turn_sequence = $this->getTurnSequence($group_id); - $result = db_query('SELECT vc_student_id + $result = db_query('SELECT id FROM vc_student WHERE vc_group_id=%d AND turn_no IN (%s)', $group_id, $turn_sequence); $valid_ids = array(); while ($data = db_fetch_object($result)) { - $valid_ids[] = $data->vc_student_id; + $valid_ids[] = $data->id; + drupal_set_message(t($data->id. ' , ')); } + return $valid_ids; } @@ -294,6 +297,7 @@ if ($dice == 6) { // check to see if we need to assess fines $this->assessFines($group_id, $current_rule_number); + } } $resources_before=$crp=$data->crp; @@ -393,9 +397,10 @@ //determine the rule for a group - $result_group=db_query("select id from vc_group where vc_game_id=%d",$this->game_id); - while($data=db_fetch_object($result_group)) - { + + $result_group=db_query("select id from vc_group where vc_game_id=%d",$this->game_id); + while($data=db_fetch_object($result_group)) + { $group_id=$data->id; //$result_voting=db_query("select vc_rules_id,count(vc_rules_id) as rule_cnt from vc_student_voting where vc_student_id in (select id from vc_student where vc_group_id=%d) group by vc_rules_id",$group_id); $result_voting=db_query(" select vc_rules_id, count(vc_rules_id) as rule_cnt from vc_student_voting v @@ -464,6 +469,7 @@ // drupal_set_message(t('Rule id : ' . $final_rule_id.'Group id is: ' . $group_id)); }//end of while + }//end of init function @@ -563,6 +569,7 @@ } } + public function getTurnSequence() { return $this->game->getTurnSequence($this->group_id); } @@ -669,15 +676,41 @@ } +public function isGameFinished() +{ +return $this->game->isFinished(); +} +public function isStageOver() +{ +drupal_set_message(t('$this->game->getCurrentRoundNo(): ' . $this->game->getCurrentRoundNo() . ' $this->game->getNumberOfRounds()'. $this->game->getNumberOfRounds())); + return ($this->game->getCurrentRoundNo() -1 == $this->game->getNumberOfRounds()); +} +public function getRoundNo() +{ + return $this->game->getCurrentRoundNo(); +} /*public function getRuleDescription() { db_result(db_query("select description select vc_selected_rules_id from vc_group where id=%d",$this->group_id)); }*/ +public function isTurn($stud_id) + { + $valid_id=$this->game->getValidStudentIds($this->group_id); + $flag=FALSE; + drupal_set_message(t('Group id is : '. $this->group_id. 'Student Id is : '. $stud_id . ' Valid student ids are: ' . $valid_id[0] . ',' . $valid_id[1])); + if(in_array($stud_id,$valid_id)) + { + $flag= TRUE; + } + else + $flag= FALSE; + drupal_set_message(t('flag for student turn : '. $flag)); + return $flag; + } - }//end of Group /** @@ -711,26 +744,26 @@ { $this->stage_id=$stage_id; } - - public function getRoundNo($game_id,$stage_id) + + /* public function getRoundNo($game_id,$stage_id) { //$this-> - $this->round_no=db_result(db_query("select current_round_no from vc_game where id=%d and vc_stage_id=%d",$game_id,$stage_id)); + return db_result(db_query("select current_round_no from vc_game where id=%d and vc_stage_id=%d",$game_id,$stage_id)); //drupal_set_message(t('round no is:' .$stage_id . $this->round_no . $game_id)); - return $this->round_no; - } +// return $this->round_no; + }*/ - public function getForestryStudentInfo($group_id,$game_id) + public function getForestryStudentInfo($group_id,$game_id,$stage_id) { - $student_decision=db_query("select round_no,harvest_decision from vc_forestry_student where vc_student_id= '%s' ",$this->stud_id); + $student_decision=db_query("select round_no,harvest_decision from vc_forestry_student where vc_student_id= '%s' and vc_stage_id=%d ",$this->stud_id,$stage_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); + $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 and vc_stage_id=%d",$group_id,$game_id,$round_no,$stage_id); while($data_resource=db_fetch_object($resource_info)) { $resources_before=$data_resource->resources_before; @@ -769,6 +802,7 @@ { 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,$game_id); } + } Modified: vcweb/trunk/virtualcommons/experiment/experiment.module =================================================================== --- vcweb/trunk/virtualcommons/experiment/experiment.module 2008-08-09 01:56:09 UTC (rev 37) +++ vcweb/trunk/virtualcommons/experiment/experiment.module 2008-08-11 23:16:36 UTC (rev 38) @@ -13,7 +13,7 @@ -function experiment_perm() +function experiment_menuperm() { return array('Only Teachers'); Modified: vcweb/trunk/virtualcommons/experiment/games/forestry_v2/forestry_v2.module =================================================================== --- vcweb/trunk/virtualcommons/experiment/games/forestry_v2/forestry_v2.module 2008-08-09 01:56:09 UTC (rev 37) +++ vcweb/trunk/virtualcommons/experiment/games/forestry_v2/forestry_v2.module 2008-08-11 23:16:36 UTC (rev 38) @@ -193,6 +193,7 @@ $group_id=$group->getGroupId(); $game_id=$group->getGameId(); + $round_no=$group->getRoundNo(); drupal_set_message(t('group id : '. $group_id . ' Game id: '. $game_id)); $resource_available= $student->getLatestResource($group_id,$game_id); @@ -205,20 +206,27 @@ drupal_set_message(t('PREV resource is NOW set to : ' . $resource_available)); } $_SESSION['prev_resource']=$resource_available; - + $current_stage_id=$group->getCurrentStageId(); + drupal_set_message(t('current stage id: '. $current_stage_id)); $game = $group->getGame(); if ( $game->isVotingEnabled() ) { $header=array("Round Number","Your Harvest Decision","Resources Before","Resources After",'Penalty', 'Net Gain', ); + if($group->isTurn($stud_id)) + $form['turn']=array( + '#type'=>'item', + '#value'=>t('You have chosen for this round to harvest. You can harvest for this round.') + ); + } else { $header=array("Round Number","Your Harvest Decision","Resources Before","Resources After"); } - $row=$student->getForestryStudentInfo($group_id,$game_id); + $row=$student->getForestryStudentInfo($group_id,$game_id,$current_stage_id); - $stage_id=$group->getCurrentStageId(); + // $stage_id=$group->getCurrentStageId(); - $round_no=$student->getRoundNo($game_id,$stage_id); + drupal_set_message(t('round no: ' .$round_no .' '. gettype($round_no) )); @@ -230,7 +238,7 @@ '#value'=>$round_no ); - drupal_set_message(t('current stage id: '. $group->getCurrentStageId())); + // $no_rounds = $group->getNumberOfRounds(); drupal_set_message(t('game id:' . $group->getGameId())); $no_rounds=$group->getNumberOfRounds(); @@ -258,6 +266,10 @@ '#maxlength'=>2, '#required'=>TRUE ); + $form['indicator']['submit'] = array( + '#type' => 'submit', + '#value' => t('Submit') + ); } else @@ -268,10 +280,8 @@ '#type' => 'submit', '#value' => t('Next Stage') ); - + } - } - $form['resource']=array( '#type'=>'fieldset', '#title'=>t('<b>Resources</b>'), @@ -392,31 +402,12 @@ 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->getNumberOfRounds(); - //$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']=="Next Stage") @@ -424,8 +415,6 @@ $stage_no=2; $exp_id=$group->getExperimentId(); $game_id=$group->getGameId(); - // $student->updateStageId($stage_no,$exp_id,$game_id); - //db_query("update virtualcommons_conducts set virtualcommons_stage_no=%d where id=%d",2,$virtual_conducts_id); unset($_SESSION['prev_resource']); return 'rules'; @@ -439,7 +428,10 @@ function theme_forestry_game_stage1_multiform($form) { $output='<div class="indicator"><table style="text-align: center; width: 100%;" border="0" - cellpadding="0" cellspacing="0"> + cellpadding="0" cellspacing="0">'; + $output.='<h2 align="center" style="color:#990000">'; + $output.=drupal_render($form['turn']); + $output.='</h2> <tbody> <tr> <td style="width: 80%;"> </td> @@ -482,7 +474,7 @@ function forestry_game_stage1_part2() { - $output=t('Please click the Next button for next round'); + // $output=t('Please click the Next button for next round'); $output.=drupal_get_form('forestry_game_stage1_part2form'); return $output; } @@ -490,12 +482,57 @@ function forestry_game_stage1_part2form() { +$student=Session::get('forestry_student'); +$stage_flag=FALSE; +$group=Session::get('group'); +$group_id=$group->getGroupId(); + $game_id=$group->getGameId(); + if ($group->isGameFinished()) + { + drupal_set_message('The game is over. Thanks for participating!'); +// $_SESSION['finished']='game'; + } + else + { + $stage_flag=$group->isStageOver(); + } + if($stage_flag) + { + $header=array("Round Number","Your Harvest Decision","Resources Before","Resources After"); + $row=$student->getForestryStudentInfo($group_id,$game_id); + + $form['stage_info']=array( + '#type'=>'item', + '#value'=>t(' Following is the summary of your harvest decision for this stage. This stage is over.') + ); + + $form['resource']=array( + '#type'=>'fieldset', + '#title'=>t('<b>Resources</b>'), - $form['submit'] = array( - '#type' => 'submit', - '#value' => t('Next Round') - ); + ); + $form['resource']['table']=array( + '#type'=>'markup', + '#value'=>theme('table',$header,$row) + ); + + $form['submit'] = array( + '#type' => 'submit', + '#value' => t('Next Stage') + ); + unset($_SESSION['finished']); + } + + + else + { + $form['submit'] = array( + '#type' => 'submit', + '#value' => t('Next Round') + ); + } return $form; + } @@ -505,20 +542,45 @@ $stud_id=$_SESSION['student_id']; $student=Session::get('forestry_student'); + $group=Session::get('group'); + + + $stage_flag=FALSE; + drupal_set_message(t($form_values['submit'])); $flag=$student->getStartFlag(); - /*$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'; +//if($round_no >= $no_rounds) { } + /*if($form_values['submit']=="Next Round") + { + $flag=$student->getStartFlag(); +drupal_set_message(t('flag'.$flag)); + if ($group->isGameFinished()) + { + drupal_set_message('The game is over. Thanks for participating!'); +// $_SESSION['finished']='game'; + } + else + { + $stage_flag=$group->isStageOver(); +// if($stage_flag) + //if(!(isset($_SESSION['finished']))) + //$_SESSION['finished']='stage'; + drupal_set_message(t('stage flag is: ' . $stage_flag)); + }*/ + if($flag) + { + // if($stage_flag) + return 'forestry_stage1'; + } + else { + return 'forestry_stage1_part2'; + } + + + + + + } Modified: vcweb/trunk/virtualcommons/experiment/teacher_dashboard/teacher_dashboard.module =================================================================== --- vcweb/trunk/virtualcommons/experiment/teacher_dashboard/teacher_dashboard.module 2008-08-09 01:56:09 UTC (rev 37) +++ vcweb/trunk/virtualcommons/experiment/teacher_dashboard/teacher_dashboard.module 2008-08-11 23:16:36 UTC (rev 38) @@ -111,8 +111,8 @@ else { $stage_flag=$game->isStageOver(); - if($stage_flag) - $game->setRoundNo($game->getCurrentRoundNo()); + // if($stage_flag) + //$game->setRoundNo($game->getCurrentRoundNo()); } @@ -134,7 +134,7 @@ // $virtual_conduct_id=(int) $form_values['game_id']; $game= Session::get('game'); drupal_set_message(t($form_values['submit'])); - if($form_values['submit']=="Go to Next Stage") + /* if($form_values['submit']=="Go to Next Stage") { if (($game->isVotingEnabled())) { @@ -144,7 +144,7 @@ } } - } + }*/ } @@ -156,6 +156,7 @@ //set flag, when flag=TRUE it means round is even , when flag=FALSE it means //that round is uneven. Ja! $game=Session::get('game'); + $game->setRoundNo($game->getCurrentRoundNo()); if($form_values['submit']=="Next Round") { // $no_rounds = $game->getNumberOfRounds(); @@ -164,13 +165,13 @@ } else if($form_values['submit']=="Go to Next Stage") { //initialise the stage 2 + - drupal_set_message(t('Go to stage 2')); // FIXME: initNextStage is actually an initialization for voting stage - // remove that assumption - + $game->setRoundNo($game->getCurrentRoundNo()); $game->initNextStage(); if ($game->isVotingEnabled()) { @@ -178,11 +179,15 @@ { $rule_no=$game->initRules(); } + else + form_set_error('submit',t('Please tell students to vote. Without voting you can not proceed to Stage 2')); } + } return 'teacher_dashboard'; } +?> \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |