Example #1
0
 /**
  * Saves a the object to the database
  *
  */
 public function saveToDb($original_id = "")
 {
     $this->saveQuestionDataToDb($original_id);
     $this->saveAdditionalQuestionDataToDb();
     $this->saveAnswerSpecificDataToDb();
     parent::saveToDb();
 }
 /**
  * Saves a assFileUpload object to a database
  *
  */
 public function saveToDb($original_id = "")
 {
     global $ilDB;
     $this->saveQuestionDataToDb($original_id);
     // save additional data
     $affectedRows = $ilDB->manipulateF("DELETE FROM " . $this->getAdditionalTableName() . " WHERE question_fi = %s", array("integer"), array($this->getId()));
     $affectedRows = $ilDB->manipulateF("INSERT INTO " . $this->getAdditionalTableName() . " (question_fi, maxsize, allowedextensions, compl_by_submission) VALUES (%s, %s, %s, %s)", array("integer", "float", "text", "integer"), array($this->getId(), strlen($this->getMaxSize()) ? $this->getMaxSize() : NULL, strlen($this->getAllowedExtensions()) ? $this->getAllowedExtensions() : NULL, (int) $this->isCompletionBySubmissionEnabled()));
     parent::saveToDb();
 }
 /**
  * Saves a assOrderingHorizontal object to a database
  *
  */
 public function saveToDb($original_id = "")
 {
     global $ilDB;
     $this->saveQuestionDataToDb($original_id);
     // save additional data
     $affectedRows = $ilDB->manipulateF("DELETE FROM " . $this->getAdditionalTableName() . " WHERE question_fi = %s", array("integer"), array($this->getId()));
     $affectedRows = $ilDB->manipulateF("INSERT INTO " . $this->getAdditionalTableName() . " (question_fi, ordertext, textsize) VALUES (%s, %s, %s)", array("integer", "text", "float"), array($this->getId(), $this->getOrderText(), $this->getTextSize() < 10 ? NULL : $this->getTextSize()));
     parent::saveToDb();
 }
 /**
  * Saves a the object to the database
  *
  */
 public function saveToDb($original_id = "")
 {
     global $ilDB;
     $this->saveQuestionDataToDb($original_id);
     // save additional data
     $affectedRows = $ilDB->manipulateF("DELETE FROM " . $this->getAdditionalTableName() . " WHERE question_fi = %s", array("integer"), array($this->getId()));
     $affectedRows = $ilDB->manipulateF("INSERT INTO " . $this->getAdditionalTableName() . " (question_fi, errortext, textsize, points_wrong) VALUES (%s, %s, %s, %s)", array("integer", "text", "float", "float"), array($this->getId(), $this->getErrorText(), $this->getTextSize(), $this->getPointsWrong()));
     $affectedRows = $ilDB->manipulateF("DELETE FROM qpl_a_errortext WHERE question_fi = %s", array('integer'), array($this->getId()));
     $sequence = 0;
     foreach ($this->errordata as $object) {
         $next_id = $ilDB->nextId('qpl_a_errortext');
         $affectedRows = $ilDB->manipulateF("INSERT INTO qpl_a_errortext (answer_id, question_fi, text_wrong, text_correct, points, sequence) VALUES (%s, %s, %s, %s, %s, %s)", array('integer', 'integer', 'text', 'text', 'float', 'integer'), array($next_id, $this->getId(), $object->text_wrong, $object->text_correct, $object->points, $sequence++));
     }
     parent::saveToDb();
 }
 /**
  * Saves a assFlashQuestion object to a database
  *
  * @access public
  */
 function saveToDb($original_id = "")
 {
     global $ilDB, $ilLog;
     $this->saveQuestionDataToDb($original_id);
     // save additional data
     $affectedRows = $ilDB->manipulateF("DELETE FROM " . $this->getAdditionalTableName() . " WHERE question_fi = %s", array("integer"), array($this->getId()));
     $affectedRows = $ilDB->manipulateF("INSERT INTO " . $this->getAdditionalTableName() . " (question_fi, width, height, applet, params) VALUES (%s, %s, %s, %s, %s)", array("integer", "integer", "integer", "text", "text"), array($this->getId(), strlen($this->getWidth()) ? $this->getWidth() : 550, strlen($this->getHeight()) ? $this->getHeight() : 400, $this->getApplet(), serialize($this->getParameters())));
     if ($_SESSION["flash_upload_filename"]) {
         $path = $this->getFlashPath();
         ilUtil::makeDirParents($path);
         @rename($_SESSION["flash_upload_filename"], $path . $this->getApplet());
         unset($_SESSION["flash_upload_filename"]);
     }
     parent::saveToDb();
 }
 /**
  * Saves a assNumeric object to a database
  *
  * @param object $db A pear DB object
  * @access public
  */
 function saveToDb($original_id = "")
 {
     global $ilDB;
     $this->saveQuestionDataToDb($original_id);
     // save additional data
     $affectedRows = $ilDB->manipulateF("DELETE FROM " . $this->getAdditionalTableName() . " WHERE question_fi = %s", array("integer"), array($this->getId()));
     $affectedRows = $ilDB->manipulateF("INSERT INTO " . $this->getAdditionalTableName() . " (question_fi, maxnumofchars) VALUES (%s, %s)", array("integer", "integer"), array($this->getId(), $this->getMaxChars() ? $this->getMaxChars() : 0));
     // Write range to the database
     // 1. delete old range
     $result = $ilDB->manipulateF("DELETE FROM qpl_num_range WHERE question_fi = %s", array('integer'), array($this->getId()));
     // 2. write range
     $next_id = $ilDB->nextId('qpl_num_range');
     $answer_result = $ilDB->manipulateF("INSERT INTO qpl_num_range (range_id, question_fi, lowerlimit, upperlimit, points, aorder, tstamp) VALUES (%s, %s, %s, %s, %s, %s, %s)", array('integer', 'integer', 'text', 'text', 'float', 'integer', 'integer'), array($next_id, $this->id, $this->getLowerLimit(), $this->getUpperLimit(), $this->getPoints(), 0, time()));
     parent::saveToDb($original_id);
 }
 /**
  * Saves a assJavaApplet object to a database
  *
  * Saves a assJavaApplet object to a database (experimental)
  *
  * @param object $db A pear DB object
  * @access public
  */
 function saveToDb($original_id = "")
 {
     global $ilDB;
     $this->saveQuestionDataToDb($original_id);
     $params = $this->buildParams();
     // save additional data
     $affectedRows = $ilDB->manipulateF("DELETE FROM " . $this->getAdditionalTableName() . " WHERE question_fi = %s", array("integer"), array($this->getId()));
     $affectedRows = $ilDB->manipulateF("INSERT INTO " . $this->getAdditionalTableName() . " (question_fi, image_file, params) VALUES (%s, %s, %s)", array("integer", "text", "text"), array($this->getId(), $this->javaapplet_filename, $params));
     parent::saveToDb($original_id);
 }
 /**
  * Saves a assMultipleChoice object to a database
  *
  * @param string $original_id
  */
 public function saveToDb($original_id = "")
 {
     $this->saveQuestionDataToDb($original_id);
     $this->saveAdditionalQuestionDataToDb();
     $this->saveAnswerSpecificDataToDb();
     $this->ensureNoInvalidObligation($this->getId());
     parent::saveToDb($original_id);
 }
 /**
  * Saves a assClozeTest object to a database
  *
  * @param integer $original_id ID of the original question
  * @access public
  */
 function saveToDb($original_id = "")
 {
     global $ilDB;
     $this->saveQuestionDataToDb($original_id);
     include_once "./Services/Math/classes/class.EvalMath.php";
     $eval = new EvalMath();
     $eval->suppress_errors = TRUE;
     // save additional data
     $affectedRows = $ilDB->manipulateF("DELETE FROM " . $this->getAdditionalTableName() . " WHERE question_fi = %s", array("integer"), array($this->getId()));
     $affectedRows = $ilDB->manipulateF("INSERT INTO " . $this->getAdditionalTableName() . " (question_fi, textgap_rating, identical_scoring, fixed_textlen) VALUES (%s, %s, %s, %s)", array("integer", "text", "text", "integer"), array($this->getId(), $this->getTextgapRating(), $this->getIdenticalScoring(), $this->getFixedTextLength() ? $this->getFixedTextLength() : NULL));
     $affectedRows = $ilDB->manipulateF("DELETE FROM qpl_a_cloze WHERE question_fi = %s", array("integer"), array($this->getId()));
     foreach ($this->gaps as $key => $gap) {
         foreach ($gap->getItems() as $item) {
             $query = "";
             switch ($gap->getType()) {
                 case CLOZE_TEXT:
                     $next_id = $ilDB->nextId('qpl_a_cloze');
                     $affectedRows = $ilDB->manipulateF("INSERT INTO qpl_a_cloze (answer_id, question_fi, gap_id, answertext, points, aorder, cloze_type) VALUES (%s, %s, %s, %s, %s, %s, %s)", array("integer", "integer", "integer", "text", "float", "integer", "text"), array($next_id, $this->getId(), $key, strlen($item->getAnswertext()) ? $item->getAnswertext() : "", $item->getPoints(), $item->getOrder(), $gap->getType()));
                     break;
                 case CLOZE_SELECT:
                     $next_id = $ilDB->nextId('qpl_a_cloze');
                     $affectedRows = $ilDB->manipulateF("INSERT INTO qpl_a_cloze (answer_id, question_fi, gap_id, answertext, points, aorder, cloze_type, shuffle) VALUES (%s, %s, %s, %s, %s, %s, %s, %s)", array("integer", "integer", "integer", "text", "float", "integer", "text", "text"), array($next_id, $this->getId(), $key, strlen($item->getAnswertext()) ? $item->getAnswertext() : "", $item->getPoints(), $item->getOrder(), $gap->getType(), $gap->getShuffle() ? "1" : "0"));
                     break;
                 case CLOZE_NUMERIC:
                     $next_id = $ilDB->nextId('qpl_a_cloze');
                     $affectedRows = $ilDB->manipulateF("INSERT INTO qpl_a_cloze (answer_id, question_fi, gap_id, answertext, points, aorder, cloze_type, lowerlimit, upperlimit) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s)", array("integer", "integer", "integer", "text", "float", "integer", "text", "text", "text"), array($next_id, $this->getId(), $key, strlen($item->getAnswertext()) ? $item->getAnswertext() : "", $item->getPoints(), $item->getOrder(), $gap->getType(), $eval->e($item->getLowerBound() !== FALSE) && strlen($item->getLowerBound()) > 0 ? $item->getLowerBound() : $item->getAnswertext(), $eval->e($item->getUpperBound() !== FALSE) && strlen($item->getUpperBound()) > 0 ? $item->getUpperBound() : $item->getAnswertext()));
                     break;
             }
         }
     }
     parent::saveToDb($original_id);
 }
    /**
     * Saves a assFormulaQuestion object to a database
     * @access public
     */
    function saveToDb($original_id = "")
    {
        global $ilDB;
        $this->saveQuestionDataToDb($original_id);
        // save variables
        $affectedRows = $ilDB->manipulateF("\n\t\tDELETE FROM il_qpl_qst_fq_var \n\t\tWHERE question_fi = %s", array("integer"), array($this->getId()));
        $source_qst_id = $original_id;
        $target_qst_id = $this->getId();
        foreach ($this->variables as $variable) {
            $next_id = $ilDB->nextId('il_qpl_qst_fq_var');
            $ilDB->insert('il_qpl_qst_fq_var', array('variable_id' => array('integer', $next_id), 'question_fi' => array('integer', $this->getId()), 'variable' => array('text', $variable->getVariable()), 'range_min' => array('float', strlen($variable->getRangeMin()) ? $variable->getRangeMin() : 0.0), 'range_max' => array('float', strlen($variable->getRangeMax()) ? $variable->getRangeMax() : 0.0), 'unit_fi' => array('integer', is_object($variable->getUnit()) ? (int) $variable->getUnit()->getId() : 0), 'varprecision' => array('integer', (int) $variable->getPrecision()), 'intprecision' => array('integer', (int) $variable->getIntprecision()), 'range_min_txt' => array('text', $variable->getRangeMinTxt()), 'range_max_txt' => array('text', $variable->getRangeMaxTxt())));
        }
        // save results
        $affectedRows = $ilDB->manipulateF("DELETE FROM il_qpl_qst_fq_res WHERE question_fi = %s", array("integer"), array($this->getId()));
        foreach ($this->results as $result) {
            $next_id = $ilDB->nextId('il_qpl_qst_fq_res');
            if (is_object($result->getUnit())) {
                $tmp_result_unit = $result->getUnit()->getId();
            } else {
                $tmp_result_unit = NULL;
            }
            $formula = str_replace(",", ".", $result->getFormula());
            $ilDB->insert("il_qpl_qst_fq_res", array("result_id" => array("integer", $next_id), "question_fi" => array("integer", $this->getId()), "result" => array("text", $result->getResult()), "range_min" => array("float", strlen($result->getRangeMin()) ? $result->getRangeMin() : 0), "range_max" => array("float", strlen($result->getRangeMax()) ? $result->getRangeMax() : 0), "tolerance" => array("float", strlen($result->getTolerance()) ? $result->getTolerance() : 0), "unit_fi" => array("integer", (int) $tmp_result_unit), "formula" => array("clob", $formula), "resprecision" => array("integer", $result->getPrecision()), "rating_simple" => array("integer", $result->getRatingSimple() ? 1 : 0), "rating_sign" => array("float", $result->getRatingSimple() ? 0 : $result->getRatingSign()), "rating_value" => array("float", $result->getRatingSimple() ? 0 : $result->getRatingValue()), "rating_unit" => array("float", $result->getRatingSimple() ? 0 : $result->getRatingUnit()), "points" => array("float", $result->getPoints()), "result_type" => array('integer', (int) $result->getResultType()), "range_min_txt" => array("text", $result->getRangeMinTxt()), "range_max_txt" => array("text", $result->getRangeMaxTxt())));
        }
        // save result units
        $affectedRows = $ilDB->manipulateF("DELETE FROM il_qpl_qst_fq_res_unit WHERE question_fi = %s", array("integer"), array($this->getId()));
        foreach ($this->results as $result) {
            foreach ($this->getResultUnits($result) as $unit) {
                $next_id = $ilDB->nextId('il_qpl_qst_fq_res_unit');
                $affectedRows = $ilDB->manipulateF("INSERT INTO il_qpl_qst_fq_res_unit (result_unit_id, question_fi, result, unit_fi) VALUES (%s, %s, %s, %s)", array('integer', 'integer', 'text', 'integer'), array($next_id, $this->getId(), $result->getResult(), $unit->getId()));
            }
        }
        // copy category/unit-process:
        // if $source_qst_id = '' -> nothing to copy because this is a new question
        // if $source_qst_id == $target_qst_id -> nothing to copy because this is just an update-process
        // if $source_qst_id != $target_qst_id -> copy categories and untis because this is a copy-process
        // @todo: Nadia wtf?
        if ($source_qst_id != $target_qst_id && $source_qst_id > 0) {
            $res = $ilDB->queryF('
				SELECT * FROM il_qpl_qst_fq_ucat WHERE question_fi = %s', array('integer'), array($source_qst_id));
            $cp_cats = array();
            while ($row = $ilDB->fetchAssoc($res)) {
                $cp_cats[] = $row['category_id'];
            }
            foreach ($cp_cats as $old_category_id) {
                // copy admin-categorie to custom-category (with question_fi)
                $new_cat_id = $this->unitrepository->copyCategory($old_category_id, $target_qst_id);
                // copy units to custom_category
                $this->unitrepository->copyUnitsByCategories($old_category_id, $new_cat_id, $target_qst_id);
            }
        }
        parent::saveToDb();
    }
 /**
  * Saves a assOrderingQuestion object to a database
  *
  * @param object $db A pear DB object
  * @access public
  */
 function saveToDb($original_id = "")
 {
     global $ilDB;
     $this->saveQuestionDataToDb($original_id);
     // save additional data
     $affectedRows = $ilDB->manipulateF("DELETE FROM " . $this->getAdditionalTableName() . " WHERE question_fi = %s", array("integer"), array($this->getId()));
     $affectedRows = $ilDB->manipulateF("INSERT INTO " . $this->getAdditionalTableName() . " (question_fi, ordering_type, thumb_geometry, element_height) VALUES (%s, %s, %s, %s)", array("integer", "text", "integer", "integer"), array($this->getId(), $this->ordering_type, $this->getThumbGeometry(), $this->getElementHeight() > 20 ? $this->getElementHeight() : NULL));
     $affectedRows = $ilDB->manipulateF("DELETE FROM qpl_a_ordering WHERE question_fi = %s", array('integer'), array($this->getId()));
     // Anworten wegschreiben
     foreach ($this->answers as $key => $value) {
         $answer_obj = $this->answers[$key];
         $next_id = $ilDB->nextId('qpl_a_ordering');
         $affectedRows = $ilDB->manipulateF("INSERT INTO qpl_a_ordering (answer_id, question_fi, answertext, solution_order, " . "random_id, tstamp) VALUES (%s, %s, %s, %s, %s, %s)", array('integer', 'integer', 'text', 'integer', 'integer', 'integer'), array($next_id, $this->getId(), ilRTE::_replaceMediaObjectImageSrc($answer_obj->getAnswertext(), 0), $key, $answer_obj->getRandomID(), time()));
     }
     if ($this->getOrderingType() == OQ_PICTURES) {
         $this->rebuildThumbnails();
     }
     $this->cleanImagefiles();
     parent::saveToDb($original_id);
 }
 /**
  * Saves a assTextQuestion object to a database
  *
  * @param object $db A pear DB object
  * @access public
  */
 function saveToDb($original_id = "")
 {
     global $ilDB;
     $this->saveQuestionDataToDb($original_id);
     // save additional data
     $affectedRows = $ilDB->manipulateF("DELETE FROM " . $this->getAdditionalTableName() . " WHERE question_fi = %s", array("integer"), array($this->getId()));
     $affectedRows = $ilDB->manipulateF("INSERT INTO " . $this->getAdditionalTableName() . " (question_fi, maxnumofchars, keywords, textgap_rating, matchcondition, keyword_relation) VALUES (%s, %s, %s, %s, %s, %s)", array("integer", "integer", "text", "text", 'integer', 'text'), array($this->getId(), $this->getMaxNumOfChars(), NULL, $this->getTextRating(), $this->matchcondition, $this->getKeywordRelation()));
     $ilDB->manipulateF("DELETE FROM qpl_a_essay WHERE question_fi = %s", array("integer"), array($this->getId()));
     foreach ($this->answers as $answer) {
         $nextID = $ilDB->nextId('qpl_a_essay');
         $ilDB->manipulateF("INSERT INTO qpl_a_essay (answer_id, question_fi, answertext, points) VALUES (%s, %s, %s, %s)", array("integer", "integer", "text", 'float'), array($nextID, $this->getId(), $answer->answertext, $answer->points));
     }
     parent::saveToDb($original_id);
 }
 /**
  * Saves a assMatchingQuestion object to a database
  *
  * @param object $db A pear DB object
  */
 public function saveToDb($original_id = "")
 {
     global $ilDB;
     $this->saveQuestionDataToDb($original_id);
     // save additional data
     $affectedRows = $ilDB->manipulateF("DELETE FROM " . $this->getAdditionalTableName() . " WHERE question_fi = %s", array("integer"), array($this->getId()));
     $affectedRows = $ilDB->manipulateF("INSERT INTO " . $this->getAdditionalTableName() . " (question_fi, shuffle, matching_type, thumb_geometry, element_height) VALUES (%s, %s, %s, %s, %s)", array("integer", "text", "text", "integer", "integer"), array($this->getId(), $this->shuffle, $this->matching_type, $this->getThumbGeometry(), $this->getElementHeight() >= 20 ? $this->getElementHeight() : NULL));
     // delete old terms
     $affectedRows = $ilDB->manipulateF("DELETE FROM qpl_a_mterm WHERE question_fi = %s", array('integer'), array($this->getId()));
     // delete old definitions
     $affectedRows = $ilDB->manipulateF("DELETE FROM qpl_a_mdef WHERE question_fi = %s", array('integer'), array($this->getId()));
     $termids = array();
     // write terms
     foreach ($this->terms as $key => $term) {
         $next_id = $ilDB->nextId('qpl_a_mterm');
         $affectedRows = $ilDB->manipulateF("INSERT INTO qpl_a_mterm (term_id, question_fi, picture, term) VALUES (%s, %s, %s, %s)", array('integer', 'integer', 'text', 'text'), array($next_id, $this->getId(), $term->picture, $term->text));
         $termids[$term->identifier] = $next_id;
     }
     $definitionids = array();
     // write definitions
     foreach ($this->definitions as $key => $definition) {
         $next_id = $ilDB->nextId('qpl_a_mdef');
         $affectedRows = $ilDB->manipulateF("INSERT INTO qpl_a_mdef (def_id, question_fi, picture, definition, morder) VALUES (%s, %s, %s, %s, %s)", array('integer', 'integer', 'text', 'text', 'integer'), array($next_id, $this->getId(), $definition->picture, $definition->text, $definition->identifier));
         $definitionids[$definition->identifier] = $next_id;
     }
     $affectedRows = $ilDB->manipulateF("DELETE FROM qpl_a_matching WHERE question_fi = %s", array('integer'), array($this->getId()));
     $matchingpairs = $this->getMatchingPairs();
     foreach ($matchingpairs as $key => $pair) {
         $next_id = $ilDB->nextId('qpl_a_matching');
         $affectedRows = $ilDB->manipulateF("INSERT INTO qpl_a_matching (answer_id, question_fi, points, term_fi, definition_fi) VALUES (%s, %s, %s, %s, %s)", array('integer', 'integer', 'float', 'integer', 'integer'), array($next_id, $this->getId(), $pair->points, $termids[$pair->term->identifier], $definitionids[$pair->definition->identifier]));
     }
     $this->rebuildThumbnails();
     parent::saveToDb($original_id);
 }
 /**
  * Saves a assFlashQuestion object to a database
  *
  * @access public
  */
 function saveToDb($original_id = "")
 {
     $this->saveQuestionDataToDb($original_id);
     $this->saveAdditionalQuestionDataToDb();
     parent::saveToDb();
 }
 /**
  * Saves a assSingleChoice object to a database
  *
  * @param string $original_id
  *
  */
 public function saveToDb($original_id = "")
 {
     /** @var ilDB $ilDB */
     global $ilDB;
     $this->saveQuestionDataToDb($original_id);
     // kann das weg?
     $oldthumbsize = 0;
     if ($this->isSingleline && $this->getThumbSize()) {
         // get old thumbnail size
         $result = $ilDB->queryF("SELECT thumb_size FROM " . $this->getAdditionalTableName() . " WHERE question_fi = %s", array("integer"), array($this->getId()));
         if ($result->numRows() == 1) {
             $data = $ilDB->fetchAssoc($result);
             $oldthumbsize = $data['thumb_size'];
         }
     }
     $this->saveAdditionalQuestionDataToDb();
     $this->saveAnswerSpecificDataToDb();
     parent::saveToDb($original_id);
 }
 /**
  * Saves a assImagemapQuestion object to a database
  *
  * Saves a assImagemapQuestion object to a database (experimental)
  *
  * @param object $db A pear DB object
  * @access public
  */
 function saveToDb($original_id = "")
 {
     global $ilDB;
     $this->saveQuestionDataToDb($original_id);
     // save additional data
     $affectedRows = $ilDB->manipulateF("DELETE FROM " . $this->getAdditionalTableName() . " WHERE question_fi = %s", array("integer"), array($this->getId()));
     $affectedRows = $ilDB->manipulateF("INSERT INTO " . $this->getAdditionalTableName() . " (question_fi, image_file) VALUES (%s, %s)", array("integer", "text"), array($this->getId(), $this->image_filename));
     $affectedRows = $ilDB->manipulateF("DELETE FROM qpl_a_imagemap WHERE question_fi = %s", array("integer"), array($this->getId()));
     // Anworten wegschreiben
     foreach ($this->answers as $key => $value) {
         $answer_obj = $this->answers[$key];
         $next_id = $ilDB->nextId('qpl_a_imagemap');
         $affectedRows = $ilDB->manipulateF("INSERT INTO qpl_a_imagemap (answer_id, question_fi, answertext, points, aorder, coords, area) VALUES (%s, %s, %s, %s, %s, %s, %s)", array("integer", "integer", "text", "float", "integer", "text", "text"), array($next_id, $this->id, $answer_obj->getAnswertext(), $answer_obj->getPoints(), $answer_obj->getOrder(), $answer_obj->getCoords(), $answer_obj->getArea()));
     }
     parent::saveToDb($original_id);
 }
 /**
  * Saves a assFormulaQuestion object to a database
  *
  * @param    string        original id
  * @param    boolean        save all parts, too
  * @access    public
  */
 function saveToDb($original_id = "", $a_save_parts = true)
 {
     global $ilDB, $ilLog;
     // collect the maximum points of all parts
     // must be done before basic data is saved
     $this->calculateMaximumPoints();
     // save the basic data (implemented in parent)
     // a new question is created if the id is -1
     // afterwards the new id is set
     $this->saveQuestionDataToDb($original_id);
     // save the account definition to a separate hash table
     $hash = hash("md5", $this->getAccountsXML());
     $ilDB->replace('il_qpl_qst_accqst_hash', array('hash' => array('text', $hash)), array('data' => array('clob', $this->getAccountsXML())));
     // save data to DB
     $ilDB->replace('il_qpl_qst_accqst_data', array('question_fi' => array('integer', $ilDB->quote($this->getId(), 'integer'))), array('question_fi' => array('integer', $ilDB->quote($this->getId(), 'integer')), 'account_hash' => array('text', $hash)));
     // save all parts (also a new one)
     if ($a_save_parts) {
         foreach ($this->parts as $part_obj) {
             $part_obj->write();
         }
     }
     // save stuff like suggested solutions
     // update the question time stamp and completion status
     parent::saveToDb();
 }
 /**
  * Saves a assSingleChoice object to a database
  *
  * @param object $db A pear DB object
  * @access public
  */
 function saveToDb($original_id = "")
 {
     global $ilDB;
     $this->saveQuestionDataToDb($original_id);
     $oldthumbsize = 0;
     if ($this->isSingleline && $this->getThumbSize()) {
         // get old thumbnail size
         $result = $ilDB->queryF("SELECT thumb_size FROM " . $this->getAdditionalTableName() . " WHERE question_fi = %s", array("integer"), array($this->getId()));
         if ($result->numRows() == 1) {
             $data = $ilDB->fetchAssoc($result);
             $oldthumbsize = $data['thumb_size'];
         }
     }
     if (!$this->isSingleline) {
         ilUtil::delDir($this->getImagePath());
     }
     // save additional data
     $affectedRows = $ilDB->manipulateF("DELETE FROM " . $this->getAdditionalTableName() . " WHERE question_fi = %s", array("integer"), array($this->getId()));
     $affectedRows = $ilDB->manipulateF("INSERT INTO " . $this->getAdditionalTableName() . " (question_fi, shuffle, allow_images, thumb_size) VALUES (%s, %s, %s, %s)", array("integer", "text", "text", "integer"), array($this->getId(), $this->getShuffle(), $this->isSingleline ? "0" : "1", strlen($this->getThumbSize()) == 0 ? null : $this->getThumbSize()));
     $affectedRows = $ilDB->manipulateF("DELETE FROM qpl_a_sc WHERE question_fi = %s", array('integer'), array($this->getId()));
     foreach ($this->answers as $key => $value) {
         $answer_obj = $this->answers[$key];
         $next_id = $ilDB->nextId('qpl_a_sc');
         $affectedRows = $ilDB->manipulateF("INSERT INTO qpl_a_sc (answer_id, question_fi, answertext, points, aorder, imagefile, tstamp) VALUES (%s, %s, %s, %s, %s, %s, %s)", array('integer', 'integer', 'text', 'float', 'integer', 'text', 'integer'), array($next_id, $this->getId(), ilRTE::_replaceMediaObjectImageSrc($answer_obj->getAnswertext(), 0), $answer_obj->getPoints(), $answer_obj->getOrder(), $answer_obj->getImage(), time()));
     }
     $this->rebuildThumbnails();
     parent::saveToDb($original_id);
 }
 /**
  * Saves a assTextSubset object to a database
  *
  * @param object $db A pear DB object
  * @access public
  */
 function saveToDb($original_id = "")
 {
     global $ilDB;
     $this->saveQuestionDataToDb($original_id);
     // save additional data
     $affectedRows = $ilDB->manipulateF("DELETE FROM " . $this->getAdditionalTableName() . " WHERE question_fi = %s", array("integer"), array($this->getId()));
     $affectedRows = $ilDB->manipulateF("INSERT INTO " . $this->getAdditionalTableName() . " (question_fi, textgap_rating, correctanswers) VALUES (%s, %s, %s)", array("integer", "text", "integer"), array($this->getId(), $this->getTextRating(), $this->getCorrectAnswers()));
     $affectedRows = $ilDB->manipulateF("DELETE FROM qpl_a_textsubset WHERE question_fi = %s", array('integer'), array($this->getId()));
     foreach ($this->answers as $key => $value) {
         $answer_obj = $this->answers[$key];
         $next_id = $ilDB->nextId('qpl_a_textsubset');
         $query = $ilDB->manipulateF("INSERT INTO qpl_a_textsubset (answer_id, question_fi, answertext, points, aorder, tstamp) VALUES (%s, %s, %s, %s, %s, %s)", array('integer', 'integer', 'text', 'float', 'integer', 'integer'), array($next_id, $this->getId(), $answer_obj->getAnswertext(), $answer_obj->getPoints(), $answer_obj->getOrder(), time()));
     }
     parent::saveToDb($original_id);
 }
Example #20
0
 /**
  * Saves a SyntaxTree object to a database
  *
  * Saves a SyntaxTree object to a database (experimental)
  *
  * @param object $db A pear DB object
  * @access public
  */
 function saveToDb($original_id = "")
 {
     global $ilDB;
     $complete = 0;
     if ($this->isComplete()) {
         $complete = 1;
     }
     $estw_time = $this->getEstimatedWorkingTime();
     $estw_time = sprintf("%02d:%02d:%02d", $estw_time['h'], $estw_time['m'], $estw_time['s']);
     if ($original_id) {
         $original_id = $ilDB->quote($original_id);
     } else {
         $original_id = "NULL";
     }
     // cleanup RTE images which are not inserted into the question text
     include_once "./Services/RTE/classes/class.ilRTE.php";
     if ($this->id == -1) {
         // Neuen Datensatz schreiben
         $now = getdate();
         $next_id = $ilDB->nextId('qpl_questions');
         $tstamp = array("integer", time());
         $question_type = $this->getQuestionTypeID();
         $created = sprintf("%04d%02d%02d%02d%02d%02d", $now['year'], $now['mon'], $now['mday'], $now['hours'], $now['minutes'], $now['seconds']);
         $query = sprintf("INSERT INTO qpl_questions (question_id, question_type_fi, obj_fi, title, description, author, owner, question_text, points, working_time, complete, created, original_id, tstamp) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)", $ilDB->quote($next_id), $ilDB->quote($question_type), $ilDB->quote($this->obj_id), $ilDB->quote($this->title), $ilDB->quote($this->comment), $ilDB->quote($this->author), $ilDB->quote($this->owner), $ilDB->quote(ilRTE::_replaceMediaObjectImageSrc($this->question, 0)), $ilDB->quote($this->getMaximumPoints() . ""), $ilDB->quote($estw_time), $ilDB->quote("{$complete}"), $ilDB->quote($created), $original_id, $ilDB->quote($tstamp));
         $result = $ilDB->query($query);
         if (PEAR::isError($result)) {
             global $ilias;
             $ilias->raiseError($result->getMessage());
         } else {
             $this->id = $ilDB->getLastInsertId();
             $query = sprintf("INSERT INTO il_qpl_qst_st_quest (question_fi, textgap_rating, correctanswers) VALUES (%s, %s, %s)", $ilDB->quote($this->id . ""), $ilDB->quote($this->getTextRating() . ""), $ilDB->quote($this->getCorrectAnswers() . ""));
             $ilDB->query($query);
             // create page object of question
             $this->createPageObject();
             // Falls die Frage in einen Test eingefügt werden soll, auch diese Verbindung erstellen
             if ($this->getTestId() > 0) {
                 $this->insertIntoTest($this->getTestId());
             }
         }
     } else {
         // Vorhandenen Datensatz aktualisieren
         $query = sprintf("UPDATE qpl_questions SET obj_fi = %s, title = %s, description = %s, author = %s, question_text = %s, points = %s, working_time=%s, complete = %s WHERE question_id = %s", $ilDB->quote($this->obj_id . ""), $ilDB->quote($this->title), $ilDB->quote($this->comment), $ilDB->quote($this->author), $ilDB->quote(ilRTE::_replaceMediaObjectImageSrc($this->question, 0)), $ilDB->quote($this->getMaximumPoints() . ""), $ilDB->quote($estw_time), $ilDB->quote("{$complete}"), $ilDB->quote($this->id));
         $result = $ilDB->query($query);
         $query = sprintf("UPDATE il_qpl_qst_st_quest SET textgap_rating = %s, correctanswers = %s WHERE question_fi = %s", $ilDB->quote($this->getTextRating() . ""), $ilDB->quote($this->getCorrectAnswers() . ""), $ilDB->quote($this->id . ""));
         $result = $ilDB->query($query);
     }
     if (PEAR::isError($result)) {
         global $ilias;
         $ilias->raiseError($result->getMessage());
     } else {
         // Write Ranges to the database
         // 1. delete old ranges
         $query = sprintf("DELETE FROM il_qpl_qst_st_answer WHERE question_fi = %s", $ilDB->quote($this->id));
         $result = $ilDB->query($query);
         // 2. write ranges
         foreach ($this->answers as $key => $value) {
             $answer_obj = $this->answers[$key];
             $query = sprintf("INSERT INTO il_qpl_qst_st_answer (answer_id, question_fi, answertext, points, aorder) VALUES (NULL, %s, %s, %s, %s)", $ilDB->quote($this->id), $ilDB->quote($answer_obj->getAnswertext()), $ilDB->quote($answer_obj->getPoints() . ""), $ilDB->quote($answer_obj->getOrder() . ""));
             $answer_result = $ilDB->query($query);
         }
     }
     parent::saveToDb($original_id);
 }
 /**
  * Saves a assJSMEQuestion object to a database
  *
  * @access public
  */
 function saveToDb($original_id = "")
 {
     global $ilDB, $ilLog;
     $this->saveQuestionDataToDb($original_id);
     $affectedRows = $ilDB->manipulateF("DELETE FROM il_qpl_qst_jsme_data WHERE question_fi = %s", array("integer"), array($this->getId()));
     $affectedRows = $ilDB->manipulateF("INSERT INTO il_qpl_qst_jsme_data (question_fi, option_string, solution) VALUES (%s, %s, %s)", array("integer", "text", "text"), array($this->getId(), $this->optionString, $this->sampleSolution));
     parent::saveToDb($original_id);
 }