コード例 #1
0
ファイル: TotalTest.php プロジェクト: aclivo/kpi
 /**
  * @covers Aclivo\Kpi\Total::setDirector
  * @covers Aclivo\Kpi\Total::getDirection
  */
 public function testSetDirector()
 {
     $total = new Total();
     $total->setActual(100);
     $total->setTarget(100);
     $total->setlowBandTarget(90);
     $total->sethighBandTarget(110);
     $director = new UpDirector();
     $total->setDirector($director);
     $this->assertEquals(Directions::GOOD, $total->getDirection());
 }
コード例 #2
0
ファイル: StudentController.php プロジェクト: sify21/Question
 private function nextpart($cur, $next)
 {
     $result = new SurveyResult();
     $parts = $this->session->get("parts");
     $stu_id = $this->session->get("stu_id");
     if ($cur != -1) {
         $end = strtotime(date("Y-m-d H:i:s"));
         $start = $this->session->get("p_start");
         $total = new Total();
         $curpart = Part::findFirst(array("p_id=:p_id:", "bind" => array("p_id" => $parts[$cur])));
         $cacheKey = $curpart->p_id . ".txt";
         $curquestions = $this->getquestion($curpart, $cacheKey);
         $tans = $this->cookies->get($stu_id . "-" . $cur)->getValue();
         $answers = str_split($tans);
         if (!(strpos($tans, "0") === false) || strlen($tans) < count($curquestions)) {
             return $this->nextpart(-1, $cur);
         }
         $stu_answers = array();
         $total->student_id = $stu_id;
         $total->part_id = $curpart->p_id;
         $total->time = $end - $start;
         $total->answers = $tans;
         foreach ($curpart->Factor as $factor) {
             $stu_answers[$factor->f_id] = new Answer();
             $stu_answers[$factor->f_id]->factor_id = $factor->f_id;
             $stu_answers[$factor->f_id]->student_id = $stu_id;
             $stu_answers[$factor->f_id]->source = 0;
         }
         foreach ($answers as $index => $ans) {
             $order = ord($ans) - ord("a");
             $q = $curquestions[$index];
             $scores = explode("|", $q["grade"]);
             $score = $scores[$order];
             // $fffid = $q["factor_id"];
             // echo "order: $order score:$score factor:$fffid<br>";
             $stu_answers[$q["factor_id"]]->source += $score;
             $stu_answers[$q["factor_id"]]->ans .= $ans;
         }
         $this->db->begin();
         try {
             $backup = new Backup();
             $filename = "../cache/backup/{$stu_id}.bak";
             $backup->total = $total->toArray();
             $i = 0;
             foreach ($stu_answers as $a) {
                 $backup->answers[$i] = $a->toArray();
                 $i++;
             }
             $file = fopen($filename, "a");
             fwrite($file, json_encode($backup) . "|");
             fclose($file);
             if (!$total->save()) {
                 throw new PDOException();
             }
             foreach ($stu_answers as $stu_answer) {
                 if (!$stu_answer->save()) {
                     throw new PDOException();
                 }
             }
             $this->db->commit();
             $result->resultinfo = 1;
         } catch (PDOException $ex) {
             echo $ex->getMessage();
             $result->resultinfo = 0;
             $this->db->rollback();
             $this->view->disable();
         }
     }
     if ($next != -1) {
         $this->session->set("cur", $next);
         $tnext = $next == $this->session->get("exam_num") - 1 ? -1 : $next + 1;
         $this->session->set("next", $tnext);
         $this->session->set("p_start", strtotime(date("Y-m-d H:i:s")));
         $nextpart = Part::findFirst(array("p_id=:p_id:", "bind" => array("p_id" => $parts[$next])));
         $cacheKey = $nextpart->p_id . ".txt";
         $questions = $this->getquestion($nextpart, $cacheKey);
         $result->description = $nextpart->description;
         $result->nextpart = $questions;
         $result->cur = $next;
         $result->next = $tnext;
         return $result;
     } else {
         $stu_id = $this->session->get("stu_id");
         $stu = Student::findFirst($stu_id);
         $stu->status = 1;
         $stu->save();
         $this->response->redirect("student/complete");
     }
 }