예제 #1
0
 public function widget_action($range_id, $range_type = "course")
 {
     if (get_class($this->parent_controller) === __CLASS__) {
         throw new RuntimeException('widget_action must be relayed');
     }
     $this->range_id = $range_id;
     $this->range_type = $range_type;
     if (in_array($this->range_id, array("public", "start"))) {
         $this->range_type = "static";
     }
     $statement = DBManager::get()->prepare("\n            SELECT questionnaires.*\n            FROM questionnaires\n                INNER JOIN questionnaire_assignments ON (questionnaires.questionnaire_id = questionnaire_assignments.questionnaire_id)\n            WHERE questionnaire_assignments.range_id = :range_id\n                AND questionnaire_assignments.range_type = :range_type\n                " . (Request::get("questionnaire_showall") ? "AND startdate <= UNIX_TIMESTAMP()" : "AND visible = 1") . "\n            ORDER BY questionnaires.mkdate DESC\n        ");
     $statement->execute(array('range_id' => $this->range_id, 'range_type' => $this->range_type));
     $this->questionnaires = array();
     foreach ($statement->fetchAll(PDO::FETCH_ASSOC) as $questionnaire_data) {
         $this->questionnaires[] = Questionnaire::buildExisting($questionnaire_data);
     }
     foreach ($this->questionnaires as $questionnaire) {
         if (!$questionnaire['visible'] && $questionnaire['startdate'] && $questionnaire['startdate'] <= time()) {
             $questionnaire->start();
         }
         if ($questionnaire['visible'] && $questionnaire['stopdate'] && $questionnaire['stopdate'] <= time()) {
             $questionnaire->stop();
         }
     }
 }