1<?php
2require_once("./Services/Style/System/classes/Less/class.ilSystemStyleLessItem.php");
3
4/***
5 * Capsules data of a less variable in the variables to less file. A less variable has the following structure:
6 *
7 * //** Comment to describe the variable
8 * @variable:   value;
9 *
10 *
11 * @author            Timon Amstutz <timon.amstutz@ilub.unibe.ch>
12 * @version           $Id$
13 *
14 */
15class ilSystemStyleLessVariable extends ilSystemStyleLessItem
16{
17
18    /**
19     * Name of the variable
20     *
21     * @var string
22     */
23    protected $name = "";
24
25    /**
26     * Value of the variable as set in the less file
27     *
28     * @var string
29     */
30    protected $value = "";
31
32    /**
33     * Comment to the variable as in the less file
34     *
35     * @var string
36     */
37    protected $comment = "";
38
39    /**
40     * Less Category which encloses this variable
41     * @var string
42     */
43    protected $category_name = "";
44
45    /**
46     * Set references to other variables that are used by this exact variable
47     *
48     * @var array
49     */
50    protected $references = array();
51
52    /**
53     * ilSystemStyleLessVariable constructor.
54     * @param $name
55     * @param $value
56     * @param $comment
57     * @param $category_name
58     * @param $references
59     */
60    public function __construct($name, $value, $comment, $category_name, $references)
61    {
62        $this->setName($name);
63        $this->setValue($value);
64        $this->setCategoryName($category_name);
65        $this->setComment($comment);
66        $this->setReferences($references);
67    }
68
69    /**
70     * @return string
71     */
72    public function getName()
73    {
74        return $this->name;
75    }
76
77    /**
78     * @param string $name
79     */
80    public function setName($name)
81    {
82        $this->name = $name;
83    }
84
85    /**
86     * @return string
87     */
88    public function getValue()
89    {
90        return $this->value;
91    }
92
93    /**
94     * @param string $value
95     */
96    public function setValue($value)
97    {
98        if ($this->getName() == "icon-font-path") {
99            if ($value[0] != "\"") {
100                $value = "\"" . $value;
101                ;
102            }
103            if (substr($value, -1, 1) != "\"") {
104                $value .= "\"";
105            }
106
107            if ($value == "\"../../libs/bower/bower_components/bootstrap/fonts/\"") {
108                $value = "\"../../../../libs/bower/bower_components/bootstrap/fonts/\"";
109            }
110        }
111
112        $value = str_replace(PHP_EOL, '', $value);
113        $this->value = str_replace("\n", '', $value);
114    }
115
116    /**
117     * @return string
118     */
119    public function getComment()
120    {
121        return $this->comment;
122    }
123
124    /**
125     * @param string $comment
126     */
127    public function setComment($comment)
128    {
129        $comment = str_replace(PHP_EOL, '', $comment);
130        $this->comment = str_replace("\n", '', $comment);
131    }
132
133    /**
134     * @return string
135     */
136    public function getCategoryName()
137    {
138        return $this->category_name;
139    }
140
141    /**
142     * @param string $category_name
143     */
144    public function setCategoryName($category_name)
145    {
146        $this->category_name = $category_name;
147    }
148
149    /**
150     * @return array
151     */
152    public function getReferences()
153    {
154        return $this->references;
155    }
156
157    /**
158     * @param array $references
159     */
160    public function setReferences($references)
161    {
162        $this->references = $references;
163    }
164
165
166    /**
167     * This function will be needed to write the variable back to the less file and restore it's initial structure
168     * in less.
169     *
170     * @return string
171     */
172    public function __toString()
173    {
174        $content = "";
175        if ($this->getComment()) {
176            $content .= "//** " . $this->getComment() . "\n";
177        }
178        $content .= "@" . $this->getName() . ":\t\t" . $this->getValue() . ";\n";
179        return $content;
180    }
181}
182