/**
  * @param ilTermsOfServiceAcceptanceEntity $entity
  */
 public function trackAcceptance(ilTermsOfServiceAcceptanceEntity $entity)
 {
     $query = 'SELECT id FROM tos_versions WHERE hash = %s AND lng = %s';
     $res = $this->db->queryF($query, array('text', 'text'), array($entity->getHash(), $entity->getIso2LanguageCode()));
     if ($this->db->numRows($res)) {
         $row = $this->db->fetchAssoc($res);
         $tosv_id = $row['id'];
     } else {
         $tosv_id = $this->db->nextId('tos_versions');
         $this->db->insert('tos_versions', array('id' => array('integer', $tosv_id), 'lng' => array('text', $entity->getIso2LanguageCode()), 'src' => array('text', $entity->getSource()), 'src_type' => array('integer', $entity->getSourceType()), 'text' => array('clob', $entity->getText()), 'hash' => array('text', $entity->getHash()), 'ts' => array('integer', $entity->getTimestamp())));
     }
     $this->db->insert('tos_acceptance_track', array('tosv_id' => array('integer', $tosv_id), 'usr_id' => array('integer', $entity->getUserId()), 'ts' => array('integer', $entity->getTimestamp())));
 }
 private function stageQuestionsFromSourcePool($sourcePoolId)
 {
     $questionIdMapping = array();
     $query = 'SELECT question_id FROM qpl_questions WHERE obj_fi = %s AND complete = %s AND original_id IS NULL';
     $res = $this->db->queryF($query, array('integer', 'text'), array($sourcePoolId, 1));
     while ($row = $this->db->fetchAssoc($res)) {
         $question = assQuestion::_instanciateQuestion($row['question_id']);
         $duplicateId = $question->duplicate(true, null, null, null, $this->testOBJ->getId());
         $nextId = $this->db->nextId('tst_rnd_cpy');
         $this->db->insert('tst_rnd_cpy', array('copy_id' => array('integer', $nextId), 'tst_fi' => array('integer', $this->testOBJ->getTestId()), 'qst_fi' => array('integer', $duplicateId), 'qpl_fi' => array('integer', $sourcePoolId)));
         $questionIdMapping[$row['question_id']] = $duplicateId;
     }
     return $questionIdMapping;
 }
 protected function adoptSourceResult($questionId, $sourcePass)
 {
     $res = $this->db->execute($this->getPreparedSelectResultRecordStatement(), array($this->getActiveId(), $questionId, $sourcePass));
     $row = $this->db->fetchAssoc($res);
     $resultId = $this->db->nextId('tst_test_result');
     $this->db->execute($this->getPreparedInsertResultRecordStatement(), array($resultId, $this->getActiveId(), $questionId, $this->getTargetPass(), time(), $row['points'], $row['manual'], $row['hint_count'], $row['hint_points'], $row['answered']));
 }
 /**
  * @return bool
  */
 public function add()
 {
     $next_id = $this->db->nextId(self::TABLE_NAME);
     $query = 'INSERT INTO ' . self::TABLE_NAME . ' (rule_id,role_id,name,value,plugin,plugin_id,add_on_update,remove_on_update ) ' . 'VALUES( ' . $this->db->quote($next_id, 'integer') . ', ' . $this->db->quote($this->getRoleId(), 'integer') . ', ' . $this->db->quote($this->getName(), 'text') . ', ' . $this->db->quote($this->getValue(), 'text') . ', ' . $this->db->quote((int) $this->isPluginActive(), 'integer') . ', ' . $this->db->quote((int) $this->getPluginId(), 'integer') . ', ' . $this->db->quote((int) $this->isAddOnUpdateEnabled(), 'integer') . ', ' . $this->db->quote((int) $this->isRemoveOnUpdateEnabled(), 'integer') . ') ';
     $this->db->manipulate($query);
     $this->setRuleId($this->db->getLastInsertId());
     return true;
 }
 /**
  * syncs the GENERIC feedback from a duplicated question back to the original question
  * 
  * @final
  * @access private
  * @param integer $originalQuestionId
  * @param integer $duplicateQuestionId
  */
 private final function syncGenericFeedback($originalQuestionId, $duplicateQuestionId)
 {
     // delete generic feedback of the original question
     $this->db->manipulateF("DELETE FROM {$this->getGenericFeedbackTableName()} WHERE question_fi = %s", array('integer'), array($originalQuestionId));
     // get generic feedback of the actual (duplicated) question
     $result = $this->db->queryF("SELECT * FROM {$this->getGenericFeedbackTableName()} WHERE question_fi = %s", array('integer'), array($duplicateQuestionId));
     // save generic feedback to the original question
     while ($row = $this->db->fetchAssoc($result)) {
         $nextId = $this->db->nextId($this->getGenericFeedbackTableName());
         $this->db->insert($this->getGenericFeedbackTableName(), array('feedback_id' => array('integer', $nextId), 'question_fi' => array('integer', $originalQuestionId), 'correctness' => array('text', $row['correctness']), 'feedback' => array('clob', $row['feedback']), 'tstamp' => array('integer', time())));
     }
 }
 /**
  * Update object in database
  */
 public function doUpdate()
 {
     //$this->loadValue(); //Removed Mantis #0011799
     $datatype = $this->field->getDatatype();
     $query = "DELETE FROM il_dcl_stloc" . $datatype->getStorageLocation() . "_value WHERE record_field_id = " . $this->db->quote($this->id, "integer");
     $this->db->manipulate($query);
     $next_id = $this->db->nextId("il_dcl_stloc" . $datatype->getStorageLocation() . "_value");
     // This is a workaround to ensure that date values in stloc3 are never stored as NULL, which is not allowed
     if ($datatype->getStorageLocation() == 3 && (is_null($this->value) || empty($this->value))) {
         $this->value = '0000-00-00 00:00:00';
     }
     $this->db->insert("il_dcl_stloc" . $datatype->getStorageLocation() . "_value", array("value" => array($datatype->getDbType(), $this->value), "record_field_id " => array("integer", $this->id), "id" => array("integer", $next_id)));
 }
예제 #7
0
 /**
  * Create object in database. Also invokes creating of translation objects.
  *
  * @throws ilOrgUnitTypeException
  */
 public function create()
 {
     $default_lang = $this->getDefaultLang();
     $title = $this->getTranslation('title', $default_lang);
     if (!$default_lang || !$title) {
         throw new ilOrgUnitTypeException($this->lng->txt('orgu_type_msg_missing_title_default_language'));
     }
     $this->id = $this->db->nextId(self::TABLE_NAME);
     $this->db->insert(self::TABLE_NAME, array('id' => array('integer', $this->getId()), 'default_lang' => array('text', $this->getDefaultLang()), 'owner' => array('integer', $this->user->getId()), 'icon' => array('text', $this->getIcon()), 'create_date' => array('text', date('Y-m-d H:i:s')), 'last_update' => array('text', date('Y-m-d H:i:s'))));
     // Create translation(s)
     /** @var $trans ilOrgUnitTypeTranslation */
     foreach ($this->translations as $lang => $trans) {
         $trans->setOrguTypeId($this->getId());
         $trans->create();
     }
 }
 private function storeQuestion(ilTestSession $testSession, ilTestRandomQuestionSetQuestion $setQuestion)
 {
     $nextId = $this->db->nextId('tst_test_rnd_qst');
     $this->db->insert('tst_test_rnd_qst', array('test_random_question_id' => array('integer', $nextId), 'active_fi' => array('integer', $testSession->getActiveId()), 'question_fi' => array('integer', $setQuestion->getQuestionId()), 'sequence' => array('integer', $setQuestion->getSequencePosition()), 'pass' => array('integer', $testSession->getPass()), 'tstamp' => array('integer', time()), 'src_pool_def_fi' => array('integer', $setQuestion->getSourcePoolDefinitionId())));
 }
 /**
  * @param $testId
  */
 private function insertDbRecord($testId)
 {
     $nextId = $this->db->nextId('tst_rnd_quest_set_qpls');
     $this->db->insert('tst_rnd_quest_set_qpls', array('def_id' => array('integer', $nextId), 'test_fi' => array('integer', $testId), 'pool_fi' => array('integer', $this->getPoolId()), 'pool_title' => array('text', $this->getPoolTitle()), 'pool_path' => array('text', $this->getPoolPath()), 'pool_quest_count' => array('integer', $this->getPoolQuestionCount()), 'origin_tax_fi' => array('integer', $this->getOriginalFilterTaxId()), 'origin_node_fi' => array('integer', $this->getOriginalFilterTaxNodeId()), 'mapped_tax_fi' => array('integer', $this->getMappedFilterTaxId()), 'mapped_node_fi' => array('integer', $this->getMappedFilterTaxNodeId()), 'quest_amount' => array('integer', $this->getQuestionAmount()), 'sequence_pos' => array('integer', $this->getSequencePosition())));
     $this->setId($nextId);
 }
 /**
  * @param string          $a_entity
  * @param                 $a_types
  * @param array           $a_rec
  * @param ilImportMapping $a_mapping
  * @param string          $a_schema_version
  */
 public function importRecord($a_entity, $a_types, $a_rec, $a_mapping, $a_schema_version)
 {
     switch ($a_entity) {
         case 'dcl':
             // Calling new_obj->create() will create the main table for us
             $new_obj = new ilObjDataCollection();
             $new_obj->setTitle($a_rec['title']);
             $new_obj->setDescription($a_rec['description']);
             $new_obj->setApproval($a_rec['approval']);
             $new_obj->setPublicNotes($a_rec['public_notes']);
             $new_obj->setNotification($a_rec['notification']);
             $new_obj->setPublicNotes($a_rec['public_notes']);
             $new_obj->setOnline(false);
             $new_obj->setRating($a_rec['rating']);
             $new_obj->create();
             $this->import_dc_object = $new_obj;
             $a_mapping->addMapping('Modules/DataCollection', 'dcl', $a_rec['id'], $new_obj->getId());
             break;
         case 'il_dcl_table':
             // If maintable, update. Other tables must be created as well
             $table = $this->count_imported_tables > 0 ? new ilDataCollectionTable() : ilDataCollectionCache::getTableCache($this->import_dc_object->getMainTableId());
             $table->setTitle($a_rec['title']);
             $table->setObjId($this->import_dc_object->getId());
             $table->setDescription($a_rec['description']);
             $table->setAddPerm($a_rec['add_perm']);
             $table->setEditPerm($a_rec['edit_perm']);
             $table->setDeletePerm($a_rec['delete_perm']);
             $table->setEditByOwner($a_rec['edit_by_owner']);
             $table->setLimited($a_rec['limited']);
             $table->setLimitStart($a_rec['limit_start']);
             $table->setLimitEnd($a_rec['limit_end']);
             $table->setIsVisible($a_rec['is_visible']);
             $table->setExportEnabled($a_rec['export_enabled']);
             $table->setDefaultSortField($a_rec['default_sort_field_id']);
             $table->setDefaultSortFieldOrder($a_rec['default_sort_field_order']);
             $table->setPublicCommentsEnabled($a_rec['public_comments']);
             $table->setViewOwnRecordsPerm($a_rec['view_own_records_perm']);
             if ($this->count_imported_tables > 0) {
                 $table->doCreate(false);
                 // false => Do not create views! They are imported later
             } else {
                 $table->doUpdate();
                 $this->count_imported_tables++;
                 // Delete views from maintable because we want to import them from the xml data
                 $set = $this->db->query('SELECT * FROM il_dcl_view WHERE table_id = ' . $this->db->quote($table->getId(), 'integer'));
                 $view_ids = array();
                 while ($row = $this->db->fetchObject($set)) {
                     $view_ids[] = $row->id;
                 }
                 if (count($view_ids)) {
                     $this->db->manipulate("DELETE FROM il_dcl_viewdefinition WHERE view_id IN (" . implode(',', $view_ids) . ")");
                 }
                 $this->db->manipulate("DELETE FROM il_dcl_view WHERE table_id = " . $this->db->quote($table->getId(), 'integer'));
             }
             $a_mapping->addMapping('Modules/DataCollection', 'il_dcl_table', $a_rec['id'], $table->getId());
             break;
         case 'il_dcl_field':
             $new_table_id = $a_mapping->getMapping('Modules/DataCollection', 'il_dcl_table', $a_rec['table_id']);
             if ($new_table_id) {
                 $field = new ilDataCollectionField();
                 $field->setTableId($new_table_id);
                 $field->setDatatypeId($a_rec['datatype_id']);
                 $field->setTitle($a_rec['title']);
                 $field->setDescription($a_rec['description']);
                 $field->setRequired($a_rec['required']);
                 $field->setUnique($a_rec['is_unique']);
                 $field->setLocked($a_rec['is_locked']);
                 $field->doCreate();
                 $a_mapping->addMapping('Modules/DataCollection', 'il_dcl_field', $a_rec['id'], $field->getId());
                 // Check if this field was used as default order by, if so, update to new id
                 $table = ilDataCollectionCache::getTableCache($new_table_id);
                 if ($table && $table->getDefaultSortField() == $a_rec['id']) {
                     $table->setDefaultSortField($field->getId());
                     $table->doUpdate();
                 }
             }
             break;
         case 'il_dcl_record':
             $new_table_id = $a_mapping->getMapping('Modules/DataCollection', 'il_dcl_table', $a_rec['table_id']);
             if ($new_table_id) {
                 $record = new ilDataCollectionRecord();
                 $record->setTableId($new_table_id);
                 $datetime = new ilDateTime(time(), IL_CAL_UNIX);
                 $record->setCreateDate($datetime);
                 $record->setLastUpdate($datetime);
                 $record->setOwner($this->user->getId());
                 $record->setLastEditBy($this->user->getId());
                 $record->doCreate();
                 $a_mapping->addMapping('Modules/DataCollection', 'il_dcl_record', $a_rec['id'], $record->getId());
             }
             break;
         case 'il_dcl_view':
             $new_table_id = $a_mapping->getMapping('Modules/DataCollection', 'il_dcl_table', $a_rec['table_id']);
             if ($new_table_id) {
                 if ($a_rec['type'] == 0 && $a_rec['formtype'] == 0) {
                     // RecordViewViewDefinition: Create a new RecordViewViewdefinition. Note that the associated Page object is NOT created.
                     // Creation of the Page object is handled by the import of Services/COPage
                     $definition = new ilDataCollectionRecordViewViewdefinition();
                     $definition->setTableId($new_table_id);
                     $definition->create(true);
                     // DO not create DB entries for page object
                     // This mapping is needed for the import handled by Services/COPage
                     $a_mapping->addMapping('Services/COPage', 'pg', 'dclf:' . $a_rec['id'], 'dclf:' . $definition->getId());
                     $a_mapping->addMapping('Modules/DataCollection', 'il_dcl_view', $a_rec['id'], $definition->getId());
                 } else {
                     // Other definitions - grab next ID from il_dcl_view
                     $view_id = $this->db->nextId("il_dcl_view");
                     $sql = "INSERT INTO il_dcl_view (id, table_id, type, formtype) VALUES (" . $this->db->quote($view_id, "integer") . ", " . $this->db->quote($new_table_id, "integer") . ", " . $this->db->quote($a_rec['type'], "integer") . ", " . $this->db->quote($a_rec['formtype'], "integer") . ")";
                     $this->db->manipulate($sql);
                     $a_mapping->addMapping('Modules/DataCollection', 'il_dcl_view', $a_rec['id'], $view_id);
                 }
             }
             break;
         case 'il_dcl_viewdefinition':
             $new_view_id = $a_mapping->getMapping('Modules/DataCollection', 'il_dcl_view', $a_rec['view_id']);
             $new_field_id = $a_mapping->getMapping('Modules/DataCollection', 'il_dcl_field', $a_rec['field']);
             $field = $new_field_id ? $new_field_id : $a_rec['field'];
             if ($new_view_id) {
                 $sql = 'INSERT INTO il_dcl_viewdefinition (view_id, field, field_order, is_set) VALUES (' . $this->db->quote($new_view_id, 'integer') . ', ' . $this->db->quote($field, 'text') . ', ' . $this->db->quote($a_rec['field_order'], 'integer') . ', ' . $this->db->quote($a_rec['is_set'], 'integer') . ')';
                 $this->db->manipulate($sql);
             }
             break;
         case 'il_dcl_field_prop':
             $new_field_id = $a_mapping->getMapping('Modules/DataCollection', 'il_dcl_field', $a_rec['field_id']);
             if ($new_field_id) {
                 $prop = new ilDataCollectionFieldProp();
                 $prop->setFieldId($new_field_id);
                 $prop->setDatatypePropertyId($a_rec['datatype_prop_id']);
                 // For field references, we need to get the new field id of the referenced field
                 // If the field_id does not yet exist (e.g. referenced table not yet created), store temp info and fix before finishing import
                 $value = $a_rec['value'];
                 $refs = array(ilDataCollectionField::PROPERTYID_REFERENCE, ilDataCollectionField::PROPERTYID_N_REFERENCE);
                 $fix_refs = false;
                 if (in_array($prop->getDatatypePropertyId(), $refs)) {
                     $new_field_id = $a_mapping->getMapping('Modules/DataCollection', 'il_dcl_field', $a_rec['value']);
                     if ($new_field_id === false) {
                         $value = NULL;
                         $fix_refs = true;
                     }
                 }
                 $prop->setValue($value);
                 $prop->doCreate();
                 $a_mapping->addMapping('Modules/DataCollection', 'il_dcl_field_prop', $a_rec['id'], $prop->getId());
                 if ($fix_refs) {
                     $this->import_temp_refs_props[$prop->getId()] = $a_rec['value'];
                 }
             }
             break;
         case 'il_dcl_record_field':
             $record_id = $a_mapping->getMapping('Modules/DataCollection', 'il_dcl_record', $a_rec['record_id']);
             $field_id = $a_mapping->getMapping('Modules/DataCollection', 'il_dcl_field', $a_rec['field_id']);
             if ($record_id && $field_id) {
                 $record = ilDataCollectionCache::getRecordCache($record_id);
                 $field = ilDataCollectionCache::getFieldCache($field_id);
                 $record_field = new ilDataCollectionRecordField($record, $field);
                 // Created in constructor if not existing
                 $a_mapping->addMapping('Modules/DataCollection', 'il_dcl_record_field', $a_rec['id'], $record_field->getId());
                 $this->import_record_field_cache[$record_field->getId()] = $record_field;
             }
             break;
         case 'il_dcl_stloc1_value':
         case 'il_dcl_stloc2_value':
         case 'il_dcl_stloc3_value':
             $new_record_field_id = $a_mapping->getMapping('Modules/DataCollection', 'il_dcl_record_field', $a_rec['record_field_id']);
             if ($new_record_field_id) {
                 /** @var ilDataCollectionRecordField $record_field */
                 $record_field = $this->import_record_field_cache[$new_record_field_id];
                 if (is_object($record_field)) {
                     // Need to rewrite internal references and lookup new objects if MOB or File
                     // For some fieldtypes it's better to reset the value, e.g. ILIAS_REF
                     switch ($record_field->getField()->getDatatypeId()) {
                         case ilDataCollectionDatatype::INPUTFORMAT_MOB:
                             // Check if we got a mapping from old object
                             $new_mob_id = $a_mapping->getMapping('Services/MediaObjects', 'mob', $a_rec['value']);
                             $value = $new_mob_id ? (int) $new_mob_id : NULL;
                             $this->import_temp_new_mob_ids[] = $new_mob_id;
                             break;
                         case ilDataCollectionDatatype::INPUTFORMAT_FILE:
                             $new_file_id = $a_mapping->getMapping('Modules/File', 'file', $a_rec['value']);
                             $value = $new_file_id ? (int) $new_file_id : NULL;
                             break;
                         case ilDataCollectionDatatype::INPUTFORMAT_REFERENCE:
                         case ilDataCollectioNDatatype::INPUTFORMAT_REFERENCELIST:
                             // If we are referencing to a record from a table that is not yet created, return value is always false because the record does exist neither
                             // Solution: Temporary store all references and fix them before finishing the import.
                             $new_record_id = $a_mapping->getMapping('Modules/DataCollection', 'il_dcl_record', $a_rec['value']);
                             if ($new_record_id === false) {
                                 $this->import_temp_refs[$new_record_field_id] = $a_rec['value'];
                             }
                             $value = $new_record_id ? (int) $new_record_id : NULL;
                             break;
                         case ilDataCollectionDatatype::INPUTFORMAT_ILIAS_REF:
                             $value = NULL;
                             break;
                         default:
                             $value = $a_rec['value'];
                             if ($a_entity == 'il_dcl_stloc3_value' && (is_null($value) || empty($value))) {
                                 $value = '0000-00-00 00:00:00';
                             }
                     }
                     $record_field->setValue($value, true);
                     $record_field->doUpdate();
                 }
             }
             break;
     }
 }