public function __construct(ilDataCollectionRecord $record, ilDataCollectionField $field) { parent::__construct($record, $field); $dclTable = ilDataCollectionCache::getTableCache($this->getField()->getTableId()); $this->dcl_obj_id = $dclTable->getCollectionObject()->getId(); $this->properties = $field->getProperties(); }
public function save() { global $lng; $table = ilDataCollectionCache::getTableCache($_GET['table_id']); $fields =& $table->getFields(); foreach ($fields as &$field) { $field->setVisible($_POST['visible'][$field->getId()] == "on"); $field->setEditable($_POST['editable'][$field->getId()] == "on"); $field->setFilterable($_POST['filterable'][$field->getId()] == "on"); $field->setLocked($_POST['locked'][$field->getId()] == "on"); $field->setOrder($_POST['order'][$field->getId()]); $field->doUpdate(); } $table->buildOrderFields(); ilUtil::sendSuccess($lng->txt("dcl_table_settings_saved")); $this->listFields(); }
public function __construct(ilDataCollectionFieldListGUI $a_parent_obj, $a_parent_cmd, $table_id) { global $lng, $tpl, $ilCtrl; parent::__construct($a_parent_obj, $a_parent_cmd); $this->parent_obj = $a_parent_obj; $this->setId("dcl_field_list"); $this->addColumn($lng->txt("dcl_order"), null, "30px"); $this->addColumn($lng->txt("dcl_title"), null, "auto"); $this->addColumn($lng->txt("dcl_visible"), null, "30px"); $this->addColumn($lng->txt("dcl_filter"), null, "30px"); $this->addColumn($lng->txt("dcl_locked"), null, "30px"); // ALWAYS EDITABLE FOR FIRST RELEASE //$this->addColumn($lng->txt("dcl_editable"), "editable", "30px"); $this->addColumn($lng->txt("dcl_description"), null, "auto"); $this->addColumn($lng->txt("dcl_field_datatype"), null, "auto"); $this->addColumn($lng->txt("dcl_required"), null, "auto"); $this->addColumn($lng->txt("dcl_unique"), null, "auto"); $this->addColumn($lng->txt("actions"), null, "30px"); $ilCtrl->setParameterByClass("ildatacollectionfieldeditgui", "table_id", $this->parent_obj->table_id); $ilCtrl->setParameterByClass("ildatacollectionfieldlistgui", "table_id", $this->parent_obj->table_id); // $img = " <img src='".ilUtil::getImagePath("cmd_add_s.png")."' /> "; // Wirklich hässlich, doch leider wird der Text, der addHeaderCommand mitgeben wird, nicht mehr angezeigt, sobald man ein Bild mitsendet... // // $this->addHeaderCommand(.$img); $this->setFormAction($ilCtrl->getFormActionByClass("ildatacollectionfieldlistgui")); $this->addCommandButton("save", $lng->txt("dcl_save")); $this->setFormAction($ilCtrl->getFormAction($a_parent_obj)); $this->setFormName('field_list'); //those two are important as we get our data as objects not as arrays. $this->setExternalSegmentation(true); $this->setExternalSorting(true); $this->setTopCommands(true); $this->setEnableHeader(true); $this->setShowRowsSelector(false); $this->setShowTemplates(false); $this->setEnableHeader(true); $this->setEnableTitle(true); $this->setDefaultOrderDirection("asc"); $this->table = ilDataCollectionCache::getTableCache($table_id); $this->setData($this->table->getFields()); require_once './Modules/DataCollection/classes/class.ilDataCollectionDatatype.php'; //wird dies benötigt? $this->setTitle($lng->txt("dcl_table_list_fields")); $this->setRowTemplate("tpl.field_list_row.html", "Modules/DataCollection"); }
public function __construct(ilDataCollectionFieldListGUI $a_parent_obj, $a_parent_cmd, $table_id) { global $lng, $tpl, $ilCtrl; parent::__construct($a_parent_obj, $a_parent_cmd); $this->parent_obj = $a_parent_obj; $this->setId("dcl_field_list"); $this->addColumn($lng->txt("dcl_order"), null, "30px"); $this->addColumn($lng->txt("dcl_title"), null, "auto"); $this->addColumn($lng->txt("dcl_visible"), null, "30px"); $this->addColumn($lng->txt("dcl_filter"), null, "30px"); $this->addColumn($lng->txt("dcl_locked"), null, "30px"); $this->addColumn($lng->txt("dcl_in_export"), null, "30px"); $this->addColumn($lng->txt("dcl_description"), null, "auto"); $this->addColumn($lng->txt("dcl_field_datatype"), null, "auto"); $this->addColumn($lng->txt("dcl_required"), null, "auto"); $this->addColumn($lng->txt("dcl_unique"), null, "auto"); $this->addColumn($lng->txt("actions"), null, "30px"); $ilCtrl->setParameterByClass("ildatacollectionfieldeditgui", "table_id", $this->parent_obj->table_id); $ilCtrl->setParameterByClass("ildatacollectionfieldlistgui", "table_id", $this->parent_obj->table_id); $this->setFormAction($ilCtrl->getFormActionByClass("ildatacollectionfieldlistgui")); $this->addCommandButton("save", $lng->txt("dcl_save")); $this->setFormAction($ilCtrl->getFormAction($a_parent_obj)); $this->setFormName('field_list'); //those two are important as we get our data as objects not as arrays. $this->setExternalSegmentation(true); $this->setExternalSorting(true); $this->setTopCommands(true); $this->setEnableHeader(true); $this->setShowRowsSelector(false); $this->setShowTemplates(false); $this->setEnableHeader(true); $this->setEnableTitle(true); $this->setDefaultOrderDirection("asc"); $this->table = ilDataCollectionCache::getTableCache($table_id); $this->setData($this->table->getFields()); require_once './Modules/DataCollection/classes/class.ilDataCollectionDatatype.php'; //wird dies benötigt? $this->setTitle($lng->txt("dcl_table_list_fields")); $this->setRowTemplate("tpl.field_list_row.html", "Modules/DataCollection"); }
/** * Constructor * * @param object $a_parent_obj * @param int $table_id We need a table_id if no field_id is set (creation mode). We ignore the table_id by edit mode * @param int $field_id The field_id of a existing fiel (edit mode) */ public function __construct(ilObjDataCollectionGUI $a_parent_obj, $table_id, $field_id) { global $ilCtrl; $this->obj_id = $a_parent_obj->obj_id; $this->parent_obj = $a_parent_obj; $this->table_id = $table_id; if (!$table_id) { $table_id = $_GET["table_id"]; } if (!isset($field_id)) { $this->field_id = $_GET['field_id']; } if (isset($field_id)) { $this->field_obj = ilDataCollectionCache::getFieldCache($field_id); } else { $this->field_obj = ilDataCollectionCache::getFieldCache(); if (!$table_id) { $ilCtrl->redirectByClass("ilDataCollectionGUI", "listFields"); } $this->field_obj->setTableId($table_id); $ilCtrl->saveParameter($this, "table_id"); } $this->table = ilDataCollectionCache::getTableCache($table_id); }
private function emptyInfo() { global $lng; $this->table = ilDataCollectionCache::getTableCache($this->object->getMainTableId()); $tables = $this->object->getTables(); if (count($tables) == 1 && count($this->table->getRecordFields()) == 0 && count($this->table->getRecords()) == 0 && $this->object->getOnline()) { ilUtil::sendInfo($lng->txt("dcl_no_content_warning"), true); } }
/** * @param ilDataCollectionField $a_set */ public function fillRow(ilDataCollectionField $a_set) { global $lng, $ilCtrl; if (!$a_set->isStandardField()) { $this->tpl->setVariable('FIELD_ID', $a_set->getId()); } $this->tpl->setVariable('NAME', 'order[' . $a_set->getId() . ']'); $this->tpl->setVariable('VALUE', $this->order); $this->tpl->setVariable('CHECKBOX_VISIBLE', 'visible[' . $a_set->getId() . ']'); if ($a_set->isVisible()) { $this->tpl->setVariable('CHECKBOX_VISIBLE_CHECKED', 'checked'); } /* Don't enable setting filter for MOB fields or reference fields that reference a MOB field */ $show_filter = true; $show_exportable = true; if ($a_set->getDatatypeId() == ilDataCollectionDatatype::INPUTFORMAT_MOB || $a_set->getDatatypeId() == ilDataCollectionDatatype::INPUTFORMAT_FILE) { $show_filter = false; } if ($a_set->getDatatypeId() == ilDataCollectionDatatype::INPUTFORMAT_REFERENCE) { $ref_field = ilDataCollectionCache::getFieldCache((int) $a_set->getFieldRef()); if ($ref_field && ($ref_field->getDatatypeId() == ilDataCollectionDatatype::INPUTFORMAT_MOB || $ref_field->getDatatypeId() == ilDataCollectionDatatype::INPUTFORMAT_FILE)) { $show_filter = false; } } if ($a_set->getId() == 'comments') { $show_filter = false; $show_exportable = false; } if ($show_filter) { $this->tpl->setVariable('CHECKBOX_FILTERABLE', 'filterable[' . $a_set->getId() . ']'); if ($a_set->isFilterable()) { $this->tpl->setVariable('CHECKBOX_FILTERABLE_CHECKED', 'checked'); } } else { $this->tpl->setVariable('NO_FILTER', ''); } if ($show_exportable) { $this->tpl->setVariable('CHECKBOX_EXPORTABLE', 'exportable[' . $a_set->getId() . ']'); if ($a_set->getExportable()) { $this->tpl->setVariable('CHECKBOX_EXPORTABLE_CHECKED', 'checked'); } } else { $this->tpl->setVariable('NO_FILTER_EXPORTABLE', ''); } if (!$a_set->isStandardField()) { $this->tpl->setVariable('CHECKBOX_NAME_LOCKED', 'locked[' . $a_set->getId() . ']'); if ($a_set->getLocked()) { $this->tpl->setVariable('CHECKBOX_CHECKED_LOCKED', 'checked'); } } else { $this->tpl->setVariable('NOT_LOCKED', ''); } $this->order = $this->order + 10; $this->tpl->setVariable('ORDER_NAME', 'order[' . $a_set->getId() . ']'); $this->tpl->setVariable('ORDER_VALUE', $this->order); $this->tpl->setVariable('TITLE', $a_set->getTitle()); $this->tpl->setVariable('DESCRIPTION', $a_set->getDescription()); $this->tpl->setVariable('DATATYPE', $a_set->getDatatypeTitle()); if (!$a_set->isStandardField()) { switch ($a_set->getRequired()) { case 0: $required = ilUtil::getImagePath('icon_not_ok.svg'); break; case 1: $required = ilUtil::getImagePath('icon_ok.svg'); break; } switch ($a_set->isUnique()) { case 0: $uniq = ilUtil::getImagePath('icon_not_ok.svg'); break; case 1: $uniq = ilUtil::getImagePath('icon_ok.svg'); break; } $this->tpl->setVariable('REQUIRED', $required); $this->tpl->setVariable('UNIQUE', $uniq); } else { $this->tpl->setVariable('NO_REQUIRED', ''); $this->tpl->setVariable('NO_UNIQUE', ''); } $ilCtrl->setParameterByClass('ildatacollectionfieldeditgui', 'field_id', $a_set->getId()); if (!$a_set->isStandardField()) { include_once './Services/UIComponent/AdvancedSelectionList/classes/class.ilAdvancedSelectionListGUI.php'; $alist = new ilAdvancedSelectionListGUI(); $alist->setId($a_set->getId()); $alist->setListTitle($lng->txt('actions')); if ($this->table->hasPermissionToFields($this->parent_obj->parent_obj->ref_id)) { $alist->addItem($lng->txt('edit'), 'edit', $ilCtrl->getLinkTargetByClass('ildatacollectionfieldeditgui', 'edit')); $alist->addItem($lng->txt('delete'), 'delete', $ilCtrl->getLinkTargetByClass('ildatacollectionfieldeditgui', 'confirmDelete')); } $this->tpl->setVariable('ACTIONS', $alist->getHTML()); } }
/** * save * * @param string $a_mode values: create | edit */ public function save($a_mode = "create") { global $ilCtrl, $ilTabs, $lng; if (!ilObjDataCollection::_checkAccess($this->obj_id)) { $this->accessDenied(); return; } $ilTabs->activateTab("id_fields"); $this->initForm($a_mode); if ($this->checkInput($a_mode)) { if ($a_mode != "update") { $this->table = ilDataCollectionCache::getTableCache(); } elseif ($this->table_id) { $this->table = ilDataCollectionCache::getTableCache($this->table_id); } else { $ilCtrl->redirectByClass("ildatacollectionfieldeditgui", "listFields"); } $this->table->setTitle($this->form->getInput("title")); $this->table->setObjId($this->obj_id); $this->table->setIsVisible($this->form->getInput("is_visible")); $this->table->setAddPerm($this->form->getInput("add_perm")); $this->table->setEditPerm($this->form->getInput("edit_perm")); $this->table->setDeletePerm($this->form->getInput("delete_perm")); $this->table->setEditByOwner($this->form->getInput("edit_by_owner")); $this->table->setExportEnabled($this->form->getInput("export_enabled")); $this->table->setDescription($this->form->getInput('description')); $this->table->setLimited($this->form->getInput("limited")); $limit_start = $this->form->getInput("limit_start"); $limit_end = $this->form->getInput("limit_end"); $this->table->setLimitStart($limit_start["date"] . " " . $limit_start["time"]); $this->table->setLimitEnd($limit_end["date"] . " " . $limit_end["time"]); if (!$this->table->hasPermissionToAddTable($this->parent_object->ref_id)) { $this->accessDenied(); return; } if ($a_mode == "update") { $this->table->doUpdate(); ilUtil::sendSuccess($lng->txt("dcl_msg_table_edited"), true); $ilCtrl->redirectByClass("ildatacollectiontableeditgui", "edit"); } else { $this->table->doCreate(); ilUtil::sendSuccess($lng->txt("dcl_msg_table_created"), true); $ilCtrl->setParameterByClass("ildatacollectionfieldlistgui", "table_id", $this->table->getId()); $ilCtrl->redirectByClass("ildatacollectionfieldlistgui", "listFields"); } } else { global $tpl; $this->form->setValuesByPost(); $tpl->setContent($this->form->getHTML()); } }
/** * 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()); } }
/** * @return ilDataCollectionTable[] Returns an array of tables of this collection with ids of the tables as keys. */ public function getTables() { global $ilDB; $query = "SELECT id FROM il_dcl_table WHERE obj_id = " . $ilDB->quote($this->getId(), "integer"); $set = $ilDB->query($query); $tables = array(); while ($rec = $ilDB->fetchAssoc($set)) { $tables[$rec['id']] = ilDataCollectionCache::getTableCache($rec['id']); } return $tables; }
public function getExportValue() { if ($this->getValue()) { $ref_rec = ilDataCollectionCache::getRecordCache($this->getValue()); return $ref_rec->getRecordField($this->getField()->getFieldRef())->getExportValue(); } else { return ""; } }
/** * Return only the needed subset of record objects for the table, according to sorting, paging and filters * * @param string $sort Title of a field where the ilTable2GUI is sorted * @param string $direction 'desc' or 'asc' * @param int $limit Limit of records * @param int $offset Offset from records * @param array $filter Containing the filter values * * @return array Array with two keys: 'record' => Contains the record objects, 'total' => Number of total records (without slicing) */ public function getPartialRecords($sort, $direction, $limit, $offset, array $filter = array()) { global $ilDB, $ilUser, $rbacreview; $sort_field = $sort ? $this->getFieldByTitle($sort) : $this->getField('id'); $direction = strtolower($direction); $direction = in_array($direction, array('desc', 'asc')) ? $direction : 'asc'; // Sorting by a status from an ILIAS Ref field. This column is added dynamically to the table, there is no field model $sort_by_status = false; if (substr($sort, 0, 8) == '_status_') { $sort_by_status = true; $sort_field = $this->getFieldByTitle(substr($sort, 8)); } if (is_null($sort_field)) { $sort_field = $this->getField('id'); } $id = $sort_field->getId(); $stl = $sort_field->getStorageLocation(); $select_str = ''; $join_str = ''; $where_additions = ''; $has_nref = false; if ($sort_field->isStandardField()) { if ($id == 'owner' || $id == 'last_edit_by') { $join_str .= "LEFT JOIN usr_data AS sort_usr_data_{$id} ON (sort_usr_data_{$id}.usr_id = record.{$id})"; $select_str .= " sort_usr_data_{$id}.login AS field_{$id},"; } else { $select_str .= " record.{$id} AS field_{$id},"; } } else { switch ($sort_field->getDatatypeId()) { case ilDataCollectionDatatype::INPUTFORMAT_RATING: $join_str .= "LEFT JOIN (SELECT AVG(sort_avg_rating.rating) AS avg_rating, sort_avg_rating.obj_id AS obj_id FROM il_rating as sort_avg_rating WHERE sort_avg_rating.sub_obj_id = {$sort_field->getId()} GROUP BY sort_avg_rating.obj_id) AS sort_avg_rating on sort_avg_rating.obj_id = record.id "; $select_str .= " sort_avg_rating.avg_rating AS field_{$id},"; break; case ilDataCollectionDatatype::INPUTFORMAT_ILIAS_REF: $join_str .= "LEFT JOIN il_dcl_record_field AS sort_record_field_{$id} ON (sort_record_field_{$id}.record_id = record.id AND sort_record_field_{$id}.field_id = " . $ilDB->quote($sort_field->getId(), 'integer') . ") "; $join_str .= "LEFT JOIN il_dcl_stloc{$stl}_value AS sort_stloc_{$id} ON (sort_stloc_{$id}.record_field_id = sort_record_field_{$id}.id) "; $join_str .= "LEFT JOIN object_reference AS sort_object_reference_{$id} ON (sort_object_reference_{$id}.ref_id = sort_stloc_{$id}.value AND sort_object_reference_{$id}.deleted IS NULL)"; $join_str .= "LEFT JOIN object_data AS sort_object_data_{$id} ON (sort_object_data_{$id}.obj_id = sort_object_reference_{$id}.obj_id)"; if ($sort_by_status) { global $ilUser; $join_str .= "LEFT JOIN ut_lp_marks AS ut ON (ut.obj_id = sort_object_data_{$id}.obj_id AND ut.usr_id = " . $ilDB->quote($ilUser->getId(), 'integer') . ") "; } $select_str .= !$sort_by_status ? " sort_object_data_{$id}.title AS field_{$id}," : " ut.status AS field_{$id}"; break; case ilDataCollectionDatatype::INPUTFORMAT_FILE: case ilDataCollectionDatatype::INPUTFORMAT_MOB: $join_str .= "LEFT JOIN il_dcl_record_field AS sort_record_field_{$id} ON (sort_record_field_{$id}.record_id = record.id AND sort_record_field_{$id}.field_id = " . $ilDB->quote($sort_field->getId(), 'integer') . ") "; $join_str .= "LEFT JOIN il_dcl_stloc{$stl}_value AS sort_stloc_{$id} ON (sort_stloc_{$id}.record_field_id = sort_record_field_{$id}.id) "; $join_str .= "LEFT JOIN object_data AS sort_object_data_{$id} ON (sort_object_data_{$id}.obj_id = sort_stloc_{$id}.value) "; $select_str .= " sort_object_data_{$id}.title AS field_{$id},"; break; case ilDataCollectionDatatype::INPUTFORMAT_REFERENCE: $prop = $sort_field->getPropertyvalues(); $ref_field = ilDataCollectionCache::getFieldCache($sort_field->getFieldRef()); $n_ref = $prop[ilDataCollectionField::PROPERTYID_N_REFERENCE]; if ($n_ref) { $has_nref = true; } $select_str .= $n_ref ? " GROUP_CONCAT(stloc_{$id}_joined.value) AS field_{$id}" : "stloc_{$id}_joined.value AS field_{$id},"; $join_str .= "LEFT JOIN il_dcl_record_field AS record_field_{$id} ON (record_field_{$id}.record_id = record.id AND record_field_{$id}.field_id = " . $ilDB->quote($sort_field->getId(), 'integer') . ") "; $join_str .= "LEFT JOIN il_dcl_stloc{$stl}_value AS stloc_{$id} ON (stloc_{$id}.record_field_id = record_field_{$id}.id) "; $join_str .= "LEFT JOIN il_dcl_record_field AS record_field_{$id}_joined ON (record_field_{$id}_joined.record_id = stloc_{$id}.value AND record_field_{$id}_joined.field_id = " . $ilDB->quote($ref_field->getId(), 'integer') . ") "; $join_str .= "LEFT JOIN il_dcl_stloc{$ref_field->getStorageLocation()}_value AS stloc_{$id}_joined ON (stloc_{$id}_joined.record_field_id = record_field_{$id}_joined.id) "; break; case ilDataCollectionDatatype::INPUTFORMAT_DATETIME: case ilDataCollectionDatatype::INPUTFORMAT_TEXT: case ilDataCollectionDatatype::INPUTFORMAT_BOOLEAN: case ilDataCollectionDatatype::INPUTFORMAT_NUMBER: $select_str .= " sort_stloc_{$id}.value AS field_{$id},"; $join_str .= "LEFT JOIN il_dcl_record_field AS sort_record_field_{$id} ON (sort_record_field_{$id}.record_id = record.id AND sort_record_field_{$id}.field_id = " . $ilDB->quote($sort_field->getId(), 'integer') . ") "; $join_str .= "LEFT JOIN il_dcl_stloc{$stl}_value AS sort_stloc_{$id} ON (sort_stloc_{$id}.record_field_id = sort_record_field_{$id}.id) "; break; } } if (count($filter)) { foreach ($filter as $key => $filter_value) { $filter_field_id = substr($key, 7); $filter_field = $this->getField($filter_field_id); switch ($filter_field->getDatatypeId()) { case ilDataCollectionDatatype::INPUTFORMAT_RATING: $join_str .= "INNER JOIN (SELECT AVG(avg_rating.rating) AS avg_rating, avg_rating.obj_id AS obj_id FROM il_rating as avg_rating WHERE avg_rating.sub_obj_id = {$filter_field_id} GROUP BY avg_rating.obj_id) AS avg_rating on avg_rating.avg_rating >= " . $ilDB->quote($filter_value, 'integer') . " AND avg_rating.obj_id = record.id "; break; case ilDataCollectionDatatype::INPUTFORMAT_ILIAS_REF: $join_str .= "INNER JOIN il_dcl_record_field AS filter_record_field_{$filter_field_id} ON (filter_record_field_{$filter_field_id}.record_id = record.id AND filter_record_field_{$filter_field_id}.field_id = " . $ilDB->quote($filter_field_id, 'integer') . ") "; $join_str .= "INNER JOIN il_dcl_stloc{$filter_field->getStorageLocation()}_value AS filter_stloc_{$filter_field_id} ON (filter_stloc_{$filter_field_id}.record_field_id = filter_record_field_{$filter_field_id}.id) "; $join_str .= "INNER JOIN object_reference AS filter_object_reference_{$filter_field_id} ON (filter_object_reference_{$filter_field_id}.ref_id = filter_stloc_{$filter_field_id}.value ) "; $join_str .= "INNER JOIN object_data AS filter_object_data_{$filter_field_id} ON (filter_object_data_{$filter_field_id}.obj_id = filter_object_reference_{$filter_field_id}.obj_id AND filter_object_data_{$filter_field_id}.title LIKE " . $ilDB->quote("%{$filter_value}%", 'text') . ") "; break; case ilDataCollectionDatatype::INPUTFORMAT_MOB: case ilDataCollectionDatatype::INPUTFORMAT_FILE: $join_str .= "INNER JOIN il_dcl_record_field AS filter_record_field_{$filter_field_id} ON (filter_record_field_{$filter_field_id}.record_id = record.id AND filter_record_field_{$filter_field_id}.field_id = " . $ilDB->quote($filter_field_id, 'integer') . ") "; $join_str .= "INNER JOIN il_dcl_stloc{$filter_field->getStorageLocation()}_value AS filter_stloc_{$filter_field_id} ON (filter_stloc_{$filter_field_id}.record_field_id = filter_record_field_{$filter_field_id}.id) "; $join_str .= "INNER JOIN object_data AS filter_object_data_{$filter_field_id} ON (filter_object_data_{$filter_field_id}.obj_id = filter_stloc_{$filter_field_id}.value AND filter_object_data_{$filter_field_id}.title LIKE " . $ilDB->quote("%{$filter_value}%", 'text') . ") "; break; case ilDataCollectionDatatype::INPUTFORMAT_DATETIME: $date_from = isset($filter_value['from']) && is_object($filter_value['from']) ? $filter_value['from'] : NULL; $date_to = isset($filter_value['to']) && is_object($filter_value['to']) ? $filter_value['to'] : NULL; if ($filter_field->isStandardField()) { if ($date_from) { $where_additions .= " AND (record.{$filter_field_id} >= " . $ilDB->quote($date_from, 'date') . ")"; } if ($date_to) { $where_additions .= " AND (record.{$filter_field_id} <= " . $ilDB->quote($date_to, 'date') . ")"; } } else { $join_str .= "INNER JOIN il_dcl_record_field AS filter_record_field_{$filter_field_id} ON (filter_record_field_{$filter_field_id}.record_id = record.id AND filter_record_field_{$filter_field_id}.field_id = " . $ilDB->quote($filter_field_id, 'integer') . ") "; $join_str .= "INNER JOIN il_dcl_stloc{$filter_field->getStorageLocation()}_value AS filter_stloc_{$filter_field_id} ON (filter_stloc_{$filter_field_id}.record_field_id = filter_record_field_{$filter_field_id}.id "; if ($date_from) { $join_str .= "AND filter_stloc_{$filter_field_id}.value >= " . $ilDB->quote($date_from, 'date') . " "; } if ($date_to) { $join_str .= "AND filter_stloc_{$filter_field_id}.value <= " . $ilDB->quote($date_to, 'date') . " "; } $join_str .= ") "; } break; case ilDataCollectionDatatype::INPUTFORMAT_NUMBER: $from = isset($filter_value['from']) ? (int) $filter_value['from'] : NULL; $to = isset($filter_value['to']) ? (int) $filter_value['to'] : NULL; if ($filter_field->isStandardField()) { if (!is_null($from)) { $where_additions .= " AND record.{$filter_field_id} >= " . $ilDB->quote($from, 'integer'); } if (!is_null($to)) { $where_additions .= " AND record.{$filter_field_id} <= " . $ilDB->quote($to, 'integer'); } } else { $join_str .= "INNER JOIN il_dcl_record_field AS filter_record_field_{$filter_field_id} ON (filter_record_field_{$filter_field_id}.record_id = record.id AND filter_record_field_{$filter_field_id}.field_id = " . $ilDB->quote($filter_field_id, 'integer') . ") "; $join_str .= "INNER JOIN il_dcl_stloc{$filter_field->getStorageLocation()}_value AS filter_stloc_{$filter_field_id} ON (filter_stloc_{$filter_field_id}.record_field_id = filter_record_field_{$filter_field_id}.id"; if (!is_null($from)) { $join_str .= " AND filter_stloc_{$filter_field_id}.value >= " . $ilDB->quote($from, 'integer'); } if (!is_null($to)) { $join_str .= " AND filter_stloc_{$filter_field_id}.value <= " . $ilDB->quote($to, 'integer'); } $join_str .= ") "; } break; case ilDataCollectionDatatype::INPUTFORMAT_BOOLEAN: if ($filter_value == "checked") { $join_str .= "INNER JOIN il_dcl_record_field AS filter_record_field_{$filter_field_id} ON (filter_record_field_{$filter_field_id}.record_id = record.id AND filter_record_field_{$filter_field_id}.field_id = " . $ilDB->quote($filter_field_id, 'integer') . ") "; $join_str .= "INNER JOIN il_dcl_stloc{$filter_field->getStorageLocation()}_value AS filter_stloc_{$filter_field_id} ON (filter_stloc_{$filter_field_id}.record_field_id = filter_record_field_{$filter_field_id}.id"; $join_str .= " AND filter_stloc_{$filter_field_id}.value = " . $ilDB->quote(1, 'integer'); } else { $join_str .= "INNER JOIN il_dcl_record_field AS filter_record_field_{$filter_field_id} ON (filter_record_field_{$filter_field_id}.record_id = record.id AND filter_record_field_{$filter_field_id}.field_id = " . $ilDB->quote($filter_field_id, 'integer') . ") "; $join_str .= "LEFT JOIN il_dcl_stloc{$filter_field->getStorageLocation()}_value AS filter_stloc_{$filter_field_id} ON (filter_stloc_{$filter_field_id}.record_field_id = filter_record_field_{$filter_field_id}.id"; $where_additions .= " AND (filter_stloc_{$filter_field_id}.value <> " . $ilDB->quote(1, 'integer') . " OR filter_stloc_{$filter_field_id}.value is NULL)"; } $join_str .= " ) "; break; case ilDataCollectionDatatype::INPUTFORMAT_TEXT: if ($filter_field->isStandardField()) { $join_str .= "INNER JOIN usr_data AS filter_usr_data_{$filter_field_id} ON (filter_usr_data_{$filter_field_id}.usr_id = record.{$filter_field_id} AND filter_usr_data_{$filter_field_id}.login LIKE " . $ilDB->quote("%{$filter_value}%", 'text') . ") "; } else { $join_str .= " INNER JOIN il_dcl_record_field AS filter_record_field_{$filter_field_id} ON (filter_record_field_{$filter_field_id}.record_id = record.id AND filter_record_field_{$filter_field_id}.field_id = " . $ilDB->quote($filter_field_id, 'integer') . ") "; $join_str .= " INNER JOIN il_dcl_stloc{$filter_field->getStorageLocation()}_value AS filter_stloc_{$filter_field_id} ON (filter_stloc_{$filter_field_id}.record_field_id = filter_record_field_{$filter_field_id}.id AND filter_stloc_{$filter_field_id}.value LIKE " . $ilDB->quote("%{$filter_value}%", 'text') . ") "; } break; case ilDataCollectionDatatype::INPUTFORMAT_REFERENCE: $join_str .= " INNER JOIN il_dcl_record_field AS filter_record_field_{$filter_field_id} ON (filter_record_field_{$filter_field_id}.record_id = record.id AND filter_record_field_{$filter_field_id}.field_id = " . $ilDB->quote($filter_field_id, 'integer') . ") "; $prop = $filter_field->getPropertyvalues(); $n_ref = $prop[ilDataCollectionField::PROPERTYID_N_REFERENCE]; if ($n_ref) { $join_str .= " INNER JOIN il_dcl_stloc{$filter_field->getStorageLocation()}_value AS filter_stloc_{$filter_field_id} ON (filter_stloc_{$filter_field_id}.record_field_id = filter_record_field_{$filter_field_id}.id AND filter_stloc_{$filter_field_id}.value LIKE " . $ilDB->quote("%{$filter_value}%", 'text') . ") "; } else { $join_str .= " INNER JOIN il_dcl_stloc{$filter_field->getStorageLocation()}_value AS filter_stloc_{$filter_field_id} ON (filter_stloc_{$filter_field_id}.record_field_id = filter_record_field_{$filter_field_id}.id AND filter_stloc_{$filter_field_id}.value = " . $ilDB->quote($filter_value, 'integer') . ") "; } break; } } } // Build the query string $sql = "SELECT DISTINCT record.id, record.owner, "; $sql .= rtrim($select_str, ',') . " FROM il_dcl_record AS record "; $sql .= $join_str; $sql .= " WHERE record.table_id = " . $ilDB->quote($this->getId(), 'integer') . $where_additions; if ($has_nref) { $sql .= " GROUP BY record.id"; } $sql .= " ORDER BY field_{$id} {$direction}"; $set = $ilDB->query($sql); $total_record_ids = array(); // Save record-ids in session to enable prev/next links in detail view $_SESSION['dcl_record_ids'] = array(); $is_allowed_to_view = $this->getCollectionObject()->getOwner() == $ilUser->getId() || $rbacreview->isAssigned($ilUser->getId(), 2); while ($rec = $ilDB->fetchAssoc($set)) { // Quick check if the current user is allowed to view the record if (!$is_allowed_to_view && ($this->getViewOwnRecordsPerm() && $ilUser->getId() != $rec['owner'])) { continue; } $total_record_ids[] = $rec['id']; $_SESSION['dcl_record_ids'][] = $rec['id']; } // Now slice the array to load only the needed records in memory $record_ids = array_slice($total_record_ids, $offset, $limit); $records = array(); foreach ($record_ids as $id) { $records[] = ilDataCollectionCache::getRecordCache($id); } return array('records' => $records, 'total' => count($total_record_ids)); }
/** * @param $found * * @return string */ public function doExtReplace($found) { $ref_rec_ids = $this->record_obj->getRecordFieldValue($this->currentField->getId()); if (!is_array($ref_rec_ids)) { $ref_rec_ids = array($ref_rec_ids); } if (!count($ref_rec_ids) || !$ref_rec_ids) { return; } $ref_recs = array(); foreach ($ref_rec_ids as $ref_rec_id) { $ref_recs[] = ilDataCollectionCache::getRecordCache($ref_rec_id); } $field = $ref_recs[0]->getTable()->getFieldByTitle($found[1]); $tpl = new ilTemplate("tpl.reference_list.html", true, true, "Modules/DataCollection"); $tpl->setCurrentBlock("reference_list"); if (!$field) { if (ilObjDataCollectionAccess::_hasWriteAccess($this->dcl_gui_object->ref_id)) { ilUtil::sendInfo("Bad Viewdefinition at [ext tableOf=\"" . $found[1] . "\" ...]", true); } return; } foreach ($ref_recs as $ref_record) { $tpl->setCurrentBlock("reference"); $tpl->setVariable("CONTENT", $ref_record->getRecordFieldHTML($field->getId())); $tpl->parseCurrentBlock(); } //$ref_rec->getRecordFieldHTML($field->getId()) if ($field) { return $tpl->get(); } }
/** * initEditCustomForm * * @param string $a_mode values: create | edit */ public function initForm($a_mode = "create") { global $ilCtrl, $lng; include_once "./Services/Form/classes/class.ilPropertyFormGUI.php"; $this->form = new ilPropertyFormGUI(); if ($a_mode == "edit") { $this->form->setTitle($lng->txt('dcl_edit_field')); $hidden_prop = new ilHiddenInputGUI("field_id"); $this->form->addItem($hidden_prop); $this->form->setFormAction($ilCtrl->getFormAction($this), "update"); $this->form->addCommandButton('update', $lng->txt('dcl_update_field')); } else { $this->form->setTitle($lng->txt('dcl_new_field')); $hidden_prop = new ilHiddenInputGUI("table_id"); $hidden_prop->setValue($this->field_obj->getTableId()); $this->form->addItem($hidden_prop); $this->form->setFormAction($ilCtrl->getFormAction($this), "save"); $this->form->addCommandButton('save', $lng->txt('dcl_create_field')); } $this->form->addCommandButton('cancel', $lng->txt('cancel')); $text_prop = new ilTextInputGUI($lng->txt("title"), "title"); $text_prop->setRequired(true); $text_prop->setInfo(sprintf($lng->txt('fieldtitle_allow_chars'), ilDataCollectionField::_getTitleValidChars(false))); $text_prop->setValidationRegexp(ilDataCollectionField::_getTitleValidChars(true)); $this->form->addItem($text_prop); $edit_datatype = new ilRadioGroupInputGUI($lng->txt('dcl_datatype'), 'datatype'); foreach (ilDataCollectionDatatype::getAllDatatypes() as $datatype) { $opt = new ilRadioOption($lng->txt('dcl_' . $datatype['title']), $datatype['id']); foreach (ilDataCollectionDatatype::getProperties($datatype['id']) as $property) { //Type Reference: List Tabels if ($datatype['id'] == ilDataCollectionDatatype::INPUTFORMAT_REFERENCE and $property['id'] == ilDataCollectionField::PROPERTYID_REFERENCE) { $options = array(); // Get Tables require_once "./Modules/DataCollection/classes/class.ilDataCollectionTable.php"; $tables = $this->parent_obj->getDataCollectionObject()->getTables(); foreach ($tables as $table) { foreach ($table->getRecordFields() as $field) { //referencing references may lead to endless loops. if ($field->getDatatypeId() != ilDataCollectionDatatype::INPUTFORMAT_REFERENCE) { $options[$field->getId()] = $table->getTitle() . self::REFERENCE_SEPARATOR . $field->getTitle(); } } } $table_selection = new ilSelectInputGUI('', 'prop_' . $property['id']); $table_selection->setOptions($options); //$table_selection->setValue($this->table_id); $opt->addSubItem($table_selection); } elseif ($datatype['id'] == ilDataCollectionDatatype::INPUTFORMAT_REFERENCELIST and $property['id'] == ilDataCollectionField::PROPERTYID_N_REFERENCE) { // Get Tables require_once "./Modules/DataCollection/classes/class.ilDataCollectionTable.php"; $tables = $this->parent_obj->getDataCollectionObject()->getTables(); foreach ($tables as $table) { foreach ($table->getRecordFields() as $field) { //referencing references may lead to endless loops. if ($field->getDatatypeId() != ilDataCollectionDatatype::INPUTFORMAT_REFERENCELIST) { $options[$field->getId()] = $table->getTitle() . self::REFERENCE_SEPARATOR . $field->getTitle(); } } } $table_selection = new ilSelectInputGUI('', 'prop_' . $property['id']); $table_selection->setOptions($options); $opt->addSubItem($table_selection); } elseif ($property['id'] == ilDataCollectionField::PROPERTYID_FORMULA_EXPRESSION) { $table = ilDataCollectionCache::getTableCache((int) $_GET['table_id']); $fields = array(); foreach ($table->getFieldsForFormula() as $f) { $placeholder = $f->isStandardField() ? $f->getId() : $f->getTitle(); $fields[] = '<a class="dclPropExpressionField" data-placeholder="' . $placeholder . '">' . $f->getTitle() . '</a>'; } $subitem = new ilTextAreaInputGUI($lng->txt('dcl_prop_expression'), 'prop_' . $property['id']); $operators = implode(', ', array_keys(ilDclExpressionParser::getOperators())); $functions = implode(', ', ilDclExpressionParser::getFunctions()); $subitem->setInfo(sprintf($lng->txt('dcl_prop_expression_info'), $operators, $functions, implode('<br>', $fields))); $opt->addSubItem($subitem); } elseif ($property['datatype_id'] == $datatype['id']) { //All other Types: List properties saved in propertie definition table if ($property['inputformat'] == ilDataCollectionDatatype::INPUTFORMAT_BOOLEAN) { $subitem = new ilCheckboxInputGUI($lng->txt('dcl_' . $property['title']), 'prop_' . $property['id']); $opt->addSubItem($subitem); } elseif ($property['inputformat'] == ilDataCollectionDatatype::INPUTFORMAT_NUMBER) { $subitem = new ilNumberInputGUI($lng->txt('dcl_' . $property['title']), 'prop_' . $property['id']); // TODO: Nicer way to add additional info to fields (need changes in language-logic) /*if($lng->txt('dcl_'.$property['title'].'_info') != '-dcl_'.$property['title'].'_info-') { $subitem->setInfo($lng->txt('dcl_'.$property['title'].'_info')); }*/ $subitem->setSize(5); if ($property['title'] == 'length') { $subitem->setMaxValue(4000); $subitem->setInfo($lng->txt('dcl_' . $property['title'] . '_info')); } $opt->addSubItem($subitem); } elseif ($property['inputformat'] == ilDataCollectionDatatype::INPUTFORMAT_NON_EDITABLE_VALUE) { $subitem = new ilNonEditableValueGUI($lng->txt('dcl_' . $property['title'])); $subitem->setValue(implode(', ', ilDataCollectionDatatype::$mob_suffixes)); $opt->addSubItem($subitem); } else { $subitem = new ilTextInputGUI($lng->txt('dcl_' . $property['title']), 'prop_' . $property['id']); // TODO: Nicer way to add additional info to fields (need changes in language-logic) /*if($lng->txt('dcl_'.$property['title'].'_info') != '-dcl_'.$property['title'].'_info-') { $subitem->setInfo($lng->txt('dcl_'.$property['title'].'_info')); }*/ if ($property['title'] == 'regex') { $subitem->setInfo($lng->txt('dcl_' . $property['title'] . '_info')); } $opt->addSubItem($subitem); } } } $edit_datatype->addOption($opt); } $edit_datatype->setRequired(true); //you can't change type but we still need it in POST if ($a_mode == "edit") { $edit_datatype->setDisabled(true); } $this->form->addItem($edit_datatype); // Description $text_prop = new ilTextAreaInputGUI($lng->txt("dcl_field_description"), "description"); $this->form->addItem($text_prop); // Required $cb = new ilCheckboxInputGUI($lng->txt("dcl_field_required"), "required"); $this->form->addItem($cb); //Unique $cb = new ilCheckboxInputGUI($lng->txt("dcl_unique"), "unique"); $this->form->addItem($cb); }
public function cloneStructure($original_id) { $original = ilDataCollectionCache::getTableCache($original_id); $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->setTitle($original->getTitle()); $this->doCreate(); //clone fields. foreach ($original->getRecordFields() as $field) { $new_field = new ilDataCollectionField(); $new_field->setTableId($this->getId()); $new_field->cloneStructure($field->getId()); } if ($old_view_id = ilDataCollectionRecordViewViewdefinition::getIdByTableId($original_id)) { $old_view = new ilDataCollectionRecordViewViewdefinition($old_view_id); $old_view->setTableId($original_id); $viewdef = new ilDataCollectionRecordViewViewdefinition(); $viewdef->setTableId($this->id); $viewdef->setXMLContent($old_view->getXMLContent(false)); $viewdef->create(); } }
public function sendFile() { global $ilAccess; //need read access to receive file if ($ilAccess->checkAccess("read", "", $this->parent_obj->ref_id)) { $rec_id = $_GET['record_id']; $record = ilDataCollectionCache::getRecordCache($rec_id); $field_id = $_GET['field_id']; $file_obj = new ilObjFile($record->getRecordFieldValue($field_id), false); if (!$this->recordBelongsToCollection($record, $this->parent_obj->ref_id)) { return; } ilUtil::deliverFile($file_obj->getFile(), $file_obj->getTitle()); } }
private function loadTable() { include_once "class.ilDataCollectionTable.php"; if ($this->table == NULL) { $this->table = ilDataCollectionCache::getTableCache($this->getTableId()); } }
/** * Substitute field values in placehoders like [[Field Title]] from current record * * @param string $placeholder * * @throws ilException * @return string */ protected function substituteFieldValue($placeholder) { if (isset(self::$cache_fields[$placeholder])) { $field = self::$cache_fields[$placeholder]; } else { $table = ilDataCollectionCache::getTableCache($this->record->getTableId()); // TODO May need caching per table in future $field_title = preg_replace('#^\\[\\[(.*)\\]\\]#', "\$1", $placeholder); $field = $table->getFieldByTitle($field_title); if ($field === NULL) { // Workaround for standardfields - title my be ID $field = $table->getField($field_title); if ($field === NULL) { global $lng; /** * @var $lng ilLanguage */ $lng->loadLanguageModule('dcl'); // throw new ilException("Field with title '$field_title' not found"); throw new ilException(sprintf($lng->txt('dcl_err_formula_field_not_found'), $field_title)); } } self::$cache_fields[$placeholder] = $field; } return $this->record->getRecordFieldHTML($field->getId()); }
/** * @return int|string */ public function getExportValue() { $values = $this->getValue(); $names = array(); foreach ($values as $value) { if ($value) { $ref_rec = ilDataCollectionCache::getRecordCache($value); $names[] = $ref_rec->getRecordField($this->getField()->getFieldRef())->getValue(); } } $string = ""; foreach ($names as $name) { $string .= $name . ", "; } if (!count($names)) { return ""; } $string = substr($string, 0, -2); return $string; }
/** * Get all placeholders for table id * @param int $a_table_id * @param bool $a_verbose * @return array */ public static function getAvailablePlaceholders($a_table_id, $a_verbose = false) { $all = array(); require_once "./Modules/DataCollection/classes/class.ilDataCollectionTable.php"; $objTable = ilDataCollectionCache::getTableCache($a_table_id); $fields = $objTable->getFields($a_table_id); foreach ($fields as $field) { if (!$a_verbose) { $all[] = "[" . $field->getTitle() . "]"; if ($field->getDatatypeId() == ilDataCollectionDatatype::INPUTFORMAT_REFERENCE) { $all[] = '[dclrefln field="' . $field->getTitle() . '"][/dclrefln]'; } if ($field->getDatatypeId() == ilDataCollectionDatatype::INPUTFORMAT_ILIAS_REF) { $all[] = '[dcliln field="' . $field->getTitle() . '"][/dcliln]'; } } else { $all["[" . $field->getTitle() . "]"] = $field; if ($field->getDatatypeId() == ilDataCollectionDatatype::INPUTFORMAT_REFERENCE) { $all['[dclrefln field="' . $field->getTitle() . '"][/dclrefln]'] = $field; } if ($field->getDatatypeId() == ilDataCollectionDatatype::INPUTFORMAT_ILIAS_REF) { $all['[dcliln field="' . $field->getTitle() . '"][/dcliln]'] = $field; } } } return $all; }
public function cloneStructure($original_id) { $original = ilDataCollectionCache::getFieldCache($original_id); $this->setTitle($original->getTitle()); $this->setDatatypeId($original->getDatatypeId()); $this->setDescription($original->getDescription()); $this->setEditable($original->isEditable()); $this->setLocked($original->getLocked()); $this->setFilterable($original->isFilterable()); $this->setVisible($original->isVisible()); $this->setOrder($original->getOrder()); $this->setRequired($original->getRequired()); $this->setUnique($original->isUnique()); $this->doCreate(); $this->cloneProperties($original); }
/** * @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; } }
/** * addFilterInputFieldToTable This function adds the according filter item to the table gui passed as argument. * @param $field ilDataCollectionField The field which should be filterable. * @param &$table ilTable2GUI The table you want the filter to be added to. */ static function addFilterInputFieldToTable(ilDataCollectionField $field, ilTable2GUI &$table) { global $lng; $type_id = $field->getDatatypeId(); $input = NULL; switch ($type_id) { case ilDataCollectionDatatype::INPUTFORMAT_TEXT: $input = $table->addFilterItemByMetaType("filter_" . $field->getId(), ilTable2GUI::FILTER_TEXT, false, $field->getId()); $input->setSubmitFormOnEnter(true); break; case ilDataCollectionDatatype::INPUTFORMAT_NUMBER: $input = $table->addFilterItemByMetaType("filter_" . $field->getId(), ilTable2GUI::FILTER_NUMBER_RANGE, false, $field->getId()); $input->setSubmitFormOnEnter(true); break; case ilDataCollectionDatatype::INPUTFORMAT_BOOLEAN: $input = $table->addFilterItemByMetaType("filter_" . $field->getId(), ilTable2GUI::FILTER_SELECT, false, $field->getId()); $input->setOptions(array("" => $lng->txt("dcl_any"), "not_checked" => $lng->txt("dcl_not_checked"), "checked" => $lng->txt("dcl_checked"))); break; case ilDataCollectionDatatype::INPUTFORMAT_DATETIME: $input = $table->addFilterItemByMetaType("filter_" . $field->getId(), ilTable2GUI::FILTER_DATE_RANGE, false, $field->getId()); $input->setSubmitFormOnEnter(true); $input->setStartYear(date("Y") - 100); break; case ilDataCollectionDatatype::INPUTFORMAT_FILE: $input = $table->addFilterItemByMetaType("filter_" . $field->getId(), ilTable2GUI::FILTER_TEXT, false, $field->getId()); $input->setSubmitFormOnEnter(true); break; case ilDataCollectionDatatype::INPUTFORMAT_REFERENCE: $input = $table->addFilterItemByMetaType("filter_" . $field->getId(), ilTable2GUI::FILTER_SELECT, false, $field->getId()); $ref_field_id = $field->getFieldRef(); $ref_field = ilDataCollectionCache::getFieldCache($ref_field_id); $ref_table = ilDataCollectionCache::getTableCache($ref_field->getTableId()); $options = array(); foreach ($ref_table->getRecords() as $record) { $options[$record->getId()] = $record->getRecordFieldValue($ref_field_id); } // Sort by values ASC asort($options); $options = array('' => $lng->txt('dcl_any')) + $options; $input->setOptions($options); break; case ilDataCollectionDatatype::INPUTFORMAT_RATING: $input = $table->addFilterItemByMetaType("filter_" . $field->getId(), ilTable2GUI::FILTER_SELECT, false, $field->getId()); $options = array("" => $lng->txt("dcl_any"), 1 => ">1", 2 => ">2", 3 => ">3", 4 => ">4", 5 => "5"); $input->setOptions($options); break; case ilDataCollectionDatatype::INPUTFORMAT_MOB: $input = $table->addFilterItemByMetaType("filter_" . $field->getId(), ilTable2GUI::FILTER_TEXT, false, $field->getId()); $input->setSubmitFormOnEnter(true); break; case ilDataCollectionDatatype::INPUTFORMAT_ILIAS_REF: $input = $table->addFilterItemByMetaType("filter_" . $field->getId(), ilTable2GUI::FILTER_TEXT, false, $field->getId()); $input->setSubmitFormOnEnter(true); break; case ilDataCollectionDatatype::INPUTFORMAT_REFERENCELIST: //FIXME $input = $table->addFilterItemByMetaType("filter_" . $field->getId(), ilTable2GUI::FILTER_SELECT, false, $field->getId()); $ref_field_id = $field->getFieldRef(); $ref_field = ilDataCollectionCache::getFieldCache($ref_field_id); $ref_table = ilDataCollectionCache::getTableCache($ref_field->getTableId()); $options = array(); foreach ($ref_table->getRecords() as $record) { $options[$record->getId()] = $record->getRecordFieldValue($ref_field_id); } // Sort by values ASC asort($options); $options = array('' => $lng->txt('dcl_any')) + $options; $input->setOptions($options); break; } if ($input != NULL) { $input->setTitle($field->getTitle()); } return $input; }
/** * Load table */ private function loadTable() { if ($this->table == NULL) { $this->table = ilDataCollectionCache::getTableCache($this->getTableId()); } }
/** * Delete multiple records * * @param array $record_ids */ public function deleteRecords(array $record_ids = array()) { /** @var ilCtrl $ilCtrl */ global $ilCtrl, $lng; $record_ids = count($record_ids) ? $record_ids : $_POST['record_ids']; $record_ids = is_null($record_ids) ? array() : $record_ids; // Invoke deletion $n_skipped = 0; foreach ($record_ids as $record_id) { /** @var ilDataCollectionRecord $record */ $record = ilDataCollectionCache::getRecordCache($record_id); if ($record) { if ($record->hasPermissionToDelete((int) $_GET['ref_id'])) { $record->doDelete(); } else { $n_skipped++; } } } $n_deleted = count($record_ids) - $n_skipped; if ($n_deleted) { ilUtil::sendSuccess(sprintf($lng->txt('dcl_deleted_records'), $n_deleted), true); } if ($n_skipped) { ilUtil::sendInfo(sprintf($lng->txt('dcl_skipped_delete_records'), $n_skipped), true); } $ilCtrl->redirect($this, 'listRecords'); }
/** * @description This adds the collumn for status. * * @param ilDataCollectionRecord $record * @param ilDataCollectionField $field * * @return string */ protected function getStatus(ilDataCollectionRecord $record, ilDataCollectionField $field) { $record_field = ilDataCollectionCache::getRecordFieldCache($record, $field); $return = ""; if ($status = $record_field->getStatus()) { $return = "<img src='" . ilLearningProgressBaseGUI::_getImagePathForStatus($status->status) . "'>"; } return $return; }