ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
ilDataCollectionRecordEditGUI Class Reference

Class ilDataCollectionRecordEditGUI. More...

+ Collaboration diagram for ilDataCollectionRecordEditGUI:

Public Member Functions

 __construct (ilObjDataCollectionGUI $parent_obj)
 executeCommand ()
 create ()
 edit ()
 confirmDelete ()
 cancelDelete ()
 delete ()
 getRecordData ($record_id=0)
 Return All fields and values from a record ID.
 initForm ()
 init Form
 setFormValues ()
 Set values from object to form.
 cancelUpdate ()
 Cancel Update.
 cancelSave ()
 Cancel Save.
 save ()
 Save record.
 searchObjects ()
 This function is only used by the ajax request if searching for ILIAS references.

Data Fields

const REDIRECT_RECORD_LIST = 1
 Possible redirects after saving/updating a record - use GET['redirect'] to set constants.
const REDIRECT_DETAIL = 2

Protected Member Functions

 checkAndPerformRedirect ($force_redirect=false)
 Checkes to what view (table or detail) should be redirected and performs redirect.
 accessDenied ()
 sendFailure ($message)
 parseSearchResults ($a_res)
 Parse search results.

Protected Attributes

 $record_id
 $table_id
 $table
 $parent_obj
 $record
 $ctrl
 $tpl
 $lng
 $user
 $form

Detailed Description

Constructor & Destructor Documentation

ilDataCollectionRecordEditGUI::__construct ( ilObjDataCollectionGUI  $parent_obj)
Parameters
ilObjDataCollectionGUI$parent_obj

Definition at line 77 of file class.ilDataCollectionRecordEditGUI.php.

References $_REQUEST, $ilCtrl, $ilUser, $lng, $parent_obj, and $tpl.

{
global $ilCtrl, $tpl, $lng, $ilUser;
$this->ctrl = $ilCtrl;
$this->tpl = $tpl;
$this->lng = $lng;
$this->user = $ilUser;
$this->parent_obj = $parent_obj;
$this->record_id = $_REQUEST['record_id'];
$this->table_id = $_REQUEST['table_id'];
}

Member Function Documentation

ilDataCollectionRecordEditGUI::accessDenied ( )
protected

Definition at line 520 of file class.ilDataCollectionRecordEditGUI.php.

References exit, and sendFailure().

Referenced by delete(), executeCommand(), and save().

{
if (! $this->ctrl->isAsynch()) {
ilUtil::sendFailure($this->lng->txt('dcl_msg_no_perm_edit'), true);
$this->ctrl->redirectByClass('ildatacollectionrecordlistgui', 'listRecords');
} else {
echo $this->lng->txt('dcl_msg_no_perm_edit');
exit();
}
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilDataCollectionRecordEditGUI::cancelDelete ( )

Definition at line 162 of file class.ilDataCollectionRecordEditGUI.php.

{
$this->ctrl->redirectByClass("ildatacollectionrecordlistgui", "listRecords");
}
ilDataCollectionRecordEditGUI::cancelSave ( )

Cancel Save.

Definition at line 369 of file class.ilDataCollectionRecordEditGUI.php.

References cancelUpdate().

{
$this->cancelUpdate();
}

+ Here is the call graph for this function:

ilDataCollectionRecordEditGUI::cancelUpdate ( )

Cancel Update.

Definition at line 361 of file class.ilDataCollectionRecordEditGUI.php.

References checkAndPerformRedirect().

Referenced by cancelSave().

{
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilDataCollectionRecordEditGUI::checkAndPerformRedirect (   $force_redirect = false)
protected

Checkes to what view (table or detail) should be redirected and performs redirect.

Definition at line 502 of file class.ilDataCollectionRecordEditGUI.php.

References $_GET.

Referenced by cancelUpdate(), and save().

{
if ($force_redirect || (isset($_GET['redirect']) && ! $this->ctrl->isAsynch())) {
switch ((int)$_GET['redirect']) {
case self::REDIRECT_DETAIL:
$this->ctrl->setParameterByClass('ildatacollectionrecordviewgui', 'record_id', $this->record_id);
$this->ctrl->setParameterByClass('ildatacollectionrecordviewgui', 'table_id', $this->table_id);
$this->ctrl->redirectByClass("ildatacollectionrecordviewgui", "renderRecord");
break;
case self::REDIRECT_RECORD_LIST:
$this->ctrl->redirectByClass("ildatacollectionrecordlistgui", "listRecords");
break;
default:
$this->ctrl->redirectByClass("ildatacollectionrecordlistgui", "listRecords");
}
}
}

+ Here is the caller graph for this function:

ilDataCollectionRecordEditGUI::confirmDelete ( )

Definition at line 149 of file class.ilDataCollectionRecordEditGUI.php.

References $record, and ilDataCollectionCache\getRecordCache().

{
$conf = new ilConfirmationGUI();
$conf->setFormAction($this->ctrl->getFormAction($this));
$conf->setHeaderText($this->lng->txt('dcl_confirm_delete_record'));
$conf->addItem('record_id', $record->getId(), implode(", ", $record->getRecordFieldValues()));
$conf->addHiddenItem('table_id', $this->table_id);
$conf->setConfirm($this->lng->txt('delete'), 'delete');
$conf->setCancel($this->lng->txt('cancel'), 'cancelDelete');
$this->tpl->setContent($conf->getHTML());
}

+ Here is the call graph for this function:

ilDataCollectionRecordEditGUI::create ( )

Definition at line 124 of file class.ilDataCollectionRecordEditGUI.php.

References exit, and initForm().

{
$this->initForm();
if ($this->ctrl->isAsynch()) {
echo $this->form->getHTML();
exit();
} else {
$this->tpl->setContent("<script>ilDataCollection.strings.add_value='" . $this->lng->txt('add_value') . "';</script>"
. $this->form->getHTML());
}
}

+ Here is the call graph for this function:

ilDataCollectionRecordEditGUI::delete ( )

Definition at line 167 of file class.ilDataCollectionRecordEditGUI.php.

References $record, accessDenied(), ilDataCollectionCache\getRecordCache(), and ilUtil\sendSuccess().

{
if (! $this->table->hasPermissionToDeleteRecord($this->parent_obj->ref_id, $record)) {
$this->accessDenied();
return;
}
$record->doDelete();
ilUtil::sendSuccess($this->lng->txt("dcl_record_deleted"), true);
$this->ctrl->redirectByClass("ildatacollectionrecordlistgui", "listRecords");
}

+ Here is the call graph for this function:

ilDataCollectionRecordEditGUI::edit ( )

Definition at line 136 of file class.ilDataCollectionRecordEditGUI.php.

References exit, initForm(), and setFormValues().

{
$this->initForm();
$this->setFormValues();
if ($this->ctrl->isAsynch()) {
echo $this->form->getHTML();
exit();
} else {
$this->tpl->setContent("<script>ilDataCollection.strings.add_value='" . $this->lng->txt('add_value') . "';</script>"
. $this->form->getHTML());
}
}

+ Here is the call graph for this function:

ilDataCollectionRecordEditGUI::executeCommand ( )
Returns
bool

Definition at line 93 of file class.ilDataCollectionRecordEditGUI.php.

References $_GET, $cmd, accessDenied(), ilDataCollectionCache\getRecordCache(), ilDataCollectionCache\getTableCache(), and ilObjDataCollectionAccess\hasAddRecordAccess().

{
if($_GET['mode']) {
$this->ctrl->saveParameter($this, 'mode');
$this->ctrl->setParameterByClass("ildatacollectionrecordlistgui", "mode", $_GET['mode']);
}
$this->ctrl->saveParameter($this, 'redirect');
if ($this->record_id) {
$this->record = ilDataCollectionCache::getRecordCache($this->record_id);
if (!$this->record->hasPermissionToEdit($this->parent_obj->ref_id) OR !$this->record->hasPermissionToView($this->parent_obj->ref_id)) {
$this->accessDenied();
}
$this->table = $this->record->getTable();
$this->table_id = $this->table->getId();
} else {
$this->table = ilDataCollectionCache::getTableCache($this->table_id);
$this->accessDenied();
}
}
$cmd = $this->ctrl->getCmd();
switch ($cmd) {
default:
$this->$cmd();
break;
}
return true;
}

+ Here is the call graph for this function:

ilDataCollectionRecordEditGUI::getRecordData (   $record_id = 0)

Return All fields and values from a record ID.

If this method is requested over AJAX, data is returned in JSON format

Parameters
int$record_id
Returns
array

Definition at line 190 of file class.ilDataCollectionRecordEditGUI.php.

References $_GET, $record, $record_id, exit, and ilDataCollectionCache\getRecordCache().

{
$record_id = ($record_id) ? $record_id : $_GET['record_id'];
$return = array();
if ($record_id) {
if (is_object($record)) {
$return = $record->getRecordFieldValues();
}
}
if ($this->ctrl->isAsynch()) {
echo json_encode($return);
exit();
}
return $return;
}

+ Here is the call graph for this function:

ilDataCollectionRecordEditGUI::initForm ( )

init Form

Definition at line 211 of file class.ilDataCollectionRecordEditGUI.php.

References $_GET, $options, $record, ilObjDataCollection\_hasWriteAccess(), ilDataCollectionCache\getFieldCache(), ilDataCollectionDatatype\getInputField(), ilDataCollectionCache\getRecordCache(), ilDataCollectionCache\getTableCache(), ilObject2\getTitle(), ilDataCollectionDatatype\INPUTFORMAT_DATETIME, ilDataCollectionDatatype\INPUTFORMAT_FILE, ilDataCollectionDatatype\INPUTFORMAT_MOB, and ilDataCollectionDatatype\INPUTFORMAT_REFERENCE.

Referenced by create(), edit(), and save().

{
$this->form = new ilPropertyFormGUI();
$prefix = ($this->ctrl->isAsynch()) ? 'dclajax' : 'dcl'; // Used by datacolleciton.js to select input elements
$this->form->setId($prefix . $this->table_id . $this->record_id);
$hidden_prop = new ilHiddenInputGUI("table_id");
$hidden_prop->setValue($this->table_id);
$this->form->addItem($hidden_prop);
if ($this->record_id) {
$hidden_prop = new ilHiddenInputGUI("record_id");
$hidden_prop->setValue($this->record_id);
$this->form->addItem($hidden_prop);
}
$this->ctrl->setParameter($this, "record_id", $this->record_id);
$this->form->setFormAction($this->ctrl->getFormAction($this));
$allFields = $this->table->getRecordFields();
$inline_css = '';
foreach ($allFields as $field) {
if ($item === NULL) {
continue; // Fields calculating values at runtime, e.g. ilDataCollectionFormulaField do not have input
}
if ($field->getDatatypeId() == ilDataCollectionDatatype::INPUTFORMAT_REFERENCE) {
$fieldref = $field->getFieldRef();
$reffield = ilDataCollectionCache::getFieldCache($fieldref);
$options = array();
if (! $field->isNRef()) {
$options[""] = $this->lng->txt('dcl_please_select');
}
$reftable = ilDataCollectionCache::getTableCache($reffield->getTableId());
foreach ($reftable->getRecords() as $record) {
// If the referenced field is MOB or FILE, we display the filename in the dropdown
switch($reffield->getDatatypeId()) {
$file_obj = new ilObjFile($record->getRecordFieldValue($fieldref), false);
$options[$record->getId()] = $file_obj->getFileName();
break;
$media_obj = new ilObjMediaObject($record->getRecordFieldValue($fieldref), false);
$options[$record->getId()] = $media_obj->getTitle();
break;
$options[$record->getId()] = $record->getRecordFieldSingleHTML($fieldref);
break;
default:
$options[$record->getId()] = $record->getRecordFieldValue($fieldref);
break;
}
}
asort($options);
$item->setOptions($options);
if ($field->getDatatypeId() == ilDataCollectionDatatype::INPUTFORMAT_REFERENCE) { // FSX use this to apply to MultiSelectInputGUI
// if (!$field->isNRef()) { // addCustomAttribute only defined for single selects
if ($reftable->hasPermissionToAddRecord($_GET['ref_id'])) {
$item->addCustomAttribute('data-ref="1"');
$item->addCustomAttribute('data-ref-table-id="' . $reftable->getId() . '"');
$item->addCustomAttribute('data-ref-field-id="' . $reffield->getId() . '"');
}
// }
}
if($item instanceof ilMultiSelectInputGUI){
$item->setWidth(400);
$item->setHeight(100);
$inline_css .= 'div#'.$item->getFieldId().'{resize:both;} ';
}
}
if ($this->record_id) {
}
$item->setRequired($field->getRequired());
//WORKAROUND. If field is from type file: if it's required but already has a value it is no longer required as the old value is taken as default without the form knowing about it.
if ($field->getDatatypeId() == ilDataCollectionDatatype::INPUTFORMAT_FILE
|| $field->getDatatypeId() == ilDataCollectionDatatype::INPUTFORMAT_MOB
) {
if ($this->record_id AND $record->getId()) {
$field_value = $record->getRecordFieldValue($field->getId());
if ($field_value) {
$item->setRequired(false);
}
}
// If this is an ajax request to return the form, input files are currently not supported
if ($this->ctrl->isAsynch()) {
$item->setDisabled(true);
}
}
if (! ilObjDataCollection::_hasWriteAccess($this->parent_obj->ref_id) && $field->getLocked()) {
$item->setDisabled(true);
}
$this->form->addItem($item);
}
$this->tpl->addInlineCss($inline_css);
// Add possibility to change the owner in edit mode
if ($this->record_id) {
$ownerField = $this->table->getField('owner');
$inputfield = ilDataCollectionDatatype::getInputField($ownerField);
$this->form->addItem($inputfield);
}
// save and cancel commands
if ($this->record_id) {
$this->form->setTitle($this->lng->txt("dcl_update_record"));
$this->form->addCommandButton("save", $this->lng->txt("dcl_update_record"));
if (! $this->ctrl->isAsynch()) {
$this->form->addCommandButton("cancelUpdate", $this->lng->txt("cancel"));
}
} else {
$this->form->setTitle($this->lng->txt("dcl_add_new_record"));
$this->form->addCommandButton("save", $this->lng->txt("save"));
if (! $this->ctrl->isAsynch()) {
$this->form->addCommandButton("cancelSave", $this->lng->txt("cancel"));
}
}
$this->ctrl->setParameter($this, "table_id", $this->table_id);
$this->ctrl->setParameter($this, "record_id", $this->record_id);
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilDataCollectionRecordEditGUI::parseSearchResults (   $a_res)
protected

Parse search results.

Parameters
ilObject[]$a_res
Returns
array

Definition at line 601 of file class.ilDataCollectionRecordEditGUI.php.

References ilObject\_lookupDescription(), and ilObject\_lookupTitle().

Referenced by searchObjects().

{
$rows = array();
foreach ($a_res as $obj_id => $references) {
$r = array();
$r['title'] = ilObject::_lookupTitle($obj_id);
$r['desc'] = ilObject::_lookupDescription($obj_id);
$r['obj_id'] = $obj_id;
$r['refs'] = $references;
$rows[] = $r;
}
return $rows;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilDataCollectionRecordEditGUI::save ( )

Save record.

Definition at line 377 of file class.ilDataCollectionRecordEditGUI.php.

References $_POST, ilObjDataCollection\_hasWriteAccess(), ilObjUser\_lookupId(), accessDenied(), checkAndPerformRedirect(), exit, ilDataCollectionCache\getRecordCache(), IL_CAL_DATETIME, IL_CAL_UNIX, initForm(), ilDataCollectionDatatype\INPUTFORMAT_FILE, ilDataCollectionDatatype\INPUTFORMAT_MOB, sendFailure(), ilObjDataCollection\sendNotification(), ilUtil\sendSuccess(), and setFormValues().

{
$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);
$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());
switch (true) {
//deletion flag on MOB inputs.
case ($field->getDatatypeId() == ilDataCollectionDatatype::INPUTFORMAT_MOB
&& $this->form->getItemByPostVar("field_" . $field->getId())->getDeletionFlag()):
$value = - 1;
$record_obj->setRecordFieldValue($field->getId(), $value);
break;
// mantis 0018064
case ($field->getDatatypeId() == ilDataCollectionDatatype::INPUTFORMAT_FILE && $value['tmp_name']):
$record_obj->setRecordFieldValue($field->getId(), $value);
break;
default:
$record_obj->setRecordFieldValue($field->getId(), $value);
break;
}
}
// 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);
}
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());
}
}
}

+ Here is the call graph for this function:

ilDataCollectionRecordEditGUI::searchObjects ( )

This function is only used by the ajax request if searching for ILIAS references.

It builds the html for the search results.

Definition at line 550 of file class.ilDataCollectionRecordEditGUI.php.

References $_POST, $path, $res, $results, $tpl, exit, parseSearchResults(), and QP_COMBINATION_AND.

{
$search = $_POST['search_for'];
$dest = $_POST['dest'];
$html = "";
include_once './Services/Search/classes/class.ilQueryParser.php';
$query_parser = new ilQueryParser($search);
$query_parser->setMinWordLength(1, true);
$query_parser->setCombination(QP_COMBINATION_AND);
$query_parser->parse();
if (! $query_parser->validate()) {
$html .= $query_parser->getMessage() . "<br />";
}
// only like search since fulltext does not support search with less than 3 characters
include_once 'Services/Search/classes/Like/class.ilLikeObjectSearch.php';
$object_search = new ilLikeObjectSearch($query_parser);
$res = $object_search->performSearch();
//$res->setRequiredPermission('copy');
$res->filter(ROOT_FOLDER_ID, true);
if (! count($results = $res->getResultsByObjId())) {
$html .= $this->lng->txt('dcl_no_search_results_found_for') . ' ' . $search . "<br />";
}
foreach ($results as $entry) {
$tpl = new ilTemplate("tpl.dcl_tree.html", true, true, "Modules/DataCollection");
foreach ((array)$entry['refs'] as $reference) {
include_once './Services/Tree/classes/class.ilPathGUI.php';
$path = new ilPathGUI();
$tpl->setCurrentBlock('result');
$tpl->setVariable('RESULT_PATH', $path->getPath(ROOT_FOLDER_ID, $reference) . " ยป " . $entry['title']);
$tpl->setVariable('RESULT_REF', $reference);
$tpl->setVariable('FIELD_ID', $dest);
$tpl->parseCurrentBlock();
}
$html .= $tpl->get();
}
echo $html;
}

+ Here is the call graph for this function:

ilDataCollectionRecordEditGUI::sendFailure (   $message)
protected
Parameters
$message

Definition at line 534 of file class.ilDataCollectionRecordEditGUI.php.

References exit.

Referenced by accessDenied(), and save().

{
$keep = ($this->ctrl->isAsynch()) ? false : true;
$this->form->setValuesByPost();
if ($this->ctrl->isAsynch()) {
echo $this->tpl->getMessageHTML($message, 'failure') . $this->form->getHTML();
exit();
} else {
ilUtil::sendFailure($message, $keep);
$this->tpl->setContent($this->form->getHTML());
}
}

+ Here is the caller graph for this function:

ilDataCollectionRecordEditGUI::setFormValues ( )

Set values from object to form.

Returns
bool

Definition at line 341 of file class.ilDataCollectionRecordEditGUI.php.

References ilDataCollectionCache\getRecordCache().

Referenced by edit(), and save().

{
//Get Record-Values
$record_obj = ilDataCollectionCache::getRecordCache($this->record_id);
//Get Table Field Definitions
$allFields = $this->table->getFields();
$values = array();
foreach ($allFields as $field) {
$value = $record_obj->getRecordFieldFormInput($field->getId());
$values['field_' . $field->getId()] = $value;
}
$values['record_id'] = $record_obj->getId();
$this->form->setValuesByArray($values);
return true;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Field Documentation

ilDataCollectionRecordEditGUI::$ctrl
protected

Definition at line 55 of file class.ilDataCollectionRecordEditGUI.php.

ilDataCollectionRecordEditGUI::$form
protected

Definition at line 71 of file class.ilDataCollectionRecordEditGUI.php.

ilDataCollectionRecordEditGUI::$lng
protected

Definition at line 63 of file class.ilDataCollectionRecordEditGUI.php.

Referenced by __construct().

ilDataCollectionRecordEditGUI::$parent_obj
protected

Definition at line 47 of file class.ilDataCollectionRecordEditGUI.php.

Referenced by __construct().

ilDataCollectionRecordEditGUI::$record
protected
ilDataCollectionRecordEditGUI::$record_id
protected

Definition at line 35 of file class.ilDataCollectionRecordEditGUI.php.

Referenced by getRecordData().

ilDataCollectionRecordEditGUI::$table
protected

Definition at line 43 of file class.ilDataCollectionRecordEditGUI.php.

ilDataCollectionRecordEditGUI::$table_id
protected

Definition at line 39 of file class.ilDataCollectionRecordEditGUI.php.

ilDataCollectionRecordEditGUI::$tpl
protected

Definition at line 59 of file class.ilDataCollectionRecordEditGUI.php.

Referenced by __construct(), and searchObjects().

ilDataCollectionRecordEditGUI::$user
protected

Definition at line 67 of file class.ilDataCollectionRecordEditGUI.php.

const ilDataCollectionRecordEditGUI::REDIRECT_DETAIL = 2
const ilDataCollectionRecordEditGUI::REDIRECT_RECORD_LIST = 1

Possible redirects after saving/updating a record - use GET['redirect'] to set constants.

Definition at line 30 of file class.ilDataCollectionRecordEditGUI.php.


The documentation for this class was generated from the following file: