ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilOrgUnitOperationContextQueries.php
Go to the documentation of this file.
1 <?php
24 {
28  public static function registerNewContext(string $context_name, ?string $parent_context = null): void
29  {
30  if (ilOrgUnitOperationContext::where(array('context' => $context_name))->hasSets()) {
31  throw new ilException('Context already registered');
32  }
33 
34  $parentList = ilOrgUnitOperationContext::where(array('context' => $parent_context));
35  $parent_id = 0;
36  if ($parent_context !== null && $parentList->hasSets()) {
37  $parent = $parentList->first();
38  if ($parent === null) {
39  throw new ilException('No record found');
40  }
41  $parent_id = $parent->getId();
42  }
43 
45  $context->setContext($context_name);
46  $context->setParentContextId($parent_id);
47  $context->create();
48  }
49 
50  protected static array $instance_by_name = array();
51 
52  public static function findByName(string $context_name): ilOrgUnitOperationContext
53  {
54  if (!isset(self::$instance_by_name[$context_name])) {
55  self::$instance_by_name[$context_name] = ilOrgUnitOperationContext::where(array('context' => $context_name))
56  ->first();
57  }
58 
59  return self::$instance_by_name[$context_name];
60  }
61 
62  public static function findById(int $id): ActiveRecord /*ilOrgUnitOperationContext|ActiveRecord*/
63  {
64  return ilOrgUnitOperationContext::find($id);
65  }
66 
67  public static function findByRefId(int $ref_id): ilOrgUnitOperationContext
68  {
69  $type_context = ilObject2::_lookupType($ref_id, true);
70 
71  return self::findByName($type_context);
72  }
73 
74  public static function findByObjId(int $obj_id): ilOrgUnitOperationContext
75  {
76  $type_context = ilObject2::_lookupType($obj_id, false);
77 
78  return self::findByName($type_context);
79  }
80 }
$context
Definition: webdav.php:29
static where($where, $operator=null)
static registerNewContext(string $context_name, ?string $parent_context=null)
$ref_id
Definition: ltiauth.php:67
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
static _lookupType(int $id, bool $reference=false)