ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilContainerGlobalProfiles.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 1998-2020 ILIAS open source, Extended GPL, see docs/LICENSE */
4
11{
15 protected $db;
16
20 protected $profiles = array();
21
25 protected $obj_id;
26
30 protected $mem_rol_id;
31
37 public function __construct(int $a_obj_id)
38 {
39 global $DIC;
40
41 $this->db = $DIC->database();
42 $this->setObjId($a_obj_id);
43
44 if ($this->getObjId() > 0) {
45 $this->setMemberRoleId();
46 $this->read();
47 }
48 }
49
55 protected function setObjId(int $a_obj_id)
56 {
57 $this->obj_id = $a_obj_id;
58 }
59
65 protected function getObjId() : int
66 {
67 return $this->obj_id;
68 }
69
75 protected function setMemberRoleId()
76 {
77 $refs = ilObject::_getAllReferences($this->getObjId());
78 $ref_id = end($refs);
79 $this->mem_rol_id = ilParticipants::getDefaultMemberRole($ref_id);
80 }
81
87 protected function getMemberRoleId() : int
88 {
89 return $this->mem_rol_id;
90 }
91
95 public function resetProfiles()
96 {
97 $this->profiles = array();
98 }
99
105 public function addProfile(int $a_profile_id)
106 {
107 $this->profiles[$a_profile_id] = array(
108 "profile_id" => $a_profile_id
109 );
110 }
111
117 public function removeProfile(int $a_profile_id)
118 {
119 unset($this->profiles[$a_profile_id]);
120 }
121
127 public function getProfiles() : array
128 {
129 return $this->profiles;
130 }
131
135 protected function read()
136 {
137 $db = $this->db;
138
139 $this->profiles = array();
140 $set = $db->query(
141 "SELECT spr.profile_id, spr.role_id, sp.title FROM skl_profile_role spr INNER JOIN skl_profile sp " .
142 " ON spr.profile_id = sp.id " .
143 " WHERE sp.ref_id = 0 " .
144 " AND role_id = " . $db->quote($this->getMemberRoleId(), "integer")
145 );
146 while ($rec = $db->fetchAssoc($set)) {
147 $this->profiles[$rec["profile_id"]] = $rec;
148 }
149 }
150
154 protected function delete()
155 {
156 $db = $this->db;
157
158 $db->manipulate(
159 "DELETE spr FROM skl_profile_role spr INNER JOIN skl_profile sp " .
160 " ON spr.profile_id = sp.id " .
161 " WHERE sp.ref_id = 0 " .
162 " AND role_id = " . $db->quote($this->getMemberRoleId(), "integer")
163 );
164 }
165
169 public function save()
170 {
171 $db = $this->db;
172
173 $this->delete();
174 foreach ($this->profiles as $p) {
175 $db->manipulate("INSERT INTO skl_profile_role " .
176 "(role_id, profile_id) VALUES (" .
177 $db->quote($this->getMemberRoleId(), "integer") . "," .
178 $db->quote($p["profile_id"], "integer") . ")");
179 }
180 }
181}
An exception for terminatinating execution or to throw for unit testing.
Global competence profiles of a container.
removeProfile(int $a_profile_id)
Remove profile.
getMemberRoleId()
Get member role id of object.
setObjId(int $a_obj_id)
Set object id.
__construct(int $a_obj_id)
Constructor.
setMemberRoleId()
Set member role id of object.
addProfile(int $a_profile_id)
Add profile.
static _getAllReferences($a_id)
get all reference ids of object
static getDefaultMemberRole($a_ref_id)
global $DIC
Definition: goto.php:24