/** * Set value for record field * * @param mixed $value * @param bool $omit_parsing If true, does not parse the value and stores it in the given format */ public function setValue($value, $omit_parsing = false) { $this->loadValue(); if (!$omit_parsing) { $tmp = $this->field->getDatatype()->parseValue($value, $this); $old = $this->value; //if parse value fails keep the old value if ($tmp !== false) { $this->value = $tmp; //delete old file from filesystem // TODO Does not belong here, create separate class ilDataCollectionFileField and overwrite setValue method if ($old && $this->field->getDatatypeId() == ilDataCollectionDatatype::INPUTFORMAT_FILE) { $this->record->deleteFile($old); } } } else { $this->value = $value; } }
/** * @param ilDataCollectionField $field * @param array $warnings * * @return bool */ private function checkImportType($field, &$warnings) { global $lng; if (in_array($field->getDatatypeId(), $this->supported_import_datatypes)) { return true; } else { $warnings[] = $field->getTitle() . ": " . $lng->txt("dcl_not_supported_in_import"); return false; } }
/** * @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()); } }
static function passThroughFilter(ilDataCollectionRecord $record, ilDataCollectionField $field, $filter) { $pass = false; $type_id = $field->getDatatypeId(); $value = $record->getRecordFieldValue($field->getId()); switch ($type_id) { case ilDataCollectionDatatype::INPUTFORMAT_TEXT: if (!$filter || strpos(strtolower($value), strtolower($filter)) !== false) { $pass = true; } break; case ilDataCollectionDatatype::INPUTFORMAT_NUMBER: if ((!$filter['from'] || $value >= $filter['from']) && (!$filter['to'] || $value <= $filter['to'])) { $pass = true; } break; case ilDataCollectionDatatype::INPUTFORMAT_BOOLEAN: if ($filter == "checked" && $value == 1 || $filter == "not_checked" && $value == 0 || $filter == '' || !$filter) { $pass = true; } break; case ilDataCollectionDatatype::INPUTFORMAT_DATETIME: if ((!$filter['from'] || $value >= $filter['from']) && (!$filter['to'] || $value <= $filter['to'])) { $pass = true; } break; case ilDataCollectionDatatype::INPUTFORMAT_FILE: if (!ilObject2::_exists($value) || ilObject2::_lookupType($value, false) != "file") { $pass = true; break; } $file_obj = new ilObjFile($value, false); $file_name = $file_obj->getTitle(); if (!$filter || strpos(strtolower($file_name), strtolower($filter)) !== false) { $pass = true; } break; case ilDataCollectionDatatype::INPUTFORMAT_REFERENCE: $props = $field->getProperties(); if ($filter && $props[ilDataCollectionField::PROPERTYID_N_REFERENCE] && is_array($value) && in_array($filter, $value)) { $pass = true; } if (!$filter || $filter == $value) { $pass = true; } break; case ilDataCollectionDatatype::INPUTFORMAT_RATING: if (!$filter || $filter <= $value['avg']) { $pass = true; } break; case ilDataCollectionDatatype::INPUTFORMAT_ILIAS_REF: $obj_id = ilObject::_lookupObjId($value); if (!$filter || strpos(strtolower(ilObject::_lookupTitle($obj_id)), strtolower($filter)) !== false) { $pass = true; } break; case ilDataCollectionDatatype::INPUTFORMAT_MOB: $m_obj = new ilObjMediaObject($value, false); $file_name = $m_obj->getTitle(); if (!$filter || strpos(strtolower($file_name), strtolower($filter)) !== false) { $pass = true; } break; } //for the fields owner and last edit by, we check the name, not the ID if (($field->getId() == "owner" || $field->getId() == "last_edit_by") && $filter) { $pass = false; $user = new ilObjUser($value); if (strpos($user->getFullname(), $filter) !== false) { $pass = true; } } return $pass; }
/** * @return array|mixed|string */ public function getHTML() { $values = $this->getValue(); $record_field = $this; if (!$values or !count($values)) { return ""; } $html = ""; $cut = false; $tpl = new ilTemplate("tpl.reference_hover.html", true, true, "Modules/DataCollection"); $tpl->setCurrentBlock("reference_list"); $elements = array(); foreach ($values as $value) { $ref_record = ilDataCollectionCache::getRecordCache($value); if (!$ref_record->getTableId() or !$record_field->getField() or !$record_field->getField()->getTableId()) { //the referenced record_field does not seem to exist. $record_field->setValue(NULL); $record_field->doUpdate(); } else { $elements[] = array('value' => $ref_record->getRecordFieldHTML($this->getField()->getFieldRef()), 'sort' => $ref_record->getRecordFieldSortingValue($this->getField()->getFieldRef())); } } //sort fetched elements $is_numeric = false; $ref_field = new ilDataCollectionField($record_field->getField()->getFieldRef()); switch ($ref_field->getDatatypeId()) { case ilDataCollectionDatatype::INPUTFORMAT_DATETIME: case ilDataCollectionDatatype::INPUTFORMAT_NUMBER: $is_numeric = true; break; } $elements = ilUtil::sortArray($elements, 'sort', 'asc', $is_numeric); //concat foreach ($elements as $element) { if (strlen($html) < $this->max_reference_length) { $html .= $element['value'] . ", "; } else { $cut = true; } $tpl->setCurrentBlock("reference"); $tpl->setVariable("CONTENT", $element['value']); $tpl->parseCurrentBlock(); } $html = substr($html, 0, -2); if ($cut) { $html .= "..."; } $tpl->setVariable("RECORD_ID", $this->getRecord()->getId()); $tpl->setVariable("ALL", $html); $tpl->parseCurrentBlock(); return $tpl->get(); }
/** * @param ilDataCollectionField $originalField */ public function cloneProperties(ilDataCollectionField $originalField) { $orgProps = $originalField->getProperties(); if ($orgProps == NULL) { return; } foreach ($orgProps as $id => $value) { $fieldprop_obj = new ilDataCollectionFieldProp(); $fieldprop_obj->setDatatypePropertyId($id); $fieldprop_obj->setFieldId($this->getId()); // If reference field, we must reset the referenced field, otherwise it will point to the old ID if ($originalField->getDatatypeId() == ilDataCollectionDatatype::INPUTFORMAT_REFERENCE && $id == ilDataCollectionField::PROPERTYID_REFERENCE) { $value = NULL; } $fieldprop_obj->setValue($value); $fieldprop_obj->doCreate(); } }