ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
ilOrgUnitOperationDBRepository Class Reference
+ Inheritance diagram for ilOrgUnitOperationDBRepository:
+ Collaboration diagram for ilOrgUnitOperationDBRepository:

Public Member Functions

 __construct (ilDBInterface $db, ilOrgUnitOperationContextDBRepository $contextRepo)
 
 get (string $operation_string, string $description, array $contexts, int $list_order=0)
 Get an operation for each of the specified contexts If the operation does not exist for one or more contexts, it is created If any contexts do not exist yet, they are created as well. More...
 
 store (ilOrgUnitOperation $operation)
 Store operation to db. More...
 
 delete (ilOrgUnitOperation $operation)
 Delete an operation Returns false if the operation was not found. More...
 
 find (string $operation_string, string $context)
 Find an existing operation for a specified context Returns null if no operation is found. More...
 
 getById (int $operation_id)
 Get operation by id Returns null if no operation is found. More...
 
 getByName (string $operation_string)
 Get operation(s) by name. More...
 
 getOperationsByContextId (int $context_id)
 Get operations by context id. More...
 
 getOperationsByContextName (string $context)
 Get operations by context name. More...
 

Data Fields

const TABLE_NAME = 'il_orgu_operations'
 

Protected Attributes

ilDBInterface $db
 
ilOrgUnitOperationContextDBRepository $contextRepo
 

Private Member Functions

 insert (ilOrgUnitOperation $operation)
 
 update (ilOrgUnitOperation $operation)
 

Detailed Description

Definition at line 20 of file class.ilOrgUnitOperationDBRepository.php.

Constructor & Destructor Documentation

◆ __construct()

ilOrgUnitOperationDBRepository::__construct ( ilDBInterface  $db,
ilOrgUnitOperationContextDBRepository  $contextRepo 
)

Definition at line 27 of file class.ilOrgUnitOperationDBRepository.php.

References $contextRepo, and $db.

28  {
29  $this->db = $db;
30  $this->contextRepo = $contextRepo;
31  }
ilOrgUnitOperationContextDBRepository $contextRepo

Member Function Documentation

◆ delete()

ilOrgUnitOperationDBRepository::delete ( ilOrgUnitOperation  $operation)

Delete an operation Returns false if the operation was not found.

Implements OrgUnitOperationRepository.

Definition at line 104 of file class.ilOrgUnitOperationDBRepository.php.

104  : bool
105  {
106  if ($operation->getOperationId() === 0) {
107  return false;
108  }
109 
110  $query = 'DELETE FROM ' . self::TABLE_NAME . PHP_EOL
111  . ' WHERE operation_id = ' . $this->db->quote($operation->getOperationId(), 'integer');
112  $rows = $this->db->manipulate($query);
113  if ($rows > 0) {
114  return true;
115  }
116 
117  return false;
118  }

◆ find()

ilOrgUnitOperationDBRepository::find ( string  $operation_string,
string  $context 
)

Find an existing operation for a specified context Returns null if no operation is found.

Implements OrgUnitOperationRepository.

Definition at line 120 of file class.ilOrgUnitOperationDBRepository.php.

References $res.

Referenced by get().

121  {
122  $context = $this->contextRepo->find($context);
123  if (!$context) {
124  return null;
125  }
126 
127  $query = 'SELECT operation_id, operation_string, description, list_order, context_id FROM' . PHP_EOL
128  . self::TABLE_NAME
129  . ' WHERE ' . self::TABLE_NAME . '.operation_string = ' . $this->db->quote($operation_string, 'string') . PHP_EOL
130  . ' AND ' . self::TABLE_NAME . '.context_id = ' . $this->db->quote($context->getId(), 'integer');
131 
132  $res = $this->db->query($query);
133  if ($res->numRows() === 0) {
134  return null;
135  }
136 
137  $rec = $this->db->fetchAssoc($res);
138  return (new ilOrgUnitOperation((int) $rec['operation_id']))
139  ->withOperationString((string) $rec['operation_string'])
140  ->withDescription((string) $rec["description"])
141  ->withListOrder((int) $rec["list_order"])
142  ->withContextId((int) $rec['context_id']);
143  }
$res
Definition: ltiservices.php:69
$context
Definition: webdav.php:31
+ Here is the caller graph for this function:

◆ get()

ilOrgUnitOperationDBRepository::get ( string  $operation_string,
string  $description,
array  $contexts,
int  $list_order = 0 
)

Get an operation for each of the specified contexts If the operation does not exist for one or more contexts, it is created If any contexts do not exist yet, they are created as well.

Parameters
array$contextsstring[]
Returns
array ilOrgUnitOperation[]

Implements OrgUnitOperationRepository.

Definition at line 33 of file class.ilOrgUnitOperationDBRepository.php.

References $context, find(), and store().

33  : array
34  {
35  $operations = [];
36  foreach ($contexts as $context) {
37  $operation = $this->find($operation_string, $context);
38  if ($operation) {
39  $operations[] = $operation;
40  continue;
41  }
42 
43  $operation_context = $this->contextRepo->get($context, null);
44 
45  $new_operation = (new ilOrgUnitOperation())
46  ->withOperationString($operation_string)
47  ->withDescription($description)
48  ->withListOrder($list_order)
49  ->withContextId($operation_context->getId());
50  $new_operation = $this->store($new_operation);
51 
52  $operations[] = $new_operation;
53  }
54 
55  return $operations;
56  }
$context
Definition: webdav.php:31
find(string $operation_string, string $context)
Find an existing operation for a specified context Returns null if no operation is found...
store(ilOrgUnitOperation $operation)
Store operation to db.
+ Here is the call graph for this function:

◆ getById()

ilOrgUnitOperationDBRepository::getById ( int  $operation_id)

Get operation by id Returns null if no operation is found.

This is only kept for backwards compatibility, but might be removed at a later date

Deprecated:
Please refer to operations by operation_string and context

Implements OrgUnitOperationRepository.

Definition at line 145 of file class.ilOrgUnitOperationDBRepository.php.

References $res.

146  {
147  $query = 'SELECT operation_id, operation_string, description, list_order, context_id FROM' . PHP_EOL
148  . self::TABLE_NAME
149  . ' WHERE ' . self::TABLE_NAME . '.operation_id = ' . $this->db->quote($operation_id, 'integer');
150 
151  $res = $this->db->query($query);
152  if ($res->numRows() === 0) {
153  return null;
154  }
155 
156  $rec = $this->db->fetchAssoc($res);
157  return (new ilOrgUnitOperation((int) $rec['operation_id']))
158  ->withOperationString((string) $rec['operation_string'])
159  ->withDescription((string) $rec["description"])
160  ->withListOrder((int) $rec["list_order"])
161  ->withContextId((int) $rec['context_id']);
162  }
$res
Definition: ltiservices.php:69

◆ getByName()

ilOrgUnitOperationDBRepository::getByName ( string  $operation_string)

Get operation(s) by name.

Returns
array ilOrgUnitOperation[]

Implements OrgUnitOperationRepository.

Definition at line 164 of file class.ilOrgUnitOperationDBRepository.php.

References $res.

164  : array
165  {
166  $query = 'SELECT operation_id, operation_string, description, list_order, context_id FROM' . PHP_EOL
167  . self::TABLE_NAME
168  . ' WHERE ' . self::TABLE_NAME . '.operation_string = ' . $this->db->quote($operation_string, 'string');
169 
170  $res = $this->db->query($query);
171  if ($res->numRows() === 0) {
172  return [];
173  }
174 
175  $ret = [];
176  while ($rec = $this->db->fetchAssoc($res)) {
177  $operation = (new ilOrgUnitOperation((int)$rec['operation_id']))
178  ->withOperationString((string)$rec['operation_string'])
179  ->withDescription((string)$rec["description"])
180  ->withListOrder((int)$rec["list_order"])
181  ->withContextId((int)$rec['context_id']);
182  $ret[] = $operation;
183  }
184 
185  return $ret;
186  }
$res
Definition: ltiservices.php:69

◆ getOperationsByContextId()

ilOrgUnitOperationDBRepository::getOperationsByContextId ( int  $context_id)

Get operations by context id.

This is only kept for backwards compatibility, but might be removed at a later date

Deprecated:
Please refer to contexts by context name (see getOperationsByContextName)
Returns
array ilOrgUnitOperation[]

Implements OrgUnitOperationRepository.

Definition at line 188 of file class.ilOrgUnitOperationDBRepository.php.

References $res.

188  : array
189  {
190  $operation_context = $this->contextRepo->getById($context_id);
191  if (!$operation_context) {
192  throw new ilException('Context with id ' . $context_id . ' does not exist!');
193  }
194 
195  $query = 'SELECT operation_id, operation_string, description, list_order, context_id FROM' . PHP_EOL
196  . self::TABLE_NAME
197  . ' WHERE ' . self::TABLE_NAME . '.context_id = ' . $this->db->quote($operation_context->getId(), 'integer');
198  $res = $this->db->query($query);
199 
200  $ret = [];
201  while ($rec = $this->db->fetchAssoc($res)) {
202  $operation = (new ilOrgUnitOperation((int)$rec['operation_id']))
203  ->withOperationString((string)$rec['operation_string'])
204  ->withDescription((string)$rec["description"])
205  ->withListOrder((int)$rec["list_order"])
206  ->withContextId((int)$rec['context_id']);
207  $ret[] = $operation;
208  }
209 
210  return $ret;
211  }
$res
Definition: ltiservices.php:69

◆ getOperationsByContextName()

ilOrgUnitOperationDBRepository::getOperationsByContextName ( string  $context)

Get operations by context name.

Returns
array ilOrgUnitOperation[]

Implements OrgUnitOperationRepository.

Definition at line 213 of file class.ilOrgUnitOperationDBRepository.php.

References $res.

213  : array
214  {
215  $operation_context = $this->contextRepo->find($context);
216  if (!$operation_context) {
217  throw new ilException('Context ' . $context . ' does not exist!');
218  }
219 
220  $query = 'SELECT operation_id, operation_string, description, list_order, context_id FROM' . PHP_EOL
221  . self::TABLE_NAME
222  . ' WHERE ' . self::TABLE_NAME . '.context_id = ' . $this->db->quote($operation_context->getId(), 'integer');
223  $res = $this->db->query($query);
224 
225  $ret = [];
226  while ($rec = $this->db->fetchAssoc($res)) {
227  $operation = (new ilOrgUnitOperation((int)$rec['operation_id']))
228  ->withOperationString((string)$rec['operation_string'])
229  ->withDescription((string)$rec["description"])
230  ->withListOrder((int)$rec["list_order"])
231  ->withContextId((int)$rec['context_id']);
232  $ret[] = $operation;
233  }
234 
235  return $ret;
236  }
$res
Definition: ltiservices.php:69
$context
Definition: webdav.php:31

◆ insert()

ilOrgUnitOperationDBRepository::insert ( ilOrgUnitOperation  $operation)
private

Definition at line 69 of file class.ilOrgUnitOperationDBRepository.php.

References $id, ilOrgUnitOperation\getContextId(), ilOrgUnitOperation\getDescription(), ilOrgUnitOperation\getListOrder(), and ilOrgUnitOperation\getOperationString().

Referenced by store().

70  {
71  $id = $this->db->nextId(self::TABLE_NAME);
72 
73  $values = [
74  'operation_id' => [ 'integer', $id ],
75  'operation_string' => [ 'string', $operation->getOperationString()],
76  'description' => [ 'string', $operation->getDescription()],
77  'list_order' => [ 'integer', $operation->getListOrder() ],
78  'context_id' => [ 'integer', $operation->getContextId() ]
79  ];
80 
81  $this->db->insert(self::TABLE_NAME, $values);
82 
83  return (new ilOrgUnitOperation($id))
84  ->withOperationString($operation->getOperationString())
85  ->withDescription($operation->getDescription())
86  ->withListOrder($operation->getListOrder())
87  ->withContextId($operation->getContextId());
88  }
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ store()

ilOrgUnitOperationDBRepository::store ( ilOrgUnitOperation  $operation)

Store operation to db.

Implements OrgUnitOperationRepository.

Definition at line 58 of file class.ilOrgUnitOperationDBRepository.php.

References ilOrgUnitOperation\getOperationId(), insert(), and update().

Referenced by get().

59  {
60  if ($operation->getOperationId() === 0) {
61  $operation = $this->insert($operation);
62  } else {
63  $this->update($operation);
64  }
65 
66  return $operation;
67  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ update()

ilOrgUnitOperationDBRepository::update ( ilOrgUnitOperation  $operation)
private

Definition at line 90 of file class.ilOrgUnitOperationDBRepository.php.

References ilOrgUnitOperation\getContextId(), ilOrgUnitOperation\getDescription(), ilOrgUnitOperation\getListOrder(), ilOrgUnitOperation\getOperationId(), and ilOrgUnitOperation\getOperationString().

Referenced by store().

90  : void
91  {
92  $where = [ 'operation_id' => [ 'integer', $operation->getOperationId() ] ];
93 
94  $values = [
95  'operation_string' => [ 'string', $operation->getOperationString()],
96  'description' => [ 'string', $operation->getDescription()],
97  'list_order' => [ 'integer', $operation->getListOrder() ],
98  'context_id' => [ 'integer', $operation->getContextId() ]
99  ];
100 
101  $this->db->update(self::TABLE_NAME, $values, $where);
102  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $contextRepo

ilOrgUnitOperationContextDBRepository ilOrgUnitOperationDBRepository::$contextRepo
protected

Definition at line 24 of file class.ilOrgUnitOperationDBRepository.php.

Referenced by __construct().

◆ $db

ilDBInterface ilOrgUnitOperationDBRepository::$db
protected

Definition at line 23 of file class.ilOrgUnitOperationDBRepository.php.

Referenced by __construct().

◆ TABLE_NAME

const ilOrgUnitOperationDBRepository::TABLE_NAME = 'il_orgu_operations'

Definition at line 22 of file class.ilOrgUnitOperationDBRepository.php.


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