@@ -40,28 +40,28 @@ discard block |
||
40 | 40 | */ |
41 | 41 | public function javascripts() : array { |
42 | 42 | |
43 | - $sDefaultPath = 'http://'.$_SERVER['HTTP_HOST'].'/getJs?'; |
|
44 | - $aJavascript = func_get_args(); |
|
45 | - $aReturns = array(); |
|
43 | + $sDefaultPath = 'http://'.$_SERVER['HTTP_HOST'].'/getJs?'; |
|
44 | + $aJavascript = func_get_args(); |
|
45 | + $aReturns = array(); |
|
46 | 46 | |
47 | - foreach($aJavascript as $aJsCombination) { |
|
47 | + foreach($aJavascript as $aJsCombination) { |
|
48 | 48 | |
49 | - $sJsPath = $sDefaultPath; |
|
49 | + $sJsPath = $sDefaultPath; |
|
50 | 50 | |
51 | - foreach ($aJsCombination as $sJsToAdd) { |
|
51 | + foreach ($aJsCombination as $sJsToAdd) { |
|
52 | 52 | |
53 | - $sJsPath = $sJsToAdd.'&'; |
|
54 | - } |
|
53 | + $sJsPath = $sJsToAdd.'&'; |
|
54 | + } |
|
55 | 55 | |
56 | - if (defined('ASSET_VERSION') && ASSET_VERSION) { |
|
56 | + if (defined('ASSET_VERSION') && ASSET_VERSION) { |
|
57 | 57 | |
58 | - $sJsPath = ASSET_VERSION; |
|
59 | - } |
|
58 | + $sJsPath = ASSET_VERSION; |
|
59 | + } |
|
60 | 60 | |
61 | - $aReturns[] = $sJsPath; |
|
62 | - } |
|
61 | + $aReturns[] = $sJsPath; |
|
62 | + } |
|
63 | 63 | |
64 | - return $aReturns; |
|
64 | + return $aReturns; |
|
65 | 65 | } |
66 | 66 | |
67 | 67 | /** |
@@ -75,27 +75,27 @@ discard block |
||
75 | 75 | */ |
76 | 76 | public function stylesheets() : array { |
77 | 77 | |
78 | - $sDefaultPath = 'http://'.$_SERVER['HTTP_HOST'].'/getCss?'; |
|
79 | - $aCss = func_get_args(); |
|
80 | - $aReturns = array(); |
|
78 | + $sDefaultPath = 'http://'.$_SERVER['HTTP_HOST'].'/getCss?'; |
|
79 | + $aCss = func_get_args(); |
|
80 | + $aReturns = array(); |
|
81 | 81 | |
82 | - foreach($aCss as $aCssCombination) { |
|
82 | + foreach($aCss as $aCssCombination) { |
|
83 | 83 | |
84 | - $sCssPath = $sDefaultPath; |
|
84 | + $sCssPath = $sDefaultPath; |
|
85 | 85 | |
86 | - foreach ($aCssCombination as $sCssToAdd) { |
|
86 | + foreach ($aCssCombination as $sCssToAdd) { |
|
87 | 87 | |
88 | - $sCssPath = $sCssToAdd.'&'; |
|
89 | - } |
|
88 | + $sCssPath = $sCssToAdd.'&'; |
|
89 | + } |
|
90 | 90 | |
91 | - if (defined('ASSET_VERSION') && ASSET_VERSION) { |
|
91 | + if (defined('ASSET_VERSION') && ASSET_VERSION) { |
|
92 | 92 | |
93 | - $sCssPath = ASSET_VERSION; |
|
94 | - } |
|
93 | + $sCssPath = ASSET_VERSION; |
|
94 | + } |
|
95 | 95 | |
96 | - $aReturns[] = $sCssPath; |
|
97 | - } |
|
96 | + $aReturns[] = $sCssPath; |
|
97 | + } |
|
98 | 98 | |
99 | - return $aReturns; |
|
99 | + return $aReturns; |
|
100 | 100 | } |
101 | 101 | } |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | */ |
82 | 82 | public static function setPointInLog(string $sName = 'default') |
83 | 83 | { |
84 | - $oLogger = Debug::getInstance(); |
|
84 | + $oLogger = Debug::getInstance(); |
|
85 | 85 | $oLogger->info('BENCHMARK: Time at this point '.(microtime(true) - self::$_fStart).' - '.$sName); |
86 | 86 | } |
87 | 87 | |
@@ -94,7 +94,7 @@ discard block |
||
94 | 94 | */ |
95 | 95 | public function setLogger(LoggerInterface $logger) |
96 | 96 | { |
97 | - if ($this->_oLogger === null) { $this->_oLogger = $logger; } |
|
97 | + if ($this->_oLogger === null) { $this->_oLogger = $logger; } |
|
98 | 98 | } |
99 | 99 | |
100 | 100 | /** |
@@ -60,408 +60,408 @@ |
||
60 | 60 | */ |
61 | 61 | class Form |
62 | 62 | { |
63 | - /** |
|
64 | - * Elements of the form |
|
65 | - * |
|
66 | - * @access private |
|
67 | - * @var array |
|
68 | - */ |
|
69 | - private $_aElement = array(); |
|
70 | - |
|
71 | - /** |
|
72 | - * Increment for form |
|
73 | - * |
|
74 | - * @access private |
|
75 | - * @var int |
|
76 | - */ |
|
77 | - private static $_iFormIncrement = 0; |
|
78 | - |
|
79 | - /** |
|
80 | - * number of form |
|
81 | - * |
|
82 | - * @access private |
|
83 | - * @var int |
|
84 | - */ |
|
85 | - private $_iFormNumber = 0; |
|
86 | - |
|
87 | - /** |
|
88 | - * Separator between fields of form |
|
89 | - * |
|
90 | - * @access private |
|
91 | - * @var string |
|
92 | - */ |
|
93 | - private $_sSeparator = '<br/>'; |
|
94 | - |
|
95 | - /** |
|
96 | - * The entity to save with the formular |
|
97 | - * |
|
98 | - * @access private |
|
99 | - * @var string |
|
100 | - */ |
|
101 | - private $_sSynchronizeEntity = null; |
|
102 | - |
|
103 | - /** |
|
104 | - * The id of entity |
|
105 | - * |
|
106 | - * @access private |
|
107 | - * @var int |
|
108 | - */ |
|
109 | - private $_iIdEntity = null; |
|
110 | - |
|
111 | - /** |
|
112 | - * The entity to save with the formular |
|
113 | - * |
|
114 | - * @access private |
|
115 | - * @var int |
|
116 | - */ |
|
117 | - private $_iIdEntityCreated = null; |
|
118 | - |
|
119 | - /** |
|
120 | - * constructor that it increment (static) for all use |
|
121 | - * |
|
122 | - * @access public |
|
123 | - */ |
|
124 | - public function __construct() |
|
125 | - { |
|
126 | - self::$_iFormIncrement++; |
|
127 | - $this->_iFormNumber = self::$_iFormIncrement; |
|
128 | - } |
|
129 | - |
|
130 | - /** |
|
131 | - * add an element in the form |
|
132 | - * |
|
133 | - * @access public |
|
134 | - * @param string $sName name |
|
135 | - * @param string|\Venus\lib\Form $mType type of field |
|
136 | - * @param string $sLabel label of field |
|
137 | - * @param mixed $mValue value of field |
|
138 | - * @parma mixed $mOptions options (for select) |
|
139 | - * @return \Venus\lib\Form |
|
140 | - */ |
|
141 | - public function add($sName, $mType, $sLabel = null, $mValue = null, $mOptions = null) |
|
142 | - { |
|
143 | - if ($mType instanceof Container) { |
|
144 | - |
|
145 | - $this->_aElement[$sName] = $mType; |
|
146 | - } else if ($mType === 'text' || $mType === 'submit' || $mType === 'password' || $mType === 'file' || $mType === 'tel' |
|
147 | - || $mType === 'url' || $mType === 'email' || $mType === 'search' || $mType === 'date' || $mType === 'time' |
|
148 | - || $mType === 'datetime' || $mType === 'month' || $mType === 'week' || $mType === 'number' || $mType === 'range' |
|
149 | - || $mType === 'color') { |
|
150 | - |
|
151 | - $this->_aElement[$sName] = new Input($sName, $mType, $sLabel, $mValue); |
|
152 | - } elseif ($mType === 'textarea') { |
|
153 | - |
|
154 | - $this->_aElement[$sName] = new Textarea($sName, $sLabel, $mValue); |
|
155 | - } else if ($mType === 'select') { |
|
156 | - |
|
157 | - $this->_aElement[$sName] = new Select($sName, $mOptions, $sLabel, $mValue); |
|
158 | - } else if ($mType === 'label') { |
|
159 | - |
|
160 | - $this->_aElement[$sName] = new Label($sName); |
|
161 | - } else if ($mType === 'list_checkbox') { |
|
162 | - |
|
163 | - $i = 0; |
|
164 | - |
|
165 | - $this->_aElement[$sName.'_'.$i++] = new Label($sLabel); |
|
166 | - |
|
167 | - foreach ($mValue as $mKey => $sValue) { |
|
168 | - |
|
169 | - $this->_aElement[$sName.'_'.$i++] = new Checkbox($sName, $sValue, $mKey, $mOptions); |
|
170 | - } |
|
171 | - } else if ($mType === 'checkbox') { |
|
172 | - |
|
173 | - $this->_aElement[$sName] = new Checkbox($sName, $sLabel, $mValue, $mOptions); |
|
174 | - } else if ($mType === 'radio') { |
|
175 | - |
|
176 | - $this->_aElement[$sName.rand(100000, 999999)] = new Radio($sName, $sLabel, $mValue, $mOptions); |
|
177 | - } else if ($mType === 'date') { |
|
178 | - |
|
179 | - $aDay = array(); |
|
180 | - |
|
181 | - for ($i = 1; $i <= 31; $i++) { |
|
182 | - |
|
183 | - if ($i < 10) { $aDay['0'.$i] = '0'.$i; } |
|
184 | - else { $aDay[$i] = $i; } |
|
185 | - } |
|
186 | - |
|
187 | - $this->_aElement[$sName.'_day'] = new Select($sName, $aDay); |
|
188 | - |
|
189 | - $aMonth = array( |
|
190 | - '01' => 'Jan', |
|
191 | - '02' => 'Feb', |
|
192 | - '03' => 'Mar', |
|
193 | - '04' => 'Apr', |
|
194 | - '05' => 'May', |
|
195 | - '06' => 'Jun', |
|
196 | - '07' => 'Jui', |
|
197 | - '08' => 'Aug', |
|
198 | - '09' => 'Sep', |
|
199 | - '10' => 'Oct', |
|
200 | - '11' => 'Nov', |
|
201 | - '12' => 'Dec', |
|
202 | - ); |
|
203 | - |
|
204 | - $this->_aElement[$sName.'_month'] = new Select($sName, $aMonth); |
|
205 | - |
|
206 | - $aYear = array(); |
|
207 | - |
|
208 | - for ($i = 1900; $i <= 2013; $i++) { |
|
209 | - |
|
210 | - $aYear[$i] = $i; |
|
211 | - } |
|
212 | - |
|
213 | - $this->_aElement[$sName.'_year'] = new Select($sName, $aMonth); |
|
214 | - } |
|
215 | - |
|
216 | - return $this; |
|
217 | - } |
|
218 | - |
|
219 | - /** |
|
220 | - * get id entity created by the formular |
|
221 | - * |
|
222 | - * @access public |
|
223 | - * @return int |
|
224 | - */ |
|
225 | - public function getIdEntityCreated() : int |
|
226 | - { |
|
227 | - return $this->_iIdEntityCreated; |
|
228 | - } |
|
229 | - |
|
230 | - /** |
|
231 | - * set id entity created by the formular |
|
232 | - * |
|
233 | - * @access public |
|
234 | - * @param int $iIdEntityCreated |
|
235 | - * @return Form |
|
236 | - */ |
|
237 | - public function setIdEntityCreated(int $iIdEntityCreated) : Form |
|
238 | - { |
|
239 | - $this->_iIdEntityCreated = $iIdEntityCreated; |
|
240 | - return $this; |
|
241 | - } |
|
242 | - |
|
243 | - /** |
|
244 | - * get form number |
|
245 | - * |
|
246 | - * @access public |
|
247 | - * @return int |
|
248 | - */ |
|
249 | - public function getFormNumber() : int |
|
250 | - { |
|
251 | - return $this->_iFormNumber; |
|
252 | - } |
|
63 | + /** |
|
64 | + * Elements of the form |
|
65 | + * |
|
66 | + * @access private |
|
67 | + * @var array |
|
68 | + */ |
|
69 | + private $_aElement = array(); |
|
70 | + |
|
71 | + /** |
|
72 | + * Increment for form |
|
73 | + * |
|
74 | + * @access private |
|
75 | + * @var int |
|
76 | + */ |
|
77 | + private static $_iFormIncrement = 0; |
|
78 | + |
|
79 | + /** |
|
80 | + * number of form |
|
81 | + * |
|
82 | + * @access private |
|
83 | + * @var int |
|
84 | + */ |
|
85 | + private $_iFormNumber = 0; |
|
86 | + |
|
87 | + /** |
|
88 | + * Separator between fields of form |
|
89 | + * |
|
90 | + * @access private |
|
91 | + * @var string |
|
92 | + */ |
|
93 | + private $_sSeparator = '<br/>'; |
|
94 | + |
|
95 | + /** |
|
96 | + * The entity to save with the formular |
|
97 | + * |
|
98 | + * @access private |
|
99 | + * @var string |
|
100 | + */ |
|
101 | + private $_sSynchronizeEntity = null; |
|
102 | + |
|
103 | + /** |
|
104 | + * The id of entity |
|
105 | + * |
|
106 | + * @access private |
|
107 | + * @var int |
|
108 | + */ |
|
109 | + private $_iIdEntity = null; |
|
110 | + |
|
111 | + /** |
|
112 | + * The entity to save with the formular |
|
113 | + * |
|
114 | + * @access private |
|
115 | + * @var int |
|
116 | + */ |
|
117 | + private $_iIdEntityCreated = null; |
|
118 | + |
|
119 | + /** |
|
120 | + * constructor that it increment (static) for all use |
|
121 | + * |
|
122 | + * @access public |
|
123 | + */ |
|
124 | + public function __construct() |
|
125 | + { |
|
126 | + self::$_iFormIncrement++; |
|
127 | + $this->_iFormNumber = self::$_iFormIncrement; |
|
128 | + } |
|
129 | + |
|
130 | + /** |
|
131 | + * add an element in the form |
|
132 | + * |
|
133 | + * @access public |
|
134 | + * @param string $sName name |
|
135 | + * @param string|\Venus\lib\Form $mType type of field |
|
136 | + * @param string $sLabel label of field |
|
137 | + * @param mixed $mValue value of field |
|
138 | + * @parma mixed $mOptions options (for select) |
|
139 | + * @return \Venus\lib\Form |
|
140 | + */ |
|
141 | + public function add($sName, $mType, $sLabel = null, $mValue = null, $mOptions = null) |
|
142 | + { |
|
143 | + if ($mType instanceof Container) { |
|
144 | + |
|
145 | + $this->_aElement[$sName] = $mType; |
|
146 | + } else if ($mType === 'text' || $mType === 'submit' || $mType === 'password' || $mType === 'file' || $mType === 'tel' |
|
147 | + || $mType === 'url' || $mType === 'email' || $mType === 'search' || $mType === 'date' || $mType === 'time' |
|
148 | + || $mType === 'datetime' || $mType === 'month' || $mType === 'week' || $mType === 'number' || $mType === 'range' |
|
149 | + || $mType === 'color') { |
|
150 | + |
|
151 | + $this->_aElement[$sName] = new Input($sName, $mType, $sLabel, $mValue); |
|
152 | + } elseif ($mType === 'textarea') { |
|
153 | + |
|
154 | + $this->_aElement[$sName] = new Textarea($sName, $sLabel, $mValue); |
|
155 | + } else if ($mType === 'select') { |
|
156 | + |
|
157 | + $this->_aElement[$sName] = new Select($sName, $mOptions, $sLabel, $mValue); |
|
158 | + } else if ($mType === 'label') { |
|
159 | + |
|
160 | + $this->_aElement[$sName] = new Label($sName); |
|
161 | + } else if ($mType === 'list_checkbox') { |
|
162 | + |
|
163 | + $i = 0; |
|
164 | + |
|
165 | + $this->_aElement[$sName.'_'.$i++] = new Label($sLabel); |
|
166 | + |
|
167 | + foreach ($mValue as $mKey => $sValue) { |
|
168 | + |
|
169 | + $this->_aElement[$sName.'_'.$i++] = new Checkbox($sName, $sValue, $mKey, $mOptions); |
|
170 | + } |
|
171 | + } else if ($mType === 'checkbox') { |
|
172 | + |
|
173 | + $this->_aElement[$sName] = new Checkbox($sName, $sLabel, $mValue, $mOptions); |
|
174 | + } else if ($mType === 'radio') { |
|
175 | + |
|
176 | + $this->_aElement[$sName.rand(100000, 999999)] = new Radio($sName, $sLabel, $mValue, $mOptions); |
|
177 | + } else if ($mType === 'date') { |
|
178 | + |
|
179 | + $aDay = array(); |
|
180 | + |
|
181 | + for ($i = 1; $i <= 31; $i++) { |
|
182 | + |
|
183 | + if ($i < 10) { $aDay['0'.$i] = '0'.$i; } |
|
184 | + else { $aDay[$i] = $i; } |
|
185 | + } |
|
186 | + |
|
187 | + $this->_aElement[$sName.'_day'] = new Select($sName, $aDay); |
|
188 | + |
|
189 | + $aMonth = array( |
|
190 | + '01' => 'Jan', |
|
191 | + '02' => 'Feb', |
|
192 | + '03' => 'Mar', |
|
193 | + '04' => 'Apr', |
|
194 | + '05' => 'May', |
|
195 | + '06' => 'Jun', |
|
196 | + '07' => 'Jui', |
|
197 | + '08' => 'Aug', |
|
198 | + '09' => 'Sep', |
|
199 | + '10' => 'Oct', |
|
200 | + '11' => 'Nov', |
|
201 | + '12' => 'Dec', |
|
202 | + ); |
|
203 | + |
|
204 | + $this->_aElement[$sName.'_month'] = new Select($sName, $aMonth); |
|
205 | + |
|
206 | + $aYear = array(); |
|
207 | + |
|
208 | + for ($i = 1900; $i <= 2013; $i++) { |
|
209 | + |
|
210 | + $aYear[$i] = $i; |
|
211 | + } |
|
212 | + |
|
213 | + $this->_aElement[$sName.'_year'] = new Select($sName, $aMonth); |
|
214 | + } |
|
215 | + |
|
216 | + return $this; |
|
217 | + } |
|
218 | + |
|
219 | + /** |
|
220 | + * get id entity created by the formular |
|
221 | + * |
|
222 | + * @access public |
|
223 | + * @return int |
|
224 | + */ |
|
225 | + public function getIdEntityCreated() : int |
|
226 | + { |
|
227 | + return $this->_iIdEntityCreated; |
|
228 | + } |
|
229 | + |
|
230 | + /** |
|
231 | + * set id entity created by the formular |
|
232 | + * |
|
233 | + * @access public |
|
234 | + * @param int $iIdEntityCreated |
|
235 | + * @return Form |
|
236 | + */ |
|
237 | + public function setIdEntityCreated(int $iIdEntityCreated) : Form |
|
238 | + { |
|
239 | + $this->_iIdEntityCreated = $iIdEntityCreated; |
|
240 | + return $this; |
|
241 | + } |
|
242 | + |
|
243 | + /** |
|
244 | + * get form number |
|
245 | + * |
|
246 | + * @access public |
|
247 | + * @return int |
|
248 | + */ |
|
249 | + public function getFormNumber() : int |
|
250 | + { |
|
251 | + return $this->_iFormNumber; |
|
252 | + } |
|
253 | 253 | |
254 | - /** |
|
255 | - * set id entity created by the formular |
|
256 | - * |
|
257 | - * @access public |
|
258 | - * @param int $iFormNumber |
|
259 | - * @return Form |
|
260 | - */ |
|
261 | - public function setFormNumber(int $iFormNumber) : Form |
|
262 | - { |
|
263 | - $this->_iFormNumber = $iFormNumber; |
|
264 | - return $this; |
|
265 | - } |
|
266 | - |
|
267 | - /** |
|
268 | - * get global form |
|
269 | - * |
|
270 | - * @access public |
|
271 | - * @return \Venus\lib\Form\Container |
|
272 | - */ |
|
273 | - public function getForm() |
|
274 | - { |
|
275 | - $oForm = $this->getFormInObject(); |
|
276 | - |
|
277 | - $sFormContent = $oForm->start; |
|
278 | - |
|
279 | - foreach ($oForm->form as $sValue) { |
|
280 | - |
|
281 | - $sFormContent .= $sValue.$this->_sSeparator; |
|
282 | - } |
|
283 | - |
|
284 | - $sFormContent .= $oForm->end; |
|
285 | - |
|
286 | - $oContainer = new Container; |
|
287 | - $oContainer->setView($sFormContent) |
|
288 | - ->setForm($this); |
|
289 | - |
|
290 | - return $oContainer; |
|
291 | - } |
|
292 | - |
|
293 | - |
|
294 | - /** |
|
295 | - * get global object form |
|
296 | - * |
|
297 | - * @access public |
|
298 | - * @return \stdClass |
|
299 | - */ |
|
300 | - public function getFormInObject() |
|
301 | - { |
|
302 | - $sExKey = null; |
|
303 | - |
|
304 | - if ($this->_iIdEntity > 0 && $this->_sSynchronizeEntity !== null && count($_POST) < 1) { |
|
305 | - |
|
306 | - $sModelName = str_replace('Entity', 'Model', $this->_sSynchronizeEntity); |
|
307 | - $oModel = new $sModelName; |
|
308 | - |
|
309 | - $oEntity = new $this->_sSynchronizeEntity; |
|
310 | - $sPrimaryKey = LibEntity::getPrimaryKeyNameWithoutMapping($oEntity); |
|
311 | - $sMethodName = 'findOneBy'.$sPrimaryKey; |
|
312 | - $oCompleteEntity = call_user_func_array(array(&$oModel, $sMethodName), array($this->_iIdEntity)); |
|
313 | - |
|
314 | - if (is_object($oCompleteEntity)) { |
|
315 | - |
|
316 | - foreach ($this->_aElement as $sKey => $sValue) { |
|
317 | - |
|
318 | - if ($sValue instanceof \Venus\lib\Form\Radio) { |
|
319 | - |
|
320 | - $sExKey = $sKey; |
|
321 | - $sKey = substr($sKey, 0, -6); |
|
322 | - } |
|
323 | - |
|
324 | - if ($sValue instanceof Form) { |
|
325 | - |
|
326 | - ; |
|
327 | - } else { |
|
328 | - |
|
329 | - $sMethodNameInEntity = 'get_'.$sKey; |
|
330 | - $mValue = $oCompleteEntity->$sMethodNameInEntity(); |
|
331 | - |
|
332 | - if ($sValue instanceof \Venus\lib\Form\Radio && method_exists($this->_aElement[$sExKey], 'setValueChecked')) { |
|
333 | - |
|
334 | - $this->_aElement[$sExKey]->setValueChecked($mValue); |
|
335 | - } else if (isset($mValue) && method_exists($this->_aElement[$sKey], 'setValue')) { |
|
336 | - |
|
337 | - $this->_aElement[$sKey]->setValue($mValue); |
|
338 | - } |
|
339 | - } |
|
340 | - } |
|
341 | - } |
|
342 | - } |
|
343 | - |
|
344 | - $oForm = new \StdClass(); |
|
345 | - $oForm->start = '<form name="form'.$this->_iFormNumber.'" method="post"><input type="hidden" value="1" name="validform'.$this->_iFormNumber.'">'; |
|
346 | - $oForm->form = array(); |
|
347 | - |
|
348 | - foreach ($this->_aElement as $sKey => $sValue) { |
|
349 | - |
|
350 | - if ($sValue instanceof Container) { |
|
351 | - |
|
352 | - $oForm->form[$sKey] = $sValue; |
|
353 | - } else { |
|
354 | - |
|
355 | - $oForm->form[$sKey] = $sValue->fetch(); |
|
356 | - } |
|
357 | - } |
|
358 | - |
|
359 | - $oForm->end = '</form>'; |
|
360 | - |
|
361 | - return $oForm; |
|
362 | - } |
|
363 | - |
|
364 | - /** |
|
365 | - * get an element of formular |
|
366 | - * |
|
367 | - * @access public |
|
368 | - * @param string $sName name |
|
369 | - * @return object |
|
370 | - */ |
|
371 | - public function get($sName) |
|
372 | - { |
|
373 | - return $this->_aElement[$sName]; |
|
374 | - } |
|
375 | - |
|
376 | - /** |
|
377 | - * get the form separator |
|
378 | - * |
|
379 | - * @access public |
|
380 | - * @return string |
|
381 | - */ |
|
382 | - public function getSeparator() |
|
383 | - { |
|
384 | - return $this->_sSeparator; |
|
385 | - } |
|
386 | - |
|
387 | - /** |
|
388 | - * set the form separator |
|
389 | - * |
|
390 | - * @access public |
|
391 | - * @param string $sSeparator separator between the fields |
|
392 | - * @return \Venus\lib\Form |
|
393 | - */ |
|
394 | - public function setSeparator($sSeparator) |
|
395 | - { |
|
396 | - $this->_sSeparator = $sSeparator; |
|
397 | - return $this; |
|
398 | - } |
|
399 | - |
|
400 | - /** |
|
401 | - * set the entity to synchronize with the formular |
|
402 | - * |
|
403 | - * @access public |
|
404 | - * @param $sSynchronizeEntity |
|
405 | - * @param int $iId id of the primary key |
|
406 | - * @return Form |
|
407 | - * @internal param string $sSeparator separator between the fields |
|
408 | - */ |
|
409 | - public function synchronizeEntity($sSynchronizeEntity, $iId = null) |
|
410 | - { |
|
411 | - if ($iId !== null) { $this->_iIdEntity = $iId; } |
|
412 | - |
|
413 | - $this->_sSynchronizeEntity = $sSynchronizeEntity; |
|
414 | - return $this; |
|
415 | - } |
|
416 | - |
|
417 | - /** |
|
418 | - * add constraint |
|
419 | - * |
|
420 | - * @access public |
|
421 | - * @param string $sName field name |
|
422 | - * @param object $oConstraint constraint on the field |
|
423 | - * @return \Venus\lib\Form |
|
424 | - */ |
|
425 | - public function addConstraint($sName, $oConstraint) |
|
426 | - { |
|
427 | - if ($this->_aElement[$sName] instanceof Input || $this->_aElement[$sName] instanceof Textarea) { |
|
428 | - |
|
429 | - $this->_aElement[$sName]->setConstraint($oConstraint); |
|
430 | - } |
|
431 | - |
|
432 | - return $this; |
|
433 | - } |
|
434 | - |
|
435 | - /** |
|
436 | - * get all elements |
|
437 | - * |
|
438 | - * @access public |
|
439 | - * @return array |
|
440 | - */ |
|
441 | - public function getElement() { |
|
442 | - |
|
443 | - return $this->_aElement; |
|
444 | - } |
|
445 | - |
|
446 | - /** |
|
447 | - * get all elements |
|
448 | - * |
|
449 | - * @access public |
|
450 | - * @return int |
|
451 | - */ |
|
452 | - public function getIdEntity() { |
|
453 | - |
|
454 | - return $this->_iIdEntity; |
|
455 | - } |
|
456 | - |
|
457 | - /** |
|
458 | - * get all elements |
|
459 | - * |
|
460 | - * @access public |
|
461 | - * @return string |
|
462 | - */ |
|
463 | - public function getSynchronizeEntity() { |
|
464 | - |
|
465 | - return $this->_sSynchronizeEntity; |
|
466 | - } |
|
254 | + /** |
|
255 | + * set id entity created by the formular |
|
256 | + * |
|
257 | + * @access public |
|
258 | + * @param int $iFormNumber |
|
259 | + * @return Form |
|
260 | + */ |
|
261 | + public function setFormNumber(int $iFormNumber) : Form |
|
262 | + { |
|
263 | + $this->_iFormNumber = $iFormNumber; |
|
264 | + return $this; |
|
265 | + } |
|
266 | + |
|
267 | + /** |
|
268 | + * get global form |
|
269 | + * |
|
270 | + * @access public |
|
271 | + * @return \Venus\lib\Form\Container |
|
272 | + */ |
|
273 | + public function getForm() |
|
274 | + { |
|
275 | + $oForm = $this->getFormInObject(); |
|
276 | + |
|
277 | + $sFormContent = $oForm->start; |
|
278 | + |
|
279 | + foreach ($oForm->form as $sValue) { |
|
280 | + |
|
281 | + $sFormContent .= $sValue.$this->_sSeparator; |
|
282 | + } |
|
283 | + |
|
284 | + $sFormContent .= $oForm->end; |
|
285 | + |
|
286 | + $oContainer = new Container; |
|
287 | + $oContainer->setView($sFormContent) |
|
288 | + ->setForm($this); |
|
289 | + |
|
290 | + return $oContainer; |
|
291 | + } |
|
292 | + |
|
293 | + |
|
294 | + /** |
|
295 | + * get global object form |
|
296 | + * |
|
297 | + * @access public |
|
298 | + * @return \stdClass |
|
299 | + */ |
|
300 | + public function getFormInObject() |
|
301 | + { |
|
302 | + $sExKey = null; |
|
303 | + |
|
304 | + if ($this->_iIdEntity > 0 && $this->_sSynchronizeEntity !== null && count($_POST) < 1) { |
|
305 | + |
|
306 | + $sModelName = str_replace('Entity', 'Model', $this->_sSynchronizeEntity); |
|
307 | + $oModel = new $sModelName; |
|
308 | + |
|
309 | + $oEntity = new $this->_sSynchronizeEntity; |
|
310 | + $sPrimaryKey = LibEntity::getPrimaryKeyNameWithoutMapping($oEntity); |
|
311 | + $sMethodName = 'findOneBy'.$sPrimaryKey; |
|
312 | + $oCompleteEntity = call_user_func_array(array(&$oModel, $sMethodName), array($this->_iIdEntity)); |
|
313 | + |
|
314 | + if (is_object($oCompleteEntity)) { |
|
315 | + |
|
316 | + foreach ($this->_aElement as $sKey => $sValue) { |
|
317 | + |
|
318 | + if ($sValue instanceof \Venus\lib\Form\Radio) { |
|
319 | + |
|
320 | + $sExKey = $sKey; |
|
321 | + $sKey = substr($sKey, 0, -6); |
|
322 | + } |
|
323 | + |
|
324 | + if ($sValue instanceof Form) { |
|
325 | + |
|
326 | + ; |
|
327 | + } else { |
|
328 | + |
|
329 | + $sMethodNameInEntity = 'get_'.$sKey; |
|
330 | + $mValue = $oCompleteEntity->$sMethodNameInEntity(); |
|
331 | + |
|
332 | + if ($sValue instanceof \Venus\lib\Form\Radio && method_exists($this->_aElement[$sExKey], 'setValueChecked')) { |
|
333 | + |
|
334 | + $this->_aElement[$sExKey]->setValueChecked($mValue); |
|
335 | + } else if (isset($mValue) && method_exists($this->_aElement[$sKey], 'setValue')) { |
|
336 | + |
|
337 | + $this->_aElement[$sKey]->setValue($mValue); |
|
338 | + } |
|
339 | + } |
|
340 | + } |
|
341 | + } |
|
342 | + } |
|
343 | + |
|
344 | + $oForm = new \StdClass(); |
|
345 | + $oForm->start = '<form name="form'.$this->_iFormNumber.'" method="post"><input type="hidden" value="1" name="validform'.$this->_iFormNumber.'">'; |
|
346 | + $oForm->form = array(); |
|
347 | + |
|
348 | + foreach ($this->_aElement as $sKey => $sValue) { |
|
349 | + |
|
350 | + if ($sValue instanceof Container) { |
|
351 | + |
|
352 | + $oForm->form[$sKey] = $sValue; |
|
353 | + } else { |
|
354 | + |
|
355 | + $oForm->form[$sKey] = $sValue->fetch(); |
|
356 | + } |
|
357 | + } |
|
358 | + |
|
359 | + $oForm->end = '</form>'; |
|
360 | + |
|
361 | + return $oForm; |
|
362 | + } |
|
363 | + |
|
364 | + /** |
|
365 | + * get an element of formular |
|
366 | + * |
|
367 | + * @access public |
|
368 | + * @param string $sName name |
|
369 | + * @return object |
|
370 | + */ |
|
371 | + public function get($sName) |
|
372 | + { |
|
373 | + return $this->_aElement[$sName]; |
|
374 | + } |
|
375 | + |
|
376 | + /** |
|
377 | + * get the form separator |
|
378 | + * |
|
379 | + * @access public |
|
380 | + * @return string |
|
381 | + */ |
|
382 | + public function getSeparator() |
|
383 | + { |
|
384 | + return $this->_sSeparator; |
|
385 | + } |
|
386 | + |
|
387 | + /** |
|
388 | + * set the form separator |
|
389 | + * |
|
390 | + * @access public |
|
391 | + * @param string $sSeparator separator between the fields |
|
392 | + * @return \Venus\lib\Form |
|
393 | + */ |
|
394 | + public function setSeparator($sSeparator) |
|
395 | + { |
|
396 | + $this->_sSeparator = $sSeparator; |
|
397 | + return $this; |
|
398 | + } |
|
399 | + |
|
400 | + /** |
|
401 | + * set the entity to synchronize with the formular |
|
402 | + * |
|
403 | + * @access public |
|
404 | + * @param $sSynchronizeEntity |
|
405 | + * @param int $iId id of the primary key |
|
406 | + * @return Form |
|
407 | + * @internal param string $sSeparator separator between the fields |
|
408 | + */ |
|
409 | + public function synchronizeEntity($sSynchronizeEntity, $iId = null) |
|
410 | + { |
|
411 | + if ($iId !== null) { $this->_iIdEntity = $iId; } |
|
412 | + |
|
413 | + $this->_sSynchronizeEntity = $sSynchronizeEntity; |
|
414 | + return $this; |
|
415 | + } |
|
416 | + |
|
417 | + /** |
|
418 | + * add constraint |
|
419 | + * |
|
420 | + * @access public |
|
421 | + * @param string $sName field name |
|
422 | + * @param object $oConstraint constraint on the field |
|
423 | + * @return \Venus\lib\Form |
|
424 | + */ |
|
425 | + public function addConstraint($sName, $oConstraint) |
|
426 | + { |
|
427 | + if ($this->_aElement[$sName] instanceof Input || $this->_aElement[$sName] instanceof Textarea) { |
|
428 | + |
|
429 | + $this->_aElement[$sName]->setConstraint($oConstraint); |
|
430 | + } |
|
431 | + |
|
432 | + return $this; |
|
433 | + } |
|
434 | + |
|
435 | + /** |
|
436 | + * get all elements |
|
437 | + * |
|
438 | + * @access public |
|
439 | + * @return array |
|
440 | + */ |
|
441 | + public function getElement() { |
|
442 | + |
|
443 | + return $this->_aElement; |
|
444 | + } |
|
445 | + |
|
446 | + /** |
|
447 | + * get all elements |
|
448 | + * |
|
449 | + * @access public |
|
450 | + * @return int |
|
451 | + */ |
|
452 | + public function getIdEntity() { |
|
453 | + |
|
454 | + return $this->_iIdEntity; |
|
455 | + } |
|
456 | + |
|
457 | + /** |
|
458 | + * get all elements |
|
459 | + * |
|
460 | + * @access public |
|
461 | + * @return string |
|
462 | + */ |
|
463 | + public function getSynchronizeEntity() { |
|
464 | + |
|
465 | + return $this->_sSynchronizeEntity; |
|
466 | + } |
|
467 | 467 | } |
@@ -30,210 +30,210 @@ |
||
30 | 30 | */ |
31 | 31 | class Date |
32 | 32 | { |
33 | - /** |
|
34 | - * set name of image |
|
35 | - * |
|
36 | - * @access public |
|
37 | - * @param int $iWeek number of week |
|
38 | - * @param int $iYear year |
|
39 | - * @param string $sFormat |
|
40 | - * @return Date |
|
41 | - */ |
|
42 | - public static function getWeek(int $iWeek, int $iYear, string $sFormat = "Y-m-d") : Date |
|
43 | - { |
|
44 | - $iFirstDayInYear = date("N",mktime(0, 0, 0, 1, 1, $iYear)); |
|
45 | - |
|
46 | - if ($iFirstDayInYear < 5) { $iShift = -($iFirstDayInYear - 1) * 86400; } else { $iShift = (8 - $iFirstDayInYear) * 86400; } |
|
47 | - |
|
48 | - if ($iWeek > 1) { $iWeekInSeconds = ($iWeek-1) * 604800; } else { $iWeekInSeconds = 0; } |
|
49 | - |
|
50 | - $iTimestamp = mktime(0, 0, 0, 1, 1, $iYear) + $iWeekInSeconds + $iShift; |
|
51 | - $iTimestampLastDay = mktime(0, 0, 0, 1, 6, $iYear) + $iWeekInSeconds + $iShift + 604800; |
|
52 | - |
|
53 | - return array(date($sFormat, $iTimestamp), date($sFormat, $iTimestampLastDay)); |
|
54 | - } |
|
55 | - |
|
56 | - /** |
|
57 | - * set name of image |
|
58 | - * |
|
59 | - * @access public |
|
60 | - * @return \Venus\lib\Date |
|
61 | - */ |
|
62 | - public static function getActualWeek() : Date |
|
63 | - { |
|
64 | - return self::getWeek(date('W'), date('Y')); |
|
65 | - } |
|
66 | - |
|
67 | - /** |
|
68 | - * set name of image |
|
69 | - * |
|
70 | - * @access public |
|
71 | - * @param string $sMonth number of week |
|
72 | - * @param string $sLanguage language |
|
73 | - * @return \Venus\lib\Date |
|
74 | - */ |
|
75 | - public static function getMonthInWord(string $sMonth, string $sLanguage = 'fr') : Date |
|
76 | - { |
|
77 | - if ($sLanguage == 'fr') { |
|
78 | - |
|
79 | - if ($sMonth == '01' || $sMonth == 1) { return 'Janvier'; } |
|
80 | - else if ($sMonth == '02' || $sMonth == 2) { return 'Février'; } |
|
81 | - else if ($sMonth == '03' || $sMonth == 3) { return 'Mars'; } |
|
82 | - else if ($sMonth == '04' || $sMonth == 4) { return 'Avril'; } |
|
83 | - else if ($sMonth == '05' || $sMonth == 5) { return 'Mai'; } |
|
84 | - else if ($sMonth == '06' || $sMonth == 6) { return 'Juin'; } |
|
85 | - else if ($sMonth == '07' || $sMonth == 7) { return 'Juillet'; } |
|
86 | - else if ($sMonth == '08' || $sMonth == 8) { return 'Août'; } |
|
87 | - else if ($sMonth == '09' || $sMonth == 9) { return 'Septembre'; } |
|
88 | - else if ($sMonth == 10) { return 'Octobre'; } |
|
89 | - else if ($sMonth == 11) { return 'Novembre'; } |
|
90 | - else if ($sMonth == 12) { return 'Décembre'; } |
|
91 | - } |
|
92 | - } |
|
93 | - |
|
94 | - /** |
|
95 | - * set name of image |
|
96 | - * |
|
97 | - * @access public |
|
98 | - * @param mixed $sDay number of day |
|
99 | - * @param string $sLanguage language |
|
100 | - * @return \Venus\lib\Date |
|
101 | - */ |
|
102 | - public static function getDayInWord(string $sDay, string $sLanguage = 'fr') : Date |
|
103 | - { |
|
104 | - if ($sLanguage == 'fr') { |
|
105 | - |
|
106 | - if ($sDay == 0) { return 'dimanche'; } |
|
107 | - else if ($sDay == 1) { return 'lundi'; } |
|
108 | - else if ($sDay == 2) { return 'mardi'; } |
|
109 | - else if ($sDay == 3) { return 'mercredi'; } |
|
110 | - else if ($sDay == 4) { return 'jeudi'; } |
|
111 | - else if ($sDay == 5) { return 'vendredi'; } |
|
112 | - else if ($sDay == 6) { return 'samedi'; } |
|
113 | - } |
|
114 | - } |
|
115 | - |
|
116 | - /** |
|
117 | - * get age by date |
|
118 | - * |
|
119 | - * @access public |
|
120 | - * @param string $sBirthday |
|
121 | - * @return int |
|
122 | - */ |
|
123 | - public static function getAgeByDate(string $sBirthday) : int |
|
124 | - { |
|
125 | - list($iYear, $iMonth, $iDay) = preg_split('/[-.]/', $sBirthday); |
|
126 | - |
|
127 | - $aToday = array(); |
|
128 | - $aToday['mois'] = date('n'); |
|
129 | - $aToday['jour'] = date('j'); |
|
130 | - $aToday['annee'] = date('Y'); |
|
131 | - |
|
132 | - $iYears = $aToday['annee'] - $iYear; |
|
133 | - |
|
134 | - if ($aToday['mois'] <= $iMonth) { |
|
135 | - |
|
136 | - if ($iMonth == $aToday['mois']) { |
|
137 | - |
|
138 | - if ($iDay > $aToday['jour']) { $iYears--; } |
|
139 | - } |
|
140 | - else { |
|
141 | - |
|
142 | - $iYears--; |
|
143 | - } |
|
144 | - } |
|
145 | - |
|
146 | - return $iYears; |
|
147 | - } |
|
148 | - |
|
149 | - /** |
|
150 | - * set name of image |
|
151 | - * |
|
152 | - * @access public |
|
153 | - * @param int $iWeek number of week |
|
154 | - * @param int $iYear year |
|
155 | - * @param string $sFormat |
|
156 | - * @return array|Date |
|
157 | - */ |
|
158 | - public static function getMiddleWeek(int $iWeek, int $iYear, string $sFormat = "Y-m-d") : array |
|
159 | - { |
|
160 | - $iFirstDayInYear = date("N",mktime(0, 0, 0, 1, 1, $iYear)); |
|
161 | - |
|
162 | - if ($iFirstDayInYear < 5) { $iShift = -($iFirstDayInYear - 1) * 86400; } |
|
163 | - else { $iShift = (8 - $iFirstDayInYear) * 86400; } |
|
164 | - |
|
165 | - if ($iWeek > 1) { $iWeekInSeconds = ($iWeek-1) * 604800; } |
|
166 | - else { $iWeekInSeconds = 0; } |
|
167 | - |
|
168 | - if (date('N') > 2) { |
|
169 | - |
|
170 | - $iTimestamp = mktime(0, 0, 0, 1, 1, $iYear) + $iWeekInSeconds + $iShift + 172800; |
|
171 | - $iTimestampLastDay = $iTimestamp + 604800; |
|
172 | - } |
|
173 | - else { |
|
174 | - |
|
175 | - $iTimestamp = mktime(0, 0, 0, 1, 1, $iYear) + $iWeekInSeconds + $iShift - 432000; |
|
176 | - $iTimestampLastDay = $iTimestamp + 604800; |
|
177 | - } |
|
178 | - |
|
179 | - $aDates = array(date($sFormat, $iTimestamp), date($sFormat, $iTimestampLastDay)); |
|
180 | - |
|
181 | - if (preg_replace('/^([0-9]+)-[0-9]+-[0-9]+$/', '$1', $aDates[0]) != date('Y')) { |
|
182 | - |
|
183 | - $aDates[0] = preg_replace('/^[0-9]+(-[0-9]+-[0-9]+)$/', date('Y').'$1', $aDates[0]); |
|
184 | - $aDates[1] = preg_replace('/^[0-9]+(-[0-9]+-[0-9]+)$/', (date('Y')+1).'$1', $aDates[1]); |
|
185 | - } |
|
186 | - |
|
187 | - return $aDates; |
|
188 | - } |
|
189 | - |
|
190 | - /** |
|
191 | - * set name of image |
|
192 | - * |
|
193 | - * @access public |
|
194 | - * @return array |
|
195 | - */ |
|
196 | - public static function getActualMiddleWeek() : array |
|
197 | - { |
|
198 | - return self::getMiddleWeek(date('W'), date('Y')); |
|
199 | - } |
|
200 | - |
|
201 | - /** |
|
202 | - * get time of kind "X hour ago" |
|
203 | - * |
|
204 | - * @access public |
|
205 | - * @param string $sDateTime datetime to convert |
|
206 | - * @param string $sLanguage language |
|
207 | - * @return string |
|
208 | - */ |
|
209 | - public static function getTimeAgoInString(string $sDateTime, string $sLanguage = 'fr') : string |
|
210 | - { |
|
211 | - if ($sLanguage == 'fr') { |
|
212 | - |
|
213 | - $sStartReturn = 'Il y a'; |
|
214 | - $sEndReturn = ''; |
|
215 | - $sMinutes = 'minute(s) '; |
|
216 | - $sHours = 'heure(s) '; |
|
217 | - $sDays = 'jour(s) '; |
|
218 | - $sMonths = 'mois '; |
|
219 | - $sYears = 'années '; |
|
220 | - } else { |
|
221 | - $sStartReturn = 'Ago'; |
|
222 | - $sEndReturn = ''; |
|
223 | - $sMinutes = 'minute(s) '; |
|
224 | - $sHours = 'hour(s) '; |
|
225 | - $sDays = 'day(s) '; |
|
226 | - $sMonths = 'month '; |
|
227 | - $sYears = 'years '; |
|
228 | - } |
|
229 | - |
|
230 | - $oDateTime = DateTime::createFromFormat('Y-m-d H:i:s', $sDateTime); |
|
231 | - $iTimeStamp = time() - $oDateTime->getTimestamp(); |
|
232 | - |
|
233 | - if ($iTimeStamp < 3600) { return $sStartReturn.' '.(int)($iTimeStamp/60).' '.$sMinutes.$sEndReturn; } |
|
234 | - if ($iTimeStamp < 86400) { return $sStartReturn.' '.(int)($iTimeStamp/3600).' '.$sHours.$sEndReturn; } |
|
235 | - if ($iTimeStamp < 2592000) { return $sStartReturn.' '.(int)($iTimeStamp/86400).' '.$sDays.$sEndReturn; } |
|
236 | - if ($iTimeStamp < 31536000) { return $sStartReturn.' '.(int)($iTimeStamp/2592000).' '.$sMonths.$sEndReturn; } |
|
237 | - else { return $sStartReturn.' '.(int)($iTimeStamp/31536000).' '.$sYears.$sEndReturn; } |
|
238 | - } |
|
33 | + /** |
|
34 | + * set name of image |
|
35 | + * |
|
36 | + * @access public |
|
37 | + * @param int $iWeek number of week |
|
38 | + * @param int $iYear year |
|
39 | + * @param string $sFormat |
|
40 | + * @return Date |
|
41 | + */ |
|
42 | + public static function getWeek(int $iWeek, int $iYear, string $sFormat = "Y-m-d") : Date |
|
43 | + { |
|
44 | + $iFirstDayInYear = date("N",mktime(0, 0, 0, 1, 1, $iYear)); |
|
45 | + |
|
46 | + if ($iFirstDayInYear < 5) { $iShift = -($iFirstDayInYear - 1) * 86400; } else { $iShift = (8 - $iFirstDayInYear) * 86400; } |
|
47 | + |
|
48 | + if ($iWeek > 1) { $iWeekInSeconds = ($iWeek-1) * 604800; } else { $iWeekInSeconds = 0; } |
|
49 | + |
|
50 | + $iTimestamp = mktime(0, 0, 0, 1, 1, $iYear) + $iWeekInSeconds + $iShift; |
|
51 | + $iTimestampLastDay = mktime(0, 0, 0, 1, 6, $iYear) + $iWeekInSeconds + $iShift + 604800; |
|
52 | + |
|
53 | + return array(date($sFormat, $iTimestamp), date($sFormat, $iTimestampLastDay)); |
|
54 | + } |
|
55 | + |
|
56 | + /** |
|
57 | + * set name of image |
|
58 | + * |
|
59 | + * @access public |
|
60 | + * @return \Venus\lib\Date |
|
61 | + */ |
|
62 | + public static function getActualWeek() : Date |
|
63 | + { |
|
64 | + return self::getWeek(date('W'), date('Y')); |
|
65 | + } |
|
66 | + |
|
67 | + /** |
|
68 | + * set name of image |
|
69 | + * |
|
70 | + * @access public |
|
71 | + * @param string $sMonth number of week |
|
72 | + * @param string $sLanguage language |
|
73 | + * @return \Venus\lib\Date |
|
74 | + */ |
|
75 | + public static function getMonthInWord(string $sMonth, string $sLanguage = 'fr') : Date |
|
76 | + { |
|
77 | + if ($sLanguage == 'fr') { |
|
78 | + |
|
79 | + if ($sMonth == '01' || $sMonth == 1) { return 'Janvier'; } |
|
80 | + else if ($sMonth == '02' || $sMonth == 2) { return 'Février'; } |
|
81 | + else if ($sMonth == '03' || $sMonth == 3) { return 'Mars'; } |
|
82 | + else if ($sMonth == '04' || $sMonth == 4) { return 'Avril'; } |
|
83 | + else if ($sMonth == '05' || $sMonth == 5) { return 'Mai'; } |
|
84 | + else if ($sMonth == '06' || $sMonth == 6) { return 'Juin'; } |
|
85 | + else if ($sMonth == '07' || $sMonth == 7) { return 'Juillet'; } |
|
86 | + else if ($sMonth == '08' || $sMonth == 8) { return 'Août'; } |
|
87 | + else if ($sMonth == '09' || $sMonth == 9) { return 'Septembre'; } |
|
88 | + else if ($sMonth == 10) { return 'Octobre'; } |
|
89 | + else if ($sMonth == 11) { return 'Novembre'; } |
|
90 | + else if ($sMonth == 12) { return 'Décembre'; } |
|
91 | + } |
|
92 | + } |
|
93 | + |
|
94 | + /** |
|
95 | + * set name of image |
|
96 | + * |
|
97 | + * @access public |
|
98 | + * @param mixed $sDay number of day |
|
99 | + * @param string $sLanguage language |
|
100 | + * @return \Venus\lib\Date |
|
101 | + */ |
|
102 | + public static function getDayInWord(string $sDay, string $sLanguage = 'fr') : Date |
|
103 | + { |
|
104 | + if ($sLanguage == 'fr') { |
|
105 | + |
|
106 | + if ($sDay == 0) { return 'dimanche'; } |
|
107 | + else if ($sDay == 1) { return 'lundi'; } |
|
108 | + else if ($sDay == 2) { return 'mardi'; } |
|
109 | + else if ($sDay == 3) { return 'mercredi'; } |
|
110 | + else if ($sDay == 4) { return 'jeudi'; } |
|
111 | + else if ($sDay == 5) { return 'vendredi'; } |
|
112 | + else if ($sDay == 6) { return 'samedi'; } |
|
113 | + } |
|
114 | + } |
|
115 | + |
|
116 | + /** |
|
117 | + * get age by date |
|
118 | + * |
|
119 | + * @access public |
|
120 | + * @param string $sBirthday |
|
121 | + * @return int |
|
122 | + */ |
|
123 | + public static function getAgeByDate(string $sBirthday) : int |
|
124 | + { |
|
125 | + list($iYear, $iMonth, $iDay) = preg_split('/[-.]/', $sBirthday); |
|
126 | + |
|
127 | + $aToday = array(); |
|
128 | + $aToday['mois'] = date('n'); |
|
129 | + $aToday['jour'] = date('j'); |
|
130 | + $aToday['annee'] = date('Y'); |
|
131 | + |
|
132 | + $iYears = $aToday['annee'] - $iYear; |
|
133 | + |
|
134 | + if ($aToday['mois'] <= $iMonth) { |
|
135 | + |
|
136 | + if ($iMonth == $aToday['mois']) { |
|
137 | + |
|
138 | + if ($iDay > $aToday['jour']) { $iYears--; } |
|
139 | + } |
|
140 | + else { |
|
141 | + |
|
142 | + $iYears--; |
|
143 | + } |
|
144 | + } |
|
145 | + |
|
146 | + return $iYears; |
|
147 | + } |
|
148 | + |
|
149 | + /** |
|
150 | + * set name of image |
|
151 | + * |
|
152 | + * @access public |
|
153 | + * @param int $iWeek number of week |
|
154 | + * @param int $iYear year |
|
155 | + * @param string $sFormat |
|
156 | + * @return array|Date |
|
157 | + */ |
|
158 | + public static function getMiddleWeek(int $iWeek, int $iYear, string $sFormat = "Y-m-d") : array |
|
159 | + { |
|
160 | + $iFirstDayInYear = date("N",mktime(0, 0, 0, 1, 1, $iYear)); |
|
161 | + |
|
162 | + if ($iFirstDayInYear < 5) { $iShift = -($iFirstDayInYear - 1) * 86400; } |
|
163 | + else { $iShift = (8 - $iFirstDayInYear) * 86400; } |
|
164 | + |
|
165 | + if ($iWeek > 1) { $iWeekInSeconds = ($iWeek-1) * 604800; } |
|
166 | + else { $iWeekInSeconds = 0; } |
|
167 | + |
|
168 | + if (date('N') > 2) { |
|
169 | + |
|
170 | + $iTimestamp = mktime(0, 0, 0, 1, 1, $iYear) + $iWeekInSeconds + $iShift + 172800; |
|
171 | + $iTimestampLastDay = $iTimestamp + 604800; |
|
172 | + } |
|
173 | + else { |
|
174 | + |
|
175 | + $iTimestamp = mktime(0, 0, 0, 1, 1, $iYear) + $iWeekInSeconds + $iShift - 432000; |
|
176 | + $iTimestampLastDay = $iTimestamp + 604800; |
|
177 | + } |
|
178 | + |
|
179 | + $aDates = array(date($sFormat, $iTimestamp), date($sFormat, $iTimestampLastDay)); |
|
180 | + |
|
181 | + if (preg_replace('/^([0-9]+)-[0-9]+-[0-9]+$/', '$1', $aDates[0]) != date('Y')) { |
|
182 | + |
|
183 | + $aDates[0] = preg_replace('/^[0-9]+(-[0-9]+-[0-9]+)$/', date('Y').'$1', $aDates[0]); |
|
184 | + $aDates[1] = preg_replace('/^[0-9]+(-[0-9]+-[0-9]+)$/', (date('Y')+1).'$1', $aDates[1]); |
|
185 | + } |
|
186 | + |
|
187 | + return $aDates; |
|
188 | + } |
|
189 | + |
|
190 | + /** |
|
191 | + * set name of image |
|
192 | + * |
|
193 | + * @access public |
|
194 | + * @return array |
|
195 | + */ |
|
196 | + public static function getActualMiddleWeek() : array |
|
197 | + { |
|
198 | + return self::getMiddleWeek(date('W'), date('Y')); |
|
199 | + } |
|
200 | + |
|
201 | + /** |
|
202 | + * get time of kind "X hour ago" |
|
203 | + * |
|
204 | + * @access public |
|
205 | + * @param string $sDateTime datetime to convert |
|
206 | + * @param string $sLanguage language |
|
207 | + * @return string |
|
208 | + */ |
|
209 | + public static function getTimeAgoInString(string $sDateTime, string $sLanguage = 'fr') : string |
|
210 | + { |
|
211 | + if ($sLanguage == 'fr') { |
|
212 | + |
|
213 | + $sStartReturn = 'Il y a'; |
|
214 | + $sEndReturn = ''; |
|
215 | + $sMinutes = 'minute(s) '; |
|
216 | + $sHours = 'heure(s) '; |
|
217 | + $sDays = 'jour(s) '; |
|
218 | + $sMonths = 'mois '; |
|
219 | + $sYears = 'années '; |
|
220 | + } else { |
|
221 | + $sStartReturn = 'Ago'; |
|
222 | + $sEndReturn = ''; |
|
223 | + $sMinutes = 'minute(s) '; |
|
224 | + $sHours = 'hour(s) '; |
|
225 | + $sDays = 'day(s) '; |
|
226 | + $sMonths = 'month '; |
|
227 | + $sYears = 'years '; |
|
228 | + } |
|
229 | + |
|
230 | + $oDateTime = DateTime::createFromFormat('Y-m-d H:i:s', $sDateTime); |
|
231 | + $iTimeStamp = time() - $oDateTime->getTimestamp(); |
|
232 | + |
|
233 | + if ($iTimeStamp < 3600) { return $sStartReturn.' '.(int)($iTimeStamp/60).' '.$sMinutes.$sEndReturn; } |
|
234 | + if ($iTimeStamp < 86400) { return $sStartReturn.' '.(int)($iTimeStamp/3600).' '.$sHours.$sEndReturn; } |
|
235 | + if ($iTimeStamp < 2592000) { return $sStartReturn.' '.(int)($iTimeStamp/86400).' '.$sDays.$sEndReturn; } |
|
236 | + if ($iTimeStamp < 31536000) { return $sStartReturn.' '.(int)($iTimeStamp/2592000).' '.$sMonths.$sEndReturn; } |
|
237 | + else { return $sStartReturn.' '.(int)($iTimeStamp/31536000).' '.$sYears.$sEndReturn; } |
|
238 | + } |
|
239 | 239 | } |
@@ -30,112 +30,112 @@ |
||
30 | 30 | */ |
31 | 31 | class UrlManager |
32 | 32 | { |
33 | - /** |
|
34 | - * The base Uri to construct the route |
|
35 | - * @var string |
|
36 | - */ |
|
37 | - private $_sBaseUri = ''; |
|
38 | - |
|
39 | - /** |
|
40 | - * create an URL |
|
41 | - * |
|
42 | - * @access public |
|
43 | - * @param string $sCode code of the url between "routes" and "route" in Route.conf |
|
44 | - * @param array $aParams parameters to create the url |
|
45 | - * @return string |
|
46 | - * |
|
47 | - * @tutorial If I have this route I could make my URL: |
|
48 | - * |
|
49 | - * "menu_edit": { |
|
50 | - * "route": "[/:language]/menu[/:id]/edit/", |
|
51 | - * "controller": "\\src\\BackOffice\\Controller\\MenuManager", |
|
52 | - * "action": "edit", |
|
53 | - * "constraints": { |
|
54 | - * "language": "[a-z]{0,2}", |
|
55 | - * "id": "[0-9]+" |
|
56 | - * }, |
|
57 | - * "content_type": "html" |
|
58 | - * }, |
|
59 | - * |
|
60 | - * I must write this: |
|
61 | - * |
|
62 | - * $oUrlManager = new \Venus\core\UrlManager; |
|
63 | - * $sUrl = $oUrlManager->getUrl('menu_edit', array('language' => 'vn', 'id' => 125)); |
|
64 | - */ |
|
65 | - public function getUrl(string $sCode, array $aParams = array()) : string |
|
66 | - { |
|
67 | - if (isset($_SERVER) && isset($_SERVER['HTTP_HOST'])) { |
|
68 | - |
|
69 | - foreach (Config::get('Route') as $sHost => $oHost) { |
|
70 | - |
|
71 | - if ((!strstr($sHost, '/') && $sHost == $_SERVER['HTTP_HOST']) |
|
72 | - || (strstr($sHost, '/') |
|
73 | - && strstr($_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'], $sHost))) { |
|
74 | - |
|
75 | - if (strstr($sHost, '/') |
|
76 | - && strstr($_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'], $sHost)) { |
|
77 | - |
|
78 | - $this->_sBaseUri = preg_replace('#^[^/]+#', '', $sHost); |
|
79 | - } |
|
80 | - |
|
81 | - if (isset($oHost->routes)) { |
|
82 | - |
|
83 | - foreach($oHost->routes as $sKey => $oRoute) { |
|
84 | - |
|
85 | - if ($sKey === $sCode) { |
|
86 | - |
|
87 | - $sRoute = $this->_sBaseUri.$oRoute->route; |
|
88 | - |
|
89 | - if (isset($oRoute->constraints)) { |
|
90 | - |
|
91 | - foreach ($oRoute->constraints as $sName => $sType) { |
|
92 | - |
|
93 | - if (!isset($aParams[$sName])) { $aParams[$sName] = ''; } |
|
94 | - |
|
95 | - if (preg_match('#'.$sType.'#', $aParams[$sName])) { |
|
96 | - |
|
97 | - if ($aParams[$sName]) { $sRoute = str_replace('[/:'.$sName.']', '/'.$aParams[$sName], $sRoute); } else { $sRoute = str_replace('[/:'.$sName.']', '', $sRoute); } |
|
98 | - $sRoute = str_replace('[:'.$sName.']', $aParams[$sName], $sRoute); |
|
99 | - continue; |
|
100 | - } else if (isset($oRoute->defaults_constraints) |
|
101 | - && isset($oRoute->defaults_constraints->{$sName}) |
|
102 | - && preg_match('#'.$sType.'#', $oRoute->defaults_constraints->{$sName})) { |
|
103 | - |
|
104 | - continue; |
|
105 | - } |
|
106 | - |
|
107 | - throw new \Exception('For the route '.$sCode.' the parameter '.$sName.' is not good!'); |
|
108 | - } |
|
109 | - } |
|
110 | - |
|
111 | - return $sRoute; |
|
112 | - } |
|
113 | - } |
|
114 | - } |
|
115 | - } |
|
116 | - } |
|
117 | - } |
|
118 | - } |
|
119 | - |
|
120 | - /** |
|
121 | - * encode text for the url |
|
122 | - * |
|
123 | - * @access public |
|
124 | - * @param string $sStringToEncode text |
|
125 | - * @return string |
|
126 | - */ |
|
127 | - public function encodeToUrl(string $sStringToEncode) : string |
|
128 | - { |
|
129 | - if (!is_string($sStringToEncode)) { |
|
130 | - |
|
131 | - throw new \Exception(); |
|
132 | - } |
|
133 | - |
|
134 | - $sStringToEncode = str_replace(['à','á','â','ã','ä','ç','è','é','ê','ë','ì','í','î','ï','ñ','ò','ó','ô','õ','ö','ù','ú','û','ü','ý','ÿ','À','Á','Â','Ã','Ä','Ç','È','É','Ê','Ë','Ì','Í','Î','Ï','Ñ','Ò','Ó','Ô','Õ','Ö','Ù','Ú','Û','Ü','Ý'], |
|
135 | - ['a','a','a','a','a','c','e','e','e','e','i','i','i','i','n','o','o','o','o','o','u','u','u','u','y','y','A','A','A','A','A','C','E','E','E','E','I','I','I','I','N','O','O','O','O','O','U','U','U','U','Y'], |
|
136 | - $sStringToEncode); |
|
137 | - |
|
138 | - $sStringToEncode = preg_replace('/[^a-zA-Z0-9_]+/', '_', preg_quote($sStringToEncode)); |
|
139 | - return strtolower($sStringToEncode); |
|
140 | - } |
|
33 | + /** |
|
34 | + * The base Uri to construct the route |
|
35 | + * @var string |
|
36 | + */ |
|
37 | + private $_sBaseUri = ''; |
|
38 | + |
|
39 | + /** |
|
40 | + * create an URL |
|
41 | + * |
|
42 | + * @access public |
|
43 | + * @param string $sCode code of the url between "routes" and "route" in Route.conf |
|
44 | + * @param array $aParams parameters to create the url |
|
45 | + * @return string |
|
46 | + * |
|
47 | + * @tutorial If I have this route I could make my URL: |
|
48 | + * |
|
49 | + * "menu_edit": { |
|
50 | + * "route": "[/:language]/menu[/:id]/edit/", |
|
51 | + * "controller": "\\src\\BackOffice\\Controller\\MenuManager", |
|
52 | + * "action": "edit", |
|
53 | + * "constraints": { |
|
54 | + * "language": "[a-z]{0,2}", |
|
55 | + * "id": "[0-9]+" |
|
56 | + * }, |
|
57 | + * "content_type": "html" |
|
58 | + * }, |
|
59 | + * |
|
60 | + * I must write this: |
|
61 | + * |
|
62 | + * $oUrlManager = new \Venus\core\UrlManager; |
|
63 | + * $sUrl = $oUrlManager->getUrl('menu_edit', array('language' => 'vn', 'id' => 125)); |
|
64 | + */ |
|
65 | + public function getUrl(string $sCode, array $aParams = array()) : string |
|
66 | + { |
|
67 | + if (isset($_SERVER) && isset($_SERVER['HTTP_HOST'])) { |
|
68 | + |
|
69 | + foreach (Config::get('Route') as $sHost => $oHost) { |
|
70 | + |
|
71 | + if ((!strstr($sHost, '/') && $sHost == $_SERVER['HTTP_HOST']) |
|
72 | + || (strstr($sHost, '/') |
|
73 | + && strstr($_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'], $sHost))) { |
|
74 | + |
|
75 | + if (strstr($sHost, '/') |
|
76 | + && strstr($_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'], $sHost)) { |
|
77 | + |
|
78 | + $this->_sBaseUri = preg_replace('#^[^/]+#', '', $sHost); |
|
79 | + } |
|
80 | + |
|
81 | + if (isset($oHost->routes)) { |
|
82 | + |
|
83 | + foreach($oHost->routes as $sKey => $oRoute) { |
|
84 | + |
|
85 | + if ($sKey === $sCode) { |
|
86 | + |
|
87 | + $sRoute = $this->_sBaseUri.$oRoute->route; |
|
88 | + |
|
89 | + if (isset($oRoute->constraints)) { |
|
90 | + |
|
91 | + foreach ($oRoute->constraints as $sName => $sType) { |
|
92 | + |
|
93 | + if (!isset($aParams[$sName])) { $aParams[$sName] = ''; } |
|
94 | + |
|
95 | + if (preg_match('#'.$sType.'#', $aParams[$sName])) { |
|
96 | + |
|
97 | + if ($aParams[$sName]) { $sRoute = str_replace('[/:'.$sName.']', '/'.$aParams[$sName], $sRoute); } else { $sRoute = str_replace('[/:'.$sName.']', '', $sRoute); } |
|
98 | + $sRoute = str_replace('[:'.$sName.']', $aParams[$sName], $sRoute); |
|
99 | + continue; |
|
100 | + } else if (isset($oRoute->defaults_constraints) |
|
101 | + && isset($oRoute->defaults_constraints->{$sName}) |
|
102 | + && preg_match('#'.$sType.'#', $oRoute->defaults_constraints->{$sName})) { |
|
103 | + |
|
104 | + continue; |
|
105 | + } |
|
106 | + |
|
107 | + throw new \Exception('For the route '.$sCode.' the parameter '.$sName.' is not good!'); |
|
108 | + } |
|
109 | + } |
|
110 | + |
|
111 | + return $sRoute; |
|
112 | + } |
|
113 | + } |
|
114 | + } |
|
115 | + } |
|
116 | + } |
|
117 | + } |
|
118 | + } |
|
119 | + |
|
120 | + /** |
|
121 | + * encode text for the url |
|
122 | + * |
|
123 | + * @access public |
|
124 | + * @param string $sStringToEncode text |
|
125 | + * @return string |
|
126 | + */ |
|
127 | + public function encodeToUrl(string $sStringToEncode) : string |
|
128 | + { |
|
129 | + if (!is_string($sStringToEncode)) { |
|
130 | + |
|
131 | + throw new \Exception(); |
|
132 | + } |
|
133 | + |
|
134 | + $sStringToEncode = str_replace(['à','á','â','ã','ä','ç','è','é','ê','ë','ì','í','î','ï','ñ','ò','ó','ô','õ','ö','ù','ú','û','ü','ý','ÿ','À','Á','Â','Ã','Ä','Ç','È','É','Ê','Ë','Ì','Í','Î','Ï','Ñ','Ò','Ó','Ô','Õ','Ö','Ù','Ú','Û','Ü','Ý'], |
|
135 | + ['a','a','a','a','a','c','e','e','e','e','i','i','i','i','n','o','o','o','o','o','u','u','u','u','y','y','A','A','A','A','A','C','E','E','E','E','I','I','I','I','N','O','O','O','O','O','U','U','U','U','Y'], |
|
136 | + $sStringToEncode); |
|
137 | + |
|
138 | + $sStringToEncode = preg_replace('/[^a-zA-Z0-9_]+/', '_', preg_quote($sStringToEncode)); |
|
139 | + return strtolower($sStringToEncode); |
|
140 | + } |
|
141 | 141 | } |