ILIAS  release_8 Revision v8.25
class.ilOrgUnitOperationContextRegisteredObjective.php
Go to the documentation of this file.
1<?php
2
20declare(strict_types=1);
21
22use ILIAS\Setup;
24
26{
27 protected string $context_name;
28 protected ?string $parent_context;
29
30 public function __construct(
31 string $context_name,
32 ?string $parent_context = null
33 ) {
34 $this->context_name = $context_name;
35 $this->parent_context = $parent_context;
36 }
37
38 public function getHash(): string
39 {
40 return hash('sha256', self::class . '::' . $this->context_name);
41 }
42
43 public function getLabel(): string
44 {
45 return 'Add OrgUnit operation context (name=' . $this->context_name .
46 ';parent_context=' . $this->parent_context . ')';
47 }
48
49 public function isNotable(): bool
50 {
51 return true;
52 }
53
54 public function getPreconditions(Environment $environment): array
55 {
56 return [
58 ];
59 }
60
61 public function achieve(Environment $environment): Environment
62 {
63 $db = $environment->getResource(Environment::RESOURCE_DATABASE);
64
65 // abort if the context already exists, just to be safe
66 if ($this->doesContextExist($db, $this->context_name)) {
67 return $environment;
68 }
69
70 $parent_context_id = 0;
71 if (isset($this->parent_context)) {
72 // abort if the parent context does not exist, just to be safe
73 if (!($id = $this->getContextId($db, $this->parent_context))) {
74 throw new Exception(
75 'Parent context ' . $this->context_name . ' does not exist,
76 this objective should not be applied!'
77 );
78 }
79 $parent_context_id = $id;
80 }
81
82 $id = $db->nextId('il_orgu_op_contexts');
83 $db->insert('il_orgu_op_contexts', [
84 'id' => ['integer', $id],
85 'context' => ['text', $this->context_name],
86 'parent_context_id' => ['integer', $parent_context_id]
87 ]);
88
89 return $environment;
90 }
91
92 public function isApplicable(Environment $environment): bool
93 {
94 $db = $environment->getResource(Environment::RESOURCE_DATABASE);
95
96 // not applicable if the context already exists
97 if ($this->doesContextExist($db, $this->context_name)) {
98 return false;
99 }
100
101 if (isset($this->parent_context)) {
102 // something is wrong if the parent context does not exist
103 if (!$this->doesContextExist($db, $this->parent_context)) {
104 throw new Exception(
105 'Cannot find parent context ' . $this->parent_context
106 );
107 }
108 }
109
110 return true;
111 }
112
113 protected function doesContextExist(
114 ilDBInterface $db,
115 string $context
116 ): bool {
117 return (bool) $this->getContextId($db, $context);
118 }
119
123 protected function getContextId(
124 ilDBInterface $db,
125 string $context
126 ): int {
127 $result = $db->query('SELECT id FROM il_orgu_op_contexts
128 WHERE context = ' . $db->quote($context, 'text'));
129 if (!($row = $result->fetchObject())) {
130 return 0;
131 }
132 return (int) $row->id;
133 }
134}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
getContextId(ilDBInterface $db, string $context)
Defaults to 0 if context is not found.
return['3gp', '7z', 'ai', 'aif', 'aifc', 'aiff', 'au', 'arw', 'avi', 'backup', 'bak', 'bas', 'bpmn', 'bpmn2', 'bmp', 'bib', 'bibtex', 'bz', 'bz2', 'c', 'c++', 'cc', 'cct', 'cdf', 'cer', 'class', 'cls', 'conf', 'cpp', 'crt', 'crs', 'crw', 'cr2', 'css', 'cst', 'csv', 'cur', 'db', 'dcr', 'des', 'dng', 'doc', 'docx', 'dot', 'dotx', 'dtd', 'dvi', 'el', 'eps', 'epub', 'f', 'f77', 'f90', 'flv', 'for', 'g3', 'gif', 'gl', 'gan', 'ggb', 'gsd', 'gsm', 'gtar', 'gz', 'gzip', 'h', 'hpp', 'htm', 'html', 'htmls', 'ibooks', 'ico', 'ics', 'ini', 'ipynb', 'java', 'jbf', 'jpeg', 'jpg', 'js', 'jsf', 'jso', 'json', 'latex', 'lang', 'less', 'log', 'lsp', 'ltx', 'm1v', 'm2a', 'm2v', 'm3u', 'm4a', 'm4v', 'markdown', 'm', 'mat', 'md', 'mdl', 'mdown', 'mid', 'min', 'midi', 'mobi', 'mod', 'mov', 'movie', 'mp2', 'mp3', 'mp4', 'mpa', 'mpeg', 'mpg', 'mph', 'mpga', 'mpp', 'mpt', 'mpv', 'mpx', 'mv', 'mw', 'mv4', 'nb', 'nbp', 'nef', 'nif', 'niff', 'obj', 'obm', 'odt', 'ods', 'odp', 'odg', 'odf', 'oga', 'ogg', 'ogv', 'old', 'p', 'pas', 'pbm', 'pcl', 'pct', 'pcx', 'pdf', 'pgm', 'pic', 'pict', 'png', 'por', 'pov', 'project', 'properties', 'ppa', 'ppm', 'pps', 'ppsx', 'ppt', 'pptx', 'ppz', 'ps', 'psd', 'pwz', 'qt', 'qtc', 'qti', 'qtif', 'r', 'ra', 'ram', 'rar', 'rast', 'rda', 'rev', 'rexx', 'ris', 'rf', 'rgb', 'rm', 'rmd', 'rmi', 'rmm', 'rmp', 'rt', 'rtf', 'rtx', 'rv', 's', 's3m', 'sav', 'sbs', 'sec', 'sdml', 'sgm', 'sgml', 'smi', 'smil', 'srt', 'sps', 'spv', 'stl', 'svg', 'swa', 'swf', 'swz', 'tar', 'tex', 'texi', 'texinfo', 'text', 'tgz', 'tif', 'tiff', 'ttf', 'txt', 'tmp', 'uvproj', 'vdf', 'vimeo', 'viv', 'vivo', 'vrml', 'vsdx', 'wav', 'webm', 'wmv', 'wmx', 'wmz', 'woff', 'wwd', 'xhtml', 'xif', 'xls', 'xlsx', 'xmind', 'xml', 'xsl', 'xsd', 'zip']
An environment holds resources to be used in the setup process.
Definition: Environment.php:28
getResource(string $id)
Consumers of this method should check if the result is what they expect, e.g.
An objective is a desired state of the system that is supposed to be created by the setup.
Definition: Objective.php:31
Interface ilDBInterface.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$context
Definition: webdav.php:29