ILIAS  release_8 Revision v8.23
ilStudyProgrammeAutoMembershipsDBRepository Class Reference

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V. More...

+ Inheritance diagram for ilStudyProgrammeAutoMembershipsDBRepository:
+ Collaboration diagram for ilStudyProgrammeAutoMembershipsDBRepository:

Public Member Functions

 __construct (ilDBInterface $db, int $current_usr_id)
 
 getFor (int $prg_obj_id)
 Read auto-membership sources of programme.
Returns
ilStudyProgrammeAutoMembershipSource[]
More...
 
 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. More...
 
 update (ilStudyProgrammeAutoMembershipSource $ams)
 Update an auto-membership source. More...
 
 delete (int $prg_obj_id, string $source_type, int $source_id)
 Delete a single source-setting. More...
 
 deleteFor (int $prg_obj_id)
 Delete all auto-membership sources of a programme. More...
 

Static Public Member Functions

static getProgrammesFor (string $source_type, int $source_id)
 Get all programmes' obj_ids monitoring the given source.
Returns
int[]
More...
 

Protected Attributes

ilDBInterface $db
 
int $current_usr_id
 

Private Attributes

const TABLE = 'prg_auto_membership'
 
const FIELD_PRG_OBJ_ID = 'prg_obj_id'
 
const FIELD_SOURCE_TYPE = 'source_type'
 
const FIELD_SOURCE_ID = 'source_id'
 
const FIELD_ENABLED = 'enabled'
 
const FIELD_EDITOR_ID = 'last_usr_id'
 
const FIELD_LAST_EDITED = 'last_edited'
 

Detailed Description

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V.

ILIAS is licensed with the GPL-3.0, see https://www.gnu.org/licenses/gpl-3.0.en.html You should have received a copy of said license along with the source code, too.

If this is not the case or you just want to try ILIAS, you'll find us at: https://www.ilias.de https://github.com/ILIAS-eLearning Class ilStudyProgrammeAutoMembershipsDBRepository

Author
Nils Haagen nils..nosp@m.haag.nosp@m.en@co.nosp@m.ncep.nosp@m.ts-an.nosp@m.d-tr.nosp@m.ainin.nosp@m.g.de

Definition at line 26 of file class.ilStudyProgrammeAutoMembershipsDBRepository.php.

Constructor & Destructor Documentation

◆ __construct()

ilStudyProgrammeAutoMembershipsDBRepository::__construct ( ilDBInterface  $db,
int  $current_usr_id 
)

Member Function Documentation

◆ create()

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.

Implements ilStudyProgrammeAutoMembershipsRepository.

Definition at line 75 of file class.ilStudyProgrammeAutoMembershipsDBRepository.php.

References $current_usr_id.

Referenced by getFor().

83  if (is_null($last_edited_usr_id)) {
84  $last_edited_usr_id = $this->current_usr_id;
85  }
86  if (is_null($last_edited)) {
87  $last_edited = new DateTimeImmutable();
88  }
90  $prg_obj_id,
91  $source_type,
92  $source_id,
93  $enabled,
94  $last_edited_usr_id,
95  $last_edited
96  );
97  }
bool $enabled
Whether the system instance is enabled to accept connection requests.
Definition: System.php:123
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
+ Here is the caller graph for this function:

◆ delete()

ilStudyProgrammeAutoMembershipsDBRepository::delete ( int  $prg_obj_id,
string  $source_type,
int  $source_id 
)

Delete a single source-setting.

Implements ilStudyProgrammeAutoMembershipsRepository.

Definition at line 135 of file class.ilStudyProgrammeAutoMembershipsDBRepository.php.

References $query.

135  : void
136  {
137  $query = 'DELETE FROM ' . self::TABLE
138  . PHP_EOL . 'WHERE prg_obj_id = ' . $this->db->quote($prg_obj_id, 'integer')
139  . PHP_EOL . 'AND ' . self::FIELD_SOURCE_TYPE . ' = ' . $this->db->quote($source_type, 'string')
140  . PHP_EOL . 'AND ' . self::FIELD_SOURCE_ID . ' = ' . $this->db->quote($source_id, 'integer');
141 
142  $this->db->manipulate($query);
143  }
$query

◆ deleteFor()

ilStudyProgrammeAutoMembershipsDBRepository::deleteFor ( int  $prg_obj_id)

Delete all auto-membership sources of a programme.

Implements ilStudyProgrammeAutoMembershipsRepository.

Definition at line 148 of file class.ilStudyProgrammeAutoMembershipsDBRepository.php.

References $query.

148  : void
149  {
150  $query = 'DELETE FROM ' . self::TABLE
151  . PHP_EOL . 'WHERE prg_obj_id = ' . $this->db->quote($prg_obj_id, 'integer');
152  $this->db->manipulate($query);
153  }
$query

◆ getFor()

ilStudyProgrammeAutoMembershipsDBRepository::getFor ( int  $prg_obj_id)

Read auto-membership sources of programme.

Returns
ilStudyProgrammeAutoMembershipSource[]

Implements ilStudyProgrammeAutoMembershipsRepository.

Definition at line 48 of file class.ilStudyProgrammeAutoMembershipsDBRepository.php.

References $query, $res, and create().

48  : array
49  {
50  $query = 'SELECT '
51  . self::FIELD_PRG_OBJ_ID . ','
52  . self::FIELD_SOURCE_TYPE . ','
53  . self::FIELD_SOURCE_ID . ','
54  . self::FIELD_ENABLED . ','
55  . self::FIELD_EDITOR_ID . ','
56  . self::FIELD_LAST_EDITED
57  . PHP_EOL . 'FROM ' . self::TABLE
58  . PHP_EOL . 'WHERE ' . self::FIELD_PRG_OBJ_ID . ' = '
59  . $this->db->quote($prg_obj_id, 'integer');
60  $res = $this->db->query($query);
61  $ret = [];
62  while ($rec = $this->db->fetchAssoc($res)) {
63  $ret[] = $this->create(
64  (int) $rec[self::FIELD_PRG_OBJ_ID],
65  $rec[self::FIELD_SOURCE_TYPE],
66  (int) $rec[self::FIELD_SOURCE_ID],
67  (bool) $rec[self::FIELD_ENABLED],
68  (int) $rec[self::FIELD_EDITOR_ID],
69  new DateTimeImmutable($rec[self::FIELD_LAST_EDITED])
70  );
71  }
72  return $ret;
73  }
$res
Definition: ltiservices.php:69
$query
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.
+ Here is the call graph for this function:

◆ getProgrammesFor()

static ilStudyProgrammeAutoMembershipsDBRepository::getProgrammesFor ( string  $source_type,
int  $source_id 
)
static

Get all programmes' obj_ids monitoring the given source.

Returns
int[]

Implements ilStudyProgrammeAutoMembershipsRepository.

Definition at line 158 of file class.ilStudyProgrammeAutoMembershipsDBRepository.php.

References $ilDB, $query, and $res.

158  : array
159  {
160  global $ilDB;
161  $query = 'SELECT ' . self::FIELD_PRG_OBJ_ID
162  . PHP_EOL . 'FROM ' . self::TABLE . ' prgs'
163  . PHP_EOL . 'INNER JOIN object_reference oref ON '
164  . 'prgs.' . self::FIELD_PRG_OBJ_ID . ' = oref.obj_id'
165  . PHP_EOL . 'WHERE ' . self::FIELD_SOURCE_TYPE . ' = ' . $ilDB->quote($source_type, 'text')
166  . PHP_EOL . 'AND ' . self::FIELD_SOURCE_ID . ' = ' . $ilDB->quote($source_id, 'integer')
167  . PHP_EOL . 'AND ' . self::FIELD_ENABLED . ' = 1'
168  . PHP_EOL . 'AND oref.deleted IS NULL';
169 
170  $res = $ilDB->query($query);
171  return $ilDB->fetchAll($res);
172  }
$res
Definition: ltiservices.php:69
$query

◆ update()

ilStudyProgrammeAutoMembershipsDBRepository::update ( ilStudyProgrammeAutoMembershipSource  $ams)

Update an auto-membership source.

Implements ilStudyProgrammeAutoMembershipsRepository.

Definition at line 102 of file class.ilStudyProgrammeAutoMembershipsDBRepository.php.

References $current_usr_id, $query, ilStudyProgrammeAutoMembershipSource\getPrgObjId(), ilStudyProgrammeAutoMembershipSource\getSourceId(), ilStudyProgrammeAutoMembershipSource\getSourceType(), ilDBInterface\insert(), ilStudyProgrammeAutoMembershipSource\isEnabled(), and ilDBInterface\manipulate().

102  : void
103  {
104  $ilAtomQuery = $this->db->buildAtomQuery();
105  $ilAtomQuery->addTableLock(self::TABLE);
107  $ilAtomQuery->addQueryCallable(
108  function (ilDBInterface $db) use ($ams, $current_usr_id) {
109  $query = 'DELETE FROM ' . self::TABLE
110  . PHP_EOL . 'WHERE prg_obj_id = ' . $ams->getPrgObjId()
111  . PHP_EOL . 'AND ' . self::FIELD_SOURCE_TYPE . ' = ' . $this->db->quote($ams->getSourceType(), 'string')
112  . PHP_EOL . 'AND ' . self::FIELD_SOURCE_ID . ' = ' . $ams->getSourceId();
113  $db->manipulate($query);
114  $now = new DateTimeImmutable();
115  $now = $now->format('Y-m-d H:i:s');
116  $db->insert(
117  self::TABLE,
118  [
119  self::FIELD_PRG_OBJ_ID => ['integer', $ams->getPrgObjId()],
120  self::FIELD_SOURCE_TYPE => ['text', $ams->getSourceType()],
121  self::FIELD_SOURCE_ID => ['integer', $ams->getSourceId()],
122  self::FIELD_ENABLED => ['integer', $ams->isEnabled()],
123  self::FIELD_EDITOR_ID => ['integer', $current_usr_id],
124  self::FIELD_LAST_EDITED => ['timestamp', $now]
125  ]
126  );
127  }
128  );
129  $ilAtomQuery->run();
130  }
insert(string $table_name, array $values)
$query
manipulate(string $query)
Run a (write) Query on the database.
+ Here is the call graph for this function:

Field Documentation

◆ $current_usr_id

int ilStudyProgrammeAutoMembershipsDBRepository::$current_usr_id
protected

◆ $db

ilDBInterface ilStudyProgrammeAutoMembershipsDBRepository::$db
protected

Definition at line 36 of file class.ilStudyProgrammeAutoMembershipsDBRepository.php.

Referenced by __construct().

◆ FIELD_EDITOR_ID

const ilStudyProgrammeAutoMembershipsDBRepository::FIELD_EDITOR_ID = 'last_usr_id'
private

◆ FIELD_ENABLED

const ilStudyProgrammeAutoMembershipsDBRepository::FIELD_ENABLED = 'enabled'
private

◆ FIELD_LAST_EDITED

const ilStudyProgrammeAutoMembershipsDBRepository::FIELD_LAST_EDITED = 'last_edited'
private

◆ FIELD_PRG_OBJ_ID

const ilStudyProgrammeAutoMembershipsDBRepository::FIELD_PRG_OBJ_ID = 'prg_obj_id'
private

◆ FIELD_SOURCE_ID

const ilStudyProgrammeAutoMembershipsDBRepository::FIELD_SOURCE_ID = 'source_id'
private

◆ FIELD_SOURCE_TYPE

const ilStudyProgrammeAutoMembershipsDBRepository::FIELD_SOURCE_TYPE = 'source_type'
private

◆ TABLE

const ilStudyProgrammeAutoMembershipsDBRepository::TABLE = 'prg_auto_membership'
private

The documentation for this class was generated from the following file: