ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilStudyProgrammeAutoCategoryDBRepository.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types = 1);
4
11{
12 const TABLE = 'prg_auto_content';
13 const FIELD_PRG_OBJ_ID = 'prg_obj_id';
14 const FIELD_CAT_REF_ID = 'cat_ref_id';
15 const FIELD_EDITOR_ID = 'last_usr_id';
16 const FIELD_LAST_EDITED = 'last_edited';
17
21 protected $db;
22
26 protected $current_usr_id;
27
28 public function __construct(
31 ) {
32 $this->db = $db;
33 $this->current_usr_id = $current_usr_id;
34 }
35
39 public function readFor(int $prg_obj_id) : array
40 {
41 $query = 'SELECT '
42 . self::FIELD_PRG_OBJ_ID . ','
43 . self::FIELD_CAT_REF_ID . ','
44 . self::FIELD_EDITOR_ID . ','
45 . self::FIELD_LAST_EDITED
46 . PHP_EOL . 'FROM ' . self::TABLE
47 . PHP_EOL . 'WHERE ' . self::FIELD_PRG_OBJ_ID . ' = '
48 . $this->db->quote($prg_obj_id, 'integer');
49
50 $res = $this->db->query($query);
51 $ret = [];
52 while ($rec = $this->db->fetchAssoc($res)) {
53 $ret[] = $this->create(
54 (int) $rec[self::FIELD_PRG_OBJ_ID],
55 (int) $rec[self::FIELD_CAT_REF_ID],
56 (int) $rec[self::FIELD_EDITOR_ID],
57 new \DateTimeImmutable($rec[self::FIELD_LAST_EDITED])
58 );
59 }
60 return $ret;
61 }
62
66 public function create(
67 int $prg_obj_id,
68 int $category_ref_id,
69 int $last_edited_usr_id = null,
70 \DateTimeImmutable $last_edited = null
72 if (is_null($last_edited_usr_id)) {
73 $last_edited_usr_id = $this->current_usr_id;
74 }
75 if (is_null($last_edited)) {
76 $last_edited = new \DateTimeImmutable();
77 }
78
80 $prg_obj_id,
81 $category_ref_id,
82 $last_edited_usr_id,
83 $last_edited
84 );
85 }
86
91 {
92 $ilAtomQuery = $this->db->buildAtomQuery();
93 $ilAtomQuery->addTableLock(self::TABLE);
94
95 $current_usr_id = $this->current_usr_id;
96 $ilAtomQuery->addQueryCallable(
97 function (ilDBInterface $db) use ($ac, $current_usr_id) {
98 $query = 'DELETE FROM ' . self::TABLE
99 . PHP_EOL . 'WHERE prg_obj_id = ' . $ac->getPrgObjId()
100 . PHP_EOL . 'AND cat_ref_id = ' . $ac->getCategoryRefId();
101 $db->manipulate($query);
102
103 $now = new \DateTimeImmutable();
104 $now = $now->format('Y-m-d H:i:s');
105 $db->insert(
106 self::TABLE,
107 [
108 self::FIELD_PRG_OBJ_ID => ['integer', $ac->getPrgObjId()],
109 self::FIELD_CAT_REF_ID => ['integer', $ac->getCategoryRefId()],
110 self::FIELD_EDITOR_ID => ['integer', $current_usr_id],
111 self::FIELD_LAST_EDITED => ['timestamp', $now]
112 ]
113 );
114 }
115 );
116 $ilAtomQuery->run();
117 }
118
122 public function delete(int $prg_obj_id, array $cat_ref_ids)
123 {
124 $ids = array_map(
125 function ($id) {
126 return $this->db->quote($id, 'integer');
127 },
128 $cat_ref_ids
129 );
130 $ids = implode(',', $ids);
131
132 $query = 'DELETE FROM ' . self::TABLE
133 . PHP_EOL . 'WHERE prg_obj_id = ' . $this->db->quote($prg_obj_id, 'integer')
134 . PHP_EOL . 'AND cat_ref_id IN (' . $ids . ')';
135 $this->db->manipulate($query);
136 }
137
141 public function deleteFor(int $prg_obj_id)
142 {
143 $query = 'DELETE FROM ' . self::TABLE
144 . PHP_EOL . 'WHERE prg_obj_id = ' . $this->db->quote($prg_obj_id, 'integer');
145 $this->db->manipulate($query);
146 }
147
148
152 public static function getProgrammesFor(int $cat_ref_id) : array
153 {
154 global $ilDB;
155 $query = 'SELECT ' . self::FIELD_PRG_OBJ_ID
156 . PHP_EOL . 'FROM ' . self::TABLE . ' prgs'
157 . PHP_EOL . 'INNER JOIN object_reference oref ON '
158 . 'prgs.' . self::FIELD_PRG_OBJ_ID . ' = oref.obj_id'
159 . PHP_EOL . 'WHERE ' . self::FIELD_CAT_REF_ID . ' = ' . $ilDB->quote($cat_ref_id, 'integer')
160 . PHP_EOL . 'AND oref.deleted IS NULL';
161
162 $res = $ilDB->query($query);
163 $ret = $ilDB->fetchAll($res);
164 return $ret;
165 }
166}
An exception for terminatinating execution or to throw for unit testing.
deleteFor(int $prg_obj_id)
Delete all category-surveillance settings for a StudyProgramme.
update(ilStudyProgrammeAutoCategory $ac)
Store a category-surveillance setting.
readFor(int $prg_obj_id)
Read category-surveillance settings of programme.ilStudyProgrammeAutoCategory[]
create(int $prg_obj_id, int $category_ref_id, int $last_edited_usr_id=null, \DateTimeImmutable $last_edited=null)
Build an auto-category object.ilStudyProgrammeAutoCategory
static getProgrammesFor(int $cat_ref_id)
Get all programmes' ref_ids monitoring the given category.int[]
Class ilStudyProgrammeAutoCategory.
if(!file_exists(getcwd() . '/ilias.ini.php'))
registration confirmation script for ilias
Definition: confirmReg.php:12
Interface ilDBInterface.
manipulate($query)
Run a (write) Query on the database.
insert($table_name, $values)
Persistence of "monitored" categories for a StudyProgramme.
$ret
Definition: parser.php:6
$query
foreach($_POST as $key=> $value) $res
global $ilDB