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