3 declare(strict_types = 1);
12 const TABLE =
'prg_auto_membership';
40 public function getFor(
int $prg_obj_id) : array
43 . self::FIELD_PRG_OBJ_ID .
',' 44 . self::FIELD_SOURCE_TYPE .
',' 45 . self::FIELD_SOURCE_ID .
',' 46 . self::FIELD_ENABLED .
',' 47 . self::FIELD_EDITOR_ID .
',' 48 . self::FIELD_LAST_EDITED
49 . PHP_EOL .
'FROM ' . self::TABLE
50 . PHP_EOL .
'WHERE ' . self::FIELD_PRG_OBJ_ID .
' = ' 51 . $this->db->quote($prg_obj_id,
'integer');
54 while ($rec = $this->db->fetchAssoc(
$res)) {
56 (
int) $rec[self::FIELD_PRG_OBJ_ID],
57 $rec[self::FIELD_SOURCE_TYPE],
58 (
int) $rec[self::FIELD_SOURCE_ID],
59 (
bool) $rec[self::FIELD_ENABLED],
60 (
int) $rec[self::FIELD_EDITOR_ID],
72 int $last_edited_usr_id = null,
75 if (is_null($last_edited_usr_id)) {
78 if (is_null($last_edited)) {
79 $last_edited = new \DateTimeImmutable();
96 $ilAtomQuery = $this->db->buildAtomQuery();
97 $ilAtomQuery->addTableLock(self::TABLE);
99 $ilAtomQuery->addQueryCallable(
101 $query =
'DELETE FROM ' . self::TABLE
102 . PHP_EOL .
'WHERE prg_obj_id = ' . $ams->
getPrgObjId()
103 . PHP_EOL .
'AND ' . self::FIELD_SOURCE_TYPE .
' = ' . $this->db->quote($ams->
getSourceType(),
'string')
104 . PHP_EOL .
'AND ' . self::FIELD_SOURCE_ID .
' = ' . $ams->
getSourceId();
106 $now = new \DateTimeImmutable();
107 $now = $now->format(
'Y-m-d H:i:s');
111 self::FIELD_PRG_OBJ_ID => [
'integer', $ams->
getPrgObjId()],
113 self::FIELD_SOURCE_ID => [
'integer', $ams->
getSourceId()],
114 self::FIELD_ENABLED => [
'integer', $ams->
isEnabled()],
116 self::FIELD_LAST_EDITED => [
'timestamp', $now]
127 public function delete(
int $prg_obj_id,
string $source_type,
int $source_id)
129 $query =
'DELETE FROM ' . self::TABLE
130 . PHP_EOL .
'WHERE prg_obj_id = ' . $this->db->quote($prg_obj_id,
'integer')
131 . PHP_EOL .
'AND ' . self::FIELD_SOURCE_TYPE .
' = ' . $this->db->quote($source_type,
'string')
132 . PHP_EOL .
'AND ' . self::FIELD_SOURCE_ID .
' = ' . $this->db->quote($source_id,
'integer');
134 $this->db->manipulate(
$query);
142 $query =
'DELETE FROM ' . self::TABLE
143 . PHP_EOL .
'WHERE prg_obj_id = ' . $this->db->quote($prg_obj_id,
'integer');
144 $this->db->manipulate(
$query);
153 $query =
'SELECT ' . self::FIELD_PRG_OBJ_ID
154 . PHP_EOL .
'FROM ' . self::TABLE .
' prgs' 155 . PHP_EOL .
'INNER JOIN object_reference oref ON ' 156 .
'prgs.' . self::FIELD_PRG_OBJ_ID .
' = oref.obj_id' 157 . PHP_EOL .
'WHERE ' . self::FIELD_SOURCE_TYPE .
' = ' . $ilDB->quote($source_type,
'text')
158 . PHP_EOL .
'AND ' . self::FIELD_SOURCE_ID .
' = ' . $ilDB->quote($source_id,
'integer')
159 . PHP_EOL .
'AND ' . self::FIELD_ENABLED .
' = 1' 160 . PHP_EOL .
'AND oref.deleted IS NULL';
static getProgrammesFor(string $source_type, int $source_id)
Get all programmes' obj_ids monitoring the given source.int[]
foreach($_POST as $key=> $value) $res
Persistence of "monitored" sources for automatic membership.
deleteFor(int $prg_obj_id)
Delete all auto-membership sources of a programme.
Class ilStudyProgrammeAutoMembershipSource.
__construct(ilDBInterface $db, int $current_usr_id)
insert($table_name, $values)
getFor(int $prg_obj_id)
Read auto-membership sources of programme.ilStudyProgrammeAutoMembershipSource[]
update(ilStudyProgrammeAutoMembershipSource $ams)
Update an auto-membership source.ilStudyProgrammeAutoCategory[]
manipulate($query)
Run a (write) Query on the database.
Class ilStudyProgrammeAutoMembershipsDBRepository.
create(int $prg_obj_id, string $source_type, int $source_id, bool $enabled, int $last_edited_usr_id=null, \DateTimeImmutable $last_edited=null)
Build an auto-membership source.