ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilCourseStart.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=0);
24{
25 private int $ref_id;
26 private int $id;
27 private array $start_objs = [];
28
29 protected ilDBInterface $db;
30 protected ilLogger $logger;
32 protected ilTree $tree;
33
34 public function __construct($a_course_ref_id, $a_course_obj_id)
35 {
36 global $DIC;
37
38 $this->db = $DIC->database();
39 $this->objectDataCache = $DIC['ilObjDataCache'];
40 $this->logger = $DIC->logger()->crs();
41
42 $this->ref_id = $a_course_ref_id;
43 $this->id = $a_course_obj_id;
44 $this->__read();
45 }
46
47 public function setId(int $a_id): void
48 {
49 $this->id = $a_id;
50 }
51
52 public function getId(): int
53 {
54 return $this->id;
55 }
56
57 public function setRefId(int $a_ref_id): void
58 {
59 $this->ref_id = $a_ref_id;
60 }
61
62 public function getRefId(): int
63 {
64 return $this->ref_id;
65 }
66
67 public function getStartObjects(): array
68 {
69 return $this->start_objs;
70 }
71
72 public function cloneDependencies(int $a_target_id, int $a_copy_id): void
73 {
74 $this->logger->debug('Begin course start objects...');
75
76 $new_obj_id = $this->objectDataCache->lookupObjId($a_target_id);
77 $start = new ilCourseStart($a_target_id, $new_obj_id);
78
79 $cwo = ilCopyWizardOptions::_getInstance($a_copy_id);
80 $mappings = $cwo->getMappings();
81 foreach ($this->getStartObjects() as $data) {
82 $item_ref_id = $data['item_ref_id'];
83 if (isset($mappings[$item_ref_id]) && $mappings[$item_ref_id]) {
84 $this->logger->debug('Clone start object nr. ' . $item_ref_id);
85 $start->add($mappings[$item_ref_id]);
86 } else {
87 $this->logger->debug('No mapping found for start object nr. ' . $item_ref_id);
88 }
89 }
90 $this->logger->debug('... end course start objects');
91 }
92
93 public function delete(int $a_crs_start_id): void
94 {
95 $query = "DELETE FROM crs_start " .
96 "WHERE crs_start_id = " . $this->db->quote($a_crs_start_id, 'integer') . " " .
97 "AND crs_id = " . $this->db->quote($this->getId(), 'integer') . " ";
98 $res = $this->db->manipulate($query);
99 }
100
101 public function exists(int $a_item_ref_id): bool
102 {
103 $query = "SELECT * FROM crs_start " .
104 "WHERE crs_id = " . $this->db->quote($this->getId(), 'integer') . " " .
105 "AND item_ref_id = " . $this->db->quote($a_item_ref_id, 'integer') . " ";
106 $res = $this->db->query($query);
107 return (bool) $res->numRows();
108 }
109
110 public function add(int $a_item_ref_id): void
111 {
112 if ($a_item_ref_id) {
113 $next_id = $this->db->nextId('crs_start');
114 $query = "INSERT INTO crs_start (crs_start_id,crs_id,item_ref_id) " .
115 "VALUES( " .
116 $this->db->quote($next_id, 'integer') . ", " .
117 $this->db->quote($this->getId(), 'integer') . ", " .
118 $this->db->quote($a_item_ref_id, 'integer') . " " .
119 ")";
120 $res = $this->db->manipulate($query);
121 }
122 }
123
124 public function getPossibleStarters(): array
125 {
126 $poss_items = [];
127 foreach (ilObjectActivation::getItems($this->getRefId(), false) as $node) {
128 switch ($node['type']) {
129 case 'lm':
130 case 'sahs':
131 case 'svy':
132 case 'tst':
133 $poss_items[] = $node['ref_id'];
134 break;
135 }
136 }
137 return $poss_items;
138 }
139
140 public function allFullfilled($user_id): bool
141 {
142 foreach ($this->getStartObjects() as $item) {
143 if (!$this->isFullfilled($user_id, $item['item_ref_id'])) {
144 return false;
145 }
146 }
147 return true;
148 }
149
150 public function isFullfilled(int $user_id, int $item_id): bool
151 {
152 $lm_continue = new ilCourseLMHistory($this->getRefId(), $user_id);
153 $continue_data = $lm_continue->getLMHistory();
154
155 $obj_id = $this->objectDataCache->lookupObjId($item_id);
156 $type = $this->objectDataCache->lookupType($obj_id);
157
158 switch ($type) {
159 case 'tst':
160
162 return false;
163 }
164 break;
165 case 'svy':
167 return false;
168 }
169 break;
170 case 'sahs':
172 return false;
173 }
174 break;
175
176 default:
177 if (!isset($continue_data[$item_id])) {
178 return false;
179 }
180 }
181 return true;
182 }
183
184 public function __read(): void
185 {
186 $this->start_objs = array();
187 $query = "SELECT * FROM crs_start " .
188 "WHERE crs_id = " . $this->db->quote($this->getId(), 'integer') . " ";
189 $res = $this->db->query($query);
190 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
191 if ($this->tree->isInTree((int) $row->item_ref_id)) {
192 $this->start_objs[(int) $row->crs_start_id]['item_ref_id'] = (int) $row->item_ref_id;
193 } else {
194 $this->delete((int) $row->item_ref_id);
195 }
196 }
197 }
198} // END class.ilObjCourseGrouping
static _getInstance(int $a_copy_id)
class ilCourseLMHistory
setRefId(int $a_ref_id)
__construct($a_course_ref_id, $a_course_obj_id)
ilDBInterface $db
ilObjectDataCache $objectDataCache
cloneDependencies(int $a_target_id, int $a_copy_id)
isFullfilled(int $user_id, int $item_id)
exists(int $a_item_ref_id)
add(int $a_item_ref_id)
static _hasUserCompleted(int $a_obj_id, int $a_user_id)
Lookup user object completion.
Component logger with individual log levels by component id.
static _lookupFinished(int $a_obj_id, int $a_user_id=0)
get finished status
static getItems(int $parent_id, bool $with_list_data=true)
Get sub item data.
class ilObjectDataCache
Tree class data representation in hierachical trees using the Nested Set Model with Gaps by Joe Celco...
static checkCondition(int $a_trigger_obj_id, string $a_operator, string $a_value, int $a_usr_id)
check condition for a specific user and object
Interface ilDBInterface.
$res
Definition: ltiservices.php:69
global $DIC
Definition: shib_login.php:26