ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilOrgUnitPathStorage.php
Go to the documentation of this file.
1<?php
2require_once('./Services/ActiveRecord/class.ActiveRecord.php');
3
10
11 const GLUE = ' > ';
12 const GLUE_SIMPLE = ' - ';
13 const ORG_SEPARATOR = ' | ';
14 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 $names = self::getAllOrguNames();
51
52 return array_keys($names);
53 }
54
55
56 public function store() {
57 if (self::where(array( 'ref_id' => $this->getRefId() ))->hasSets()) {
58 $this->update();
59 } else {
60 $this->create();
61 }
62 }
63
64
75 public static function getTextRepresentationOfUsersOrgUnits($user_id, $separator = self::ORG_SEPARATOR, $using_tmp_table = true) {
76 if ($using_tmp_table) {
77 global $DIC;
81 $ilDB = $DIC['ilDB'];
82 ilObjOrgUnitTree::_getInstance()->buildTempTableWithUsrAssignements();
83
84 $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 ));
85 $dat = $ilDB->fetchObject($res);
86
87 return $dat->orgus ? $dat->orgus : '-';
88 } else {
89 $array_of_org_ids = ilObjOrgUnitTree::_getInstance()->getOrgUnitOfUser($user_id);
90
91 if (!$array_of_org_ids) {
92 return '-';
93 }
94 require_once('./Modules/OrgUnit/classes/PathStorage/class.ilOrgUnitPathStorage.php');
95 $paths = ilOrgUnitPathStorage::where(array( 'ref_id' => $array_of_org_ids ))->getArray(null, 'path');
96
97 return implode($separator, $paths);
98 }
99 }
100
101
109 public static function getTextRepresentationOfOrgUnits($sort_by_title = true) {
110 if ($sort_by_title) {
111 return ilOrgUnitPathStorage::orderBy('path')->getArray('ref_id', 'path');
112 } else {
113 return ilOrgUnitPathStorage::getArray('ref_id', 'path');
114 }
115 }
116
117
122 public static function writePathByRefId($ref_id) {
123 require_once('./Modules/OrgUnit/classes/PathStorage/class.ilOrgUnitPathStorage.php');
124 $original_ref_id = $ref_id;
125 $names = self::getAllOrguNames();
126 $root_ref_id = ilObjOrgUnit::getRootOrgRefId();
128 $path = array( $names[$ref_id] );
129 if ($ref_id == $root_ref_id || !$ref_id) {
130 return false;
131 }
132 while ($ref_id != $root_ref_id && $ref_id) {
133 $ref_id = $tree->getParent($ref_id);
134 if ($ref_id != $root_ref_id && $names[$ref_id]) {
135 $path[] = $names[$ref_id];
136 }
137 }
138
139 $expression = reset($path) . self::GLUE_SIMPLE . end($path);
143 $ilOrgUnitPathStorage = self::findOrGetInstance($original_ref_id);
144 $ilOrgUnitPathStorage->setRefId($original_ref_id);
145 $ilOrgUnitPathStorage->setObjId(ilObject2::_lookupObjectId($original_ref_id));
146 $ilOrgUnitPathStorage->setPath($expression);
147 $ilOrgUnitPathStorage->store();
148
149 return true;
150 }
151
152
153 public static function clearDeleted() {
154 global $DIC;
158 $ilDB = $DIC['ilDB'];
159 $ref_ids = self::getAllOrguRefIds();
160 $q = "DELETE FROM " . self::TABLE_NAME . " WHERE " . $ilDB->in('ref_id', $ref_ids, true, 'integer');
161 $ilDB->manipulate($q);
162 }
163
164
170 protected static function writeFullPathByRefId($ref_id) {
171 require_once('./Modules/OrgUnit/classes/PathStorage/class.ilOrgUnitPathStorage.php');
172 $original_ref_id = $ref_id;
173 $names = self::getAllOrguNames();
174 $root_ref_id = ilObjOrgUnit::getRootOrgRefId();
176 $path = array( $names[$ref_id] );
177 if ($ref_id == $root_ref_id || !$ref_id) {
178 return false;
179 }
180 while ($ref_id != $root_ref_id && $ref_id) {
181 $ref_id = $tree->getParent($ref_id);
182 if ($ref_id != $root_ref_id && $names[$ref_id]) {
183 $path[] = $names[$ref_id];
184 }
185 }
186
187 $path = array_reverse($path);
188
189 $expression = implode(self::GLUE, $path);
193 $ilOrgUnitPathStorage = self::findOrGetInstance($original_ref_id);
194 $ilOrgUnitPathStorage->setRefId($original_ref_id);
195 $ilOrgUnitPathStorage->setObjId(ilObject2::_lookupObjectId($original_ref_id));
196 $ilOrgUnitPathStorage->setPath($expression);
197 $ilOrgUnitPathStorage->store();
198
199 return true;
200 }
201
202
207 public static function getAllOrguNames($lng_key = null) {
208 if (count(self::$orgu_names) == 0) {
209 global $DIC;
213 $ilDB = $DIC['ilDB'];
214 $res = $ilDB->queryF('SELECT * FROM object_reference
215 JOIN object_data ON object_reference.obj_id = object_data.obj_id AND deleted IS NULL
216 WHERE object_data.type = %s', array( 'text' ), array( 'orgu' ));
217 while ($data = $ilDB->fetchObject($res)) {
218 self::$orgu_names[$data->ref_id] = $data->title;
219 }
220 }
221
222 return self::$orgu_names;
223 }
224
225
229 public function getConnectorContainerName() {
230 return self::TABLE_NAME;
231 }
232
233
237 public function getRefId() {
238 return $this->ref_id;
239 }
240
241
245 public function setRefId($ref_id) {
246 $this->ref_id = $ref_id;
247 }
248
249
253 public function getPath() {
254 return $this->path;
255 }
256
257
261 public function setPath($path) {
262 $this->path = $path;
263 }
264
265
269 public function getObjId() {
270 return $this->obj_id;
271 }
272
273
277 public function setObjId($obj_id) {
278 $this->obj_id = $obj_id;
279 }
280}
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 $ilDB
global $DIC