Beispiel #1
0
 protected function loadModel($id)
 {
     /**
      * TODO или сделать в один запрос?
      */
     $criteria = new CDbCriteria();
     $criteria->compare('t.active', Quiz::STATUS_ACTIVE);
     /** @var $quiz Quiz */
     $quiz = Quiz::model()->findByPk($id, $criteria);
     if ($quiz === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     $criteria = new CDbCriteria(array('with' => 'answers', 'order' => 't.sequence ASC, answers.sequence ASC'));
     $criteria->compare('t.id_quiz', $id);
     $questions = QuizQuestion::model()->findAll($criteria);
     if (empty($questions)) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     $quiz->addRelatedRecord('questions', $questions, false);
     return $quiz;
 }
 /**
  * Build the orphan questions
  */
 public function build_quiz_orphan_questions()
 {
     $table_qui = Database::get_course_table(TABLE_QUIZ_TEST);
     $table_rel = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION);
     $table_que = Database::get_course_table(TABLE_QUIZ_QUESTION);
     $table_ans = Database::get_course_table(TABLE_QUIZ_ANSWER);
     $courseId = api_get_course_int_id();
     $sql = 'SELECT *
             FROM ' . $table_que . ' as questions
             LEFT JOIN ' . $table_rel . ' as quizz_questions
             ON questions.id=quizz_questions.question_id
             LEFT JOIN ' . $table_qui . ' as exercises
             ON quizz_questions.exercice_id = exercises.id
             WHERE
                 questions.c_id = quizz_questions.c_id AND
                 questions.c_id = exercises.c_id AND
                 exercises.c_id = ' . $courseId . ' AND
                 (quizz_questions.exercice_id IS NULL OR
                 exercises.active = -1)';
     $db_result = Database::query($sql);
     if (Database::num_rows($db_result) > 0) {
         // This is the fictional test for collecting orphan questions.
         $orphan_questions = new Quiz(-1, get_lang('OrphanQuestions', ''), '', 0, 0, 1, '', 0);
         $this->course->add_resource($orphan_questions);
         while ($obj = Database::fetch_object($db_result)) {
             $question = new QuizQuestion($obj->id, $obj->question, $obj->description, $obj->ponderation, $obj->type, $obj->position, $obj->picture, $obj->level, $obj->extra);
             $sql = 'SELECT * FROM ' . $table_ans . ' WHERE question_id = ' . $obj->id;
             $db_result2 = Database::query($sql);
             while ($obj2 = Database::fetch_object($db_result2)) {
                 $question->add_answer($obj2->id, $obj2->answer, $obj2->correct, $obj2->comment, $obj2->ponderation, $obj2->position, $obj2->hotspot_coordinates, $obj2->hotspot_type);
             }
             $this->course->add_resource($question);
         }
     }
 }
 /**
  * Adds an object to the instance pool.
  *
  * Propel keeps cached copies of objects in an instance pool when they are retrieved
  * from the database.  In some cases -- especially when you override doSelect*()
  * methods in your stub classes -- you may need to explicitly add objects
  * to the cache in order to ensure that the same objects are always returned by doSelect*()
  * and retrieveByPK*() calls.
  *
  * @param      QuizQuestion $value A QuizQuestion object.
  * @param      string $key (optional) key to use for instance map (for performance boost if key was already calculated externally).
  */
 public static function addInstanceToPool(QuizQuestion $obj, $key = null)
 {
     if (Propel::isInstancePoolingEnabled()) {
         if ($key === null) {
             $key = (string) $obj->getId();
         }
         // if key === null
         self::$instances[$key] = $obj;
     }
 }
 /**
  * Exclude object from result
  *
  * @param     QuizQuestion $quizQuestion Object to remove from the list of results
  *
  * @return    QuizQuestionQuery The current query, for fluid interface
  */
 public function prune($quizQuestion = null)
 {
     if ($quizQuestion) {
         $this->addUsingAlias(QuizQuestionPeer::ID, $quizQuestion->getId(), Criteria::NOT_EQUAL);
     }
     return $this;
 }
Beispiel #5
0
 /**
  * Implementation of getAnweringForm
  *
  * @see QuizQuestion#getAnsweringForm($form_state, $rid)
  */
 public function getAnsweringForm(array $form_state = NULL, $rid)
 {
     $form = parent::getAnsweringForm($form_state, $rid);
     $form['#theme'] = 'long_answer_answering_form';
     $form['tries'] = array('#type' => 'textarea', '#title' => t('Answer'), '#description' => t('Enter your answer here. If you need more space, click on the grey bar at the bottom of this area and drag it down.'), '#rows' => 15, '#cols' => 60, '#required' => FALSE);
     if (isset($rid)) {
         $response = new LongAnswerResponse($rid, $this->node);
         $form['tries']['#default_value'] = $response->getResponse();
     }
     return $form;
 }
Beispiel #6
0
 function hapus_ul($args)
 {
     list($id) = $args;
     if (!isset($id) || $id < 1) {
         die('no proper id');
     }
     $ul = new QuizUlangan();
     $ul->getByID($id);
     if ($ul->ulangan_creator_id == Account::getMyID() && !$ul->ulangan_aktif) {
         $ul->delete($id);
         //$ul->ulangan_aktif = 0;
         //$ul->save();
         $q = new QuizQuestion();
         $arr = $q->getWhere("q_ulangan_id = '{$id}'");
         foreach ($arr as $qq) {
             $q->delete($qq->qid);
             $a = new QuizAnswer();
             $arr2 = $a->getWhere("answer_qid = '{$qq->qid}'");
             foreach ($arr2 as $aa) {
                 $a->delete($aa->answer_id);
             }
         }
     }
 }
 function saveQ()
 {
     //pr($_POST);
     $myid = 0;
     $qid = addslashes($_POST['qid']);
     $q = new QuizQuestion();
     if ($qid != "" && $qid != 0) {
         $q->getByID($qid);
         $myid = $q->qid;
     }
     $q->q_title = addslashes($_POST['q_title']);
     $q->q_image = addslashes($_POST['q_img']);
     $q->q_ulangan_id = addslashes($_POST['ul_id']);
     $q->q_aktif = addslashes($_POST['q_aktif']);
     $scc = $q->save();
     //echo "Sukses save question : ".$scc." \n<br>";
     if ($scc) {
         if ($myid == 0) {
             $myid = $scc;
         }
         //echo "Sukses question ID : ".$myid." \n<br>";
         echo "Penyimpanan Sukses";
         $a = new QuizAnswer();
         $arrAns = $a->getWhere("answer_qid = '{$myid}'");
         foreach ($arrAns as $n) {
             $a->delete($n->answer_id);
         }
         //sekarang save baru
         for ($x = 0; $x < 4; $x++) {
             $checked = 0;
             if ($x == $_POST['radio']) {
                 $checked = 1;
             }
             $ans = addslashes($_POST['answer_' . $x]);
             $ans_img = addslashes($_POST['answer_' . $x . '_img']);
             $an = new QuizAnswer();
             $an->answer_qid = $myid;
             $an->answer_image = $ans_img;
             $an->answer_text = $ans;
             $an_id = $an->save();
             //echo "Sukses save answer $x : ".$an_id." \n<br>";
             if ($checked) {
                 $q1 = new QuizQuestion();
                 $q1->getByID($myid);
                 $q1->q_correct_answer_id = $an_id;
                 $q1->load = 1;
                 $q1->save();
             }
         }
     }
     //echo "end";
     exit;
 }
Beispiel #8
0
 public function hitung($args)
 {
     //pr($_POST);
     $jwb = $_POST['jwb'];
     $qid = $_POST['qid'];
     if (!isset($qid)) {
         die("No ID");
     }
     $ul = new QuizUlangan();
     $ul->getByID($qid);
     //update number
     $ul->ulangan_finished = $ul->ulangan_finished + 1;
     $ul->ulangan_update_date = leap_mysqldate();
     $ul->save();
     // user gen
     $acc = new Account();
     $ucreate = 0;
     if ($ul->ulangan_creator_id != 0) {
         $ucreate = 1;
         $acc->getByID($ul->ulangan_creator_id);
     }
     $ucreate_text = "Seberapa Indonesiakah Anda";
     //campur badge
     if ($ucreate) {
         $ul->ulangan_badge_1 = $ul->ulangan_image;
         $ul->ulangan_badge_2 = $ul->ulangan_image;
         $ul->ulangan_badge_3 = $ul->ulangan_image;
         $ul->ulangan_badge_4 = $ul->ulangan_image;
         $ul->ulangan_badge_5 = $ul->ulangan_image;
         $ucreate_text_title = $ul->ulangan_name;
         $ucreate_text = $acc->admin_name . " membuat ujian '" . $ul->ulangan_name . "' untuk INDONESIA. Berani terima tantangan dia?!?";
         $ul->ulangan_desc_1 = $ucreate_text;
         $ul->ulangan_desc_2 = $ucreate_text;
         $ul->ulangan_desc_3 = $ucreate_text;
         $ul->ulangan_desc_4 = $ucreate_text;
         $ul->ulangan_desc_5 = $ucreate_text;
         $ul->ulangan_descr = $ucreate_text;
     }
     $q = new QuizQuestion();
     $arrQ = $q->getWhere("q_ulangan_id = '{$ul->ulangan_id}' AND q_aktif = 1");
     //pr($arrQ);
     $jumlah_question = $ul->ulangan_jumlah_soal;
     foreach ($arrQ as $q) {
         $qs[$q->qid] = $q;
     }
     $point = 0;
     foreach ($jwb as $o) {
         $active = $qs[$o['qid']];
         if ($active->q_correct_answer_id == $o['aid']) {
             $point++;
         }
         //echo $o['qid']." jwb ".$o['aid']."<br>";
     }
     //pilah poin ke badge
     if ($point == 0) {
         $json['badge'] = _BPATH . _PHOTOURL . "thumbnail/" . $ul->ulangan_badge_1;
     }
     if ($point > 0 && $point < 6) {
         $json['badge'] = _BPATH . _PHOTOURL . "thumbnail/" . $ul->ulangan_badge_2;
     }
     if ($point > 5 && $point < 8) {
         $json['badge'] = _BPATH . _PHOTOURL . "thumbnail/" . $ul->ulangan_badge_3;
     }
     if ($point > 7 && $point < 10) {
         $json['badge'] = _BPATH . _PHOTOURL . "thumbnail/" . $ul->ulangan_badge_4;
     }
     if ($point == 10) {
         $json['badge'] = _BPATH . _PHOTOURL . "thumbnail/" . $ul->ulangan_badge_5;
     }
     $json['points'] = $point;
     $json['saved'] = 0;
     $json['naik_level'] = 0;
     $json['total_point'] = -1;
     $qp = new QuizPoints();
     if (Auth::isLogged()) {
         $pid = $qid . "_" . Account::getMyID();
         $qp->getByID($pid);
         if ($qp->points_id == "") {
             $qp->load = 0;
         }
         $qp->points_id = $pid;
         $qp->points_acc_id = Account::getMyID();
         $qp->points_ul_id = $qid;
         $qp->points_update = leap_mysqldate();
         if ($qp->points_nilai < $point) {
             $qp->points_nilai = $point;
         }
         $json['saved'] = $qp->save();
         $pointLama = QuizPoints::myPoints();
         $lvl_lama = floor($pointLama / 36);
         //update sessions points
         $qp->getPoints();
         $pointBaru = QuizPoints::myPoints();
         $lvl_baru = floor($pointBaru / 36);
         if ($lvl_baru > $lvl_lama && $pointLama > 0) {
             $json['naik_level'] = 1;
         }
         $json['total_point'] = $pointBaru;
     } else {
         if (!isset($_SESSION['game']['unsaved'])) {
             $_SESSION['game']['unsaved'] = array();
         }
         $_SESSION['game']['unsaved'][] = array($qid, $point);
     }
     echo json_encode($json);
     exit;
 }