ILIAS  release_4-4 Revision
class.ilRbacLogTableGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 include_once './Services/Table/classes/class.ilTable2GUI.php';
5 include_once "Services/AccessControl/classes/class.ilRbacLog.php";
6 
19 {
20  protected $operations = array();
21  protected $filter = array();
22  protected $action_map = array();
23 
24  function __construct($a_parent_obj, $a_parent_cmd, $a_ref_id)
25  {
26  global $ilCtrl, $lng, $ilAccess, $lng;
27 
28  $this->setId("rbaclog");
29  $this->ref_id = $a_ref_id;
30 
31  parent::__construct($a_parent_obj, $a_parent_cmd);
32  $this->setTitle($lng->txt("rbac_log"));
33  $this->setLimit(5);
34 
35  $this->addColumn($this->lng->txt("date"), "", "15%");
36  $this->addColumn($this->lng->txt("user"), "", "15%");
37  $this->addColumn($this->lng->txt("action"), "", "20%");
38  $this->addColumn($this->lng->txt("rbac_changes"), "", "50%");
39 
40  $this->setExternalSegmentation(true);
41  $this->setEnableHeader(true);
42  $this->setFormAction($ilCtrl->getFormAction($a_parent_obj, $a_parent_cmd));
43  $this->setRowTemplate("tpl.rbac_log_row.html", "Services/AccessControl");
44  $this->setFilterCommand("applyLogFilter");
45  $this->setResetCommand("resetLogFilter");
46 
47  $this->action_map = array(ilRbacLog::EDIT_PERMISSIONS => $this->lng->txt("rbac_log_edit_permissions"),
48  ilRbacLog::MOVE_OBJECT => $this->lng->txt("rbac_log_move_object"),
49  ilRbacLog::LINK_OBJECT => $this->lng->txt("rbac_log_link_object"),
50  ilRbacLog::COPY_OBJECT => $this->lng->txt("rbac_log_copy_object"),
51  ilRbacLog::CREATE_OBJECT => $this->lng->txt("rbac_log_create_object"),
52  ilRbacLog::EDIT_TEMPLATE => $this->lng->txt("rbac_log_edit_template"),
53  ilRbacLog::EDIT_TEMPLATE_EXISTING=> $this->lng->txt("rbac_log_edit_template_existing"),
54  ilRbacLog::CHANGE_OWNER=> $this->lng->txt("rbac_log_change_owner"));
55 
56  $this->initFilter();
57 
58  $this->getItems($this->ref_id, $this->filter);
59  }
60 
61  public function initFilter()
62  {
63  $item = $this->addFilterItemByMetaType("action", ilTable2GUI::FILTER_SELECT);
64  $item->setOptions(array("" => $this->lng->txt("all"))+$this->action_map);
65  $this->filter["action"] = $item->getValue();
66 
68  $this->filter["date"] = $item->getDate();
69  }
70 
71  protected function getItems($a_ref_id, array $a_current_filter = NULL)
72  {
73  global $rbacreview;
74 
75  $this->determineOffsetAndOrder();
76 
77  foreach($rbacreview->getOperations() as $op)
78  {
79  $this->operations[$op["ops_id"]] = $op["operation"];
80  }
81 
82  // special case: role folder should display root folder entries
83  if($a_ref_id == ROLE_FOLDER_ID)
84  {
85  $a_ref_id = ROOT_FOLDER_ID;
86  }
87 
88  $data = ilRbacLog::getLogItems($a_ref_id, $this->getLimit(), $this->getOffset(), $a_current_filter);
89 
90  $this->setData($data["set"]);
91  $this->setMaxCount($data["cnt"]);
92  }
93 
94  protected function fillRow($a_set)
95  {
96  $this->tpl->setVariable("DATE", ilDatePresentation::formatDate(new ilDateTime($a_set["created"], IL_CAL_UNIX)));
97  $this->tpl->setVariable("USER", ilObjUser::_lookupFullname($a_set["user_id"]));
98  $this->tpl->setVariable("ACTION", $this->action_map[$a_set["action"]]);
99 
100  if($a_set["action"] == ilRbacLog::CHANGE_OWNER)
101  {
102  $user = ilObjUser::_lookupFullname($a_set["data"][0]);
103  $changes = array(array("action"=>$this->lng->txt("rbac_log_changed_owner"), "operation"=>$user));
104  }
105  else if($a_set["action"] == ilRbacLog::EDIT_TEMPLATE)
106  {
107  $changes = $this->parseChangesTemplate($a_set["data"]);
108  }
109  else
110  {
111  $changes = $this->parseChangesFaPa($a_set["data"]);
112  }
113 
114  $this->tpl->setCurrentBlock("changes");
115  foreach($changes as $change)
116  {
117  $this->tpl->setVariable("CHANGE_ACTION", $change["action"]);
118  $this->tpl->setVariable("CHANGE_OPERATION", $change["operation"]);
119  $this->tpl->parseCurrentBlock();
120  }
121  }
122 
123  protected function parseChangesFaPa(array $raw)
124  {
125  $result = array();
126 
127  $type = ilObject::_lookupType($this->ref_id, true);
128 
129  if(isset($raw["src"]))
130  {
131  $obj_id = ilObject::_lookupObjectId($raw["src"]);
132  if($obj_id)
133  {
134  include_once "./Services/Link/classes/class.ilLink.php";
135  $result[] = array("action"=>$this->lng->txt("rbac_log_source_object"),
136  "operation"=>"<a href=\"".ilLink::_getLink($raw["src"])."\">".ilObject::_lookupTitle($obj_id)."</a>");
137  }
138 
139  // added only
140  foreach($raw["ops"] as $role_id => $ops)
141  {
142  foreach($ops as $op)
143  {
144  $result[] = array("action"=>sprintf($this->lng->txt("rbac_log_operation_add"), ilObject::_lookupTitle($role_id)),
145  "operation"=>$this->getOPCaption($type, $op));
146  }
147  }
148  }
149  else if(isset($raw["ops"]))
150  {
151  foreach($raw["ops"] as $role_id => $actions)
152  {
153  foreach($actions as $action => $ops)
154  {
155  foreach((array) $ops as $op)
156  {
157  $result[] = array("action"=>sprintf($this->lng->txt("rbac_log_operation_".$action), ilObject::_lookupTitle($role_id)),
158  "operation"=>$this->getOPCaption($type, $op));
159  }
160  }
161  }
162  }
163 
164  if(isset($raw["inht"]))
165  {
166  foreach($raw["inht"] as $action => $role_ids)
167  {
168  foreach((array) $role_ids as $role_id)
169  {
170  $result[] = array("action"=>sprintf($this->lng->txt("rbac_log_inheritance_".$action), ilObject::_lookupTitle($role_id)));
171  }
172  }
173  }
174 
175  return $result;
176  }
177 
178  protected function parseChangesTemplate(array $raw)
179  {
180  $result = array();
181  foreach($raw as $type => $actions)
182  {
183  foreach($actions as $action => $ops)
184  {
185  foreach($ops as $op)
186  {
187  $result[] = array("action"=>sprintf($this->lng->txt("rbac_log_operation_".$action), $this->lng->txt("obj_".$type)),
188  "operation"=>$this->getOPCaption($type, $op));
189  }
190  }
191  }
192  return $result;
193  }
194 
195  // #10946
196  protected function getOPCaption($a_type, $a_op)
197  {
198  // #11717
199  if(is_array($a_op))
200  {
201  $res = array();
202  foreach($a_op as $op)
203  {
204  $res[] = $this->getOPCaption($a_type, $op);
205  }
206  return implode(", ", $res);
207  }
208 
209  if(is_numeric($a_op) && isset($this->operations[$a_op]))
210  {
211  $op_id = $this->operations[$a_op];
212  if(substr($op_id, 0, 7) != "create_")
213  {
214  return $this->lng->txt($a_type."_".$this->operations[$a_op]);
215  }
216  else
217  {
218  return $this->lng->txt("rbac_".$this->operations[$a_op]);
219  }
220  }
221  }
222 }
223 
224 ?>
$result
addFilterItemByMetaType($id, $type=self::FILTER_TEXT, $a_optional=false, $caption=NULL)
Add filter by standard type.
setFilterCommand($a_val)
Set filter command.
setExternalSegmentation($a_val)
Set external segmentation.
const CHANGE_OWNER
static _lookupTitle($a_id)
lookup object title
const IL_CAL_UNIX
setId($a_val)
Set id.
_lookupFullname($a_user_id)
Lookup Full Name.
static _lookupObjectId($a_ref_id)
lookup object id
global $ilCtrl
Definition: ilias.php:18
setTitle($a_title, $a_icon=0, $a_icon_alt=0)
Set title and title icon.
const EDIT_PERMISSIONS
const CREATE_OBJECT
setLimit($a_limit=0, $a_default_limit=0)
set max.
Class ilTable2GUI.
getItems($a_ref_id, array $a_current_filter=NULL)
addColumn($a_text, $a_sort_field="", $a_width="", $a_is_checkbox_action_column=false, $a_class="", $a_tooltip="")
Add a column to the header.
getOffset()
Get offset.
static formatDate(ilDateTime $date)
Format a date public.
Date and time handling
const COPY_OBJECT
const LINK_OBJECT
setRowTemplate($a_template, $a_template_dir="")
Set row template.
static _lookupType($a_id, $a_reference=false)
lookup object type
Class ilRbacLogTableGUI.
determineOffsetAndOrder($a_omit_offset=false)
Determine offset and order.
static getLogItems($a_ref_id, $a_limit, $a_offset, array $a_filter=NULL)
global $lng
Definition: privfeed.php:40
setFormAction($a_form_action)
Set Form action parameter.
const EDIT_TEMPLATE_EXISTING
const EDIT_TEMPLATE
setEnableHeader($a_enableheader)
Set Enable Header.
const MOVE_OBJECT
getLimit()
Get limit.
setMaxCount($a_max_count)
set max.
setResetCommand($a_val)
Set reset filter command.
__construct($a_parent_obj, $a_parent_cmd, $a_ref_id)