/**
  * List Records
  *
  *
  */
 public function listRecords()
 {
     global $ilTabs, $tpl, $lng, $ilCtrl, $ilToolbar;
     // Show tables
     require_once "./Modules/DataCollection/classes/class.ilDataCollectionTable.php";
     if (ilObjDataCollection::_hasWriteAccess($this->parent_obj->ref_id)) {
         $tables = $this->parent_obj->object->getTables();
     } else {
         $tables = $this->parent_obj->object->getVisibleTables();
     }
     foreach ($tables as $table) {
         $options[$table->getId()] = $table->getTitle();
     }
     $tpl->addCss("./Modules/DataCollection/css/dcl_reference_hover.css");
     if (count($options) > 0) {
         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("ilDataCollectionRecordListGUI", "doTableSwitch"));
         $ilToolbar->addText($lng->txt("dcl_table"));
         $ilToolbar->addInputItem($table_selection);
         $ilToolbar->addFormButton($lng->txt('change'), 'doTableSwitch');
         $ilToolbar->addSeparator();
     }
     if (($this->table_obj->getExportEnabled() || $this->table_obj->hasPermissionToFields($this->parent_obj->ref_id)) && count($this->table_obj->getExportableFields())) {
         $ilToolbar->addButton($lng->txt('dcl_export_table_excel'), $ilCtrl->getFormActionByClass("ildatacollectionrecordlistgui", "exportExcel"));
     }
     if ($this->table_obj->hasPermissionToAddRecord($this->parent_obj->ref_id) && $this->table_obj->hasCustomFields()) {
         $ilCtrl->setParameterByClass("ildatacollectionrecordeditgui", "record_id", null);
         $ilToolbar->addButton($lng->txt("dcl_import_records .xls"), $ilCtrl->getFormActionByClass("ildatacollectionrecordlistgui", "showImportExcel"));
         $ilToolbar->addButton($lng->txt("dcl_add_new_record"), $ilCtrl->getFormActionByClass("ildatacollectionrecordeditgui", "create"), "", "", "", "", "submit emphsubmit");
         // #11502
     }
     // requested not to implement this way...
     //$tpl->addJavaScript("Modules/DataCollection/js/fastTableSwitcher.js");
     $tpl->addJavaScript("Modules/DataCollection/js/datacollection.js");
     if (count($this->table_obj->getRecordFields()) == 0) {
         ilUtil::sendInfo($lng->txt("dcl_no_fields_yet") . " " . ($this->table_obj->hasPermissionToFields($this->parent_obj->ref_id) ? $lng->txt("dcl_create_fields") : ""));
     }
     $list = new ilDataCollectionRecordListTableGUI($this, $ilCtrl->getCmd(), $this->table_obj);
     $tpl->getStandardTemplate();
     $tpl->setPermanentLink("dcl", $this->parent_obj->ref_id);
     if ($desc = $this->table_obj->getDescription()) {
         $desc = "<div class='ilDclTableDescription'>{$desc}</div>";
     }
     $tpl->setContent($desc . $list->getHTML());
 }
 public function listRecords()
 {
     global $tpl, $lng, $ilToolbar;
     /**
      * @var $ilToolbar ilToolbarGUI
      * @var $ilToolbar ilToolbarGUI
      */
     // Show tables
     require_once "./Modules/DataCollection/classes/class.ilDataCollectionTable.php";
     if (ilObjDataCollection::_hasWriteAccess($this->parent_obj->ref_id)) {
         $tables = $this->parent_obj->object->getTables();
     } else {
         $tables = $this->parent_obj->object->getVisibleTables();
     }
     $options = array();
     foreach ($tables as $table) {
         $options[$table->getId()] = $table->getTitle();
     }
     $tpl->addCss("./Modules/DataCollection/css/dcl_reference_hover.css");
     $list = new ilDataCollectionRecordListTableGUI($this, "listRecords", $this->table_obj, $this->mode);
     $list->setExternalSegmentation(true);
     $list->setExternalSorting(true);
     $list->determineLimit();
     $list->determineOffsetAndOrder();
     $data = $this->table_obj->getPartialRecords($list->getOrderField(), $list->getOrderDirection(), $list->getLimit(), $list->getOffset(), $list->getFilter());
     $records = $data['records'];
     $total = $data['total'];
     $list->setMaxCount($total);
     $list->setRecordData($records);
     if (count($options) > 0) {
         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($this->ctrl->getFormActionByClass("ilDataCollectionRecordListGUI", "doTableSwitch"));
         $ilToolbar->addText($lng->txt("dcl_table"));
         $ilToolbar->addInputItem($table_selection);
         $ilToolbar->addFormButton($lng->txt('change'), 'doTableSwitch');
         $ilToolbar->addSeparator();
     }
     $permission_to_add_or_import = $this->table_obj->hasPermissionToAddRecord($this->parent_obj->ref_id) and $this->table_obj->hasCustomFields();
     if ($permission_to_add_or_import) {
         $this->ctrl->setParameterByClass("ildatacollectionrecordeditgui", "record_id", NULL);
         $add_new = ilLinkButton::getInstance();
         $add_new->setCaption("dcl_add_new_record");
         $add_new->setUrl($this->ctrl->getFormActionByClass("ildatacollectionrecordeditgui", "create"));
         //			$add_new->addCSSClass('emphsubmit');
         $ilToolbar->addButtonInstance($add_new);
     }
     if ($this->table_obj->getExportEnabled() or $this->table_obj->hasPermissionToFields($this->parent_obj->ref_id)) {
         $export = ilDataCollectionLinkButton::getInstance();
         $export->setCaption("dcl_export_table_excel");
         $export->setUrl($this->ctrl->getFormActionByClass("ildatacollectionrecordlistgui", "exportExcel"));
         if (count($this->table_obj->getExportableFields()) == 0 or $total == 0) {
             $export->setUseWrapper(true);
             $export->setDisabled(true);
             $export->addAttribute('data-toggle', 'datacollection-tooltip', true);
             $export->addAttribute('data-placement', 'bottom', true);
             $export->addAttribute('title', $lng->txt('dcl_no_exportable_fields_or_no_data'), true);
         }
         $ilToolbar->addButtonInstance($export);
     }
     if ($permission_to_add_or_import) {
         $this->ctrl->setParameterByClass("ildatacollectionrecordeditgui", "record_id", NULL);
         $import = ilLinkButton::getInstance();
         $import->setCaption("dcl_import_records .xls");
         $import->setUrl($this->ctrl->getFormActionByClass("ildatacollectionrecordlistgui", "showImportExcel"));
         $ilToolbar->addButtonInstance($import);
     }
     // requested not to implement this way...
     //$tpl->addJavaScript("Modules/DataCollection/js/fastTableSwitcher.js");
     if (count($this->table_obj->getRecordFields()) == 0) {
         ilUtil::sendInfo($lng->txt("dcl_no_fields_yet") . " " . ($this->table_obj->hasPermissionToFields($this->parent_obj->ref_id) ? $lng->txt("dcl_create_fields") : ""));
     }
     $tpl->getStandardTemplate();
     $tpl->setPermanentLink("dcl", $this->parent_obj->ref_id);
     if ($desc = $this->table_obj->getDescription()) {
         $desc = "<div class='ilDclTableDescription'>{$desc}</div>";
     }
     $tpl->setContent($desc . $list->getHTML());
 }
 /**
  * Custom checks for the form input
  * @param $a_mode 'create' | 'update'
  * @return bool
  */
 protected function checkInput($a_mode)
 {
     global $lng;
     $return = $this->form->checkInput();
     // Title of table must be unique in one DC
     if ($a_mode == 'create') {
         if ($title = $this->form->getInput('title')) {
             if (ilObjDataCollection::_hasTableByTitle($title, $this->obj_id)) {
                 $inputObj = $this->form->getItemByPostVar('title');
                 $inputObj->setAlert($lng->txt("dcl_table_title_unique"));
                 $return = false;
             }
         }
     }
     if (!$return) {
         ilUtil::sendFailure($lng->txt("form_input_not_valid"));
     }
     return $return;
 }
 /**
  * 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());
     }
 }
Ejemplo n.º 5
0
 /**
  * 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
  *
  * @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->form->checkInput()) {
         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->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());
     }
 }
 /**
  * @return bool
  */
 protected function checkAccess()
 {
     $ref_id = $this->parent_obj->getDataCollectionObject()->getRefId();
     return ilObjDataCollection::_hasWriteAccess($ref_id);
 }
 /**
  * @param $ref int the reference id of the current datacollection object
  * @param $record ilDataCollectionRecord the record which will be deleted
  * @return bool
  */
 public function hasPermissionToDeleteRecord($ref, $record)
 {
     return $this->getDeletePerm() && ilObjDataCollection::_hasReadAccess($ref) && $this->checkEditByOwner($record) && $this->checkLimit() || ilObjDataCollection::_hasWriteAccess($ref);
 }
 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());
 }
 /**
  * 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();
 }
 /**
  * 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];
             }
     }
 }
 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 (ilObjDataCollection::_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();
     }
 }