ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilStudyProgrammeAutoCategoryDBRepository.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
27{
28 private const TABLE = 'prg_auto_content';
29 private const FIELD_PRG_OBJ_ID = 'prg_obj_id';
30 private const FIELD_CAT_REF_ID = 'cat_ref_id';
31 private const FIELD_EDITOR_ID = 'last_usr_id';
32 private const FIELD_LAST_EDITED = 'last_edited';
33
34 protected ilDBInterface $db;
35 protected int $current_usr_id;
36
37 public function __construct(
40 ) {
41 $this->db = $db;
42 $this->current_usr_id = $current_usr_id;
43 }
44
48 public function getFor(int $prg_obj_id): array
49 {
50 $query = 'SELECT '
51 . self::FIELD_PRG_OBJ_ID . ','
52 . self::FIELD_CAT_REF_ID . ','
53 . self::FIELD_EDITOR_ID . ','
54 . self::FIELD_LAST_EDITED
55 . PHP_EOL . 'FROM ' . self::TABLE
56 . PHP_EOL . 'WHERE ' . self::FIELD_PRG_OBJ_ID . ' = '
57 . $this->db->quote($prg_obj_id, 'integer');
58
59 $res = $this->db->query($query);
60 $ret = [];
61 while ($rec = $this->db->fetchAssoc($res)) {
62 $ret[] = $this->create(
63 (int) $rec[self::FIELD_PRG_OBJ_ID],
64 (int) $rec[self::FIELD_CAT_REF_ID],
65 (int) $rec[self::FIELD_EDITOR_ID],
66 new DateTimeImmutable($rec[self::FIELD_LAST_EDITED])
67 );
68 }
69 return $ret;
70 }
71
75 public function create(
76 int $prg_obj_id,
77 int $category_ref_id,
78 ?int $last_edited_usr_id = null,
79 ?DateTimeImmutable $last_edited = null
81 if (is_null($last_edited_usr_id)) {
82 $last_edited_usr_id = $this->current_usr_id;
83 }
84 if (is_null($last_edited)) {
85 $last_edited = new DateTimeImmutable();
86 }
87
89 $prg_obj_id,
90 $category_ref_id,
91 $last_edited_usr_id,
92 $last_edited
93 );
94 }
95
99 public function update(ilStudyProgrammeAutoCategory $ac): void
100 {
101 $ilAtomQuery = $this->db->buildAtomQuery();
102 $ilAtomQuery->addTableLock(self::TABLE);
103
104 $current_usr_id = $this->current_usr_id;
105 $ilAtomQuery->addQueryCallable(
106 function (ilDBInterface $db) use ($ac, $current_usr_id) {
107 $query =
108 'DELETE FROM ' . self::TABLE . PHP_EOL
109 . 'WHERE prg_obj_id = ' . $ac->getPrgObjId() . PHP_EOL
110 . 'AND cat_ref_id = ' . $ac->getCategoryRefId()
111 ;
112
113 $db->manipulate($query);
114
115 $now = new DateTimeImmutable();
116 $now = $now->format('Y-m-d H:i:s');
117 $db->insert(
118 self::TABLE,
119 [
120 self::FIELD_PRG_OBJ_ID => ['integer', $ac->getPrgObjId()],
121 self::FIELD_CAT_REF_ID => ['integer', $ac->getCategoryRefId()],
122 self::FIELD_EDITOR_ID => ['integer', $current_usr_id],
123 self::FIELD_LAST_EDITED => ['timestamp', $now]
124 ]
125 );
126 }
127 );
128 $ilAtomQuery->run();
129 }
130
134 public function delete(int $prg_obj_id, array $cat_ref_ids): void
135 {
136 $ids = array_map(
137 function ($id) {
138 return $this->db->quote($id, 'integer');
139 },
140 $cat_ref_ids
141 );
142 $ids = implode(',', $ids);
143
144 $query =
145 'DELETE FROM ' . self::TABLE . PHP_EOL
146 . 'WHERE prg_obj_id = ' . $this->db->quote($prg_obj_id, 'integer') . PHP_EOL
147 . 'AND cat_ref_id IN (' . $ids . ')'
148 ;
149 $this->db->manipulate($query);
150 }
151
155 public function deleteFor(int $prg_obj_id): void
156 {
157 $query =
158 'DELETE FROM ' . self::TABLE . PHP_EOL
159 . 'WHERE prg_obj_id = ' . $this->db->quote($prg_obj_id, 'integer')
160 ;
161 $this->db->manipulate($query);
162 }
163
164
168 public static function getProgrammesFor(int $cat_ref_id): array
169 {
170 global $ilDB;
171 $query = 'SELECT ' . self::FIELD_PRG_OBJ_ID
172 . PHP_EOL . 'FROM ' . self::TABLE . ' prgs'
173 . PHP_EOL . 'INNER JOIN object_reference oref ON '
174 . 'prgs.' . self::FIELD_PRG_OBJ_ID . ' = oref.obj_id'
175 . PHP_EOL . 'WHERE ' . self::FIELD_CAT_REF_ID . ' = ' . $ilDB->quote($cat_ref_id, 'integer')
176 . PHP_EOL . 'AND oref.deleted IS NULL';
177
178 $res = $ilDB->query($query);
179 return $ilDB->fetchAll($res);
180 }
181}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
deleteFor(int $prg_obj_id)
Delete all category-surveillance settings for a StudyProgramme.
getFor(int $prg_obj_id)
Read category-surveillance settings of programme.ilStudyProgrammeAutoCategory[]
update(ilStudyProgrammeAutoCategory $ac)
Store a category-surveillance setting.
create(int $prg_obj_id, int $category_ref_id, ?int $last_edited_usr_id=null, ?DateTimeImmutable $last_edited=null)
Build an auto-category object.
static getProgrammesFor(int $cat_ref_id)
Get all programmes' ref_ids monitoring the given category.int[]
Class ilStudyProgrammeAutoCategory.
Interface ilDBInterface.
insert(string $table_name, array $values)
manipulate(string $query)
Run a (write) Query on the database.
Persistence of "monitored" categories for a StudyProgramme.
$res
Definition: ltiservices.php:69
if(!file_exists('../ilias.ini.php'))