/** * Attention only use this for objects who have not yet been created (use like: $x = new ilObjDataCollection; $x->cloneStructure($id)) * @param $original_id The original ID of the dataselection you want to clone it's structure */ public function cloneStructure($original_id) { $original = new ilObjDataCollection($original_id); $this->setApproval($original->getApproval()); $this->setNotification($original->getNotification()); $this->setOnline($original->getOnline()); $this->setPublicNotes($original->getPublicNotes()); $this->setRating($original->getRating()); //delete old tables. foreach ($this->getTables() as $table) { $table->doDelete(true); } //add new tables. foreach ($original->getTables() as $table) { $new_table = ilDataCollectionCache::getTableCache(); $new_table->setObjId($this->getId()); $new_table->cloneStructure($table->getId()); if ($table->getId() == $original->getMainTableId()) { $this->setMainTableId($new_table->getId()); } } // update because maintable id is now set. $this->doUpdate(); }
/** * Attention only use this for objects who have not yet been created (use like: $x = new ilObjDataCollection; $x->cloneStructure($id)) * * @param $original_id The original ID of the dataselection you want to clone it's structure */ public function cloneStructure($original_id) { $original = new ilObjDataCollection($original_id); $this->setApproval($original->getApproval()); $this->setNotification($original->getNotification()); $this->setPublicNotes($original->getPublicNotes()); $this->setRating($original->getRating()); // delete old tables. foreach ($this->getTables() as $table) { $table->doDelete(true); } // add new tables. foreach ($original->getTables() as $table) { $new_table = new ilDataCollectionTable(); $new_table->setObjId($this->getId()); $new_table->cloneStructure($table); if ($table->getId() == $original->getMainTableId()) { $this->setMainTableId($new_table->getId()); } } // update because maintable id is now set. $this->doUpdate(); // Set new field-ID of referenced fields foreach ($original->getTables() as $origTable) { foreach ($origTable->getRecordFields() as $origField) { if ($origField->getDatatypeId() == ilDataCollectionDatatype::INPUTFORMAT_REFERENCE) { $newRefId = NULL; $origFieldRefObj = ilDataCollectionCache::getFieldCache($origField->getFieldRef()); $origRefTable = ilDataCollectionCache::getTableCache($origFieldRefObj->getTableId()); // Lookup the new ID of the referenced field in the actual DC $tableId = ilDataCollectionTable::_getTableIdByTitle($origRefTable->getTitle(), $this->getId()); $fieldId = ilDataCollectionField::_getFieldIdByTitle($origFieldRefObj->getTitle(), $tableId); $field = ilDataCollectionCache::getFieldCache($fieldId); $newRefId = $field->getId(); // Set the new refID in the actual DC $tableId = ilDataCollectionTable::_getTableIdByTitle($origTable->getTitle(), $this->getId()); $fieldId = ilDataCollectionField::_getFieldIdByTitle($origField->getTitle(), $tableId); $field = ilDataCollectionCache::getFieldCache($fieldId); $field->setPropertyvalue($newRefId, ilDataCollectionField::PROPERTYID_REFERENCE); $field->doUpdate(); } } } }
/** * Build data array, data is read from cache except dcl object itself * * @param $a_entity * @param $a_ids */ protected function _readData($a_entity, $a_ids) { switch ($a_entity) { case 'dcl': foreach ($a_ids as $dcl_id) { if (ilObject::_lookupType($dcl_id) == 'dcl') { $obj = new ilObjDataCollection($dcl_id, false); $data = array('id' => $dcl_id, 'title' => $obj->getTitle(), 'description' => $obj->getDescription(), 'main_table_id' => $obj->getMainTableId(), 'is_online' => $obj->getOnline(), 'rating' => $obj->getRating(), 'public_notes' => $obj->getPublicNotes(), 'approval' => $obj->getApproval(), 'notification' => $obj->getNotification()); $this->caches['dcl'][$dcl_id] = $data; $this->data[] = $data; } } break; default: $data = $this->getCache($a_entity); foreach ($a_ids as $id) { $this->data[] = $data[$id]; } } }