ILIAS  release_8 Revision v8.24
ilSystemStyleLessGUI Class Reference
+ Collaboration diagram for ilSystemStyleLessGUI:

Public Member Functions

 __construct (ilCtrl $ctrl, ilLanguage $lng, ilGlobalTemplateInterface $tpl, Factory $ui_factory, Renderer $renderer, ServerRequestInterface $request, ilToolbarGUI $toolbar, Refinery $refinery, ilSkinFactory $factory, string $skin_id, string $style_id)
 
 executeCommand ()
 Execute command. More...
 
 initSystemStyleLessForm (bool $modify=true)
 
 update ()
 

Protected Member Functions

 addResetToolbar ()
 
 reset ()
 
 checkRequirements ()
 
 checkLessInstallation ()
 
 edit ()
 

Protected Attributes

ilCtrl $ctrl
 
ilLanguage $lng
 
ilGlobalTemplateInterface $tpl
 
ilSkinStyleContainer $style_container
 
ilSystemStyleLessFile $less_file
 
ilSystemStyleMessageStack $message_stack
 
Factory $ui_factory
 
Renderer $renderer
 
ServerRequestInterface $request
 
ilToolbarGUI $toolbar
 
Refinery $refinery
 
ilSystemStyleConfig $config
 
string $style_id
 

Detailed Description

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

Constructor & Destructor Documentation

◆ __construct()

ilSystemStyleLessGUI::__construct ( ilCtrl  $ctrl,
ilLanguage  $lng,
ilGlobalTemplateInterface  $tpl,
Factory  $ui_factory,
Renderer  $renderer,
ServerRequestInterface  $request,
ilToolbarGUI  $toolbar,
Refinery  $refinery,
ilSkinFactory  $factory,
string  $skin_id,
string  $style_id 
)

Definition at line 43 of file class.ilSystemStyleLessGUI.php.

55 {
56 $this->ctrl = $ctrl;
57 $this->lng = $lng;
58 $this->tpl = $tpl;
59 $this->ui_factory = $ui_factory;
60 $this->renderer = $renderer;
61 $this->request = $request;
62 $this->toolbar = $toolbar;
63 $this->refinery = $refinery;
64 $this->style_id = $style_id;
65
66 $this->message_stack = new ilSystemStyleMessageStack($this->tpl);
67
68 $this->style_container = $factory->skinStyleContainerFromId($skin_id, $this->message_stack);
69 $this->less_file = new ilSystemStyleLessFile($this->style_container->getLessVariablesFilePath($style_id));
70 }
ServerRequestInterface $request
ilGlobalTemplateInterface $tpl
Used to stack messages to be shown to the user.
$factory
Definition: metadata.php:75

References $ctrl, $factory, $lng, $refinery, $renderer, $request, $style_id, $toolbar, $tpl, $ui_factory, ILIAS\Repository\ctrl(), ILIAS\Repository\lng(), ILIAS\Repository\refinery(), and ILIAS\Repository\toolbar().

+ Here is the call graph for this function:

Member Function Documentation

◆ addResetToolbar()

ilSystemStyleLessGUI::addResetToolbar ( )
protected

Definition at line 103 of file class.ilSystemStyleLessGUI.php.

103 : void
104 {
105 $this->toolbar->addComponent($this->ui_factory->button()->standard(
106 $this->lng->txt('reset_variables'),
107 $this->ctrl->getLinkTarget($this, 'reset')
108 ));
109 }

References ILIAS\Repository\toolbar().

Referenced by executeCommand().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ checkLessInstallation()

ilSystemStyleLessGUI::checkLessInstallation ( )
protected

Definition at line 172 of file class.ilSystemStyleLessGUI.php.

172 : bool
173 {
174 $pass = true;
175
176 if (!PATH_TO_LESSC) {
177 $this->message_stack->addMessage(
178 new ilSystemStyleMessage($this->lng->txt('no_less_path_set'), ilSystemStyleMessage::TYPE_ERROR)
179 );
180 $pass = false;
181 } elseif (!shell_exec(PATH_TO_LESSC)) {
182 $this->message_stack->addMessage(
183 new ilSystemStyleMessage($this->lng->txt('invalid_less_path'), ilSystemStyleMessage::TYPE_ERROR)
184 );
185 $this->message_stack->addMessage(
187 $this->lng->txt('provided_less_path') . ' ' . PATH_TO_LESSC,
189 )
190 );
191 $pass = false;
192 }
193
194 if (!$pass && shell_exec('which lessc')) {
195 $this->message_stack->addMessage(
197 $this->lng->txt('less_less_installation_detected') . shell_exec('which lessc'),
199 )
200 );
201 }
202
203 return $pass;
204 }

References ILIAS\Repository\lng(), and ilSystemStyleMessage\TYPE_ERROR.

Referenced by checkRequirements().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ checkRequirements()

ilSystemStyleLessGUI::checkRequirements ( )
protected

Definition at line 126 of file class.ilSystemStyleLessGUI.php.

126 : bool
127 {
128 $less_path = $this->style_container->getLessFilePath($this->style_id);
129
130 $pass = $this->checkLessInstallation();
131
132 if (file_exists($less_path)) {
133 $less_variables_name = $this->style_container->getLessVariablesName($this->style_id);
134 $content = '';
135 try {
136 $content = file_get_contents($less_path);
137 } catch (Exception $e) {
138 $this->message_stack->addMessage(
140 $this->lng->txt('can_not_read_less_file') . ' ' . $less_path,
142 )
143 );
144 $pass = false;
145 }
146 if ($content) {
147 $reg_exp = '/' . preg_quote($less_variables_name, '/') . '/';
148
149 if (!preg_match($reg_exp, $content)) {
150 $this->message_stack->addMessage(
152 $this->lng->txt('less_variables_file_not_included') . ' ' . $less_variables_name
153 . ' ' . $this->lng->txt('in_main_less_file') . ' ' . $less_path,
155 )
156 );
157 $pass = false;
158 }
159 }
160 } else {
161 $this->message_stack->addMessage(
163 $this->lng->txt('less_file_does_not_exist') . $less_path,
165 )
166 );
167 $pass = false;
168 }
169 return $pass;
170 }

References Vendor\Package\$e, checkLessInstallation(), ILIAS\Repository\lng(), and ilSystemStyleMessage\TYPE_ERROR.

Referenced by edit().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ edit()

ilSystemStyleLessGUI::edit ( )
protected

Definition at line 206 of file class.ilSystemStyleLessGUI.php.

206 : Form
207 {
208 $modify = true;
209
210 if (!$this->checkRequirements()) {
211 $this->message_stack->prependMessage(
212 new ilSystemStyleMessage($this->lng->txt('less_can_not_be_modified'), ilSystemStyleMessage::TYPE_ERROR)
213 );
214 $modify = false;
215 }
216
217 return $this->initSystemStyleLessForm($modify);
218 }
initSystemStyleLessForm(bool $modify=true)

References checkRequirements(), initSystemStyleLessForm(), ILIAS\Repository\lng(), and ilSystemStyleMessage\TYPE_ERROR.

Referenced by executeCommand().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ executeCommand()

ilSystemStyleLessGUI::executeCommand ( )

Execute command.

Definition at line 75 of file class.ilSystemStyleLessGUI.php.

75 : void
76 {
77 $this->addResetToolbar();
78 $form = null;
79
80 $cmd = $this->ctrl->getCmd();
81
82 switch ($cmd) {
83 case 'update':
84 $form = $this->update();
85 break;
86 case 'reset':
87 $this->reset();
88 $form = $this->edit();
89 break;
90 case 'edit':
91 case '':
92 $form = $this->edit();
93 break;
94 }
95 $components = $this->message_stack->getUIComponentsMessages($this->ui_factory);
96 if ($form) {
97 $components[] = $form;
98 }
99
100 $this->tpl->setContent($this->renderer->render($components));
101 }

References addResetToolbar(), ILIAS\Repository\ctrl(), edit(), reset(), and update().

+ Here is the call graph for this function:

◆ initSystemStyleLessForm()

ilSystemStyleLessGUI::initSystemStyleLessForm ( bool  $modify = true)

Definition at line 220 of file class.ilSystemStyleLessGUI.php.

220 : Form
221 {
222 $f = $this->ui_factory->input();
223 $category_section = [];
224 foreach ($this->less_file->getCategories() as $category) {
225 $variables_inptus = [];
226 foreach ($this->less_file->getVariablesPerCategory($category->getName()) as $variable) {
227 $info = $this->less_file->getRefAndCommentAsString($variable->getName(), $this->lng->txt('usages'));
228 $save_closure = function ($v) use ($variable) {
229 $variable->setValue($v);
230 };
231 $variables_inptus[] = $f->field()->text($variable->getName(), $info)
232 //->withRequired(true)
233 ->withDisabled(!$modify)
234 ->withValue($variable->getValue())
235 ->withAdditionalTransformation($this->refinery->custom()->transformation($save_closure));
236 }
237
238 $category_section[] = $f->field()->section(
239 $variables_inptus,
240 $category->getName(),
241 $category->getComment()
242 );
243 }
244
245 $form_section = $f->field()->section(
246 $category_section,
247 $this->lng->txt('adapt_less'),
248 $this->lng->txt('adapt_less_description')
249 );
250
251 return $f->container()->form()->standard(
252 $this->ctrl->getFormAction($this, 'update'),
253 [$form_section]
254 )->withSubmitCaption($this->lng->txt('update_variables'));
255 }
withAdditionalTransformation(Transformation $trafo)
@inheritDoc

References Vendor\Package\$f, ILIAS\Repository\ctrl(), ILIAS\Repository\lng(), ILIAS\Repository\refinery(), and ILIAS\UI\Implementation\Component\Input\ViewControl\withAdditionalTransformation().

Referenced by edit(), and update().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ reset()

ilSystemStyleLessGUI::reset ( )
protected

Definition at line 111 of file class.ilSystemStyleLessGUI.php.

111 : void
112 {
113 $style = $this->style_container->getSkin()->getStyle($this->style_id);
114 $this->less_file = $this->style_container->copyVariablesFromDefault($style);
115 try {
116 $this->message_stack->addMessage(new ilSystemStyleMessage($this->lng->txt('less_file_reset')));
117 $this->style_container->compileLess($style->getId());
118 } catch (ilSystemStyleException $e) {
119 $this->message_stack->addMessage(new ilSystemStyleMessage(
120 $this->lng->txt($e->getMessage()),
122 ));
123 }
124 }
Class for advanced editing exception handling in ILIAS.

References Vendor\Package\$e, ILIAS\Repository\lng(), and ilSystemStyleMessage\TYPE_ERROR.

Referenced by executeCommand().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ update()

ilSystemStyleLessGUI::update ( )

Definition at line 257 of file class.ilSystemStyleLessGUI.php.

257 : Form
258 {
259 $form = $this->initSystemStyleLessForm();
260 $form = $form->withRequest($this->request);
261
262 if (!$form->getData()) {
263 $this->message_stack->addMessage(new ilSystemStyleMessage(
264 $this->lng->txt('less_variables_empty_might_have_changed'),
266 ));
267 return $form;
268 }
269
270 try {
271 $this->less_file->write();
272 $this->style_container->compileLess($this->style_id);
273 $skin = $this->style_container->getSkin();
274 $skin->getVersionStep($skin->getVersion());
275 $this->style_container->updateSkin($skin);
276 $this->message_stack->addMessage(new ilSystemStyleMessage($this->lng->txt('less_file_updated')));
277 } catch (Exception $e) {
278 $this->message_stack->addMessage(new ilSystemStyleMessage(
279 $this->lng->txt($e->getMessage()),
281 ));
282 }
283
284 return $form;
285 }

References Vendor\Package\$e, initSystemStyleLessForm(), ILIAS\Repository\lng(), and ilSystemStyleMessage\TYPE_ERROR.

Referenced by executeCommand().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $config

ilSystemStyleConfig ilSystemStyleLessGUI::$config
protected

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

◆ $ctrl

ilCtrl ilSystemStyleLessGUI::$ctrl
protected

Definition at line 29 of file class.ilSystemStyleLessGUI.php.

Referenced by __construct().

◆ $less_file

ilSystemStyleLessFile ilSystemStyleLessGUI::$less_file
protected

Definition at line 33 of file class.ilSystemStyleLessGUI.php.

◆ $lng

ilLanguage ilSystemStyleLessGUI::$lng
protected

Definition at line 30 of file class.ilSystemStyleLessGUI.php.

Referenced by __construct().

◆ $message_stack

ilSystemStyleMessageStack ilSystemStyleLessGUI::$message_stack
protected

Definition at line 34 of file class.ilSystemStyleLessGUI.php.

◆ $refinery

Refinery ilSystemStyleLessGUI::$refinery
protected

Definition at line 39 of file class.ilSystemStyleLessGUI.php.

Referenced by __construct().

◆ $renderer

Renderer ilSystemStyleLessGUI::$renderer
protected

Definition at line 36 of file class.ilSystemStyleLessGUI.php.

Referenced by __construct().

◆ $request

ServerRequestInterface ilSystemStyleLessGUI::$request
protected

Definition at line 37 of file class.ilSystemStyleLessGUI.php.

Referenced by __construct().

◆ $style_container

ilSkinStyleContainer ilSystemStyleLessGUI::$style_container
protected

Definition at line 32 of file class.ilSystemStyleLessGUI.php.

◆ $style_id

string ilSystemStyleLessGUI::$style_id
protected

Definition at line 41 of file class.ilSystemStyleLessGUI.php.

Referenced by __construct().

◆ $toolbar

ilToolbarGUI ilSystemStyleLessGUI::$toolbar
protected

Definition at line 38 of file class.ilSystemStyleLessGUI.php.

Referenced by __construct().

◆ $tpl

ilGlobalTemplateInterface ilSystemStyleLessGUI::$tpl
protected

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

Referenced by __construct().

◆ $ui_factory

Factory ilSystemStyleLessGUI::$ui_factory
protected

Definition at line 35 of file class.ilSystemStyleLessGUI.php.

Referenced by __construct().


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