ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilSkillTemplateReference.php
Go to the documentation of this file.
1 <?php
2 
26 {
27  protected ilDBInterface $db;
28  protected int $skill_template_id = 0;
29 
30  public function __construct(int $a_id = 0)
31  {
32  global $DIC;
33 
34  $this->db = $DIC->database();
35  parent::__construct($a_id);
36  $this->setType("sktr");
37  }
38 
39  public function setSkillTemplateId(int $a_val): void
40  {
41  $this->skill_template_id = $a_val;
42  }
43 
44  public function getSkillTemplateId(): int
45  {
47  }
48 
49  public function read(): void
50  {
51  $ilDB = $this->db;
52 
53  parent::read();
54 
55  $set = $ilDB->query(
56  "SELECT * FROM skl_templ_ref " .
57  " WHERE skl_node_id = " . $ilDB->quote($this->getId(), "integer")
58  );
59  if ($rec = $ilDB->fetchAssoc($set)) {
60  $this->setSkillTemplateId((int) $rec["templ_id"]);
61  }
62  }
63 
64  public function create(): void
65  {
66  $ilDB = $this->db;
67 
68  parent::create();
69 
70  $ilDB->manipulate("INSERT INTO skl_templ_ref " .
71  "(skl_node_id, templ_id) VALUES (" .
72  $ilDB->quote($this->getId(), "integer") . "," .
73  $ilDB->quote($this->getSkillTemplateId(), "integer") .
74  ")");
75  }
76 
77  public function update(): void
78  {
79  $ilDB = $this->db;
80 
81  parent::update();
82 
83  $ilDB->manipulate(
84  "UPDATE skl_templ_ref SET " .
85  " templ_id = " . $ilDB->quote($this->getSkillTemplateId(), "integer") .
86  " WHERE skl_node_id = " . $ilDB->quote($this->getId(), "integer")
87  );
88  }
89 
90  public function delete(): void
91  {
92  $ilDB = $this->db;
93 
94  $ilDB->manipulate(
95  "DELETE FROM skl_templ_ref WHERE "
96  . " skl_node_id = " . $ilDB->quote($this->getId(), "integer")
97  );
98 
99  parent::delete();
100  }
101 
102  public function copy(): ilSkillTemplateReference
103  {
104  $sktr = new ilSkillTemplateReference();
105  $sktr->setTitle($this->getTitle());
106  $sktr->setDescription($this->getDescription());
107  $sktr->setType($this->getType());
108  $sktr->setSkillTemplateId($this->getSkillTemplateId());
109  $sktr->setSelfEvaluation($this->getSelfEvaluation());
110  $sktr->setOrderNr($this->getOrderNr());
111  $sktr->create();
112 
113  return $sktr;
114  }
115 
116  public static function _lookupTemplateId(int $a_obj_id): int
117  {
118  global $DIC;
119 
120  $ilDB = $DIC->database();
121 
122  $query = "SELECT templ_id FROM skl_templ_ref WHERE skl_node_id = " .
123  $ilDB->quote($a_obj_id, "integer");
124  $obj_set = $ilDB->query($query);
125  $obj_rec = $ilDB->fetchAssoc($obj_set);
126 
127  return (int) $obj_rec["templ_id"];
128  }
129 
134  public static function _lookupTrefIdsForTopTemplateId(int $a_template_id): array
135  {
136  global $DIC;
137 
138  $ilDB = $DIC->database();
139 
140  $set = $ilDB->query(
141  "SELECT * FROM skl_templ_ref " .
142  " WHERE templ_id = " . $ilDB->quote($a_template_id, "integer")
143  );
144  $trefs = [];
145  while ($rec = $ilDB->fetchAssoc($set)) {
146  $trefs[] = (int) $rec["skl_node_id"];
147  }
148  return $trefs;
149  }
150 
151 
156  public static function _lookupTrefIdsForTemplateId(int $a_tid): array
157  {
158  global $DIC;
159 
160  $tree = $DIC->skills()->internal()->repo()->getTreeRepo()->getTreeForNodeId($a_tid);
161  $top_template_id = $tree->getTopParentNodeId($a_tid);
162  return self::_lookupTrefIdsForTopTemplateId($top_template_id);
163  }
164 }
setType(string $a_type)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $DIC
Definition: feed.php:28
static _lookupTrefIdsForTopTemplateId(int $a_template_id)
$query
__construct(Container $dic, ilPlugin $plugin)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...