ILIAS  trunk Revision v11.0_alpha-1811-gd2d5443e411
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
ilOrgUnitOperationRegisteredObjective Class Reference
+ Inheritance diagram for ilOrgUnitOperationRegisteredObjective:
+ Collaboration diagram for ilOrgUnitOperationRegisteredObjective:

Public Member Functions

 __construct (string $operation_name, string $description, string $context=ilOrgUnitOperationContext::CONTEXT_OBJECT)
 
 getHash ()
 
 getLabel ()
 
 isNotable ()
 
 getPreconditions (Environment $environment)
 
 achieve (Environment $environment)
 
 isApplicable (Environment $environment)
 

Protected Member Functions

 doesOperationExistInContext (ilDBInterface $db, int $context_id, string $operation)
 
 getContextId (ilDBInterface $db, string $context)
 Defaults to 0 if context is not found. More...
 

Protected Attributes

string $operation_name
 
string $description
 
string $context
 

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

ilOrgUnitOperationRegisteredObjective::__construct ( string  $operation_name,
string  $description,
string  $context = ilOrgUnitOperationContext::CONTEXT_OBJECT 
)

Member Function Documentation

◆ achieve()

ilOrgUnitOperationRegisteredObjective::achieve ( Environment  $environment)

Definition at line 63 of file class.ilOrgUnitOperationRegisteredObjective.php.

References $id, doesOperationExistInContext(), getContextId(), and ILIAS\Setup\Environment\getResource().

63  : Environment
64  {
65  $db = $environment->getResource(Environment::RESOURCE_DATABASE);
66 
67  // abort if context does not exist, just to be safe
68  if (!($context_id = $this->getContextId($db, $this->context))) {
69  throw new Exception(
70  'Context ' . $this->context . ' does not exists,
71  this objective should not be applied!'
72  );
73  }
74 
75  // abort if operation already exists in this context, just to be safe
76  if ($this->doesOperationExistInContext(
77  $db,
78  $context_id,
79  $this->operation_name
80  )) {
81  return $environment;
82  }
83 
84  $id = $db->nextId('il_orgu_operations');
85  $db->insert('il_orgu_operations', [
86  'operation_id' => ['integer', $id],
87  'operation_string' => ['text', $this->operation_name],
88  'description' => ['text', $this->description],
89  'list_order' => ['integer', 0],
90  'context_id' => ['integer', $context_id],
91  ]);
92 
93  return $environment;
94  }
doesOperationExistInContext(ilDBInterface $db, int $context_id, string $operation)
getContextId(ilDBInterface $db, string $context)
Defaults to 0 if context is not found.
getResource(string $id)
Consumers of this method should check if the result is what they expect, e.g.
An environment holds resources to be used in the setup process.
Definition: Environment.php:27
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
+ Here is the call graph for this function:

◆ doesOperationExistInContext()

ilOrgUnitOperationRegisteredObjective::doesOperationExistInContext ( ilDBInterface  $db,
int  $context_id,
string  $operation 
)
protected

Definition at line 119 of file class.ilOrgUnitOperationRegisteredObjective.php.

References ilDBInterface\query(), and ilDBInterface\quote().

Referenced by achieve(), and isApplicable().

123  : bool {
124  $result = $db->query('SELECT * FROM il_orgu_operations
125  WHERE context_id = ' . $db->quote($context_id, 'integer') .
126  ' AND operation_string = ' . $db->quote($operation, 'text'));
127  if ($result->numRows()) {
128  return true;
129  }
130  return false;
131  }
quote($value, string $type)
query(string $query)
Run a (read-only) Query on the database.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getContextId()

ilOrgUnitOperationRegisteredObjective::getContextId ( ilDBInterface  $db,
string  $context 
)
protected

Defaults to 0 if context is not found.

Definition at line 136 of file class.ilOrgUnitOperationRegisteredObjective.php.

References ilDBInterface\query(), and ilDBInterface\quote().

Referenced by achieve(), and isApplicable().

139  : int {
140  $result = $db->query('SELECT id FROM il_orgu_op_contexts
141  WHERE context = ' . $db->quote($context, 'text'));
142  if (!($row = $result->fetchObject())) {
143  return 0;
144  }
145  return (int) $row->id;
146  }
quote($value, string $type)
query(string $query)
Run a (read-only) Query on the database.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getHash()

ilOrgUnitOperationRegisteredObjective::getHash ( )

Definition at line 40 of file class.ilOrgUnitOperationRegisteredObjective.php.

40  : string
41  {
42  return hash('sha256', self::class . '::' . $this->operation_name);
43  }

◆ getLabel()

ilOrgUnitOperationRegisteredObjective::getLabel ( )

Definition at line 45 of file class.ilOrgUnitOperationRegisteredObjective.php.

45  : string
46  {
47  return 'Add OrgUnit operation (name=' . $this->operation_name .
48  ';context=' . $this->context . ')';
49  }

◆ getPreconditions()

ilOrgUnitOperationRegisteredObjective::getPreconditions ( Environment  $environment)

Definition at line 56 of file class.ilOrgUnitOperationRegisteredObjective.php.

56  : array
57  {
58  return [
60  ];
61  }

◆ isApplicable()

ilOrgUnitOperationRegisteredObjective::isApplicable ( Environment  $environment)

Definition at line 96 of file class.ilOrgUnitOperationRegisteredObjective.php.

References doesOperationExistInContext(), getContextId(), and ILIAS\Setup\Environment\getResource().

96  : bool
97  {
98  $db = $environment->getResource(Environment::RESOURCE_DATABASE);
99 
100  // something is wrong if context does not exist
101  if (!($context_id = $this->getContextId($db, $this->context))) {
102  throw new Setup\UnachievableException(
103  'Cannot find context ' . $this->context
104  );
105  }
106 
107  // not applicable if operation already exists in this context
108  if ($this->doesOperationExistInContext(
109  $db,
110  $context_id,
111  $this->operation_name
112  )) {
113  return false;
114  }
115 
116  return true;
117  }
doesOperationExistInContext(ilDBInterface $db, int $context_id, string $operation)
getContextId(ilDBInterface $db, string $context)
Defaults to 0 if context is not found.
getResource(string $id)
Consumers of this method should check if the result is what they expect, e.g.
+ Here is the call graph for this function:

◆ isNotable()

ilOrgUnitOperationRegisteredObjective::isNotable ( )

Definition at line 51 of file class.ilOrgUnitOperationRegisteredObjective.php.

51  : bool
52  {
53  return true;
54  }

Field Documentation

◆ $context

string ilOrgUnitOperationRegisteredObjective::$context
protected

Definition at line 28 of file class.ilOrgUnitOperationRegisteredObjective.php.

Referenced by __construct().

◆ $description

string ilOrgUnitOperationRegisteredObjective::$description
protected

Definition at line 27 of file class.ilOrgUnitOperationRegisteredObjective.php.

Referenced by __construct().

◆ $operation_name

string ilOrgUnitOperationRegisteredObjective::$operation_name
protected

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

Referenced by __construct().


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