/**
  * return necessaries html objects that represent the object
  *
  * @access protected
  *
  * @param $ref reference to the object that will contain this rendered object
  * @param $feedback "show feedback" flag on rendering
  * @param $rating "show rating" flag on rendering
  * @param $rating_answer "show correct answer" on rendering
  *
  * @return an object of CDOMElement
  */
 protected function renderingHtml(&$ref = null, $feedback = false, $rating = false, $rating_answer = false)
 {
     if (!$this->display) {
         return new CText('');
     }
     //if we don't have to display this question, let's return an empty item
     $out = parent::renderingHtml($ref, $feedback, $rating, $rating_answer);
     $li = new CLi();
     $li->setAttribute("class", "answer_cloze_test");
     $li->addChild(new CText($this->getPreparedText($feedback, $rating, $rating_answer)));
     $ref->addChild($li);
     return $out;
 }
 /**
  * return necessaries html objects that represent the object
  *
  * @access protected
  *
  * @param $ref reference to the object that will contain this rendered object
  * @param $feedback "show feedback" flag on rendering
  * @param $rating "show rating" flag on rendering
  * @param $rating_answer "show correct answer" on rendering
  *
  * @return an object of CDOMElement
  */
 protected function renderingHtml(&$ref = null, $feedback = false, $rating = false, $rating_answer = false)
 {
     if (!$this->display) {
         return new CText('');
     }
     //if we don't have to display this question, let's return an empty item
     if ($_SESSION['sess_id_user_type'] == AMA_TYPE_TUTOR) {
         $rating = true;
         $rating_answer = true;
     }
     $out = parent::renderingHtml($ref, $feedback, $rating, $rating_answer);
     $li = new CLi();
     $li->setAttribute('class', 'answer_cloze_multiple_test');
     $this->buildDragDropElements($li, $this->getPreparedText($feedback, $rating, $rating_answer));
     $ref->addChild($li);
     return $out;
 }
 /**
  * return necessaries html objects that represent the object
  *
  * @access protected
  *
  * @param $ref reference to the object that will contain this rendered object
  * @param $feedback "show feedback" flag on rendering
  * @param $rating "show rating" flag on rendering
  * @param $rating_answer "show correct answer" on rendering
  *
  * @return an object of CDOMElement
  */
 protected function renderingHtml(&$ref = null, $feedback = false, $rating = false, $rating_answer = false)
 {
     if (!$this->display) {
         return new CText('');
     }
     //if we don't have to display this question, let's return an empty item
     $out = parent::renderingHtml($ref, $feedback, $rating, $rating_answer);
     $li = CDOMElement::create('li');
     $li->setAttribute('class', 'answer_cloze_test');
     $preparedText = $this->getPreparedText($feedback, $rating, $rating_answer);
     if (!$feedback) {
         $this->buildDragDropElements($li, $preparedText);
     } else {
         $li->addChild(new CText($preparedText));
     }
     $ref->addChild($li);
     return $out;
 }
 /**
  * Function that automatic creates answers (and save it to database) for cloze question type
  * ADA_ERASE_TEST_SIMPLICITY version
  *
  * @global db $dh
  *
  * @param int $question_id
  * @param array $data question data
  * @param array $test test record
  *
  * @see QuestionClozeTest::createClozeAnswers
  */
 public static function createEraseClozeAnswers($question_id, $data, $test)
 {
     $dh = $GLOBALS['dh'];
     QuestionClozeTest::createClozeAnswers($question_id, $data, $test);
     require_once MODULES_TEST_PATH . '/include/nodeTest.class.inc.php';
     $questionObj = nodeTest::readNode($question_id);
     //the next function computes cloze orders with span orders and returns it
     $nuovi_ordini = $questionObj->getClozeOrders();
     //save new computed orders for each answer
     $res = $dh->test_getNodesByParent($questionObj->id_nodo);
     if (!empty($res)) {
         foreach ($res as $v) {
             $v['ordine'] = $nuovi_ordini[$v['ordine']];
             $dh->test_updateNode($v['id_nodo'], array('ordine' => $v['ordine']));
         }
     }
     //change original orders with new ones inside question text
     $testo = $questionObj->testo;
     foreach ($nuovi_ordini as $k => $v) {
         $testo = str_replace('<cloze title="' . $k . '">', '<clozeTMP title="' . $v . '">', $testo);
     }
     $testo = str_replace('<clozeTMP', '<cloze', $testo);
     $dh->test_updateNode($questionObj->id_nodo, array('testo' => $testo));
 }
 /**
  * function used to save question
  *
  * @global db $dh
  *
  * @param array $data question data to be saved in database
  * @param int $question_id question node id
  * 
  * @return node id in case of successful insert or boolean
  */
 protected function saveQuestion($data, $question_id = null)
 {
     $dh = $GLOBALS['dh'];
     $data['testo'] = preg_replace(array('#<p[^>]*>#', '#</p>#'), array('', '<br />'), $data['testo']);
     if (is_null($question_id)) {
         $question_res = $dh->test_addNode($data);
         $question_id = $question_res;
     } else {
         $question_res = $dh->test_updateNode($question_id, $data);
     }
     if ($data['tipo'][1] == ADA_CLOZE_TEST_TYPE && $question_res) {
         require_once MODULES_TEST_PATH . '/include/question.class.inc.php';
         require_once MODULES_TEST_PATH . '/include/questionCloze.class.inc.php';
         if ($data['tipo'][3] == ADA_ERASE_TEST_SIMPLICITY) {
             require_once MODULES_TEST_PATH . '/include/questionEraseCloze.class.inc.php';
             QuestionEraseClozeTest::createEraseClozeAnswers($question_id, $data, $this->test);
         } else {
             if ($data['tipo'][3] == ADA_SLOT_TEST_SIMPLICITY) {
                 require_once MODULES_TEST_PATH . '/include/questionSlotCloze.class.inc.php';
                 QuestionSlotClozeTest::createSlotClozeAnswers($question_id, $data, $this->test);
             } else {
                 if ($data['tipo'][3] == ADA_MULTIPLE_TEST_SIMPLICITY) {
                     require_once MODULES_TEST_PATH . '/include/questionMultipleCloze.class.inc.php';
                     QuestionMultipleClozeTest::createMultipleClozeAnswers($question_id, $data, $this->test);
                 } else {
                     QuestionClozeTest::createClozeAnswers($question_id, $data, $this->test);
                 }
             }
         }
     }
     return $question_res;
 }
 /**
  * Serialize answer data
  *
  * @return string serialized data
  *
  * @see Root::saveAnswers
  */
 public function serializeAnswers($data)
 {
     $orders = array();
     if (!empty($this->_children)) {
         foreach ($this->_children as $k => $v) {
             $orders[] = $v->ordine;
         }
     }
     foreach ($data[self::POST_ANSWER_VAR] as $k => $v) {
         if (!in_array($k, $orders) && empty($v)) {
             unset($data[self::POST_ANSWER_VAR][$k]);
         }
     }
     return parent::serializeAnswers($data);
 }