/** * save Record * * @param string $a_mode values: create | edit */ public function save() { global $tpl, $ilUser, $lng, $ilCtrl; $this->initForm(); if ($this->form->checkInput()) { $record_obj = ilDataCollectionCache::getRecordCache($this->record_id); $date_obj = new ilDateTime(time(), IL_CAL_UNIX); $record_obj->setTableId($this->table_id); $record_obj->setLastUpdate($date_obj->get(IL_CAL_DATETIME)); $record_obj->setLastEditBy($ilUser->getId()); $create_mode = false; if (ilObjDataCollection::_hasWriteAccess($this->parent_obj->ref_id)) { $all_fields = $this->table->getRecordFields(); } else { $all_fields = $this->table->getEditableFields(); } $fail = ""; //Check if we can create this record. foreach ($all_fields as $field) { try { $value = $this->form->getInput("field_" . $field->getId()); $field->checkValidity($value, $this->record_id); } catch (ilDataCollectionInputException $e) { $fail .= $field->getTitle() . ": " . $e . "<br>"; } } if ($fail) { ilUtil::sendFailure($fail, true); $this->sendFailure(); return; } if (!isset($this->record_id)) { if (!$this->table->hasPermissionToAddRecord($this->parent_obj->ref_id)) { $this->accessDenied(); return; } $record_obj->setOwner($ilUser->getId()); $record_obj->setCreateDate($date_obj->get(IL_CAL_DATETIME)); $record_obj->setTableId($this->table_id); $record_obj->doCreate(); $this->record_id = $record_obj->getId(); $create_mode = true; } else { if (!$record_obj->hasPermissionToEdit($this->parent_obj->ref_id)) { $this->accessDenied(); return; } } //edit values, they are valid we already checked them above foreach ($all_fields as $field) { $value = $this->form->getInput("field_" . $field->getId()); //deletion flag on MOB inputs. if ($field->getDatatypeId() == ilDataCollectionDatatype::INPUTFORMAT_MOB && $this->form->getItemByPostVar("field_" . $field->getId())->getDeletionFlag()) { $value = -1; } $record_obj->setRecordFieldValue($field->getId(), $value); } // Do we need to set a new owner for this record? if (!$create_mode) { $owner_id = ilObjUser::_lookupId($_POST['field_owner']); if (!$owner_id) { ilUtil::sendFailure($lng->txt('user_not_known')); $this->sendFailure(); return; } $record_obj->setOwner($owner_id); } if ($create_mode) { ilObjDataCollection::sendNotification("new_record", $this->table_id, $record_obj->getId()); } $record_obj->doUpdate(); ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true); $ilCtrl->setParameter($this, "table_id", $this->table_id); $ilCtrl->setParameter($this, "record_id", $this->record_id); $ilCtrl->redirectByClass("ildatacollectionrecordlistgui", "listRecords"); } else { global $tpl; $this->form->setValuesByPost(); $tpl->setContent($this->form->getHTML()); } }
public function doDelete() { global $ilDB; $this->loadRecordFields(); foreach ($this->recordfields as $recordfield) { if ($recordfield->getField()->getDatatypeId() == ilDataCollectionDatatype::INPUTFORMAT_FILE) { $this->deleteFile($recordfield->getValue()); } if ($recordfield->getField()->getDatatypeId() == ilDataCollectionDatatype::INPUTFORMAT_MOB) { $this->deleteMob($recordfield->getValue()); } $recordfield->delete(); } $query = "DELETE FROM il_dcl_record WHERE id = " . $ilDB->quote($this->getId(), "integer"); $ilDB->manipulate($query); include_once "./Modules/DataCollection/classes/class.ilObjDataCollection.php"; ilObjDataCollection::sendNotification("delete_record", $this->getTableId(), $this->getId()); }