1<?php 2/* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */ 3 4include_once('./Services/Table/classes/class.ilTable2GUI.php'); 5require_once('./Services/Repository/classes/class.ilObjectPlugin.php'); 6 7/** 8* Table for object role permissions 9* 10* @author Jörg Lützenkirchen <luetzenkirchen@leifos.com> 11* 12* @version $Id$ 13* 14* @ingroup ServicesObject 15*/ 16class ilObjectOwnershipManagementTableGUI extends ilTable2GUI 17{ 18 /** 19 * @var ilCtrl 20 */ 21 protected $ctrl; 22 23 /** 24 * @var ilAccessHandler 25 */ 26 protected $access; 27 28 /** 29 * @var ilTree 30 */ 31 protected $tree; 32 33 /** 34 * @var ilObjectDefinition 35 */ 36 protected $obj_definition; 37 38 protected $user_id; // [int] 39 40 public function __construct($a_parent_obj, $a_parent_cmd, $a_user_id, array $a_data = null) 41 { 42 global $DIC; 43 44 $this->ctrl = $DIC->ctrl(); 45 $this->lng = $DIC->language(); 46 $this->access = $DIC->access(); 47 $this->tree = $DIC->repositoryTree(); 48 $this->obj_definition = $DIC["objDefinition"]; 49 $ilCtrl = $DIC->ctrl(); 50 $lng = $DIC->language(); 51 52 $this->user_id = (int) $a_user_id; 53 $this->setId('objownmgmt'); // #16373 54 55 parent::__construct($a_parent_obj, $a_parent_cmd); 56 57 $this->addColumn($lng->txt("title"), "title"); 58 $this->addColumn($lng->txt("path"), "path"); 59 $this->addColumn($lng->txt("action"), ""); 60 61 // $this->setTitle($this->lng->txt('')); 62 $this->setFormAction($ilCtrl->getFormAction($a_parent_obj, $a_parent_cmd)); 63 $this->setRowTemplate("tpl.obj_ownership_row.html", "Services/Object"); 64 $this->setDisableFilterHiding(true); 65 66 $this->setDefaultOrderField("title"); 67 $this->setDefaultOrderDirection("asc"); 68 69 $this->initItems($a_data); 70 } 71 72 protected function initItems($a_data) 73 { 74 $ilAccess = $this->access; 75 $tree = $this->tree; 76 77 $data = array(); 78 79 if (is_array($a_data) && sizeof($a_data)) { 80 if (!$this->user_id) { 81 $is_admin = $ilAccess->checkAccess("visible", "", SYSTEM_FOLDER_ID); 82 } 83 84 foreach ($a_data as $id => $item) { 85 // workspace objects won't have references 86 $refs = ilObject::_getAllReferences($id); 87 if ($refs) { 88 foreach ($refs as $idx => $ref_id) { 89 // objects in trash are hidden 90 if (!$tree->isDeleted($ref_id)) { 91 if ($this->user_id) { 92 $readable = $ilAccess->checkAccessOfUser($this->user_id, "read", "", $ref_id, $a_type); 93 } else { 94 $readable = $is_admin; 95 } 96 97 $data[$ref_id] = array("obj_id" => $id, 98 "ref_id" => $ref_id, 99 "type" => ilObject::_lookupType($id), 100 "title" => $item, 101 "path" => $this->buildPath($ref_id), 102 "readable" => $readable); 103 } 104 } 105 } 106 } 107 } 108 109 $this->setData($data); 110 } 111 112 public function fillRow($row) 113 { 114 $lng = $this->lng; 115 $objDefinition = $this->obj_definition; 116 117 // #11050 118 if (!$objDefinition->isPlugin($row["type"])) { 119 $txt_type = $lng->txt("obj_" . $row["type"]); 120 } else { 121 include_once("./Services/Component/classes/class.ilPlugin.php"); 122 $txt_type = ilObjectPlugin::lookupTxtById($row["type"], "obj_" . $row["type"]); 123 } 124 125 $this->tpl->setVariable("TITLE", $row["title"]); 126 $this->tpl->setVariable("ALT_ICON", $txt_type); 127 $this->tpl->setVariable("SRC_ICON", ilObject::_getIcon("", "tiny", $row["type"])); 128 $this->tpl->setVariable("PATH", $row["path"]); 129 130 if ($row["readable"]) { 131 $this->tpl->setCurrentBlock("actions"); 132 $this->tpl->setVariable("ACTIONS", $this->buildActions($row["ref_id"], $row["type"])); 133 $this->tpl->parseCurrentBlock(); 134 } 135 } 136 137 protected function buildActions($a_ref_id, $a_type) 138 { 139 $lng = $this->lng; 140 $ilCtrl = $this->ctrl; 141 $objDefinition = $this->obj_definition; 142 143 include_once "Services/UIComponent/AdvancedSelectionList/classes/class.ilAdvancedSelectionListGUI.php"; 144 $agui = new ilAdvancedSelectionListGUI(); 145 $agui->setId($this->id . "-" . $a_ref_id); 146 $agui->setListTitle($lng->txt("actions")); 147 148 $ilCtrl->setParameter($this->parent_obj, "ownid", $a_ref_id); 149 150 include_once "Services/Link/classes/class.ilLink.php"; 151 $agui->addItem( 152 $lng->txt("show"), 153 "", 154 ilLink::_getLink($a_ref_id, $a_type), 155 "", 156 "", 157 "_blank" 158 ); 159 160 $agui->addItem( 161 $lng->txt("move"), 162 "", 163 $ilCtrl->getLinkTarget($this->parent_obj, "move"), 164 "", 165 "", 166 "" 167 ); 168 169 $agui->addItem( 170 $lng->txt("change_owner"), 171 "", 172 $ilCtrl->getLinkTarget($this->parent_obj, "changeOwner"), 173 "", 174 "", 175 "" 176 ); 177 178 if (!in_array($a_type, array("crsr", "catr", "grpr")) && $objDefinition->allowExport($a_type)) { 179 $agui->addItem( 180 $lng->txt("export"), 181 "", 182 $ilCtrl->getLinkTarget($this->parent_obj, "export"), 183 "", 184 "", 185 "" 186 ); 187 } 188 189 $agui->addItem( 190 $lng->txt("delete"), 191 "", 192 $ilCtrl->getLinkTarget($this->parent_obj, "delete"), 193 "", 194 "", 195 "" 196 ); 197 198 $ilCtrl->setParameter($this->parent_obj, "ownid", ""); 199 200 return $agui->getHTML(); 201 } 202 203 protected function buildPath($a_ref_id) 204 { 205 $tree = $this->tree; 206 207 $path = "..."; 208 $counter = 0; 209 $path_full = $tree->getPathFull($a_ref_id); 210 foreach ($path_full as $data) { 211 if (++$counter < (count($path_full) - 2)) { 212 continue; 213 } 214 if ($a_ref_id != $data['ref_id']) { 215 $path .= " » " . $data['title']; 216 } 217 } 218 219 return $path; 220 } 221} 222