ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
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...
 
 get (string $operation_string, string $description, array $contexts, int $list_order)
 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 21 of file class.ilOrgUnitOperationDBRepository.php.

Constructor & Destructor Documentation

◆ __construct()

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

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

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

References $contextRepo, and $db.

Member Function Documentation

◆ delete()

ilOrgUnitOperationDBRepository::delete ( ilOrgUnitOperation  $operation)

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

Implements OrgUnitOperationRepository.

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

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

◆ 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 121 of file class.ilOrgUnitOperationDBRepository.php.

122 {
123 $context = $this->contextRepo->find($context);
124 if (!$context) {
125 return null;
126 }
127
128 $query = 'SELECT operation_id, operation_string, description, list_order, context_id FROM' . PHP_EOL
129 . self::TABLE_NAME
130 . ' WHERE ' . self::TABLE_NAME . '.operation_string = ' . $this->db->quote($operation_string, 'string') . PHP_EOL
131 . ' AND ' . self::TABLE_NAME . '.context_id = ' . $this->db->quote($context->getId(), 'integer');
132
133 $res = $this->db->query($query);
134 if ($res->numRows() === 0) {
135 return null;
136 }
137
138 $rec = $this->db->fetchAssoc($res);
139 return (new ilOrgUnitOperation((int) $rec['operation_id']))
140 ->withOperationString((string) $rec['operation_string'])
141 ->withDescription((string) $rec["description"])
142 ->withListOrder((int) $rec["list_order"])
143 ->withContextId((int) $rec['context_id']);
144 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$res
Definition: ltiservices.php:69
$context
Definition: webdav.php:31

References $context, and $res.

Referenced by get().

+ 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 34 of file class.ilOrgUnitOperationDBRepository.php.

34 : array
35 {
36 $operations = [];
37 foreach ($contexts as $context) {
38 $operation = $this->find($operation_string, $context);
39 if ($operation) {
40 $operations[] = $operation;
41 continue;
42 }
43
44 $operation_context = $this->contextRepo->get($context, null);
45
46 $new_operation = (new ilOrgUnitOperation())
47 ->withOperationString($operation_string)
48 ->withDescription($description)
49 ->withListOrder($list_order)
50 ->withContextId($operation_context->getId());
51 $new_operation = $this->store($new_operation);
52
53 $operations[] = $new_operation;
54 }
55
56 return $operations;
57 }
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.

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

+ 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 146 of file class.ilOrgUnitOperationDBRepository.php.

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

References $res.

◆ getByName()

ilOrgUnitOperationDBRepository::getByName ( string  $operation_string)

Get operation(s) by name.

Returns
array ilOrgUnitOperation[]

Implements OrgUnitOperationRepository.

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

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

References $res.

◆ 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 189 of file class.ilOrgUnitOperationDBRepository.php.

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

References $res.

◆ getOperationsByContextName()

ilOrgUnitOperationDBRepository::getOperationsByContextName ( string  $context)

Get operations by context name.

Returns
array ilOrgUnitOperation[]

Implements OrgUnitOperationRepository.

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

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

References $context, and $res.

◆ insert()

ilOrgUnitOperationDBRepository::insert ( ilOrgUnitOperation  $operation)
private

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

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

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

Referenced by store().

+ 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 59 of file class.ilOrgUnitOperationDBRepository.php.

60 {
61 if ($operation->getOperationId() === 0) {
62 $operation = $this->insert($operation);
63 } else {
64 $this->update($operation);
65 }
66
67 return $operation;
68 }

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

Referenced by get().

+ 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 91 of file class.ilOrgUnitOperationDBRepository.php.

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

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

Referenced by store().

+ 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 25 of file class.ilOrgUnitOperationDBRepository.php.

Referenced by __construct().

◆ $db

ilDBInterface ilOrgUnitOperationDBRepository::$db
protected

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

Referenced by __construct().

◆ TABLE_NAME

const ilOrgUnitOperationDBRepository::TABLE_NAME = 'il_orgu_operations'

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


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