public function planAction()
 {
     $group_id = $this->_request->getParam('g');
     $target_id = $this->_request->getParam('t');
     $level_id = $this->_request->getParam('l');
     $game_id = $this->_request->getParam('gm');
     if ($group_id && $target_id && $level_id && $game_id) {
         $plan_DB = new Application_Model_DbTable_Planing();
         $new_plan = array('group_id' => $group_id, 'target_id' => $target_id, 'level_id' => $level_id, 'game_id' => $game_id, 'create_date' => time());
         try {
             $plan_id = $plan_DB->insert($new_plan);
             $plans = $plan_DB->getAll($plan_id);
             $this->view->plan_id = $plan_id;
             $this->view->plans = $plans;
         } catch (Exception $ex) {
             die(json_encode(array('status' => 'danger', 'msg' => $this->lang->_('FAILED_DOC'))));
         }
     }
 }
Exemplo n.º 2
0
 public function planAction()
 {
     $group_id = $this->_request->getParam('g');
     $target_id = $this->_request->getParam('t');
     $game_id = $this->_request->getParam('gm');
     if ($group_id && $target_id && $game_id) {
         $plan_DB = new Application_Model_DbTable_Planing();
         //date_default_timezone_set('Asia/Jerusalem');
         $new_plan = array('groupID' => $group_id, 'gameID' => $game_id, 'date' => date('Y-m-d H:i:s'), 'fieldID' => $_SESSION['Default']['field']);
         try {
             $plan_id = $plan_DB->insert($new_plan);
             $plans = $plan_DB->getAll($plan_id);
             $this->view->plan_id = $plan_id;
             $this->view->plans = $plans;
             $this->_redirect('/groups/group/g/' . $group_id . '/t/' . $target_id . '/gm/' . $game_id);
         } catch (Exception $ex) {
             die(json_encode(array('status' => 'danger', 'msg' => $this->lang->_('FAILED_DOC'))));
         }
         $groups_DB = new Application_Model_DbTable_Group();
         $this->view->groupName = $groups_DB->getName($group_id);
     }
 }
 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));
     }
 }