1<?php 2/* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */ 3 4/** 5 * Class ilObjOrgUnitAccess 6 * 7 * @author: Oskar Truffer <ot@studer-raimann.ch> 8 * @author: Martin Studer <ms@studer-raimann.ch> 9 * 10 */ 11class ilObjOrgUnitAccess extends ilObjectAccess 12{ 13 14 /** 15 * get commands 16 * 17 * this method returns an array of all possible commands/permission combinations 18 * 19 * example: 20 * $commands = array 21 * ( 22 * array('permission' => 'read', 'cmd' => 'view', 'lang_var' => 'show'), 23 * array('permission' => 'write', 'cmd' => 'edit', 'lang_var' => 'edit'), 24 * ); 25 */ 26 public static function _getCommands() : array 27 { 28 $commands = [ 29 [ 30 'permission' => 'read', 31 'cmd' => 'view', 32 'lang_var' => 'show', 33 'default' => true, 34 ], 35 ]; 36 37 return $commands; 38 } 39 40 41 /** 42 * @param integer $ref_id 43 * 44 * @return bool 45 */ 46 public static function _checkAccessStaff($ref_id) : bool 47 { 48 global $DIC; 49 50 return ($DIC->access()->checkAccess('write', '', $ref_id) 51 || $DIC->access()->checkAccess('view_learning_progress', '', $ref_id)) 52 && $DIC->access()->checkAccess('read', '', $ref_id); 53 } 54 55 /** 56 * @param int $ref_id 57 * 58 * @return bool 59 */ 60 public static function _checkAccessSettings(int $ref_id) : bool 61 { 62 global $DIC; 63 64 return $DIC->access()->checkAccess('write', '', $ref_id); 65 } 66 67 /** 68 * @param int $ref_id 69 * 70 * @return bool 71 */ 72 public static function _checkAccessExport(int $ref_id) : bool 73 { 74 global $DIC; 75 76 return $DIC->access()->checkAccess('write', '', $ref_id); 77 } 78 79 /** 80 * @param int $ref_id 81 * 82 * @return bool 83 */ 84 public static function _checkAccessTypes(int $ref_id) : bool 85 { 86 global $DIC; 87 88 return $DIC->access()->checkAccess('write', '', $ref_id); 89 } 90 91 /** 92 * @param int $ref_id 93 * 94 * @return bool 95 */ 96 public static function _checkAccessPositions(int $ref_id) : bool 97 { 98 global $DIC; 99 100 return $DIC->access()->checkAccess('write', '', $ref_id); 101 } 102 103 104 /** 105 * @param integer $ref_id 106 * 107 * @return bool 108 */ 109 public static function _checkAccessStaffRec($ref_id) : bool 110 { 111 global $DIC; 112 113 return ($DIC->access()->checkAccess('write', '', $ref_id) 114 || $DIC->access()->checkAccess('view_learning_progress_rec', '', $ref_id)) 115 && $DIC->access()->checkAccess('read', '', $ref_id); 116 } 117 118 119 /** 120 * @param integer $ref_id 121 * 122 * @return bool 123 */ 124 public static function _checkAccessAdministrateUsers($ref_id) : bool 125 { 126 global $DIC; 127 128 return ilUserAccountSettings::getInstance()->isLocalUserAdministrationEnabled() 129 && $DIC->access()->checkAccess('cat_administrate_users', '', $ref_id); 130 } 131 132 133 /** 134 * @param integer $ref_id 135 * @param integer $usr_id 136 * 137 * @return bool 138 */ 139 public static function _checkAccessToUserLearningProgress($ref_id, $usr_id) : bool 140 { 141 global $DIC; 142 143 //Permission to view the Learning Progress of an OrgUnit: Employees 144 if ($DIC->access()->checkAccess('view_learning_progress', '', $ref_id) 145 && in_array($usr_id, ilObjOrgUnitTree::_getInstance()->getEmployees($ref_id, false)) 146 ) { 147 return true; 148 } 149 //Permission to view the Learning Progress of an OrgUnit: Superiors 150 if ($DIC->access()->checkAccess('view_learning_progress', '', $ref_id) 151 && in_array($usr_id, ilObjOrgUnitTree::_getInstance()->getSuperiors($ref_id, false)) 152 ) { 153 return true; 154 } 155 156 //Permission to view the Learning Progress of an OrgUnit or SubOrgUnit!: Employees 157 if ($DIC->access()->checkAccess('view_learning_progress_rec', '', $ref_id) 158 && in_array($usr_id, ilObjOrgUnitTree::_getInstance()->getEmployees($ref_id, true)) 159 ) { 160 return true; 161 } 162 163 //Permission to view the Learning Progress of an OrgUnit or SubOrgUnit!: Superiors 164 if ($DIC->access()->checkAccess('view_learning_progress_rec', '', $ref_id) 165 && in_array($usr_id, ilObjOrgUnitTree::_getInstance()->getSuperiors($ref_id, true)) 166 ) { 167 return true; 168 } 169 170 return false; 171 } 172 173 174 /** 175 * @param string $a_target check whether goto script will succeed 176 * 177 * @return bool 178 */ 179 public static function _checkGoto($a_target) : bool 180 { 181 global $DIC; 182 183 $t_arr = explode('_', $a_target); 184 if ($t_arr[0] !== 'orgu' || ((int) $t_arr[1]) <= 0) { 185 return false; 186 } 187 if ($DIC->access()->checkAccess('read', '', $t_arr[1])) { 188 return true; 189 } 190 191 return false; 192 } 193} 194