Completed
Branch master (07b0df)
by judicael
05:36 queued 02:38
created
bundles/lib/Form/Container.php 1 patch
Indentation   +203 added lines, -203 removed lines patch added patch discarded remove patch
@@ -33,207 +33,207 @@
 block discarded – undo
33 33
  */
34 34
 class Container
35 35
 {
36
-    /**
37
-     * complete view
38
-     *
39
-     * @access private
40
-     * @var    string
41
-     */
42
-    private $_sView = null;
43
-
44
-    /**
45
-     * form library with its entity
46
-     *
47
-     * @access private
48
-     * @var    Form
49
-     */
50
-    private $_oForm = null;
51
-
52
-    /**
53
-     * Block the save in the entity if you don't call handleRequest
54
-     *
55
-     * @access private
56
-     * @var    bool
57
-     */
58
-    private $_bHandleRequestActivate = false;
59
-
60
-    /**
61
-     * Request of the formular
62
-     *
63
-     * @access private
64
-     * @var    array
65
-     */
66
-    private $_aRequest = null;
67
-
68
-    /**
69
-     * get the Value
70
-     *
71
-     * @access public
72
-     * @return \stdClass
73
-     */
74
-    public function createView() : \stdClass
75
-    {
76
-        $oView = new \stdClass;
77
-        $oView->form = $this->_sView;
78
-        $oView->form_start = $this->_oForm->getFormInObject()->start;
79
-        $oView->form_end = $this->_oForm->getFormInObject()->end;
80
-        $oView->form_row = array();
81
-
82
-        foreach ($this->_oForm->getFormInObject()->form as $sKey => $mValue) {
83
-
84
-            if ($mValue instanceof Container) {
85
-
86
-                $oNewForm = $mValue->createView();
87
-                $oView->form_row[$sKey] = $oNewForm->form_row;
88
-            } else {
89
-
90
-               $oView->form_row[$sKey] = $mValue;
91
-            }
92
-        }
93
-
94
-        return $oView;
95
-    }
96
-
97
-    /**
98
-     * set the Value
99
-     *
100
-     * @access public
101
-     * @param  string $sView Display of form;
102
-     * @return \Venus\lib\Form\Container
103
-     */
104
-    public function setView(string $sView) : Container
105
-    {
106
-        $this->_sView = $sView;
107
-        return $this;
108
-    }
109
-
110
-    /**
111
-     * handle the request to do many actions on it
112
-     *
113
-     * @access public
114
-     * @param  array $aRequest request like $_POST
115
-     * @return bool
116
-     */
117
-    public function handleRequest(array $aRequest) : bool
118
-    {
119
-        if (!count($_POST)) { return true; }
120
-
121
-        // Validation
122
-        foreach ($this->_oForm->getElement() as $sKey => $sValue) {
123
-
124
-            if (!$sValue instanceof self && !$this->_validate($sValue)) {
125
-
126
-                return false;
127
-            }
128
-        }
129
-
130
-        // Save
131
-        if ($this->_oForm->getIdEntity() > 0 && $this->_oForm->getSynchronizeEntity() !== null && count($aRequest) > 0) {
132
-
133
-            $sModelName = str_replace('Entity', 'Model', $this->_oForm->getSynchronizeEntity());
134
-            $oModel = new $sModelName;
135
-
136
-            $oEntity = new $this->_oForm->getSynchronizeEntity();
137
-            $sPrimaryKey = LibEntity::getPrimaryKeyNameWithoutMapping($oEntity);
138
-            $sMethodName = 'set_'.$sPrimaryKey;
139
-
140
-            call_user_func_array(array(&$oEntity, $sMethodName), array($this->_oForm->getIdEntity()));
141
-
142
-            foreach ($this->_oForm->getElement() as $sKey => $sValue) {
143
-
144
-                $sMethodName = 'set_'.$sValue->getName().'';
145
-                call_user_func_array(array(&$oEntity, $sMethodName), array($aRequest[$sValue->getName()]));
146
-            }
147
-
148
-            $oEntity->save();
149
-        } else if ($this->_oForm->getSynchronizeEntity() !== null && isset($aRequest) && count($aRequest) > 0) {
150
-
151
-            $oEntity = new $this->_oForm->_sSynchronizeEntity;
152
-
153
-            foreach ($this->_oForm->getElement() as $sKey => $sValue) {
154
-
155
-                $sMethodName = 'set_'.$sValue->getName().'';
156
-                call_user_func_array(array(&$oEntity, $sMethodName), array($aRequest[$sValue->getName()]));
157
-            }
158
-
159
-            $this->_oForm->setIdEntityCreated($oEntity->save());
160
-        }
161
-
162
-        $this->_bHandleRequestActivate = true;
163
-        $this->_aRequest = $aRequest;
164
-        return true;
165
-    }
166
-
167
-    /**
168
-     * set Form lib with its entity
169
-     *
170
-     * @access public
171
-     * @param  Form $oForm request like $_POST
172
-     * @return \Venus\lib\Form\Container
173
-     */
174
-    public function setForm(Form $oForm) : Container
175
-    {
176
-        $this->_oForm = $oForm;
177
-        return $this;
178
-    }
179
-
180
-    /**
181
-     * if this form is validate and save
182
-     *
183
-     * @access public
184
-     * @return boolean
185
-     */
186
-    public function isValid() : bool
187
-    {
188
-        if ($this->_bHandleRequestActivate === true) { return true; } else { return false; }
189
-    }
190
-
191
-    /**
192
-     * if this form is validate and save
193
-     *
194
-     * @access public
195
-     * @return boolean
196
-     */
197
-    public function isSubmitted() : bool
198
-    {
199
-        if (isset($_POST['validform'.$this->_oForm->getFormNumber()]) && $_POST['validform'.$this->_oForm->getFormNumber()] == 1) {
200
-
201
-            return true;
202
-        } else {
203
-
204
-            return false;
205
-        }
206
-    }
207
-
208
-    /**
209
-     * if this form is validate and save
210
-     *
211
-     * @access public
212
-     * @param  string $sElementName element name what we want test the click
213
-     * @return boolean
214
-     */
215
-    public function isClicked(string $sElementName) : bool
216
-    {
217
-        if (isset($_POST[$sElementName]) && $_POST[$sElementName]) { return true; } else { return false; }
218
-    }
219
-
220
-    /**
221
-     * if the element is valide or not (with the constraint)
222
-     *
223
-     * @access private
224
-     * @param  object $oElement element of formular
225
-     * @return boolean
226
-     */
227
-    private function _validate($oElement) : bool
228
-    {
229
-        foreach ($oElement->getConstraint() as $oConstraint) {
230
-
231
-            if (!$oConstraint->validate($_POST[$oElement->getName()])) {
232
-
233
-                return false;
234
-            }
235
-        }
236
-
237
-        return true;
238
-    }
36
+	/**
37
+	 * complete view
38
+	 *
39
+	 * @access private
40
+	 * @var    string
41
+	 */
42
+	private $_sView = null;
43
+
44
+	/**
45
+	 * form library with its entity
46
+	 *
47
+	 * @access private
48
+	 * @var    Form
49
+	 */
50
+	private $_oForm = null;
51
+
52
+	/**
53
+	 * Block the save in the entity if you don't call handleRequest
54
+	 *
55
+	 * @access private
56
+	 * @var    bool
57
+	 */
58
+	private $_bHandleRequestActivate = false;
59
+
60
+	/**
61
+	 * Request of the formular
62
+	 *
63
+	 * @access private
64
+	 * @var    array
65
+	 */
66
+	private $_aRequest = null;
67
+
68
+	/**
69
+	 * get the Value
70
+	 *
71
+	 * @access public
72
+	 * @return \stdClass
73
+	 */
74
+	public function createView() : \stdClass
75
+	{
76
+		$oView = new \stdClass;
77
+		$oView->form = $this->_sView;
78
+		$oView->form_start = $this->_oForm->getFormInObject()->start;
79
+		$oView->form_end = $this->_oForm->getFormInObject()->end;
80
+		$oView->form_row = array();
81
+
82
+		foreach ($this->_oForm->getFormInObject()->form as $sKey => $mValue) {
83
+
84
+			if ($mValue instanceof Container) {
85
+
86
+				$oNewForm = $mValue->createView();
87
+				$oView->form_row[$sKey] = $oNewForm->form_row;
88
+			} else {
89
+
90
+			   $oView->form_row[$sKey] = $mValue;
91
+			}
92
+		}
93
+
94
+		return $oView;
95
+	}
96
+
97
+	/**
98
+	 * set the Value
99
+	 *
100
+	 * @access public
101
+	 * @param  string $sView Display of form;
102
+	 * @return \Venus\lib\Form\Container
103
+	 */
104
+	public function setView(string $sView) : Container
105
+	{
106
+		$this->_sView = $sView;
107
+		return $this;
108
+	}
109
+
110
+	/**
111
+	 * handle the request to do many actions on it
112
+	 *
113
+	 * @access public
114
+	 * @param  array $aRequest request like $_POST
115
+	 * @return bool
116
+	 */
117
+	public function handleRequest(array $aRequest) : bool
118
+	{
119
+		if (!count($_POST)) { return true; }
120
+
121
+		// Validation
122
+		foreach ($this->_oForm->getElement() as $sKey => $sValue) {
123
+
124
+			if (!$sValue instanceof self && !$this->_validate($sValue)) {
125
+
126
+				return false;
127
+			}
128
+		}
129
+
130
+		// Save
131
+		if ($this->_oForm->getIdEntity() > 0 && $this->_oForm->getSynchronizeEntity() !== null && count($aRequest) > 0) {
132
+
133
+			$sModelName = str_replace('Entity', 'Model', $this->_oForm->getSynchronizeEntity());
134
+			$oModel = new $sModelName;
135
+
136
+			$oEntity = new $this->_oForm->getSynchronizeEntity();
137
+			$sPrimaryKey = LibEntity::getPrimaryKeyNameWithoutMapping($oEntity);
138
+			$sMethodName = 'set_'.$sPrimaryKey;
139
+
140
+			call_user_func_array(array(&$oEntity, $sMethodName), array($this->_oForm->getIdEntity()));
141
+
142
+			foreach ($this->_oForm->getElement() as $sKey => $sValue) {
143
+
144
+				$sMethodName = 'set_'.$sValue->getName().'';
145
+				call_user_func_array(array(&$oEntity, $sMethodName), array($aRequest[$sValue->getName()]));
146
+			}
147
+
148
+			$oEntity->save();
149
+		} else if ($this->_oForm->getSynchronizeEntity() !== null && isset($aRequest) && count($aRequest) > 0) {
150
+
151
+			$oEntity = new $this->_oForm->_sSynchronizeEntity;
152
+
153
+			foreach ($this->_oForm->getElement() as $sKey => $sValue) {
154
+
155
+				$sMethodName = 'set_'.$sValue->getName().'';
156
+				call_user_func_array(array(&$oEntity, $sMethodName), array($aRequest[$sValue->getName()]));
157
+			}
158
+
159
+			$this->_oForm->setIdEntityCreated($oEntity->save());
160
+		}
161
+
162
+		$this->_bHandleRequestActivate = true;
163
+		$this->_aRequest = $aRequest;
164
+		return true;
165
+	}
166
+
167
+	/**
168
+	 * set Form lib with its entity
169
+	 *
170
+	 * @access public
171
+	 * @param  Form $oForm request like $_POST
172
+	 * @return \Venus\lib\Form\Container
173
+	 */
174
+	public function setForm(Form $oForm) : Container
175
+	{
176
+		$this->_oForm = $oForm;
177
+		return $this;
178
+	}
179
+
180
+	/**
181
+	 * if this form is validate and save
182
+	 *
183
+	 * @access public
184
+	 * @return boolean
185
+	 */
186
+	public function isValid() : bool
187
+	{
188
+		if ($this->_bHandleRequestActivate === true) { return true; } else { return false; }
189
+	}
190
+
191
+	/**
192
+	 * if this form is validate and save
193
+	 *
194
+	 * @access public
195
+	 * @return boolean
196
+	 */
197
+	public function isSubmitted() : bool
198
+	{
199
+		if (isset($_POST['validform'.$this->_oForm->getFormNumber()]) && $_POST['validform'.$this->_oForm->getFormNumber()] == 1) {
200
+
201
+			return true;
202
+		} else {
203
+
204
+			return false;
205
+		}
206
+	}
207
+
208
+	/**
209
+	 * if this form is validate and save
210
+	 *
211
+	 * @access public
212
+	 * @param  string $sElementName element name what we want test the click
213
+	 * @return boolean
214
+	 */
215
+	public function isClicked(string $sElementName) : bool
216
+	{
217
+		if (isset($_POST[$sElementName]) && $_POST[$sElementName]) { return true; } else { return false; }
218
+	}
219
+
220
+	/**
221
+	 * if the element is valide or not (with the constraint)
222
+	 *
223
+	 * @access private
224
+	 * @param  object $oElement element of formular
225
+	 * @return boolean
226
+	 */
227
+	private function _validate($oElement) : bool
228
+	{
229
+		foreach ($oElement->getConstraint() as $oConstraint) {
230
+
231
+			if (!$oConstraint->validate($_POST[$oElement->getName()])) {
232
+
233
+				return false;
234
+			}
235
+		}
236
+
237
+		return true;
238
+	}
239 239
 }
Please login to merge, or discard this patch.
bundles/lib/Date.php 3 patches
Indentation   +197 added lines, -197 removed lines patch added patch discarded remove patch
@@ -30,201 +30,201 @@
 block discarded – undo
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 unknown $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
-     * @return \Venus\lib\Date
156
-     */
157
-    public static function getMiddleWeek(int $iWeek, int $iYear, string $sFormat = "Y-m-d") : array
158
-    {
159
-        $iFirstDayInYear = date("N",mktime(0, 0, 0, 1, 1, $iYear));
160
-
161
-        if ($iFirstDayInYear < 5) { $iShift = -($iFirstDayInYear - 1) * 86400; }
162
-        else { $iShift = (8 - $iFirstDayInYear) * 86400; }
163
-
164
-        if ($iWeek > 1) { $iWeekInSeconds = ($iWeek-1) * 604800; }
165
-        else { $iWeekInSeconds = 0; }
166
-
167
-        if (date('N') > 2) {
168
-
169
-            $iTimestamp = mktime(0, 0, 0, 1, 1, $iYear) + $iWeekInSeconds + $iShift + 172800;
170
-            $iTimestampLastDay = $iTimestamp + 604800;
171
-        }
172
-        else {
173
-
174
-            $iTimestamp = mktime(0, 0, 0, 1, 1, $iYear) + $iWeekInSeconds + $iShift - 432000;
175
-            $iTimestampLastDay = $iTimestamp + 604800;
176
-        }
177
-
178
-        $aDates = array(date($sFormat, $iTimestamp), date($sFormat, $iTimestampLastDay));
179
-
180
-        if (preg_replace('/^([0-9]+)-[0-9]+-[0-9]+$/', '$1', $aDates[0]) != date('Y')) {
181
-
182
-            $aDates[0] = preg_replace('/^[0-9]+(-[0-9]+-[0-9]+)$/', date('Y').'$1', $aDates[0]);
183
-            $aDates[1] = preg_replace('/^[0-9]+(-[0-9]+-[0-9]+)$/', (date('Y')+1).'$1', $aDates[1]);
184
-        }
185
-
186
-        return $aDates;
187
-    }
188
-
189
-    /**
190
-     * set name of image
191
-     *
192
-     * @access public
193
-     * @return array
194
-     */
195
-    public static function getActualMiddleWeek() : array
196
-    {
197
-        return self::getMiddleWeek(date('W'), date('Y'));
198
-    }
199
-
200
-    /**
201
-     * get time of kind "X hour ago"
202
-     *
203
-     * @access public
204
-     * @param  string $sDateTime datetime to convert
205
-     * @param  string $sLanguage language
206
-     * @return string
207
-     */
208
-    public static function getTimeAgoInString(string $sDateTime, string $sLanguage = 'fr') : string
209
-    {
210
-        if ($sLanguage == 'fr') {
211
-
212
-            $sStartReturn = 'Il y a';
213
-            $sEndReturn = '';
214
-            $sMinutes = 'minute(s) ';
215
-            $sHours = 'heure(s) ';
216
-            $sDays = 'jour(s) ';
217
-            $sMonths = 'mois ';
218
-            $sYears = 'mois ';
219
-        }
220
-
221
-        $oDateTime = DateTime::createFromFormat('Y-m-d H:i:s', $sDateTime);
222
-        $iTimeStamp = time() - $oDateTime->getTimestamp();
223
-
224
-        if ($iTimeStamp < 3600) { return $sStartReturn.' '.(int)($iTimeStamp/60).' '.$sMinutes.$sEndReturn; }
225
-        if ($iTimeStamp < 86400) { return $sStartReturn.' '.(int)($iTimeStamp/3600).' '.$sHours.$sEndReturn; }
226
-        if ($iTimeStamp < 2592000) { return $sStartReturn.' '.(int)($iTimeStamp/86400).' '.$sDays.$sEndReturn; }
227
-        if ($iTimeStamp < 31536000) { return $sStartReturn.' '.(int)($iTimeStamp/2592000).' '.$sMonths.$sEndReturn; }
228
-        else { return $sStartReturn.' '.(int)($iTimeStamp/31536000).' '.$sYears.$sEndReturn; }
229
-    }
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 unknown $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
+	 * @return \Venus\lib\Date
156
+	 */
157
+	public static function getMiddleWeek(int $iWeek, int $iYear, string $sFormat = "Y-m-d") : array
158
+	{
159
+		$iFirstDayInYear = date("N",mktime(0, 0, 0, 1, 1, $iYear));
160
+
161
+		if ($iFirstDayInYear < 5) { $iShift = -($iFirstDayInYear - 1) * 86400; }
162
+		else { $iShift = (8 - $iFirstDayInYear) * 86400; }
163
+
164
+		if ($iWeek > 1) { $iWeekInSeconds = ($iWeek-1) * 604800; }
165
+		else { $iWeekInSeconds = 0; }
166
+
167
+		if (date('N') > 2) {
168
+
169
+			$iTimestamp = mktime(0, 0, 0, 1, 1, $iYear) + $iWeekInSeconds + $iShift + 172800;
170
+			$iTimestampLastDay = $iTimestamp + 604800;
171
+		}
172
+		else {
173
+
174
+			$iTimestamp = mktime(0, 0, 0, 1, 1, $iYear) + $iWeekInSeconds + $iShift - 432000;
175
+			$iTimestampLastDay = $iTimestamp + 604800;
176
+		}
177
+
178
+		$aDates = array(date($sFormat, $iTimestamp), date($sFormat, $iTimestampLastDay));
179
+
180
+		if (preg_replace('/^([0-9]+)-[0-9]+-[0-9]+$/', '$1', $aDates[0]) != date('Y')) {
181
+
182
+			$aDates[0] = preg_replace('/^[0-9]+(-[0-9]+-[0-9]+)$/', date('Y').'$1', $aDates[0]);
183
+			$aDates[1] = preg_replace('/^[0-9]+(-[0-9]+-[0-9]+)$/', (date('Y')+1).'$1', $aDates[1]);
184
+		}
185
+
186
+		return $aDates;
187
+	}
188
+
189
+	/**
190
+	 * set name of image
191
+	 *
192
+	 * @access public
193
+	 * @return array
194
+	 */
195
+	public static function getActualMiddleWeek() : array
196
+	{
197
+		return self::getMiddleWeek(date('W'), date('Y'));
198
+	}
199
+
200
+	/**
201
+	 * get time of kind "X hour ago"
202
+	 *
203
+	 * @access public
204
+	 * @param  string $sDateTime datetime to convert
205
+	 * @param  string $sLanguage language
206
+	 * @return string
207
+	 */
208
+	public static function getTimeAgoInString(string $sDateTime, string $sLanguage = 'fr') : string
209
+	{
210
+		if ($sLanguage == 'fr') {
211
+
212
+			$sStartReturn = 'Il y a';
213
+			$sEndReturn = '';
214
+			$sMinutes = 'minute(s) ';
215
+			$sHours = 'heure(s) ';
216
+			$sDays = 'jour(s) ';
217
+			$sMonths = 'mois ';
218
+			$sYears = 'mois ';
219
+		}
220
+
221
+		$oDateTime = DateTime::createFromFormat('Y-m-d H:i:s', $sDateTime);
222
+		$iTimeStamp = time() - $oDateTime->getTimestamp();
223
+
224
+		if ($iTimeStamp < 3600) { return $sStartReturn.' '.(int)($iTimeStamp/60).' '.$sMinutes.$sEndReturn; }
225
+		if ($iTimeStamp < 86400) { return $sStartReturn.' '.(int)($iTimeStamp/3600).' '.$sHours.$sEndReturn; }
226
+		if ($iTimeStamp < 2592000) { return $sStartReturn.' '.(int)($iTimeStamp/86400).' '.$sDays.$sEndReturn; }
227
+		if ($iTimeStamp < 31536000) { return $sStartReturn.' '.(int)($iTimeStamp/2592000).' '.$sMonths.$sEndReturn; }
228
+		else { return $sStartReturn.' '.(int)($iTimeStamp/31536000).' '.$sYears.$sEndReturn; }
229
+	}
230 230
 }
Please login to merge, or discard this patch.
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -41,11 +41,11 @@  discard block
 block discarded – undo
41 41
      */
42 42
     public static function getWeek(int $iWeek, int $iYear, string $sFormat = "Y-m-d") : Date
43 43
     {
44
-        $iFirstDayInYear = date("N",mktime(0, 0, 0, 1, 1, $iYear));
44
+        $iFirstDayInYear = date("N", mktime(0, 0, 0, 1, 1, $iYear));
45 45
 
46 46
         if ($iFirstDayInYear < 5) { $iShift = -($iFirstDayInYear - 1) * 86400; } else { $iShift = (8 - $iFirstDayInYear) * 86400; }
47 47
 
48
-        if ($iWeek > 1) { $iWeekInSeconds = ($iWeek-1) * 604800; } else { $iWeekInSeconds = 0; }
48
+        if ($iWeek > 1) { $iWeekInSeconds = ($iWeek - 1) * 604800; } else { $iWeekInSeconds = 0; }
49 49
 
50 50
         $iTimestamp = mktime(0, 0, 0, 1, 1, $iYear) + $iWeekInSeconds + $iShift;
51 51
         $iTimestampLastDay = mktime(0, 0, 0, 1, 6, $iYear) + $iWeekInSeconds + $iShift + 604800;
@@ -156,12 +156,12 @@  discard block
 block discarded – undo
156 156
      */
157 157
     public static function getMiddleWeek(int $iWeek, int $iYear, string $sFormat = "Y-m-d") : array
158 158
     {
159
-        $iFirstDayInYear = date("N",mktime(0, 0, 0, 1, 1, $iYear));
159
+        $iFirstDayInYear = date("N", mktime(0, 0, 0, 1, 1, $iYear));
160 160
 
161 161
         if ($iFirstDayInYear < 5) { $iShift = -($iFirstDayInYear - 1) * 86400; }
162 162
         else { $iShift = (8 - $iFirstDayInYear) * 86400; }
163 163
 
164
-        if ($iWeek > 1) { $iWeekInSeconds = ($iWeek-1) * 604800; }
164
+        if ($iWeek > 1) { $iWeekInSeconds = ($iWeek - 1) * 604800; }
165 165
         else { $iWeekInSeconds = 0; }
166 166
 
167 167
         if (date('N') > 2) {
@@ -180,7 +180,7 @@  discard block
 block discarded – undo
180 180
         if (preg_replace('/^([0-9]+)-[0-9]+-[0-9]+$/', '$1', $aDates[0]) != date('Y')) {
181 181
 
182 182
             $aDates[0] = preg_replace('/^[0-9]+(-[0-9]+-[0-9]+)$/', date('Y').'$1', $aDates[0]);
183
-            $aDates[1] = preg_replace('/^[0-9]+(-[0-9]+-[0-9]+)$/', (date('Y')+1).'$1', $aDates[1]);
183
+            $aDates[1] = preg_replace('/^[0-9]+(-[0-9]+-[0-9]+)$/', (date('Y') + 1).'$1', $aDates[1]);
184 184
         }
185 185
 
186 186
         return $aDates;
@@ -221,10 +221,10 @@  discard block
 block discarded – undo
221 221
         $oDateTime = DateTime::createFromFormat('Y-m-d H:i:s', $sDateTime);
222 222
         $iTimeStamp = time() - $oDateTime->getTimestamp();
223 223
 
224
-        if ($iTimeStamp < 3600) { return $sStartReturn.' '.(int)($iTimeStamp/60).' '.$sMinutes.$sEndReturn; }
225
-        if ($iTimeStamp < 86400) { return $sStartReturn.' '.(int)($iTimeStamp/3600).' '.$sHours.$sEndReturn; }
226
-        if ($iTimeStamp < 2592000) { return $sStartReturn.' '.(int)($iTimeStamp/86400).' '.$sDays.$sEndReturn; }
227
-        if ($iTimeStamp < 31536000) { return $sStartReturn.' '.(int)($iTimeStamp/2592000).' '.$sMonths.$sEndReturn; }
228
-        else { return $sStartReturn.' '.(int)($iTimeStamp/31536000).' '.$sYears.$sEndReturn; }
224
+        if ($iTimeStamp < 3600) { return $sStartReturn.' '.(int)($iTimeStamp / 60).' '.$sMinutes.$sEndReturn; }
225
+        if ($iTimeStamp < 86400) { return $sStartReturn.' '.(int)($iTimeStamp / 3600).' '.$sHours.$sEndReturn; }
226
+        if ($iTimeStamp < 2592000) { return $sStartReturn.' '.(int)($iTimeStamp / 86400).' '.$sDays.$sEndReturn; }
227
+        if ($iTimeStamp < 31536000) { return $sStartReturn.' '.(int)($iTimeStamp / 2592000).' '.$sMonths.$sEndReturn; }
228
+        else { return $sStartReturn.' '.(int)($iTimeStamp / 31536000).' '.$sYears.$sEndReturn; }
229 229
     }
230 230
 }
Please login to merge, or discard this patch.
Braces   +7 added lines, -29 removed lines patch added patch discarded remove patch
@@ -76,18 +76,7 @@  discard block
 block discarded – undo
76 76
     {
77 77
         if ($sLanguage == 'fr') {
78 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'; }
79
+            if ($sMonth == '01' || $sMonth == 1) { return 'Janvier'; } else if ($sMonth == '02' || $sMonth == 2) { return 'Février'; } else if ($sMonth == '03' || $sMonth == 3) { return 'Mars'; } else if ($sMonth == '04' || $sMonth == 4) { return 'Avril'; } else if ($sMonth == '05' || $sMonth == 5) { return 'Mai'; } else if ($sMonth == '06' || $sMonth == 6) { return 'Juin'; } else if ($sMonth == '07' || $sMonth == 7) { return 'Juillet'; } else if ($sMonth == '08' || $sMonth == 8) { return 'Août'; } else if ($sMonth == '09' || $sMonth == 9) { return 'Septembre'; } else if ($sMonth == 10) { return 'Octobre'; } else if ($sMonth == 11) { return 'Novembre'; } else if ($sMonth == 12) { return 'Décembre'; }
91 80
         }
92 81
     }
93 82
 
@@ -103,13 +92,7 @@  discard block
 block discarded – undo
103 92
     {
104 93
         if ($sLanguage == 'fr') {
105 94
 
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'; }
95
+            if ($sDay == 0) { return 'dimanche'; } else if ($sDay == 1) { return 'lundi'; } else if ($sDay == 2) { return 'mardi'; } else if ($sDay == 3) { return 'mercredi'; } else if ($sDay == 4) { return 'jeudi'; } else if ($sDay == 5) { return 'vendredi'; } else if ($sDay == 6) { return 'samedi'; }
113 96
         }
114 97
     }
115 98
 
@@ -136,8 +119,7 @@  discard block
 block discarded – undo
136 119
             if ($iMonth == $aToday['mois']) {
137 120
 
138 121
                 if ($iDay > $aToday['jour']) { $iYears--; }
139
-            }
140
-            else {
122
+            } else {
141 123
 
142 124
                 $iYears--;
143 125
             }
@@ -158,18 +140,15 @@  discard block
 block discarded – undo
158 140
     {
159 141
         $iFirstDayInYear = date("N",mktime(0, 0, 0, 1, 1, $iYear));
160 142
 
161
-        if ($iFirstDayInYear < 5) { $iShift = -($iFirstDayInYear - 1) * 86400; }
162
-        else { $iShift = (8 - $iFirstDayInYear) * 86400; }
143
+        if ($iFirstDayInYear < 5) { $iShift = -($iFirstDayInYear - 1) * 86400; } else { $iShift = (8 - $iFirstDayInYear) * 86400; }
163 144
 
164
-        if ($iWeek > 1) { $iWeekInSeconds = ($iWeek-1) * 604800; }
165
-        else { $iWeekInSeconds = 0; }
145
+        if ($iWeek > 1) { $iWeekInSeconds = ($iWeek-1) * 604800; } else { $iWeekInSeconds = 0; }
166 146
 
167 147
         if (date('N') > 2) {
168 148
 
169 149
             $iTimestamp = mktime(0, 0, 0, 1, 1, $iYear) + $iWeekInSeconds + $iShift + 172800;
170 150
             $iTimestampLastDay = $iTimestamp + 604800;
171
-        }
172
-        else {
151
+        } else {
173 152
 
174 153
             $iTimestamp = mktime(0, 0, 0, 1, 1, $iYear) + $iWeekInSeconds + $iShift - 432000;
175 154
             $iTimestampLastDay = $iTimestamp + 604800;
@@ -224,7 +203,6 @@  discard block
 block discarded – undo
224 203
         if ($iTimeStamp < 3600) { return $sStartReturn.' '.(int)($iTimeStamp/60).' '.$sMinutes.$sEndReturn; }
225 204
         if ($iTimeStamp < 86400) { return $sStartReturn.' '.(int)($iTimeStamp/3600).' '.$sHours.$sEndReturn; }
226 205
         if ($iTimeStamp < 2592000) { return $sStartReturn.' '.(int)($iTimeStamp/86400).' '.$sDays.$sEndReturn; }
227
-        if ($iTimeStamp < 31536000) { return $sStartReturn.' '.(int)($iTimeStamp/2592000).' '.$sMonths.$sEndReturn; }
228
-        else { return $sStartReturn.' '.(int)($iTimeStamp/31536000).' '.$sYears.$sEndReturn; }
206
+        if ($iTimeStamp < 31536000) { return $sStartReturn.' '.(int)($iTimeStamp/2592000).' '.$sMonths.$sEndReturn; } else { return $sStartReturn.' '.(int)($iTimeStamp/31536000).' '.$sYears.$sEndReturn; }
229 207
     }
230 208
 }
Please login to merge, or discard this patch.
bundles/lib/Form.php 2 patches
Indentation   +401 added lines, -401 removed lines patch added patch discarded remove patch
@@ -60,406 +60,406 @@
 block discarded – undo
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
-        if ($this->_iIdEntity > 0 && $this->_sSynchronizeEntity !== null && count($_POST) < 1) {
303
-
304
-            $sModelName = str_replace('Entity', 'Model', $this->_sSynchronizeEntity);
305
-            $oModel = new $sModelName;
306
-
307
-            $oEntity = new $this->_sSynchronizeEntity;
308
-            $sPrimaryKey = LibEntity::getPrimaryKeyNameWithoutMapping($oEntity);
309
-            $sMethodName = 'findOneBy'.$sPrimaryKey;
310
-            $oCompleteEntity = call_user_func_array(array(&$oModel, $sMethodName), array($this->_iIdEntity));
311
-
312
-            if (is_object($oCompleteEntity)) {
313
-
314
-                foreach ($this->_aElement as $sKey => $sValue) {
315
-
316
-                    if ($sValue instanceof \Venus\lib\Form\Radio) {
317
-
318
-                        $sExKey = $sKey;
319
-                        $sKey = substr($sKey, 0, -6);
320
-                    }
321
-
322
-                    if ($sValue instanceof Form) {
323
-
324
-                        ;
325
-                    } else {
326
-
327
-                        $sMethodNameInEntity = 'get_'.$sKey;
328
-                        $mValue = $oCompleteEntity->$sMethodNameInEntity();
329
-
330
-                        if ($sValue instanceof \Venus\lib\Form\Radio && method_exists($this->_aElement[$sExKey], 'setValueChecked')) {
331
-
332
-                            $this->_aElement[$sExKey]->setValueChecked($mValue);
333
-                        } else if (isset($mValue) && method_exists($this->_aElement[$sKey], 'setValue')) {
334
-
335
-                            $this->_aElement[$sKey]->setValue($mValue);
336
-                        }
337
-                    }
338
-                }
339
-            }
340
-        }
341
-
342
-        $oForm = new \StdClass();
343
-        $oForm->start = '<form name="form'.$this->_iFormNumber.'" method="post"><input type="hidden" value="1" name="validform'.$this->_iFormNumber.'">';
344
-        $oForm->form = array();
345
-
346
-        foreach ($this->_aElement as $sKey => $sValue) {
347
-
348
-            if ($sValue instanceof Container) {
349
-
350
-                $oForm->form[$sKey] = $sValue;
351
-            } else {
352
-
353
-                $oForm->form[$sKey] = $sValue->fetch();
354
-            }
355
-        }
356
-
357
-        $oForm->end = '</form>';
358
-
359
-        return $oForm;
360
-    }
361
-
362
-    /**
363
-     * get an element of formular
364
-     *
365
-     * @access public
366
-     * @param  string $sName name
367
-     * @return object
368
-     */
369
-    public function get($sName)
370
-    {
371
-        return $this->_aElement[$sName];
372
-    }
373
-
374
-    /**
375
-     * get the form separator
376
-     *
377
-     * @access public
378
-     * @return string
379
-     */
380
-    public function getSeparator()
381
-    {
382
-        return $this->_sSeparator;
383
-    }
384
-
385
-    /**
386
-     * set the form separator
387
-     *
388
-     * @access public
389
-     * @param  string $sSeparator separator between the fields
390
-     * @return \Venus\lib\Form
391
-     */
392
-    public function setSeparator($sSeparator)
393
-    {
394
-        $this->_sSeparator = $sSeparator;
395
-        return $this;
396
-    }
397
-
398
-    /**
399
-     * set the entity to synchronize with the formular
400
-     *
401
-     * @access public
402
-     * @param $sSynchronizeEntity
403
-     * @param  int $iId id of the primary key
404
-     * @return Form
405
-     * @internal param string $sSeparator separator between the fields
406
-     */
407
-    public function synchronizeEntity($sSynchronizeEntity, $iId = null)
408
-    {
409
-        if ($iId !== null) { $this->_iIdEntity = $iId; }
410
-
411
-        $this->_sSynchronizeEntity = $sSynchronizeEntity;
412
-        return $this;
413
-    }
414
-
415
-    /**
416
-     * add constraint
417
-     *
418
-     * @access public
419
-     * @param  string $sName field name
420
-     * @param  object $oConstraint constraint on the field
421
-     * @return \Venus\lib\Form
422
-     */
423
-    public function addConstraint($sName, $oConstraint)
424
-    {
425
-        if ($this->_aElement[$sName] instanceof Input || $this->_aElement[$sName] instanceof Textarea) {
426
-
427
-            $this->_aElement[$sName]->setConstraint($oConstraint);
428
-        }
429
-
430
-        return $this;
431
-    }
432
-
433
-    /**
434
-     * get all elements
435
-     *
436
-     * @access public
437
-     * @return  array
438
-     */
439
-    public function getElement() {
440
-
441
-        return $this->_aElement;
442
-    }
443
-
444
-    /**
445
-     * get all elements
446
-     *
447
-     * @access public
448
-     * @return int
449
-     */
450
-    public function getIdEntity() {
451
-
452
-        return $this->_iIdEntity;
453
-    }
454
-
455
-    /**
456
-     * get all elements
457
-     *
458
-     * @access public
459
-     * @return string
460
-     */
461
-    public function getSynchronizeEntity() {
462
-
463
-        return $this->_sSynchronizeEntity;
464
-    }
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
+		if ($this->_iIdEntity > 0 && $this->_sSynchronizeEntity !== null && count($_POST) < 1) {
303
+
304
+			$sModelName = str_replace('Entity', 'Model', $this->_sSynchronizeEntity);
305
+			$oModel = new $sModelName;
306
+
307
+			$oEntity = new $this->_sSynchronizeEntity;
308
+			$sPrimaryKey = LibEntity::getPrimaryKeyNameWithoutMapping($oEntity);
309
+			$sMethodName = 'findOneBy'.$sPrimaryKey;
310
+			$oCompleteEntity = call_user_func_array(array(&$oModel, $sMethodName), array($this->_iIdEntity));
311
+
312
+			if (is_object($oCompleteEntity)) {
313
+
314
+				foreach ($this->_aElement as $sKey => $sValue) {
315
+
316
+					if ($sValue instanceof \Venus\lib\Form\Radio) {
317
+
318
+						$sExKey = $sKey;
319
+						$sKey = substr($sKey, 0, -6);
320
+					}
321
+
322
+					if ($sValue instanceof Form) {
323
+
324
+						;
325
+					} else {
326
+
327
+						$sMethodNameInEntity = 'get_'.$sKey;
328
+						$mValue = $oCompleteEntity->$sMethodNameInEntity();
329
+
330
+						if ($sValue instanceof \Venus\lib\Form\Radio && method_exists($this->_aElement[$sExKey], 'setValueChecked')) {
331
+
332
+							$this->_aElement[$sExKey]->setValueChecked($mValue);
333
+						} else if (isset($mValue) && method_exists($this->_aElement[$sKey], 'setValue')) {
334
+
335
+							$this->_aElement[$sKey]->setValue($mValue);
336
+						}
337
+					}
338
+				}
339
+			}
340
+		}
341
+
342
+		$oForm = new \StdClass();
343
+		$oForm->start = '<form name="form'.$this->_iFormNumber.'" method="post"><input type="hidden" value="1" name="validform'.$this->_iFormNumber.'">';
344
+		$oForm->form = array();
345
+
346
+		foreach ($this->_aElement as $sKey => $sValue) {
347
+
348
+			if ($sValue instanceof Container) {
349
+
350
+				$oForm->form[$sKey] = $sValue;
351
+			} else {
352
+
353
+				$oForm->form[$sKey] = $sValue->fetch();
354
+			}
355
+		}
356
+
357
+		$oForm->end = '</form>';
358
+
359
+		return $oForm;
360
+	}
361
+
362
+	/**
363
+	 * get an element of formular
364
+	 *
365
+	 * @access public
366
+	 * @param  string $sName name
367
+	 * @return object
368
+	 */
369
+	public function get($sName)
370
+	{
371
+		return $this->_aElement[$sName];
372
+	}
373
+
374
+	/**
375
+	 * get the form separator
376
+	 *
377
+	 * @access public
378
+	 * @return string
379
+	 */
380
+	public function getSeparator()
381
+	{
382
+		return $this->_sSeparator;
383
+	}
384
+
385
+	/**
386
+	 * set the form separator
387
+	 *
388
+	 * @access public
389
+	 * @param  string $sSeparator separator between the fields
390
+	 * @return \Venus\lib\Form
391
+	 */
392
+	public function setSeparator($sSeparator)
393
+	{
394
+		$this->_sSeparator = $sSeparator;
395
+		return $this;
396
+	}
397
+
398
+	/**
399
+	 * set the entity to synchronize with the formular
400
+	 *
401
+	 * @access public
402
+	 * @param $sSynchronizeEntity
403
+	 * @param  int $iId id of the primary key
404
+	 * @return Form
405
+	 * @internal param string $sSeparator separator between the fields
406
+	 */
407
+	public function synchronizeEntity($sSynchronizeEntity, $iId = null)
408
+	{
409
+		if ($iId !== null) { $this->_iIdEntity = $iId; }
410
+
411
+		$this->_sSynchronizeEntity = $sSynchronizeEntity;
412
+		return $this;
413
+	}
414
+
415
+	/**
416
+	 * add constraint
417
+	 *
418
+	 * @access public
419
+	 * @param  string $sName field name
420
+	 * @param  object $oConstraint constraint on the field
421
+	 * @return \Venus\lib\Form
422
+	 */
423
+	public function addConstraint($sName, $oConstraint)
424
+	{
425
+		if ($this->_aElement[$sName] instanceof Input || $this->_aElement[$sName] instanceof Textarea) {
426
+
427
+			$this->_aElement[$sName]->setConstraint($oConstraint);
428
+		}
429
+
430
+		return $this;
431
+	}
432
+
433
+	/**
434
+	 * get all elements
435
+	 *
436
+	 * @access public
437
+	 * @return  array
438
+	 */
439
+	public function getElement() {
440
+
441
+		return $this->_aElement;
442
+	}
443
+
444
+	/**
445
+	 * get all elements
446
+	 *
447
+	 * @access public
448
+	 * @return int
449
+	 */
450
+	public function getIdEntity() {
451
+
452
+		return $this->_iIdEntity;
453
+	}
454
+
455
+	/**
456
+	 * get all elements
457
+	 *
458
+	 * @access public
459
+	 * @return string
460
+	 */
461
+	public function getSynchronizeEntity() {
462
+
463
+		return $this->_sSynchronizeEntity;
464
+	}
465 465
 }
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -180,8 +180,7 @@
 block discarded – undo
180 180
 
181 181
             for ($i = 1; $i <= 31; $i++) {
182 182
 
183
-                if ($i < 10) { $aDay['0'.$i] = '0'.$i; }
184
-                else { $aDay[$i] = $i; }
183
+                if ($i < 10) { $aDay['0'.$i] = '0'.$i; } else { $aDay[$i] = $i; }
185 184
             }
186 185
 
187 186
             $this->_aElement[$sName.'_day'] = new Select($sName, $aDay);
Please login to merge, or discard this patch.
bundles/lib/Cache/Mock.php 1 patch
Indentation   +61 added lines, -61 removed lines patch added patch discarded remove patch
@@ -30,69 +30,69 @@
 block discarded – undo
30 30
  */
31 31
 class Mock implements CacheInterface
32 32
 {
33
-    /**
34
-     * get a value
35
-     *
36
-     * @access public
37
-     * @param  string $sName name of the session
38
-     * @param  int $iFlags flags
39
-     * @param  int $iTimeout expiration of cache
40
-     * @return boolean
41
-     */
42
-    public function get(string $sName, int&$iFlags = null, int $iTimeout = 0)
43
-    {
44
-        return false;
45
-    }
33
+	/**
34
+	 * get a value
35
+	 *
36
+	 * @access public
37
+	 * @param  string $sName name of the session
38
+	 * @param  int $iFlags flags
39
+	 * @param  int $iTimeout expiration of cache
40
+	 * @return boolean
41
+	 */
42
+	public function get(string $sName, int&$iFlags = null, int $iTimeout = 0)
43
+	{
44
+		return false;
45
+	}
46 46
 
47
-    /**
48
-     * set a value
49
-     *
50
-     * @access public
51
-     * @param  string $sName name of the session
52
-     * @param  mixed $mValue value of this sesion var
53
-     * @param  int $iFlag unused
54
-     * @param  int $iExpire expiration of cache
55
-     * @return boolean
56
-     */
57
-    public function set(string $sName, $mValue, int $iFlag = 0, int $iExpire = false)
58
-    {
59
-        return true;
60
-    }
47
+	/**
48
+	 * set a value
49
+	 *
50
+	 * @access public
51
+	 * @param  string $sName name of the session
52
+	 * @param  mixed $mValue value of this sesion var
53
+	 * @param  int $iFlag unused
54
+	 * @param  int $iExpire expiration of cache
55
+	 * @return boolean
56
+	 */
57
+	public function set(string $sName, $mValue, int $iFlag = 0, int $iExpire = false)
58
+	{
59
+		return true;
60
+	}
61 61
 
62
-    /**
63
-     * flush the cache
64
-     *
65
-     * @access public
66
-     * @return boolean
67
-     */
68
-    public function flush()
69
-    {
70
-        return false;
71
-    }
62
+	/**
63
+	 * flush the cache
64
+	 *
65
+	 * @access public
66
+	 * @return boolean
67
+	 */
68
+	public function flush()
69
+	{
70
+		return false;
71
+	}
72 72
 
73
-    /**
74
-     * delete a value
75
-     *
76
-     * @access public
77
-     * @param  string $sName name of the session
78
-     * @return boolean
79
-     */
80
-    public function delete(string $sName)
81
-    {
82
-        return false;
83
-    }
73
+	/**
74
+	 * delete a value
75
+	 *
76
+	 * @access public
77
+	 * @param  string $sName name of the session
78
+	 * @return boolean
79
+	 */
80
+	public function delete(string $sName)
81
+	{
82
+		return false;
83
+	}
84 84
 
85
-    /**
86
-     * add
87
-     *
88
-     * @access public
89
-     * @param  string $sName name of the session
90
-     * @param  mixed $mValue value of this sesion var
91
-     * @param  int $iExpire expiration of cache
92
-     * @return boolean
93
-     */
94
-    public function add($sName, $mValue, $iExpire = false)
95
-    {
96
-        return true;
97
-    }
85
+	/**
86
+	 * add
87
+	 *
88
+	 * @access public
89
+	 * @param  string $sName name of the session
90
+	 * @param  mixed $mValue value of this sesion var
91
+	 * @param  int $iExpire expiration of cache
92
+	 * @return boolean
93
+	 */
94
+	public function add($sName, $mValue, $iExpire = false)
95
+	{
96
+		return true;
97
+	}
98 98
 }
Please login to merge, or discard this patch.
bundles/core/UrlManager.php 2 patches
Indentation   +110 added lines, -110 removed lines patch added patch discarded remove patch
@@ -30,114 +30,114 @@
 block discarded – undo
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
-                        $aRoutes = array();
84
-
85
-                        foreach($oHost->routes as $sKey => $oRoute) {
86
-
87
-                            if ($sKey === $sCode) {
88
-
89
-                                $sRoute = $this->_sBaseUri.$oRoute->route;
90
-
91
-                                if (isset($oRoute->constraints)) {
92
-
93
-                                    foreach ($oRoute->constraints as $sName => $sType) {
94
-
95
-                                        if (!isset($aParams[$sName])) { $aParams[$sName] = ''; }
96
-
97
-                                        if (preg_match('#'.$sType.'#', $aParams[$sName])) {
98
-
99
-                                            if ($aParams[$sName]) { $sRoute = str_replace('[/:'.$sName.']', '/'.$aParams[$sName], $sRoute); } else { $sRoute = str_replace('[/:'.$sName.']', '', $sRoute); }
100
-                                            $sRoute = str_replace('[:'.$sName.']', $aParams[$sName], $sRoute);
101
-                                            continue;
102
-                                        } else if (isset($oRoute->defaults_constraints)
103
-                                            && isset($oRoute->defaults_constraints->{$sName})
104
-                                            && preg_match('#'.$sType.'#', $oRoute->defaults_constraints->{$sName})) {
105
-
106
-                                            continue;
107
-                                        }
108
-
109
-                                        throw new \Exception('For the route '.$sCode.' the parameter '.$sName.' is not good!');
110
-                                    }
111
-                                }
112
-
113
-                                return $sRoute;
114
-                            }
115
-                        }
116
-                    }
117
-                }
118
-            }
119
-        }
120
-    }
121
-
122
-    /**
123
-     * encode text for the url
124
-     *
125
-     * @access public
126
-     * @param  string $sStringToEncode text
127
-     * @return string
128
-     */
129
-    public function encodeToUrl(string $sStringToEncode) : string
130
-    {
131
-        if (!is_string($sStringToEncode)) {
132
-
133
-            throw new \Exception();
134
-        }
135
-
136
-        $sStringToEncode = str_replace(['à','á','â','ã','ä','ç','è','é','ê','ë','ì','í','î','ï','ñ','ò','ó','ô','õ','ö','ù','ú','û','ü','ý','ÿ','À','Á','Â','Ã','Ä','Ç','È','É','Ê','Ë','Ì','Í','Î','Ï','Ñ','Ò','Ó','Ô','Õ','Ö','Ù','Ú','Û','Ü','Ý'],
137
-            ['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'],
138
-                $sStringToEncode);
139
-
140
-        $sStringToEncode = preg_replace('/[^a-zA-Z0-9_]+/', '_', preg_quote($sStringToEncode));
141
-        return strtolower($sStringToEncode);
142
-    }
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
+						$aRoutes = array();
84
+
85
+						foreach($oHost->routes as $sKey => $oRoute) {
86
+
87
+							if ($sKey === $sCode) {
88
+
89
+								$sRoute = $this->_sBaseUri.$oRoute->route;
90
+
91
+								if (isset($oRoute->constraints)) {
92
+
93
+									foreach ($oRoute->constraints as $sName => $sType) {
94
+
95
+										if (!isset($aParams[$sName])) { $aParams[$sName] = ''; }
96
+
97
+										if (preg_match('#'.$sType.'#', $aParams[$sName])) {
98
+
99
+											if ($aParams[$sName]) { $sRoute = str_replace('[/:'.$sName.']', '/'.$aParams[$sName], $sRoute); } else { $sRoute = str_replace('[/:'.$sName.']', '', $sRoute); }
100
+											$sRoute = str_replace('[:'.$sName.']', $aParams[$sName], $sRoute);
101
+											continue;
102
+										} else if (isset($oRoute->defaults_constraints)
103
+											&& isset($oRoute->defaults_constraints->{$sName})
104
+											&& preg_match('#'.$sType.'#', $oRoute->defaults_constraints->{$sName})) {
105
+
106
+											continue;
107
+										}
108
+
109
+										throw new \Exception('For the route '.$sCode.' the parameter '.$sName.' is not good!');
110
+									}
111
+								}
112
+
113
+								return $sRoute;
114
+							}
115
+						}
116
+					}
117
+				}
118
+			}
119
+		}
120
+	}
121
+
122
+	/**
123
+	 * encode text for the url
124
+	 *
125
+	 * @access public
126
+	 * @param  string $sStringToEncode text
127
+	 * @return string
128
+	 */
129
+	public function encodeToUrl(string $sStringToEncode) : string
130
+	{
131
+		if (!is_string($sStringToEncode)) {
132
+
133
+			throw new \Exception();
134
+		}
135
+
136
+		$sStringToEncode = str_replace(['à','á','â','ã','ä','ç','è','é','ê','ë','ì','í','î','ï','ñ','ò','ó','ô','õ','ö','ù','ú','û','ü','ý','ÿ','À','Á','Â','Ã','Ä','Ç','È','É','Ê','Ë','Ì','Í','Î','Ï','Ñ','Ò','Ó','Ô','Õ','Ö','Ù','Ú','Û','Ü','Ý'],
137
+			['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'],
138
+				$sStringToEncode);
139
+
140
+		$sStringToEncode = preg_replace('/[^a-zA-Z0-9_]+/', '_', preg_quote($sStringToEncode));
141
+		return strtolower($sStringToEncode);
142
+	}
143 143
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -82,7 +82,7 @@  discard block
 block discarded – undo
82 82
 
83 83
                         $aRoutes = array();
84 84
 
85
-                        foreach($oHost->routes as $sKey => $oRoute) {
85
+                        foreach ($oHost->routes as $sKey => $oRoute) {
86 86
 
87 87
                             if ($sKey === $sCode) {
88 88
 
@@ -133,8 +133,8 @@  discard block
 block discarded – undo
133 133
             throw new \Exception();
134 134
         }
135 135
 
136
-        $sStringToEncode = str_replace(['à','á','â','ã','ä','ç','è','é','ê','ë','ì','í','î','ï','ñ','ò','ó','ô','õ','ö','ù','ú','û','ü','ý','ÿ','À','Á','Â','Ã','Ä','Ç','È','É','Ê','Ë','Ì','Í','Î','Ï','Ñ','Ò','Ó','Ô','Õ','Ö','Ù','Ú','Û','Ü','Ý'],
137
-            ['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 = str_replace(['à', 'á', 'â', 'ã', 'ä', 'ç', 'è', 'é', 'ê', 'ë', 'ì', 'í', 'î', 'ï', 'ñ', 'ò', 'ó', 'ô', 'õ', 'ö', 'ù', 'ú', 'û', 'ü', 'ý', 'ÿ', 'À', 'Á', 'Â', 'Ã', 'Ä', 'Ç', 'È', 'É', 'Ê', 'Ë', 'Ì', 'Í', 'Î', 'Ï', 'Ñ', 'Ò', 'Ó', 'Ô', 'Õ', 'Ö', 'Ù', 'Ú', 'Û', 'Ü', 'Ý'],
137
+            ['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'],
138 138
                 $sStringToEncode);
139 139
 
140 140
         $sStringToEncode = preg_replace('/[^a-zA-Z0-9_]+/', '_', preg_quote($sStringToEncode));
Please login to merge, or discard this patch.