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

Public Member Functions

 __construct (ilDBInterface $db)
 
 get (string $context, ?string $parent_context)
 Get a context If the context does not exist, it is created. More...
 
 store (ilOrgUnitOperationContext $operation_context)
 Store context to db. More...
 
 delete (string $context)
 Delete context by name Returns false, if no context is found. More...
 
 find (string $context)
 Find an existing context Returns null if no context is found. More...
 
 getById (int $id)
 Get context by id Returns null if no context is found. More...
 
 getByRefId (int $ref_id)
 Get context by ref_id Returns null if no context is found. More...
 
 getByObjId (int $obj_id)
 Get context by obj_id Returns null if no context is found. More...
 

Data Fields

const TABLE_NAME = 'il_orgu_op_contexts'
 

Protected Attributes

ilDBInterface $db
 

Private Member Functions

 insert (ilOrgUnitOperationContext $operation_context)
 
 update (ilOrgUnitOperationContext $operation_context)
 
 appendPath (ilOrgUnitOperationContext $operation_context, int $next=null)
 

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

ilOrgUnitOperationContextDBRepository::__construct ( ilDBInterface  $db)

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

References $db.

27  {
28  $this->db = $db;
29  }

Member Function Documentation

◆ appendPath()

ilOrgUnitOperationContextDBRepository::appendPath ( ilOrgUnitOperationContext  $operation_context,
int  $next = null 
)
private

Definition at line 182 of file class.ilOrgUnitOperationContextDBRepository.php.

References getById(), ilOrgUnitOperationContext\getId(), ilOrgUnitOperationContext\getParentContextId(), ilOrgUnitOperationContext\getPathIds(), ilOrgUnitOperationContext\getPathNames(), and ilOrgUnitOperationContext\withPathNames().

Referenced by find(), get(), getById(), insert(), and store().

183  {
184  $parent_context_id = ($next >= 0) ? $next : $operation_context->getParentContextId();
185  if ($parent_context_id > 0) {
186  $parent = $this->getById($parent_context_id);
187  if ($parent) {
188  $path_names = $operation_context->getPathNames();
189  $path_names[] = $parent->getContext();
190  $path_ids = $operation_context->getPathIds();
191  $path_ids[] = $parent->getId();
192 
193  $operation_context = $operation_context
194  ->withPathNames($path_names)
195  ->withPathIds($path_ids);
196 
197  $operation_context = $this->appendPath($operation_context, $parent->getId());
198  }
199  }
200  return $operation_context;
201  }
appendPath(ilOrgUnitOperationContext $operation_context, int $next=null)
getById(int $id)
Get context by id Returns null if no context is found.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ delete()

ilOrgUnitOperationContextDBRepository::delete ( string  $context)

Delete context by name Returns false, if no context is found.

Implements OrgUnitOperationContextRepository.

Definition at line 110 of file class.ilOrgUnitOperationContextDBRepository.php.

References find().

110  : bool
111  {
112  $operation_context = $this->find($context);
113  if (!$operation_context) {
114  return false;
115  }
116 
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);
120  if ($rows > 0) {
121  return true;
122  }
123 
124  return false;
125  }
find(string $context)
Find an existing context Returns null if no context is found.
$context
Definition: webdav.php:31
+ Here is the call graph for this function:

◆ find()

ilOrgUnitOperationContextDBRepository::find ( string  $context)

Find an existing context Returns null if no context is found.

Implements OrgUnitOperationContextRepository.

Definition at line 127 of file class.ilOrgUnitOperationContextDBRepository.php.

References $res, and appendPath().

Referenced by delete(), get(), getByObjId(), and getByRefId().

128  {
129  $query = 'SELECT id, context, parent_context_id FROM' . PHP_EOL
130  . self::TABLE_NAME
131  . ' WHERE ' . self::TABLE_NAME . '.context = ' . $this->db->quote($context, 'string');
132  $res = $this->db->query($query);
133  if ($res->numRows() === 0) {
134  return null;
135  }
136 
137  $rec = $this->db->fetchAssoc($res);
138  $operation_context = (new ilOrgUnitOperationContext((int) $rec['id']))
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);
144 
145  return $operation_context;
146  }
$res
Definition: ltiservices.php:69
$context
Definition: webdav.php:31
appendPath(ilOrgUnitOperationContext $operation_context, int $next=null)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ get()

ilOrgUnitOperationContextDBRepository::get ( string  $context,
?string  $parent_context 
)

Get a context If the context does not exist, it is created.

Exceptions
ilException

Implements OrgUnitOperationContextRepository.

Definition at line 31 of file class.ilOrgUnitOperationContextDBRepository.php.

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

32  {
33  $found_context = $this->find($context);
34  if ($found_context) {
35  return $found_context;
36  }
37 
38  $parent_id = 0;
39  if ($parent_context !== null) {
40  $parent = $this->find($parent_context);
41  if (!$parent) {
42  throw new ilException("Parent context not found");
43  }
44  $parent_id = $parent->getId();
45  }
46 
48  ->withContext($context)
49  ->withParentContextId($parent_id);
50  $this->store($context);
51 
53  ->withPathNames([$context->getContext()])
54  ->withPathIds([$context->getId()]);
55  $context = $this->appendPath($context);
56 
57  return $context;
58  }
find(string $context)
Find an existing context Returns null if no context is found.
$context
Definition: webdav.php:31
appendPath(ilOrgUnitOperationContext $operation_context, int $next=null)
store(ilOrgUnitOperationContext $operation_context)
Store context to db.
+ Here is the call graph for this function:

◆ getById()

ilOrgUnitOperationContextDBRepository::getById ( int  $id)

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

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

Deprecated:
Please refer to contexts by context name

Implements OrgUnitOperationContextRepository.

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

References $res, and appendPath().

Referenced by appendPath().

149  {
150  $query = 'SELECT id, context, parent_context_id FROM' . PHP_EOL
151  . self::TABLE_NAME
152  . ' WHERE ' . self::TABLE_NAME . '.id = ' . $this->db->quote($id, 'integer');
153  $res = $this->db->query($query);
154  if ($res->numRows() === 0) {
155  return null;
156  }
157 
158  $rec = $this->db->fetchAssoc($res);
159  $operation_context = (new ilOrgUnitOperationContext((int) $rec['id']))
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);
165 
166  return $operation_context;
167  }
$res
Definition: ltiservices.php:69
appendPath(ilOrgUnitOperationContext $operation_context, int $next=null)
$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:

◆ getByObjId()

ilOrgUnitOperationContextDBRepository::getByObjId ( int  $obj_id)

Get context by obj_id Returns null if no context is found.

Implements OrgUnitOperationContextRepository.

Definition at line 175 of file class.ilOrgUnitOperationContextDBRepository.php.

References ilObject\_lookupType(), and find().

176  {
177  $type_context = ilObject2::_lookupType($obj_id, false);
178  return $this->find($type_context);
179  }
find(string $context)
Find an existing context Returns null if no context is found.
static _lookupType(int $id, bool $reference=false)
+ Here is the call graph for this function:

◆ getByRefId()

ilOrgUnitOperationContextDBRepository::getByRefId ( int  $ref_id)

Get context by ref_id Returns null if no context is found.

Implements OrgUnitOperationContextRepository.

Definition at line 169 of file class.ilOrgUnitOperationContextDBRepository.php.

References ilObject\_lookupType(), and find().

170  {
171  $type_context = ilObject2::_lookupType($ref_id, true);
172  return $this->find($type_context);
173  }
find(string $context)
Find an existing context Returns null if no context is found.
$ref_id
Definition: ltiauth.php:67
static _lookupType(int $id, bool $reference=false)
+ Here is the call graph for this function:

◆ insert()

ilOrgUnitOperationContextDBRepository::insert ( ilOrgUnitOperationContext  $operation_context)
private

Definition at line 76 of file class.ilOrgUnitOperationContextDBRepository.php.

References $id, appendPath(), ilOrgUnitOperationContext\getContext(), and ilOrgUnitOperationContext\getParentContextId().

Referenced by store().

77  {
78  $id = $this->db->nextId(self::TABLE_NAME);
79 
80  $values = [
81  'id' => [ 'integer', $id ],
82  'context' => [ 'string', $operation_context->getContext() ],
83  'parent_context_id' => [ 'integer', $operation_context->getParentContextId() ]
84  ];
85 
86  $this->db->insert(self::TABLE_NAME, $values);
87 
88  $ret = (new ilOrgUnitOperationContext($id))
89  ->withContext($operation_context->getContext())
90  ->withParentContextId($operation_context->getParentContextId())
91  ->withPathNames([$operation_context->getContext()])
92  ->withPathIds([$id]);
93  $ret = $this->appendPath($ret);
94 
95  return $ret;
96  }
appendPath(ilOrgUnitOperationContext $operation_context, int $next=null)
$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()

ilOrgUnitOperationContextDBRepository::store ( ilOrgUnitOperationContext  $operation_context)

Store context to db.

Implements OrgUnitOperationContextRepository.

Definition at line 61 of file class.ilOrgUnitOperationContextDBRepository.php.

References appendPath(), ilOrgUnitOperationContext\getContext(), ilOrgUnitOperationContext\getId(), insert(), update(), and ilOrgUnitOperationContext\withPathNames().

Referenced by get().

62  {
63  if ($operation_context->getId() === 0) {
64  $operation_context = $this->insert($operation_context);
65  } else {
66  $this->update($operation_context);
67  $operation_context = $operation_context
68  ->withPathNames([$operation_context->getContext()])
69  ->withPathIds([$operation_context->getId()]);
70  $operation_context = $this->appendPath($operation_context);
71  }
72 
73  return $operation_context;
74  }
insert(ilOrgUnitOperationContext $operation_context)
appendPath(ilOrgUnitOperationContext $operation_context, int $next=null)
update(ilOrgUnitOperationContext $operation_context)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ update()

ilOrgUnitOperationContextDBRepository::update ( ilOrgUnitOperationContext  $operation_context)
private

Definition at line 98 of file class.ilOrgUnitOperationContextDBRepository.php.

References ilOrgUnitOperationContext\getContext(), ilOrgUnitOperationContext\getId(), and ilOrgUnitOperationContext\getParentContextId().

Referenced by store().

98  : void
99  {
100  $where = [ 'id' => [ 'integer', $operation_context->getId() ] ];
101 
102  $values = [
103  'context' => [ 'integer', $operation_context->getContext() ],
104  'parent_context_id' => [ 'integer', $operation_context->getParentContextId() ]
105  ];
106 
107  $this->db->update(self::TABLE_NAME, $values, $where);
108  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $db

ilDBInterface ilOrgUnitOperationContextDBRepository::$db
protected

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

Referenced by __construct().

◆ TABLE_NAME

const ilOrgUnitOperationContextDBRepository::TABLE_NAME = 'il_orgu_op_contexts'

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