public function gamesAction()
 {
     $group_id = $this->_request->getParam('g');
     $target_id = $this->_request->getParam('t');
     $level_id = $this->_request->getParam('l');
     if ($group_id && $target_id && $level_id) {
         $game_DB = new Application_Model_DbTable_Game();
         $games = $game_DB->getAll($target_id, $level_id);
         $this->view->group_id = $group_id;
         $this->view->games = $games;
     }
 }
Exemplo n.º 2
0
 public function plannedactivitiesAction()
 {
     $user = Zend_Auth::getInstance()->getStorage()->read();
     $group_DB = new Application_Model_DbTable_Group();
     if (!isset($_SESSION['Default']['field'])) {
         $this->view->field_error = true;
     } else {
         $groups = $group_DB->getAll($user->ganID, $_SESSION['Default']['field']);
         $plans_DB = new Application_Model_DbTable_Planing();
         $games_DB = new Application_Model_DbTable_Game();
         $_groups = array();
         foreach ($groups as $g) {
             $last_plan = $plans_DB->getLastPlan($g['groupID'], $_SESSION['Default']['field']);
             $gameID = $last_plan['game_id'];
             $goalName = $games_DB->getGoalName($gameID);
             if ($last_plan) {
                 $g['plan'] = $last_plan['game_name'];
                 $g['goal'] = $goalName;
                 $_groups[] = $g;
             }
         }
         #VIEWS
         $this->view->groups = $_groups;
     }
 }
Exemplo n.º 3
0
 public function editgameAction()
 {
     $gameID = $this->_request->getParam('gm');
     $game_DB = new Application_Model_DbTable_Game();
     $gameName = $game_DB->getGameName($gameID);
     $form = new Application_Form_AddGameToGoal(array('gamename' => $gameName));
     $this->view->form = $form;
 }
 public function recommend()
 {
     $group_id = $this->_request->getParam('g');
     $plans_DB = new Application_Model_DbTable_Planing();
     $last_plan = $plans_DB->getLastPlan($group_id, $_SESSION['Default']['field']);
     if ($last_plan) {
         $target_id = $last_plan['goal_id'];
         $game_id = $last_plan['game_id'];
         $related_plan_id = $last_plan['planID'];
         $targets_DB = new Application_Model_DbTable_Target();
         $target_level = $targets_DB->getGoalLevel($target_id);
         settype($target_level, "integer");
         $records_DB = new Application_Model_DbTable_Records();
         $records = $records_DB->getAll($group_id, $game_id);
         $count_1 = 0;
         $count_2 = 0;
         $count_3 = 0;
         $count_4 = 0;
         foreach ($records as $r) {
             $grade = $r['grade_value'];
             settype($grade, "integer");
             if ($grade == 1) {
                 $count_1++;
             } else {
                 if ($grade == 2) {
                     $count_2++;
                 } else {
                     if ($grade == 3) {
                         $count_3++;
                     } else {
                         if ($grade == 4) {
                             $count_4++;
                         }
                     }
                 }
             }
         }
         $num_of_students = count($records);
         $continue_childrenless = false;
         $students_DB = new Application_Model_DbTable_StudentsInField();
         $real_num_of_students = count($students_DB->getAll($group_id));
         if ($num_of_students < $real_num_of_students) {
             $continue_childrenless = true;
         }
         $num_of_levels = count($targets_DB->getLevels());
         //current target
         $recommended_target = $target_id;
         $recommendation = $this->lang->_('RECOMMEND_CURRENT_LEVEL');
         if ($num_of_students > 2 && $count_1 >= $num_of_students / 2 || $num_of_students == 1 && $count_1 == 1 || $num_of_students == 2 && ($count_1 == 2 || $count_1 == 1 && $count_2 == 1)) {
             //return to a game from prev goal
             if ($target_level > 1) {
                 $target_level = $target_level - 1;
                 $recommended_target = $targets_DB->getAllByLevel($target_level, $_SESSION['Default']['field']);
                 $recommendation = $this->lang->_('RECOMMEND_PREV_LEVEL');
             }
         } else {
             if ($num_of_students > 2 && $count_4 >= $num_of_students - 1 || $num_of_students == 1 && $count_4 == 1 || $num_of_students == 2 && ($count_4 == 2 || $count_4 == 1 && $count_3 == 1)) {
                 $unlearned_targets = $targets_DB->getUnlearnedInLevel($target_level, $group_id, $_SESSION['Default']['field']);
                 //next target in current level
                 if (count($unlearned_targets) > 0) {
                     $recommended_target = $unlearned_targets[0]['goalID'];
                     $recommendation = $this->lang->_('RECOMMEND_NEXT_LEVEL');
                 } else {
                     if ($target_level < $num_of_levels) {
                         $target_level = $target_level + 1;
                         $recommended_target = $targets_DB->getAllByLevel($target_level, $_SESSION['Default']['field']);
                         $recommendation = $this->lang->_('RECOMMEND_NEXT_LEVEL');
                     }
                 }
             }
         }
         $games_DB = new Application_Model_DbTable_Game();
         settype($recommended_target, "integer");
         $unplayed_games = $games_DB->getGamesNotPlayed($group_id, $recommended_target);
         //check if all games were played
         if (count($unplayed_games) == 0) {
             $recommended_game = $games_DB->getRandomGame($recommended_target);
         } else {
             $recommended_game = $unplayed_games[0];
         }
         $recommended_target_name = $targets_DB->getGoalName($recommended_target);
         $this->view->recommended_target = $recommended_target_name;
         $this->view->recommendation = $recommendation;
         $this->view->recommended_game = $recommended_game['name'];
         //insert to DB as last plan
         $plan_DB = new Application_Model_DbTable_Planing();
         $new_plan = array('groupID' => $group_id, 'gameID' => $recommended_game['gameID'], 'date' => date('Y-m-d H:i:s'), 'recommendation' => $recommendation, 'relatedPlanID' => $related_plan_id, 'fieldID' => $_SESSION['Default']['field']);
         try {
             $plan_id = $plan_DB->insert($new_plan);
         } catch (Exception $ex) {
             die(json_encode(array('status' => 'danger', 'msg' => $this->lang->_('FAILED_DOC'))));
         }
         //return json to ajax
         $this->getHelper('Layout')->disableLayout();
         $this->getHelper('ViewRenderer')->setNoRender();
         echo json_encode(array('recommendation' => $recommendation, 'recommended_game' => $recommended_game['name'], 'recommended_target' => $recommended_target_name, 'continue_childrenless' => $continue_childrenless));
     }
 }