ILIAS  release_7 Revision v7.30-3-g800a261c036
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
126 public static function writePathByRefId($ref_id)
127 {
128 $original_ref_id = $ref_id;
129 $names = self::getAllOrguNames();
130 $root_ref_id = ilObjOrgUnit::getRootOrgRefId();
132 $path = array($names[$ref_id]);
133 if ($ref_id == $root_ref_id || !$ref_id) {
134 return false;
135 }
136 while ($ref_id != $root_ref_id && $ref_id) {
137 $ref_id = $tree->getParent($ref_id);
138 if ($ref_id != $root_ref_id && $names[$ref_id]) {
139 $path[] = $names[$ref_id];
140 }
141 }
142
143 if (count($path) > 2) {
144 $first = array_shift($path);
145 $last = array_pop($path);
146 $middle = implode(self::GLUE_SIMPLE, $path);
147 if (strlen($middle) > self::MAX_MIDDLE_PATH_LENGTH) {
148 $middle = substr($middle, 0, self::MAX_MIDDLE_PATH_LENGTH) . " ...";
149 }
150 $expression = implode(self::GLUE_SIMPLE, [$first, $middle, $last]);
151 } else {
152 $expression = implode(self::GLUE_SIMPLE, $path);
153 }
157 $ilOrgUnitPathStorage = self::findOrGetInstance($original_ref_id);
158 $ilOrgUnitPathStorage->setRefId($original_ref_id);
159 $ilOrgUnitPathStorage->setObjId(ilObject2::_lookupObjectId($original_ref_id));
160 $ilOrgUnitPathStorage->setPath($expression);
161 $ilOrgUnitPathStorage->store();
162
163 return true;
164 }
165
166
167 public static function clearDeleted()
168 {
169 global $DIC;
173 $ilDB = $DIC['ilDB'];
174 $ref_ids = self::getAllOrguRefIds();
175 $q = "DELETE FROM " . self::TABLE_NAME . " WHERE " . $ilDB->in('ref_id', $ref_ids, true, 'integer');
176 $ilDB->manipulate($q);
177 }
178
179
186 protected static function writeFullPathByRefId($ref_id)
187 {
188 $original_ref_id = $ref_id;
189 $names = self::getAllOrguNames();
190 $root_ref_id = ilObjOrgUnit::getRootOrgRefId();
192 $path = array($names[$ref_id]);
193 if ($ref_id == $root_ref_id || !$ref_id) {
194 return false;
195 }
196 while ($ref_id != $root_ref_id && $ref_id) {
197 $ref_id = $tree->getParent($ref_id);
198 if ($ref_id != $root_ref_id && $names[$ref_id]) {
199 $path[] = $names[$ref_id];
200 }
201 }
202
203 $path = array_reverse($path);
204
205 $expression = implode(self::GLUE, $path);
209 $ilOrgUnitPathStorage = self::findOrGetInstance($original_ref_id);
210 $ilOrgUnitPathStorage->setRefId($original_ref_id);
211 $ilOrgUnitPathStorage->setObjId(ilObject2::_lookupObjectId($original_ref_id));
212 $ilOrgUnitPathStorage->setPath($expression);
213 $ilOrgUnitPathStorage->store();
214
215 return true;
216 }
217
218
224 public static function getAllOrguNames($lng_key = null)
225 {
226 if (count(self::$orgu_names) == 0) {
227 global $DIC;
231 $ilDB = $DIC['ilDB'];
232 $res = $ilDB->queryF('SELECT * FROM object_reference
233 JOIN object_data ON object_reference.obj_id = object_data.obj_id AND deleted IS NULL
234 WHERE object_data.type = %s', array('text'), array('orgu'));
235 while ($data = $ilDB->fetchObject($res)) {
236 self::$orgu_names[$data->ref_id] = $data->title;
237 }
238 }
239
240 return self::$orgu_names;
241 }
242
243
248 {
249 return self::TABLE_NAME;
250 }
251
252
256 public function getRefId()
257 {
258 return $this->ref_id;
259 }
260
261
265 public function setRefId($ref_id)
266 {
267 $this->ref_id = $ref_id;
268 }
269
270
274 public function getPath()
275 {
276 return $this->path;
277 }
278
279
283 public function setPath($path)
284 {
285 $this->path = $path;
286 }
287
288
292 public function getObjId()
293 {
294 return $this->obj_id;
295 }
296
297
301 public function setObjId($obj_id)
302 {
303 $this->obj_id = $obj_id;
304 }
305}
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: goto.php:24
foreach($_POST as $key=> $value) $res
global $ilDB
$data
Definition: storeScorm.php:23