18 declare(strict_types=1);
33 $found_context = $this->
find($context);
35 return $found_context;
39 if ($parent_context !== null) {
40 $parent = $this->
find($parent_context);
44 $parent_id = $parent->getId();
48 ->withContext($context)
49 ->withParentContextId($parent_id);
50 $this->
store($context);
53 ->withPathNames([$context->getContext()])
54 ->withPathIds([$context->getId()]);
63 if ($operation_context->
getId() === 0) {
64 $operation_context = $this->
insert($operation_context);
66 $this->
update($operation_context);
67 $operation_context = $operation_context
69 ->withPathIds([$operation_context->
getId()]);
70 $operation_context = $this->
appendPath($operation_context);
73 return $operation_context;
78 $id = $this->db->nextId(self::TABLE_NAME);
81 'id' => [
'integer',
$id ],
82 'context' => [
'string', $operation_context->
getContext() ],
86 $this->db->insert(self::TABLE_NAME, $values);
89 ->withContext($operation_context->
getContext())
91 ->withPathNames([$operation_context->
getContext()])
100 $where = [
'id' => [
'integer', $operation_context->
getId() ] ];
103 'context' => [
'integer', $operation_context->
getContext() ],
107 $this->db->update(self::TABLE_NAME, $values, $where);
112 $operation_context = $this->
find($context);
113 if (!$operation_context) {
117 $query =
'DELETE FROM ' . self::TABLE_NAME . PHP_EOL
118 .
' WHERE id = ' . $this->db->quote($operation_context->getId(),
'integer');
119 $rows = $this->db->manipulate($query);
129 $query =
'SELECT id, context, parent_context_id FROM' . PHP_EOL
131 .
' WHERE ' . self::TABLE_NAME .
'.context = ' . $this->db->quote($context,
'string');
132 $res = $this->db->query($query);
133 if (
$res->numRows() === 0) {
137 $rec = $this->db->fetchAssoc(
$res);
139 ->withContext((
string) $rec[
'context'])
140 ->withParentContextId((
int) $rec[
'parent_context_id'])
141 ->withPathNames([(
string) $rec[
'context']])
142 ->withPathIds([(
int) $rec[
'id']]);
143 $operation_context = $this->
appendPath($operation_context);
145 return $operation_context;
150 $query =
'SELECT id, context, parent_context_id FROM' . PHP_EOL
152 .
' WHERE ' . self::TABLE_NAME .
'.id = ' . $this->db->quote($id,
'integer');
153 $res = $this->db->query($query);
154 if (
$res->numRows() === 0) {
158 $rec = $this->db->fetchAssoc(
$res);
160 ->withContext((
string) $rec[
'context'])
161 ->withParentContextId((
int) $rec[
'parent_context_id'])
162 ->withPathNames([(
string) $rec[
'context']])
163 ->withPathIds([(
int) $rec[
'id']]);
164 $operation_context = $this->
appendPath($operation_context);
166 return $operation_context;
172 return $this->
find($type_context);
178 return $this->
find($type_context);
185 if ($parent_context_id > 0) {
186 $parent = $this->
getById($parent_context_id);
189 $path_names[] = $parent->getContext();
191 $path_ids[] = $parent->getId();
193 $operation_context = $operation_context
195 ->withPathIds($path_ids);
197 $operation_context = $this->
appendPath($operation_context, $parent->
getId());
200 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)
appendPath(ilOrgUnitOperationContext $operation_context, int $next=null)
__construct(ilDBInterface $db)
getById(int $id)
Get context by id Returns null if no context is found.
store(ilOrgUnitOperationContext $operation_context)
Store context to db.
getByObjId(int $obj_id)
Get context by obj_id Returns null if no context is found.
update(ilOrgUnitOperationContext $operation_context)
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
withPathNames(array $path_names)
static _lookupType(int $id, bool $reference=false)