ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilContainerGlobalProfiles.php
Go to the documentation of this file.
1 <?php
2 
26 {
27  protected ilDBInterface $db;
28  protected array $profiles = [];
29  protected int $obj_id = 0;
30  protected int $mem_rol_id = 0;
31 
32  public function __construct(int $a_obj_id)
33  {
34  global $DIC;
35 
36  $this->db = $DIC->database();
37  $this->setObjId($a_obj_id);
38 
39  if ($this->getObjId() > 0) {
40  $this->setMemberRoleId();
41  $this->read();
42  }
43  }
44 
45  protected function setObjId(int $a_obj_id): void
46  {
47  $this->obj_id = $a_obj_id;
48  }
49 
50  protected function getObjId(): int
51  {
52  return $this->obj_id;
53  }
54 
55  protected function setMemberRoleId(): void
56  {
57  $refs = ilObject::_getAllReferences($this->getObjId());
58  $ref_id = end($refs);
59  $this->mem_rol_id = ilParticipants::getDefaultMemberRole($ref_id);
60  }
61 
62  protected function getMemberRoleId(): int
63  {
64  return $this->mem_rol_id;
65  }
66 
67  public function resetProfiles(): void
68  {
69  $this->profiles = [];
70  }
71 
72  public function addProfile(int $a_profile_id): void
73  {
74  $this->profiles[$a_profile_id] = [
75  "profile_id" => $a_profile_id
76  ];
77  }
78 
79  public function removeProfile(int $a_profile_id): void
80  {
81  unset($this->profiles[$a_profile_id]);
82  }
83 
84  public function getProfiles(): array
85  {
86  return $this->profiles;
87  }
88 
89  protected function read(): void
90  {
91  $db = $this->db;
92 
93  $this->profiles = [];
94  $set = $db->query(
95  "SELECT spr.profile_id, spr.role_id, sp.title, sp.skill_tree_id " .
96  " FROM skl_profile_role spr INNER JOIN skl_profile sp ON spr.profile_id = sp.id " .
97  " WHERE sp.ref_id = 0 " .
98  " AND role_id = " . $db->quote($this->getMemberRoleId(), "integer")
99  );
100  while ($rec = $db->fetchAssoc($set)) {
101  $this->profiles[$rec["profile_id"]] = $rec;
102  }
103  }
104 
105  protected function delete(): void
106  {
107  $db = $this->db;
108 
109  $db->manipulate(
110  "DELETE spr FROM skl_profile_role spr INNER JOIN skl_profile sp " .
111  " ON spr.profile_id = sp.id " .
112  " WHERE sp.ref_id = 0 " .
113  " AND role_id = " . $db->quote($this->getMemberRoleId(), "integer")
114  );
115  }
116 
117  public function save(): void
118  {
119  $db = $this->db;
120 
121  $this->delete();
122  foreach ($this->profiles as $p) {
123  $db->manipulate("INSERT INTO skl_profile_role " .
124  "(role_id, profile_id) VALUES (" .
125  $db->quote($this->getMemberRoleId(), "integer") . "," .
126  $db->quote($p["profile_id"], "integer") . ")");
127  }
128  }
129 }
fetchAssoc(ilDBStatement $statement)
static _getAllReferences(int $id)
get all reference ids for object ID
quote($value, string $type)
static getDefaultMemberRole(int $a_ref_id)
global $DIC
Definition: feed.php:28
$ref_id
Definition: ltiauth.php:67
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
query(string $query)
Run a (read-only) Query on the database.
manipulate(string $query)
Run a (write) Query on the database.