3 declare(strict_types=0);
46 $this->db = $DIC->database();
47 $this->
logger = $DIC->logger()->crs();
50 $this->objective_id = $a_objective_id;
51 if ($this->objective_id) {
65 $ilDB = $DIC->database();
66 $query =
"SELECT crs_id FROM crs_objectives " .
67 "WHERE objective_id = " .
$ilDB->quote($a_objective_id,
'integer');
70 return (
int) $row->crs_id;
85 $query =
'SELECT passes from crs_objectives ' .
86 'WHERE objective_id = ' .
$ilDB->quote($a_objective_id,
'integer');
89 return (
int) $row->passes;
101 $ilDB = $DIC->database();
102 $query =
'SELECT title,description from crs_objectives ' .
103 'WHERE objective_id = ' .
$ilDB->quote($a_objective_id,
'integer');
106 if (!$a_add_description) {
107 return $row[
'title'];
115 public function ilClone(
int $a_target_id,
int $a_copy_id): void
117 $query =
"SELECT * FROM crs_objectives " .
118 "WHERE crs_id = " . $this->db->quote($this->course_obj->getId(),
'integer') .
' ' .
119 "ORDER BY position ";
121 if (
$res->numRows() === 0) {
122 $this->
logger->debug(
'.. no objectives found');
127 $this->
logger->warning(
'Cannot create course instance');
132 $new_objective->setTitle((
string) $row->title);
133 $new_objective->setDescription((
string) $row->description);
134 $new_objective->setActive((
bool) $row->active);
135 $objective_id = $new_objective->add();
136 $this->
logger->debug(
'Added new objective nr: ' . $objective_id);
140 $objective_qst->cloneDependencies($objective_id, $a_copy_id);
144 (
int) $row->objective_id,
148 $random_i->copy($a_copy_id, $new_course->getId(),
$objective_id);
152 (
int) $row->objective_id,
156 $random_q->copy($a_copy_id, $new_course->getId(),
$objective_id);
159 $assignment_it = $assignments->getAssignmentByObjective(
160 (
int) $row->objective_id,
163 if ($assignment_it) {
164 $assignment_it->cloneSettings($a_copy_id, $new_course->getId(),
$objective_id);
167 $assignment_qt = $assignments->getAssignmentByObjective(
168 (
int) $row->objective_id,
171 if ($assignment_qt) {
172 $assignment_qt->cloneSettings($a_copy_id, $new_course->getId(),
$objective_id);
175 $this->
logger->debug(
'Finished copying question dependencies');
179 $objective_material->cloneDependencies($objective_id, $a_copy_id);
181 $this->
logger->debug(
'Finished copying objectives');
186 $this->active = $a_stat;
196 $this->passes = $a_passes;
206 return $this->passes > 0;
213 $this->title = $a_title;
223 $this->description = $a_description;
233 $this->objective_id = $a_objective_id;
243 $this->position = $a_pos;
248 $next_id = $this->db->nextId(
'crs_objectives');
249 $query =
"INSERT INTO crs_objectives (crs_id,objective_id,active,title,description,position,created,passes) " .
251 $this->db->quote($this->course_obj->getId(),
'integer') .
", " .
252 $this->db->quote($next_id,
'integer') .
", " .
253 $this->db->quote($this->
isActive(),
'integer') .
', ' .
254 $this->db->quote($this->
getTitle(),
'text') .
", " .
257 $this->db->quote(time(),
'integer') .
", " .
258 $this->db->quote($this->
getPasses(),
'integer') .
' ' .
264 return $this->objective_id = $next_id;
269 $query =
"UPDATE crs_objectives " .
270 "SET title = " . $this->db->quote($this->
getTitle(),
'text') .
", " .
271 'active = ' . $this->db->quote($this->
isActive(),
'integer') .
', ' .
272 "description = " . $this->db->quote($this->
getDescription(),
'text') .
", " .
273 'passes = ' . $this->db->quote($this->
getPasses(),
'integer') .
' ' .
274 "WHERE objective_id = " . $this->db->quote($this->
getObjectiveId(),
'integer') .
" " .
275 "AND crs_id = " . $this->db->quote($this->course_obj->getId(),
'integer') .
" ";
281 $query =
"UPDATE crs_objectives " .
282 "SET position = " . $this->db->quote((
string) $a_position,
'integer') .
" " .
283 "WHERE objective_id = " . $this->db->quote($this->
getObjectiveId(),
'integer') .
" ";
289 return (
bool) strlen($this->
getTitle());
292 public function delete():
void 295 $tmp_obj_qst->deleteAll();
298 $tmp_obj_lm->deleteAll();
300 $query =
"DELETE FROM crs_objectives " .
301 "WHERE crs_id = " . $this->db->quote($this->course_obj->getId(),
'integer') .
" " .
302 "AND objective_id = " . $this->db->quote($this->getObjectiveId(),
'integer') .
" ";
319 $query =
"UPDATE crs_objectives " .
320 "SET position = position + 1 " .
321 "WHERE position = " . $this->db->quote($this->
__getPosition() - 1,
'integer') .
" " .
322 "AND crs_id = " . $this->db->quote($this->course_obj->getId(),
'integer') .
" ";
325 $query =
"UPDATE crs_objectives " .
326 "SET position = position - 1 " .
327 "WHERE objective_id = " . $this->db->quote($this->
getObjectiveId(),
'integer') .
" " .
328 "AND crs_id = " . $this->db->quote($this->course_obj->getId(),
'integer') .
" ";
344 $query =
"UPDATE crs_objectives " .
345 "SET position = position - 1 " .
346 "WHERE position = " . $this->db->quote($this->
__getPosition() + 1,
'integer') .
" " .
347 "AND crs_id = " . $this->db->quote($this->course_obj->getId(),
'integer') .
" ";
350 $query =
"UPDATE crs_objectives " .
351 "SET position = position + 1 " .
352 "WHERE objective_id = " . $this->db->quote($this->
getObjectiveId(),
'integer') .
" " .
353 "AND crs_id = " . $this->db->quote($this->course_obj->getId(),
'integer') .
" ";
361 $this->position = $a_position;
371 $this->created = $a_created;
382 $query =
"SELECT * FROM crs_objectives " .
383 "WHERE crs_id = " . $this->db->quote($this->course_obj->getId(),
'integer') .
" " .
384 "AND objective_id = " . $this->db->quote($this->getObjectiveId(),
'integer') .
" ";
393 $this->
setTitle((
string) $row->title);
403 switch ($this->course_obj->getOrderType()) {
405 return 'ORDER BY position';
408 return 'ORDER BY title';
411 return 'ORDER BY create';
418 $query =
"UPDATE crs_objectives " .
419 "SET position = position - 1 " .
420 "WHERE position > " . $this->db->quote($this->
__getPosition(),
'integer') .
" " .
421 "AND crs_id = " . $this->db->quote($this->course_obj->getId(),
'integer') .
" ";
427 $query =
"SELECT MAX(position) pos FROM crs_objectives " .
428 "WHERE crs_id = " . $this->db->quote($this->course_obj->getId(),
'integer') .
" ";
432 return (
int) $row->pos;
437 public static function _getObjectiveIds(
int $course_id,
bool $a_activated_only =
false): array
441 $ilDB = $DIC[
'ilDB'];
443 if ($a_activated_only) {
444 $query =
"SELECT objective_id FROM crs_objectives " .
445 "WHERE crs_id = " .
$ilDB->quote($course_id,
'integer') .
" " .
446 'AND active = ' .
$ilDB->quote(1,
'integer') .
' ' .
449 $query =
"SELECT objective_id FROM crs_objectives " .
450 "WHERE crs_id = " .
$ilDB->quote($course_id,
'integer') .
" " .
457 $ids[] = $row->objective_id;
466 $ilDB = $DIC[
'ilDB'];
475 $in =
$ilDB->in(
'objective_id', $ids,
false,
'integer');
477 $query =
"DELETE FROM crs_objective_lm WHERE " . $in;
480 $query =
"DELETE FROM crs_objective_tst WHERE " . $in;
483 $query =
"DELETE FROM crs_objective_qst WHERE " . $in;
486 $query =
"DELETE FROM crs_objectives WHERE crs_id = " .
$ilDB->quote($course_id,
'integer');
498 'online' => (
int) $this->
isActive(),
499 'position' => $this->position,
508 $materials->toXml($writer);
512 $test->toXml($writer);
setTitle(string $a_title)
toXml(ilXmlWriter $writer)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
writePosition(int $a_position)
static _getObjectiveIds(int $course_id, bool $a_activated_only=false)
static toXml(ilXmlWriter $writer, int $a_objective_id)
static _lookupContainerIdByObjectiveId(int $a_objective_id)
xmlEndTag(string $tag)
Writes an endtag.
static _deleteAll(int $course_id)
class ilCourseObjectiveMaterials
static _getCountObjectives(int $a_obj_id, bool $a_activated_only=false)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getInstanceByRefId(int $ref_id, bool $stop_on_error=true)
get an instance of an Ilias object by reference id
static lookupMaxPasses(int $a_objective_id)
static _refreshStatus(int $a_obj_id, ?array $a_users=null)
__construct(ilObject $course_obj, int $a_objective_id=0)
ilClone(int $a_target_id, int $a_copy_id)
setDescription(string $a_description)
__setPosition(int $a_position)
static lookupObjectiveTitle(int $a_objective_id, bool $a_add_description=false)
setObjectiveId(int $a_objective_id)
__setCreated(int $a_created)
static getInstance(int $a_container_id)
xmlStartTag(string $tag, ?array $attrs=null, bool $empty=false, bool $encode=true, bool $escape=true)
Writes a starttag.
const TYPE_TEST_QUALIFIED
xmlElement(string $tag, $attrs=null, $data=null, $encode=true, $escape=true)
Writes a basic element (no children, just textual content)
class ilcourseobjectiveQuestion