19 declare(strict_types=1);
34 $found_context = $this->
find($context);
36 return $found_context;
40 if ($parent_context !==
null) {
41 $parent = $this->
find($parent_context);
45 $parent_id = $parent->getId();
49 ->withContext($context)
50 ->withParentContextId($parent_id);
51 $this->
store($context);
54 ->withPathNames([$context->getContext()])
55 ->withPathIds([$context->getId()]);
64 if ($operation_context->
getId() === 0) {
65 $operation_context = $this->
insert($operation_context);
67 $this->
update($operation_context);
68 $operation_context = $operation_context
70 ->withPathIds([$operation_context->
getId()]);
71 $operation_context = $this->
appendPath($operation_context);
74 return $operation_context;
79 $id = $this->db->nextId(self::TABLE_NAME);
82 'id' => [
'integer',
$id ],
83 'context' => [
'string', $operation_context->
getContext() ],
87 $this->db->insert(self::TABLE_NAME, $values);
90 ->withContext($operation_context->
getContext())
92 ->withPathNames([$operation_context->
getContext()])
101 $where = [
'id' => [
'integer', $operation_context->
getId() ] ];
104 'context' => [
'integer', $operation_context->
getContext() ],
108 $this->db->update(self::TABLE_NAME, $values, $where);
113 $operation_context = $this->
find($context);
114 if (!$operation_context) {
118 $query =
'DELETE FROM ' . self::TABLE_NAME . PHP_EOL
119 .
' WHERE id = ' . $this->db->quote($operation_context->getId(),
'integer');
120 $rows = $this->db->manipulate($query);
130 $query =
'SELECT id, context, parent_context_id FROM' . PHP_EOL
132 .
' WHERE ' . self::TABLE_NAME .
'.context = ' . $this->db->quote($context,
'string');
133 $res = $this->db->query($query);
134 if (
$res->numRows() === 0) {
138 $rec = $this->db->fetchAssoc(
$res);
140 ->withContext((
string) $rec[
'context'])
141 ->withParentContextId((
int) $rec[
'parent_context_id'])
142 ->withPathNames([(
string) $rec[
'context']])
143 ->withPathIds([(
int) $rec[
'id']]);
144 $operation_context = $this->
appendPath($operation_context);
146 return $operation_context;
151 $query =
'SELECT id, context, parent_context_id FROM' . PHP_EOL
153 .
' WHERE ' . self::TABLE_NAME .
'.id = ' . $this->db->quote($id,
'integer');
154 $res = $this->db->query($query);
155 if (
$res->numRows() === 0) {
159 $rec = $this->db->fetchAssoc(
$res);
161 ->withContext((
string) $rec[
'context'])
162 ->withParentContextId((
int) $rec[
'parent_context_id'])
163 ->withPathNames([(
string) $rec[
'context']])
164 ->withPathIds([(
int) $rec[
'id']]);
165 $operation_context = $this->
appendPath($operation_context);
167 return $operation_context;
173 return $this->
find($type_context);
179 return $this->
find($type_context);
186 if ($parent_context_id > 0) {
187 $parent = $this->
getById($parent_context_id);
190 $path_names[] = $parent->getContext();
192 $path_ids[] = $parent->getId();
194 $operation_context = $operation_context
196 ->withPathIds($path_ids);
198 $operation_context = $this->
appendPath($operation_context, $parent->
getId());
201 return $operation_context;
find(string $context)
Find an existing context Returns null if no context is found.
getByRefId(int $ref_id)
Get context by ref_id Returns null if no context is found.
insert(ilOrgUnitOperationContext $operation_context)
__construct(ilDBInterface $db)
getById(int $id)
Get context by id Returns null if no context is found.
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
store(ilOrgUnitOperationContext $operation_context)
Store context to db.
getByObjId(int $obj_id)
Get context by obj_id Returns null if no context is found.
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
update(ilOrgUnitOperationContext $operation_context)
withPathNames(array $path_names)
static _lookupType(int $id, bool $reference=false)
appendPath(ilOrgUnitOperationContext $operation_context, ?int $next=null)