Passed
Branch 1.0.0-dev (958860)
by nguereza
06:24
created
core/libraries/Pagination.php 1 patch
Indentation   +133 added lines, -133 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-    defined('ROOT_PATH') || exit('Access denied');
2
+	defined('ROOT_PATH') || exit('Access denied');
3 3
 	/**
4 4
 	 * TNH Framework
5 5
 	 *
@@ -22,154 +22,154 @@  discard block
 block discarded – undo
22 22
 	 * You should have received a copy of the GNU General Public License
23 23
 	 * along with this program; if not, write to the Free Software
24 24
 	 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25
-	*/
25
+	 */
26 26
 
27
-    class Pagination{
27
+	class Pagination{
28 28
         
29 29
 		/**
30
-         * The list of loaded config
31
-         * @var array
32
-         */
33
-        private $config = array();
30
+		 * The list of loaded config
31
+		 * @var array
32
+		 */
33
+		private $config = array();
34 34
 
35
-        /**
36
-         * Create an instance of pagination
37
-         * @param array $overwriteConfig the list of configuration to overwrite the defined configuration in config_pagination.php
38
-         */
39
-        public function __construct($overwriteConfig = array()){
40
-            if(file_exists(CONFIG_PATH . 'config_pagination.php')){
41
-                require_once CONFIG_PATH . 'config_pagination.php';
42
-                if(empty($config) || ! is_array($config)){
43
-                    show_error('No configuration found in ' . CONFIG_PATH . 'config_pagination.php');
44
-                }
35
+		/**
36
+		 * Create an instance of pagination
37
+		 * @param array $overwriteConfig the list of configuration to overwrite the defined configuration in config_pagination.php
38
+		 */
39
+		public function __construct($overwriteConfig = array()){
40
+			if(file_exists(CONFIG_PATH . 'config_pagination.php')){
41
+				require_once CONFIG_PATH . 'config_pagination.php';
42
+				if(empty($config) || ! is_array($config)){
43
+					show_error('No configuration found in ' . CONFIG_PATH . 'config_pagination.php');
44
+				}
45 45
 				else{
46 46
 					if(! empty($overwriteConfig)){
47 47
 						$config = array_merge($config, $overwriteConfig);
48 48
 					}
49 49
 					$this->config = $config;
50
-                    //put it gobally
50
+					//put it gobally
51 51
 					Config::setAll($config);
52 52
 					unset($config);
53 53
 				}
54
-            }
55
-            else{
56
-                show_error('Unable to find the pagination configuration file');
57
-            }
58
-        }
54
+			}
55
+			else{
56
+				show_error('Unable to find the pagination configuration file');
57
+			}
58
+		}
59 59
 
60 60
 
61
-        /**
62
-         * Set the pagination custom configuration to overwrite the default configuration in
63
-         * config_pagination.php
64
-         * @param array $config the configuration to set
65
-         */
66
-        public function setConfig(array $config = array()){
67
-            if(! empty($config)){
68
-                $this->config = array_merge($this->config, $config);
69
-                Config::setAll($config);
70
-            }
71
-        }
61
+		/**
62
+		 * Set the pagination custom configuration to overwrite the default configuration in
63
+		 * config_pagination.php
64
+		 * @param array $config the configuration to set
65
+		 */
66
+		public function setConfig(array $config = array()){
67
+			if(! empty($config)){
68
+				$this->config = array_merge($this->config, $config);
69
+				Config::setAll($config);
70
+			}
71
+		}
72 72
 
73
-        /**
74
-         * Generate the pagination link
75
-         * @param  int $totalRows the total number of data
76
-         * @param  int $currentPageNumber the current page number
77
-         * @return string the pagination link
78
-         */
79
-        public function getLink($totalRows, $currentPageNumber){
80
-            $pageQueryName = $this->config['page_query_string_name'];
81
-            $numberOfLink = $this->config['nb_link'];
73
+		/**
74
+		 * Generate the pagination link
75
+		 * @param  int $totalRows the total number of data
76
+		 * @param  int $currentPageNumber the current page number
77
+		 * @return string the pagination link
78
+		 */
79
+		public function getLink($totalRows, $currentPageNumber){
80
+			$pageQueryName = $this->config['page_query_string_name'];
81
+			$numberOfLink = $this->config['nb_link'];
82 82
 			$numberOfRowPerPage = $this->config['pagination_per_page'];
83
-            $queryString = Url::queryString();
84
-            $currentUrl = Url::current();
85
-            if($queryString == ''){
86
-                $query = '?' . $pageQueryName . '=';
87
-            }
88
-            else{
89
-                $tab = explode($pageQueryName . '=', $queryString);
90
-                $nb = count($tab);
91
-                if($nb == 1){
92
-                    $query = '?' . $queryString . '&' . $pageQueryName . '=';
93
-                }
94
-                else{
95
-                    if($tab[0] == ''){
96
-                        $query = '?' . $pageQueryName . '=';
97
-                    }
98
-                    else{
99
-                        $query = '?' . $tab[0] . '' . $pageQueryName . '=';
100
-                    }
101
-                }
102
-            }
103
-            $temp = explode('?', $currentUrl);
104
-            $query = $temp[0] . $query;
105
-            $navbar = '';
106
-            $numberOfPage = ceil($totalRows / $numberOfRowPerPage);
83
+			$queryString = Url::queryString();
84
+			$currentUrl = Url::current();
85
+			if($queryString == ''){
86
+				$query = '?' . $pageQueryName . '=';
87
+			}
88
+			else{
89
+				$tab = explode($pageQueryName . '=', $queryString);
90
+				$nb = count($tab);
91
+				if($nb == 1){
92
+					$query = '?' . $queryString . '&' . $pageQueryName . '=';
93
+				}
94
+				else{
95
+					if($tab[0] == ''){
96
+						$query = '?' . $pageQueryName . '=';
97
+					}
98
+					else{
99
+						$query = '?' . $tab[0] . '' . $pageQueryName . '=';
100
+					}
101
+				}
102
+			}
103
+			$temp = explode('?', $currentUrl);
104
+			$query = $temp[0] . $query;
105
+			$navbar = '';
106
+			$numberOfPage = ceil($totalRows / $numberOfRowPerPage);
107 107
 			if(! is_numeric ($currentPageNumber) || $currentPageNumber <= 0){
108 108
 				$currentPageNumber = 1;
109 109
 			}
110
-            if($numberOfPage <= 1 || $numberOfLink <= 0 || $numberOfRowPerPage <= 0 || !is_numeric($numberOfLink) || !is_numeric($numberOfRowPerPage)
111
-            ){
112
-                return $navbar;
113
-            }
114
-            if($numberOfLink % 2 == 0){
115
-                $start = $currentPageNumber - ($numberOfLink / 2) + 1;
116
-                $end = $currentPageNumber + ($numberOfLink / 2);
117
-            }
118
-            else{
119
-                $start = $currentPageNumber - floor($numberOfLink / 2);
120
-                $end = $currentPageNumber + floor($numberOfLink / 2);
121
-            }
122
-            if($start <= 1){
123
-                $begin = 1;
124
-                $end = $numberOfLink;
125
-            }
126
-            else if($start > 1 && $end < $numberOfPage){
127
-                $begin = $start;
128
-                $end = $end;
129
-            }
130
-            else{
131
-                $begin = ($numberOfPage - $numberOfLink) + 1;
132
-                $end = $numberOfPage;
133
-            }
134
-            if($numberOfPage <= $numberOfLink){
135
-                $begin = 1;
136
-                $end = $numberOfPage;
137
-            }
138
-            if($currentPageNumber == 1){
139
-                for($i = $begin; $i <= $end; $i++){
140
-                    if($i == $currentPageNumber){
141
-                        $navbar .= $this->config['active_link_open'] . $currentPageNumber . $this->config['active_link_close'];
142
-                    }
143
-                    else{
144
-                        $navbar .= $this->config['digit_open'] . '<a href="' . $query . $i . '" ' . attributes_to_string($this->config['attributes']) . '>' . $i . '</a>' . $this->config['digit_close'];
145
-                    }
146
-                }
147
-                $navbar .= $this->config['next_open'] . '<a href="' . $query . ($currentPageNumber + 1) . '">' . $this->config['next_text'] . '</a>' . $this->config['next_close'];
148
-            }
149
-            else if($currentPageNumber > 1 && $currentPageNumber < $numberOfPage){
150
-                $navbar .= $this->config['previous_open'] . '<a href="' . $query . ($currentPageNumber - 1) . '">' . $this->config['previous_text'] . '</a>' . $this->config['previous_close'];
151
-                for($i = $begin; $i <= $end; $i++){
152
-                    if($i == $currentPageNumber){
153
-                        $navbar .= $this->config['active_link_open'] . $currentPageNumber . $this->config['active_link_close'];
154
-                    }
155
-                    else{
156
-                        $navbar .= $this->config['digit_open'] . '<a href="' . $query . $i . '"' . attributes_to_string($this->config['attributes']) . '>' . $i .'</a>' . $this->config['digit_close'];
157
-                    }
158
-                }
159
-                $navbar .= $this->config['next_open']."<a href='$query".($currentPageNumber + 1)."'>".$this->config['next_text']."</a>".$this->config['next_close'];
160
-            }
161
-            else if($currentPageNumber == $numberOfPage){
162
-                $navbar .= $this->config['previous_open'] . '<a href="' . $query . ($currentPageNumber - 1) . '">' . $this->config['previous_text'] . '</a>' . $this->config['previous_close'];
163
-                for($i = $begin; $i <= $end; $i++){
164
-                    if($i == $currentPageNumber){
165
-                        $navbar .= $this->config['active_link_open'] . $currentPageNumber . $this->config['active_link_close'];
166
-                    }
167
-                    else{
168
-                        $navbar .= $this->config['digit_open'] . '<a href="' . $query . $i . '"' . attributes_to_string($this->config['attributes']) . '>' . $i . '</a>' . $this->config['digit_close'];
169
-                    }
170
-                }
171
-            }
172
-            $navbar = $this->config['pagination_open'] . $navbar . $this->config['pagination_close'];
173
-            return $navbar;
174
-        }
175
-    }
110
+			if($numberOfPage <= 1 || $numberOfLink <= 0 || $numberOfRowPerPage <= 0 || !is_numeric($numberOfLink) || !is_numeric($numberOfRowPerPage)
111
+			){
112
+				return $navbar;
113
+			}
114
+			if($numberOfLink % 2 == 0){
115
+				$start = $currentPageNumber - ($numberOfLink / 2) + 1;
116
+				$end = $currentPageNumber + ($numberOfLink / 2);
117
+			}
118
+			else{
119
+				$start = $currentPageNumber - floor($numberOfLink / 2);
120
+				$end = $currentPageNumber + floor($numberOfLink / 2);
121
+			}
122
+			if($start <= 1){
123
+				$begin = 1;
124
+				$end = $numberOfLink;
125
+			}
126
+			else if($start > 1 && $end < $numberOfPage){
127
+				$begin = $start;
128
+				$end = $end;
129
+			}
130
+			else{
131
+				$begin = ($numberOfPage - $numberOfLink) + 1;
132
+				$end = $numberOfPage;
133
+			}
134
+			if($numberOfPage <= $numberOfLink){
135
+				$begin = 1;
136
+				$end = $numberOfPage;
137
+			}
138
+			if($currentPageNumber == 1){
139
+				for($i = $begin; $i <= $end; $i++){
140
+					if($i == $currentPageNumber){
141
+						$navbar .= $this->config['active_link_open'] . $currentPageNumber . $this->config['active_link_close'];
142
+					}
143
+					else{
144
+						$navbar .= $this->config['digit_open'] . '<a href="' . $query . $i . '" ' . attributes_to_string($this->config['attributes']) . '>' . $i . '</a>' . $this->config['digit_close'];
145
+					}
146
+				}
147
+				$navbar .= $this->config['next_open'] . '<a href="' . $query . ($currentPageNumber + 1) . '">' . $this->config['next_text'] . '</a>' . $this->config['next_close'];
148
+			}
149
+			else if($currentPageNumber > 1 && $currentPageNumber < $numberOfPage){
150
+				$navbar .= $this->config['previous_open'] . '<a href="' . $query . ($currentPageNumber - 1) . '">' . $this->config['previous_text'] . '</a>' . $this->config['previous_close'];
151
+				for($i = $begin; $i <= $end; $i++){
152
+					if($i == $currentPageNumber){
153
+						$navbar .= $this->config['active_link_open'] . $currentPageNumber . $this->config['active_link_close'];
154
+					}
155
+					else{
156
+						$navbar .= $this->config['digit_open'] . '<a href="' . $query . $i . '"' . attributes_to_string($this->config['attributes']) . '>' . $i .'</a>' . $this->config['digit_close'];
157
+					}
158
+				}
159
+				$navbar .= $this->config['next_open']."<a href='$query".($currentPageNumber + 1)."'>".$this->config['next_text']."</a>".$this->config['next_close'];
160
+			}
161
+			else if($currentPageNumber == $numberOfPage){
162
+				$navbar .= $this->config['previous_open'] . '<a href="' . $query . ($currentPageNumber - 1) . '">' . $this->config['previous_text'] . '</a>' . $this->config['previous_close'];
163
+				for($i = $begin; $i <= $end; $i++){
164
+					if($i == $currentPageNumber){
165
+						$navbar .= $this->config['active_link_open'] . $currentPageNumber . $this->config['active_link_close'];
166
+					}
167
+					else{
168
+						$navbar .= $this->config['digit_open'] . '<a href="' . $query . $i . '"' . attributes_to_string($this->config['attributes']) . '>' . $i . '</a>' . $this->config['digit_close'];
169
+					}
170
+				}
171
+			}
172
+			$navbar = $this->config['pagination_open'] . $navbar . $this->config['pagination_close'];
173
+			return $navbar;
174
+		}
175
+	}
Please login to merge, or discard this patch.
core/classes/Response.php 1 patch
Indentation   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -22,7 +22,7 @@  discard block
 block discarded – undo
22 22
 	 * You should have received a copy of the GNU General Public License
23 23
 	 * along with this program; if not, write to the Free Software
24 24
 	 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25
-	*/
25
+	 */
26 26
 
27 27
 	class Response{
28 28
 
@@ -57,9 +57,9 @@  discard block
 block discarded – undo
57 57
 		private $_currentUrlCacheKey = null;
58 58
 		
59 59
 		/**
60
-		* Whether we can compress the output using Gzip
61
-		* @var boolean
62
-		*/
60
+		 * Whether we can compress the output using Gzip
61
+		 * @var boolean
62
+		 */
63 63
 		private static $_canCompressOutput = false;
64 64
 		
65 65
 		/**
@@ -236,8 +236,8 @@  discard block
 block discarded – undo
236 236
 		}
237 237
 		
238 238
 		/**
239
-		* Send the final page output to user
240
-		*/
239
+		 * Send the final page output to user
240
+		 */
241 241
 		public function renderFinalPage(){
242 242
 			$logger = self::getLogger();
243 243
 			$obj = & get_instance();
@@ -301,8 +301,8 @@  discard block
 block discarded – undo
301 301
 		}
302 302
 		
303 303
 		/**
304
-		* Send the final page output to user if is cached
305
-		*/
304
+		 * Send the final page output to user if is cached
305
+		 */
306 306
 		public function renderFinalPageFromCache(&$cache){
307 307
 			$logger = self::getLogger();
308 308
 			$url = $this->_currentUrl;					
@@ -362,9 +362,9 @@  discard block
 block discarded – undo
362 362
 		}
363 363
 		
364 364
 		/**
365
-		* Get the final page to be rendered
366
-		* @return string
367
-		*/
365
+		 * Get the final page to be rendered
366
+		 * @return string
367
+		 */
368 368
 		public function getFinalPageRendered(){
369 369
 			return $this->_pageRender;
370 370
 		}
Please login to merge, or discard this patch.
core/classes/EventInfo.php 1 patch
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -22,7 +22,7 @@
 block discarded – undo
22 22
 	 * You should have received a copy of the GNU General Public License
23 23
 	 * along with this program; if not, write to the Free Software
24 24
 	 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25
-	*/
25
+	 */
26 26
 
27 27
 	/**
28 28
 	 * This class represent the event detail to dispatch to correspond listener
Please login to merge, or discard this patch.
core/classes/Controller.php 1 patch
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -22,7 +22,7 @@  discard block
 block discarded – undo
22 22
 	 * You should have received a copy of the GNU General Public License
23 23
 	 * along with this program; if not, write to the Free Software
24 24
 	 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25
-	*/
25
+	 */
26 26
 
27 27
 	class Controller{
28 28
 		
@@ -114,12 +114,12 @@  discard block
 block discarded – undo
114 114
 		 */
115 115
 		protected function setLoggerFromParamOrCreateNewInstance(Log $logger = null){
116 116
 			if($logger !== null){
117
-	          $this->logger = $logger;
118
-	        }
119
-	        else{
120
-	            $this->logger =& class_loader('Log', 'classes');
117
+			  $this->logger = $logger;
118
+			}
119
+			else{
120
+				$this->logger =& class_loader('Log', 'classes');
121 121
 				$this->logger->setLogger('MainController');
122
-	        }
122
+			}
123 123
 		}
124 124
 
125 125
 		/**
Please login to merge, or discard this patch.
core/libraries/FormValidation.php 1 patch
Indentation   +872 added lines, -872 removed lines patch added patch discarded remove patch
@@ -1,914 +1,914 @@
 block discarded – undo
1 1
 <?php
2
-    defined('ROOT_PATH') || exit('Access denied');
3
-    /**
4
-     * TNH Framework
5
-     *
6
-     * A simple PHP framework using HMVC architecture
7
-     *
8
-     * This content is released under the GNU GPL License (GPL)
9
-     *
10
-     * Copyright (C) 2017 Tony NGUEREZA
11
-     *
12
-     * This program is free software; you can redistribute it and/or
13
-     * modify it under the terms of the GNU General Public License
14
-     * as published by the Free Software Foundation; either version 3
15
-     * of the License, or (at your option) any later version.
16
-     *
17
-     * This program is distributed in the hope that it will be useful,
18
-     * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
-     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
-     * GNU General Public License for more details.
21
-     *
22
-     * You should have received a copy of the GNU General Public License
23
-     * along with this program; if not, write to the Free Software
24
-     * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25
-    */
26
-
27
-
28
-     class FormValidation{
2
+	defined('ROOT_PATH') || exit('Access denied');
3
+	/**
4
+	 * TNH Framework
5
+	 *
6
+	 * A simple PHP framework using HMVC architecture
7
+	 *
8
+	 * This content is released under the GNU GPL License (GPL)
9
+	 *
10
+	 * Copyright (C) 2017 Tony NGUEREZA
11
+	 *
12
+	 * This program is free software; you can redistribute it and/or
13
+	 * modify it under the terms of the GNU General Public License
14
+	 * as published by the Free Software Foundation; either version 3
15
+	 * of the License, or (at your option) any later version.
16
+	 *
17
+	 * This program is distributed in the hope that it will be useful,
18
+	 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
+	 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
+	 * GNU General Public License for more details.
21
+	 *
22
+	 * You should have received a copy of the GNU General Public License
23
+	 * along with this program; if not, write to the Free Software
24
+	 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25
+	 */
26
+
27
+
28
+	 class FormValidation{
29 29
 		 
30
-        /**
31
-         * The form validation status
32
-         * @var boolean
33
-         */
34
-        protected $_success  = false;
35
-
36
-        /**
37
-         * The list of errors messages
38
-         * @var array
39
-         */
40
-        protected $_errorsMessages = array();
30
+		/**
31
+		 * The form validation status
32
+		 * @var boolean
33
+		 */
34
+		protected $_success  = false;
35
+
36
+		/**
37
+		 * The list of errors messages
38
+		 * @var array
39
+		 */
40
+		protected $_errorsMessages = array();
41 41
         
42
-        // Array of rule sets, fieldName => PIPE seperated ruleString
43
-        protected $_rules             = array();
42
+		// Array of rule sets, fieldName => PIPE seperated ruleString
43
+		protected $_rules             = array();
44 44
         
45
-        // Array of errors, niceName => Error Message
46
-        protected $_errors             = array();
45
+		// Array of errors, niceName => Error Message
46
+		protected $_errors             = array();
47 47
         
48
-        // Array of post Key => Nice name labels
49
-        protected $_labels          = array();
48
+		// Array of post Key => Nice name labels
49
+		protected $_labels          = array();
50 50
         
51
-        /**
52
-         * The errors delimiters
53
-         * @var array
54
-         */
55
-        protected $_allErrorsDelimiter   = array('<div class="error">', '</div>');
56
-
57
-        /**
58
-         * The each error delimiter
59
-         * @var array
60
-         */
61
-        protected $_eachErrorDelimiter   = array('<p class="error">', '</p>');
51
+		/**
52
+		 * The errors delimiters
53
+		 * @var array
54
+		 */
55
+		protected $_allErrorsDelimiter   = array('<div class="error">', '</div>');
56
+
57
+		/**
58
+		 * The each error delimiter
59
+		 * @var array
60
+		 */
61
+		protected $_eachErrorDelimiter   = array('<p class="error">', '</p>');
62 62
         
63 63
 		/**
64
-         * Indicated if need force the validation to be failed
65
-         * @var boolean
66
-         */
67
-        protected $_forceFail            = false;
68
-
69
-        /**
70
-         * The list of the error messages overrides by the original
71
-         * @var array
72
-         */
73
-        protected $_errorPhraseOverrides = array();
74
-
75
-        /**
76
-         * The logger instance
77
-         * @var Log
78
-         */
79
-        private $logger;
80
-
81
-        /**
82
-         * The data to be validated, the default is to use $_POST
83
-         * @var array
84
-         */
85
-        private $data = array();
86
-
87
-        /**
88
-         * Whether to check the CSRF. This attribute is just a way to allow custom change of the 
64
+		 * Indicated if need force the validation to be failed
65
+		 * @var boolean
66
+		 */
67
+		protected $_forceFail            = false;
68
+
69
+		/**
70
+		 * The list of the error messages overrides by the original
71
+		 * @var array
72
+		 */
73
+		protected $_errorPhraseOverrides = array();
74
+
75
+		/**
76
+		 * The logger instance
77
+		 * @var Log
78
+		 */
79
+		private $logger;
80
+
81
+		/**
82
+		 * The data to be validated, the default is to use $_POST
83
+		 * @var array
84
+		 */
85
+		private $data = array();
86
+
87
+		/**
88
+		 * Whether to check the CSRF. This attribute is just a way to allow custom change of the 
89 89
 		 * CSRF global configuration
90 90
 		 *
91
-         * @var boolean
92
-         */
93
-        public $enableCsrfCheck = false;
94
-
95
-        /**
96
-         * Set all errors and rule sets empty, and sets success to false.
97
-         *
98
-         * @return void
99
-         */
100
-        public function __construct() {
101
-            $this->logger =& class_loader('Log', 'classes');
102
-            $this->logger->setLogger('Library::FormValidation');
91
+		 * @var boolean
92
+		 */
93
+		public $enableCsrfCheck = false;
94
+
95
+		/**
96
+		 * Set all errors and rule sets empty, and sets success to false.
97
+		 *
98
+		 * @return void
99
+		 */
100
+		public function __construct() {
101
+			$this->logger =& class_loader('Log', 'classes');
102
+			$this->logger->setLogger('Library::FormValidation');
103 103
            
104 104
 		   //Load form validation language message
105
-            Loader::lang('form_validation');
106
-            $obj = & get_instance();
107
-            $this->_errorsMessages  = array(
108
-                        'required'         => $obj->lang->get('fv_required'),
109
-                        'min_length'       => $obj->lang->get('fv_min_length'),
110
-                        'max_length'       => $obj->lang->get('fv_max_length'),
111
-                        'exact_length'     => $obj->lang->get('fv_exact_length'),
112
-                        'less_than'        => $obj->lang->get('fv_less_than'),
113
-                        'greater_than'     => $obj->lang->get('fv_greater_than'),
114
-                        'matches'          => $obj->lang->get('fv_matches'),
115
-                        'valid_email'      => $obj->lang->get('fv_valid_email'),
116
-                        'not_equal'        => array(
117
-                                                'post:key' => $obj->lang->get('fv_not_equal_post_key'),
118
-                                                'string'   => $obj->lang->get('fv_not_equal_string')
119
-                                            ),
120
-                        'depends'          => $obj->lang->get('fv_depends'),
121
-                        'is_unique'        => $obj->lang->get('fv_is_unique'),
122
-                        'is_unique_update' => $obj->lang->get('fv_is_unique_update'),
123
-                        'exists'           => $obj->lang->get('fv_exists'),
124
-                        'regex'            => $obj->lang->get('fv_regex'),
125
-                        'in_list'          => $obj->lang->get('fv_in_list'),
126
-                        'numeric'          => $obj->lang->get('fv_numeric'),
127
-                        'callback'         => $obj->lang->get('fv_callback'),
128
-                    );
129
-            $this->_resetValidation();
130
-            $this->setData($obj->request->post(null));
131
-        }
132
-
133
-        /**
134
-         * Reset the form validation instance
135
-         */
136
-        protected function _resetValidation() {
137
-            $this->_rules                = array();
138
-            $this->_labels               = array();
139
-            $this->_errorPhraseOverrides = array();
140
-            $this->_errors               = array();
141
-            $this->_success              = false;
142
-            $this->_forceFail            = false;
143
-            $this->data                  = array();
105
+			Loader::lang('form_validation');
106
+			$obj = & get_instance();
107
+			$this->_errorsMessages  = array(
108
+						'required'         => $obj->lang->get('fv_required'),
109
+						'min_length'       => $obj->lang->get('fv_min_length'),
110
+						'max_length'       => $obj->lang->get('fv_max_length'),
111
+						'exact_length'     => $obj->lang->get('fv_exact_length'),
112
+						'less_than'        => $obj->lang->get('fv_less_than'),
113
+						'greater_than'     => $obj->lang->get('fv_greater_than'),
114
+						'matches'          => $obj->lang->get('fv_matches'),
115
+						'valid_email'      => $obj->lang->get('fv_valid_email'),
116
+						'not_equal'        => array(
117
+												'post:key' => $obj->lang->get('fv_not_equal_post_key'),
118
+												'string'   => $obj->lang->get('fv_not_equal_string')
119
+											),
120
+						'depends'          => $obj->lang->get('fv_depends'),
121
+						'is_unique'        => $obj->lang->get('fv_is_unique'),
122
+						'is_unique_update' => $obj->lang->get('fv_is_unique_update'),
123
+						'exists'           => $obj->lang->get('fv_exists'),
124
+						'regex'            => $obj->lang->get('fv_regex'),
125
+						'in_list'          => $obj->lang->get('fv_in_list'),
126
+						'numeric'          => $obj->lang->get('fv_numeric'),
127
+						'callback'         => $obj->lang->get('fv_callback'),
128
+					);
129
+			$this->_resetValidation();
130
+			$this->setData($obj->request->post(null));
131
+		}
132
+
133
+		/**
134
+		 * Reset the form validation instance
135
+		 */
136
+		protected function _resetValidation() {
137
+			$this->_rules                = array();
138
+			$this->_labels               = array();
139
+			$this->_errorPhraseOverrides = array();
140
+			$this->_errors               = array();
141
+			$this->_success              = false;
142
+			$this->_forceFail            = false;
143
+			$this->data                  = array();
144 144
 			$this->enableCsrfCheck       = false;
145
-        }
145
+		}
146 146
 
147
-        /**
148
-         * Set the form validation data
149
-         * @param array $data the values to be validated
147
+		/**
148
+		 * Set the form validation data
149
+		 * @param array $data the values to be validated
150 150
 		 *
151
-         * @return FormValidation Current instance of object.
152
-         */
153
-        public function setData(array $data){
154
-            $this->logger->debug('Setting the form validation data, the values are: ' . stringfy_vars($data));
155
-            $this->data = $data;
151
+		 * @return FormValidation Current instance of object.
152
+		 */
153
+		public function setData(array $data){
154
+			$this->logger->debug('Setting the form validation data, the values are: ' . stringfy_vars($data));
155
+			$this->data = $data;
156 156
 			return $this;
157
-        }
158
-
159
-        /**
160
-         * Get the form validation data
161
-         * @return array the form validation data to be validated
162
-         */
163
-        public function getData(){
164
-            return $this->data;
165
-        }
166
-
167
-		/**
168
-		* Get the validation function name to validate a rule
169
-		*
170
-		* @return string the function name
171
-		*/
172
-        protected function _toCallCase($funcName, $prefix='_validate') {
173
-            $funcName = strtolower($funcName);
174
-            $finalFuncName = $prefix;
175
-            foreach (explode('_', $funcName) as $funcNamePart) {
176
-                $finalFuncName .= strtoupper($funcNamePart[0]) . substr($funcNamePart, 1);
177
-            }
178
-            return $finalFuncName;
179
-        }
180
-
181
-        /**
182
-         * Returns the boolean of the data status success. It goes by the simple
183
-         *
184
-         * @return boolean Whether or not the data validation has succeeded
185
-         */
186
-        public function isSuccess() {
187
-            return $this->_success;
188
-        }
189
-
190
-        /**
191
-         * Checks if the request method is POST or the Data to be validated is set
192
-         *
193
-         * @return boolean Whether or not the form has been submitted or the data is available for validation.
194
-         */
195
-        public function canDoValidation() {
196
-            return get_instance()->request->method() === 'POST' || ! empty($this->data);
197
-        }
198
-
199
-        /**
200
-         * Runs _run once POST data has been submitted or data is set manually.
201
-         *
202
-         * @return boolean
203
-         */
204
-        public function run() {
205
-            if ($this->canDoValidation()) {
206
-                $this->logger->info('The data to validate are listed below: ' . stringfy_vars($this->getData()));
207
-                $this->_run();
208
-            }
209
-            return $this->isSuccess();
210
-        }
211
-
212
-        /**
213
-         * Takes and trims each data, if it has any rules, we parse the rule string and run
214
-         * each rule against the data value. Sets _success to true if there are no errors
215
-         * afterwards.
216
-         */
217
-        protected function _run() {
218
-            if(get_instance()->request->method() == 'POST' || $this->enableCsrfCheck){
219
-                $this->logger->debug('Check if CSRF is enabled in configuration');
220
-                //first check for CSRF
221
-                if ((get_config('csrf_enable', false) || $this->enableCsrfCheck) && ! Security::validateCSRF()){
222
-                    show_error('Invalide data, Cross Site Request Forgery do his job, the data to validate is corrupted.');
223
-                }
224
-                else{
225
-                    $this->logger->info('CSRF is not enabled in configuration or not set manully, no need to check it');
226
-                }
227
-            }
228
-            /////////////////////////////////////////////
229
-            $this->_forceFail = false;
230
-
231
-            foreach ($this->getData() as $inputName => $inputVal) {
232
-    			if(is_array($this->data[$inputName])){
233
-    				$this->data[$inputName] = array_map('trim', $this->data[$inputName]);
234
-    			}
235
-    			else{
236
-    				$this->data[$inputName] = trim($this->data[$inputName]);
237
-    			}
238
-
239
-                if (array_key_exists($inputName, $this->_rules)) {
240
-                    foreach ($this->_parseRuleString($this->_rules[$inputName]) as $eachRule) {
241
-                        $this->_validateRule($inputName, $this->data[$inputName], $eachRule);
242
-                    }
243
-                }
244
-            }
245
-
246
-            if (empty($this->_errors) && $this->_forceFail === false) {
247
-                $this->_success = true;
248
-            }
249
-        }
250
-
251
-        /**
252
-         * Adds a rule to a form data validation field.
253
-         *
254
-         * @param string $inputField Name of the field or the data key to add a rule to
255
-         * @param string $ruleSets PIPE seperated string of rules
256
-		 *
257
-         * @return FormValidation Current instance of object.
258
-         */
259
-        public function setRule($inputField, $inputLabel, $ruleSets) {
260
-            $this->_rules[$inputField] = $ruleSets;
261
-            $this->_labels[$inputField] = $inputLabel;
262
-            $this->logger->info('Set the field rule: name [' .$inputField. '], label [' .$inputLabel. '], rules [' .$ruleSets. ']');
263
-            return $this;
264
-        }
265
-
266
-        /**
267
-         * Takes an array of rules and uses setRule() to set them, accepts an array
268
-         * of rule names rather than a pipe-delimited string as well.
269
-         * @param array $ruleSets
157
+		}
158
+
159
+		/**
160
+		 * Get the form validation data
161
+		 * @return array the form validation data to be validated
162
+		 */
163
+		public function getData(){
164
+			return $this->data;
165
+		}
166
+
167
+		/**
168
+		 * Get the validation function name to validate a rule
169
+		 *
170
+		 * @return string the function name
171
+		 */
172
+		protected function _toCallCase($funcName, $prefix='_validate') {
173
+			$funcName = strtolower($funcName);
174
+			$finalFuncName = $prefix;
175
+			foreach (explode('_', $funcName) as $funcNamePart) {
176
+				$finalFuncName .= strtoupper($funcNamePart[0]) . substr($funcNamePart, 1);
177
+			}
178
+			return $finalFuncName;
179
+		}
180
+
181
+		/**
182
+		 * Returns the boolean of the data status success. It goes by the simple
183
+		 *
184
+		 * @return boolean Whether or not the data validation has succeeded
185
+		 */
186
+		public function isSuccess() {
187
+			return $this->_success;
188
+		}
189
+
190
+		/**
191
+		 * Checks if the request method is POST or the Data to be validated is set
192
+		 *
193
+		 * @return boolean Whether or not the form has been submitted or the data is available for validation.
194
+		 */
195
+		public function canDoValidation() {
196
+			return get_instance()->request->method() === 'POST' || ! empty($this->data);
197
+		}
198
+
199
+		/**
200
+		 * Runs _run once POST data has been submitted or data is set manually.
201
+		 *
202
+		 * @return boolean
203
+		 */
204
+		public function run() {
205
+			if ($this->canDoValidation()) {
206
+				$this->logger->info('The data to validate are listed below: ' . stringfy_vars($this->getData()));
207
+				$this->_run();
208
+			}
209
+			return $this->isSuccess();
210
+		}
211
+
212
+		/**
213
+		 * Takes and trims each data, if it has any rules, we parse the rule string and run
214
+		 * each rule against the data value. Sets _success to true if there are no errors
215
+		 * afterwards.
216
+		 */
217
+		protected function _run() {
218
+			if(get_instance()->request->method() == 'POST' || $this->enableCsrfCheck){
219
+				$this->logger->debug('Check if CSRF is enabled in configuration');
220
+				//first check for CSRF
221
+				if ((get_config('csrf_enable', false) || $this->enableCsrfCheck) && ! Security::validateCSRF()){
222
+					show_error('Invalide data, Cross Site Request Forgery do his job, the data to validate is corrupted.');
223
+				}
224
+				else{
225
+					$this->logger->info('CSRF is not enabled in configuration or not set manully, no need to check it');
226
+				}
227
+			}
228
+			/////////////////////////////////////////////
229
+			$this->_forceFail = false;
230
+
231
+			foreach ($this->getData() as $inputName => $inputVal) {
232
+				if(is_array($this->data[$inputName])){
233
+					$this->data[$inputName] = array_map('trim', $this->data[$inputName]);
234
+				}
235
+				else{
236
+					$this->data[$inputName] = trim($this->data[$inputName]);
237
+				}
238
+
239
+				if (array_key_exists($inputName, $this->_rules)) {
240
+					foreach ($this->_parseRuleString($this->_rules[$inputName]) as $eachRule) {
241
+						$this->_validateRule($inputName, $this->data[$inputName], $eachRule);
242
+					}
243
+				}
244
+			}
245
+
246
+			if (empty($this->_errors) && $this->_forceFail === false) {
247
+				$this->_success = true;
248
+			}
249
+		}
250
+
251
+		/**
252
+		 * Adds a rule to a form data validation field.
253
+		 *
254
+		 * @param string $inputField Name of the field or the data key to add a rule to
255
+		 * @param string $ruleSets PIPE seperated string of rules
270 256
 		 *
271 257
 		 * @return FormValidation Current instance of object.
272
-         */
273
-        public function setRules(array $ruleSets) {
274
-            foreach ($ruleSets as $ruleSet) {
275
-                $pipeDelimitedRules = null;
276
-                if (is_array($ruleSet['rules'])) {
277
-                    $pipeDelimitedRules = implode('|', $ruleSet['rules']);
278
-                } else {
279
-                    $pipeDelimitedRules = $ruleSet['rules'];
280
-                }
281
-                $this->setRule($ruleSet['name'], $ruleSet['label'], $pipeDelimitedRules);
282
-            }
283
-            return $this;
284
-        }
285
-
286
-        /**
287
-         * This method creates the global errors delimiter, each argument occurs once, at the beginning, and
288
-         * end of the errors block respectively.
289
-         *
290
-         * @param string $start Before block of errors gets displayed, HTML allowed.
291
-         * @param string $end After the block of errors gets displayed, HTML allowed.
292
-         *
258
+		 */
259
+		public function setRule($inputField, $inputLabel, $ruleSets) {
260
+			$this->_rules[$inputField] = $ruleSets;
261
+			$this->_labels[$inputField] = $inputLabel;
262
+			$this->logger->info('Set the field rule: name [' .$inputField. '], label [' .$inputLabel. '], rules [' .$ruleSets. ']');
263
+			return $this;
264
+		}
265
+
266
+		/**
267
+		 * Takes an array of rules and uses setRule() to set them, accepts an array
268
+		 * of rule names rather than a pipe-delimited string as well.
269
+		 * @param array $ruleSets
270
+		 *
293 271
 		 * @return FormValidation Current instance of object.
294
-         */
295
-        public function setErrorsDelimiter($start, $end) {
296
-            $this->_allErrorsDelimiter[0] = $start;
297
-            $this->_allErrorsDelimiter[1] = $end;
298
-            return $this;
299
-        }
300
-
301
-        /**
302
-         * This is the individual error delimiter, each argument occurs once before and after
303
-         * each individual error listed.
304
-         *
305
-         * @param string $start Displayed before each error.
306
-         * @param string $end Displayed after each error.
307
-         * 
272
+		 */
273
+		public function setRules(array $ruleSets) {
274
+			foreach ($ruleSets as $ruleSet) {
275
+				$pipeDelimitedRules = null;
276
+				if (is_array($ruleSet['rules'])) {
277
+					$pipeDelimitedRules = implode('|', $ruleSet['rules']);
278
+				} else {
279
+					$pipeDelimitedRules = $ruleSet['rules'];
280
+				}
281
+				$this->setRule($ruleSet['name'], $ruleSet['label'], $pipeDelimitedRules);
282
+			}
283
+			return $this;
284
+		}
285
+
286
+		/**
287
+		 * This method creates the global errors delimiter, each argument occurs once, at the beginning, and
288
+		 * end of the errors block respectively.
289
+		 *
290
+		 * @param string $start Before block of errors gets displayed, HTML allowed.
291
+		 * @param string $end After the block of errors gets displayed, HTML allowed.
292
+		 *
308 293
 		 * @return FormValidation Current instance of object.
309
-         */
310
-        public function setErrorDelimiter($start, $end) {
311
-            $this->_eachErrorDelimiter[0] = $start;
312
-            $this->_eachErrorDelimiter[1] = $end;
313
-            return $this;
314
-        }
315
-
316
-		/**
317
-		* Get the each errors delimiters
318
-		*
319
-		* @return array
320
-		*/
321
-    	public function getErrorDelimiter() {
322
-            return $this->_eachErrorDelimiter;
323
-        }
324
-
325
-		/**
326
-		* Get the all errors delimiters
327
-		*
328
-		* @return array
329
-		*/
330
-    	public function getErrorsDelimiter() {
331
-            return $this->_allErrorsDelimiter;
332
-        }
333
-
334
-        /**
335
-         * This sets a custom error message that can override the default error phrase provided
336
-         * by FormValidation, it can be used in the format of setMessage('rule', 'error phrase')
337
-         * which will globally change the error phrase of that rule, or in the format of:
338
-         * setMessage('rule', 'fieldname', 'error phrase') - which will only change the error phrase for
339
-         * that rule, applied on that field.
340
-         *
341
-         * @return boolean True on success, false on failure.
342
-         */
343
-        public function setMessage() {
344
-            $numArgs = func_num_args();
345
-            switch ($numArgs) {
346
-                default:
347
-                    return false;
348
-                // A global rule error message
349
-                case 2:
350
-                    foreach ($this->post(null) as $key => $val) {
351
-                        $this->_errorPhraseOverrides[$key][func_get_arg(0)] = func_get_arg(1);
352
-                    }
353
-                    break;
354
-                // Field specific rule error message
355
-                case 3:
356
-                    $this->_errorPhraseOverrides[func_get_arg(1)][func_get_arg(0)] = func_get_arg(2);
357
-                    break;
358
-            }
359
-            return true;
360
-        }
361
-
362
-        /**
363
-         * Adds a custom error message in the errorSet array, that will
364
-         * forcibly display it.
365
-         *
366
-         * @param string $inputName The form input name or data key
367
-         * @param string $errorMessage Error to display
368
-		 *
369
-         * @return formValidation Current instance of the object
370
-         */
371
-        public function setCustomError($inputName, $errorMessage) {
372
-            $errorMessage = str_replace('%1', $this->_labels[$inputName], $errorMessage);
373
-            $this->_errors[$inputName] = $errorMessage;
374
-            return $this;
375
-        }
376
-
377
-        /**
378
-         * Allows for an accesor to any/all post values, if a value of null is passed as the key, it
379
-         * will recursively find all keys/values of the $_POST array or data array. It also automatically trims
380
-         * all values.
381
-         *
382
-         * @param string $key Key of $this->data to be found, pass null for all Key => Val pairs.
383
-         * @param boolean $trim Defaults to true, trims all $this->data values.
384
-         * @return string|array Array of post or data values if null is passed as key, string if only one key is desired.
385
-         */
386
-        public function post($key = null, $trim = true) {
387
-            $returnValue = null;
388
-            if (is_null($key)) {
389
-                $returnValue = array();
390
-                foreach ($this->getData()  as $key => $val) {
391
-                    $returnValue[$key] = $this->post($key, $trim);
392
-                }
393
-            } else {
394
-                $returnValue = (array_key_exists($key, $this->getData())) ? (($trim) ? trim($this->data[$key]) : $this->data[$key]) : null;
395
-            }
396
-            return $returnValue;
397
-        }
398
-
399
-        /**
400
-         * Gets all errors from errorSet and displays them, can be echo out from the
401
-         * function or just returned.
402
-         *
403
-         * @param boolean $limit number of error to display or return
404
-         * @param boolean $echo Whether or not the values are to be returned or displayed
405
-		 *
406
-         * @return string Errors formatted for output
407
-         */
408
-        public function displayErrors($limit = null, $echo = true) {
409
-            list($errorsStart, $errorsEnd) = $this->_allErrorsDelimiter;
410
-            list($errorStart, $errorEnd) = $this->_eachErrorDelimiter;
411
-            $errorOutput = $errorsStart;
412
-    		$i = 0;
413
-            if (!empty($this->_errors)) {
414
-                foreach ($this->_errors as $fieldName => $error) {
415
-        	    	if ($i === $limit) { 
416
-                        break; 
417
-                    }
418
-                    $errorOutput .= $errorStart;
419
-                    $errorOutput .= $error;
420
-                    $errorOutput .= $errorEnd;
421
-                    $i++;
422
-                }
423
-            }
424
-            $errorOutput .= $errorsEnd;
425
-            echo ($echo) ? $errorOutput : '';
426
-            return (! $echo) ? $errorOutput : null;
427
-        }
428
-
429
-        /**
430
-         * Returns raw array of errors in no format instead of displaying them
431
-         * formatted.
432
-         *
433
-         * @return array
434
-         */
435
-        public function returnErrors() {
436
-            return $this->_errors;
437
-        }
438
-
439
-        /**
440
-         * Breaks up a PIPE seperated string of rules, and puts them into an array.
441
-         *
442
-         * @param string $ruleString String to be parsed.
443
-		 *
444
-         * @return array Array of each value in original string.
445
-         */
446
-        protected function _parseRuleString($ruleString) {
447
-            $ruleSets = array();
448
-            /*
294
+		 */
295
+		public function setErrorsDelimiter($start, $end) {
296
+			$this->_allErrorsDelimiter[0] = $start;
297
+			$this->_allErrorsDelimiter[1] = $end;
298
+			return $this;
299
+		}
300
+
301
+		/**
302
+		 * This is the individual error delimiter, each argument occurs once before and after
303
+		 * each individual error listed.
304
+		 *
305
+		 * @param string $start Displayed before each error.
306
+		 * @param string $end Displayed after each error.
307
+		 * 
308
+		 * @return FormValidation Current instance of object.
309
+		 */
310
+		public function setErrorDelimiter($start, $end) {
311
+			$this->_eachErrorDelimiter[0] = $start;
312
+			$this->_eachErrorDelimiter[1] = $end;
313
+			return $this;
314
+		}
315
+
316
+		/**
317
+		 * Get the each errors delimiters
318
+		 *
319
+		 * @return array
320
+		 */
321
+		public function getErrorDelimiter() {
322
+			return $this->_eachErrorDelimiter;
323
+		}
324
+
325
+		/**
326
+		 * Get the all errors delimiters
327
+		 *
328
+		 * @return array
329
+		 */
330
+		public function getErrorsDelimiter() {
331
+			return $this->_allErrorsDelimiter;
332
+		}
333
+
334
+		/**
335
+		 * This sets a custom error message that can override the default error phrase provided
336
+		 * by FormValidation, it can be used in the format of setMessage('rule', 'error phrase')
337
+		 * which will globally change the error phrase of that rule, or in the format of:
338
+		 * setMessage('rule', 'fieldname', 'error phrase') - which will only change the error phrase for
339
+		 * that rule, applied on that field.
340
+		 *
341
+		 * @return boolean True on success, false on failure.
342
+		 */
343
+		public function setMessage() {
344
+			$numArgs = func_num_args();
345
+			switch ($numArgs) {
346
+				default:
347
+					return false;
348
+				// A global rule error message
349
+				case 2:
350
+					foreach ($this->post(null) as $key => $val) {
351
+						$this->_errorPhraseOverrides[$key][func_get_arg(0)] = func_get_arg(1);
352
+					}
353
+					break;
354
+				// Field specific rule error message
355
+				case 3:
356
+					$this->_errorPhraseOverrides[func_get_arg(1)][func_get_arg(0)] = func_get_arg(2);
357
+					break;
358
+			}
359
+			return true;
360
+		}
361
+
362
+		/**
363
+		 * Adds a custom error message in the errorSet array, that will
364
+		 * forcibly display it.
365
+		 *
366
+		 * @param string $inputName The form input name or data key
367
+		 * @param string $errorMessage Error to display
368
+		 *
369
+		 * @return formValidation Current instance of the object
370
+		 */
371
+		public function setCustomError($inputName, $errorMessage) {
372
+			$errorMessage = str_replace('%1', $this->_labels[$inputName], $errorMessage);
373
+			$this->_errors[$inputName] = $errorMessage;
374
+			return $this;
375
+		}
376
+
377
+		/**
378
+		 * Allows for an accesor to any/all post values, if a value of null is passed as the key, it
379
+		 * will recursively find all keys/values of the $_POST array or data array. It also automatically trims
380
+		 * all values.
381
+		 *
382
+		 * @param string $key Key of $this->data to be found, pass null for all Key => Val pairs.
383
+		 * @param boolean $trim Defaults to true, trims all $this->data values.
384
+		 * @return string|array Array of post or data values if null is passed as key, string if only one key is desired.
385
+		 */
386
+		public function post($key = null, $trim = true) {
387
+			$returnValue = null;
388
+			if (is_null($key)) {
389
+				$returnValue = array();
390
+				foreach ($this->getData()  as $key => $val) {
391
+					$returnValue[$key] = $this->post($key, $trim);
392
+				}
393
+			} else {
394
+				$returnValue = (array_key_exists($key, $this->getData())) ? (($trim) ? trim($this->data[$key]) : $this->data[$key]) : null;
395
+			}
396
+			return $returnValue;
397
+		}
398
+
399
+		/**
400
+		 * Gets all errors from errorSet and displays them, can be echo out from the
401
+		 * function or just returned.
402
+		 *
403
+		 * @param boolean $limit number of error to display or return
404
+		 * @param boolean $echo Whether or not the values are to be returned or displayed
405
+		 *
406
+		 * @return string Errors formatted for output
407
+		 */
408
+		public function displayErrors($limit = null, $echo = true) {
409
+			list($errorsStart, $errorsEnd) = $this->_allErrorsDelimiter;
410
+			list($errorStart, $errorEnd) = $this->_eachErrorDelimiter;
411
+			$errorOutput = $errorsStart;
412
+			$i = 0;
413
+			if (!empty($this->_errors)) {
414
+				foreach ($this->_errors as $fieldName => $error) {
415
+					if ($i === $limit) { 
416
+						break; 
417
+					}
418
+					$errorOutput .= $errorStart;
419
+					$errorOutput .= $error;
420
+					$errorOutput .= $errorEnd;
421
+					$i++;
422
+				}
423
+			}
424
+			$errorOutput .= $errorsEnd;
425
+			echo ($echo) ? $errorOutput : '';
426
+			return (! $echo) ? $errorOutput : null;
427
+		}
428
+
429
+		/**
430
+		 * Returns raw array of errors in no format instead of displaying them
431
+		 * formatted.
432
+		 *
433
+		 * @return array
434
+		 */
435
+		public function returnErrors() {
436
+			return $this->_errors;
437
+		}
438
+
439
+		/**
440
+		 * Breaks up a PIPE seperated string of rules, and puts them into an array.
441
+		 *
442
+		 * @param string $ruleString String to be parsed.
443
+		 *
444
+		 * @return array Array of each value in original string.
445
+		 */
446
+		protected function _parseRuleString($ruleString) {
447
+			$ruleSets = array();
448
+			/*
449 449
             //////////////// hack for regex rule that can contain "|"
450 450
             */
451
-            if(strpos($ruleString, 'regex') !== false){
452
-                $regexRule = array();
453
-                $rule = '#regex\[\/(.*)\/([a-zA-Z0-9]?)\]#';
454
-                preg_match($rule, $ruleString, $regexRule);
455
-                $ruleStringTemp = preg_replace($rule, '', $ruleString);
456
-                 if(!empty($regexRule[0])){
457
-                     $ruleSets[] = $regexRule[0];
458
-                 }
459
-                 $ruleStringRegex = explode('|', $ruleStringTemp);
460
-                foreach ($ruleStringRegex as $rule) {
461
-                    $rule = trim($rule);
462
-                    if($rule){
463
-                        $ruleSets[] = $rule;
464
-                    }
465
-                }
451
+			if(strpos($ruleString, 'regex') !== false){
452
+				$regexRule = array();
453
+				$rule = '#regex\[\/(.*)\/([a-zA-Z0-9]?)\]#';
454
+				preg_match($rule, $ruleString, $regexRule);
455
+				$ruleStringTemp = preg_replace($rule, '', $ruleString);
456
+				 if(!empty($regexRule[0])){
457
+					 $ruleSets[] = $regexRule[0];
458
+				 }
459
+				 $ruleStringRegex = explode('|', $ruleStringTemp);
460
+				foreach ($ruleStringRegex as $rule) {
461
+					$rule = trim($rule);
462
+					if($rule){
463
+						$ruleSets[] = $rule;
464
+					}
465
+				}
466 466
                  
467
-            }
468
-            /***********************************/
469
-            else{
470
-                if (strpos($ruleString, '|') !== FALSE) {
471
-                    $ruleSets = explode('|', $ruleString);
472
-                } else {
473
-                    $ruleSets[] = $ruleString;
474
-                }
475
-             }
476
-            return $ruleSets;
477
-        }
478
-
479
-        /**
480
-         * Returns whether or not a field obtains the rule "required".
481
-         *
482
-         * @param string $fieldName Field to check if required.
483
-		 *
484
-         * @return boolean Whether or not the field is required.
485
-         */
486
-        protected function _fieldIsRequired($fieldName) {
487
-            $rules = $this->_parseRuleString($this->_rules[$fieldName]);
488
-            return (in_array('required', $rules));
489
-        }
490
-
491
-        /**
492
-         * Takes a data input name, it's value, and the rule it's being validated against (ex: max_length[16])
493
-         * and adds an error to the errorSet if it fails validation of the rule.
494
-         *
495
-         * @param string $inputName Name or key of the validation data
496
-         * @param string $inputVal Value of the validation data
497
-         * @param string $ruleName Rule to be validated against, including args (exact_length[5])
498
-         * @return void
499
-         */
500
-        protected function _validateRule($inputName, $inputVal, $ruleName) {
501
-            $this->logger->debug('Rule validation of field [' .$inputName. '], value [' .$inputVal. '], rule [' .$ruleName. ']');
502
-            // Array to store args
503
-            $ruleArgs = array();
504
-
505
-            preg_match('/\[(.*)\]/', $ruleName, $ruleArgs);
506
-
507
-            // Get the rule arguments, realRule is just the base rule name
508
-            // Like min_length instead of min_length[3]
509
-            $ruleName = preg_replace('/\[(.*)\]/', '', $ruleName);
467
+			}
468
+			/***********************************/
469
+			else{
470
+				if (strpos($ruleString, '|') !== FALSE) {
471
+					$ruleSets = explode('|', $ruleString);
472
+				} else {
473
+					$ruleSets[] = $ruleString;
474
+				}
475
+			 }
476
+			return $ruleSets;
477
+		}
478
+
479
+		/**
480
+		 * Returns whether or not a field obtains the rule "required".
481
+		 *
482
+		 * @param string $fieldName Field to check if required.
483
+		 *
484
+		 * @return boolean Whether or not the field is required.
485
+		 */
486
+		protected function _fieldIsRequired($fieldName) {
487
+			$rules = $this->_parseRuleString($this->_rules[$fieldName]);
488
+			return (in_array('required', $rules));
489
+		}
490
+
491
+		/**
492
+		 * Takes a data input name, it's value, and the rule it's being validated against (ex: max_length[16])
493
+		 * and adds an error to the errorSet if it fails validation of the rule.
494
+		 *
495
+		 * @param string $inputName Name or key of the validation data
496
+		 * @param string $inputVal Value of the validation data
497
+		 * @param string $ruleName Rule to be validated against, including args (exact_length[5])
498
+		 * @return void
499
+		 */
500
+		protected function _validateRule($inputName, $inputVal, $ruleName) {
501
+			$this->logger->debug('Rule validation of field [' .$inputName. '], value [' .$inputVal. '], rule [' .$ruleName. ']');
502
+			// Array to store args
503
+			$ruleArgs = array();
504
+
505
+			preg_match('/\[(.*)\]/', $ruleName, $ruleArgs);
506
+
507
+			// Get the rule arguments, realRule is just the base rule name
508
+			// Like min_length instead of min_length[3]
509
+			$ruleName = preg_replace('/\[(.*)\]/', '', $ruleName);
510 510
             
511
-            if (method_exists($this, $this->_toCallCase($ruleName))) {
512
-                $methodToCall = $this->_toCallCase($ruleName);
513
-                call_user_func(array($this, $methodToCall), $inputName, $ruleName, $ruleArgs);
514
-            }
515
-            return;
516
-        }
517
-
518
-		/**
519
-		* Set error for the given field or key
520
-		*
521
-		* @param string $inputName the input or key name
522
-		* @param string $ruleName the rule name
523
-		* @param array|string $replacements
524
-		*/
525
-        protected function _setError($inputName, $ruleName, $replacements = array()) {
526
-            $rulePhraseKeyParts = explode(',', $ruleName);
527
-            $rulePhrase = null;
528
-            foreach ($rulePhraseKeyParts as $rulePhraseKeyPart) {
529
-                if (array_key_exists($rulePhraseKeyPart, $this->_errorsMessages)) {
530
-                    $rulePhrase = $this->_errorsMessages[$rulePhraseKeyPart];
531
-                } else {
532
-                    $rulePhrase = $rulePhrase[$rulePhraseKeyPart];
533
-                }
534
-            }
535
-            // Any overrides?
536
-            if (array_key_exists($inputName, $this->_errorPhraseOverrides) && array_key_exists($ruleName, $this->_errorPhraseOverrides[$inputName])) {
537
-                $rulePhrase = $this->_errorPhraseOverrides[$inputName][$ruleName];
538
-            }
539
-            // Type cast to array in case it's a string
540
-            $replacements = (array) $replacements;
511
+			if (method_exists($this, $this->_toCallCase($ruleName))) {
512
+				$methodToCall = $this->_toCallCase($ruleName);
513
+				call_user_func(array($this, $methodToCall), $inputName, $ruleName, $ruleArgs);
514
+			}
515
+			return;
516
+		}
517
+
518
+		/**
519
+		 * Set error for the given field or key
520
+		 *
521
+		 * @param string $inputName the input or key name
522
+		 * @param string $ruleName the rule name
523
+		 * @param array|string $replacements
524
+		 */
525
+		protected function _setError($inputName, $ruleName, $replacements = array()) {
526
+			$rulePhraseKeyParts = explode(',', $ruleName);
527
+			$rulePhrase = null;
528
+			foreach ($rulePhraseKeyParts as $rulePhraseKeyPart) {
529
+				if (array_key_exists($rulePhraseKeyPart, $this->_errorsMessages)) {
530
+					$rulePhrase = $this->_errorsMessages[$rulePhraseKeyPart];
531
+				} else {
532
+					$rulePhrase = $rulePhrase[$rulePhraseKeyPart];
533
+				}
534
+			}
535
+			// Any overrides?
536
+			if (array_key_exists($inputName, $this->_errorPhraseOverrides) && array_key_exists($ruleName, $this->_errorPhraseOverrides[$inputName])) {
537
+				$rulePhrase = $this->_errorPhraseOverrides[$inputName][$ruleName];
538
+			}
539
+			// Type cast to array in case it's a string
540
+			$replacements = (array) $replacements;
541 541
 			$replacementCount = count($replacements);
542
-            for ($i = 1; $i <= $replacementCount; $i++) {
543
-                $key = $i - 1;
544
-                $rulePhrase = str_replace('%' . $i, $replacements[$key], $rulePhrase);
545
-            }
546
-            if (! array_key_exists($inputName, $this->_errors)) {
547
-                $this->_errors[$inputName] = $rulePhrase;
548
-            }
549
-        }
550
-
551
-        /**
552
-         * Used to run a callback for the callback rule, as well as pass in a default
553
-         * argument of the post value. For example the username field having a rule:
554
-         * callback[userExists] will eval userExists(data[username]) - Note the use
555
-         * of eval over call_user_func is in case the function is not user defined.
556
-         *
557
-         * @param type $inputArg
558
-         * @param string $callbackFunc
559
-		 *
560
-         * @return mixed
561
-         */
562
-        protected function _runCallback($inputArg, $callbackFunc) {
542
+			for ($i = 1; $i <= $replacementCount; $i++) {
543
+				$key = $i - 1;
544
+				$rulePhrase = str_replace('%' . $i, $replacements[$key], $rulePhrase);
545
+			}
546
+			if (! array_key_exists($inputName, $this->_errors)) {
547
+				$this->_errors[$inputName] = $rulePhrase;
548
+			}
549
+		}
550
+
551
+		/**
552
+		 * Used to run a callback for the callback rule, as well as pass in a default
553
+		 * argument of the post value. For example the username field having a rule:
554
+		 * callback[userExists] will eval userExists(data[username]) - Note the use
555
+		 * of eval over call_user_func is in case the function is not user defined.
556
+		 *
557
+		 * @param type $inputArg
558
+		 * @param string $callbackFunc
559
+		 *
560
+		 * @return mixed
561
+		 */
562
+		protected function _runCallback($inputArg, $callbackFunc) {
563 563
 			return eval('return ' . $callbackFunc . '("' . $inputArg . '");');
564
-        }
565
-
566
-        /**
567
-         * Used for applying a rule only if the empty callback evaluates to true,
568
-         * for example required[funcName] - This runs funcName without passing any
569
-         * arguments.
570
-         *
571
-         * @param string $callbackFunc
572
-		 *
573
-         * @return mixed
574
-         */
575
-        protected function _runEmptyCallback($callbackFunc) {
576
-            return eval('return ' . $callbackFunc . '();');
577
-        }
578
-
579
-        /**
580
-         * Gets a specific label of a specific field input name.
581
-         *
582
-         * @param string $inputName
583
-		 *
584
-         * @return string
585
-         */
586
-        protected function _getLabel($inputName) {
587
-            return (array_key_exists($inputName, $this->_labels)) ? $this->_labels[$inputName] : $inputName;
588
-        }
564
+		}
565
+
566
+		/**
567
+		 * Used for applying a rule only if the empty callback evaluates to true,
568
+		 * for example required[funcName] - This runs funcName without passing any
569
+		 * arguments.
570
+		 *
571
+		 * @param string $callbackFunc
572
+		 *
573
+		 * @return mixed
574
+		 */
575
+		protected function _runEmptyCallback($callbackFunc) {
576
+			return eval('return ' . $callbackFunc . '();');
577
+		}
578
+
579
+		/**
580
+		 * Gets a specific label of a specific field input name.
581
+		 *
582
+		 * @param string $inputName
583
+		 *
584
+		 * @return string
585
+		 */
586
+		protected function _getLabel($inputName) {
587
+			return (array_key_exists($inputName, $this->_labels)) ? $this->_labels[$inputName] : $inputName;
588
+		}
589 589
 		
590
-        /**
591
-         * Peform validation for the rule "required"
592
-         * @param  string $inputName the form field or data key name used
593
-         * @param  string $ruleName  the rule name for this validation ("required")
594
-         * @param  array  $ruleArgs  the rules argument
595
-         */
590
+		/**
591
+		 * Peform validation for the rule "required"
592
+		 * @param  string $inputName the form field or data key name used
593
+		 * @param  string $ruleName  the rule name for this validation ("required")
594
+		 * @param  array  $ruleArgs  the rules argument
595
+		 */
596 596
 		protected function _validateRequired($inputName, $ruleName, array $ruleArgs) {
597
-            $inputVal = $this->post($inputName);
598
-            if(array_key_exists(1, $ruleArgs) && function_exists($ruleArgs[1])) {
599
-                $callbackReturn = $this->_runEmptyCallback($ruleArgs[1]);
600
-                if ($inputVal == '' && $callbackReturn == true) {
601
-                    $this->_setError($inputName, $ruleName, $this->_getLabel($inputName));
602
-                }
603
-            } 
597
+			$inputVal = $this->post($inputName);
598
+			if(array_key_exists(1, $ruleArgs) && function_exists($ruleArgs[1])) {
599
+				$callbackReturn = $this->_runEmptyCallback($ruleArgs[1]);
600
+				if ($inputVal == '' && $callbackReturn == true) {
601
+					$this->_setError($inputName, $ruleName, $this->_getLabel($inputName));
602
+				}
603
+			} 
604 604
 			else if($inputVal == '') {
605 605
 				$this->_setError($inputName, $ruleName, $this->_getLabel($inputName));
606
-            }
607
-        }
608
-
609
-        /**
610
-         * Perform validation for the honey pot so means for the validation to be failed
611
-         * @param  string $inputName the form field or data key name used
612
-         * @param  string $ruleName  the rule name for this validation
613
-         * @param  array  $ruleArgs  the rules argument
614
-         */
615
-        protected function _validateHoneypot($inputName, $ruleName, array $ruleArgs) {
616
-            if ($this->data[$inputName] != '') {
617
-                $this->_forceFail = true;
618
-            }
619
-        }
620
-
621
-        /**
622
-         * Peform validation for the rule "callback"
623
-         * @param  string $inputName the form field or data key name used
624
-         * @param  string $ruleName  the rule name for this validation ("callback")
625
-         * @param  array  $ruleArgs  the rules argument
626
-         */
627
-        protected function _validateCallback($inputName, $ruleName, array $ruleArgs) {
628
-            if (function_exists($ruleArgs[1]) && !empty($this->data[$inputName])) {
606
+			}
607
+		}
608
+
609
+		/**
610
+		 * Perform validation for the honey pot so means for the validation to be failed
611
+		 * @param  string $inputName the form field or data key name used
612
+		 * @param  string $ruleName  the rule name for this validation
613
+		 * @param  array  $ruleArgs  the rules argument
614
+		 */
615
+		protected function _validateHoneypot($inputName, $ruleName, array $ruleArgs) {
616
+			if ($this->data[$inputName] != '') {
617
+				$this->_forceFail = true;
618
+			}
619
+		}
620
+
621
+		/**
622
+		 * Peform validation for the rule "callback"
623
+		 * @param  string $inputName the form field or data key name used
624
+		 * @param  string $ruleName  the rule name for this validation ("callback")
625
+		 * @param  array  $ruleArgs  the rules argument
626
+		 */
627
+		protected function _validateCallback($inputName, $ruleName, array $ruleArgs) {
628
+			if (function_exists($ruleArgs[1]) && !empty($this->data[$inputName])) {
629 629
 				$result = $this->_runCallback($this->data[$inputName], $ruleArgs[1]);
630 630
 				if(! $result){
631 631
 					$this->_setError($inputName, $ruleName, array($this->_getLabel($inputName)));
632 632
 				}
633
-            }
634
-        }
635
-
636
-        /**
637
-         * Peform validation for the rule "depends"
638
-         * @param  string $inputName the form field or data key name used
639
-         * @param  string $ruleName  the rule name for this validation ("depends")
640
-         * @param  array  $ruleArgs  the rules argument
641
-         */
642
-        protected function _validateDepends($inputName, $ruleName, array $ruleArgs) {
643
-            if (array_key_exists($ruleArgs[1], $this->_errors)) {
644
-                $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName), $this->_getLabel($ruleArgs[1])));
645
-            }
646
-        }
647
-
648
-        /**
649
-         * Peform validation for the rule "not_equal"
650
-         * @param  string $inputName the form field or data key name used
651
-         * @param  string $ruleName  the rule name for this validation ("not_equal")
652
-         * @param  array  $ruleArgs  the rules argument
653
-         */
654
-        protected function _validateNotEqual($inputName, $ruleName, array $ruleArgs) {
655
-            $canNotEqual = explode(',', $ruleArgs[1]);
656
-            foreach ($canNotEqual as $doNotEqual) {
657
-                $inputVal = $this->post($inputName);
658
-                if (preg_match('/post:(.*)/', $doNotEqual)) {
659
-                    if ($inputVal == $this->data[str_replace('post:', '', $doNotEqual)]) {
660
-                        $this->_setError($inputName, $ruleName . ',post:key', array($this->_getLabel($inputName), $this->_getLabel(str_replace('post:', '', $doNotEqual))));
661
-                        continue;
662
-                    }
663
-                } 
633
+			}
634
+		}
635
+
636
+		/**
637
+		 * Peform validation for the rule "depends"
638
+		 * @param  string $inputName the form field or data key name used
639
+		 * @param  string $ruleName  the rule name for this validation ("depends")
640
+		 * @param  array  $ruleArgs  the rules argument
641
+		 */
642
+		protected function _validateDepends($inputName, $ruleName, array $ruleArgs) {
643
+			if (array_key_exists($ruleArgs[1], $this->_errors)) {
644
+				$this->_setError($inputName, $ruleName, array($this->_getLabel($inputName), $this->_getLabel($ruleArgs[1])));
645
+			}
646
+		}
647
+
648
+		/**
649
+		 * Peform validation for the rule "not_equal"
650
+		 * @param  string $inputName the form field or data key name used
651
+		 * @param  string $ruleName  the rule name for this validation ("not_equal")
652
+		 * @param  array  $ruleArgs  the rules argument
653
+		 */
654
+		protected function _validateNotEqual($inputName, $ruleName, array $ruleArgs) {
655
+			$canNotEqual = explode(',', $ruleArgs[1]);
656
+			foreach ($canNotEqual as $doNotEqual) {
657
+				$inputVal = $this->post($inputName);
658
+				if (preg_match('/post:(.*)/', $doNotEqual)) {
659
+					if ($inputVal == $this->data[str_replace('post:', '', $doNotEqual)]) {
660
+						$this->_setError($inputName, $ruleName . ',post:key', array($this->_getLabel($inputName), $this->_getLabel(str_replace('post:', '', $doNotEqual))));
661
+						continue;
662
+					}
663
+				} 
664 664
 				else{
665
-                    if ($inputVal == $doNotEqual) {
666
-                        $this->_setError($inputName, $ruleName . ',string', array($this->_getLabel($inputName), $doNotEqual));
667
-                        continue;
668
-                    }
669
-                }
670
-            }
671
-        }
672
-
673
-        /**
674
-         * Peform validation for the rule "matches"
675
-         * @param  string $inputName the form field or data key name used
676
-         * @param  string $ruleName  the rule name for this validation ("matches")
677
-         * @param  array  $ruleArgs  the rules argument
678
-         */
679
-        protected function _validateMatches($inputName, $ruleName, array $ruleArgs) {
680
-            $inputVal = $this->post($inputName);
681
-            if ($inputVal != $this->data[$ruleArgs[1]]) {
682
-                $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName), $this->_getLabel($ruleArgs[1])));
683
-            }
684
-        }
685
-
686
-        /**
687
-         * Peform validation for the rule "valid_email"
688
-         * @param  string $inputName the form field or data key name used
689
-         * @param  string $ruleName  the rule name for this validation ("valid_email")
690
-         * @param  array  $ruleArgs  the rules argument
691
-         */
692
-        protected function _validateValidEmail($inputName, $ruleName, array $ruleArgs) {
693
-            $inputVal = $this->post($inputName);
694
-            if (! preg_match("/^([\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+\.)*[\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+@((((([a-z0-9]{1}[a-z0-9\-]{0,62}[a-z0-9]{1})|[a-z])\.)+[a-z]{2,6})|(\d{1,3}\.){3}\d{1,3}(\:\d{1,5})?)$/i", $inputVal)) {
695
-                if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
696
-                    return;
697
-                }
698
-                $this->_setError($inputName, $ruleName, $this->_getLabel($inputName));
699
-            }
700
-        }
701
-
702
-        /**
703
-         * Peform validation for the rule "exact_length"
704
-         * @param  string $inputName the form field or data key name used
705
-         * @param  string $ruleName  the rule name for this validation ("exact_length")
706
-         * @param  array  $ruleArgs  the rules argument
707
-         */
708
-        protected function _validateExactLength($inputName, $ruleName, array $ruleArgs) {
709
-            $inputVal = $this->post($inputName);
710
-            if (strlen($inputVal) != $ruleArgs[1]) { // $ruleArgs[0] is [length] $rulesArgs[1] is just length
711
-                if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
712
-                    return;
713
-                }
714
-                $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName), $this->_getLabel($ruleArgs[1])));
715
-            }
716
-        }
717
-
718
-        /**
719
-         * Peform validation for the rule "max_length"
720
-         * @param  string $inputName the form field or data key name used
721
-         * @param  string $ruleName  the rule name for this validation ("max_length")
722
-         * @param  array  $ruleArgs  the rules argument
723
-         */
724
-        protected function _validateMaxLength($inputName, $ruleName, array $ruleArgs) {
725
-            $inputVal = $this->post($inputName);
726
-            if (strlen($inputVal) > $ruleArgs[1]) { // $ruleArgs[0] is [length] $rulesArgs[1] is just length
727
-                if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
728
-                    return;
729
-                }
730
-                $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName), $this->_getLabel($ruleArgs[1])));
731
-            }
732
-        }
733
-
734
-        /**
735
-         * Peform validation for the rule "min_length"
736
-         * @param  string $inputName the form field or data key name used
737
-         * @param  string $ruleName  the rule name for this validation ("min_length")
738
-         * @param  array  $ruleArgs  the rules argument
739
-         */
740
-        protected function _validateMinLength($inputName, $ruleName, array $ruleArgs) {
741
-            $inputVal = $this->post($inputName);
742
-            if (strlen($inputVal) < $ruleArgs[1]) { // $ruleArgs[0] is [length] $rulesArgs[1] is just length
743
-                if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
744
-                    return;
745
-                }
746
-                $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName), $this->_getLabel($ruleArgs[1])));
747
-            }
748
-        }
665
+					if ($inputVal == $doNotEqual) {
666
+						$this->_setError($inputName, $ruleName . ',string', array($this->_getLabel($inputName), $doNotEqual));
667
+						continue;
668
+					}
669
+				}
670
+			}
671
+		}
672
+
673
+		/**
674
+		 * Peform validation for the rule "matches"
675
+		 * @param  string $inputName the form field or data key name used
676
+		 * @param  string $ruleName  the rule name for this validation ("matches")
677
+		 * @param  array  $ruleArgs  the rules argument
678
+		 */
679
+		protected function _validateMatches($inputName, $ruleName, array $ruleArgs) {
680
+			$inputVal = $this->post($inputName);
681
+			if ($inputVal != $this->data[$ruleArgs[1]]) {
682
+				$this->_setError($inputName, $ruleName, array($this->_getLabel($inputName), $this->_getLabel($ruleArgs[1])));
683
+			}
684
+		}
685
+
686
+		/**
687
+		 * Peform validation for the rule "valid_email"
688
+		 * @param  string $inputName the form field or data key name used
689
+		 * @param  string $ruleName  the rule name for this validation ("valid_email")
690
+		 * @param  array  $ruleArgs  the rules argument
691
+		 */
692
+		protected function _validateValidEmail($inputName, $ruleName, array $ruleArgs) {
693
+			$inputVal = $this->post($inputName);
694
+			if (! preg_match("/^([\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+\.)*[\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+@((((([a-z0-9]{1}[a-z0-9\-]{0,62}[a-z0-9]{1})|[a-z])\.)+[a-z]{2,6})|(\d{1,3}\.){3}\d{1,3}(\:\d{1,5})?)$/i", $inputVal)) {
695
+				if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
696
+					return;
697
+				}
698
+				$this->_setError($inputName, $ruleName, $this->_getLabel($inputName));
699
+			}
700
+		}
701
+
702
+		/**
703
+		 * Peform validation for the rule "exact_length"
704
+		 * @param  string $inputName the form field or data key name used
705
+		 * @param  string $ruleName  the rule name for this validation ("exact_length")
706
+		 * @param  array  $ruleArgs  the rules argument
707
+		 */
708
+		protected function _validateExactLength($inputName, $ruleName, array $ruleArgs) {
709
+			$inputVal = $this->post($inputName);
710
+			if (strlen($inputVal) != $ruleArgs[1]) { // $ruleArgs[0] is [length] $rulesArgs[1] is just length
711
+				if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
712
+					return;
713
+				}
714
+				$this->_setError($inputName, $ruleName, array($this->_getLabel($inputName), $this->_getLabel($ruleArgs[1])));
715
+			}
716
+		}
717
+
718
+		/**
719
+		 * Peform validation for the rule "max_length"
720
+		 * @param  string $inputName the form field or data key name used
721
+		 * @param  string $ruleName  the rule name for this validation ("max_length")
722
+		 * @param  array  $ruleArgs  the rules argument
723
+		 */
724
+		protected function _validateMaxLength($inputName, $ruleName, array $ruleArgs) {
725
+			$inputVal = $this->post($inputName);
726
+			if (strlen($inputVal) > $ruleArgs[1]) { // $ruleArgs[0] is [length] $rulesArgs[1] is just length
727
+				if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
728
+					return;
729
+				}
730
+				$this->_setError($inputName, $ruleName, array($this->_getLabel($inputName), $this->_getLabel($ruleArgs[1])));
731
+			}
732
+		}
733
+
734
+		/**
735
+		 * Peform validation for the rule "min_length"
736
+		 * @param  string $inputName the form field or data key name used
737
+		 * @param  string $ruleName  the rule name for this validation ("min_length")
738
+		 * @param  array  $ruleArgs  the rules argument
739
+		 */
740
+		protected function _validateMinLength($inputName, $ruleName, array $ruleArgs) {
741
+			$inputVal = $this->post($inputName);
742
+			if (strlen($inputVal) < $ruleArgs[1]) { // $ruleArgs[0] is [length] $rulesArgs[1] is just length
743
+				if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
744
+					return;
745
+				}
746
+				$this->_setError($inputName, $ruleName, array($this->_getLabel($inputName), $this->_getLabel($ruleArgs[1])));
747
+			}
748
+		}
749 749
     	
750
-        /**
751
-         * Peform validation for the rule "less_than"
752
-         * @param  string $inputName the form field or data key name used
753
-         * @param  string $ruleName  the rule name for this validation ("less_than")
754
-         * @param  array  $ruleArgs  the rules argument
755
-         */
756
-    	protected function _validateLessThan($inputName, $ruleName, array $ruleArgs) {
757
-            $inputVal = $this->post($inputName);
758
-            if ($inputVal >= $ruleArgs[1]) { 
759
-                if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
760
-                    return;
761
-                }
762
-                $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName), $this->_getLabel($ruleArgs[1])));
763
-            }
764
-        }
750
+		/**
751
+		 * Peform validation for the rule "less_than"
752
+		 * @param  string $inputName the form field or data key name used
753
+		 * @param  string $ruleName  the rule name for this validation ("less_than")
754
+		 * @param  array  $ruleArgs  the rules argument
755
+		 */
756
+		protected function _validateLessThan($inputName, $ruleName, array $ruleArgs) {
757
+			$inputVal = $this->post($inputName);
758
+			if ($inputVal >= $ruleArgs[1]) { 
759
+				if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
760
+					return;
761
+				}
762
+				$this->_setError($inputName, $ruleName, array($this->_getLabel($inputName), $this->_getLabel($ruleArgs[1])));
763
+			}
764
+		}
765 765
     	
766
-        /**
767
-         * Peform validation for the rule "greater_than"
768
-         * @param  string $inputName the form field or data key name used
769
-         * @param  string $ruleName  the rule name for this validation ("greater_than")
770
-         * @param  array  $ruleArgs  the rules argument
771
-         */
772
-    	protected function _validateGreaterThan($inputName, $ruleName, array $ruleArgs) {
773
-            $inputVal = $this->post($inputName);
774
-            if ($inputVal <= $ruleArgs[1]) {
775
-                if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
776
-                    return;
777
-                }
778
-                $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName), $this->_getLabel($ruleArgs[1])));
779
-            }
780
-        }
766
+		/**
767
+		 * Peform validation for the rule "greater_than"
768
+		 * @param  string $inputName the form field or data key name used
769
+		 * @param  string $ruleName  the rule name for this validation ("greater_than")
770
+		 * @param  array  $ruleArgs  the rules argument
771
+		 */
772
+		protected function _validateGreaterThan($inputName, $ruleName, array $ruleArgs) {
773
+			$inputVal = $this->post($inputName);
774
+			if ($inputVal <= $ruleArgs[1]) {
775
+				if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
776
+					return;
777
+				}
778
+				$this->_setError($inputName, $ruleName, array($this->_getLabel($inputName), $this->_getLabel($ruleArgs[1])));
779
+			}
780
+		}
781 781
     	
782
-        /**
783
-         * Peform validation for the rule "numeric"
784
-         * @param  string $inputName the form field or data key name used
785
-         * @param  string $ruleName  the rule name for this validation ("numeric")
786
-         * @param  array  $ruleArgs  the rules argument
787
-         */
788
-    	protected function _validateNumeric($inputName, $ruleName, array $ruleArgs) {
789
-            $inputVal = $this->post($inputName);
790
-            if (! is_numeric($inputVal)) {
791
-                if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
792
-                    return;
793
-                }
794
-                $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName)));
795
-            }
796
-        }
782
+		/**
783
+		 * Peform validation for the rule "numeric"
784
+		 * @param  string $inputName the form field or data key name used
785
+		 * @param  string $ruleName  the rule name for this validation ("numeric")
786
+		 * @param  array  $ruleArgs  the rules argument
787
+		 */
788
+		protected function _validateNumeric($inputName, $ruleName, array $ruleArgs) {
789
+			$inputVal = $this->post($inputName);
790
+			if (! is_numeric($inputVal)) {
791
+				if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
792
+					return;
793
+				}
794
+				$this->_setError($inputName, $ruleName, array($this->_getLabel($inputName)));
795
+			}
796
+		}
797 797
 		
798
-        /**
799
-         * Peform validation for the rule "exists"
800
-         * @param  string $inputName the form field or data key name used
801
-         * @param  string $ruleName  the rule name for this validation ("exists")
802
-         * @param  array  $ruleArgs  the rules argument
803
-         */
798
+		/**
799
+		 * Peform validation for the rule "exists"
800
+		 * @param  string $inputName the form field or data key name used
801
+		 * @param  string $ruleName  the rule name for this validation ("exists")
802
+		 * @param  array  $ruleArgs  the rules argument
803
+		 */
804 804
 		protected function _validateExists($inputName, $ruleName, array $ruleArgs) {
805
-            $inputVal = $this->post($inputName);
806
-    		$obj = & get_instance();
807
-    		if(! isset($obj->database)){
808
-    			return;
809
-    		}
810
-    		list($table, $column) = explode('.', $ruleArgs[1]);
811
-    		$obj->database->from($table)
812
-    			          ->where($column, $inputVal)
813
-    			          ->get();
814
-    		$nb = $obj->database->numRows();
815
-            if ($nb == 0) {
816
-                if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
817
-                    return;
818
-                }
819
-                $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName)));
820
-            }
821
-        }
822
-
823
-        /**
824
-         * Peform validation for the rule "is_unique"
825
-         * @param  string $inputName the form field or data key name used
826
-         * @param  string $ruleName  the rule name for this validation ("is_unique")
827
-         * @param  array  $ruleArgs  the rules argument
828
-         */
829
-    	protected function _validateIsUnique($inputName, $ruleName, array $ruleArgs) {
830
-            $inputVal = $this->post($inputName);
831
-    		$obj = & get_instance();
832
-    		if(! isset($obj->database)){
833
-    			return;
834
-    		}
835
-    		list($table, $column) = explode('.', $ruleArgs[1]);
836
-    		$obj->database->from($table)
837
-    			          ->where($column, $inputVal)
838
-    			          ->get();
839
-    		$nb = $obj->database->numRows();
840
-            if ($nb != 0) {
841
-                if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
842
-                    return;
843
-                }
844
-                $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName)));
845
-            }
846
-        }
805
+			$inputVal = $this->post($inputName);
806
+			$obj = & get_instance();
807
+			if(! isset($obj->database)){
808
+				return;
809
+			}
810
+			list($table, $column) = explode('.', $ruleArgs[1]);
811
+			$obj->database->from($table)
812
+						  ->where($column, $inputVal)
813
+						  ->get();
814
+			$nb = $obj->database->numRows();
815
+			if ($nb == 0) {
816
+				if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
817
+					return;
818
+				}
819
+				$this->_setError($inputName, $ruleName, array($this->_getLabel($inputName)));
820
+			}
821
+		}
822
+
823
+		/**
824
+		 * Peform validation for the rule "is_unique"
825
+		 * @param  string $inputName the form field or data key name used
826
+		 * @param  string $ruleName  the rule name for this validation ("is_unique")
827
+		 * @param  array  $ruleArgs  the rules argument
828
+		 */
829
+		protected function _validateIsUnique($inputName, $ruleName, array $ruleArgs) {
830
+			$inputVal = $this->post($inputName);
831
+			$obj = & get_instance();
832
+			if(! isset($obj->database)){
833
+				return;
834
+			}
835
+			list($table, $column) = explode('.', $ruleArgs[1]);
836
+			$obj->database->from($table)
837
+						  ->where($column, $inputVal)
838
+						  ->get();
839
+			$nb = $obj->database->numRows();
840
+			if ($nb != 0) {
841
+				if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
842
+					return;
843
+				}
844
+				$this->_setError($inputName, $ruleName, array($this->_getLabel($inputName)));
845
+			}
846
+		}
847 847
     	
848
-        /**
849
-         * Peform validation for the rule "is_unique_update"
850
-         * @param  string $inputName the form field or data key name used
851
-         * @param  string $ruleName  the rule name for this validation ("is_unique_update")
852
-         * @param  array  $ruleArgs  the rules argument
853
-         */
854
-    	protected function _validateIsUniqueUpdate($inputName, $ruleName, array $ruleArgs) {
855
-            $inputVal = $this->post($inputName);
856
-    		$obj = & get_instance();
857
-    		if(! isset($obj->database)){
858
-    			return;
859
-    		}
860
-    		$data = explode(',', $ruleArgs[1]);
861
-    		if(count($data) < 2){
862
-    			return;
863
-    		}
864
-    		list($table, $column) = explode('.', $data[0]);
865
-    		list($field, $val) = explode('=', $data[1]);
866
-    		$obj->database->from($table)
867
-    			          ->where($column, $inputVal)
868
-                		  ->where($field, '!=', trim($val))
869
-                		  ->get();
870
-    		$nb = $obj->database->numRows();
871
-            if ($nb != 0) {
872
-                if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
873
-                    return;
874
-                }
875
-                $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName)));
876
-            }
877
-        }
878
-
879
-        /**
880
-         * Peform validation for the rule "in_list"
881
-         * @param  string $inputName the form field or data key name used
882
-         * @param  string $ruleName  the rule name for this validation ("in_list")
883
-         * @param  array  $ruleArgs  the rules argument
884
-         */
885
-        protected function _validateInList($inputName, $ruleName, array $ruleArgs) {
886
-            $inputVal = $this->post($inputName);
887
-    		$list = explode(',', $ruleArgs[1]);
888
-            $list = array_map('trim', $list);
889
-            if (! in_array($inputVal, $list)) {
890
-                if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
891
-                    return;
892
-                }
893
-                $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName), $this->_getLabel($ruleArgs[1])));
894
-            }
895
-        }
896
-
897
-        /**
898
-         * Peform validation for the rule "regex"
899
-         * @param  string $inputName the form field or data key name used
900
-         * @param  string $ruleName  the rule name for this validation ("regex")
901
-         * @param  array  $ruleArgs  the rules argument
902
-         */
903
-        protected function _validateRegex($inputName, $ruleName, array $ruleArgs) {
904
-            $inputVal = $this->post($inputName);
905
-    		$regex = $ruleArgs[1];
906
-            if (! preg_match($regex, $inputVal)) {
907
-                if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
908
-                    return;
909
-                }
910
-                $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName)));
911
-            }
912
-        }
848
+		/**
849
+		 * Peform validation for the rule "is_unique_update"
850
+		 * @param  string $inputName the form field or data key name used
851
+		 * @param  string $ruleName  the rule name for this validation ("is_unique_update")
852
+		 * @param  array  $ruleArgs  the rules argument
853
+		 */
854
+		protected function _validateIsUniqueUpdate($inputName, $ruleName, array $ruleArgs) {
855
+			$inputVal = $this->post($inputName);
856
+			$obj = & get_instance();
857
+			if(! isset($obj->database)){
858
+				return;
859
+			}
860
+			$data = explode(',', $ruleArgs[1]);
861
+			if(count($data) < 2){
862
+				return;
863
+			}
864
+			list($table, $column) = explode('.', $data[0]);
865
+			list($field, $val) = explode('=', $data[1]);
866
+			$obj->database->from($table)
867
+						  ->where($column, $inputVal)
868
+						  ->where($field, '!=', trim($val))
869
+						  ->get();
870
+			$nb = $obj->database->numRows();
871
+			if ($nb != 0) {
872
+				if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
873
+					return;
874
+				}
875
+				$this->_setError($inputName, $ruleName, array($this->_getLabel($inputName)));
876
+			}
877
+		}
878
+
879
+		/**
880
+		 * Peform validation for the rule "in_list"
881
+		 * @param  string $inputName the form field or data key name used
882
+		 * @param  string $ruleName  the rule name for this validation ("in_list")
883
+		 * @param  array  $ruleArgs  the rules argument
884
+		 */
885
+		protected function _validateInList($inputName, $ruleName, array $ruleArgs) {
886
+			$inputVal = $this->post($inputName);
887
+			$list = explode(',', $ruleArgs[1]);
888
+			$list = array_map('trim', $list);
889
+			if (! in_array($inputVal, $list)) {
890
+				if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
891
+					return;
892
+				}
893
+				$this->_setError($inputName, $ruleName, array($this->_getLabel($inputName), $this->_getLabel($ruleArgs[1])));
894
+			}
895
+		}
896
+
897
+		/**
898
+		 * Peform validation for the rule "regex"
899
+		 * @param  string $inputName the form field or data key name used
900
+		 * @param  string $ruleName  the rule name for this validation ("regex")
901
+		 * @param  array  $ruleArgs  the rules argument
902
+		 */
903
+		protected function _validateRegex($inputName, $ruleName, array $ruleArgs) {
904
+			$inputVal = $this->post($inputName);
905
+			$regex = $ruleArgs[1];
906
+			if (! preg_match($regex, $inputVal)) {
907
+				if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
908
+					return;
909
+				}
910
+				$this->_setError($inputName, $ruleName, array($this->_getLabel($inputName)));
911
+			}
912
+		}
913 913
         
914
-    }
914
+	}
Please login to merge, or discard this patch.
tests/bootstrap.php 1 patch
Indentation   +128 added lines, -128 removed lines patch added patch discarded remove patch
@@ -21,21 +21,21 @@  discard block
 block discarded – undo
21 21
 	 * You should have received a copy of the GNU General Public License
22 22
 	 * along with this program; if not, write to the Free Software
23 23
 	 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
24
-	*/
24
+	 */
25 25
 	
26 26
 	error_reporting(E_ALL | E_STRICT);
27 27
 	ini_set('display_errors', 1);
28 28
 
29 29
 	/**
30
-	* the directory separator, under windows it is \ and unix, linux /
31
-	*/
30
+	 * the directory separator, under windows it is \ and unix, linux /
31
+	 */
32 32
 	define('DS', DIRECTORY_SEPARATOR);
33 33
 
34 34
 	/**
35
-	* The root directory of the application.
36
-	*
37
-	* you can place this directory outside of your web directory, for example "/home/your_app", etc.
38
-	*/
35
+	 * The root directory of the application.
36
+	 *
37
+	 * you can place this directory outside of your web directory, for example "/home/your_app", etc.
38
+	 */
39 39
 	define('ROOT_PATH', dirname(realpath(__FILE__)) . DS . '..' . DS);
40 40
 	
41 41
 	//tests dir path
@@ -43,176 +43,176 @@  discard block
 block discarded – undo
43 43
 
44 44
 
45 45
 	/**
46
-	* The path to the directory.
47
-	*
48
-	* That contains your static files (javascript, css, images, etc.)
49
-	* Note: the path must be relative to the file index.php (the front-end controller).
50
-	*/
46
+	 * The path to the directory.
47
+	 *
48
+	 * That contains your static files (javascript, css, images, etc.)
49
+	 * Note: the path must be relative to the file index.php (the front-end controller).
50
+	 */
51 51
 	define('ASSETS_PATH', 'assets/');
52 52
 
53 53
 	/**
54
-	* The path to the directory of your cache files.
55
-	*
56
-	* This feature is available currently for database and views.
57
-	*/
54
+	 * The path to the directory of your cache files.
55
+	 *
56
+	 * This feature is available currently for database and views.
57
+	 */
58 58
 	define('CACHE_PATH', ROOT_PATH . 'cache' . DS);
59 59
 
60 60
 	/**
61
-	* Custom application path for tests 
62
-	*/
61
+	 * Custom application path for tests 
62
+	 */
63 63
 	define('APPS_PATH', TESTS_PATH .'hmvc' . DS);
64 64
 
65 65
 	/**
66
-	* The path to the controller directory of your application.
67
-	*
68
-	* If you already know the MVC architecture you know what a controller means; 
69
-	* it is he who makes the business logic of your application in general.
70
-	*/
66
+	 * The path to the controller directory of your application.
67
+	 *
68
+	 * If you already know the MVC architecture you know what a controller means; 
69
+	 * it is he who makes the business logic of your application in general.
70
+	 */
71 71
 	define('APPS_CONTROLLER_PATH', APPS_PATH . 'controllers' . DS);
72 72
 
73 73
 	/**
74
-	* The path to the directory of your model classes of your application. 
75
-	*
76
-	* If you already know the MVC architecture you know what a model means; 
77
-	* it's the one who interacts with the database, in one word persistent data from your application.
78
-	*/
74
+	 * The path to the directory of your model classes of your application. 
75
+	 *
76
+	 * If you already know the MVC architecture you know what a model means; 
77
+	 * it's the one who interacts with the database, in one word persistent data from your application.
78
+	 */
79 79
 	define('APPS_MODEL_PATH', APPS_PATH . 'models' . DS);
80 80
 
81 81
 	/**
82
-	* The path to the directory of your views.
83
-	*
84
-	* If you already know the MVC architecture you know what a view means, 
85
-	* a view is just a user interface (html page, form, etc.) that is to say 
86
-	* everything displayed in the browser interface, etc.
87
-	*/
82
+	 * The path to the directory of your views.
83
+	 *
84
+	 * If you already know the MVC architecture you know what a view means, 
85
+	 * a view is just a user interface (html page, form, etc.) that is to say 
86
+	 * everything displayed in the browser interface, etc.
87
+	 */
88 88
 	define('APPS_VIEWS_PATH', APPS_PATH . 'views' . DS);
89 89
 
90 90
 	/**
91
-	* The path to the configuration directory.
92
-	*
93
-	* That contains most of the configuration files for your 
94
-	* application (database, class loading file, functions, etc.)
95
-	*/
91
+	 * The path to the configuration directory.
92
+	 *
93
+	 * That contains most of the configuration files for your 
94
+	 * application (database, class loading file, functions, etc.)
95
+	 */
96 96
 	define('CONFIG_PATH', ROOT_PATH . 'config' . DS);
97 97
 
98 98
 	/** 
99
-	* The core directory
100
-	*
101
-	* It is recommended to put this folder out of the web directory of your server and 
102
-	* you should not change its content because in case of update you could lose the modified files.
103
-	*/
99
+	 * The core directory
100
+	 *
101
+	 * It is recommended to put this folder out of the web directory of your server and 
102
+	 * you should not change its content because in case of update you could lose the modified files.
103
+	 */
104 104
 	define('CORE_PATH', ROOT_PATH . 'core' . DS);
105 105
 	
106 106
 	/**
107
-	* The path to the directory of core classes that used by the system.
108
-	*
109
-	* It contains PHP classes that are used by the framework internally.
110
-	*/
107
+	 * The path to the directory of core classes that used by the system.
108
+	 *
109
+	 * It contains PHP classes that are used by the framework internally.
110
+	 */
111 111
 	define('CORE_CLASSES_PATH', CORE_PATH . 'classes' . DS);
112 112
 	
113 113
 	/**
114
-	* The path to the directory of core classes for the cache used by the system.
115
-	*
116
-	* It contains PHP classes for the cache drivers.
117
-	*/
114
+	 * The path to the directory of core classes for the cache used by the system.
115
+	 *
116
+	 * It contains PHP classes for the cache drivers.
117
+	 */
118 118
 	define('CORE_CLASSES_CACHE_PATH', CORE_CLASSES_PATH . 'cache' . DS);
119 119
 	
120 120
 	/**
121
-	* The path to the directory of core classes for the model used by the system.
122
-	*
123
-	* It contains PHP classes for the models.
124
-	*/
121
+	 * The path to the directory of core classes for the model used by the system.
122
+	 *
123
+	 * It contains PHP classes for the models.
124
+	 */
125 125
 	define('CORE_CLASSES_MODEL_PATH', CORE_CLASSES_PATH . 'model' . DS);
126 126
 
127 127
 	/**
128
-	* The path to the directory of functions or helper systems.
129
-	*
130
-	* It contains PHP functions that perform a particular task: character string processing, URL, etc.
131
-	*/
128
+	 * The path to the directory of functions or helper systems.
129
+	 *
130
+	 * It contains PHP functions that perform a particular task: character string processing, URL, etc.
131
+	 */
132 132
 	define('CORE_FUNCTIONS_PATH', CORE_PATH . 'functions' . DS);
133 133
 
134 134
 	/**
135
-	* The path to the core directory of languages files. 
136
-	*
137
-	*/
135
+	 * The path to the core directory of languages files. 
136
+	 *
137
+	 */
138 138
 	define('CORE_LANG_PATH', CORE_PATH . 'lang' . DS);
139 139
 
140 140
 	/**
141
-	* The path to the system library directory.
142
-	*
143
-	* Which contains the libraries most often used in your web application, as for the 
144
-	* core directory it is advisable to put it out of the root directory of your application.
145
-	*/
141
+	 * The path to the system library directory.
142
+	 *
143
+	 * Which contains the libraries most often used in your web application, as for the 
144
+	 * core directory it is advisable to put it out of the root directory of your application.
145
+	 */
146 146
 	define('CORE_LIBRARY_PATH', CORE_PATH . 'libraries' . DS);
147 147
 
148 148
 	/**
149
-	* The path to the system view directory.
150
-	*
151
-	* That contains the views used for the system, such as error messages, and so on.
152
-	*/
149
+	 * The path to the system view directory.
150
+	 *
151
+	 * That contains the views used for the system, such as error messages, and so on.
152
+	 */
153 153
 	define('CORE_VIEWS_PATH', CORE_PATH . 'views' . DS);
154 154
 	
155 155
 	/**
156
-	* The path to the directory of your PHP personal functions or helper.
157
-	*
158
-	* It contains your PHP functions that perform a particular task: utilities, etc.
159
-	* Note: Do not put your personal functions or helpers in the system functions directory, 
160
-	* because if you update the system you may lose them.
161
-	*/
156
+	 * The path to the directory of your PHP personal functions or helper.
157
+	 *
158
+	 * It contains your PHP functions that perform a particular task: utilities, etc.
159
+	 * Note: Do not put your personal functions or helpers in the system functions directory, 
160
+	 * because if you update the system you may lose them.
161
+	 */
162 162
 	define('FUNCTIONS_PATH', ROOT_PATH . 'functions' . DS);
163 163
 
164 164
 	/**
165
-	* The path to the app directory of personal language. 
166
-	*
167
-	* This feature is not yet available. 
168
-	* You can help us do this if you are nice or wish to see the developed framework.
169
-	*/
165
+	 * The path to the app directory of personal language. 
166
+	 *
167
+	 * This feature is not yet available. 
168
+	 * You can help us do this if you are nice or wish to see the developed framework.
169
+	 */
170 170
 	define('APP_LANG_PATH', ROOT_PATH . 'lang' . DS);
171 171
 
172 172
 	/**
173
-	* The path to the directory of your personal libraries
174
-	*
175
-	* It contains your PHP classes, package, etc.
176
-	* Note: you should not put your personal libraries in the system library directory, 
177
-	* because it is recalled in case of updating the system you might have surprises.
178
-	*/
173
+	 * The path to the directory of your personal libraries
174
+	 *
175
+	 * It contains your PHP classes, package, etc.
176
+	 * Note: you should not put your personal libraries in the system library directory, 
177
+	 * because it is recalled in case of updating the system you might have surprises.
178
+	 */
179 179
 	define('LIBRARY_PATH', ROOT_PATH . 'libraries' . DS);
180 180
 
181 181
 	/**
182
-	* The path to the directory that contains the log files.
183
-	*
184
-	* Note: This directory must be available in writing and if possible must have as owner the user who launches your web server, 
185
-	* under unix or linux most often with the apache web server it is "www-data" or "httpd" even "nobody" for more
186
-	* details see the documentation of your web server.
187
-	* Example for Unix or linux with apache web server:
188
-	* # chmod -R 700 /path/to/your/logs/directory/
189
-	* # chown -R www-data:www-data /path/to/your/logs/directory/
190
-	*/
182
+	 * The path to the directory that contains the log files.
183
+	 *
184
+	 * Note: This directory must be available in writing and if possible must have as owner the user who launches your web server, 
185
+	 * under unix or linux most often with the apache web server it is "www-data" or "httpd" even "nobody" for more
186
+	 * details see the documentation of your web server.
187
+	 * Example for Unix or linux with apache web server:
188
+	 * # chmod -R 700 /path/to/your/logs/directory/
189
+	 * # chown -R www-data:www-data /path/to/your/logs/directory/
190
+	 */
191 191
 	define('LOGS_PATH', ROOT_PATH . 'logs' . DS);
192 192
 
193 193
 	/**
194
-	* The path to the modules directory. 
195
-	*
196
-	* It contains your modules used files (config, controllers, libraries, etc.) that is to say which contains your files of the modules, 
197
-	* in HMVC architecture (hierichical, controllers, models, views).
198
-	*/
194
+	 * The path to the modules directory. 
195
+	 *
196
+	 * It contains your modules used files (config, controllers, libraries, etc.) that is to say which contains your files of the modules, 
197
+	 * in HMVC architecture (hierichical, controllers, models, views).
198
+	 */
199 199
 	define('MODULE_PATH', dirname(realpath(__FILE__)) . DS .'hmvc' . DS . 'modules' . DS);
200 200
 
201 201
 	/**
202
-	* The path to the directory of sources external to your application.
203
-	*
204
-	* If you have already used "composer" you know what that means.
205
-	*/
202
+	 * The path to the directory of sources external to your application.
203
+	 *
204
+	 * If you have already used "composer" you know what that means.
205
+	 */
206 206
 	define('VENDOR_PATH', ROOT_PATH . 'vendor' . DS);
207 207
 
208 208
 	/**
209
-	* The front controller of your application.
210
-	*
211
-	* "index.php" it is through this file that all the requests come, there is a possibility to hidden it in the url of 
212
-	* your application by using the rewrite module URL of your web server .
213
-	* For example, under apache web server, there is a configuration example file that is located at the root 
214
-	* of your framework folder : "htaccess.txt" rename it to ".htaccess".
215
-	*/
209
+	 * The front controller of your application.
210
+	 *
211
+	 * "index.php" it is through this file that all the requests come, there is a possibility to hidden it in the url of 
212
+	 * your application by using the rewrite module URL of your web server .
213
+	 * For example, under apache web server, there is a configuration example file that is located at the root 
214
+	 * of your framework folder : "htaccess.txt" rename it to ".htaccess".
215
+	 */
216 216
 	define('SELF', pathinfo(__FILE__, PATHINFO_BASENAME));
217 217
 	
218 218
 	/**
@@ -221,14 +221,14 @@  discard block
 block discarded – undo
221 221
 	define('IS_CLI', stripos('cli', php_sapi_name()) !== false);
222 222
 
223 223
 	/**
224
-	* The environment of your application (production, test, development). 
225
-	*
226
-	* if your application is still in development you use the value "development" 
227
-	* so you will have the display of the error messages, etc. 
228
-	* Once you finish the development of your application that is to put it online 
229
-	* you change this value to "production" or "testing", in this case there will be deactivation of error messages, 
230
-	* the loading of the system, will be fast.
231
-	*/
224
+	 * The environment of your application (production, test, development). 
225
+	 *
226
+	 * if your application is still in development you use the value "development" 
227
+	 * so you will have the display of the error messages, etc. 
228
+	 * Once you finish the development of your application that is to put it online 
229
+	 * you change this value to "production" or "testing", in this case there will be deactivation of error messages, 
230
+	 * the loading of the system, will be fast.
231
+	 */
232 232
 	define('ENVIRONMENT', 'testing');
233 233
 	
234 234
 	
@@ -262,13 +262,13 @@  discard block
 block discarded – undo
262 262
 	require_once  'include/testsUtil.php';
263 263
 	
264 264
 	/**
265
-	* Setting of the PHP error message handling function
266
-	*/
265
+	 * Setting of the PHP error message handling function
266
+	 */
267 267
 	set_error_handler('php_error_handler');
268 268
 
269 269
 	/**
270
-	* Setting of the PHP error exception handling function
271
-	*/
270
+	 * Setting of the PHP error exception handling function
271
+	 */
272 272
 	set_exception_handler('php_exception_handler');
273 273
 
274 274
 	/**
@@ -277,8 +277,8 @@  discard block
 block discarded – undo
277 277
 	register_shutdown_function('php_shudown_handler');
278 278
 	
279 279
 	/**
280
-	* Register the tests autoload
281
-	*/
280
+	 * Register the tests autoload
281
+	 */
282 282
 	spl_autoload_register('tests_autoload');
283 283
 	
284 284
 	
Please login to merge, or discard this patch.
core/classes/DatabaseQueryBuilder.php 1 patch
Indentation   +826 added lines, -826 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-    defined('ROOT_PATH') || exit('Access denied');
2
+	defined('ROOT_PATH') || exit('Access denied');
3 3
   /**
4 4
    * TNH Framework
5 5
    *
@@ -22,740 +22,740 @@  discard block
 block discarded – undo
22 22
    * You should have received a copy of the GNU General Public License
23 23
    * along with this program; if not, write to the Free Software
24 24
    * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25
-  */
25
+   */
26 26
   class DatabaseQueryBuilder{
27 27
   	/**
28 28
   	 * The SQL SELECT statment
29 29
   	 * @var string
30
-  	*/
30
+  	 */
31 31
   	private $select              = '*';
32 32
   	
33 33
   	/**
34 34
   	 * The SQL FROM statment
35 35
   	 * @var string
36
-  	*/
37
-      private $from                = null;
36
+  	 */
37
+	  private $from                = null;
38 38
   	
39 39
   	/**
40 40
   	 * The SQL WHERE statment
41 41
   	 * @var string
42
-  	*/
43
-      private $where               = null;
42
+  	 */
43
+	  private $where               = null;
44 44
   	
45 45
   	/**
46 46
   	 * The SQL LIMIT statment
47 47
   	 * @var string
48
-  	*/
49
-      private $limit               = null;
48
+  	 */
49
+	  private $limit               = null;
50 50
   	
51 51
   	/**
52 52
   	 * The SQL JOIN statment
53 53
   	 * @var string
54
-  	*/
55
-      private $join                = null;
54
+  	 */
55
+	  private $join                = null;
56 56
   	
57 57
   	/**
58 58
   	 * The SQL ORDER BY statment
59 59
   	 * @var string
60
-  	*/
61
-      private $orderBy             = null;
60
+  	 */
61
+	  private $orderBy             = null;
62 62
   	
63 63
   	/**
64 64
   	 * The SQL GROUP BY statment
65 65
   	 * @var string
66
-  	*/
67
-      private $groupBy             = null;
66
+  	 */
67
+	  private $groupBy             = null;
68 68
   	
69 69
   	/**
70 70
   	 * The SQL HAVING statment
71 71
   	 * @var string
72
-  	*/
73
-      private $having              = null;
72
+  	 */
73
+	  private $having              = null;
74 74
   	
75 75
   	/**
76 76
   	 * The full SQL query statment after build for each command
77 77
   	 * @var string
78
-  	*/
79
-      private $query               = null;
78
+  	 */
79
+	  private $query               = null;
80 80
   	
81 81
   	/**
82 82
   	 * The list of SQL valid operators
83 83
   	 * @var array
84
-  	*/
85
-    private $operatorList        = array('=','!=','<','>','<=','>=','<>');
84
+  	 */
85
+	private $operatorList        = array('=','!=','<','>','<=','>=','<>');
86 86
   	
87 87
 	
88 88
 	/**
89 89
 	 * The prefix used in each database table
90 90
 	 * @var string
91
-	*/
92
-    private $prefix              = null;
91
+	 */
92
+	private $prefix              = null;
93 93
     
94 94
 
95 95
   /**
96
-	 * The PDO instance
97
-	 * @var object
98
-	*/
96
+   * The PDO instance
97
+   * @var object
98
+   */
99 99
   private $pdo                 = null;
100 100
 	
101 101
   	/**
102 102
   	 * The database driver name used
103 103
   	 * @var string
104
-  	*/
104
+  	 */
105 105
   	private $driver              = null;
106 106
   	
107 107
 	
108
-    /**
109
-     * Construct new DatabaseQueryBuilder
110
-     * @param object $pdo the PDO object
111
-     */
112
-    public function __construct(PDO $pdo = null){
113
-        if (is_object($pdo)){
114
-          $this->setPdo($pdo);
115
-        }
116
-    }
117
-
118
-    /**
119
-     * Set the SQL FROM statment
120
-     * @param  string|array $table the table name or array of table list
121
-     * @return object        the current DatabaseQueryBuilder instance
122
-     */
123
-    public function from($table){
108
+	/**
109
+	 * Construct new DatabaseQueryBuilder
110
+	 * @param object $pdo the PDO object
111
+	 */
112
+	public function __construct(PDO $pdo = null){
113
+		if (is_object($pdo)){
114
+		  $this->setPdo($pdo);
115
+		}
116
+	}
117
+
118
+	/**
119
+	 * Set the SQL FROM statment
120
+	 * @param  string|array $table the table name or array of table list
121
+	 * @return object        the current DatabaseQueryBuilder instance
122
+	 */
123
+	public function from($table){
124 124
 	  if (is_array($table)){
125
-        $froms = '';
126
-        foreach($table as $key){
127
-          $froms .= $this->getPrefix() . $key . ', ';
128
-        }
129
-        $this->from = rtrim($froms, ', ');
130
-      } else {
131
-        $this->from = $this->getPrefix() . $table;
132
-      }
133
-      return $this;
134
-    }
135
-
136
-    /**
137
-     * Set the SQL SELECT statment
138
-     * @param  string|array $fields the field name or array of field list
139
-     * @return object        the current DatabaseQueryBuilder instance
140
-     */
141
-    public function select($fields){
142
-      $select = (is_array($fields) ? implode(', ', $fields) : $fields);
143
-      $this->select = (($this->select == '*' || empty($this->select)) ? $select : $this->select . ', ' . $select);
144
-      return $this;
145
-    }
146
-
147
-    /**
148
-     * Set the SQL SELECT DISTINCT statment
149
-     * @param  string $field the field name to distinct
150
-     * @return object        the current DatabaseQueryBuilder instance
151
-     */
152
-    public function distinct($field){
153
-      $distinct = ' DISTINCT ' . $field;
154
-      $this->select = (($this->select == '*' || empty($this->select)) ? $distinct : $this->select . ', ' . $distinct);
155
-      return $this;
156
-    }
157
-
158
-     /**
159
-     * Set the SQL function COUNT in SELECT statment
160
-     * @param  string $field the field name
161
-     * @param  string $name  if is not null represent the alias used for this field in the result
162
-     * @return object        the current DatabaseQueryBuilder instance
163
-     */
164
-    public function count($field = '*', $name = null){
165
-      return $this->select_min_max_sum_count_avg('COUNT', $field, $name);
166
-    }
125
+		$froms = '';
126
+		foreach($table as $key){
127
+		  $froms .= $this->getPrefix() . $key . ', ';
128
+		}
129
+		$this->from = rtrim($froms, ', ');
130
+	  } else {
131
+		$this->from = $this->getPrefix() . $table;
132
+	  }
133
+	  return $this;
134
+	}
135
+
136
+	/**
137
+	 * Set the SQL SELECT statment
138
+	 * @param  string|array $fields the field name or array of field list
139
+	 * @return object        the current DatabaseQueryBuilder instance
140
+	 */
141
+	public function select($fields){
142
+	  $select = (is_array($fields) ? implode(', ', $fields) : $fields);
143
+	  $this->select = (($this->select == '*' || empty($this->select)) ? $select : $this->select . ', ' . $select);
144
+	  return $this;
145
+	}
146
+
147
+	/**
148
+	 * Set the SQL SELECT DISTINCT statment
149
+	 * @param  string $field the field name to distinct
150
+	 * @return object        the current DatabaseQueryBuilder instance
151
+	 */
152
+	public function distinct($field){
153
+	  $distinct = ' DISTINCT ' . $field;
154
+	  $this->select = (($this->select == '*' || empty($this->select)) ? $distinct : $this->select . ', ' . $distinct);
155
+	  return $this;
156
+	}
157
+
158
+	 /**
159
+	  * Set the SQL function COUNT in SELECT statment
160
+	  * @param  string $field the field name
161
+	  * @param  string $name  if is not null represent the alias used for this field in the result
162
+	  * @return object        the current DatabaseQueryBuilder instance
163
+	  */
164
+	public function count($field = '*', $name = null){
165
+	  return $this->select_min_max_sum_count_avg('COUNT', $field, $name);
166
+	}
167 167
     
168
-    /**
169
-     * Set the SQL function MIN in SELECT statment
170
-     * @param  string $field the field name
171
-     * @param  string $name  if is not null represent the alias used for this field in the result
172
-     * @return object        the current DatabaseQueryBuilder instance
173
-     */
174
-    public function min($field, $name = null){
175
-      return $this->select_min_max_sum_count_avg('MIN', $field, $name);
176
-    }
177
-
178
-    /**
179
-     * Set the SQL function MAX in SELECT statment
180
-     * @param  string $field the field name
181
-     * @param  string $name  if is not null represent the alias used for this field in the result
182
-     * @return object        the current DatabaseQueryBuilder instance
183
-     */
184
-    public function max($field, $name = null){
185
-      return $this->select_min_max_sum_count_avg('MAX', $field, $name);
186
-    }
187
-
188
-    /**
189
-     * Set the SQL function SUM in SELECT statment
190
-     * @param  string $field the field name
191
-     * @param  string $name  if is not null represent the alias used for this field in the result
192
-     * @return object        the current DatabaseQueryBuilder instance
193
-     */
194
-    public function sum($field, $name = null){
195
-      return $this->select_min_max_sum_count_avg('SUM', $field, $name);
196
-    }
197
-
198
-    /**
199
-     * Set the SQL function AVG in SELECT statment
200
-     * @param  string $field the field name
201
-     * @param  string $name  if is not null represent the alias used for this field in the result
202
-     * @return object        the current DatabaseQueryBuilder instance
203
-     */
204
-    public function avg($field, $name = null){
205
-      return $this->select_min_max_sum_count_avg('AVG', $field, $name);
206
-    }
207
-
208
-
209
-    /**
210
-     * Set the SQL JOIN statment
211
-     * @param  string $table  the join table name
212
-     * @param  string $field1 the first field for join conditions	
213
-     * @param  string $op     the join condition operator. If is null the default will be "="
214
-     * @param  string $field2 the second field for join conditions
215
-     * @param  string $type   the type of join (INNER, LEFT, RIGHT)
216
-     * @return object        the current DatabaseQueryBuilder instance
217
-     */
218
-    public function join($table, $field1 = null, $op = null, $field2 = null, $type = ''){
219
-      $on = $field1;
220
-      $table = $this->getPrefix() . $table;
221
-      if (! is_null($op)){
222
-        $on = (! in_array($op, $this->operatorList) 
168
+	/**
169
+	 * Set the SQL function MIN in SELECT statment
170
+	 * @param  string $field the field name
171
+	 * @param  string $name  if is not null represent the alias used for this field in the result
172
+	 * @return object        the current DatabaseQueryBuilder instance
173
+	 */
174
+	public function min($field, $name = null){
175
+	  return $this->select_min_max_sum_count_avg('MIN', $field, $name);
176
+	}
177
+
178
+	/**
179
+	 * Set the SQL function MAX in SELECT statment
180
+	 * @param  string $field the field name
181
+	 * @param  string $name  if is not null represent the alias used for this field in the result
182
+	 * @return object        the current DatabaseQueryBuilder instance
183
+	 */
184
+	public function max($field, $name = null){
185
+	  return $this->select_min_max_sum_count_avg('MAX', $field, $name);
186
+	}
187
+
188
+	/**
189
+	 * Set the SQL function SUM in SELECT statment
190
+	 * @param  string $field the field name
191
+	 * @param  string $name  if is not null represent the alias used for this field in the result
192
+	 * @return object        the current DatabaseQueryBuilder instance
193
+	 */
194
+	public function sum($field, $name = null){
195
+	  return $this->select_min_max_sum_count_avg('SUM', $field, $name);
196
+	}
197
+
198
+	/**
199
+	 * Set the SQL function AVG in SELECT statment
200
+	 * @param  string $field the field name
201
+	 * @param  string $name  if is not null represent the alias used for this field in the result
202
+	 * @return object        the current DatabaseQueryBuilder instance
203
+	 */
204
+	public function avg($field, $name = null){
205
+	  return $this->select_min_max_sum_count_avg('AVG', $field, $name);
206
+	}
207
+
208
+
209
+	/**
210
+	 * Set the SQL JOIN statment
211
+	 * @param  string $table  the join table name
212
+	 * @param  string $field1 the first field for join conditions	
213
+	 * @param  string $op     the join condition operator. If is null the default will be "="
214
+	 * @param  string $field2 the second field for join conditions
215
+	 * @param  string $type   the type of join (INNER, LEFT, RIGHT)
216
+	 * @return object        the current DatabaseQueryBuilder instance
217
+	 */
218
+	public function join($table, $field1 = null, $op = null, $field2 = null, $type = ''){
219
+	  $on = $field1;
220
+	  $table = $this->getPrefix() . $table;
221
+	  if (! is_null($op)){
222
+		$on = (! in_array($op, $this->operatorList) 
223 223
 													? ($this->getPrefix() . $field1 . ' = ' . $this->getPrefix() . $op) 
224 224
 													: ($this->getPrefix() . $field1 . ' ' . $op . ' ' . $this->getPrefix() . $field2));
225
-      }
226
-      if (empty($this->join)){
227
-        $this->join = ' ' . $type . 'JOIN' . ' ' . $table . ' ON ' . $on;
228
-      }
229
-      else{
230
-        $this->join = $this->join . ' ' . $type . 'JOIN' . ' ' . $table . ' ON ' . $on;
231
-      }
232
-      return $this;
233
-    }
234
-
235
-    /**
236
-     * Set the SQL INNER JOIN statment
237
-     * @see  DatabaseQueryBuilder::join()
238
-     * @return object        the current DatabaseQueryBuilder instance
239
-     */
240
-    public function innerJoin($table, $field1, $op = null, $field2 = ''){
241
-      return $this->join($table, $field1, $op, $field2, 'INNER ');
242
-    }
243
-
244
-    /**
245
-     * Set the SQL LEFT JOIN statment
246
-     * @see  DatabaseQueryBuilder::join()
247
-     * @return object        the current DatabaseQueryBuilder instance
248
-     */
249
-    public function leftJoin($table, $field1, $op = null, $field2 = ''){
250
-      return $this->join($table, $field1, $op, $field2, 'LEFT ');
251
-	}
252
-
253
-	/**
254
-     * Set the SQL RIGHT JOIN statment
255
-     * @see  DatabaseQueryBuilder::join()
256
-     * @return object        the current DatabaseQueryBuilder instance
257
-     */
258
-    public function rightJoin($table, $field1, $op = null, $field2 = ''){
259
-      return $this->join($table, $field1, $op, $field2, 'RIGHT ');
260
-    }
261
-
262
-    /**
263
-     * Set the SQL FULL OUTER JOIN statment
264
-     * @see  DatabaseQueryBuilder::join()
265
-     * @return object        the current DatabaseQueryBuilder instance
266
-     */
267
-    public function fullOuterJoin($table, $field1, $op = null, $field2 = ''){
268
-    	return $this->join($table, $field1, $op, $field2, 'FULL OUTER ');
269
-    }
270
-
271
-    /**
272
-     * Set the SQL LEFT OUTER JOIN statment
273
-     * @see  DatabaseQueryBuilder::join()
274
-     * @return object        the current DatabaseQueryBuilder instance
275
-     */
276
-    public function leftOuterJoin($table, $field1, $op = null, $field2 = ''){
277
-      return $this->join($table, $field1, $op, $field2, 'LEFT OUTER ');
278
-    }
279
-
280
-    /**
281
-     * Set the SQL RIGHT OUTER JOIN statment
282
-     * @see  DatabaseQueryBuilder::join()
283
-     * @return object        the current DatabaseQueryBuilder instance
284
-     */
285
-    public function rightOuterJoin($table, $field1, $op = null, $field2 = ''){
286
-      return $this->join($table, $field1, $op, $field2, 'RIGHT OUTER ');
287
-    }
288
-
289
-    /**
290
-     * Set the SQL WHERE CLAUSE for IS NULL
291
-     * @param  string|array $field  the field name or array of field list
292
-     * @param  string $andOr the separator type used 'AND', 'OR', etc.
293
-     * @return object        the current DatabaseQueryBuilder instance
294
-     */
295
-    public function whereIsNull($field, $andOr = 'AND'){
296
-      if (is_array($field)){
297
-        foreach($field as $f){
298
-        	$this->whereIsNull($f, $andOr);
299
-        }
300
-      } else {
301
-          $this->setWhereStr($field.' IS NULL ', $andOr);
302
-      }
303
-      return $this;
304
-    }
305
-
306
-    /**
307
-     * Set the SQL WHERE CLAUSE for IS NOT NULL
308
-     * @param  string|array $field  the field name or array of field list
309
-     * @param  string $andOr the separator type used 'AND', 'OR', etc.
310
-     * @return object        the current DatabaseQueryBuilder instance
311
-     */
312
-    public function whereIsNotNull($field, $andOr = 'AND'){
313
-      if (is_array($field)){
314
-        foreach($field as $f){
315
-          $this->whereIsNotNull($f, $andOr);
316
-        }
317
-      } else {
318
-          $this->setWhereStr($field.' IS NOT NULL ', $andOr);
319
-      }
320
-      return $this;
321
-    }
225
+	  }
226
+	  if (empty($this->join)){
227
+		$this->join = ' ' . $type . 'JOIN' . ' ' . $table . ' ON ' . $on;
228
+	  }
229
+	  else{
230
+		$this->join = $this->join . ' ' . $type . 'JOIN' . ' ' . $table . ' ON ' . $on;
231
+	  }
232
+	  return $this;
233
+	}
234
+
235
+	/**
236
+	 * Set the SQL INNER JOIN statment
237
+	 * @see  DatabaseQueryBuilder::join()
238
+	 * @return object        the current DatabaseQueryBuilder instance
239
+	 */
240
+	public function innerJoin($table, $field1, $op = null, $field2 = ''){
241
+	  return $this->join($table, $field1, $op, $field2, 'INNER ');
242
+	}
243
+
244
+	/**
245
+	 * Set the SQL LEFT JOIN statment
246
+	 * @see  DatabaseQueryBuilder::join()
247
+	 * @return object        the current DatabaseQueryBuilder instance
248
+	 */
249
+	public function leftJoin($table, $field1, $op = null, $field2 = ''){
250
+	  return $this->join($table, $field1, $op, $field2, 'LEFT ');
251
+	}
252
+
253
+	/**
254
+	 * Set the SQL RIGHT JOIN statment
255
+	 * @see  DatabaseQueryBuilder::join()
256
+	 * @return object        the current DatabaseQueryBuilder instance
257
+	 */
258
+	public function rightJoin($table, $field1, $op = null, $field2 = ''){
259
+	  return $this->join($table, $field1, $op, $field2, 'RIGHT ');
260
+	}
261
+
262
+	/**
263
+	 * Set the SQL FULL OUTER JOIN statment
264
+	 * @see  DatabaseQueryBuilder::join()
265
+	 * @return object        the current DatabaseQueryBuilder instance
266
+	 */
267
+	public function fullOuterJoin($table, $field1, $op = null, $field2 = ''){
268
+		return $this->join($table, $field1, $op, $field2, 'FULL OUTER ');
269
+	}
270
+
271
+	/**
272
+	 * Set the SQL LEFT OUTER JOIN statment
273
+	 * @see  DatabaseQueryBuilder::join()
274
+	 * @return object        the current DatabaseQueryBuilder instance
275
+	 */
276
+	public function leftOuterJoin($table, $field1, $op = null, $field2 = ''){
277
+	  return $this->join($table, $field1, $op, $field2, 'LEFT OUTER ');
278
+	}
279
+
280
+	/**
281
+	 * Set the SQL RIGHT OUTER JOIN statment
282
+	 * @see  DatabaseQueryBuilder::join()
283
+	 * @return object        the current DatabaseQueryBuilder instance
284
+	 */
285
+	public function rightOuterJoin($table, $field1, $op = null, $field2 = ''){
286
+	  return $this->join($table, $field1, $op, $field2, 'RIGHT OUTER ');
287
+	}
288
+
289
+	/**
290
+	 * Set the SQL WHERE CLAUSE for IS NULL
291
+	 * @param  string|array $field  the field name or array of field list
292
+	 * @param  string $andOr the separator type used 'AND', 'OR', etc.
293
+	 * @return object        the current DatabaseQueryBuilder instance
294
+	 */
295
+	public function whereIsNull($field, $andOr = 'AND'){
296
+	  if (is_array($field)){
297
+		foreach($field as $f){
298
+			$this->whereIsNull($f, $andOr);
299
+		}
300
+	  } else {
301
+		  $this->setWhereStr($field.' IS NULL ', $andOr);
302
+	  }
303
+	  return $this;
304
+	}
305
+
306
+	/**
307
+	 * Set the SQL WHERE CLAUSE for IS NOT NULL
308
+	 * @param  string|array $field  the field name or array of field list
309
+	 * @param  string $andOr the separator type used 'AND', 'OR', etc.
310
+	 * @return object        the current DatabaseQueryBuilder instance
311
+	 */
312
+	public function whereIsNotNull($field, $andOr = 'AND'){
313
+	  if (is_array($field)){
314
+		foreach($field as $f){
315
+		  $this->whereIsNotNull($f, $andOr);
316
+		}
317
+	  } else {
318
+		  $this->setWhereStr($field.' IS NOT NULL ', $andOr);
319
+	  }
320
+	  return $this;
321
+	}
322 322
     
323
-    /**
324
-     * Set the SQL WHERE CLAUSE statment
325
-     * @param  string|array  $where the where field or array of field list
326
-     * @param  array|string  $op     the condition operator. If is null the default will be "="
327
-     * @param  mixed  $val    the where value
328
-     * @param  string  $type   the type used for this where clause (NOT, etc.)
329
-     * @param  string  $andOr the separator type used 'AND', 'OR', etc.
330
-     * @param  boolean $escape whether to escape or not the $val
331
-     * @return object        the current DatabaseQueryBuilder instance
332
-     */
333
-    public function where($where, $op = null, $val = null, $type = '', $andOr = 'AND', $escape = true){
334
-      $whereStr = '';
335
-      if (is_array($where)){
336
-        $whereStr = $this->getWhereStrIfIsArray($where, $type, $andOr, $escape);
337
-      }
338
-      else{
339
-        if (is_array($op)){
340
-          $whereStr = $this->getWhereStrIfOperatorIsArray($where, $op, $type, $escape);
341
-        } else {
342
-          $whereStr = $this->getWhereStrForOperator($where, $op, $val, $type, $escape = true);
343
-        }
344
-      }
345
-      $this->setWhereStr($whereStr, $andOr);
346
-      return $this;
347
-    }
348
-
349
-    /**
350
-     * Set the SQL WHERE CLAUSE statment using OR
351
-     * @see  DatabaseQueryBuilder::where()
352
-     * @return object        the current DatabaseQueryBuilder instance
353
-     */
354
-    public function orWhere($where, $op = null, $val = null, $escape = true){
355
-      return $this->where($where, $op, $val, '', 'OR', $escape);
356
-    }
357
-
358
-
359
-    /**
360
-     * Set the SQL WHERE CLAUSE statment using AND and NOT
361
-     * @see  DatabaseQueryBuilder::where()
362
-     * @return object        the current DatabaseQueryBuilder instance
363
-     */
364
-    public function notWhere($where, $op = null, $val = null, $escape = true){
365
-      return $this->where($where, $op, $val, 'NOT ', 'AND', $escape);
366
-    }
367
-
368
-    /**
369
-     * Set the SQL WHERE CLAUSE statment using OR and NOT
370
-     * @see  DatabaseQueryBuilder::where()
371
-     * @return object        the current DatabaseQueryBuilder instance
372
-     */
373
-    public function orNotWhere($where, $op = null, $val = null, $escape = true){
374
-    	return $this->where($where, $op, $val, 'NOT ', 'OR', $escape);
375
-    }
376
-
377
-    /**
378
-     * Set the opened parenthesis for the complex SQL query
379
-     * @param  string $type   the type of this grouped (NOT, etc.)
380
-     * @param  string $andOr the multiple conditions separator (AND, OR, etc.)
381
-     * @return object        the current DatabaseQueryBuilder instance
382
-     */
383
-    public function groupStart($type = '', $andOr = ' AND'){
384
-      if (empty($this->where)){
385
-        $this->where = $type . ' (';
386
-      } else {
387
-          if (substr(trim($this->where), -1) == '('){
388
-            $this->where .= $type . ' (';
389
-          } else {
390
-          	$this->where .= $andOr . ' ' . $type . ' (';
391
-          }
392
-      }
393
-      return $this;
394
-    }
395
-
396
-    /**
397
-     * Set the opened parenthesis for the complex SQL query using NOT type
398
-     * @see  DatabaseQueryBuilder::groupStart()
399
-     * @return object        the current DatabaseQueryBuilder instance
400
-     */
401
-    public function notGroupStart(){
402
-      return $this->groupStart('NOT');
403
-    }
404
-
405
-    /**
406
-     * Set the opened parenthesis for the complex SQL query using OR for separator
407
-     * @see  DatabaseQueryBuilder::groupStart()
408
-     * @return object        the current DatabaseQueryBuilder instance
409
-     */
410
-    public function orGroupStart(){
411
-      return $this->groupStart('', ' OR');
412
-    }
413
-
414
-     /**
415
-     * Set the opened parenthesis for the complex SQL query using OR for separator and NOT for type
416
-     * @see  DatabaseQueryBuilder::groupStart()
417
-     * @return object        the current DatabaseQueryBuilder instance
418
-     */
419
-    public function orNotGroupStart(){
420
-      return $this->groupStart('NOT', ' OR');
421
-    }
422
-
423
-    /**
424
-     * Close the parenthesis for the grouped SQL
425
-     * @return object        the current DatabaseQueryBuilder instance
426
-     */
427
-    public function groupEnd(){
428
-      $this->where .= ')';
429
-      return $this;
430
-    }
431
-
432
-    /**
433
-     * Set the SQL WHERE CLAUSE statment for IN
434
-     * @param  string  $field  the field name for IN statment
435
-     * @param  array   $keys   the list of values used
436
-     * @param  string  $type   the condition separator type (NOT)
437
-     * @param  string  $andOr the multiple conditions separator (OR, AND)
438
-     * @param  boolean $escape whether to escape or not the values
439
-     * @return object        the current DatabaseQueryBuilder instance
440
-     */
441
-    public function in($field, array $keys, $type = '', $andOr = 'AND', $escape = true){
442
-      $_keys = array();
443
-      foreach ($keys as $k => $v){
444
-        if (is_null($v)){
445
-          $v = '';
446
-        }
447
-        $_keys[] = (is_numeric($v) ? $v : $this->escape($v, $escape));
448
-      }
449
-      $keys = implode(', ', $_keys);
450
-      $whereStr = $field . ' ' . $type . ' IN (' . $keys . ')';
451
-      $this->setWhereStr($whereStr, $andOr);
452
-      return $this;
453
-    }
454
-
455
-    /**
456
-     * Set the SQL WHERE CLAUSE statment for NOT IN with AND separator
457
-     * @see  DatabaseQueryBuilder::in()
458
-     * @return object        the current DatabaseQueryBuilder instance
459
-     */
460
-    public function notIn($field, array $keys, $escape = true){
461
-      return $this->in($field, $keys, 'NOT ', 'AND', $escape);
462
-    }
463
-
464
-    /**
465
-     * Set the SQL WHERE CLAUSE statment for IN with OR separator
466
-     * @see  DatabaseQueryBuilder::in()
467
-     * @return object        the current DatabaseQueryBuilder instance
468
-     */
469
-    public function orIn($field, array $keys, $escape = true){
470
-      return $this->in($field, $keys, '', 'OR', $escape);
471
-    }
472
-
473
-    /**
474
-     * Set the SQL WHERE CLAUSE statment for NOT IN with OR separator
475
-     * @see  DatabaseQueryBuilder::in()
476
-     * @return object        the current DatabaseQueryBuilder instance
477
-     */
478
-    public function orNotIn($field, array $keys, $escape = true){
479
-      return $this->in($field, $keys, 'NOT ', 'OR', $escape);
480
-    }
481
-
482
-    /**
483
-     * Set the SQL WHERE CLAUSE statment for BETWEEN
484
-     * @param  string  $field  the field used for the BETWEEN statment
485
-     * @param  mixed  $value1 the BETWEEN begin value
486
-     * @param  mixed  $value2 the BETWEEN end value
487
-     * @param  string  $type   the condition separator type (NOT)
488
-     * @param  string  $andOr the multiple conditions separator (OR, AND)
489
-     * @param  boolean $escape whether to escape or not the values
490
-     * @return object        the current DatabaseQueryBuilder instance
491
-     */
492
-    public function between($field, $value1, $value2, $type = '', $andOr = 'AND', $escape = true){
493
-      if (is_null($value1)){
494
-        $value1 = '';
495
-      }
496
-      if (is_null($value2)){
497
-        $value2 = '';
498
-      }
499
-      $whereStr = $field . ' ' . $type . ' BETWEEN ' . $this->escape($value1, $escape) . ' AND ' . $this->escape($value2, $escape);
500
-      $this->setWhereStr($whereStr, $andOr);
501
-      return $this;
502
-    }
503
-
504
-    /**
505
-     * Set the SQL WHERE CLAUSE statment for BETWEEN with NOT type and AND separator
506
-     * @see  DatabaseQueryBuilder::between()
507
-     * @return object        the current DatabaseQueryBuilder instance
508
-     */
509
-    public function notBetween($field, $value1, $value2, $escape = true){
510
-      return $this->between($field, $value1, $value2, 'NOT ', 'AND', $escape);
511
-    }
512
-
513
-    /**
514
-     * Set the SQL WHERE CLAUSE statment for BETWEEN with OR separator
515
-     * @see  DatabaseQueryBuilder::between()
516
-     * @return object        the current DatabaseQueryBuilder instance
517
-     */
518
-    public function orBetween($field, $value1, $value2, $escape = true){
519
-      return $this->between($field, $value1, $value2, '', 'OR', $escape);
520
-    }
521
-
522
-    /**
523
-     * Set the SQL WHERE CLAUSE statment for BETWEEN with NOT type and OR separator
524
-     * @see  DatabaseQueryBuilder::between()
525
-     * @return object        the current DatabaseQueryBuilder instance
526
-     */
527
-    public function orNotBetween($field, $value1, $value2, $escape = true){
528
-      return $this->between($field, $value1, $value2, 'NOT ', 'OR', $escape);
529
-    }
530
-
531
-    /**
532
-     * Set the SQL WHERE CLAUSE statment for LIKE
533
-     * @param  string  $field  the field name used in LIKE statment
534
-     * @param  string  $data   the LIKE value for this field including the '%', and '_' part
535
-     * @param  string  $type   the condition separator type (NOT)
536
-     * @param  string  $andOr the multiple conditions separator (OR, AND)
537
-     * @param  boolean $escape whether to escape or not the values
538
-     * @return object        the current DatabaseQueryBuilder instance
539
-     */
540
-    public function like($field, $data, $type = '', $andOr = 'AND', $escape = true){
541
-      if (empty($data)){
542
-        $data = '';
543
-      }
544
-      $this->setWhereStr($field . ' ' . $type . ' LIKE ' . ($this->escape($data, $escape)), $andOr);
545
-      return $this;
546
-    }
547
-
548
-    /**
549
-     * Set the SQL WHERE CLAUSE statment for LIKE with OR separator
550
-     * @see  DatabaseQueryBuilder::like()
551
-     * @return object        the current DatabaseQueryBuilder instance
552
-     */
553
-    public function orLike($field, $data, $escape = true){
554
-      return $this->like($field, $data, '', 'OR', $escape);
555
-    }
556
-
557
-    /**
558
-     * Set the SQL WHERE CLAUSE statment for LIKE with NOT type and AND separator
559
-     * @see  DatabaseQueryBuilder::like()
560
-     * @return object        the current DatabaseQueryBuilder instance
561
-     */
562
-    public function notLike($field, $data, $escape = true){
563
-      return $this->like($field, $data, 'NOT ', 'AND', $escape);
564
-    }
565
-
566
-    /**
567
-     * Set the SQL WHERE CLAUSE statment for LIKE with NOT type and OR separator
568
-     * @see  DatabaseQueryBuilder::like()
569
-     * @return object        the current DatabaseQueryBuilder instance
570
-     */
571
-    public function orNotLike($field, $data, $escape = true){
572
-      return $this->like($field, $data, 'NOT ', 'OR', $escape);
573
-    }
574
-
575
-    /**
576
-     * Set the SQL LIMIT statment
577
-     * @param  int $limit    the limit offset. If $limitEnd is null this will be the limit count
578
-     * like LIMIT n;
579
-     * @param  int $limitEnd the limit count
580
-     * @return object        the current DatabaseQueryBuilder instance
581
-     */
582
-    public function limit($limit, $limitEnd = null){
583
-      if (empty($limit)){
584
-        $limit = 0;
585
-      }
586
-      if (! is_null($limitEnd)){
587
-        $this->limit = $limit . ', ' . $limitEnd;
588
-      }
589
-      else{
590
-        $this->limit = $limit;
591
-      }
592
-      return $this;
593
-    }
594
-
595
-    /**
596
-     * Set the SQL ORDER BY CLAUSE statment
597
-     * @param  string $orderBy   the field name used for order
598
-     * @param  string $orderDir the order direction (ASC or DESC)
599
-     * @return object        the current DatabaseQueryBuilder instance
600
-     */
601
-    public function orderBy($orderBy, $orderDir = ' ASC'){
602
-      if (stristr($orderBy, ' ') || $orderBy == 'rand()'){
603
-        $this->orderBy = empty($this->orderBy) ? $orderBy : $this->orderBy . ', ' . $orderBy;
604
-      }
605
-      else{
606
-        $this->orderBy = empty($this->orderBy) 
323
+	/**
324
+	 * Set the SQL WHERE CLAUSE statment
325
+	 * @param  string|array  $where the where field or array of field list
326
+	 * @param  array|string  $op     the condition operator. If is null the default will be "="
327
+	 * @param  mixed  $val    the where value
328
+	 * @param  string  $type   the type used for this where clause (NOT, etc.)
329
+	 * @param  string  $andOr the separator type used 'AND', 'OR', etc.
330
+	 * @param  boolean $escape whether to escape or not the $val
331
+	 * @return object        the current DatabaseQueryBuilder instance
332
+	 */
333
+	public function where($where, $op = null, $val = null, $type = '', $andOr = 'AND', $escape = true){
334
+	  $whereStr = '';
335
+	  if (is_array($where)){
336
+		$whereStr = $this->getWhereStrIfIsArray($where, $type, $andOr, $escape);
337
+	  }
338
+	  else{
339
+		if (is_array($op)){
340
+		  $whereStr = $this->getWhereStrIfOperatorIsArray($where, $op, $type, $escape);
341
+		} else {
342
+		  $whereStr = $this->getWhereStrForOperator($where, $op, $val, $type, $escape = true);
343
+		}
344
+	  }
345
+	  $this->setWhereStr($whereStr, $andOr);
346
+	  return $this;
347
+	}
348
+
349
+	/**
350
+	 * Set the SQL WHERE CLAUSE statment using OR
351
+	 * @see  DatabaseQueryBuilder::where()
352
+	 * @return object        the current DatabaseQueryBuilder instance
353
+	 */
354
+	public function orWhere($where, $op = null, $val = null, $escape = true){
355
+	  return $this->where($where, $op, $val, '', 'OR', $escape);
356
+	}
357
+
358
+
359
+	/**
360
+	 * Set the SQL WHERE CLAUSE statment using AND and NOT
361
+	 * @see  DatabaseQueryBuilder::where()
362
+	 * @return object        the current DatabaseQueryBuilder instance
363
+	 */
364
+	public function notWhere($where, $op = null, $val = null, $escape = true){
365
+	  return $this->where($where, $op, $val, 'NOT ', 'AND', $escape);
366
+	}
367
+
368
+	/**
369
+	 * Set the SQL WHERE CLAUSE statment using OR and NOT
370
+	 * @see  DatabaseQueryBuilder::where()
371
+	 * @return object        the current DatabaseQueryBuilder instance
372
+	 */
373
+	public function orNotWhere($where, $op = null, $val = null, $escape = true){
374
+		return $this->where($where, $op, $val, 'NOT ', 'OR', $escape);
375
+	}
376
+
377
+	/**
378
+	 * Set the opened parenthesis for the complex SQL query
379
+	 * @param  string $type   the type of this grouped (NOT, etc.)
380
+	 * @param  string $andOr the multiple conditions separator (AND, OR, etc.)
381
+	 * @return object        the current DatabaseQueryBuilder instance
382
+	 */
383
+	public function groupStart($type = '', $andOr = ' AND'){
384
+	  if (empty($this->where)){
385
+		$this->where = $type . ' (';
386
+	  } else {
387
+		  if (substr(trim($this->where), -1) == '('){
388
+			$this->where .= $type . ' (';
389
+		  } else {
390
+		  	$this->where .= $andOr . ' ' . $type . ' (';
391
+		  }
392
+	  }
393
+	  return $this;
394
+	}
395
+
396
+	/**
397
+	 * Set the opened parenthesis for the complex SQL query using NOT type
398
+	 * @see  DatabaseQueryBuilder::groupStart()
399
+	 * @return object        the current DatabaseQueryBuilder instance
400
+	 */
401
+	public function notGroupStart(){
402
+	  return $this->groupStart('NOT');
403
+	}
404
+
405
+	/**
406
+	 * Set the opened parenthesis for the complex SQL query using OR for separator
407
+	 * @see  DatabaseQueryBuilder::groupStart()
408
+	 * @return object        the current DatabaseQueryBuilder instance
409
+	 */
410
+	public function orGroupStart(){
411
+	  return $this->groupStart('', ' OR');
412
+	}
413
+
414
+	 /**
415
+	  * Set the opened parenthesis for the complex SQL query using OR for separator and NOT for type
416
+	  * @see  DatabaseQueryBuilder::groupStart()
417
+	  * @return object        the current DatabaseQueryBuilder instance
418
+	  */
419
+	public function orNotGroupStart(){
420
+	  return $this->groupStart('NOT', ' OR');
421
+	}
422
+
423
+	/**
424
+	 * Close the parenthesis for the grouped SQL
425
+	 * @return object        the current DatabaseQueryBuilder instance
426
+	 */
427
+	public function groupEnd(){
428
+	  $this->where .= ')';
429
+	  return $this;
430
+	}
431
+
432
+	/**
433
+	 * Set the SQL WHERE CLAUSE statment for IN
434
+	 * @param  string  $field  the field name for IN statment
435
+	 * @param  array   $keys   the list of values used
436
+	 * @param  string  $type   the condition separator type (NOT)
437
+	 * @param  string  $andOr the multiple conditions separator (OR, AND)
438
+	 * @param  boolean $escape whether to escape or not the values
439
+	 * @return object        the current DatabaseQueryBuilder instance
440
+	 */
441
+	public function in($field, array $keys, $type = '', $andOr = 'AND', $escape = true){
442
+	  $_keys = array();
443
+	  foreach ($keys as $k => $v){
444
+		if (is_null($v)){
445
+		  $v = '';
446
+		}
447
+		$_keys[] = (is_numeric($v) ? $v : $this->escape($v, $escape));
448
+	  }
449
+	  $keys = implode(', ', $_keys);
450
+	  $whereStr = $field . ' ' . $type . ' IN (' . $keys . ')';
451
+	  $this->setWhereStr($whereStr, $andOr);
452
+	  return $this;
453
+	}
454
+
455
+	/**
456
+	 * Set the SQL WHERE CLAUSE statment for NOT IN with AND separator
457
+	 * @see  DatabaseQueryBuilder::in()
458
+	 * @return object        the current DatabaseQueryBuilder instance
459
+	 */
460
+	public function notIn($field, array $keys, $escape = true){
461
+	  return $this->in($field, $keys, 'NOT ', 'AND', $escape);
462
+	}
463
+
464
+	/**
465
+	 * Set the SQL WHERE CLAUSE statment for IN with OR separator
466
+	 * @see  DatabaseQueryBuilder::in()
467
+	 * @return object        the current DatabaseQueryBuilder instance
468
+	 */
469
+	public function orIn($field, array $keys, $escape = true){
470
+	  return $this->in($field, $keys, '', 'OR', $escape);
471
+	}
472
+
473
+	/**
474
+	 * Set the SQL WHERE CLAUSE statment for NOT IN with OR separator
475
+	 * @see  DatabaseQueryBuilder::in()
476
+	 * @return object        the current DatabaseQueryBuilder instance
477
+	 */
478
+	public function orNotIn($field, array $keys, $escape = true){
479
+	  return $this->in($field, $keys, 'NOT ', 'OR', $escape);
480
+	}
481
+
482
+	/**
483
+	 * Set the SQL WHERE CLAUSE statment for BETWEEN
484
+	 * @param  string  $field  the field used for the BETWEEN statment
485
+	 * @param  mixed  $value1 the BETWEEN begin value
486
+	 * @param  mixed  $value2 the BETWEEN end value
487
+	 * @param  string  $type   the condition separator type (NOT)
488
+	 * @param  string  $andOr the multiple conditions separator (OR, AND)
489
+	 * @param  boolean $escape whether to escape or not the values
490
+	 * @return object        the current DatabaseQueryBuilder instance
491
+	 */
492
+	public function between($field, $value1, $value2, $type = '', $andOr = 'AND', $escape = true){
493
+	  if (is_null($value1)){
494
+		$value1 = '';
495
+	  }
496
+	  if (is_null($value2)){
497
+		$value2 = '';
498
+	  }
499
+	  $whereStr = $field . ' ' . $type . ' BETWEEN ' . $this->escape($value1, $escape) . ' AND ' . $this->escape($value2, $escape);
500
+	  $this->setWhereStr($whereStr, $andOr);
501
+	  return $this;
502
+	}
503
+
504
+	/**
505
+	 * Set the SQL WHERE CLAUSE statment for BETWEEN with NOT type and AND separator
506
+	 * @see  DatabaseQueryBuilder::between()
507
+	 * @return object        the current DatabaseQueryBuilder instance
508
+	 */
509
+	public function notBetween($field, $value1, $value2, $escape = true){
510
+	  return $this->between($field, $value1, $value2, 'NOT ', 'AND', $escape);
511
+	}
512
+
513
+	/**
514
+	 * Set the SQL WHERE CLAUSE statment for BETWEEN with OR separator
515
+	 * @see  DatabaseQueryBuilder::between()
516
+	 * @return object        the current DatabaseQueryBuilder instance
517
+	 */
518
+	public function orBetween($field, $value1, $value2, $escape = true){
519
+	  return $this->between($field, $value1, $value2, '', 'OR', $escape);
520
+	}
521
+
522
+	/**
523
+	 * Set the SQL WHERE CLAUSE statment for BETWEEN with NOT type and OR separator
524
+	 * @see  DatabaseQueryBuilder::between()
525
+	 * @return object        the current DatabaseQueryBuilder instance
526
+	 */
527
+	public function orNotBetween($field, $value1, $value2, $escape = true){
528
+	  return $this->between($field, $value1, $value2, 'NOT ', 'OR', $escape);
529
+	}
530
+
531
+	/**
532
+	 * Set the SQL WHERE CLAUSE statment for LIKE
533
+	 * @param  string  $field  the field name used in LIKE statment
534
+	 * @param  string  $data   the LIKE value for this field including the '%', and '_' part
535
+	 * @param  string  $type   the condition separator type (NOT)
536
+	 * @param  string  $andOr the multiple conditions separator (OR, AND)
537
+	 * @param  boolean $escape whether to escape or not the values
538
+	 * @return object        the current DatabaseQueryBuilder instance
539
+	 */
540
+	public function like($field, $data, $type = '', $andOr = 'AND', $escape = true){
541
+	  if (empty($data)){
542
+		$data = '';
543
+	  }
544
+	  $this->setWhereStr($field . ' ' . $type . ' LIKE ' . ($this->escape($data, $escape)), $andOr);
545
+	  return $this;
546
+	}
547
+
548
+	/**
549
+	 * Set the SQL WHERE CLAUSE statment for LIKE with OR separator
550
+	 * @see  DatabaseQueryBuilder::like()
551
+	 * @return object        the current DatabaseQueryBuilder instance
552
+	 */
553
+	public function orLike($field, $data, $escape = true){
554
+	  return $this->like($field, $data, '', 'OR', $escape);
555
+	}
556
+
557
+	/**
558
+	 * Set the SQL WHERE CLAUSE statment for LIKE with NOT type and AND separator
559
+	 * @see  DatabaseQueryBuilder::like()
560
+	 * @return object        the current DatabaseQueryBuilder instance
561
+	 */
562
+	public function notLike($field, $data, $escape = true){
563
+	  return $this->like($field, $data, 'NOT ', 'AND', $escape);
564
+	}
565
+
566
+	/**
567
+	 * Set the SQL WHERE CLAUSE statment for LIKE with NOT type and OR separator
568
+	 * @see  DatabaseQueryBuilder::like()
569
+	 * @return object        the current DatabaseQueryBuilder instance
570
+	 */
571
+	public function orNotLike($field, $data, $escape = true){
572
+	  return $this->like($field, $data, 'NOT ', 'OR', $escape);
573
+	}
574
+
575
+	/**
576
+	 * Set the SQL LIMIT statment
577
+	 * @param  int $limit    the limit offset. If $limitEnd is null this will be the limit count
578
+	 * like LIMIT n;
579
+	 * @param  int $limitEnd the limit count
580
+	 * @return object        the current DatabaseQueryBuilder instance
581
+	 */
582
+	public function limit($limit, $limitEnd = null){
583
+	  if (empty($limit)){
584
+		$limit = 0;
585
+	  }
586
+	  if (! is_null($limitEnd)){
587
+		$this->limit = $limit . ', ' . $limitEnd;
588
+	  }
589
+	  else{
590
+		$this->limit = $limit;
591
+	  }
592
+	  return $this;
593
+	}
594
+
595
+	/**
596
+	 * Set the SQL ORDER BY CLAUSE statment
597
+	 * @param  string $orderBy   the field name used for order
598
+	 * @param  string $orderDir the order direction (ASC or DESC)
599
+	 * @return object        the current DatabaseQueryBuilder instance
600
+	 */
601
+	public function orderBy($orderBy, $orderDir = ' ASC'){
602
+	  if (stristr($orderBy, ' ') || $orderBy == 'rand()'){
603
+		$this->orderBy = empty($this->orderBy) ? $orderBy : $this->orderBy . ', ' . $orderBy;
604
+	  }
605
+	  else{
606
+		$this->orderBy = empty($this->orderBy) 
607 607
 						? ($orderBy . ' ' . strtoupper($orderDir)) 
608 608
 						: $this->orderBy . ', ' . $orderBy . ' ' . strtoupper($orderDir);
609
-      }
610
-      return $this;
611
-    }
612
-
613
-    /**
614
-     * Set the SQL GROUP BY CLAUSE statment
615
-     * @param  string|array $field the field name used or array of field list
616
-     * @return object        the current DatabaseQueryBuilder instance
617
-     */
618
-    public function groupBy($field){
619
-      if (is_array($field)){
620
-        $this->groupBy = implode(', ', $field);
621
-      }
622
-      else{
623
-        $this->groupBy = $field;
624
-      }
625
-      return $this;
626
-    }
627
-
628
-    /**
629
-     * Set the SQL HAVING CLAUSE statment
630
-     * @param  string  $field  the field name used for HAVING statment
631
-     * @param  string|array  $op     the operator used or array
632
-     * @param  mixed  $val    the value for HAVING comparaison
633
-     * @param  boolean $escape whether to escape or not the values
634
-     * @return object        the current DatabaseQueryBuilder instance
635
-     */
636
-    public function having($field, $op = null, $val = null, $escape = true){
637
-      if (is_array($op)){
638
-        $this->having = $this->getHavingStrIfOperatorIsArray($field, $op, $escape);
639
-      }
640
-      else if (! in_array($op, $this->operatorList)){
641
-        if (is_null($op)){
642
-          $op = '';
643
-        }
644
-        $this->having = $field . ' > ' . ($this->escape($op, $escape));
645
-      }
646
-      else{
647
-        if (is_null($val)){
648
-          $val = '';
649
-        }
650
-        $this->having = $field . ' ' . $op . ' ' . ($this->escape($val, $escape));
651
-      }
652
-      return $this;
653
-    }
654
-
655
-    /**
656
-     * Insert new record in the database
657
-     * @param  array   $data   the record data
658
-     * @param  boolean $escape  whether to escape or not the values
659
-     * @return object  the current DatabaseQueryBuilder instance        
660
-     */
661
-    public function insert($data = array(), $escape = true){
662
-      $columns = array_keys($data);
663
-      $column = implode(',', $columns);
664
-      $val = implode(', ', ($escape ? array_map(array($this, 'escape'), $data) : $data));
665
-
666
-      $this->query = 'INSERT INTO ' . $this->from . ' (' . $column . ') VALUES (' . $val . ')';
667
-      return $this;
668
-    }
669
-
670
-    /**
671
-     * Update record in the database
672
-     * @param  array   $data   the record data if is empty will use the $this->data array.
673
-     * @param  boolean $escape  whether to escape or not the values
674
-     * @return object  the current DatabaseQueryBuilder instance 
675
-     */
676
-    public function update($data = array(), $escape = true){
677
-      $query = 'UPDATE ' . $this->from . ' SET ';
678
-      $values = array();
679
-      foreach ($data as $column => $val){
680
-        $values[] = $column . ' = ' . ($this->escape($val, $escape));
681
-      }
682
-      $query .= implode(', ', $values);
683
-      if (! empty($this->where)){
684
-        $query .= ' WHERE ' . $this->where;
685
-      }
686
-
687
-      if (! empty($this->orderBy)){
688
-        $query .= ' ORDER BY ' . $this->orderBy;
689
-      }
690
-
691
-      if (! empty($this->limit)){
692
-        $query .= ' LIMIT ' . $this->limit;
693
-      }
694
-      $this->query = $query;
695
-      return $this;
696
-    }
697
-
698
-    /**
699
-     * Delete the record in database
700
-     * @return object  the current DatabaseQueryBuilder instance 
701
-     */
702
-    public function delete(){
703
-    	$query = 'DELETE FROM ' . $this->from;
704
-      $isTruncate = $query;
705
-    	if (! empty($this->where)){
609
+	  }
610
+	  return $this;
611
+	}
612
+
613
+	/**
614
+	 * Set the SQL GROUP BY CLAUSE statment
615
+	 * @param  string|array $field the field name used or array of field list
616
+	 * @return object        the current DatabaseQueryBuilder instance
617
+	 */
618
+	public function groupBy($field){
619
+	  if (is_array($field)){
620
+		$this->groupBy = implode(', ', $field);
621
+	  }
622
+	  else{
623
+		$this->groupBy = $field;
624
+	  }
625
+	  return $this;
626
+	}
627
+
628
+	/**
629
+	 * Set the SQL HAVING CLAUSE statment
630
+	 * @param  string  $field  the field name used for HAVING statment
631
+	 * @param  string|array  $op     the operator used or array
632
+	 * @param  mixed  $val    the value for HAVING comparaison
633
+	 * @param  boolean $escape whether to escape or not the values
634
+	 * @return object        the current DatabaseQueryBuilder instance
635
+	 */
636
+	public function having($field, $op = null, $val = null, $escape = true){
637
+	  if (is_array($op)){
638
+		$this->having = $this->getHavingStrIfOperatorIsArray($field, $op, $escape);
639
+	  }
640
+	  else if (! in_array($op, $this->operatorList)){
641
+		if (is_null($op)){
642
+		  $op = '';
643
+		}
644
+		$this->having = $field . ' > ' . ($this->escape($op, $escape));
645
+	  }
646
+	  else{
647
+		if (is_null($val)){
648
+		  $val = '';
649
+		}
650
+		$this->having = $field . ' ' . $op . ' ' . ($this->escape($val, $escape));
651
+	  }
652
+	  return $this;
653
+	}
654
+
655
+	/**
656
+	 * Insert new record in the database
657
+	 * @param  array   $data   the record data
658
+	 * @param  boolean $escape  whether to escape or not the values
659
+	 * @return object  the current DatabaseQueryBuilder instance        
660
+	 */
661
+	public function insert($data = array(), $escape = true){
662
+	  $columns = array_keys($data);
663
+	  $column = implode(',', $columns);
664
+	  $val = implode(', ', ($escape ? array_map(array($this, 'escape'), $data) : $data));
665
+
666
+	  $this->query = 'INSERT INTO ' . $this->from . ' (' . $column . ') VALUES (' . $val . ')';
667
+	  return $this;
668
+	}
669
+
670
+	/**
671
+	 * Update record in the database
672
+	 * @param  array   $data   the record data if is empty will use the $this->data array.
673
+	 * @param  boolean $escape  whether to escape or not the values
674
+	 * @return object  the current DatabaseQueryBuilder instance 
675
+	 */
676
+	public function update($data = array(), $escape = true){
677
+	  $query = 'UPDATE ' . $this->from . ' SET ';
678
+	  $values = array();
679
+	  foreach ($data as $column => $val){
680
+		$values[] = $column . ' = ' . ($this->escape($val, $escape));
681
+	  }
682
+	  $query .= implode(', ', $values);
683
+	  if (! empty($this->where)){
684
+		$query .= ' WHERE ' . $this->where;
685
+	  }
686
+
687
+	  if (! empty($this->orderBy)){
688
+		$query .= ' ORDER BY ' . $this->orderBy;
689
+	  }
690
+
691
+	  if (! empty($this->limit)){
692
+		$query .= ' LIMIT ' . $this->limit;
693
+	  }
694
+	  $this->query = $query;
695
+	  return $this;
696
+	}
697
+
698
+	/**
699
+	 * Delete the record in database
700
+	 * @return object  the current DatabaseQueryBuilder instance 
701
+	 */
702
+	public function delete(){
703
+		$query = 'DELETE FROM ' . $this->from;
704
+	  $isTruncate = $query;
705
+		if (! empty($this->where)){
706 706
   		  $query .= ' WHERE ' . $this->where;
707
-    	}
707
+		}
708 708
 
709
-    	if (! empty($this->orderBy)){
710
-    	  $query .= ' ORDER BY ' . $this->orderBy;
711
-      }
709
+		if (! empty($this->orderBy)){
710
+		  $query .= ' ORDER BY ' . $this->orderBy;
711
+	  }
712 712
 
713
-    	if (! empty($this->limit)){
714
-    		$query .= ' LIMIT ' . $this->limit;
715
-      }
713
+		if (! empty($this->limit)){
714
+			$query .= ' LIMIT ' . $this->limit;
715
+	  }
716 716
 
717 717
   		if ($isTruncate == $query && $this->driver != 'sqlite'){  
718
-      	$query = 'TRUNCATE TABLE ' . $this->from;
718
+	  	$query = 'TRUNCATE TABLE ' . $this->from;
719 719
   		}
720 720
 	   $this->query = $query;
721 721
 	   return $this;
722
-    }
723
-
724
-    /**
725
-     * Escape the data before execute query useful for security.
726
-     * @param  mixed $data the data to be escaped
727
-     * @param boolean $escaped whether we can do escape of not 
728
-     * @return mixed       the data after escaped or the same data if not
729
-     */
730
-    public function escape($data, $escaped = true){
731
-      return $escaped 
732
-                    ? $this->getPdo()->quote(trim($data)) 
733
-                    : $data; 
734
-    }
735
-
736
-
737
-    /**
738
-     * Return the current SQL query string
739
-     * @return string
740
-     */
741
-    public function getQuery(){
722
+	}
723
+
724
+	/**
725
+	 * Escape the data before execute query useful for security.
726
+	 * @param  mixed $data the data to be escaped
727
+	 * @param boolean $escaped whether we can do escape of not 
728
+	 * @return mixed       the data after escaped or the same data if not
729
+	 */
730
+	public function escape($data, $escaped = true){
731
+	  return $escaped 
732
+					? $this->getPdo()->quote(trim($data)) 
733
+					: $data; 
734
+	}
735
+
736
+
737
+	/**
738
+	 * Return the current SQL query string
739
+	 * @return string
740
+	 */
741
+	public function getQuery(){
742 742
   	  //INSERT, UPDATE, DELETE already set it, if is the SELECT we need set it now
743 743
   	  if(empty($this->query)){
744 744
   		  $query = 'SELECT ' . $this->select . ' FROM ' . $this->from;
745 745
   		  if (! empty($this->join)){
746
-          $query .= $this->join;
746
+		  $query .= $this->join;
747 747
   		  }
748 748
   		  
749 749
   		  if (! empty($this->where)){
750
-          $query .= ' WHERE ' . $this->where;
750
+		  $query .= ' WHERE ' . $this->where;
751 751
   		  }
752 752
 
753 753
   		  if (! empty($this->groupBy)){
754
-          $query .= ' GROUP BY ' . $this->groupBy;
754
+		  $query .= ' GROUP BY ' . $this->groupBy;
755 755
   		  }
756 756
 
757 757
   		  if (! empty($this->having)){
758
-          $query .= ' HAVING ' . $this->having;
758
+		  $query .= ' HAVING ' . $this->having;
759 759
   		  }
760 760
 
761 761
   		  if (! empty($this->orderBy)){
@@ -763,198 +763,198 @@  discard block
 block discarded – undo
763 763
   		  }
764 764
 
765 765
   		  if (! empty($this->limit)){
766
-          $query .= ' LIMIT ' . $this->limit;
766
+		  $query .= ' LIMIT ' . $this->limit;
767 767
   		  }
768 768
   		  $this->query = $query;
769 769
   	  }
770
-      return $this->query;
771
-    }
770
+	  return $this->query;
771
+	}
772 772
 
773 773
 	
774 774
 	 /**
775
-     * Return the PDO instance
776
-     * @return PDO
777
-     */
778
-    public function getPdo(){
779
-      return $this->pdo;
780
-    }
781
-
782
-    /**
783
-     * Set the PDO instance
784
-     * @param PDO $pdo the pdo object
775
+	  * Return the PDO instance
776
+	  * @return PDO
777
+	  */
778
+	public function getPdo(){
779
+	  return $this->pdo;
780
+	}
781
+
782
+	/**
783
+	 * Set the PDO instance
784
+	 * @param PDO $pdo the pdo object
785 785
 	 * @return object DatabaseQueryBuilder
786
-     */
787
-    public function setPdo(PDO $pdo = null){
788
-      $this->pdo = $pdo;
789
-      return $this;
790
-    }
786
+	 */
787
+	public function setPdo(PDO $pdo = null){
788
+	  $this->pdo = $pdo;
789
+	  return $this;
790
+	}
791 791
 	
792 792
    /**
793
-   * Return the database table prefix
794
-   * @return string
795
-   */
796
-    public function getPrefix(){
797
-      return $this->prefix;
798
-    }
799
-
800
-    /**
801
-     * Set the database table prefix
802
-     * @param string $prefix the new prefix
803
-	   * @return object DatabaseQueryBuilder
804
-     */
805
-    public function setPrefix($prefix){
806
-      $this->prefix = $prefix;
807
-      return $this;
808
-    }
793
+    * Return the database table prefix
794
+    * @return string
795
+    */
796
+	public function getPrefix(){
797
+	  return $this->prefix;
798
+	}
799
+
800
+	/**
801
+	 * Set the database table prefix
802
+	 * @param string $prefix the new prefix
803
+	 * @return object DatabaseQueryBuilder
804
+	 */
805
+	public function setPrefix($prefix){
806
+	  $this->prefix = $prefix;
807
+	  return $this;
808
+	}
809 809
 	
810 810
 	   /**
811
-     * Return the database driver
812
-     * @return string
813
-     */
814
-    public function getDriver(){
815
-      return $this->driver;
816
-    }
817
-
818
-    /**
819
-     * Set the database driver
820
-     * @param string $driver the new driver
821
-	   * @return object DatabaseQueryBuilder
822
-     */
823
-    public function setDriver($driver){
824
-      $this->driver = $driver;
825
-      return $this;
826
-    }
811
+	    * Return the database driver
812
+	    * @return string
813
+	    */
814
+	public function getDriver(){
815
+	  return $this->driver;
816
+	}
817
+
818
+	/**
819
+	 * Set the database driver
820
+	 * @param string $driver the new driver
821
+	 * @return object DatabaseQueryBuilder
822
+	 */
823
+	public function setDriver($driver){
824
+	  $this->driver = $driver;
825
+	  return $this;
826
+	}
827 827
 	
828 828
 	   /**
829
-     * Reset the DatabaseQueryBuilder class attributs to the initial values before each query.
830
-	   * @return object  the current DatabaseQueryBuilder instance 
831
-     */
832
-    public function reset(){
833
-      $this->select   = '*';
834
-      $this->from     = null;
835
-      $this->where    = null;
836
-      $this->limit    = null;
837
-      $this->orderBy  = null;
838
-      $this->groupBy  = null;
839
-      $this->having   = null;
840
-      $this->join     = null;
841
-      $this->query    = null;
842
-      return $this;
843
-    }
829
+	    * Reset the DatabaseQueryBuilder class attributs to the initial values before each query.
830
+	    * @return object  the current DatabaseQueryBuilder instance 
831
+	    */
832
+	public function reset(){
833
+	  $this->select   = '*';
834
+	  $this->from     = null;
835
+	  $this->where    = null;
836
+	  $this->limit    = null;
837
+	  $this->orderBy  = null;
838
+	  $this->groupBy  = null;
839
+	  $this->having   = null;
840
+	  $this->join     = null;
841
+	  $this->query    = null;
842
+	  return $this;
843
+	}
844 844
 
845 845
 	   /**
846
-     * Get the SQL HAVING clause when operator argument is an array
847
-     * @see DatabaseQueryBuilder::having
848
-     *
849
-     * @return string
850
-     */
851
-    protected function getHavingStrIfOperatorIsArray($field, $op = null, $escape = true){
852
-        $x = explode('?', $field);
853
-        $w = '';
854
-        foreach($x as $k => $v){
855
-  	      if (!empty($v)){
856
-            if (! isset($op[$k])){
857
-              $op[$k] = '';
858
-            }
859
-  	      	$w .= $v . (isset($op[$k]) ? $this->escape($op[$k], $escape) : '');
860
-  	      }
861
-      	}
862
-        return $w;
863
-    }
864
-
865
-
866
-    /**
867
-     * Get the SQL WHERE clause using array column => value
868
-     * @see DatabaseQueryBuilder::where
869
-     *
870
-     * @return string
871
-     */
872
-    protected function getWhereStrIfIsArray(array $where, $type = '', $andOr = 'AND', $escape = true){
873
-      $_where = array();
874
-      foreach ($where as $column => $data){
875
-        if (is_null($data)){
876
-          $data = '';
877
-        }
878
-        $_where[] = $type . $column . ' = ' . ($this->escape($data, $escape));
879
-      }
880
-      $where = implode(' '.$andOr.' ', $_where);
881
-      return $where;
882
-    }
883
-
884
-     /**
885
-     * Get the SQL WHERE clause when operator argument is an array
886
-     * @see DatabaseQueryBuilder::where
887
-     *
888
-     * @return string
889
-     */
890
-    protected function getWhereStrIfOperatorIsArray($where, array $op, $type = '', $escape = true){
891
-     $x = explode('?', $where);
892
-     $w = '';
893
-      foreach($x as $k => $v){
894
-        if (! empty($v)){
895
-            if (isset($op[$k]) && is_null($op[$k])){
896
-              $op[$k] = '';
897
-            }
898
-            $w .= $type . $v . (isset($op[$k]) ? ($this->escape($op[$k], $escape)) : '');
899
-        }
900
-      }
901
-      return $w;
902
-    }
903
-
904
-    /**
905
-     * Get the default SQL WHERE clause using operator = or the operator argument
906
-     * @see DatabaseQueryBuilder::where
907
-     *
908
-     * @return string
909
-     */
910
-    protected function getWhereStrForOperator($where, $op = null, $val = null, $type = '', $escape = true){
911
-       $w = '';
912
-       if (! in_array((string)$op, $this->operatorList)){
913
-          if (is_null($op)){
914
-            $op = '';
915
-          }
916
-          $w = $type . $where . ' = ' . ($this->escape($op, $escape));
917
-        } else {
918
-          if (is_null($val)){
919
-            $val = '';
920
-          }
921
-          $w = $type . $where . $op . ($this->escape($val, $escape));
922
-        }
923
-        return $w;
924
-      }
925
-
926
-      /**
927
-       * Set the $this->where property 
928
-       * @param string $whereStr the WHERE clause string
929
-       * @param  string  $andOr the separator type used 'AND', 'OR', etc.
930
-       */
931
-      protected function setWhereStr($whereStr, $andOr = 'AND'){
932
-        if (empty($this->where)){
933
-          $this->where = $whereStr;
934
-        } else {
935
-          if (substr(trim($this->where), -1) == '('){
936
-            $this->where = $this->where . ' ' . $whereStr;
937
-          } else {
938
-            $this->where = $this->where . ' '.$andOr.' ' . $whereStr;
939
-          }
940
-        }
941
-      }
846
+	    * Get the SQL HAVING clause when operator argument is an array
847
+	    * @see DatabaseQueryBuilder::having
848
+	    *
849
+	    * @return string
850
+	    */
851
+	protected function getHavingStrIfOperatorIsArray($field, $op = null, $escape = true){
852
+		$x = explode('?', $field);
853
+		$w = '';
854
+		foreach($x as $k => $v){
855
+  		  if (!empty($v)){
856
+			if (! isset($op[$k])){
857
+			  $op[$k] = '';
858
+			}
859
+  		  	$w .= $v . (isset($op[$k]) ? $this->escape($op[$k], $escape) : '');
860
+  		  }
861
+	  	}
862
+		return $w;
863
+	}
864
+
865
+
866
+	/**
867
+	 * Get the SQL WHERE clause using array column => value
868
+	 * @see DatabaseQueryBuilder::where
869
+	 *
870
+	 * @return string
871
+	 */
872
+	protected function getWhereStrIfIsArray(array $where, $type = '', $andOr = 'AND', $escape = true){
873
+	  $_where = array();
874
+	  foreach ($where as $column => $data){
875
+		if (is_null($data)){
876
+		  $data = '';
877
+		}
878
+		$_where[] = $type . $column . ' = ' . ($this->escape($data, $escape));
879
+	  }
880
+	  $where = implode(' '.$andOr.' ', $_where);
881
+	  return $where;
882
+	}
883
+
884
+	 /**
885
+	  * Get the SQL WHERE clause when operator argument is an array
886
+	  * @see DatabaseQueryBuilder::where
887
+	  *
888
+	  * @return string
889
+	  */
890
+	protected function getWhereStrIfOperatorIsArray($where, array $op, $type = '', $escape = true){
891
+	 $x = explode('?', $where);
892
+	 $w = '';
893
+	  foreach($x as $k => $v){
894
+		if (! empty($v)){
895
+			if (isset($op[$k]) && is_null($op[$k])){
896
+			  $op[$k] = '';
897
+			}
898
+			$w .= $type . $v . (isset($op[$k]) ? ($this->escape($op[$k], $escape)) : '');
899
+		}
900
+	  }
901
+	  return $w;
902
+	}
903
+
904
+	/**
905
+	 * Get the default SQL WHERE clause using operator = or the operator argument
906
+	 * @see DatabaseQueryBuilder::where
907
+	 *
908
+	 * @return string
909
+	 */
910
+	protected function getWhereStrForOperator($where, $op = null, $val = null, $type = '', $escape = true){
911
+	   $w = '';
912
+	   if (! in_array((string)$op, $this->operatorList)){
913
+		  if (is_null($op)){
914
+			$op = '';
915
+		  }
916
+		  $w = $type . $where . ' = ' . ($this->escape($op, $escape));
917
+		} else {
918
+		  if (is_null($val)){
919
+			$val = '';
920
+		  }
921
+		  $w = $type . $where . $op . ($this->escape($val, $escape));
922
+		}
923
+		return $w;
924
+	  }
925
+
926
+	  /**
927
+	   * Set the $this->where property 
928
+	   * @param string $whereStr the WHERE clause string
929
+	   * @param  string  $andOr the separator type used 'AND', 'OR', etc.
930
+	   */
931
+	  protected function setWhereStr($whereStr, $andOr = 'AND'){
932
+		if (empty($this->where)){
933
+		  $this->where = $whereStr;
934
+		} else {
935
+		  if (substr(trim($this->where), -1) == '('){
936
+			$this->where = $this->where . ' ' . $whereStr;
937
+		  } else {
938
+			$this->where = $this->where . ' '.$andOr.' ' . $whereStr;
939
+		  }
940
+		}
941
+	  }
942 942
 
943 943
 
944 944
 	 /**
945
-     * Set the SQL SELECT for function MIN, MAX, SUM, AVG, COUNT, AVG
946
-     * @param  string $clause the clause type like MIN, MAX, etc.
947
-     * @see  DatabaseQueryBuilder::min
948
-     * @see  DatabaseQueryBuilder::max
949
-     * @see  DatabaseQueryBuilder::sum
950
-     * @see  DatabaseQueryBuilder::count
951
-     * @see  DatabaseQueryBuilder::avg
952
-     * @return object
953
-     */
954
-    protected function select_min_max_sum_count_avg($clause, $field, $name = null){
955
-      $clause = strtoupper($clause);
956
-      $func = $clause . '(' . $field . ')' . (!is_null($name) ? ' AS ' . $name : '');
957
-      $this->select = ($this->select == '*' ? $func : $this->select . ', ' . $func);
958
-      return $this;
959
-    }
945
+	  * Set the SQL SELECT for function MIN, MAX, SUM, AVG, COUNT, AVG
946
+	  * @param  string $clause the clause type like MIN, MAX, etc.
947
+	  * @see  DatabaseQueryBuilder::min
948
+	  * @see  DatabaseQueryBuilder::max
949
+	  * @see  DatabaseQueryBuilder::sum
950
+	  * @see  DatabaseQueryBuilder::count
951
+	  * @see  DatabaseQueryBuilder::avg
952
+	  * @return object
953
+	  */
954
+	protected function select_min_max_sum_count_avg($clause, $field, $name = null){
955
+	  $clause = strtoupper($clause);
956
+	  $func = $clause . '(' . $field . ')' . (!is_null($name) ? ' AS ' . $name : '');
957
+	  $this->select = ($this->select == '*' ? $func : $this->select . ', ' . $func);
958
+	  return $this;
959
+	}
960 960
 }
Please login to merge, or discard this patch.
core/classes/cache/FileCache.php 1 patch
Indentation   +86 added lines, -86 removed lines patch added patch discarded remove patch
@@ -22,7 +22,7 @@  discard block
 block discarded – undo
22 22
 	 * You should have received a copy of the GNU General Public License
23 23
 	 * along with this program; if not, write to the Free Software
24 24
 	 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25
-	*/
25
+	 */
26 26
 
27 27
 	class FileCache implements CacheInterface{
28 28
 		
@@ -44,15 +44,15 @@  discard block
 block discarded – undo
44 44
 				show_error('The cache for file system is not available. Check the cache directory if is exists or is writable.');
45 45
 			}
46 46
 			/**
47
-	         * instance of the Log class
48
-	         */
49
-	        if(is_object($logger)){
50
-	          $this->logger = $logger;
51
-	        }
52
-	        else{
53
-	            $this->logger =& class_loader('Log', 'classes');
54
-	            $this->logger->setLogger('Library::FileCache');
55
-	        }
47
+			 * instance of the Log class
48
+			 */
49
+			if(is_object($logger)){
50
+			  $this->logger = $logger;
51
+			}
52
+			else{
53
+				$this->logger =& class_loader('Log', 'classes');
54
+				$this->logger->setLogger('Library::FileCache');
55
+			}
56 56
 			
57 57
 			//if Zlib extension is not loaded set compressCacheData to false
58 58
 			if(! extension_loaded('zlib')){
@@ -80,26 +80,26 @@  discard block
 block discarded – undo
80 80
 				return false;
81 81
 			}
82 82
 			// Getting a shared lock 
83
-		    flock($handle, LOCK_SH);
84
-		    $data = file_get_contents($filePath);
85
-      		fclose($handle);
86
-      		$data = @unserialize($this->compressCacheData ? gzinflate($data) : $data);
87
-      		if (! $data) {
88
-      			$this->logger->error('Can not unserialize the cache data for the key ['. $key .'], return false');
89
-		         // If unserializing somehow didn't work out, we'll delete the file
90
-		         unlink($filePath);
91
-		         return false;
92
-	      	}
93
-	      	if (time() > $data['expire']) {
94
-	      		$this->logger->info('The cache data for the key ['. $key .'] already expired delete the cache file [' .$filePath. ']');
95
-		        // Unlinking when the file was expired
96
-		        unlink($filePath);
97
-		        return false;
98
-		     }
99
-		     else{
100
-		     	$this->logger->info('The cache not yet expire, now return the cache data for key ['. $key .'], the cache will expire at [' . date('Y-m-d H:i:s', $data['expire']) . ']');
101
-		     	return $data['data'];
102
-		     }
83
+			flock($handle, LOCK_SH);
84
+			$data = file_get_contents($filePath);
85
+	  		fclose($handle);
86
+	  		$data = @unserialize($this->compressCacheData ? gzinflate($data) : $data);
87
+	  		if (! $data) {
88
+	  			$this->logger->error('Can not unserialize the cache data for the key ['. $key .'], return false');
89
+				 // If unserializing somehow didn't work out, we'll delete the file
90
+				 unlink($filePath);
91
+				 return false;
92
+		  	}
93
+		  	if (time() > $data['expire']) {
94
+		  		$this->logger->info('The cache data for the key ['. $key .'] already expired delete the cache file [' .$filePath. ']');
95
+				// Unlinking when the file was expired
96
+				unlink($filePath);
97
+				return false;
98
+			 }
99
+			 else{
100
+			 	$this->logger->info('The cache not yet expire, now return the cache data for key ['. $key .'], the cache will expire at [' . date('Y-m-d H:i:s', $data['expire']) . ']');
101
+			 	return $data['data'];
102
+			 }
103 103
 		}
104 104
 
105 105
 
@@ -121,25 +121,25 @@  discard block
 block discarded – undo
121 121
 			}
122 122
 			flock($handle, LOCK_EX); // exclusive lock, will get released when the file is closed
123 123
 			//Serializing along with the TTL
124
-		    $cacheData = serialize(array(
124
+			$cacheData = serialize(array(
125 125
 									'mtime' => time(),
126 126
 									'expire' => $expire,
127 127
 									'data' => $data,
128 128
 									'ttl' => $ttl
129 129
 									)
130 130
 								);		   
131
-		    $result = fwrite($handle, $this->compressCacheData ? gzdeflate($cacheData, 9) : $cacheData);
132
-		    if(! $result){
133
-		    	$this->logger->error('Can not write cache data into file [' .$filePath. '] for the key ['. $key .'], return false');
134
-		    	fclose($handle);
135
-		    	return false;
136
-		    }
137
-		    else{
138
-		    	$this->logger->info('Cache data saved into file [' .$filePath. '] for the key ['. $key .']');
139
-		    	fclose($handle);
131
+			$result = fwrite($handle, $this->compressCacheData ? gzdeflate($cacheData, 9) : $cacheData);
132
+			if(! $result){
133
+				$this->logger->error('Can not write cache data into file [' .$filePath. '] for the key ['. $key .'], return false');
134
+				fclose($handle);
135
+				return false;
136
+			}
137
+			else{
138
+				$this->logger->info('Cache data saved into file [' .$filePath. '] for the key ['. $key .']');
139
+				fclose($handle);
140 140
 				chmod($filePath, 0640);
141 141
 				return true;
142
-		    }
142
+			}
143 143
 		}	
144 144
 
145 145
 
@@ -159,7 +159,7 @@  discard block
 block discarded – undo
159 159
 			}
160 160
 			else{
161 161
 				$this->logger->info('Found cache file [' .$filePath. '] remove it');
162
-	      		unlink($filePath);
162
+		  		unlink($filePath);
163 163
 				return true;
164 164
 			}
165 165
 		}
@@ -182,7 +182,7 @@  discard block
 block discarded – undo
182 182
 			}
183 183
 			else{
184 184
 				$this->logger->info('Found cache file [' .$filePath. '] check the validity');
185
-	      		$data = file_get_contents($filePath);
185
+		  		$data = file_get_contents($filePath);
186 186
 				$data = @unserialize($this->compressCacheData ? gzinflate($data) : $data);
187 187
 				if(! $data){
188 188
 					$this->logger->warning('Can not unserialize the cache data for file [' . $filePath . ']');
@@ -222,17 +222,17 @@  discard block
 block discarded – undo
222 222
 				foreach ($list as $file) {
223 223
 					$this->logger->debug('Processing the cache file [' . $file . ']');
224 224
 					$data = file_get_contents($file);
225
-		      		$data = @unserialize($this->compressCacheData ? gzinflate($data) : $data);
226
-		      		if(! $data){
227
-		      			$this->logger->warning('Can not unserialize the cache data for file [' . $file . ']');
228
-		      		}
229
-		      		else if(time() > $data['expire']){
230
-		      			$this->logger->info('The cache data for file [' . $file . '] already expired remove it');
231
-		      			unlink($file);
232
-		      		}
233
-		      		else{
234
-		      			$this->logger->info('The cache data for file [' . $file . '] not yet expired skip it');
235
-		      		}
225
+			  		$data = @unserialize($this->compressCacheData ? gzinflate($data) : $data);
226
+			  		if(! $data){
227
+			  			$this->logger->warning('Can not unserialize the cache data for file [' . $file . ']');
228
+			  		}
229
+			  		else if(time() > $data['expire']){
230
+			  			$this->logger->info('The cache data for file [' . $file . '] already expired remove it');
231
+			  			unlink($file);
232
+			  		}
233
+			  		else{
234
+			  			$this->logger->info('The cache data for file [' . $file . '] not yet expired skip it');
235
+			  		}
236 236
 				}
237 237
 			}
238 238
 		}	
@@ -255,19 +255,19 @@  discard block
 block discarded – undo
255 255
 			}
256 256
 		}
257 257
 	
258
-	    /**
259
-	     * @return boolean
260
-	     */
261
-	    public function isCompressCacheData(){
262
-	        return $this->compressCacheData;
263
-	    }
258
+		/**
259
+		 * @return boolean
260
+		 */
261
+		public function isCompressCacheData(){
262
+			return $this->compressCacheData;
263
+		}
264 264
 
265
-	    /**
266
-	     * @param boolean $compressCacheData
267
-	     *
268
-	     * @return self
269
-	     */
270
-	    public function setCompressCacheData($status = true){
265
+		/**
266
+		 * @param boolean $compressCacheData
267
+		 *
268
+		 * @return self
269
+		 */
270
+		public function setCompressCacheData($status = true){
271 271
 			//if Zlib extension is not loaded set compressCacheData to false
272 272
 			if($status === true && ! extension_loaded('zlib')){
273 273
 				
@@ -278,7 +278,7 @@  discard block
 block discarded – undo
278 278
 				$this->compressCacheData = $status;
279 279
 			}
280 280
 			return $this;
281
-	    }
281
+		}
282 282
 		
283 283
 		/**
284 284
 		 * Check whether the cache feature for the handle is supported
@@ -290,28 +290,28 @@  discard block
 block discarded – undo
290 290
 		}
291 291
 
292 292
 		/**
293
-	     * Return the Log instance
294
-	     * @return Log
295
-	     */
296
-	    public function getLogger(){
297
-	      return $this->logger;
298
-	    }
293
+		 * Return the Log instance
294
+		 * @return Log
295
+		 */
296
+		public function getLogger(){
297
+		  return $this->logger;
298
+		}
299 299
 
300
-	    /**
301
-	     * Set the log instance
302
-	     * @param Log $logger the log object
303
-	     */
304
-	    public function setLogger(Log $logger){
305
-	      $this->logger = $logger;
306
-	      return $this;
307
-	    }
300
+		/**
301
+		 * Set the log instance
302
+		 * @param Log $logger the log object
303
+		 */
304
+		public function setLogger(Log $logger){
305
+		  $this->logger = $logger;
306
+		  return $this;
307
+		}
308 308
 		
309 309
 		/**
310
-		* Get the cache file full path for the given key
311
-		*
312
-		* @param $key the cache item key
313
-		* @return string  		the full cache file path for this key
314
-		*/
310
+		 * Get the cache file full path for the given key
311
+		 *
312
+		 * @param $key the cache item key
313
+		 * @return string  		the full cache file path for this key
314
+		 */
315 315
 		private function getFilePath($key){
316 316
 			return CACHE_PATH . md5($key) . '.cache';
317 317
 		}
Please login to merge, or discard this patch.
core/classes/model/Model.php 1 patch
Indentation   +920 added lines, -920 removed lines patch added patch discarded remove patch
@@ -1,561 +1,561 @@  discard block
 block discarded – undo
1 1
 <?php
2
-    defined('ROOT_PATH') || exit('Access denied');
3
-    /**
4
-     * TNH Framework
5
-     *
6
-     * A simple PHP framework using HMVC architecture
7
-     *
8
-     * This content is released under the GNU GPL License (GPL)
9
-     *
10
-     * Copyright (C) 2017 Tony NGUEREZA
11
-     *
12
-     * This program is free software; you can redistribute it and/or
13
-     * modify it under the terms of the GNU General Public License
14
-     * as published by the Free Software Foundation; either version 3
15
-     * of the License, or (at your option) any later version.
16
-     *
17
-     * This program is distributed in the hope that it will be useful,
18
-     * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
-     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
-     * GNU General Public License for more details.
21
-     *
22
-     * You should have received a copy of the GNU General Public License
23
-     * along with this program; if not, write to the Free Software
24
-     * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25
-    */
26
-
27
-
28
-    /**
29
-     * A base model with a series of CRUD functions (powered by CI's query builder),
30
-     * validation-in-model support, event callbacks and more.
31
-     *
32
-     * @link http://github.com/jamierumbelow/codeigniter-base-model
33
-     * @copyright Copyright (c) 2012, Jamie Rumbelow <http://jamierumbelow.net>
34
-     */
35
-
36
-    class Model{
37
-
38
-        /* --------------------------------------------------------------
2
+	defined('ROOT_PATH') || exit('Access denied');
3
+	/**
4
+	 * TNH Framework
5
+	 *
6
+	 * A simple PHP framework using HMVC architecture
7
+	 *
8
+	 * This content is released under the GNU GPL License (GPL)
9
+	 *
10
+	 * Copyright (C) 2017 Tony NGUEREZA
11
+	 *
12
+	 * This program is free software; you can redistribute it and/or
13
+	 * modify it under the terms of the GNU General Public License
14
+	 * as published by the Free Software Foundation; either version 3
15
+	 * of the License, or (at your option) any later version.
16
+	 *
17
+	 * This program is distributed in the hope that it will be useful,
18
+	 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
+	 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
+	 * GNU General Public License for more details.
21
+	 *
22
+	 * You should have received a copy of the GNU General Public License
23
+	 * along with this program; if not, write to the Free Software
24
+	 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25
+	 */
26
+
27
+
28
+	/**
29
+	 * A base model with a series of CRUD functions (powered by CI's query builder),
30
+	 * validation-in-model support, event callbacks and more.
31
+	 *
32
+	 * @link http://github.com/jamierumbelow/codeigniter-base-model
33
+	 * @copyright Copyright (c) 2012, Jamie Rumbelow <http://jamierumbelow.net>
34
+	 */
35
+
36
+	class Model{
37
+
38
+		/* --------------------------------------------------------------
39 39
          * VARIABLES
40 40
          * ------------------------------------------------------------ */
41 41
 
42
-        /**
43
-         * This model's default database table. Automatically
44
-         * guessed by pluralising the model name.
45
-         */
46
-        protected $_table;
47
-
48
-        /**
49
-         * The database connection object. Will be set to the default
50
-         * connection. This allows individual models to use different DBs
51
-         * without overwriting the global database connection.
52
-         */
53
-        protected $_database;
54
-
55
-        /**
56
-         * This model's default primary key or unique identifier.
57
-         * Used by the get(), update() and delete() functions.
58
-         */
59
-        protected $primary_key = 'id';
60
-
61
-        /**
62
-         * Support for soft deletes and this model's 'deleted' key
63
-         */
64
-        protected $soft_delete = false;
65
-        protected $soft_delete_key = 'is_deleted';
66
-        protected $_temporary_with_deleted = FALSE;
67
-        protected $_temporary_only_deleted = FALSE;
68
-
69
-        /**
70
-         * The various callbacks available to the model. Each are
71
-         * simple lists of method names (methods will be run on $this).
72
-         */
73
-        protected $before_create = array();
74
-        protected $after_create = array();
75
-        protected $before_update = array();
76
-        protected $after_update = array();
77
-        protected $before_get = array();
78
-        protected $after_get = array();
79
-        protected $before_delete = array();
80
-        protected $after_delete = array();
81
-
82
-        protected $callback_parameters = array();
83
-
84
-        /**
85
-         * Protected, non-modifiable attributes
86
-         */
87
-        protected $protected_attributes = array();
88
-
89
-        /**
90
-         * Relationship arrays. Use flat strings for defaults or string
91
-         * => array to customise the class name and primary key
92
-         */
93
-        protected $belongs_to = array();
94
-        protected $has_many = array();
95
-
96
-        protected $_with = array();
97
-
98
-        /**
99
-         * An array of validation rules. This needs to be the same format
100
-         * as validation rules passed to the FormValidation library.
101
-         */
102
-        protected $validate = array();
103
-
104
-        /**
105
-         * Optionally skip the validation. Used in conjunction with
106
-         * skip_validation() to skip data validation for any future calls.
107
-         */
108
-        protected $skip_validation = FALSE;
109
-
110
-        /**
111
-         * By default we return our results as objects. If we need to override
112
-         * this, we can, or, we could use the `as_array()` and `as_object()` scopes.
113
-         */
114
-        protected $return_type = 'object';
115
-
116
-        /**
117
-         * Set return type array or object
118
-         * @var string
119
-         */
120
-        protected $_temporary_return_type = NULL;
42
+		/**
43
+		 * This model's default database table. Automatically
44
+		 * guessed by pluralising the model name.
45
+		 */
46
+		protected $_table;
47
+
48
+		/**
49
+		 * The database connection object. Will be set to the default
50
+		 * connection. This allows individual models to use different DBs
51
+		 * without overwriting the global database connection.
52
+		 */
53
+		protected $_database;
54
+
55
+		/**
56
+		 * This model's default primary key or unique identifier.
57
+		 * Used by the get(), update() and delete() functions.
58
+		 */
59
+		protected $primary_key = 'id';
60
+
61
+		/**
62
+		 * Support for soft deletes and this model's 'deleted' key
63
+		 */
64
+		protected $soft_delete = false;
65
+		protected $soft_delete_key = 'is_deleted';
66
+		protected $_temporary_with_deleted = FALSE;
67
+		protected $_temporary_only_deleted = FALSE;
68
+
69
+		/**
70
+		 * The various callbacks available to the model. Each are
71
+		 * simple lists of method names (methods will be run on $this).
72
+		 */
73
+		protected $before_create = array();
74
+		protected $after_create = array();
75
+		protected $before_update = array();
76
+		protected $after_update = array();
77
+		protected $before_get = array();
78
+		protected $after_get = array();
79
+		protected $before_delete = array();
80
+		protected $after_delete = array();
81
+
82
+		protected $callback_parameters = array();
83
+
84
+		/**
85
+		 * Protected, non-modifiable attributes
86
+		 */
87
+		protected $protected_attributes = array();
88
+
89
+		/**
90
+		 * Relationship arrays. Use flat strings for defaults or string
91
+		 * => array to customise the class name and primary key
92
+		 */
93
+		protected $belongs_to = array();
94
+		protected $has_many = array();
95
+
96
+		protected $_with = array();
97
+
98
+		/**
99
+		 * An array of validation rules. This needs to be the same format
100
+		 * as validation rules passed to the FormValidation library.
101
+		 */
102
+		protected $validate = array();
103
+
104
+		/**
105
+		 * Optionally skip the validation. Used in conjunction with
106
+		 * skip_validation() to skip data validation for any future calls.
107
+		 */
108
+		protected $skip_validation = FALSE;
109
+
110
+		/**
111
+		 * By default we return our results as objects. If we need to override
112
+		 * this, we can, or, we could use the `as_array()` and `as_object()` scopes.
113
+		 */
114
+		protected $return_type = 'object';
115
+
116
+		/**
117
+		 * Set return type array or object
118
+		 * @var string
119
+		 */
120
+		protected $_temporary_return_type = NULL;
121 121
     	
122 122
     	
123
-    	/**
123
+		/**
124 124
     		The database cache time 
125
-    	*/
126
-    	protected $dbCacheTime = 0;
127
-
128
-        /**
129
-         * Instance of the Loader class
130
-         * @var Loader
131
-         */
132
-        protected $loaderInstance = null;
133
-
134
-        /**
135
-         * Instance of the FormValidation library
136
-         * @var FormValidation
137
-         */
138
-        protected $formValidationInstance = null;
125
+		 */
126
+		protected $dbCacheTime = 0;
127
+
128
+		/**
129
+		 * Instance of the Loader class
130
+		 * @var Loader
131
+		 */
132
+		protected $loaderInstance = null;
133
+
134
+		/**
135
+		 * Instance of the FormValidation library
136
+		 * @var FormValidation
137
+		 */
138
+		protected $formValidationInstance = null;
139 139
 		
140
-        /* --------------------------------------------------------------
140
+		/* --------------------------------------------------------------
141 141
          * GENERIC METHODS
142 142
          * ------------------------------------------------------------ */
143 143
 
144
-        /**
145
-         * Initialise the model, tie into the CodeIgniter superobject and
146
-         * try our best to guess the table name.
147
-         */
148
-        public function __construct(Database $db = null){
149
-            if (is_object($db)){
150
-                $this->setDatabaseInstance($db);
151
-            }
152
-            else{
153
-                $obj = & get_instance();
154
-        		if (isset($obj->database) && is_object($obj->database)){
155
-                    /**
156
-                    * NOTE: Need use "clone" because some Model need have the personal instance of the database library
157
-                    * to prevent duplication
158
-                    */
159
-        			$this->setDatabaseInstance(clone $obj->database);
160
-                }
161
-            }
162
-
163
-            array_unshift($this->before_create, 'protect_attributes');
164
-            array_unshift($this->before_update, 'protect_attributes');
165
-            $this->_temporary_return_type = $this->return_type;
166
-        }
167
-
168
-        /* --------------------------------------------------------------
144
+		/**
145
+		 * Initialise the model, tie into the CodeIgniter superobject and
146
+		 * try our best to guess the table name.
147
+		 */
148
+		public function __construct(Database $db = null){
149
+			if (is_object($db)){
150
+				$this->setDatabaseInstance($db);
151
+			}
152
+			else{
153
+				$obj = & get_instance();
154
+				if (isset($obj->database) && is_object($obj->database)){
155
+					/**
156
+					 * NOTE: Need use "clone" because some Model need have the personal instance of the database library
157
+					 * to prevent duplication
158
+					 */
159
+					$this->setDatabaseInstance(clone $obj->database);
160
+				}
161
+			}
162
+
163
+			array_unshift($this->before_create, 'protect_attributes');
164
+			array_unshift($this->before_update, 'protect_attributes');
165
+			$this->_temporary_return_type = $this->return_type;
166
+		}
167
+
168
+		/* --------------------------------------------------------------
169 169
          * CRUD INTERFACE
170 170
          * ------------------------------------------------------------ */
171 171
 
172
-        /**
173
-         * Fetch a single record based on the primary key. Returns an object.
174
-         */
175
-        public function get($primary_value)
176
-        {
177
-    		return $this->get_by($this->primary_key, $primary_value);
178
-        }
179
-
180
-        /**
181
-         * Fetch a single record based on an arbitrary WHERE call. Can be
182
-         * any valid value to DatabaseQueryBuilder->where().
183
-         */
184
-        public function get_by()
185
-        {
186
-            $where = func_get_args();
187
-
188
-            if ($this->soft_delete && $this->_temporary_with_deleted !== TRUE)
189
-            {
190
-                $this->getQueryBuilder()->where($this->soft_delete_key, (bool)$this->_temporary_only_deleted);
191
-            }
192
-    		$this->_set_where($where);
193
-
194
-            $this->trigger('before_get');
172
+		/**
173
+		 * Fetch a single record based on the primary key. Returns an object.
174
+		 */
175
+		public function get($primary_value)
176
+		{
177
+			return $this->get_by($this->primary_key, $primary_value);
178
+		}
179
+
180
+		/**
181
+		 * Fetch a single record based on an arbitrary WHERE call. Can be
182
+		 * any valid value to DatabaseQueryBuilder->where().
183
+		 */
184
+		public function get_by()
185
+		{
186
+			$where = func_get_args();
187
+
188
+			if ($this->soft_delete && $this->_temporary_with_deleted !== TRUE)
189
+			{
190
+				$this->getQueryBuilder()->where($this->soft_delete_key, (bool)$this->_temporary_only_deleted);
191
+			}
192
+			$this->_set_where($where);
193
+
194
+			$this->trigger('before_get');
195 195
 			$type = $this->_temporary_return_type == 'array' ? 'array' : false;
196
-            $this->getQueryBuilder()->from($this->_table);
196
+			$this->getQueryBuilder()->from($this->_table);
197 197
 			$row = $this->_database->get($type);
198
-            $this->_temporary_return_type = $this->return_type;
199
-            $row = $this->trigger('after_get', $row);
200
-            $this->_with = array();
201
-            return $row;
202
-        }
203
-
204
-        /**
205
-         * Fetch an array of records based on an array of primary values.
206
-         */
207
-        public function get_many($values)
208
-        {
209
-            $this->getQueryBuilder()->in($this->primary_key, $values);
210
-            return $this->get_all();
211
-        }
212
-
213
-        /**
214
-         * Fetch an array of records based on an arbitrary WHERE call.
215
-         */
216
-        public function get_many_by()
217
-        {
218
-            $where = func_get_args();
219
-            $this->_set_where($where);
220
-            return $this->get_all();
221
-        }
222
-
223
-        /**
224
-         * Fetch all the records in the table. Can be used as a generic call
225
-         * to $this->_database->get() with scoped methods.
226
-         */
227
-        public function get_all()
228
-        {
229
-            $this->trigger('before_get');
230
-            if ($this->soft_delete && $this->_temporary_with_deleted !== TRUE)
231
-            {
232
-                $this->getQueryBuilder()->where($this->soft_delete_key, (bool)$this->_temporary_only_deleted);
233
-            }
198
+			$this->_temporary_return_type = $this->return_type;
199
+			$row = $this->trigger('after_get', $row);
200
+			$this->_with = array();
201
+			return $row;
202
+		}
203
+
204
+		/**
205
+		 * Fetch an array of records based on an array of primary values.
206
+		 */
207
+		public function get_many($values)
208
+		{
209
+			$this->getQueryBuilder()->in($this->primary_key, $values);
210
+			return $this->get_all();
211
+		}
212
+
213
+		/**
214
+		 * Fetch an array of records based on an arbitrary WHERE call.
215
+		 */
216
+		public function get_many_by()
217
+		{
218
+			$where = func_get_args();
219
+			$this->_set_where($where);
220
+			return $this->get_all();
221
+		}
222
+
223
+		/**
224
+		 * Fetch all the records in the table. Can be used as a generic call
225
+		 * to $this->_database->get() with scoped methods.
226
+		 */
227
+		public function get_all()
228
+		{
229
+			$this->trigger('before_get');
230
+			if ($this->soft_delete && $this->_temporary_with_deleted !== TRUE)
231
+			{
232
+				$this->getQueryBuilder()->where($this->soft_delete_key, (bool)$this->_temporary_only_deleted);
233
+			}
234 234
 			$type = $this->_temporary_return_type == 'array' ? 'array':false;
235
-            $this->getQueryBuilder()->from($this->_table);
235
+			$this->getQueryBuilder()->from($this->_table);
236 236
 			$result = $this->_database->getAll($type);
237
-            $this->_temporary_return_type = $this->return_type;
238
-
239
-            foreach ($result as $key => &$row)
240
-            {
241
-                $row = $this->trigger('after_get', $row, ($key == count($result) - 1));
242
-            }
243
-            $this->_with = array();
244
-            return $result;
245
-        }
246
-
247
-        /**
248
-         * Insert a new row into the table. $data should be an associative array
249
-         * of data to be inserted. Returns newly created ID.
237
+			$this->_temporary_return_type = $this->return_type;
238
+
239
+			foreach ($result as $key => &$row)
240
+			{
241
+				$row = $this->trigger('after_get', $row, ($key == count($result) - 1));
242
+			}
243
+			$this->_with = array();
244
+			return $result;
245
+		}
246
+
247
+		/**
248
+		 * Insert a new row into the table. $data should be an associative array
249
+		 * of data to be inserted. Returns newly created ID.
250 250
 		 * @see Database::insert
251
-         */
252
-        public function insert($data = array(), $skip_validation = FALSE, $escape = true)
253
-        {
254
-            if ($skip_validation === FALSE)
255
-            {
256
-                $data = $this->validate($data);
257
-            }
258
-
259
-            if ($data !== FALSE)
260
-            {
261
-                $data = $this->trigger('before_create', $data);
262
-                $this->getQueryBuilder()->from($this->_table);
251
+		 */
252
+		public function insert($data = array(), $skip_validation = FALSE, $escape = true)
253
+		{
254
+			if ($skip_validation === FALSE)
255
+			{
256
+				$data = $this->validate($data);
257
+			}
258
+
259
+			if ($data !== FALSE)
260
+			{
261
+				$data = $this->trigger('before_create', $data);
262
+				$this->getQueryBuilder()->from($this->_table);
263 263
 				$this->_database->insert($data, $escape);
264
-                $insert_id = $this->_database->insertId();
265
-                $this->trigger('after_create', $insert_id);
264
+				$insert_id = $this->_database->insertId();
265
+				$this->trigger('after_create', $insert_id);
266 266
 				//if the table doesn't have the auto increment field or sequence, the value of 0 will be returned 
267 267
 				return ! $insert_id ? true : $insert_id;
268
-            }
269
-            else
270
-            {
271
-                return FALSE;
272
-            }
273
-        }
274
-
275
-        /**
276
-         * Insert multiple rows into the table. Returns an array of multiple IDs.
277
-         */
278
-        public function insert_many($data = array(), $skip_validation = FALSE, $escape = true)
279
-        {
280
-            $ids = array();
281
-            foreach ($data as $key => $row)
282
-            {
283
-                $ids[] = $this->insert($row, $skip_validation, $escape);
284
-            }
285
-            return $ids;
286
-        }
287
-
288
-        /**
289
-         * Updated a record based on the primary value.
290
-         */
291
-        public function update($primary_value, $data = array(), $skip_validation = FALSE, $escape = true)
292
-        {
293
-            $data = $this->trigger('before_update', $data);
294
-            if ($skip_validation === FALSE)
295
-            {
296
-                $data = $this->validate($data);
297
-            }
298
-
299
-            if ($data !== FALSE)
300
-            {
301
-                $this->getQueryBuilder()->where($this->primary_key, $primary_value)
302
-                                        ->from($this->_table);
303
-                $result = $this->_database->update($data, $escape);
304
-                $this->trigger('after_update', array($data, $result));
305
-                return $result;
306
-            }
307
-            else
308
-            {
309
-                return FALSE;
310
-            }
311
-        }
312
-
313
-        /**
314
-         * Update many records, based on an array of primary values.
315
-         */
316
-        public function update_many($primary_values, $data = array(), $skip_validation = FALSE, $escape = true)
317
-        {
318
-            $data = $this->trigger('before_update', $data);
319
-            if ($skip_validation === FALSE)
320
-            {
321
-                $data = $this->validate($data);
322
-            }
323
-            if ($data !== FALSE)
324
-            {
325
-                $this->getQueryBuilder()->in($this->primary_key, $primary_values)
326
-                                        ->from($this->_table);
268
+			}
269
+			else
270
+			{
271
+				return FALSE;
272
+			}
273
+		}
274
+
275
+		/**
276
+		 * Insert multiple rows into the table. Returns an array of multiple IDs.
277
+		 */
278
+		public function insert_many($data = array(), $skip_validation = FALSE, $escape = true)
279
+		{
280
+			$ids = array();
281
+			foreach ($data as $key => $row)
282
+			{
283
+				$ids[] = $this->insert($row, $skip_validation, $escape);
284
+			}
285
+			return $ids;
286
+		}
287
+
288
+		/**
289
+		 * Updated a record based on the primary value.
290
+		 */
291
+		public function update($primary_value, $data = array(), $skip_validation = FALSE, $escape = true)
292
+		{
293
+			$data = $this->trigger('before_update', $data);
294
+			if ($skip_validation === FALSE)
295
+			{
296
+				$data = $this->validate($data);
297
+			}
298
+
299
+			if ($data !== FALSE)
300
+			{
301
+				$this->getQueryBuilder()->where($this->primary_key, $primary_value)
302
+										->from($this->_table);
303
+				$result = $this->_database->update($data, $escape);
304
+				$this->trigger('after_update', array($data, $result));
305
+				return $result;
306
+			}
307
+			else
308
+			{
309
+				return FALSE;
310
+			}
311
+		}
312
+
313
+		/**
314
+		 * Update many records, based on an array of primary values.
315
+		 */
316
+		public function update_many($primary_values, $data = array(), $skip_validation = FALSE, $escape = true)
317
+		{
318
+			$data = $this->trigger('before_update', $data);
319
+			if ($skip_validation === FALSE)
320
+			{
321
+				$data = $this->validate($data);
322
+			}
323
+			if ($data !== FALSE)
324
+			{
325
+				$this->getQueryBuilder()->in($this->primary_key, $primary_values)
326
+										->from($this->_table);
327 327
 				$result = $this->_database->update($data, $escape);
328
-                $this->trigger('after_update', array($data, $result));
329
-                return $result;
330
-            }
331
-            else
332
-            {
333
-                return FALSE;
334
-            }
335
-        }
336
-
337
-        /**
338
-         * Updated a record based on an arbitrary WHERE clause.
339
-         */
340
-        public function update_by()
341
-        {
342
-            $args = func_get_args();
343
-            $data = array();
344
-            if (count($args) == 2){
345
-                if (is_array($args[1])){
346
-                    $data = array_pop($args);
347
-                }
348
-            }
349
-            else if (count($args) == 3){
350
-                if (is_array($args[2])){
351
-                    $data = array_pop($args);
352
-                }
353
-            }
354
-            $data = $this->trigger('before_update', $data);
355
-            if ($this->validate($data) !== FALSE)
356
-            {
357
-                $this->_set_where($args);
358
-                $this->getQueryBuilder()->from($this->_table);
328
+				$this->trigger('after_update', array($data, $result));
329
+				return $result;
330
+			}
331
+			else
332
+			{
333
+				return FALSE;
334
+			}
335
+		}
336
+
337
+		/**
338
+		 * Updated a record based on an arbitrary WHERE clause.
339
+		 */
340
+		public function update_by()
341
+		{
342
+			$args = func_get_args();
343
+			$data = array();
344
+			if (count($args) == 2){
345
+				if (is_array($args[1])){
346
+					$data = array_pop($args);
347
+				}
348
+			}
349
+			else if (count($args) == 3){
350
+				if (is_array($args[2])){
351
+					$data = array_pop($args);
352
+				}
353
+			}
354
+			$data = $this->trigger('before_update', $data);
355
+			if ($this->validate($data) !== FALSE)
356
+			{
357
+				$this->_set_where($args);
358
+				$this->getQueryBuilder()->from($this->_table);
359 359
 				$result = $this->_database->update($data);
360
-                $this->trigger('after_update', array($data, $result));
361
-                return $result;
362
-            }
363
-            else
364
-            {
365
-                return FALSE;
366
-            }
367
-        }
368
-
369
-        /**
370
-         * Update all records
371
-         */
372
-        public function update_all($data = array(), $escape = true)
373
-        {
374
-            $data = $this->trigger('before_update', $data);
375
-            $this->getQueryBuilder()->from($this->_table);
360
+				$this->trigger('after_update', array($data, $result));
361
+				return $result;
362
+			}
363
+			else
364
+			{
365
+				return FALSE;
366
+			}
367
+		}
368
+
369
+		/**
370
+		 * Update all records
371
+		 */
372
+		public function update_all($data = array(), $escape = true)
373
+		{
374
+			$data = $this->trigger('before_update', $data);
375
+			$this->getQueryBuilder()->from($this->_table);
376 376
 			$result = $this->_database->update($data, $escape);
377
-            $this->trigger('after_update', array($data, $result));
378
-            return $result;
379
-        }
380
-
381
-        /**
382
-         * Delete a row from the table by the primary value
383
-         */
384
-        public function delete($id)
385
-        {
386
-            $this->trigger('before_delete', $id);
387
-            $this->getQueryBuilder()->where($this->primary_key, $id);
377
+			$this->trigger('after_update', array($data, $result));
378
+			return $result;
379
+		}
380
+
381
+		/**
382
+		 * Delete a row from the table by the primary value
383
+		 */
384
+		public function delete($id)
385
+		{
386
+			$this->trigger('before_delete', $id);
387
+			$this->getQueryBuilder()->where($this->primary_key, $id);
388 388
 			$result = false;
389
-            if ($this->soft_delete)
390
-            {
391
-                $this->getQueryBuilder()->from($this->_table);	
389
+			if ($this->soft_delete)
390
+			{
391
+				$this->getQueryBuilder()->from($this->_table);	
392 392
 				$result = $this->_database->update(array( $this->soft_delete_key => TRUE ));
393
-            }
394
-            else
395
-            {
396
-                $this->getQueryBuilder()->from($this->_table); 
393
+			}
394
+			else
395
+			{
396
+				$this->getQueryBuilder()->from($this->_table); 
397 397
 				$result = $this->_database->delete();
398
-            }
399
-
400
-            $this->trigger('after_delete', $result);
401
-            return $result;
402
-        }
403
-
404
-        /**
405
-         * Delete a row from the database table by an arbitrary WHERE clause
406
-         */
407
-        public function delete_by()
408
-        {
409
-            $where = func_get_args();
410
-    	    $where = $this->trigger('before_delete', $where);
411
-            $this->_set_where($where);
398
+			}
399
+
400
+			$this->trigger('after_delete', $result);
401
+			return $result;
402
+		}
403
+
404
+		/**
405
+		 * Delete a row from the database table by an arbitrary WHERE clause
406
+		 */
407
+		public function delete_by()
408
+		{
409
+			$where = func_get_args();
410
+			$where = $this->trigger('before_delete', $where);
411
+			$this->_set_where($where);
412 412
 			$result = false;
413
-            if ($this->soft_delete)
414
-            {
415
-                $this->getQueryBuilder()->from($this->_table);	
413
+			if ($this->soft_delete)
414
+			{
415
+				$this->getQueryBuilder()->from($this->_table);	
416 416
 				$result = $this->_database->update(array( $this->soft_delete_key => TRUE ));
417
-            }
418
-            else
419
-            {
420
-                $this->getQueryBuilder()->from($this->_table); 
417
+			}
418
+			else
419
+			{
420
+				$this->getQueryBuilder()->from($this->_table); 
421 421
 				$result = $this->_database->delete();
422
-            }
423
-            $this->trigger('after_delete', $result);
424
-            return $result;
425
-        }
426
-
427
-        /**
428
-         * Delete many rows from the database table by multiple primary values
429
-         */
430
-        public function delete_many($primary_values)
431
-        {
432
-            $primary_values = $this->trigger('before_delete', $primary_values);
433
-            $this->getQueryBuilder()->in($this->primary_key, $primary_values);
422
+			}
423
+			$this->trigger('after_delete', $result);
424
+			return $result;
425
+		}
426
+
427
+		/**
428
+		 * Delete many rows from the database table by multiple primary values
429
+		 */
430
+		public function delete_many($primary_values)
431
+		{
432
+			$primary_values = $this->trigger('before_delete', $primary_values);
433
+			$this->getQueryBuilder()->in($this->primary_key, $primary_values);
434 434
 			$result = false;
435
-            if ($this->soft_delete)
436
-            {
437
-                $this->getQueryBuilder()->from($this->_table);	
435
+			if ($this->soft_delete)
436
+			{
437
+				$this->getQueryBuilder()->from($this->_table);	
438 438
 				$result = $this->_database->update(array( $this->soft_delete_key => TRUE ));
439
-            }
440
-            else
441
-            {
442
-                $this->getQueryBuilder()->from($this->_table); 
439
+			}
440
+			else
441
+			{
442
+				$this->getQueryBuilder()->from($this->_table); 
443 443
 				$result = $this->_database->delete();
444
-            }
445
-            $this->trigger('after_delete', $result);
446
-            return $result;
447
-        }
444
+			}
445
+			$this->trigger('after_delete', $result);
446
+			return $result;
447
+		}
448 448
 
449 449
 
450
-        /**
451
-         * Truncates the table
452
-         */
453
-        public function truncate()
454
-        {
450
+		/**
451
+		 * Truncates the table
452
+		 */
453
+		public function truncate()
454
+		{
455 455
 			$this->getQueryBuilder()->from($this->_table); 
456 456
 			$result = $this->_database->delete();
457
-            return $result;
458
-        }
457
+			return $result;
458
+		}
459 459
 
460
-        /* --------------------------------------------------------------
460
+		/* --------------------------------------------------------------
461 461
          * RELATIONSHIPS
462 462
          * ------------------------------------------------------------ */
463 463
 
464
-        public function with($relationship)
465
-        {
466
-            $this->_with[] = $relationship;
467
-            if (!in_array('relate', $this->after_get))
468
-            {
469
-                $this->after_get[] = 'relate';
470
-            }
471
-            return $this;
472
-        }
464
+		public function with($relationship)
465
+		{
466
+			$this->_with[] = $relationship;
467
+			if (!in_array('relate', $this->after_get))
468
+			{
469
+				$this->after_get[] = 'relate';
470
+			}
471
+			return $this;
472
+		}
473 473
 		
474 474
 		/**
475
-		* Relationship
476
-		*/
477
-        public function relate($row)
478
-        {
479
-    		if (empty($row))
480
-            {
481
-    		    return $row;
482
-            }
483
-
484
-            $row = $this->relateBelongsTo($row);
485
-            $row = $this->relateHasMany($row);
486
-            return $row;
487
-        }
488
-
489
-        /* --------------------------------------------------------------
475
+		 * Relationship
476
+		 */
477
+		public function relate($row)
478
+		{
479
+			if (empty($row))
480
+			{
481
+				return $row;
482
+			}
483
+
484
+			$row = $this->relateBelongsTo($row);
485
+			$row = $this->relateHasMany($row);
486
+			return $row;
487
+		}
488
+
489
+		/* --------------------------------------------------------------
490 490
          * UTILITY METHODS
491 491
          * ------------------------------------------------------------ */
492 492
 
493
-        /**
494
-         * Retrieve and generate a form_dropdown friendly array
495
-         */
496
-        public function dropdown()
497
-        {
498
-            $args = func_get_args();
499
-            if (count($args) == 2)
500
-            {
501
-                list($key, $value) = $args;
502
-            }
503
-            else
504
-            {
505
-                $key = $this->primary_key;
506
-                $value = $args[0];
507
-            }
508
-            $this->trigger('before_dropdown', array( $key, $value ));
509
-            if ($this->soft_delete && $this->_temporary_with_deleted !== TRUE)
510
-            {
511
-                $this->getQueryBuilder()->where($this->soft_delete_key, FALSE);
512
-            }
513
-            $this->getQueryBuilder()
493
+		/**
494
+		 * Retrieve and generate a form_dropdown friendly array
495
+		 */
496
+		public function dropdown()
497
+		{
498
+			$args = func_get_args();
499
+			if (count($args) == 2)
500
+			{
501
+				list($key, $value) = $args;
502
+			}
503
+			else
504
+			{
505
+				$key = $this->primary_key;
506
+				$value = $args[0];
507
+			}
508
+			$this->trigger('before_dropdown', array( $key, $value ));
509
+			if ($this->soft_delete && $this->_temporary_with_deleted !== TRUE)
510
+			{
511
+				$this->getQueryBuilder()->where($this->soft_delete_key, FALSE);
512
+			}
513
+			$this->getQueryBuilder()
514 514
 									 ->select(array($key, $value))
515 515
 									 ->from($this->_table);
516 516
 			$result = $this->_database->getAll();
517
-            $options = array();
518
-            foreach ($result as $row)
519
-            {
520
-                $options[$row->{$key}] = $row->{$value};
521
-            }
522
-            $options = $this->trigger('after_dropdown', $options);
523
-            return $options;
524
-        }
525
-
526
-        /**
527
-         * Fetch a count of rows based on an arbitrary WHERE call.
528
-         */
529
-        public function count_by()
530
-        {
531
-            if ($this->soft_delete && $this->_temporary_with_deleted !== TRUE)
532
-            {
533
-                $this->getQueryBuilder()->where($this->soft_delete_key, (bool)$this->_temporary_only_deleted);
534
-            }
535
-            $where = func_get_args();
536
-            $this->_set_where($where);
537
-            $this->getQueryBuilder()->from($this->_table);
517
+			$options = array();
518
+			foreach ($result as $row)
519
+			{
520
+				$options[$row->{$key}] = $row->{$value};
521
+			}
522
+			$options = $this->trigger('after_dropdown', $options);
523
+			return $options;
524
+		}
525
+
526
+		/**
527
+		 * Fetch a count of rows based on an arbitrary WHERE call.
528
+		 */
529
+		public function count_by()
530
+		{
531
+			if ($this->soft_delete && $this->_temporary_with_deleted !== TRUE)
532
+			{
533
+				$this->getQueryBuilder()->where($this->soft_delete_key, (bool)$this->_temporary_only_deleted);
534
+			}
535
+			$where = func_get_args();
536
+			$this->_set_where($where);
537
+			$this->getQueryBuilder()->from($this->_table);
538 538
 			$this->_database->getAll();
539
-            return $this->_database->numRows();
540
-        }
541
-
542
-        /**
543
-         * Fetch a total count of rows, disregarding any previous conditions
544
-         */
545
-        public function count_all()
546
-        {
547
-            if ($this->soft_delete && $this->_temporary_with_deleted !== TRUE)
548
-            {
549
-                $this->getQueryBuilder()->where($this->soft_delete_key, (bool)$this->_temporary_only_deleted);
550
-            }
539
+			return $this->_database->numRows();
540
+		}
541
+
542
+		/**
543
+		 * Fetch a total count of rows, disregarding any previous conditions
544
+		 */
545
+		public function count_all()
546
+		{
547
+			if ($this->soft_delete && $this->_temporary_with_deleted !== TRUE)
548
+			{
549
+				$this->getQueryBuilder()->where($this->soft_delete_key, (bool)$this->_temporary_only_deleted);
550
+			}
551 551
 			$this->getQueryBuilder()->from($this->_table);
552 552
 			$this->_database->getAll();
553
-            return $this->_database->numRows();
554
-        }
553
+			return $this->_database->numRows();
554
+		}
555 555
 		
556 556
 		/**
557
-		* Enabled cache temporary
558
-		*/
557
+		 * Enabled cache temporary
558
+		 */
559 559
 		public function cached($ttl = 0){
560 560
 		  if ($ttl > 0){
561 561
 			$this->_database = $this->_database->cached($ttl);
@@ -563,424 +563,424 @@  discard block
 block discarded – undo
563 563
 		  return $this;
564 564
 		}
565 565
 
566
-        /**
567
-         * Tell the class to skip the insert validation
568
-         */
569
-        public function skip_validation()
570
-        {
571
-            $this->skip_validation = TRUE;
572
-            return $this;
573
-        }
574
-
575
-        /**
576
-         * Get the skip validation status
577
-         */
578
-        public function get_skip_validation()
579
-        {
580
-            return $this->skip_validation;
581
-        }
582
-
583
-        /**
584
-         * Return the next auto increment of the table. Only tested on MySQL.
585
-         */
586
-        public function get_next_id()
587
-        {
566
+		/**
567
+		 * Tell the class to skip the insert validation
568
+		 */
569
+		public function skip_validation()
570
+		{
571
+			$this->skip_validation = TRUE;
572
+			return $this;
573
+		}
574
+
575
+		/**
576
+		 * Get the skip validation status
577
+		 */
578
+		public function get_skip_validation()
579
+		{
580
+			return $this->skip_validation;
581
+		}
582
+
583
+		/**
584
+		 * Return the next auto increment of the table. Only tested on MySQL.
585
+		 */
586
+		public function get_next_id()
587
+		{
588 588
 			$this->getQueryBuilder()->select('AUTO_INCREMENT')
589 589
 									->from('information_schema.TABLES')
590 590
 									->where('TABLE_NAME', $this->_table)
591 591
 									->where('TABLE_SCHEMA', $this->_database->getDatabaseName());
592
-            return (int) $this->_database->get()->AUTO_INCREMENT;
593
-        }
594
-
595
-        /**
596
-         * Getter for the table name
597
-         */
598
-        public function table()
599
-        {
600
-            return $this->_table;
601
-        }
602
-
603
-        /* --------------------------------------------------------------
592
+			return (int) $this->_database->get()->AUTO_INCREMENT;
593
+		}
594
+
595
+		/**
596
+		 * Getter for the table name
597
+		 */
598
+		public function table()
599
+		{
600
+			return $this->_table;
601
+		}
602
+
603
+		/* --------------------------------------------------------------
604 604
          * GLOBAL SCOPES
605 605
          * ------------------------------------------------------------ */
606 606
 
607
-        /**
608
-         * Return the next call as an array rather than an object
609
-         */
610
-        public function as_array()
611
-        {
612
-            $this->_temporary_return_type = 'array';
613
-            return $this;
614
-        }
615
-
616
-        /**
617
-         * Return the next call as an object rather than an array
618
-         */
619
-        public function as_object()
620
-        {
621
-            $this->_temporary_return_type = 'object';
622
-            return $this;
623
-        }
624
-
625
-        /**
626
-         * Don't care about soft deleted rows on the next call
627
-         */
628
-        public function with_deleted()
629
-        {
630
-            $this->_temporary_with_deleted = TRUE;
631
-            return $this;
632
-        }
633
-
634
-        /**
635
-         * Only get deleted rows on the next call
636
-         */
637
-        public function only_deleted()
638
-        {
639
-            $this->_temporary_only_deleted = TRUE;
640
-            return $this;
641
-        }
642
-
643
-        /* --------------------------------------------------------------
607
+		/**
608
+		 * Return the next call as an array rather than an object
609
+		 */
610
+		public function as_array()
611
+		{
612
+			$this->_temporary_return_type = 'array';
613
+			return $this;
614
+		}
615
+
616
+		/**
617
+		 * Return the next call as an object rather than an array
618
+		 */
619
+		public function as_object()
620
+		{
621
+			$this->_temporary_return_type = 'object';
622
+			return $this;
623
+		}
624
+
625
+		/**
626
+		 * Don't care about soft deleted rows on the next call
627
+		 */
628
+		public function with_deleted()
629
+		{
630
+			$this->_temporary_with_deleted = TRUE;
631
+			return $this;
632
+		}
633
+
634
+		/**
635
+		 * Only get deleted rows on the next call
636
+		 */
637
+		public function only_deleted()
638
+		{
639
+			$this->_temporary_only_deleted = TRUE;
640
+			return $this;
641
+		}
642
+
643
+		/* --------------------------------------------------------------
644 644
          * OBSERVERS
645 645
          * ------------------------------------------------------------ */
646 646
 
647
-        /**
648
-         * MySQL DATETIME created_at and updated_at
649
-         */
650
-        public function created_at($row)
651
-        {
652
-            if (is_object($row))
653
-            {
654
-                $row->created_at = date('Y-m-d H:i:s');
655
-            }
656
-            else
657
-            {
658
-                $row['created_at'] = date('Y-m-d H:i:s');
659
-            }
660
-            return $row;
661
-        }
662
-
663
-        public function updated_at($row)
664
-        {
665
-            if (is_object($row))
666
-            {
667
-                $row->updated_at = date('Y-m-d H:i:s');
668
-            }
669
-            else
670
-            {
671
-                $row['updated_at'] = date('Y-m-d H:i:s');
672
-            }
673
-            return $row;
674
-        }
675
-
676
-        /**
677
-         * Serialises data for you automatically, allowing you to pass
678
-         * through objects and let it handle the serialisation in the background
679
-         */
680
-        public function serialize($row)
681
-        {
682
-            foreach ($this->callback_parameters as $column)
683
-            {
684
-                $row[$column] = serialize($row[$column]);
685
-            }
686
-            return $row;
687
-        }
688
-
689
-        public function unserialize($row)
690
-        {
691
-            foreach ($this->callback_parameters as $column)
692
-            {
693
-                if (is_array($row))
694
-                {
695
-                    $row[$column] = unserialize($row[$column]);
696
-                }
697
-                else
698
-                {
699
-                    $row->$column = unserialize($row->$column);
700
-                }
701
-            }
702
-            return $row;
703
-        }
704
-
705
-        /**
706
-         * Protect attributes by removing them from $row array
707
-         */
708
-        public function protect_attributes($row)
709
-        {
710
-            foreach ($this->protected_attributes as $attr)
711
-            {
712
-                if (is_object($row))
713
-                {
647
+		/**
648
+		 * MySQL DATETIME created_at and updated_at
649
+		 */
650
+		public function created_at($row)
651
+		{
652
+			if (is_object($row))
653
+			{
654
+				$row->created_at = date('Y-m-d H:i:s');
655
+			}
656
+			else
657
+			{
658
+				$row['created_at'] = date('Y-m-d H:i:s');
659
+			}
660
+			return $row;
661
+		}
662
+
663
+		public function updated_at($row)
664
+		{
665
+			if (is_object($row))
666
+			{
667
+				$row->updated_at = date('Y-m-d H:i:s');
668
+			}
669
+			else
670
+			{
671
+				$row['updated_at'] = date('Y-m-d H:i:s');
672
+			}
673
+			return $row;
674
+		}
675
+
676
+		/**
677
+		 * Serialises data for you automatically, allowing you to pass
678
+		 * through objects and let it handle the serialisation in the background
679
+		 */
680
+		public function serialize($row)
681
+		{
682
+			foreach ($this->callback_parameters as $column)
683
+			{
684
+				$row[$column] = serialize($row[$column]);
685
+			}
686
+			return $row;
687
+		}
688
+
689
+		public function unserialize($row)
690
+		{
691
+			foreach ($this->callback_parameters as $column)
692
+			{
693
+				if (is_array($row))
694
+				{
695
+					$row[$column] = unserialize($row[$column]);
696
+				}
697
+				else
698
+				{
699
+					$row->$column = unserialize($row->$column);
700
+				}
701
+			}
702
+			return $row;
703
+		}
704
+
705
+		/**
706
+		 * Protect attributes by removing them from $row array
707
+		 */
708
+		public function protect_attributes($row)
709
+		{
710
+			foreach ($this->protected_attributes as $attr)
711
+			{
712
+				if (is_object($row))
713
+				{
714 714
 					if (isset($row->$attr)){
715 715
 						unset($row->$attr);
716 716
 					}
717
-                }
718
-                else
719
-                {
717
+				}
718
+				else
719
+				{
720 720
 					if (isset($row[$attr])){
721 721
 						unset($row[$attr]);
722 722
 					}
723
-                }
724
-            }
725
-            return $row;
726
-        }
723
+				}
724
+			}
725
+			return $row;
726
+		}
727 727
 		
728 728
 		 /**
729
-         * Return the database instance
730
-         * @return Database the database instance
731
-         */
732
-        public function getDatabaseInstance(){
733
-            return $this->_database;
734
-        }
735
-
736
-        /**
737
-         * set the Database instance for future use
738
-         * @param Database $db the database object
739
-         */
740
-         public function setDatabaseInstance($db){
741
-            $this->_database = $db;
742
-            if ($this->dbCacheTime > 0){
743
-                $this->_database->setCache($this->dbCacheTime);
744
-            }
745
-            return $this;
746
-        }
747
-
748
-        /**
749
-         * Return the loader instance
750
-         * @return Loader the loader instance
751
-         */
752
-        public function getLoader(){
753
-            return $this->loaderInstance;
754
-        }
755
-
756
-        /**
757
-         * Set the loader instance for future use
758
-         * @param Loader $loader the loader object
729
+		  * Return the database instance
730
+		  * @return Database the database instance
731
+		  */
732
+		public function getDatabaseInstance(){
733
+			return $this->_database;
734
+		}
735
+
736
+		/**
737
+		 * set the Database instance for future use
738
+		 * @param Database $db the database object
739
+		 */
740
+		 public function setDatabaseInstance($db){
741
+			$this->_database = $db;
742
+			if ($this->dbCacheTime > 0){
743
+				$this->_database->setCache($this->dbCacheTime);
744
+			}
745
+			return $this;
746
+		}
747
+
748
+		/**
749
+		 * Return the loader instance
750
+		 * @return Loader the loader instance
751
+		 */
752
+		public function getLoader(){
753
+			return $this->loaderInstance;
754
+		}
755
+
756
+		/**
757
+		 * Set the loader instance for future use
758
+		 * @param Loader $loader the loader object
759 759
 		 * @return object
760
-         */
761
-         public function setLoader($loader){
762
-            $this->loaderInstance = $loader;
763
-            return $this;
764
-        }
760
+		 */
761
+		 public function setLoader($loader){
762
+			$this->loaderInstance = $loader;
763
+			return $this;
764
+		}
765
+
766
+		/**
767
+		 * Return the queryBuilder instance this is the shortcut to database queryBuilder
768
+		 * @return object the DatabaseQueryBuilder instance
769
+		 */
770
+		public function getQueryBuilder(){
771
+			return $this->_database->getQueryBuilder();
772
+		}
765 773
 
766 774
 		/**
767
-         * Return the queryBuilder instance this is the shortcut to database queryBuilder
768
-         * @return object the DatabaseQueryBuilder instance
769
-         */
770
-        public function getQueryBuilder(){
771
-            return $this->_database->getQueryBuilder();
772
-        }
773
-
774
-        /**
775
-         * Set the DatabaseQueryBuilder instance for future use
776
-         * @param object $queryBuilder the DatabaseQueryBuilder object
775
+		 * Set the DatabaseQueryBuilder instance for future use
776
+		 * @param object $queryBuilder the DatabaseQueryBuilder object
777 777
 		 * @return object
778
-         */
779
-         public function setQueryBuilder($queryBuilder){
780
-            $this->_database->setQueryBuilder($queryBuilder);
781
-            return $this;
782
-        }
778
+		 */
779
+		 public function setQueryBuilder($queryBuilder){
780
+			$this->_database->setQueryBuilder($queryBuilder);
781
+			return $this;
782
+		}
783 783
 
784 784
 		
785
-        /**
786
-         * Return the FormValidation instance
787
-         * @return FormValidation the form validation instance
788
-         */
789
-        public function getFormValidation(){
790
-            return $this->formValidationInstance;
791
-        }
792
-
793
-        /**
794
-         * Set the form validation instance for future use
795
-         * @param FormValidation $fv the form validation object
785
+		/**
786
+		 * Return the FormValidation instance
787
+		 * @return FormValidation the form validation instance
788
+		 */
789
+		public function getFormValidation(){
790
+			return $this->formValidationInstance;
791
+		}
792
+
793
+		/**
794
+		 * Set the form validation instance for future use
795
+		 * @param FormValidation $fv the form validation object
796 796
 		 * @return object
797
-         */
798
-         public function setFormValidation($fv){
799
-            $this->formValidationInstance = $fv;
800
-            return $this;
801
-        }
797
+		 */
798
+		 public function setFormValidation($fv){
799
+			$this->formValidationInstance = $fv;
800
+			return $this;
801
+		}
802 802
 
803
-        /* --------------------------------------------------------------
803
+		/* --------------------------------------------------------------
804 804
          * QUERY BUILDER DIRECT ACCESS METHODS
805 805
          * ------------------------------------------------------------ */
806 806
 
807
-        /**
808
-         * A wrapper to $this->getQueryBuilder()->orderBy()
809
-         */
810
-        public function order_by($criteria, $order = 'ASC')
811
-        {
812
-            if ( is_array($criteria) )
813
-            {
814
-                foreach ($criteria as $key => $value)
815
-                {
816
-                    $this->getQueryBuilder()->orderBy($key, $value);
817
-                }
818
-            }
819
-            else
820
-            {
821
-                $this->getQueryBuilder()->orderBy($criteria, $order);
822
-            }
823
-            return $this;
824
-        }
825
-
826
-        /**
827
-         * A wrapper to $this->getQueryBuilder()->limit()
828
-         */
829
-        public function limit($offset = 0, $limit = 10)
830
-        {
831
-            $this->getQueryBuilder()->limit($offset, $limit);
832
-            return $this;
833
-        }
834
-
835
-        /* --------------------------------------------------------------
807
+		/**
808
+		 * A wrapper to $this->getQueryBuilder()->orderBy()
809
+		 */
810
+		public function order_by($criteria, $order = 'ASC')
811
+		{
812
+			if ( is_array($criteria) )
813
+			{
814
+				foreach ($criteria as $key => $value)
815
+				{
816
+					$this->getQueryBuilder()->orderBy($key, $value);
817
+				}
818
+			}
819
+			else
820
+			{
821
+				$this->getQueryBuilder()->orderBy($criteria, $order);
822
+			}
823
+			return $this;
824
+		}
825
+
826
+		/**
827
+		 * A wrapper to $this->getQueryBuilder()->limit()
828
+		 */
829
+		public function limit($offset = 0, $limit = 10)
830
+		{
831
+			$this->getQueryBuilder()->limit($offset, $limit);
832
+			return $this;
833
+		}
834
+
835
+		/* --------------------------------------------------------------
836 836
          * INTERNAL METHODS
837 837
          * ------------------------------------------------------------ */
838 838
 
839 839
 		/**
840
-		* relate for the relation "belongs_to"
841
-		* @return mixed
842
-		*/
840
+		 * relate for the relation "belongs_to"
841
+		 * @return mixed
842
+		 */
843 843
 		protected function relateBelongsTo($row){
844 844
 			foreach ($this->belongs_to as $key => $value)
845
-            {
846
-                if (is_string($value))
847
-                {
848
-                    $relationship = $value;
849
-                    $options = array( 'primary_key' => $value . '_id', 'model' => $value . '_model' );
850
-                }
851
-                else
852
-                {
853
-                    $relationship = $key;
854
-                    $options = $value;
855
-                }
856
-
857
-                if (in_array($relationship, $this->_with))
858
-                {
859
-                    if (is_object($this->loaderInstance)){
860
-                        $this->loaderInstance->model($options['model'], $relationship . '_model');
861
-                    }
862
-                    else{
863
-                        Loader::model($options['model'], $relationship . '_model');    
864
-                    }
865
-                    if (is_object($row))
866
-                    {
867
-                        $row->{$relationship} = $this->{$relationship . '_model'}->get($row->{$options['primary_key']});
868
-                    }
869
-                    else
870
-                    {
871
-                        $row[$relationship] = $this->{$relationship . '_model'}->get($row[$options['primary_key']]);
872
-                    }
873
-                }
874
-            }
845
+			{
846
+				if (is_string($value))
847
+				{
848
+					$relationship = $value;
849
+					$options = array( 'primary_key' => $value . '_id', 'model' => $value . '_model' );
850
+				}
851
+				else
852
+				{
853
+					$relationship = $key;
854
+					$options = $value;
855
+				}
856
+
857
+				if (in_array($relationship, $this->_with))
858
+				{
859
+					if (is_object($this->loaderInstance)){
860
+						$this->loaderInstance->model($options['model'], $relationship . '_model');
861
+					}
862
+					else{
863
+						Loader::model($options['model'], $relationship . '_model');    
864
+					}
865
+					if (is_object($row))
866
+					{
867
+						$row->{$relationship} = $this->{$relationship . '_model'}->get($row->{$options['primary_key']});
868
+					}
869
+					else
870
+					{
871
+						$row[$relationship] = $this->{$relationship . '_model'}->get($row[$options['primary_key']]);
872
+					}
873
+				}
874
+			}
875 875
 			return $row;
876 876
 		}
877 877
 
878 878
 		/**
879
-		* relate for the relation "has_many"
880
-		* @return mixed
881
-		*/
879
+		 * relate for the relation "has_many"
880
+		 * @return mixed
881
+		 */
882 882
 		protected function relateHasMany($row){
883 883
 			foreach ($this->has_many as $key => $value)
884
-            {
885
-                if (is_string($value))
886
-                {
887
-                    $relationship = $value;
888
-                    $options = array( 'primary_key' => $this->_table . '_id', 'model' => $value . '_model' );
889
-                }
890
-                else
891
-                {
892
-                    $relationship = $key;
893
-                    $options = $value;
894
-                }
895
-
896
-                if (in_array($relationship, $this->_with))
897
-                {
898
-                    if (is_object($this->loaderInstance)){
899
-                        $this->loaderInstance->model($options['model'], $relationship . '_model');
900
-                    }
901
-                    else{
902
-                        Loader::model($options['model'], $relationship . '_model');    
903
-                    }
904
-                    if (is_object($row))
905
-                    {
906
-                        $row->{$relationship} = $this->{$relationship . '_model'}->get_many_by($options['primary_key'], $row->{$this->primary_key});
907
-                    }
908
-                    else
909
-                    {
910
-                        $row[$relationship] = $this->{$relationship . '_model'}->get_many_by($options['primary_key'], $row[$this->primary_key]);
911
-                    }
912
-                }
913
-            }
884
+			{
885
+				if (is_string($value))
886
+				{
887
+					$relationship = $value;
888
+					$options = array( 'primary_key' => $this->_table . '_id', 'model' => $value . '_model' );
889
+				}
890
+				else
891
+				{
892
+					$relationship = $key;
893
+					$options = $value;
894
+				}
895
+
896
+				if (in_array($relationship, $this->_with))
897
+				{
898
+					if (is_object($this->loaderInstance)){
899
+						$this->loaderInstance->model($options['model'], $relationship . '_model');
900
+					}
901
+					else{
902
+						Loader::model($options['model'], $relationship . '_model');    
903
+					}
904
+					if (is_object($row))
905
+					{
906
+						$row->{$relationship} = $this->{$relationship . '_model'}->get_many_by($options['primary_key'], $row->{$this->primary_key});
907
+					}
908
+					else
909
+					{
910
+						$row[$relationship] = $this->{$relationship . '_model'}->get_many_by($options['primary_key'], $row[$this->primary_key]);
911
+					}
912
+				}
913
+			}
914 914
 			return $row;
915 915
 		}
916 916
 		
917
-        /**
918
-         * Trigger an event and call its observers. Pass through the event name
919
-         * (which looks for an instance variable $this->event_name), an array of
920
-         * parameters to pass through and an optional 'last in interation' boolean
921
-         */
922
-        protected function trigger($event, $data = FALSE, $last = TRUE)
923
-        {
924
-            if (isset($this->$event) && is_array($this->$event))
925
-            {
926
-                foreach ($this->$event as $method)
927
-                {
928
-                    if (strpos($method, '('))
929
-                    {
930
-                        preg_match('/([a-zA-Z0-9\_\-]+)(\(([a-zA-Z0-9\_\-\., ]+)\))?/', $method, $matches);
931
-                        $method = $matches[1];
932
-                        $this->callback_parameters = explode(',', $matches[3]);
933
-                    }
934
-                    $data = call_user_func_array(array($this, $method), array($data, $last));
935
-                }
936
-            }
937
-            return $data;
938
-        }
939
-
940
-        /**
941
-         * Run validation on the passed data
942
-         */
943
-        protected function validate(array $data)
944
-        {
945
-            if ($this->skip_validation)
946
-            {
947
-                return $data;
948
-            }
949
-            if (!empty($this->validate))
950
-            {
951
-                $fv = null;
952
-                if (is_object($this->formValidationInstance)){
953
-                    $fv = $this->formValidationInstance;
954
-                }
955
-                else{
956
-                    Loader::library('FormValidation');
957
-                    $fv = $this->formvalidation;
958
-                    $this->setFormValidation($fv);
959
-                }
917
+		/**
918
+		 * Trigger an event and call its observers. Pass through the event name
919
+		 * (which looks for an instance variable $this->event_name), an array of
920
+		 * parameters to pass through and an optional 'last in interation' boolean
921
+		 */
922
+		protected function trigger($event, $data = FALSE, $last = TRUE)
923
+		{
924
+			if (isset($this->$event) && is_array($this->$event))
925
+			{
926
+				foreach ($this->$event as $method)
927
+				{
928
+					if (strpos($method, '('))
929
+					{
930
+						preg_match('/([a-zA-Z0-9\_\-]+)(\(([a-zA-Z0-9\_\-\., ]+)\))?/', $method, $matches);
931
+						$method = $matches[1];
932
+						$this->callback_parameters = explode(',', $matches[3]);
933
+					}
934
+					$data = call_user_func_array(array($this, $method), array($data, $last));
935
+				}
936
+			}
937
+			return $data;
938
+		}
939
+
940
+		/**
941
+		 * Run validation on the passed data
942
+		 */
943
+		protected function validate(array $data)
944
+		{
945
+			if ($this->skip_validation)
946
+			{
947
+				return $data;
948
+			}
949
+			if (!empty($this->validate))
950
+			{
951
+				$fv = null;
952
+				if (is_object($this->formValidationInstance)){
953
+					$fv = $this->formValidationInstance;
954
+				}
955
+				else{
956
+					Loader::library('FormValidation');
957
+					$fv = $this->formvalidation;
958
+					$this->setFormValidation($fv);
959
+				}
960 960
                
961
-                $fv->setData($data);
962
-                $fv->setRules($this->validate);
963
-
964
-                if ($fv->run())
965
-                {
966
-                    return $data;
967
-                }
968
-                else
969
-                {
970
-                    return FALSE;
971
-                }
972
-            }
973
-            else
974
-            {
975
-                return $data;
976
-            }
977
-        }
961
+				$fv->setData($data);
962
+				$fv->setRules($this->validate);
963
+
964
+				if ($fv->run())
965
+				{
966
+					return $data;
967
+				}
968
+				else
969
+				{
970
+					return FALSE;
971
+				}
972
+			}
973
+			else
974
+			{
975
+				return $data;
976
+			}
977
+		}
978 978
 		
979 979
 		
980 980
 		/**
981
-		* Set WHERE parameters, when is array
982
-		* @param array $params
983
-		*/
981
+		 * Set WHERE parameters, when is array
982
+		 * @param array $params
983
+		 */
984 984
 		protected function _set_where_array(array $params){
985 985
 			foreach ($params as $field => $filter)
986 986
 			{
@@ -1003,52 +1003,52 @@  discard block
 block discarded – undo
1003 1003
 		}
1004 1004
 
1005 1005
 
1006
-        /**
1007
-         * Set WHERE parameters, cleverly
1008
-         */
1009
-        protected function _set_where($params)
1010
-        {
1011
-            if (count($params) == 1 && is_array($params[0]))
1012
-            {
1013
-                $this->_set_where_array($params[0]);
1014
-            }
1015
-            else if (count($params) == 1)
1016
-            {
1017
-                $this->getQueryBuilder()->where($params[0]);
1018
-            }
1019
-        	else if (count($params) == 2)
1020
-    		{
1021
-                if (is_array($params[1]))
1022
-                {
1023
-                    $this->getQueryBuilder()->in($params[0], $params[1]);
1024
-                }
1025
-                else
1026
-                {
1027
-                    $this->getQueryBuilder()->where($params[0], $params[1]);
1028
-                }
1029
-    		}
1030
-    		else if (count($params) == 3)
1031
-    		{
1032
-    			$this->getQueryBuilder()->where($params[0], $params[1], $params[2]);
1033
-    		}
1034
-            else
1035
-            {
1036
-                if (is_array($params[1]))
1037
-                {
1038
-                    $this->getQueryBuilder()->in($params[0], $params[1]);
1039
-                }
1040
-                else
1041
-                {
1042
-                    $this->getQueryBuilder()->where($params[0], $params[1]);
1043
-                }
1044
-            }
1045
-        }
1046
-
1047
-        /**
1006
+		/**
1007
+		 * Set WHERE parameters, cleverly
1008
+		 */
1009
+		protected function _set_where($params)
1010
+		{
1011
+			if (count($params) == 1 && is_array($params[0]))
1012
+			{
1013
+				$this->_set_where_array($params[0]);
1014
+			}
1015
+			else if (count($params) == 1)
1016
+			{
1017
+				$this->getQueryBuilder()->where($params[0]);
1018
+			}
1019
+			else if (count($params) == 2)
1020
+			{
1021
+				if (is_array($params[1]))
1022
+				{
1023
+					$this->getQueryBuilder()->in($params[0], $params[1]);
1024
+				}
1025
+				else
1026
+				{
1027
+					$this->getQueryBuilder()->where($params[0], $params[1]);
1028
+				}
1029
+			}
1030
+			else if (count($params) == 3)
1031
+			{
1032
+				$this->getQueryBuilder()->where($params[0], $params[1], $params[2]);
1033
+			}
1034
+			else
1035
+			{
1036
+				if (is_array($params[1]))
1037
+				{
1038
+					$this->getQueryBuilder()->in($params[0], $params[1]);
1039
+				}
1040
+				else
1041
+				{
1042
+					$this->getQueryBuilder()->where($params[0], $params[1]);
1043
+				}
1044
+			}
1045
+		}
1046
+
1047
+		/**
1048 1048
             Shortcut to controller
1049
-        */
1050
-        public function __get($key){
1051
-            return get_instance()->{$key};
1052
-        }
1049
+		 */
1050
+		public function __get($key){
1051
+			return get_instance()->{$key};
1052
+		}
1053 1053
 
1054
-    }
1054
+	}
Please login to merge, or discard this patch.