ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilOrgUnitPathStorage.php
Go to the documentation of this file.
1<?php
2
9{
10 const GLUE = ' > ';
11 const GLUE_SIMPLE = ' - ';
12 const ORG_SEPARATOR = ' | ';
13 const TABLE_NAME = 'orgu_path_storage';
24 protected $ref_id = 0;
32 protected $obj_id = 0;
39 protected $path = '';
43 protected static $orgu_names = array();
44
45
49 public static function getAllOrguRefIds()
50 {
51 $names = self::getAllOrguNames();
52
53 return array_keys($names);
54 }
55
56
57 public function store()
58 {
59 if (self::where(array( 'ref_id' => $this->getRefId() ))->hasSets()) {
60 $this->update();
61 } else {
62 $this->create();
63 }
64 }
65
66
77 public static function getTextRepresentationOfUsersOrgUnits($user_id, $separator = self::ORG_SEPARATOR, $using_tmp_table = true)
78 {
79 if ($using_tmp_table) {
80 global $DIC;
84 $ilDB = $DIC['ilDB'];
85 ilObjOrgUnitTree::_getInstance()->buildTempTableWithUsrAssignements();
86
87 $res = $ilDB->queryF("SELECT " . $ilDB->groupConcat("path", $separator) . " AS orgus FROM orgu_usr_assignements WHERE user_id = %s GROUP BY user_id;", array( 'integer' ), array( $user_id ));
88 $dat = $ilDB->fetchObject($res);
89
90 return $dat->orgus ? $dat->orgus : '-';
91 } else {
92 $array_of_org_ids = ilObjOrgUnitTree::_getInstance()->getOrgUnitOfUser($user_id);
93
94 if (!$array_of_org_ids) {
95 return '-';
96 }
97 $paths = ilOrgUnitPathStorage::where(array( 'ref_id' => $array_of_org_ids ))->getArray(null, 'path');
98
99 return implode($separator, $paths);
100 }
101 }
102
103
111 public static function getTextRepresentationOfOrgUnits($sort_by_title = true)
112 {
113 if ($sort_by_title) {
114 return ilOrgUnitPathStorage::orderBy('path')->getArray('ref_id', 'path');
115 } else {
116 return ilOrgUnitPathStorage::getArray('ref_id', 'path');
117 }
118 }
119
120
125 public static function writePathByRefId($ref_id)
126 {
127 $original_ref_id = $ref_id;
128 $names = self::getAllOrguNames();
129 $root_ref_id = ilObjOrgUnit::getRootOrgRefId();
131 $path = array( $names[$ref_id] );
132 if ($ref_id == $root_ref_id || !$ref_id) {
133 return false;
134 }
135 while ($ref_id != $root_ref_id && $ref_id) {
136 $ref_id = $tree->getParent($ref_id);
137 if ($ref_id != $root_ref_id && $names[$ref_id]) {
138 $path[] = $names[$ref_id];
139 }
140 }
141
142 if (count($path) > 2) {
143 $first = array_shift($path);
144 $last = array_pop($path);
145 $middle = implode(self::GLUE_SIMPLE, $path);
146 if (strlen($middle) > self::MAX_MIDDLE_PATH_LENGTH) {
147 $middle = substr($middle, 0, self::MAX_MIDDLE_PATH_LENGTH) . " ...";
148 }
149 $expression = implode(self::GLUE_SIMPLE, [ $first, $middle, $last ]);
150 } else {
151 $expression = implode(self::GLUE_SIMPLE, $path);
152 }
156 $ilOrgUnitPathStorage = self::findOrGetInstance($original_ref_id);
157 $ilOrgUnitPathStorage->setRefId($original_ref_id);
158 $ilOrgUnitPathStorage->setObjId(ilObject2::_lookupObjectId($original_ref_id));
159 $ilOrgUnitPathStorage->setPath($expression);
160 $ilOrgUnitPathStorage->store();
161
162 return true;
163 }
164
165
166 public static function clearDeleted()
167 {
168 global $DIC;
172 $ilDB = $DIC['ilDB'];
173 $ref_ids = self::getAllOrguRefIds();
174 $q = "DELETE FROM " . self::TABLE_NAME . " WHERE " . $ilDB->in('ref_id', $ref_ids, true, 'integer');
175 $ilDB->manipulate($q);
176 }
177
178
184 protected static function writeFullPathByRefId($ref_id)
185 {
186 $original_ref_id = $ref_id;
187 $names = self::getAllOrguNames();
188 $root_ref_id = ilObjOrgUnit::getRootOrgRefId();
190 $path = array( $names[$ref_id] );
191 if ($ref_id == $root_ref_id || !$ref_id) {
192 return false;
193 }
194 while ($ref_id != $root_ref_id && $ref_id) {
195 $ref_id = $tree->getParent($ref_id);
196 if ($ref_id != $root_ref_id && $names[$ref_id]) {
197 $path[] = $names[$ref_id];
198 }
199 }
200
201 $path = array_reverse($path);
202
203 $expression = implode(self::GLUE, $path);
207 $ilOrgUnitPathStorage = self::findOrGetInstance($original_ref_id);
208 $ilOrgUnitPathStorage->setRefId($original_ref_id);
209 $ilOrgUnitPathStorage->setObjId(ilObject2::_lookupObjectId($original_ref_id));
210 $ilOrgUnitPathStorage->setPath($expression);
211 $ilOrgUnitPathStorage->store();
212
213 return true;
214 }
215
216
221 public static function getAllOrguNames($lng_key = null)
222 {
223 if (count(self::$orgu_names) == 0) {
224 global $DIC;
228 $ilDB = $DIC['ilDB'];
229 $res = $ilDB->queryF('SELECT * FROM object_reference
230 JOIN object_data ON object_reference.obj_id = object_data.obj_id AND deleted IS NULL
231 WHERE object_data.type = %s', array( 'text' ), array( 'orgu' ));
232 while ($data = $ilDB->fetchObject($res)) {
233 self::$orgu_names[$data->ref_id] = $data->title;
234 }
235 }
236
237 return self::$orgu_names;
238 }
239
240
245 {
246 return self::TABLE_NAME;
247 }
248
249
253 public function getRefId()
254 {
255 return $this->ref_id;
256 }
257
258
262 public function setRefId($ref_id)
263 {
264 $this->ref_id = $ref_id;
265 }
266
267
271 public function getPath()
272 {
273 return $this->path;
274 }
275
276
280 public function setPath($path)
281 {
282 $this->path = $path;
283 }
284
285
289 public function getObjId()
290 {
291 return $this->obj_id;
292 }
293
294
298 public function setObjId($obj_id)
299 {
300 $this->obj_id = $obj_id;
301 }
302}
Class ActiveRecord.
static where($where, $operator=null)
static findOrGetInstance($primary_key, array $add_constructor_args=array())
static getArray($key=null, $values=null)
static orderBy($orderBy, $orderDirection='ASC')
An exception for terminatinating execution or to throw for unit testing.
static getRootOrgRefId()
static _lookupObjectId($a_ref_id)
lookup object id
Class ilOrgUnitPathStorage.
static getTextRepresentationOfOrgUnits($sort_by_title=true)
Get ref id path array.
global $DIC
Definition: saml.php:7
foreach($_POST as $key=> $value) $res
global $ilDB