2 require_once(
'class.ilOrgUnitTypeTranslation.php');
3 require_once(
'./Modules/OrgUnit/exceptions/class.ilOrgUnitTypeException.php');
4 require_once(
'./Modules/OrgUnit/exceptions/class.ilOrgUnitTypePluginException.php');
5 require_once(
'./Services/AdvancedMetaData/classes/class.ilAdvancedMDRecord.php');
106 $this->pluginAdmin = $ilPluginAdmin;
109 $this->
id = (int)$a_id;
130 if (isset(self::$instances[$a_id])) {
131 return self::$instances[$a_id];
134 $type =
new self($a_id);
135 self::$instances[$a_id] = $type;
152 $sql =
'SELECT id FROM ' . self::TABLE_NAME;
153 $set = $ilDB->query($sql);
155 while ($rec = $ilDB->fetchObject($set)) {
156 $type =
new self($rec->id);
158 self::$instances[$rec->id] = $type;
170 public function create() {
177 $this->
id = $this->db->nextId(self::TABLE_NAME);
178 $this->db->insert(self::TABLE_NAME, array(
179 'id' => array(
'integer', $this->
getId() ),
181 'owner' => array(
'integer', $this->user->getId() ),
182 'icon' => array(
'text', $this->
getIcon() ),
183 'create_date' => array(
'text', date(
'Y-m-d H:i:s') ),
184 'last_update' => array(
'text', date(
'Y-m-d H:i:s') ),
189 foreach ($this->translations as
$lang => $trans) {
190 $trans->setOrguTypeId($this->
getId());
202 public function update() {
208 $disallowed = array();
211 foreach ($this->getActivePlugins() as $plugin) {
212 if (!$plugin->allowUpdate($this->getId())) {
213 $disallowed[] = $plugin;
214 $titles[] = $plugin->getPluginName();
217 if (count($disallowed)) {
218 $msg = sprintf($this->lng->txt(
'orgu_type_msg_updating_prevented'), implode(
', ', $titles));
222 $this->db->update(self::TABLE_NAME, array(
224 'owner' => array(
'integer', $this->
getOwner() ),
225 'icon' => array(
'text', $this->
getIcon() ),
226 'last_update' => array(
'text', date(
'Y-m-d H:i:s') ),
228 'id' => array(
'integer', $this->
getId() ),
233 foreach ($this->translations as $trans) {
245 if ($this->
getId()) {
259 public function delete() {
264 foreach (
$orgus as $orgu) {
265 $titles[] = $orgu->getTitle();
267 throw new ilOrgUnitTypeException(sprintf($this->lng->txt(
'orgu_type_msg_unable_delete'), implode(
', ', $titles)));
270 $disallowed = array();
273 foreach ($this->getActivePlugins() as $plugin) {
274 if (!$plugin->allowDelete($this->getId())) {
275 $disallowed[] = $plugin;
276 $titles[] = $plugin->getPluginName();
279 if (count($disallowed)) {
280 $msg = sprintf($this->lng->txt(
'orgu_type_msg_deletion_prevented'), implode(
', ', $titles));
284 $sql =
'DELETE FROM ' . self::TABLE_NAME .
' WHERE id = ' . $this->db->quote($this->
getId(),
'integer');
285 $this->db->manipulate($sql);
288 $this->db->update(
'orgu_data', array(
289 'orgu_type_id' => array(
'integer', 0 ),
291 'orgu_type_id' => array(
'integer', $this->
getId() ),
295 ilOrgUnitTypeTranslation::deleteAllTranslations($this->
getId());
306 $sql =
'DELETE FROM orgu_types_adv_md_rec WHERE type_id = ' . $this->db->quote($this->
getId(),
'integer');
307 $this->db->manipulate($sql);
332 public function setTitle($a_title, $a_lang_code =
'') {
334 $this->setTranslation(
'title', $a_title,
$lang);
361 $this->setTranslation(
'description', $a_description,
$lang);
373 $cache_key = ($include_deleted) ? 1 : 0;
374 if (is_array($this->orgus_ids[$cache_key])) {
375 return $this->orgus_ids[$cache_key];
377 if ($include_deleted) {
378 $sql =
'SELECT * FROM orgu_data WHERE orgu_type_id = ' . $this->db->quote($this->
getId(),
'integer');
381 'SELECT DISTINCT orgu_id FROM orgu_data od ' .
'JOIN object_reference oref ON oref.obj_id = od.orgu_id ' .
'WHERE od.orgu_type_id = ' 382 . $this->db->quote($this->
getId(),
'integer') .
' AND oref.deleted IS NULL';
384 $set = $this->db->query($sql);
385 $this->orgus_ids[$cache_key] = array();
386 while ($rec = $this->db->fetchObject($set)) {
387 $this->orgus_ids[$cache_key][] = $rec->orgu_id;
390 return $this->orgus_ids[$cache_key];
402 $cache_key = ($include_deleted) ? 1 : 0;
403 if (is_array($this->orgus[$cache_key])) {
404 return $this->orgus[$cache_key];
406 $this->orgus[$cache_key] = array();
408 foreach ($ids as
$id) {
410 if (!$include_deleted) {
413 $ref_ids = array_values($ref_ids);
415 if ($orgu->_isInTrash(
$ref_id)) {
419 $this->orgus[$cache_key][] = $orgu;
422 return $this->orgus[$cache_key];
434 $active = ($a_only_active) ? 1 : 0;
435 if (is_array($this->amd_records_assigned[$active])) {
436 return $this->amd_records_assigned[$active];
438 $this->amd_records_assigned[$active] = array();
439 $sql =
'SELECT * FROM orgu_types_adv_md_rec WHERE type_id = ' . $this->db->quote($this->
getId(),
'integer');
440 $set = $this->db->query($sql);
441 while ($rec = $this->db->fetchObject($set)) {
443 if ($a_only_active) {
444 if ($amd_record->isActive()) {
445 $this->amd_records_assigned[1][] = $amd_record;
448 $this->amd_records_assigned[0][] = $amd_record;
452 return $this->amd_records_assigned[$active];
463 public function getAssignedAdvancedMDRecordIds($a_only_active =
false) {
467 $ids[] = $record->getRecordId();
480 if (is_array(self::$amd_records_available)) {
481 return self::$amd_records_available;
485 return self::$amd_records_available;
494 public static function getAvailableAdvancedMDRecordIds() {
497 foreach (self::getAvailableAdvancedMDRecords() as $record) {
498 $ids[] = $record->getRecordId();
515 public function assignAdvancedMDRecord($a_record_id) {
516 if (!in_array($a_record_id, $this->getAssignedAdvancedMDRecordIds())) {
517 if (!in_array($a_record_id, self::getAvailableAdvancedMDRecordIds())) {
518 throw new ilOrgUnitTypeException(
"AdvancedMDRecord with ID {$a_record_id} cannot be assigned to OrgUnit types");
521 $disallowed = array();
523 foreach ($this->getActivePlugins() as $plugin) {
524 if (!$plugin->allowAssignAdvancedMDRecord($this->getId(), $a_record_id)) {
525 $disallowed[] = $plugin;
526 $titles[] = $plugin->getPluginName();
529 if (count($disallowed)) {
530 $msg = sprintf($this->lng->txt(
'orgu_type_msg_assign_amd_prevented'), implode(
', ', $titles));
533 $record_ids = $this->getAssignedAdvancedMDRecordIds();
534 $record_ids[] = $a_record_id;
535 $this->db->insert(
'orgu_types_adv_md_rec', array(
536 'type_id' => array(
'integer', $this->
getId() ),
537 'rec_id' => array(
'integer', $a_record_id ),
543 $this->amd_records_assigned = NULL;
555 public function deassignAdvancedMdRecord($a_record_id) {
556 $record_ids = $this->getAssignedAdvancedMDRecordIds();
557 $key = array_search($a_record_id, $record_ids);
558 if ($key !==
false) {
560 $disallowed = array();
562 foreach ($this->getActivePlugins() as $plugin) {
563 if (!$plugin->allowDeassignAdvancedMDRecord($this->getId(), $a_record_id)) {
564 $disallowed[] = $plugin;
565 $titles[] = $plugin->getPluginName();
568 if (count($disallowed)) {
569 $msg = sprintf($this->lng->txt(
'orgu_type_msg_deassign_amd_prevented'), implode(
', ', $titles));
572 unset($record_ids[$key]);
573 $sql =
'DELETE FROM orgu_types_adv_md_rec 574 WHERE type_id = ' . $this->db->quote($this->
getId(),
'integer') .
' 575 AND rec_id = ' . $this->db->quote($a_record_id,
'integer');
576 $this->db->query($sql);
581 $this->amd_records_assigned = NULL;
597 if (!count($file_data) || !$file_data[
'name']) {
638 $lang = ($a_lang_code) ? $a_lang_code : $this->user->getLanguage();
640 if (!is_null($trans_obj)) {
641 $translation = $trans_obj->getMember($a_member);
644 if (!$a_lang_code && !$translation) {
647 return $trans_obj->getMember($a_member);
656 return $trans_obj->getMember($a_member);
673 protected function setTranslation($a_member, $a_value, $a_lang_code) {
674 $a_value = trim($a_value);
676 $existing_translation = $this->
getTranslation($a_member, $a_lang_code);
677 if ($existing_translation == $a_value) {
686 $disallowed = array();
689 foreach ($this->getActivePlugins() as $plugin) {
691 if ($a_member ==
'title') {
692 $allowed = $plugin->allowSetTitle($this->
getId(), $a_lang_code, $a_value);
694 if ($a_member ==
'description') {
695 $allowed = $plugin->allowSetDescription($this->
getId(), $a_lang_code, $a_value);
699 $disallowed[] = $plugin;
700 $titles[] = $plugin->getPluginName();
703 if (count($disallowed)) {
704 $msg = sprintf($this->lng->txt(
'orgu_type_msg_setting_member_prevented'), $a_value, implode(
', ', $titles));
708 if (!is_null($trans_obj)) {
709 $trans_obj->setMember($a_member, $a_value);
712 $trans_obj->setOrguTypeId($this->
getId());
713 $trans_obj->setLang($a_lang_code);
714 $trans_obj->setMember($a_member, $a_value);
715 $this->translations[$a_lang_code] = $trans_obj;
718 if ($this->
getId()) {
719 $trans_obj->create();
730 protected function getActivePlugins() {
731 if ($this->active_plugins === NULL) {
733 $this->active_plugins = array();
736 $plugin = $this->pluginAdmin->getPluginObject(
IL_COMP_MODULE,
'OrgUnit',
'orgutypehk', $pl_name);
737 $this->active_plugins[] = $plugin;
754 if (isset($this->translations[$a_lang_code])) {
755 return $this->translations[$a_lang_code];
758 if (!is_null($trans_obj)) {
759 $this->translations[$a_lang_code] = $trans_obj;
775 $sql =
'SELECT * FROM ' . self::TABLE_NAME .
' WHERE id = ' . $this->db->quote($this->
id,
'integer');
776 $set = $this->db->query($sql);
777 if (!$this->db->numRows($set)) {
780 $rec = $this->db->fetchObject($set);
781 $this->default_lang = $rec->default_lang;
795 foreach ($this->getActivePlugins() as $plugin) {
796 if (!$plugin->allowUpdate($this->getId())) {
832 public function getAllTranslations() {
836 $this->translations[$trans->getLang()] = $trans;
896 if (
$icon AND !preg_match(
'/\.(svg)$/',
$icon)) {
920 if ($append_filename) {
938 $disallowed = array();
943 foreach ($this->getActivePlugins() as $plugin) {
944 if (!$plugin->allowSetDefaultLanguage($this->getId(),
$default_lang)) {
945 $disallowed[] = $plugin;
946 $titles[] = $plugin->getPluginName();
949 if (count($disallowed)) {
950 $msg = sprintf($this->lng->txt(
'orgu_type_msg_setting_default_lang_prevented'),
$default_lang, implode(
', ', $titles));
static makeDirParents($a_dir)
Create a new directory and all parent directories.
setTranslations($translations)
Getters & Setters.
Class ilOrgUnitTypeException.
save()
Wrapper around create() and update() methods.
updateable()
Helper function to check if this type can be updated.
processAndStoreIconFile(array $file_data)
Resize and store an icon file for this object.
setTitle($a_title, $a_lang_code='')
Set title of OrgUnit type.
static _getActivatedRecordsByObjectType($a_obj_type, $a_sub_type="")
Get activated records by object type.
static getAllTypes()
Get array of all instances of ilOrgUnitType objects.
static getAvailableAdvancedMDRecords()
Get all available AdvancedMDRecord objects for OrgUnits/Types.
static saveObjRecSelection($a_obj_id, $a_sub_type="", array $a_records=null, $a_delete_before=true)
Save repository object record selection.
static _getAllReferences($a_id)
get all reference ids of object
getOrgUnitIds($include_deleted=true)
Get an array of IDs of ilObjOrgUnit objects using this type.
read()
Read object data from database.
setIcon($icon)
Set new Icon filename.
getIconPath($append_filename=false)
Return the path to the icon.
setCreateDate($create_date)
getTranslation($a_member, $a_lang_code)
Protected.
static moveUploadedFile($a_file, $a_name, $a_target, $a_raise_errors=true, $a_mode="move_uploaded")
move uploaded file
static getInstance($a_id)
Public.
removeIconFile()
Remove the icon file on disk.
getTranslations()
Returns the loaded translation objects.
loadTranslation($a_lang_code)
Helper function to load a translation.
getOrgUnits($include_deleted=true)
Get an array of ilObjOrgUnit objects using this type.
Class ilOrgUnitTypeTranslation This class represents a translation for a given ilOrgUnit object and l...
Class ilOrgUnitTypePluginException This exception is thrown whenever one or multiple ilOrgUnitTypeHoo...
getAssignedAdvancedMDRecords($a_only_active=false)
Get assigned AdvancedMDRecord objects.
const WEB_DATA_FOLDER
Folder in ILIAS webdir to store the icons.
static getInstance($a_orgu_type_id, $a_lang_code)
Public.
setLastUpdate($last_update)
static $amd_records_available
static getWebspaceDir($mode="filesystem")
get webspace directory
getTitle($a_lang_code='')
Get the title of an OrgUnit type.
getDescription($a_lang_code='')
Get the description of an OrgUnit type.
setDescription($a_description, $a_lang_code='')
Set description of OrgUnit type.