[virtualcommons-svn] SF.net SVN: virtualcommons:[28] vcweb/trunk/virtualcommons
Status: Beta
Brought to you by:
alllee
From: <al...@us...> - 2008-08-06 23:58:11
|
Revision: 28 http://virtualcommons.svn.sourceforge.net/virtualcommons/?rev=28&view=rev Author: alllee Date: 2008-08-06 23:58:18 +0000 (Wed, 06 Aug 2008) Log Message: ----------- moving games into experiment Modified Paths: -------------- vcweb/trunk/virtualcommons/experiment/experiment.inc vcweb/trunk/virtualcommons/experiment/games/rules/rules.install vcweb/trunk/virtualcommons/experiment/games/rules/rules.module vcweb/trunk/virtualcommons/experiment/survey-questions.sql Added Paths: ----------- vcweb/trunk/virtualcommons/experiment/games/ vcweb/trunk/virtualcommons/experiment/games/forestry_v2/forestry_v2.install vcweb/trunk/virtualcommons/experiment/games/forestry_v2/forestry_v2.module vcweb/trunk/virtualcommons/experiment/games/teacher_dashboard/teacher_dashboard.install vcweb/trunk/virtualcommons/experiment/games/teacher_dashboard/teacher_dashboard.module Removed Paths: ------------- vcweb/trunk/virtualcommons/experiment/games/forestry_v2/forestry_v2.install vcweb/trunk/virtualcommons/experiment/games/forestry_v2/forestry_v2.module vcweb/trunk/virtualcommons/experiment/games/teacher_dashboard/teacher_dashboard.install vcweb/trunk/virtualcommons/experiment/games/teacher_dashboard/teacher_dashboard.module vcweb/trunk/virtualcommons/games/ Modified: vcweb/trunk/virtualcommons/experiment/experiment.inc =================================================================== --- vcweb/trunk/virtualcommons/experiment/experiment.inc 2008-08-06 05:48:17 UTC (rev 27) +++ vcweb/trunk/virtualcommons/experiment/experiment.inc 2008-08-06 23:58:18 UTC (rev 28) @@ -29,6 +29,7 @@ private $current_round_no; private $no_of_students; private $experiment_name; + private $prev_round_no; public function __construct($game_id, $experiment_id=-1, $teacher_id=-1, $no_of_students=-1) { $this->game_id = $game_id; @@ -37,6 +38,7 @@ $this->no_of_students = $no_of_students; $this->current_stage_no = 1; $this->current_round_no = 1; + $this->prev_round_no=1; $this->experiment_name = db_result(db_query("select e.name from vc_experiment e where e.id=%d", $experiment_id)); } @@ -125,7 +127,9 @@ } public function isVotingEnabled() { - return db_result(db_query("select s.voting from vc_stage s inner join vc_game g on s.id=g.vc_stage_id and g.id=%d", $this->game_id)); + $flag=db_result(db_query("select s.voting from vc_stage s inner join vc_game g on s.id=g.vc_stage_id and g.id=%d", $this->game_id)); + drupal_set_message(t('Voting Flag is: '.$flag)); + return $flag; } public function isVotingEnabledForStage($stage_id) { @@ -135,6 +139,7 @@ public function isVotingDone() { $count=db_result(db_query("select count(*) from vc_group where vc_game_id=%d and vc_selected_rules_id is null",$this->game_id)); + drupal_set_message(t('Is voting done Flag: '.$count)); return $count==0; } // FIXME: turn into $forestryGame->init() overloaded method @@ -195,6 +200,11 @@ return db_result(db_query("SELECT s.stage_no FROM {vc_game g, vc_stage s} WHERE g.vc_stage_id=s.id AND g.id=%d", $this->game_id)); } + /*public function getPrevRoundNo() + { + + return ($this->getCurrentRoundNo() -1); + }*/ public function processGroups() { $round_no=$this->getCurrentRoundNo(); @@ -223,10 +233,14 @@ } //update start flag $this->updateStartFlag(true); + $this->prev_round_no=$round_no; - //update crrent round_no + //update current round_no $round_no=$round_no+1; - if ($round_no > ($this->getNumberOfRounds())) { + $this->current_round_no = $round_no; + drupal_set_message(t('Round no which is over is :' . $this->prev_round_no . 'Current round no set to is: ' . $this->current_round_no)); + //call setRound function + /* if ($round_no > ($this->getNumberOfRounds())) { // reset round number to 1 $this->current_round_no = 1; // increment stage number and try to find a stage id for that stage @@ -243,11 +257,80 @@ } else { $this->current_round_no = $round_no; - } + }*/ db_query("UPDATE {vc_game} SET current_round_no=%d WHERE id=%d", $this->current_round_no, $this->game_id); } +public function setRoundNo($round_no) +{ + if ($round_no > ($this->getNumberOfRounds())) { + // reset round number to 1 + $this->current_round_no = 1; + + // increment stage number and try to find a stage id for that stage + + $current_stage_no = $this->getCurrentStageNumber(); + $next_stage_id = $this->getStageId( $current_stage_no + 1 ); + if ($next_stage_id) { + db_query("UPDATE {vc_game} SET vc_stage_id=%d WHERE id=%d", $next_stage_id, $this->game_id); + } + else { + // experiment is over. figure out how to signal the end of + + } + } + else { + $this->current_round_no = $round_no; + } + db_query("UPDATE {vc_game} SET current_round_no=%d WHERE id=%d", $this->current_round_no, $this->game_id); + + +} + + + +//Stage 2 + +public function initNextStage() +{ +//reset the forestry common resource pool + + $result_resource=db_query("select max_resources,vc_group_id from vc_forestry_common_resource_pool where vc_game_id=%d",$this->game_id); + while($data=db_fetch_object($result_resource)) + { + db_query("update vc_forestry_common_resource_pool set common_resource_pool=%d where vc_group_id=%d and vc_game_id=%d",$data->max_resources,$data->vc_group_id,$this>game_id); + + } + +//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)) + { + $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); + $max=0; + while($data=db_fetch_object($result_voting)) + { + $rule_id=$data->vc_rules_id; + $rule_cnt=$data->rule_cnt; + //$voting[$data->vc_rules_id]=$data->rule_cnt; + if($rule_cnt> $max) + { + $max =$rule_cnt; + $final_rule_id=$rule_id; + } + + } + drupal_set_message(t('Rule id : ' . $final_rule_id.'Group id is: ' . $group_id)); + db_query("update vc_group set vc_selected_rules_id =%d where id=%d",$final_rule_id,$group_id); + } + + + +} + }//end of class Game class Group { @@ -315,7 +398,24 @@ return $this->game->getCurrentStageId(); } + public function getSelectedRule() + { + $result_rule= db_result(db_query("select rule_no,description from vc_rules where id = (select vc_selected_rules_id from vc_group where id=%d);",$this->group_id )); + while($data=db_fetch_object($result_rule)) + { + $rule_info=array($data->rule_no,$data->description); + } + return $rule_info; + + } + /*public function getRuleDescription() + { + db_result(db_query("select description select vc_selected_rules_id from vc_group where id=%d",$this->group_id)); + + }*/ + + }//end of Group /** @@ -352,6 +452,7 @@ public function getRoundNo() { + db_result(db_query("select current_round_no from vc_game where id=%d",$this->game_id)); return $this->round_no; } @@ -392,9 +493,71 @@ return db_result(db_query("select start_flag from vc_student where id ='%s' ",$this->stud_id)); } - public function updateStageId($stage_no,$experiment_id) + public function updateStageId($stage_no,$experiment_id,$game_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); + 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); } } + +class Rules +{ + + public function getRules($stage_id) + { + $result=db_query("Select rule_no,description from vc_rules where vc_stage_id=%d",$stage_id ); + while($data=db_fetch_object($result)) + { + $rules[$data->rule_no]=array($data->description); + } + + return $rules; + } + + public function saveStudentVoting($stud_id,$rule_no,$stage_id) + { + $rule_id=db_result(db_query("select id from vc_rules where vc_stage_id=%d and rule_no=%d",$stage_id,$rule_no)); + db_query("insert into {vc_student_voting} (vc_student_id,vc_rules_id) values('%s',%d)",$stud_id,$rule_id); + + } +} + +class Survey +{ + + public function getSurveyQuestions($exp_id) + { + $survey_id=db_result(db_query("Select id from vc_survey where vc_experiment_id=%d",$exp_id)); + $Q_result=db_query("Select id,vc_rules_id,questions from vc_survey_questions where vc_survey_id=%d",$survey_id); + + //get questions + while($survey=db_fetch_object($Q_result)) + { + $Q_id=$survey->id; + $rule_id=$survey->vc_rules_id; + $questions=$survey->questions; + $rule_no=db_result(db_query("select rule_no from vc_rules where id= %d",$rule_id)); + + //get options for questions + $option_result=db_query("select min_value,max_value from vc_survey_questions_options where vc_survey_questions_id=%d",$Q_id); + + while($survey_ans=db_fetch_object($option_result)) + { + $survey_data[$rule_no][$questions]=array($survey_ans->min_value,1,2,3,4,5,$survey_ans->max_value); + } + + } + + return $survey_data; + } + + + public function saveSurveyResponse($stage_id,$stud_id,$rule,$Q,$ans) + { + $rule_id=db_result(db_query("select id from vc_rules where rule_no=%d and vc_stage_id=%d",$rule,$stage_id)); + $Q_id=db_result(db_query("select id from vc_survey_questions where vc_rules_id=%d and questions='%s'",$rule_id,$Q)); + db_query("insert into {vc_survey_response} (vc_student_id,vc_survey_questions_id,response) values('%s',%d,'%s')",$stud_id,$Q_id,$ans); + + } + +} Deleted: vcweb/trunk/virtualcommons/experiment/games/forestry_v2/forestry_v2.install =================================================================== --- vcweb/trunk/virtualcommons/games/forestry_v2/forestry_v2.install 2008-08-02 00:29:43 UTC (rev 21) +++ vcweb/trunk/virtualcommons/experiment/games/forestry_v2/forestry_v2.install 2008-08-06 23:58:18 UTC (rev 28) @@ -1,200 +0,0 @@ -<?php -// vim:sts=2:sw=2:filetype=php -// $Id$ -/** - * Implementation of hook_install(). - */ -function forestry_v2_install() { - switch ($GLOBALS['db_type']) { - case 'mysql': - case 'mysqli': - db_query("CREATE TABLE {vc_forestry_common_resource_pool} - ( - id INT AUTO_INCREMENT, - vc_group_id INT NOT NULL, - common_resource_pool INT NOT NULL, - harvest_decision INT NOT NULL, - vc_game_id INT NOT NULL, - max_harvest_decision INT NOT NULL, - - PRIMARY KEY(id), - FOREIGN KEY(vc_group_id) REFERENCES vc_group(id) - ON DELETE CASCADE, - - FOREIGN KEY(vc_game_id) REFERENCES vc_game(id) - ON DELETE CASCADE - - )ENGINE=InnoDB /*!40100 DEFAULT CHARACTER SET UTF8 */"); - - //Forestry Game Harvest Tables. - db_query("CREATE TABLE {vc_forestry_5player_harvest_table} - ( - id INT AUTO_INCREMENT, - min_resource_level INT NOT NULL, - max_resource_level INT NOT NULL, - individual_harvest_level INT NOT NULL, - - PRIMARY KEY(id) - )ENGINE=InnoDB /*!40100 DEFAULT CHARACTER SET UTF8 */"); - - db_query("INSERT INTO {vc_forestry_5player_harvest_table} (min_resource_level,max_resource_level,individual_harvest_level) values(25,100,5)"); - db_query("INSERT INTO {vc_forestry_5player_harvest_table} (min_resource_level,max_resource_level,individual_harvest_level) values(20,24,4)"); - db_query("INSERT INTO {vc_forestry_5player_harvest_table} (min_resource_level,max_resource_level,individual_harvest_level) values(15,19,3)"); - db_query("INSERT INTO {vc_forestry_5player_harvest_table} (min_resource_level,max_resource_level,individual_harvest_level) values(10,14,2)"); - db_query("INSERT INTO {vc_forestry_5player_harvest_table} (min_resource_level,max_resource_level,individual_harvest_level) values(5,9,1)"); - db_query("INSERT INTO {vc_forestry_5player_harvest_table} (min_resource_level,max_resource_level,individual_harvest_level) values(0,4,0)"); - - - - db_query("CREATE TABLE {vc_forestry_4player_harvest_table} ( - id INT AUTO_INCREMENT, - min_resource_level INT NOT NULL, - max_resource_level INT NOT NULL, - individual_harvest_level INT NOT NULL, - - PRIMARY KEY(id) - - )ENGINE=InnoDB /*!40100 DEFAULT CHARACTER SET UTF8 */"); - - - db_query("INSERT INTO {vc_forestry_4player_harvest_table} (min_resource_level,max_resource_level,individual_harvest_level) values(20,80,5)"); - db_query("INSERT INTO {vc_forestry_4player_harvest_table} (min_resource_level,max_resource_level,individual_harvest_level) values(16,19,4)"); - db_query("INSERT INTO {vc_forestry_4player_harvest_table} (min_resource_level,max_resource_level,individual_harvest_level) values(12,15,3)"); - db_query("INSERT INTO {vc_forestry_4player_harvest_table} (min_resource_level,max_resource_level,individual_harvest_level) values(8,11,2)"); - db_query("INSERT INTO {vc_forestry_4player_harvest_table} (min_resource_level,max_resource_level,individual_harvest_level) values(4,7,1)"); - db_query("INSERT INTO {vc_forestry_4player_harvest_table} (min_resource_level,max_resource_level,individual_harvest_level) values(0,3,0)"); - - db_query("CREATE TABLE {vc_forestry_3player_harvest_table} ( - id INT AUTO_INCREMENT, - min_resource_level INT NOT NULL, - max_resource_level INT NOT NULL, - individual_harvest_level INT NOT NULL, - - PRIMARY KEY(id) - - )ENGINE=InnoDB /*!40100 DEFAULT CHARACTER SET UTF8 */"); - - db_query("INSERT INTO {vc_forestry_3player_harvest_table} (min_resource_level,max_resource_level,individual_harvest_level) values(15,60,5)"); - db_query("INSERT INTO {vc_forestry_3player_harvest_table} (min_resource_level,max_resource_level,individual_harvest_level) values(12,14,4)"); - db_query("INSERT INTO {vc_forestry_3player_harvest_table} (min_resource_level,max_resource_level,individual_harvest_level) values(9,11,3)"); - db_query("INSERT INTO {vc_forestry_3player_harvest_table} (min_resource_level,max_resource_level,individual_harvest_level) values(6,8,2)"); - db_query("INSERT INTO {vc_forestry_3player_harvest_table} (min_resource_level,max_resource_level,individual_harvest_level) values(3,5,1)"); - db_query("INSERT INTO {vc_forestry_3player_harvest_table} (min_resource_level,max_resource_level,individual_harvest_level) values(0,2,0)"); - - db_query("CREATE TABLE {vc_forestry_student} ( - id int NOT NULL AUTO_INCREMENT, - round_no int NOT NULL, - vc_student_id varchar(14) NOT NULL, - vc_stage_id int NOT NULL, - harvest_decision int NOT NULL, - fine int, - total_points int, - date TIMESTAMP NOT NULL, - - PRIMARY KEY(id), - - FOREIGN KEY(vc_student_id) REFERENCES vc_student(id) - ON DELETE CASCADE, - - FOREIGN KEY(vc_stage_id) REFERENCES vc_stage(id) - ON DELETE CASCADE - - - ) ENGINE=InnoDB /*!40100 DEFAULT CHARACTER SET UTF8 */"); - - db_query("CREATE TABLE {vc_forestry_turn_sequence} ( - id int AUTO_INCREMENT, - round_no int NOT NULL, - turn_sequence varchar(10) NOT NULL, - vc_group_id int NOT NULL, - vc_rules_id int NOT NULL, - vc_game_id int NOT NULL, - - PRIMARY KEY(id), - - FOREIGN KEY(vc_group_id) REFERENCES vc_group(id) - ON DELETE CASCADE, - - FOREIGN KEY(vc_rules_id) REFERENCES vc_rules(id) - ON DELETE CASCADE, - - FOREIGN KEY(vc_game_id) REFERENCES vc_game(id) - ON DELETE CASCADE - - )ENGINE=InnoDB /*!40100 DEFAULT CHARACTER SET UTF8 */"); - - - $flag=TRUE; - break; - case 'pgsql': - - db_query("CREATE TABLE {vc_forestry_student} ( - id int NOT NULL AUTO_INCREMENT, - round_no int NOT NULL, - vc_student_id varchar(14) NOT NULL, - vc_stage_id int NOT NULL, - harvest_decision int NOT NULL, - fine int, - total_points int, - date TIMESTAMP NOT NULL, - - PRIMARY KEY(id), - - FOREIGN KEY(vc_student_id) REFERENCES vc_student(id) - ON DELETE CASCADE, - - FOREIGN KEY(vc_stage_id) REFERENCES vc_stage(id) - ON DELETE CASCADE - - - ) ENGINE=InnoDB /*!40100 DEFAULT CHARACTER SET UTF8 */"); - - db_query("CREATE TABLE {vc_forestry_turn_sequence} ( - id int NOT NULL AUTO_INCREMENT, - round_no int NOT NULL, - turn_sequence varchar(10) NOT NULL, - vc_rules_id int NOT NULL, - vc_group_id int NOT NULL, - vc_game_id int NOT NULL, - - PRIMARY KEY(id), - - FOREIGN KEY(vc_group_id) REFERENCES vc_group(id) - ON DELETE CASCADE, - - FOREIGN KEY(vc_rules_id) REFERENCES vc_rules(id) - ON DELETE CASCADE, - - FOREIGN KEY(vc_game_id) REFERENCES vc_conducts(id) - ON DELETE CASCADE - - ) /*!40100 DEFAULT CHARACTER SET UTF8 */"); - $flag=TRUE; - break; - default: - drupal_set_message(t('Unsupported Database')); - } - if($flag) - { - drupal_set_message(t('Forestry stage database is successfully created.')); - } - else - { - drupal_set_message(t('Forestry stage database is NOT successfully created.'),'error'); - } -} - -/** - * Implementation of hook_uninstall(). - */ -function forestry_v2_uninstall() -{ - db_query("DROP TABLE {vc_forestry_3player_harvest_table}"); - db_query("DROP TABLE {vc_forestry_4player_harvest_table}"); - db_query("DROP TABLE {vc_forestry_5player_harvest_table}"); - db_query("DROP TABLE {vc_forestry_common_resource_pool}"); - db_query("DROP TABLE {vc_forestry_student}"); - db_query("DROP TABLE {vc_forestry_turn_sequence}"); - drupal_set_message(t('Forestry stage table is successfully deleted from the database.')); -} - Copied: vcweb/trunk/virtualcommons/experiment/games/forestry_v2/forestry_v2.install (from rev 23, vcweb/trunk/virtualcommons/games/forestry_v2/forestry_v2.install) =================================================================== --- vcweb/trunk/virtualcommons/experiment/games/forestry_v2/forestry_v2.install (rev 0) +++ vcweb/trunk/virtualcommons/experiment/games/forestry_v2/forestry_v2.install 2008-08-06 23:58:18 UTC (rev 28) @@ -0,0 +1,200 @@ +<?php +// vim:sts=2:sw=2:filetype=php +// $Id$ +/** + * Implementation of hook_install(). + */ +function forestry_v2_install() { + switch ($GLOBALS['db_type']) { + case 'mysql': + case 'mysqli': + db_query("CREATE TABLE {vc_forestry_common_resource_pool} + ( + id INT AUTO_INCREMENT, + vc_group_id INT NOT NULL, + common_resource_pool INT NOT NULL, + + vc_game_id INT NOT NULL, + max_resources INT NOT NULL, + + PRIMARY KEY(id), + FOREIGN KEY(vc_group_id) REFERENCES vc_group(id) + ON DELETE CASCADE, + + FOREIGN KEY(vc_game_id) REFERENCES vc_game(id) + ON DELETE CASCADE + + )ENGINE=InnoDB /*!40100 DEFAULT CHARACTER SET UTF8 */"); + + //Forestry Game Harvest Tables. + db_query("CREATE TABLE {vc_forestry_5player_harvest_table} + ( + id INT AUTO_INCREMENT, + min_resource_level INT NOT NULL, + max_resource_level INT NOT NULL, + individual_harvest_level INT NOT NULL, + + PRIMARY KEY(id) + )ENGINE=InnoDB /*!40100 DEFAULT CHARACTER SET UTF8 */"); + + db_query("INSERT INTO {vc_forestry_5player_harvest_table} (min_resource_level,max_resource_level,individual_harvest_level) values(25,100,5)"); + db_query("INSERT INTO {vc_forestry_5player_harvest_table} (min_resource_level,max_resource_level,individual_harvest_level) values(20,24,4)"); + db_query("INSERT INTO {vc_forestry_5player_harvest_table} (min_resource_level,max_resource_level,individual_harvest_level) values(15,19,3)"); + db_query("INSERT INTO {vc_forestry_5player_harvest_table} (min_resource_level,max_resource_level,individual_harvest_level) values(10,14,2)"); + db_query("INSERT INTO {vc_forestry_5player_harvest_table} (min_resource_level,max_resource_level,individual_harvest_level) values(5,9,1)"); + db_query("INSERT INTO {vc_forestry_5player_harvest_table} (min_resource_level,max_resource_level,individual_harvest_level) values(0,4,0)"); + + + + db_query("CREATE TABLE {vc_forestry_4player_harvest_table} ( + id INT AUTO_INCREMENT, + min_resource_level INT NOT NULL, + max_resource_level INT NOT NULL, + individual_harvest_level INT NOT NULL, + + PRIMARY KEY(id) + + )ENGINE=InnoDB /*!40100 DEFAULT CHARACTER SET UTF8 */"); + + + db_query("INSERT INTO {vc_forestry_4player_harvest_table} (min_resource_level,max_resource_level,individual_harvest_level) values(20,80,5)"); + db_query("INSERT INTO {vc_forestry_4player_harvest_table} (min_resource_level,max_resource_level,individual_harvest_level) values(16,19,4)"); + db_query("INSERT INTO {vc_forestry_4player_harvest_table} (min_resource_level,max_resource_level,individual_harvest_level) values(12,15,3)"); + db_query("INSERT INTO {vc_forestry_4player_harvest_table} (min_resource_level,max_resource_level,individual_harvest_level) values(8,11,2)"); + db_query("INSERT INTO {vc_forestry_4player_harvest_table} (min_resource_level,max_resource_level,individual_harvest_level) values(4,7,1)"); + db_query("INSERT INTO {vc_forestry_4player_harvest_table} (min_resource_level,max_resource_level,individual_harvest_level) values(0,3,0)"); + + db_query("CREATE TABLE {vc_forestry_3player_harvest_table} ( + id INT AUTO_INCREMENT, + min_resource_level INT NOT NULL, + max_resource_level INT NOT NULL, + individual_harvest_level INT NOT NULL, + + PRIMARY KEY(id) + + )ENGINE=InnoDB /*!40100 DEFAULT CHARACTER SET UTF8 */"); + + db_query("INSERT INTO {vc_forestry_3player_harvest_table} (min_resource_level,max_resource_level,individual_harvest_level) values(15,60,5)"); + db_query("INSERT INTO {vc_forestry_3player_harvest_table} (min_resource_level,max_resource_level,individual_harvest_level) values(12,14,4)"); + db_query("INSERT INTO {vc_forestry_3player_harvest_table} (min_resource_level,max_resource_level,individual_harvest_level) values(9,11,3)"); + db_query("INSERT INTO {vc_forestry_3player_harvest_table} (min_resource_level,max_resource_level,individual_harvest_level) values(6,8,2)"); + db_query("INSERT INTO {vc_forestry_3player_harvest_table} (min_resource_level,max_resource_level,individual_harvest_level) values(3,5,1)"); + db_query("INSERT INTO {vc_forestry_3player_harvest_table} (min_resource_level,max_resource_level,individual_harvest_level) values(0,2,0)"); + + db_query("CREATE TABLE {vc_forestry_student} ( + id int NOT NULL AUTO_INCREMENT, + round_no int NOT NULL, + vc_student_id varchar(14) NOT NULL, + vc_stage_id int NOT NULL, + harvest_decision int NOT NULL, + fine int, + total_points int, + date TIMESTAMP NOT NULL, + + PRIMARY KEY(id), + + FOREIGN KEY(vc_student_id) REFERENCES vc_student(id) + ON DELETE CASCADE, + + FOREIGN KEY(vc_stage_id) REFERENCES vc_stage(id) + ON DELETE CASCADE + + + ) ENGINE=InnoDB /*!40100 DEFAULT CHARACTER SET UTF8 */"); + + db_query("CREATE TABLE {vc_forestry_turn_sequence} ( + id int AUTO_INCREMENT, + round_no int NOT NULL, + turn_sequence varchar(10) NOT NULL, + vc_group_id int NOT NULL, + vc_rules_id int NOT NULL, + vc_game_id int NOT NULL, + + PRIMARY KEY(id), + + FOREIGN KEY(vc_group_id) REFERENCES vc_group(id) + ON DELETE CASCADE, + + FOREIGN KEY(vc_rules_id) REFERENCES vc_rules(id) + ON DELETE CASCADE, + + FOREIGN KEY(vc_game_id) REFERENCES vc_game(id) + ON DELETE CASCADE + + )ENGINE=InnoDB /*!40100 DEFAULT CHARACTER SET UTF8 */"); + + + $flag=TRUE; + break; + case 'pgsql': + + db_query("CREATE TABLE {vc_forestry_student} ( + id int NOT NULL AUTO_INCREMENT, + round_no int NOT NULL, + vc_student_id varchar(14) NOT NULL, + vc_stage_id int NOT NULL, + harvest_decision int NOT NULL, + fine int, + total_points int, + date TIMESTAMP NOT NULL, + + PRIMARY KEY(id), + + FOREIGN KEY(vc_student_id) REFERENCES vc_student(id) + ON DELETE CASCADE, + + FOREIGN KEY(vc_stage_id) REFERENCES vc_stage(id) + ON DELETE CASCADE + + + ) ENGINE=InnoDB /*!40100 DEFAULT CHARACTER SET UTF8 */"); + + db_query("CREATE TABLE {vc_forestry_turn_sequence} ( + id int NOT NULL AUTO_INCREMENT, + round_no int NOT NULL, + turn_sequence varchar(10) NOT NULL, + vc_rules_id int NOT NULL, + vc_group_id int NOT NULL, + vc_game_id int NOT NULL, + + PRIMARY KEY(id), + + FOREIGN KEY(vc_group_id) REFERENCES vc_group(id) + ON DELETE CASCADE, + + FOREIGN KEY(vc_rules_id) REFERENCES vc_rules(id) + ON DELETE CASCADE, + + FOREIGN KEY(vc_game_id) REFERENCES vc_conducts(id) + ON DELETE CASCADE + + ) /*!40100 DEFAULT CHARACTER SET UTF8 */"); + $flag=TRUE; + break; + default: + drupal_set_message(t('Unsupported Database')); + } + if($flag) + { + drupal_set_message(t('Forestry stage database is successfully created.')); + } + else + { + drupal_set_message(t('Forestry stage database is NOT successfully created.'),'error'); + } +} + +/** + * Implementation of hook_uninstall(). + */ +function forestry_v2_uninstall() +{ + db_query("DROP TABLE {vc_forestry_3player_harvest_table}"); + db_query("DROP TABLE {vc_forestry_4player_harvest_table}"); + db_query("DROP TABLE {vc_forestry_5player_harvest_table}"); + db_query("DROP TABLE {vc_forestry_common_resource_pool}"); + db_query("DROP TABLE {vc_forestry_student}"); + db_query("DROP TABLE {vc_forestry_turn_sequence}"); + drupal_set_message(t('Forestry stage table is successfully deleted from the database.')); +} + Deleted: vcweb/trunk/virtualcommons/experiment/games/forestry_v2/forestry_v2.module =================================================================== --- vcweb/trunk/virtualcommons/games/forestry_v2/forestry_v2.module 2008-08-02 00:29:43 UTC (rev 21) +++ vcweb/trunk/virtualcommons/experiment/games/forestry_v2/forestry_v2.module 2008-08-06 23:58:18 UTC (rev 28) @@ -1,528 +0,0 @@ -<?php -// vim:sts=2:sw=2:filetype=php -// $Id$ - -include_once('./' . drupal_get_path('module', 'experiment') . '/experiment.inc'); - - -/** - * implement the _user hook. - **/ -// $Id$ -/** - * Implementation of hook_menu(). - */ -function forestry_v2_menu($may_cache) { - $items = array(); - if ($may_cache) { - $items[] = array('path' => 'forestry', - 'title' => t('Forestry Game'), - 'callback' => 'forestry_v2_page', - 'type'=>MENU_CALLBACK, - '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 - */ -function forestry_v2_page() { - $output = t('Please note the following maximum harvest table.'); - // Return the HTML generated from the $form data structure. - $output .= drupal_get_form('forestry_v2_nameform'); - return $output; -} -/** - * Defines a form. - */ -function forestry_v2_nameform() { - //$form['#method']='post'; - //+$form['#action']='http://localhost/drupal/?q=studentgroup'; - $form['#id']='forestry_v2'; - $header = array('Current Resource Level', 'Individual Maximum Harvest Level'); - - $stud_id=$_SESSION['student_id']; - $group = unserialize($_SESSION['group']); - // FIXME: merge harvest tables into single table - - $game_id=$group->getGameId(); - $group_id=$group->getGroupId(); - $result_group=$group->getNumberOfStudents(); - drupal_set_message(t('Group no'. $result_group)); - $result = db_query("SELECT min_resource_level,max_resource_level,individual_harvest_level from {vc_forestry_${result_group}player_harvest_table}"); -/* - - if($result_group==5) - { - $result=db_query(db_rewrite_sql("Select min_resource_level,max_resource_level,individual_harvest_level from {virtualcommons_forestry_5player_harvest_table}")); - - } - else if($result_group==4) - { - $result=db_query(db_rewrite_sql("Select min_resource_level,max_resource_level,individual_harvest_level from {virtualcommons_forestry_4player_harvest_table}")); - } - else if($result_group==3) - { - $result=db_query(db_rewrite_sql("Select min_resource_level,max_resource_level,individual_harvest_level from virtualcommons_forestry_3player_harvest_table")); - } - } - */ - - while($harvest_data=db_fetch_object($result)) - { - $min=$harvest_data->min_resource_level; - $max=$harvest_data->max_resource_level; - $ind=$harvest_data->individual_harvest_level; - $row[]=array($min.' - '.$max,$ind); - //drupal_set_message(t($min . " " . $max . " " . $ind)); - } - $_SESSION['harvest_table']=$row; - - $form['harvest_table']=array( - '#type'=>'markup', - '#value'=>theme('table',$header,$row) - ); - - $form['submit'] = array( - '#type' => 'submit', - '#value' => t('Next') - ); - return $form; -} -/** - * Invoked after the student has successfully logged in and is trying to click - * "Next" to start the game. - */ -function forestry_v2_nameform_submit($form_id, $form_values) -{ - $stud_id=$_SESSION['student_id']; - $group = unserialize($_SESSION['group']); - $flag=$group->getStartFlag($stud_id); - $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) - { - $current_rule_no=$group->getCurrentRuleNumber(); - switch($current_rule_no) { - case 1: - return 'forestry_stage2_rule1'; - case 2: - return 'forestry_stage2_rule2'; - case 3: - return 'forestry_stage2_rule3'; - } - - } - } - else { - return 'forestry'; - } -} - -//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'; - -} - - - - - Copied: vcweb/trunk/virtualcommons/experiment/games/forestry_v2/forestry_v2.module (from rev 22, vcweb/trunk/virtualcommons/games/forestry_v2/forestry_v2.module) =================================================================== --- vcweb/trunk/virtualcommons/experiment/games/forestry_v2/forestry_v2.module (rev 0) +++ vcweb/trunk/virtualcommons/experiment/games/forestry_v2/forestry_v2.module 2008-08-06 23:58:18 UTC (rev 28) @@ -0,0 +1,518 @@ +<?php +// vim:sts=2:sw=2:filetype=php +// $Id$ + +include_once('./' . drupal_get_path('module', 'experiment') . '/experiment.inc'); + + +/** + * implement the _user hook. + **/ +// $Id$ +/** + * Implementation of hook_menu(). + */ +function forestry_v2_menu($may_cache) { + $items = array(); + if ($may_cache) { + $items[] = array('path' => 'forestry', + 'title' => t('Forestry Game'), + 'callback' => 'forestry_v2_page', + 'type'=>MENU_CALLBACK, + '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 + */ +function forestry_v2_page() { + $output = t('Please note the following maximum harvest table.'); + // Return the HTML generated from the $form data structure. + $output .= drupal_get_form('forestry_v2_nameform'); + return $output; +} +/** + * Defines a form. + */ +function forestry_v2_nameform() { + //$form['#method']='post'; + //+$form['#action']='http://localhost/drupal/?q=studentgroup'; + $form['#id']='forestry_v2'; + $header = array('Current Resource Level', 'Individual Maximum Harvest Level'); + + $stud_id=$_SESSION['student_id']; + $group = Session::get('group'); + drupal_set_message(' group id: ' . $group->getGroupId() ); + // FIXME: merge harvest tables into single table + + $game_id=$group->getGameId(); + $group_id=$group->getGroupId(); + $result_group=$group->getNumberOfStudents(); + drupal_set_message(t('Group no'. $result_group)); + $result = db_query("SELECT min_resource_level,max_resource_level,individual_harvest_level from {vc_forestry_${result_group}player_harvest_table}"); + /* + + if($result_group==5) + { + $result=db_query(db_rewrite_sql("Select min_resource_level,max_resource_level,individual_harvest_level from {virtualcommons_forestry_5player_harvest_table}")); + + } + else if($result_group==4) + { + $result=db_query(db_rewrite_sql("Select min_resource_level,max_resource_level,individual_harvest_level from {virtualcommons_forestry_4player_harvest_table}")); + } + else if($result_group==3) + { + $result=db_query(db_rewrite_sql("Select min_resource_level,max_resource_level,individual_harvest_level from virtualcommons_forestry_3player_harvest_table")); + } + } + */ + +while($harvest_data=db_fetch_object($result)) +{ + $min=$harvest_data->min_resource_level; + $max=$harvest_data->max_resource_level; + $ind=$harvest_data->individual_harvest_level; + $row[]=array($min.' - '.$max,$ind); + //drupal_set_message(t($min . " " . $max . " " . $ind)); +} +$_SESSION['harvest_table']=$row; + +$form['harvest_table']=array( + '#type'=>'markup', + '#value'=>theme('table',$header,$row) + ); + +$form['submit'] = array( + '#type' => 'submit', + '#value' => t('Next') + ); +return $form; +} +/** + * Invoked after the student has successfully logged in and is trying to click + * "Next" to start the game. + */ +function forestry_v2_nameform_submit($form_id, $form_values) +{ + $stud_id=$_SESSION['student_id']; + $group = Session::get('group'); + $flag=$group->getStartFlag($stud_id); + $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) + { + $current_rule_no=$group->getCurrentRuleNumber(); + switch($current_rule_no) { + case 1: + return 'forestry_stage2_rule1'; + case 2: + return 'forestry_stage2_rule2'; + case 3: + return 'forestry_stage2_rule3'; + } + + } + } + else { + return 'forestry'; + } +} + +//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 = Session::get('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; + //FIXME:later on use session objects to do all session activity + 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); + + $round_no=$student->getRoundNo()+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 + ); + + 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(); + 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(); + // drupal_set_message(t('Stage no is : '.$stage_no)); + $form['indicator']['submit'] = array( + '#type' => 'submit', + '#value' => t('Next Stage') + ); + + } + + $form['resource']=array( + + '#type'=>'fieldset', + '#title'=>t('<b>Resources</b>'), + + ); + $form['resource']['table']=array( + '#type'=>'markup', + '#value'=>theme('table',$header,$final_row) + ); + + Session::put('forestry_student',$student); + 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 = Session::get('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... [truncated message content] |