/** * Get all comments of this record * * @return array ilNote[] */ public function getComments() { if ($this->comments === null) { $this->comments = ilNote::_getNotesOfObject($this->table->getCollectionObject()->getId(), $this->getId(), 'dcl', IL_NOTE_PUBLIC); } return $this->comments; }
public function __construct(ilDataCollectionRecordListGUI $a_parent_obj, $a_parent_cmd, ilDataCollectionTable $table) { global $lng, $tpl, $ilCtrl; $this->setPrefix("dcl_record_list"); $this->setFormName('record_list'); $this->setId("dcl_record_list"); parent::__construct($a_parent_obj, $a_parent_cmd); $this->table = $table; include_once "class.ilDataCollectionDatatype.php"; $this->parent_obj = $a_parent_obj; $this->setRowTemplate("tpl.record_list_row.html", "Modules/DataCollection"); $this->addColumn("", "_front", "15px"); $this->numeric_fields = array(); foreach ($this->table->getVisibleFields() as $field) { $title = $field->getTitle(); $sort_field = $title; if ($field->getDatatypeId() == ilDataCollectionDatatype::INPUTFORMAT_DATETIME) { $sort_field = $title . self::DATETIME_SORTING_STR; } $this->addColumn($title, $sort_field); if ($field->getLearningProgress()) { $this->addColumn($lng->txt("dcl_status"), "_status_" . $field->getTitle()); } if ($field->getDatatypeId() == ilDataCollectionDatatype::INPUTFORMAT_NUMBER) { $this->numeric_fields[] = $field->getTitle(); } } $this->setId("dcl_record_list"); $this->addColumn($lng->txt("actions"), "", "30px"); //$ilCtrl->saveParameterByClass("ildatacollectionrecordlistgui", "dcl_record_list_trows"); $this->setTopCommands(true); $this->setEnableHeader(true); $this->setShowRowsSelector(true); $this->setShowTemplates(true); $this->setEnableHeader(true); $this->setEnableTitle(true); $this->setDefaultOrderDirection("asc"); $this->setFormAction($ilCtrl->getFormAction($a_parent_obj, "applyFilter")); $this->initFilter(); $this->object_data = $table->getRecordsByFilter($this->filter); $this->buildData(); // $this->setData($table->getRecordsByFilter($this->filter)); //leave these two $this->setExternalSegmentation(false); // $this->setExternalSorting(true); }
public function passThroughFilter(array $filter) { $pass = true; $this->loadTable(); foreach ($this->table->getFields() as $field) { if (!ilDataCollectionDatatype::passThroughFilter($this, $field, $filter["filter_" . $field->getId()])) { $pass = false; } } return $pass; }
public function delete() { $mainTableId = $this->table->getCollectionObject()->getMainTableId(); if ($mainTableId == $this->table->getId()) { ilUtil::sendFailure($this->lng->txt("dcl_cant_delete_main_table"), true); } else { $this->ctrl->setParameterByClass("ildatacollectionfieldlistgui", "table_id", $mainTableId); } $this->table->doDelete(); $this->ctrl->redirectByClass("ildatacollectionfieldlistgui", "listFields"); }
/** * Add subtabs * */ protected function setSubTabs() { global $ilTabs, $lng, $ilCtrl; /** @var ilCtrl $ilCtrl */ /** @var ilTabsGUI $ilTabs */ $ilTabs->addSubTab('mode_1', $lng->txt('view'), $ilCtrl->getLinkTarget($this, 'listRecords')); if ($this->table_obj->hasPermissionToDeleteRecords((int) $_GET['ref_id'])) { $ilCtrl->setParameter($this, 'mode', self::MODE_MANAGE); $ilTabs->addSubTab('mode_2', $lng->txt('dcl_manage'), $ilCtrl->getLinkTarget($this, 'listRecords')); $ilCtrl->clearParameters($this); } $ilTabs->setSubTabActive('mode_' . $this->mode); }
public function initFilter() { foreach ($this->table->getFilterableFields() as $field) { $input = ilDataCollectionDatatype::addFilterInputFieldToTable($field, $this); $input->readFromSession(); $value = $input->getValue(); if (is_array($value)) { if ($value['from'] || $value['to']) { $this->filter["filter_" . $field->getId()] = $value; } } else { if ($value != '') { $this->filter["filter_" . $field->getId()] = $value; } } } }
/** * initRecordListViewdefinitionForm * */ public function initForm() { global $lng, $ilCtrl, $ilToolbar; // Show tables require_once "./Modules/DataCollection/classes/class.ilDataCollectionTable.php"; $arrTables = ilDataCollectionTable::getAll($this->obj_id); foreach ($arrTables as $table) { $options[$table['id']] = $table['title']; } include_once './Services/Form/classes/class.ilSelectInputGUI.php'; $table_selection = new ilSelectInputGUI('', 'table_id'); $table_selection->setOptions($options); $table_selection->setValue($this->table_id); $ilToolbar->setFormAction($ilCtrl->getFormActionByClass("ilDataCollectionRecordListViewdefinitionGUI", "doTableSwitch")); $ilToolbar->addInputItem($table_selection); $ilToolbar->addFormButton($lng->txt('change'), 'doTableSwitch'); // Form require_once "./Services/Form/classes/class.ilPropertyFormGUI.php"; $this->form = new ilPropertyFormGUI(); $this->form->setFormAction($ilCtrl->getFormAction($this), "save"); $this->form->addCommandButton('save', $lng->txt('dcl_listviewdefinition_update')); $this->form->addCommandButton('cancel', $lng->txt('cancel')); //Table-ID $hidden_prop = new ilHiddenInputGUI("table_id"); $hidden_prop->setValue($this->table_id); $this->form->addItem($hidden_prop); //Get fields require_once "./Modules/DataCollection/classes/class.ilDataCollectionField.php"; $fields = ilDataCollectionField::getAll($this->table_id); $tabledefinition = array("id" => array("title" => $lng->txt("id")), "table_id" => array("title" => $lng->txt("dcl_table_id")), "create_date" => array("title" => $lng->txt("create_date")), "last_update" => array("title" => $lng->txt("last_update")), "owner" => array("title" => $lng->txt("owner"))); //Array zusammenführen foreach ($fields as $key => $value) { $tabledefinition[$key] = $value; } foreach ($tabledefinition as $key => $field) { $chk_prop = new ilCheckboxInputGUI($field['title'], 'visible_' . $key); $chk_prop->setOptionTitle($lng->txt('visible')); $text_prop = new ilTextInputGUI($lng->txt('dcl_field_ordering'), 'order_' . $key); $chk_prop->addSubItem($text_prop); $this->form->addItem($chk_prop); } $this->form->setTitle($lng->txt('dcl_view_viewdefinition')); }
/** * @param bool $editComments */ public function renderRecord($editComments = false) { global $ilTabs, $tpl, $ilCtrl, $lng; $rctpl = new ilTemplate("tpl.record_view.html", false, true, "Modules/DataCollection"); $ilTabs->setTabActive("id_content"); $view_id = self::_getViewDefinitionId($this->record_obj); if (!$view_id) { $ilCtrl->redirectByClass("ildatacollectionrecordlistgui", "listRecords"); } // see ilObjDataCollectionGUI->executeCommand about instantiation include_once "./Modules/DataCollection/classes/class.ilDataCollectionRecordViewViewdefinitionGUI.php"; $pageObj = new ilDataCollectionRecordViewViewdefinitionGUI($this->record_obj->getTableId(), $view_id); include_once "./Services/Style/classes/class.ilObjStyleSheet.php"; $pageObj->setStyleId(ilObjStyleSheet::getEffectiveContentStyleId(0, "dcl")); $html = $pageObj->getHTML(); $rctpl->addCss("./Services/COPage/css/content.css"); $rctpl->fillCssFiles(); $table = ilDataCollectionCache::getTableCache($this->record_obj->getTableId()); foreach ($table->getRecordFields() as $field) { //ILIAS_Ref_Links $pattern = '/\\[dcliln field="' . preg_quote($field->getTitle(), "/") . '"\\](.*?)\\[\\/dcliln\\]/'; if (preg_match($pattern, $html)) { $html = preg_replace($pattern, $this->record_obj->getRecordFieldSingleHTML($field->getId(), $this->setOptions("\$1")), $html); } //DataCollection Ref Links $pattern = '/\\[dclrefln field="' . preg_quote($field->getTitle(), "/") . '"\\](.*?)\\[\\/dclrefln\\]/'; if (preg_match($pattern, $html)) { $this->currentField = $field; $html = preg_replace_callback($pattern, array($this, "doReplace"), $html); } $pattern = '/\\[ext tableOf="' . preg_quote($field->getTitle(), "/") . '" field="(.*?)"\\]/'; if (preg_match($pattern, $html)) { $this->currentField = $field; $html = preg_replace_callback($pattern, array($this, "doExtReplace"), $html); } $html = str_ireplace("[" . $field->getTitle() . "]", $this->record_obj->getRecordFieldSingleHTML($field->getId()), $html); } foreach ($table->getStandardFields() as $field) { $html = str_ireplace("[" . $field->getId() . "]", $this->record_obj->getRecordFieldSingleHTML($field->getId()), $html); } $rctpl->setVariable("CONTENT", $html); //Permanent Link $perma_link = new ilPermanentLinkGUI("dcl", $_GET["ref_id"], "_" . $_GET['record_id']); $tpl->setVariable('PRMLINK', $perma_link->getHTML()); // Buttons for previous/next records if ($this->is_enabled_paging) { $prevNextLinks = $this->renderPrevNextLinks(); $rctpl->setVariable('PREV_NEXT_RECORD_LINKS', $prevNextLinks); $ilCtrl->clearParameters($this); // #14083 $rctpl->setVariable('FORM_ACTION', $ilCtrl->getFormAction($this)); $rctpl->setVariable('RECORD', $lng->txt('dcl_record')); $rctpl->setVariable('RECORD_FROM_TOTAL', sprintf($lng->txt('dcl_record_from_total'), $this->current_record_position, count($this->record_ids))); $rctpl->setVariable('SELECT_OPTIONS', $this->renderSelectOptions()); } // Edit Button if ($this->record_obj->hasPermissionToEdit((int) $_GET['ref_id'])) { $button = ilLinkButton::getInstance(); $ilCtrl->setParameterByClass('ildatacollectionrecordeditgui', 'table_id', $this->table->getId()); $ilCtrl->setParameterByClass('ildatacollectionrecordeditgui', 'redirect', ilDataCollectionRecordEditGUI::REDIRECT_DETAIL); $ilCtrl->saveParameterByClass('ildatacollectionrecordeditgui', 'record_id'); $button->setUrl($ilCtrl->getLinkTargetByClass('ildatacollectionrecordeditgui', 'edit')); $button->setCaption($lng->txt('dcl_edit_record'), false); $rctpl->setVariable('EDIT_RECORD_BUTTON', $button->render()); } // Comments if ($this->table->getPublicCommentsEnabled()) { $rctpl->setVariable('COMMENTS', $this->renderComments($editComments)); } $tpl->setContent($rctpl->get()); }
/** * Create new field */ public function doCreate() { global $ilDB; $this->getLocked() == NULL ? $this->setLocked(false) : true; if (!ilDataCollectionTable::_tableExists($this->getTableId())) { throw new ilException("The field does not have a related table!"); } $id = $ilDB->nextId("il_dcl_field"); $this->setId($id); $query = "INSERT INTO il_dcl_field (" . "id" . ", table_id" . ", datatype_id" . ", title" . ", description" . ", required" . ", is_unique" . ", is_locked" . " ) VALUES (" . $ilDB->quote($this->getId(), "integer") . "," . $ilDB->quote($this->getTableId(), "integer") . "," . $ilDB->quote($this->getDatatypeId(), "integer") . "," . $ilDB->quote($this->getTitle(), "text") . "," . $ilDB->quote($this->getDescription(), "text") . "," . $ilDB->quote($this->getRequired(), "integer") . "," . $ilDB->quote($this->isUnique(), "integer") . "," . $ilDB->quote($this->getLocked() ? 1 : 0, "integer") . ")"; $ilDB->manipulate($query); $this->updateVisibility(); $this->updateFilterability(); $this->updateEditability(); }
/** * 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(); } } } }
/** * Save record */ public function save() { $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($this->user->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) { $this->sendFailure($fail); return; } if (!isset($this->record_id)) { if (!$this->table->hasPermissionToAddRecord($this->parent_obj->ref_id)) { $this->accessDenied(); return; } $record_obj->setOwner($this->user->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) { $this->sendFailure($this->lng->txt('user_not_known')); return; } $record_obj->setOwner($owner_id); } if ($create_mode) { ilObjDataCollection::sendNotification("new_record", $this->table_id, $record_obj->getId()); } $record_obj->doUpdate(); $this->ctrl->setParameter($this, "table_id", $this->table_id); $this->ctrl->setParameter($this, "record_id", $this->record_id); if (!$this->ctrl->isAsynch()) { ilUtil::sendSuccess($this->lng->txt("msg_obj_modified"), true); } $this->checkAndPerformRedirect(); if ($this->ctrl->isAsynch()) { // If ajax request, return the form in edit mode again $this->record_id = $record_obj->getId(); $this->initForm(); $this->setFormValues(); echo $this->tpl->getMessageHTML($this->lng->txt('msg_obj_modified'), 'success') . $this->form->getHTML(); exit; } else { $this->ctrl->redirectByClass("ildatacollectionrecordlistgui", "listRecords"); } } else { // Form not valid... $this->form->setValuesByPost(); if ($this->ctrl->isAsynch()) { echo $this->form->getHTML(); exit; } else { $this->tpl->setContent($this->form->getHTML()); } } }
/** * Check input of form * @param $a_mode 'create' | 'update' * @return bool */ protected function checkInput($a_mode) { global $lng; $return = $this->form->checkInput(); // Additional check for text fields: The length property should be max 200 if the textarea option is not set if ($this->form->getInput('datatype') == ilDataCollectionDatatype::INPUTFORMAT_TEXT && (int) $this->form->getInput('prop_' . ilDataCollectionField::PROPERTYID_LENGTH) > 200 && !$this->form->getInput('prop_' . ilDataCollectionField::PROPERTYID_TEXTAREA)) { $inputObj = $this->form->getItemByPostVar('prop_' . ilDataCollectionField::PROPERTYID_LENGTH); $inputObj->setAlert($lng->txt("form_msg_value_too_high")); $return = false; } // Don't allow multiple fields with the same title in this table if ($a_mode == 'create') { if ($title = $this->form->getInput('title')) { if (ilDataCollectionTable::_hasFieldByTitle($title, $this->table_id)) { $inputObj = $this->form->getItemByPostVar('title'); $inputObj->setAlert($lng->txt("dcl_field_title_unique")); $return = false; } } } if (!$return) { ilUtil::sendFailure($lng->txt("form_input_not_valid")); } return $return; }
/** * @param ilDataCollectionTable $original */ public function cloneStructure(ilDataCollectionTable $original) { $this->setTitle($original->getTitle()); $this->setDescription($original->getDescription()); $this->setIsVisible($original->getIsVisible()); $this->setEditByOwner($original->getEditByOwner()); $this->setAddPerm($original->getAddPerm()); $this->setEditPerm($original->getEditPerm()); $this->setDeletePerm($original->getDeletePerm()); $this->setLimited($original->getLimited()); $this->setLimitStart($original->getLimitStart()); $this->setLimitEnd($original->getLimitEnd()); $this->setViewOwnRecordsPerm($original->getViewOwnRecordsPerm()); $this->setExportEnabled($original->getExportEnabled()); $this->setPublicCommentsEnabled($original->getPublicCommentsEnabled()); $this->setDefaultSortFieldOrder($original->getDefaultSortFieldOrder()); $this->doCreate(); // reset stdFields to get new for the created object $default_sort_field = 0; // Clone standard-fields $org_std_fields = $original->getStandardFields(); foreach ($this->getStandardFields() as $element_key => $std_field) { $std_field->cloneStructure($org_std_fields[$element_key]); if ($std_field->getId() == $original->getDefaultSortField()) { $default_sort_field = $std_field->getId(); } } // Clone fields $new_fields = array(); foreach ($original->getFields() as $orig_field) { if (!$orig_field->isStandardField()) { $new_field = new ilDataCollectionField(); $new_field->setTableId($this->getId()); $new_field->cloneStructure($orig_field->getId()); $new_fields[$orig_field->getId()] = $new_field; if ($orig_field->getId() == $original->getDefaultSortField()) { $default_sort_field = $new_field->getId(); } } } $this->setDefaultSortField($default_sort_field); $this->doUpdate(); //TODO: Find better way to copy data (include referenced data) // Clone Records with recordfields /*foreach($original->getRecords() as $orig_record){ $new_record = new ilDataCollectionRecord(); $new_record->setTableId($this->getId()); $new_record->cloneStructure($orig_record->getId(), $new_fields); }*/ if ($old_view_id = ilDataCollectionRecordViewViewdefinition::getIdByTableId($original->getId())) { $old_view = new ilDataCollectionRecordViewViewdefinition($old_view_id); $old_view->setTableId($original->getId()); $viewdef = new ilDataCollectionRecordViewViewdefinition(); $viewdef->setTableId($this->id); $viewdef->setXMLContent($old_view->getXMLContent(false)); $viewdef->create(); } }