ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
ilSystemStyleLessGUI Class Reference
+ Collaboration diagram for ilSystemStyleLessGUI:

Public Member Functions

 __construct ($skin_id="", $style_id="")
 ilSystemStyleLessGUI constructor. More...
 
 executeCommand ()
 Execute command. More...
 
 initSystemStyleLessForm ($modify=true)
 
 getVariablesValues (ilPropertyFormGUI $form)
 
 reset ()
 
 update ()
 
 getStyleContainer ()
 
 setStyleContainer ($style_container)
 
 getLessFile ()
 
 setLessFile ($less_file)
 
 getMessageStack ()
 
 setMessageStack ($message_stack)
 

Protected Member Functions

 checkRequirements ()
 
 checkLessInstallation ()
 
 edit ()
 

Protected Attributes

 $ctrl
 
 $lng
 
 $tpl
 
 $style_container
 
 $less_file
 
 $message_stack
 

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

ilSystemStyleLessGUI::__construct (   $skin_id = "",
  $style_id = "" 
)

ilSystemStyleLessGUI constructor.

Parameters
string$skin_id
string$style_id

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

References $_GET, $DIC, $less_file, ilSystemStyleSkinContainer\generateFromId(), getMessageStack(), getStyleContainer(), setLessFile(), setMessageStack(), setStyleContainer(), and ilSystemStyleMessage\TYPE_ERROR.

52  {
53  global $DIC;
54 
55  $this->ctrl = $DIC->ctrl();
56  $this->lng = $DIC->language();
57  $this->tpl = $DIC["tpl"];
58 
60 
61  if ($skin_id == "") {
62  $skin_id = $_GET["skin_id"];
63  }
64  if ($style_id == "") {
65  $style_id = $_GET["style_id"];
66  }
67 
68  try {
70  $less_file = new ilSystemStyleLessFile($this->getStyleContainer()->getLessVariablesFilePath($style_id));
71  $this->setLessFile($less_file);
72  } catch (ilSystemStyleException $e) {
73  $this->getMessageStack()->addMessage(
75  );
76  }
77  }
global $DIC
Definition: saml.php:7
$_GET["client_id"]
Class for advanced editing exception handling in ILIAS.
static generateFromId($skin_id, ilSystemStyleMessageStack $message_stack=null, ilSystemStyleConfig $system_styles_conf=null)
Generate the container class by parsing the corresponding XML.
Used to stack messages to be shown to the user.
+ Here is the call graph for this function:

Member Function Documentation

◆ checkLessInstallation()

ilSystemStyleLessGUI::checkLessInstallation ( )
protected
Returns
bool

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

References $pass, getMessageStack(), and ilSystemStyleMessage\TYPE_ERROR.

Referenced by checkRequirements().

145  {
146  $pass = true;
147 
148  if (!PATH_TO_LESSC) {
149  $this->getMessageStack()->addMessage(
150  new ilSystemStyleMessage($this->lng->txt("no_less_path_set"), ilSystemStyleMessage::TYPE_ERROR)
151  );
152  $pass = false;
153  } elseif (!shell_exec(PATH_TO_LESSC)) {
154  $this->getMessageStack()->addMessage(
155  new ilSystemStyleMessage($this->lng->txt("invalid_less_path"), ilSystemStyleMessage::TYPE_ERROR)
156  );
157  $this->getMessageStack()->addMessage(
158  new ilSystemStyleMessage($this->lng->txt("provided_less_path") . " " . PATH_TO_LESSC, ilSystemStyleMessage::TYPE_ERROR)
159  );
160  $pass = false;
161  }
162 
163  if (!$pass && shell_exec("which lessc")) {
164  $this->getMessageStack()->addMessage(
165  new ilSystemStyleMessage($this->lng->txt("less_less_installation_detected") . shell_exec("which lessc"), ilSystemStyleMessage::TYPE_ERROR)
166  );
167  }
168 
169  return $pass;
170  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ checkRequirements()

ilSystemStyleLessGUI::checkRequirements ( )
protected
Returns
bool

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

References $_GET, $pass, checkLessInstallation(), getMessageStack(), getStyleContainer(), and ilSystemStyleMessage\TYPE_ERROR.

Referenced by edit().

104  {
105  $style_id = $_GET['style_id'];
106  $less_path = $this->getStyleContainer()->getLessFilePath($style_id);
107 
108  $pass = $this->checkLessInstallation();
109 
110  if (file_exists($less_path)) {
111  $less_variables_name = $this->getStyleContainer()->getLessVariablesName($style_id);
112  $content = "";
113  try {
114  $content = file_get_contents($less_path);
115  } catch (Exception $e) {
116  $this->getMessageStack()->addMessage(
117  new ilSystemStyleMessage($this->lng->txt("can_not_read_less_file") . " " . $less_path, ilSystemStyleMessage::TYPE_ERROR)
118  );
119  $pass = false;
120  }
121  if ($content) {
122  $reg_exp = "/" . preg_quote($less_variables_name, "/") . "/";
123 
124  if (!preg_match($reg_exp, $content)) {
125  $this->getMessageStack()->addMessage(
126  new ilSystemStyleMessage($this->lng->txt("less_variables_file_not_included") . " " . $less_variables_name
127  . " " . $this->lng->txt("in_main_less_file") . " " . $less_path, ilSystemStyleMessage::TYPE_ERROR)
128  );
129  $pass = false;
130  }
131  }
132  } else {
133  $this->getMessageStack()->addMessage(
134  new ilSystemStyleMessage($this->lng->txt("less_file_does_not_exist") . $less_path, ilSystemStyleMessage::TYPE_ERROR)
135  );
136  $pass = false;
137  }
138  return $pass;
139  }
$_GET["client_id"]
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ edit()

ilSystemStyleLessGUI::edit ( )
protected

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

References $form, checkRequirements(), getLessFile(), getMessageStack(), getVariablesValues(), initSystemStyleLessForm(), and ilSystemStyleMessage\TYPE_ERROR.

Referenced by executeCommand(), and reset().

174  {
175  $modify = true;
176 
177  if (!$this->checkRequirements()) {
178  $this->getMessageStack()->prependMessage(
179  new ilSystemStyleMessage($this->lng->txt("less_can_not_be_modified"), ilSystemStyleMessage::TYPE_ERROR)
180  );
181  $modify = false;
182  }
183 
184  if ($this->getLessFile()) {
185  $form = $this->initSystemStyleLessForm($modify);
186  $this->getVariablesValues($form);
187  $this->tpl->setContent($form->getHTML());
188  }
189 
190  $this->getMessageStack()->sendMessages(true);
191  }
if(isset($_POST['submit'])) $form
getVariablesValues(ilPropertyFormGUI $form)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ executeCommand()

ilSystemStyleLessGUI::executeCommand ( )

Execute command.

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

References edit().

83  {
84  $cmd = $this->ctrl->getCmd();
85 
86  switch ($cmd) {
87  case "save":
88  case "edit":
89  case "reset":
90  case "update":
91  $this->$cmd();
92  break;
93  default:
94  $this->edit();
95  break;
96  }
97  }
+ Here is the call graph for this function:

◆ getLessFile()

ilSystemStyleLessGUI::getLessFile ( )
Returns
ilSystemStyleLessFile

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

References $less_file.

Referenced by edit(), getVariablesValues(), initSystemStyleLessForm(), and update().

344  {
345  return $this->less_file;
346  }
+ Here is the caller graph for this function:

◆ getMessageStack()

ilSystemStyleLessGUI::getMessageStack ( )
Returns
ilSystemStyleMessageStack

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

References $message_stack.

Referenced by __construct(), checkLessInstallation(), checkRequirements(), and edit().

+ Here is the caller graph for this function:

◆ getStyleContainer()

ilSystemStyleLessGUI::getStyleContainer ( )
Returns
ilSystemStyleSkinContainer

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

References $style_container.

Referenced by __construct(), checkRequirements(), reset(), and update().

+ Here is the caller graph for this function:

◆ getVariablesValues()

ilSystemStyleLessGUI::getVariablesValues ( ilPropertyFormGUI  $form)
Parameters
ilPropertyFormGUI$form

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

References getLessFile(), and ilPropertyFormGUI\setValuesByArray().

Referenced by edit().

253  {
254  $values = [];
255  foreach ($this->getLessFile()->getCategories() as $category) {
256  foreach ($this->getLessFile()->getVariablesPerCategory($category->getName()) as $variable) {
257  $values[$variable->getName()] = $variable->getValue();
258  }
259  }
260 
261  $form->setValuesByArray($values);
262  }
setValuesByArray($a_values, $a_restrict_to_value_keys=false)
Set form values from an array.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ initSystemStyleLessForm()

ilSystemStyleLessGUI::initSystemStyleLessForm (   $modify = true)
Parameters
bool | true$modify
Returns
ilPropertyFormGUI

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

References $_GET, $form, $info, $section, getLessFile(), and ilFormPropertyGUI\setRequired().

Referenced by edit(), and update().

198  {
199  $form = new ilPropertyFormGUI();
200 
201  $form->setTitle($this->lng->txt("adapt_less"));
202  $form->setDescription($this->lng->txt("adapt_less_description"));
203  $focus_variable = $_GET['id_less_variable'];
204  if ($focus_variable) {
205  $this->tpl->addOnLoadCode("setTimeout(function() { $('#" . $focus_variable . "').focus();}, 100);");
206  }
207 
208  foreach ($this->getLessFile()->getCategories() as $category) {
210  $section->setTitle($category->getName());
211  $section->setInfo($category->getComment());
212  //$section->setSectionAnchor($category->getName());
213  $form->addItem($section);
214  foreach ($this->getLessFile()->getVariablesPerCategory($category->getName()) as $variable) {
215  $input = new ilTextInputGUI($variable->getName(), $variable->getName());
216  $input->setRequired(true);
217  $input->setDisabled(!$modify);
218 
219  $references = $this->getLessFile()->getReferencesToVariableAsString($variable->getName());
220 
221  if ($references != "") {
222  if ($variable->getComment()) {
223  $info = $variable->getComment() . "</br>" . $this->lng->txt("usages") . " " . $references;
224  } else {
225  $info = $this->lng->txt("usages") . " " . $references;
226  }
227  } else {
228  $info = $variable->getComment();
229  }
230  $input->setInfo($info);
231 
232  $form->addItem($input);
233  }
234  }
235 
236  if ($modify) {
237  $form->addCommandButton("update", $this->lng->txt("update_variables"));
238  $form->addCommandButton("reset", $this->lng->txt("reset_variables"));
239  $form->addCommandButton("cancel", $this->lng->txt("cancel"));
240  }
241 
242 
243  $form->setFormAction($this->ctrl->getFormAction($this));
244 
245  return $form;
246  }
This class represents a property form user interface.
$_GET["client_id"]
This class represents a section header in a property form.
$section
Definition: Utf8Test.php:83
if(isset($_POST['submit'])) $form
This class represents a text property in a property form.
$info
Definition: index.php:5
setRequired($a_required)
Set Required.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ reset()

ilSystemStyleLessGUI::reset ( )

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

References $_GET, $style, edit(), getStyleContainer(), ilUtil\sendFailure(), ilUtil\sendSuccess(), and setLessFile().

268  {
269  $style = $this->getStyleContainer()->getSkin()->getStyle($_GET["style_id"]);
270  $this->setLessFile($this->getStyleContainer()->copyVariablesFromDefault($style));
271  try {
272  ilUtil::sendSuccess($this->lng->txt("less_file_reset"));
273  $this->getStyleContainer()->compileLess($style->getId());
274  } catch (ilSystemStyleException $e) {
275  ilUtil::sendFailure($this->lng->txt($e->getMessage()), true);
276  }
277 
278  $this->edit();
279  }
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
$style
Definition: example_012.php:70
$_GET["client_id"]
Class for advanced editing exception handling in ILIAS.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
+ Here is the call graph for this function:

◆ setLessFile()

ilSystemStyleLessGUI::setLessFile (   $less_file)
Parameters
ilSystemStyleLessFile$less_file

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

References $less_file.

Referenced by __construct(), and reset().

352  {
353  $this->less_file = $less_file;
354  }
+ Here is the caller graph for this function:

◆ setMessageStack()

ilSystemStyleLessGUI::setMessageStack (   $message_stack)
Parameters
ilSystemStyleMessageStack$message_stack

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

References $message_stack.

Referenced by __construct().

368  {
369  $this->message_stack = $message_stack;
370  }
+ Here is the caller graph for this function:

◆ setStyleContainer()

ilSystemStyleLessGUI::setStyleContainer (   $style_container)
Parameters
ilSystemStyleSkinContainer$style_container

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

References $style_container.

Referenced by __construct().

336  {
337  $this->style_container = $style_container;
338  }
+ Here is the caller graph for this function:

◆ update()

ilSystemStyleLessGUI::update ( )

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

References $_GET, $form, getLessFile(), getStyleContainer(), initSystemStyleLessForm(), ilUtil\sendFailure(), and ilUtil\sendSuccess().

282  {
283  $form = $this->initSystemStyleLessForm();
284  if (!$form->checkInput()) {
285  $empty_fields = [];
286  foreach ($this->getLessFile()->getCategories() as $category) {
287  foreach ($this->getLessFile()->getVariablesPerCategory($category->getName()) as $variable) {
288  if ($form->getInput($variable->getName()) == "") {
289  $empty_fields[$variable->getName()] = $this->getLessFile()->getVariableByName($variable->getName())->getValue();
290  $item = $form->getItemByPostVar($variable->getName());
291  $item->setAlert($this->lng->txt("less_variable_empty"));
292  }
293  }
294  }
295  if (!empty($empty_fields)) {
296  $form->setValuesByPost();
297  $form->setValuesByArray($empty_fields, true);
298  ilUtil::sendFailure($this->lng->txt("less_variables_empty_might_have_changed"), true);
299  $this->tpl->setContent($form->getHTML());
300  return;
301  }
302  } else {
303  foreach ($this->getLessFile()->getCategories() as $category) {
304  foreach ($this->getLessFile()->getVariablesPerCategory($category->getName()) as $variable) {
305  $variable->setValue($form->getInput($variable->getName()));
306  }
307  }
308  try {
309  $this->getLessFile()->write();
310  $this->getStyleContainer()->compileLess($_GET["style_id"]);
311  $skin = $this->getStyleContainer()->getSkin();
312  $skin->getVersionStep($skin->getVersion());
313  $this->getStyleContainer()->updateSkin($skin);
314  ilUtil::sendSuccess($this->lng->txt("less_file_updated"));
315  } catch (Exception $e) {
316  ilUtil::sendFailure($this->lng->txt($e->getMessage()), true);
317  }
318  }
319 
320  $form->setValuesByPost();
321  $this->tpl->setContent($form->getHTML());
322  }
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
$_GET["client_id"]
if(isset($_POST['submit'])) $form
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
+ Here is the call graph for this function:

Field Documentation

◆ $ctrl

ilSystemStyleLessGUI::$ctrl
protected

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

◆ $less_file

ilSystemStyleLessGUI::$less_file
protected

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

Referenced by __construct(), getLessFile(), and setLessFile().

◆ $lng

ilSystemStyleLessGUI::$lng
protected

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

◆ $message_stack

ilSystemStyleLessGUI::$message_stack
protected

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

Referenced by getMessageStack(), and setMessageStack().

◆ $style_container

ilSystemStyleLessGUI::$style_container
protected

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

Referenced by getStyleContainer(), and setStyleContainer().

◆ $tpl

ilSystemStyleLessGUI::$tpl
protected

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


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