ILIAS  release_4-4 Revision
ilDataCollectionRecordEditGUI Class Reference

Class ilDataCollectionRecordEditGUI. More...

+ Collaboration diagram for ilDataCollectionRecordEditGUI:

Public Member Functions

 __construct (ilObjDataCollectionGUI $parent_obj)
 Constructor. More...
 
 executeCommand ()
 execute command More...
 
 create ()
 create Record More...
 
 edit ()
 edit Record More...
 
 confirmDelete ()
 confirmDelete More...
 
 cancelDelete ()
 cancelDelete More...
 
 delete ()
 
 initForm ()
 init Form More...
 
 getValues ()
 get Values More...
 
 cancelUpdate ()
 
 cancelSave ()
 
 save ()
 save Record More...
 
 searchObjects ()
 This function is only used by the ajax request if searching for ILIAS references. More...
 

Private Member Functions

 accessDenied ()
 
 sendFailure ()
 
 parseSearchResults ($a_res)
 Parse search results. More...
 

Private Attributes

 $record_id
 
 $table_id
 
 $table
 
 $parent_obj
 

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

ilDataCollectionRecordEditGUI::__construct ( ilObjDataCollectionGUI  $parent_obj)

Constructor.

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

References $_GET, $_REQUEST, $parent_obj, and ilDataCollectionCache\getTableCache().

31  {
32  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
33  $this->form = new ilPropertyFormGUI();
34  $this->parent_obj = $parent_obj;
35  $this->record_id = $_REQUEST['record_id'];
36  $this->table_id = $_GET['table_id'];
37 
38  include_once("class.ilDataCollectionDatatype.php");
39  if ($_REQUEST['table_id']) {
40  $this->table_id = $_REQUEST['table_id'];
41  }
42 
43  $this->table = ilDataCollectionCache::getTableCache($this->table_id);
44  }
This class represents a property form user interface.
$_GET["client_id"]
if($_REQUEST['ilias_path']) define('ILIAS_HTTP_PATH' $_REQUEST['ilias_path']
Definition: index.php:7
+ Here is the call graph for this function:

Member Function Documentation

◆ accessDenied()

ilDataCollectionRecordEditGUI::accessDenied ( )
private

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

References $tpl.

Referenced by delete(), and save().

401  {
402  global $tpl;
403  $tpl->setContent("Access denied");
404  }
if(isset($_FILES['img_file']['size']) && $_FILES['img_file']['size'] > 0) $tpl
+ Here is the caller graph for this function:

◆ cancelDelete()

ilDataCollectionRecordEditGUI::cancelDelete ( )

cancelDelete

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

References $ilCtrl.

116  {
117  global $ilCtrl;
118 
119  $ilCtrl->redirectByClass("ildatacollectionrecordlistgui", "listRecords");
120  }
global $ilCtrl
Definition: ilias.php:18

◆ cancelSave()

ilDataCollectionRecordEditGUI::cancelSave ( )

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

References cancelUpdate().

+ Here is the call graph for this function:

◆ cancelUpdate()

ilDataCollectionRecordEditGUI::cancelUpdate ( )

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

References $ilCtrl.

Referenced by cancelSave().

280  {
281  global $ilCtrl;
282  $ilCtrl->redirectByClass("ildatacollectionrecordlistgui", "listRecords");
283  }
global $ilCtrl
Definition: ilias.php:18
+ Here is the caller graph for this function:

◆ confirmDelete()

ilDataCollectionRecordEditGUI::confirmDelete ( )

confirmDelete

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

References $ilCtrl, $lng, $tpl, and ilDataCollectionCache\getRecordCache().

93  {
94  global $ilCtrl, $lng, $tpl;
95 
96  include_once './Services/Utilities/classes/class.ilConfirmationGUI.php';
97  $conf = new ilConfirmationGUI();
98  $conf->setFormAction($ilCtrl->getFormAction($this));
99  $conf->setHeaderText($lng->txt('dcl_confirm_delete_record'));
100 
101  $record = ilDataCollectionCache::getRecordCache($this->record_id);
102 
103  $conf->addItem('record_id', $record->getId(), implode(", ", $record->getRecordFieldValues()));
104  $conf->addHiddenItem('table_id', $this->table_id);
105 
106  $conf->setConfirm($lng->txt('delete'), 'delete');
107  $conf->setCancel($lng->txt('cancel'), 'cancelDelete');
108 
109  $tpl->setContent($conf->getHTML());
110  }
static getRecordCache($record_id=0)
global $ilCtrl
Definition: ilias.php:18
if(isset($_FILES['img_file']['size']) && $_FILES['img_file']['size'] > 0) $tpl
global $lng
Definition: privfeed.php:40
Confirmation screen class.
+ Here is the call graph for this function:

◆ create()

ilDataCollectionRecordEditGUI::create ( )

create Record

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

References $ilCtrl, $tpl, and initForm().

68  {
69  global $ilCtrl, $tpl;
70 
71  $this->initForm();
72 
73  $tpl->setContent($this->form->getHTML());
74  }
global $ilCtrl
Definition: ilias.php:18
if(isset($_FILES['img_file']['size']) && $_FILES['img_file']['size'] > 0) $tpl
+ Here is the call graph for this function:

◆ delete()

ilDataCollectionRecordEditGUI::delete ( )

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

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

126  {
127  global $ilCtrl, $lng;
128  $record = ilDataCollectionCache::getRecordCache($this->record_id);
129 
130  if (! $this->table->hasPermissionToDeleteRecord($this->parent_obj->ref_id, $record)) {
131  $this->accessDenied();
132 
133  return;
134  }
135 
136  $record->doDelete();
137  ilUtil::sendSuccess($lng->txt("dcl_record_deleted"), true);
138  $ilCtrl->redirectByClass("ildatacollectionrecordlistgui", "listRecords");
139  }
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
static getRecordCache($record_id=0)
global $ilCtrl
Definition: ilias.php:18
global $lng
Definition: privfeed.php:40
+ Here is the call graph for this function:

◆ edit()

ilDataCollectionRecordEditGUI::edit ( )

edit Record

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

References $ilCtrl, $tpl, getValues(), and initForm().

80  {
81  global $tpl, $ilCtrl;
82 
83  $this->initForm("edit");
84  $this->getValues();
85 
86  $tpl->setContent($this->form->getHTML());
87  }
global $ilCtrl
Definition: ilias.php:18
if(isset($_FILES['img_file']['size']) && $_FILES['img_file']['size'] > 0) $tpl
+ Here is the call graph for this function:

◆ executeCommand()

ilDataCollectionRecordEditGUI::executeCommand ( )

execute command

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

References $cmd, and $ilCtrl.

50  {
51  global $ilCtrl;
52 
53  $cmd = $ilCtrl->getCmd();
54  switch ($cmd) {
55  default:
56  $this->$cmd();
57  break;
58  }
59 
60  return true;
61  }
$cmd
Definition: sahs_server.php:35
global $ilCtrl
Definition: ilias.php:18

◆ getValues()

ilDataCollectionRecordEditGUI::getValues ( )

get Values

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

References $img, ilObjMediaObject\_lookupItemPath(), ilDataCollectionCache\getRecordCache(), and ilDataCollectionDatatype\INPUTFORMAT_MOB.

Referenced by edit().

251  {
252 
253  //Get Record-Values
254  $record_obj = ilDataCollectionCache::getRecordCache($this->record_id);
255 
256  //Get Table Field Definitions
257  $allFields = $this->table->getFields();
258 
259  $values = array();
260  foreach ($allFields as $field) {
261  $value = $record_obj->getRecordFieldFormInput($field->getId());
262  $values['field_' . $field->getId()] = $value;
263  if ($field->getDatatypeId() == ilDataCollectionDatatype::INPUTFORMAT_MOB) {
265  if ($value) {
266  $this->form->getItemByPostVar('field_' . $field->getId())->setImage($img);
267  }
268  }
269  }
270 
271  $this->form->setValuesByArray($values);
272 
273  return true;
274  }
static getRecordCache($record_id=0)
static _lookupItemPath($a_mob_id, $a_url_encode=false, $a_web=true, $a_purpose="")
Get path for item with specific purpose.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ initForm()

ilDataCollectionRecordEditGUI::initForm ( )

init Form

Parameters
string$a_modevalues: create | edit

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

References $ilCtrl, $lng, $options, $tpl, 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().

147  {
148  global $lng, $ilCtrl, $tpl;
149 
150  //table_id
151  $hidden_prop = new ilHiddenInputGUI("table_id");
152  $hidden_prop->setValue($this->table_id);
153  $this->form->addItem($hidden_prop);
154 
155  $ilCtrl->setParameter($this, "record_id", $this->record_id);
156  $this->form->setFormAction($ilCtrl->getFormAction($this));
157  $allFields = $this->table->getRecordFields();
158 
159  $inline_css = '';
160  foreach ($allFields as $field) {
162 
163  if ($field->getDatatypeId() == ilDataCollectionDatatype::INPUTFORMAT_REFERENCE) {
164  $fieldref = $field->getFieldRef();
165  $reffield = ilDataCollectionCache::getFieldCache($fieldref);
166  $options = array();
167  if (! $field->isNRef()) {
168  $options[""] = $lng->txt('dcl_please_select');
169  }
170  $reftable = ilDataCollectionCache::getTableCache($reffield->getTableId());
171  foreach ($reftable->getRecords() as $record) {
172  switch($reffield->getDatatypeId()) {
174  $file_obj = new ilObjFile($record->getRecordFieldValue($fieldref), false);
175  $options[$record->getId()] = $file_obj->getFileName();
176  break;
178  $media_obj = new ilObjMediaObject($record->getRecordFieldValue($fieldref), false);
179  $options[$record->getId()] = $media_obj->getTitle();
180  break;
182  $options[$record->getId()] = $record->getRecordFieldSingleHTML($fieldref);
183  break;
184  default:
185  $options[$record->getId()] = $record->getRecordFieldValue($fieldref);
186  break;
187  }
188 
189  }
190  asort($options);
191  $item->setOptions($options);
192  if($item instanceof ilMultiSelectInputGUI)
193  {
194  $item->setWidth(400);
195  $item->setHeight(100);
196  $inline_css .= 'div#'.$item->getFieldId().'{resize:both;} ';
197  }
198  }
199  $tpl->addInlineCss($inline_css);
200 
201  if ($this->record_id) {
202  $record = ilDataCollectionCache::getRecordCache($this->record_id);
203  }
204 
205  $item->setRequired($field->getRequired());
206  //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.
207  if ($field->getDatatypeId() == ilDataCollectionDatatype::INPUTFORMAT_FILE
208  || $field->getDatatypeId() == ilDataCollectionDatatype::INPUTFORMAT_MOB
209  ) {
210  if ($this->record_id && $record->getId()) {
211  $field_value = $record->getRecordFieldValue($field->getId());
212  if ($field_value) {
213  $item->setRequired(false);
214  }
215  }
216  }
217 
218  if (! ilObjDataCollection::_hasWriteAccess($this->parent_obj->ref_id) && $field->getLocked()) {
219  $item->setDisabled(true);
220  }
221  $this->form->addItem($item);
222  }
223 
224  // Add possibility to change the owner in edit mode
225  if ($this->record_id) {
226  $ownerField = $this->table->getField('owner');
227  $inputfield = ilDataCollectionDatatype::getInputField($ownerField);
228  $this->form->addItem($inputfield);
229  }
230 
231  // save and cancel commands
232  if (isset($this->record_id)) {
233  $this->form->setTitle($lng->txt("dcl_update_record"));
234  $this->form->addCommandButton("save", $lng->txt("dcl_update_record"));
235  $this->form->addCommandButton("cancelUpdate", $lng->txt("cancel"));
236  } else {
237  $this->form->setTitle($lng->txt("dcl_add_new_record"));
238  $this->form->addCommandButton("save", $lng->txt("save"));
239  $this->form->addCommandButton("cancelSave", $lng->txt("cancel"));
240  }
241 
242  $ilCtrl->setParameter($this, "table_id", $this->table_id);
243  $ilCtrl->setParameter($this, "record_id", $this->record_id);
244  }
static getRecordCache($record_id=0)
global $ilCtrl
Definition: ilias.php:18
This class represents a hidden form property in a property form.
This class represents a multi selection list property in a property form.
if(!is_array($argv)) $options
Class ilObjFile.
if(isset($_FILES['img_file']['size']) && $_FILES['img_file']['size'] > 0) $tpl
Class ilObjMediaObject.
static getInputField(ilDataCollectionField $field)
global $lng
Definition: privfeed.php:40
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ parseSearchResults()

ilDataCollectionRecordEditGUI::parseSearchResults (   $a_res)
private

Parse search results.

Parameters
ilObject[]$a_res
Returns
array

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

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

Referenced by searchObjects().

474  {
475  foreach ($a_res as $obj_id => $references) {
476  $r['title'] = ilObject::_lookupTitle($obj_id);
477  $r['desc'] = ilObject::_lookupDescription($obj_id);
478  $r['obj_id'] = $obj_id;
479  $r['refs'] = $references;
480 
481  $rows[] = $r;
482  }
483 
484  return $rows ? $rows : array();
485  }
static _lookupTitle($a_id)
lookup object title
static _lookupDescription($a_id)
lookup object description
$r
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ save()

ilDataCollectionRecordEditGUI::save ( )

save Record

Parameters
string$a_modevalues: create | edit

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

References $_POST, $ilCtrl, $ilUser, $lng, $tpl, ilObjDataCollection\_hasWriteAccess(), ilObjUser\_lookupId(), accessDenied(), ilDataCollectionCache\getRecordCache(), IL_CAL_DATETIME, IL_CAL_UNIX, initForm(), ilDataCollectionDatatype\INPUTFORMAT_MOB, sendFailure(), ilUtil\sendFailure(), ilObjDataCollection\sendNotification(), and ilUtil\sendSuccess().

299  {
300  global $tpl, $ilUser, $lng, $ilCtrl;
301 
302  $this->initForm();
303  if ($this->form->checkInput()) {
304  $record_obj = ilDataCollectionCache::getRecordCache($this->record_id);
305  $date_obj = new ilDateTime(time(), IL_CAL_UNIX);
306 
307  $record_obj->setTableId($this->table_id);
308  $record_obj->setLastUpdate($date_obj->get(IL_CAL_DATETIME));
309  $record_obj->setLastEditBy($ilUser->getId());
310 
311  $create_mode = false;
312 
313  if (ilObjDataCollection::_hasWriteAccess($this->parent_obj->ref_id)) {
314  $all_fields = $this->table->getRecordFields();
315  } else {
316  $all_fields = $this->table->getEditableFields();
317  }
318 
319  $fail = "";
320  //Check if we can create this record.
321  foreach ($all_fields as $field) {
322  try {
323  $value = $this->form->getInput("field_" . $field->getId());
324  $field->checkValidity($value, $this->record_id);
325  } catch (ilDataCollectionInputException $e) {
326  $fail .= $field->getTitle() . ": " . $e . "<br>";
327  }
328  }
329 
330  if ($fail) {
331  ilUtil::sendFailure($fail, true);
332  $this->sendFailure();
333 
334  return;
335  }
336 
337  if (! isset($this->record_id)) {
338  if (! ($this->table->hasPermissionToAddRecord($this->parent_obj->ref_id))) {
339  $this->accessDenied();
340 
341  return;
342  }
343  $record_obj->setOwner($ilUser->getId());
344  $record_obj->setCreateDate($date_obj->get(IL_CAL_DATETIME));
345  $record_obj->setTableId($this->table_id);
346  $record_obj->doCreate();
347  $this->record_id = $record_obj->getId();
348  $create_mode = true;
349  } else {
350  if (! $record_obj->hasPermissionToEdit($this->parent_obj->ref_id)) {
351  $this->accessDenied();
352 
353  return;
354  }
355  }
356  //edit values, they are valid we already checked them above
357  foreach ($all_fields as $field) {
358  $value = $this->form->getInput("field_" . $field->getId());
359  //deletion flag on MOB inputs.
360  if ($field->getDatatypeId() == ilDataCollectionDatatype::INPUTFORMAT_MOB
361  && $this->form->getItemByPostVar("field_" . $field->getId())->getDeletionFlag()
362  ) {
363  $value = - 1;
364  }
365  $record_obj->setRecordFieldValue($field->getId(), $value);
366  }
367 
368  // Do we need to set a new owner for this record?
369  if (! $create_mode) {
370  $owner_id = ilObjUser::_lookupId($_POST['field_owner']);
371  if (! $owner_id) {
372  ilUtil::sendFailure($lng->txt('user_not_known'));
373  $this->sendFailure();
374 
375  return;
376  }
377  $record_obj->setOwner($owner_id);
378  }
379 
380  if ($create_mode) {
381  ilObjDataCollection::sendNotification("new_record", $this->table_id, $record_obj->getId());
382  }
383 
384  $record_obj->doUpdate();
385  ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true);
386 
387  $ilCtrl->setParameter($this, "table_id", $this->table_id);
388  $ilCtrl->setParameter($this, "record_id", $this->record_id);
389  $ilCtrl->redirectByClass("ildatacollectionrecordlistgui", "listRecords");
390  } else {
391  global $tpl;
392  $this->form->setValuesByPost();
393  $tpl->setContent($this->form->getHTML());
394  }
395  }
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
static getRecordCache($record_id=0)
$_POST['username']
Definition: cron.php:12
const IL_CAL_DATETIME
static _lookupId($a_user_str)
lookup id by login
const IL_CAL_UNIX
global $ilCtrl
Definition: ilias.php:18
Date and time handling
if(isset($_FILES['img_file']['size']) && $_FILES['img_file']['size'] > 0) $tpl
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
global $ilUser
Definition: imgupload.php:15
global $lng
Definition: privfeed.php:40
static sendNotification($a_action, $a_table_id, $a_record_id=NULL)
+ Here is the call graph for this function:

◆ searchObjects()

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 420 of file class.ilDataCollectionRecordEditGUI.php.

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

420  {
421  global $lng;
422 
423  $search = $_POST['search_for'];
424  $dest = $_POST['dest'];
425  $html = "";
426  include_once './Services/Search/classes/class.ilQueryParser.php';
427  $query_parser = new ilQueryParser($search);
428  $query_parser->setMinWordLength(1, true);
429  $query_parser->setCombination(QP_COMBINATION_AND);
430  $query_parser->parse();
431  if (! $query_parser->validate()) {
432  $html .= $query_parser->getMessage() . "<br />";
433  }
434 
435  // only like search since fulltext does not support search with less than 3 characters
436  include_once 'Services/Search/classes/Like/class.ilLikeObjectSearch.php';
437  $object_search = new ilLikeObjectSearch($query_parser);
438  $res = $object_search->performSearch();
439  //$res->setRequiredPermission('copy');
440  $res->filter(ROOT_FOLDER_ID, true);
441 
442  if (! count($results = $res->getResultsByObjId())) {
443  $html .= $lng->txt('dcl_no_search_results_found_for') . ' ' . $search . "<br />";
444  }
446 
447  foreach ($results as $entry) {
448  $tpl = new ilTemplate("tpl.dcl_tree.html", true, true, "Modules/DataCollection");
449  foreach ((array)$entry['refs'] as $reference) {
450  include_once './Services/Tree/classes/class.ilPathGUI.php';
451  $path = new ilPathGUI();
452 
453  $tpl->setCurrentBlock('result');
454  $tpl->setVariable('RESULT_PATH', $path->getPath(ROOT_FOLDER_ID, $reference) . " ยป " . $entry['title']);
455  $tpl->setVariable('RESULT_REF', $reference);
456  $tpl->setVariable('FIELD_ID', $dest);
457  $tpl->parseCurrentBlock();
458  }
459  $html .= $tpl->get();
460  }
461 
462  echo $html;
463  exit;
464  }
Creates a path for a start and endnode.
exit
Definition: login.php:54
$_POST['username']
Definition: cron.php:12
special template class to simplify handling of ITX/PEAR
if(isset($_FILES['img_file']['size']) && $_FILES['img_file']['size'] > 0) $tpl
$results
global $lng
Definition: privfeed.php:40
$path
Definition: index.php:22
const QP_COMBINATION_AND
+ Here is the call graph for this function:

◆ sendFailure()

ilDataCollectionRecordEditGUI::sendFailure ( )
private

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

References $tpl.

Referenced by save().

410  {
411  global $tpl;
412  $this->form->setValuesByPost();
413  $tpl->setContent($this->form->getHTML());
414  }
if(isset($_FILES['img_file']['size']) && $_FILES['img_file']['size'] > 0) $tpl
+ Here is the caller graph for this function:

Field Documentation

◆ $parent_obj

ilDataCollectionRecordEditGUI::$parent_obj
private

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

Referenced by __construct().

◆ $record_id

ilDataCollectionRecordEditGUI::$record_id
private

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

◆ $table

ilDataCollectionRecordEditGUI::$table
private

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

◆ $table_id

ilDataCollectionRecordEditGUI::$table_id
private

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


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