ILIAS  trunk Revision v11.0_alpha-1713-gd8962da2f67
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
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 27 of file class.ilOrgUnitOperationContextDBRepository.php.

References $db.

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

Member Function Documentation

◆ appendPath()

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

Definition at line 183 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().

184  {
185  $parent_context_id = ($next >= 0) ? $next : $operation_context->getParentContextId();
186  if ($parent_context_id > 0) {
187  $parent = $this->getById($parent_context_id);
188  if ($parent) {
189  $path_names = $operation_context->getPathNames();
190  $path_names[] = $parent->getContext();
191  $path_ids = $operation_context->getPathIds();
192  $path_ids[] = $parent->getId();
193 
194  $operation_context = $operation_context
195  ->withPathNames($path_names)
196  ->withPathIds($path_ids);
197 
198  $operation_context = $this->appendPath($operation_context, $parent->getId());
199  }
200  }
201  return $operation_context;
202  }
getById(int $id)
Get context by id Returns null if no context is found.
appendPath(ilOrgUnitOperationContext $operation_context, ?int $next=null)
+ 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 111 of file class.ilOrgUnitOperationContextDBRepository.php.

References find().

111  : bool
112  {
113  $operation_context = $this->find($context);
114  if (!$operation_context) {
115  return false;
116  }
117 
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);
121  if ($rows > 0) {
122  return true;
123  }
124 
125  return false;
126  }
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 128 of file class.ilOrgUnitOperationContextDBRepository.php.

References $res, appendPath(), and null.

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

129  {
130  $query = 'SELECT id, context, parent_context_id FROM' . PHP_EOL
131  . self::TABLE_NAME
132  . ' WHERE ' . self::TABLE_NAME . '.context = ' . $this->db->quote($context, 'string');
133  $res = $this->db->query($query);
134  if ($res->numRows() === 0) {
135  return null;
136  }
137 
138  $rec = $this->db->fetchAssoc($res);
139  $operation_context = (new ilOrgUnitOperationContext((int) $rec['id']))
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);
145 
146  return $operation_context;
147  }
$res
Definition: ltiservices.php:66
$context
Definition: webdav.php:31
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
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 32 of file class.ilOrgUnitOperationContextDBRepository.php.

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

33  {
34  $found_context = $this->find($context);
35  if ($found_context) {
36  return $found_context;
37  }
38 
39  $parent_id = 0;
40  if ($parent_context !== null) {
41  $parent = $this->find($parent_context);
42  if (!$parent) {
43  throw new ilException("Parent context not found");
44  }
45  $parent_id = $parent->getId();
46  }
47 
49  ->withContext($context)
50  ->withParentContextId($parent_id);
51  $this->store($context);
52 
54  ->withPathNames([$context->getContext()])
55  ->withPathIds([$context->getId()]);
56  $context = $this->appendPath($context);
57 
58  return $context;
59  }
find(string $context)
Find an existing context Returns null if no context is found.
$context
Definition: webdav.php:31
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
store(ilOrgUnitOperationContext $operation_context)
Store context to db.
appendPath(ilOrgUnitOperationContext $operation_context, ?int $next=null)
+ 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 149 of file class.ilOrgUnitOperationContextDBRepository.php.

References $res, appendPath(), and null.

Referenced by appendPath().

150  {
151  $query = 'SELECT id, context, parent_context_id FROM' . PHP_EOL
152  . self::TABLE_NAME
153  . ' WHERE ' . self::TABLE_NAME . '.id = ' . $this->db->quote($id, 'integer');
154  $res = $this->db->query($query);
155  if ($res->numRows() === 0) {
156  return null;
157  }
158 
159  $rec = $this->db->fetchAssoc($res);
160  $operation_context = (new ilOrgUnitOperationContext((int) $rec['id']))
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);
166 
167  return $operation_context;
168  }
$res
Definition: ltiservices.php:66
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
appendPath(ilOrgUnitOperationContext $operation_context, ?int $next=null)
+ 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 176 of file class.ilOrgUnitOperationContextDBRepository.php.

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

177  {
178  $type_context = ilObject2::_lookupType($obj_id, false);
179  return $this->find($type_context);
180  }
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 170 of file class.ilOrgUnitOperationContextDBRepository.php.

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

171  {
172  $type_context = ilObject2::_lookupType($ref_id, true);
173  return $this->find($type_context);
174  }
find(string $context)
Find an existing context Returns null if no context is found.
$ref_id
Definition: ltiauth.php:65
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 77 of file class.ilOrgUnitOperationContextDBRepository.php.

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

Referenced by store().

78  {
79  $id = $this->db->nextId(self::TABLE_NAME);
80 
81  $values = [
82  'id' => [ 'integer', $id ],
83  'context' => [ 'string', $operation_context->getContext() ],
84  'parent_context_id' => [ 'integer', $operation_context->getParentContextId() ]
85  ];
86 
87  $this->db->insert(self::TABLE_NAME, $values);
88 
89  $ret = (new ilOrgUnitOperationContext($id))
90  ->withContext($operation_context->getContext())
91  ->withParentContextId($operation_context->getParentContextId())
92  ->withPathNames([$operation_context->getContext()])
93  ->withPathIds([$id]);
94  $ret = $this->appendPath($ret);
95 
96  return $ret;
97  }
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
appendPath(ilOrgUnitOperationContext $operation_context, ?int $next=null)
+ 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 62 of file class.ilOrgUnitOperationContextDBRepository.php.

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

Referenced by get().

63  {
64  if ($operation_context->getId() === 0) {
65  $operation_context = $this->insert($operation_context);
66  } else {
67  $this->update($operation_context);
68  $operation_context = $operation_context
69  ->withPathNames([$operation_context->getContext()])
70  ->withPathIds([$operation_context->getId()]);
71  $operation_context = $this->appendPath($operation_context);
72  }
73 
74  return $operation_context;
75  }
insert(ilOrgUnitOperationContext $operation_context)
update(ilOrgUnitOperationContext $operation_context)
appendPath(ilOrgUnitOperationContext $operation_context, ?int $next=null)
+ 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 99 of file class.ilOrgUnitOperationContextDBRepository.php.

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

Referenced by store().

99  : void
100  {
101  $where = [ 'id' => [ 'integer', $operation_context->getId() ] ];
102 
103  $values = [
104  'context' => [ 'integer', $operation_context->getContext() ],
105  'parent_context_id' => [ 'integer', $operation_context->getParentContextId() ]
106  ];
107 
108  $this->db->update(self::TABLE_NAME, $values, $where);
109  }
+ 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 24 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: