@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | |
26 | 26 | |
27 | 27 | |
28 | - public function testDefaultValue(){ |
|
28 | + public function testDefaultValue() { |
|
29 | 29 | $e = new Event('foo'); |
30 | 30 | $this->assertSame($e->name, 'foo'); |
31 | 31 | $this->assertSame($e->payload, array()); |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | $this->assertFalse($e->stop); |
34 | 34 | } |
35 | 35 | |
36 | - public function testPayloadValueIsSet(){ |
|
36 | + public function testPayloadValueIsSet() { |
|
37 | 37 | $e = new Event('foo', array('bar')); |
38 | 38 | $this->assertSame($e->name, 'foo'); |
39 | 39 | $this->assertSame($e->payload, array('bar')); |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | $this->assertFalse($e->stop); |
42 | 42 | } |
43 | 43 | |
44 | - public function testReturnBackValueIsSetToTrue(){ |
|
44 | + public function testReturnBackValueIsSetToTrue() { |
|
45 | 45 | $e = new Event('foo', array('bar'), true); |
46 | 46 | $this->assertSame($e->name, 'foo'); |
47 | 47 | $this->assertSame($e->payload, array('bar')); |
@@ -49,7 +49,7 @@ discard block |
||
49 | 49 | $this->assertFalse($e->stop); |
50 | 50 | } |
51 | 51 | |
52 | - public function testStopValueIsSetToTue(){ |
|
52 | + public function testStopValueIsSetToTue() { |
|
53 | 53 | $e = new Event('foo', array('bar'), true, true); |
54 | 54 | $this->assertSame($e->name, 'foo'); |
55 | 55 | $this->assertSame($e->payload, array('bar')); |
@@ -45,7 +45,7 @@ discard block |
||
45 | 45 | |
46 | 46 | |
47 | 47 | |
48 | - public function testUsingSessionConfiguration(){ |
|
48 | + public function testUsingSessionConfiguration() { |
|
49 | 49 | $secret = 'bXlzZWNyZXQ'; |
50 | 50 | //using value in the configuration |
51 | 51 | static::$config->set('session_save_path', 'DBSessionModel'); |
@@ -72,7 +72,7 @@ discard block |
||
72 | 72 | $this->assertEquals($dbsh->decode($encoded), 'foo'); |
73 | 73 | } |
74 | 74 | |
75 | - public function testWhenDataIsExpired(){ |
|
75 | + public function testWhenDataIsExpired() { |
|
76 | 76 | $model = new DBSessionModel($this->db); |
77 | 77 | //to prevent old data conflict |
78 | 78 | $model->truncate(); |
@@ -90,7 +90,7 @@ discard block |
||
90 | 90 | $this->assertFalse($dbsh->read('foo')); |
91 | 91 | } |
92 | 92 | |
93 | - public function testWhenDataAlreadyExistDoUpdate(){ |
|
93 | + public function testWhenDataAlreadyExistDoUpdate() { |
|
94 | 94 | $model = new DBSessionModel($this->db); |
95 | 95 | //to prevent old data conflict |
96 | 96 | $model->truncate(); |
@@ -108,7 +108,7 @@ discard block |
||
108 | 108 | $this->assertEquals($dbsh->read('foo'), '445'); |
109 | 109 | } |
110 | 110 | |
111 | - public function testUsingCustomModelInstance(){ |
|
111 | + public function testUsingCustomModelInstance() { |
|
112 | 112 | |
113 | 113 | $model = new DBSessionModel($this->db); |
114 | 114 | //to prevent old data conflict |
@@ -142,7 +142,7 @@ discard block |
||
142 | 142 | } |
143 | 143 | |
144 | 144 | |
145 | - public function testUsingCustomLogInstance(){ |
|
145 | + public function testUsingCustomLogInstance() { |
|
146 | 146 | $model = new DBSessionModel($this->db); |
147 | 147 | //to prevent old data conflict |
148 | 148 | $model->truncate(); |
@@ -174,7 +174,7 @@ discard block |
||
174 | 174 | $this->assertEquals($dbsh->decode($encoded), 'foo'); |
175 | 175 | } |
176 | 176 | |
177 | - public function testUsingCustomLoaderInstance(){ |
|
177 | + public function testUsingCustomLoaderInstance() { |
|
178 | 178 | $model = new DBSessionModel($this->db); |
179 | 179 | //to prevent old data conflict |
180 | 180 | $model->truncate(); |
@@ -206,7 +206,7 @@ discard block |
||
206 | 206 | $this->assertEquals($dbsh->decode($encoded), 'foo'); |
207 | 207 | } |
208 | 208 | |
209 | - public function testWhenModelInsanceIsNotSet(){ |
|
209 | + public function testWhenModelInsanceIsNotSet() { |
|
210 | 210 | $model = new DBSessionModel($this->db); |
211 | 211 | //to prevent old data conflict |
212 | 212 | $model->truncate(); |
@@ -238,7 +238,7 @@ discard block |
||
238 | 238 | $this->assertEquals($dbsh->decode($encoded), 'foo'); |
239 | 239 | } |
240 | 240 | |
241 | - public function testWhenModelTableColumnsIsNotSet(){ |
|
241 | + public function testWhenModelTableColumnsIsNotSet() { |
|
242 | 242 | $model = new DBSessionModel($this->db); |
243 | 243 | //to prevent old data conflict |
244 | 244 | $model->truncate(); |
@@ -30,7 +30,7 @@ |
||
30 | 30 | $this->assertEquals('bar', Session::get('foo')); |
31 | 31 | } |
32 | 32 | |
33 | - public function testExc(){ |
|
33 | + public function testExc() { |
|
34 | 34 | //$this->expectException(InvalidArgumentException::class); |
35 | 35 | } |
36 | 36 | } |
37 | 37 | \ No newline at end of file |
@@ -1,5 +1,5 @@ |
||
1 | 1 | <?php |
2 | - class CoursModel extends Model{ |
|
2 | + class CoursModel extends Model { |
|
3 | 3 | |
4 | 4 | protected $_table = 'specialite'; |
5 | 5 | protected $validate = array( |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | - class DBSessionModel extends DBSessionHandlerModel{ |
|
2 | + class DBSessionModel extends DBSessionHandlerModel { |
|
3 | 3 | |
4 | 4 | protected $_table = 'ses'; |
5 | 5 | protected $primary_key = 's_id'; |
@@ -14,14 +14,14 @@ discard block |
||
14 | 14 | 'skey' => 'usr_id' //VARCHAR(255) |
15 | 15 | ); |
16 | 16 | |
17 | - public function deleteByTime($time){ |
|
17 | + public function deleteByTime($time) { |
|
18 | 18 | $this->_database->from($this->_table) |
19 | 19 | ->where('s_time', '<', $time) |
20 | 20 | ->delete(); |
21 | 21 | } |
22 | 22 | |
23 | 23 | |
24 | - public function getKeyValue(){ |
|
24 | + public function getKeyValue() { |
|
25 | 25 | $user_id = 0; |
26 | 26 | return $user_id; |
27 | 27 | } |
@@ -1,5 +1,5 @@ |
||
1 | 1 | <?php |
2 | - class ClasseModel extends Model{ |
|
2 | + class ClasseModel extends Model { |
|
3 | 3 | |
4 | 4 | protected $_table = 'classe'; |
5 | 5 | protected $primary_key = 'cls_id'; |
@@ -21,195 +21,195 @@ discard block |
||
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 | |
42 | 42 | /** |
43 | - * The path to the directory. |
|
44 | - * |
|
45 | - * That contains your static files (javascript, css, images, etc.) |
|
46 | - * Note: the path must be relative to the file index.php (the front-end controller). |
|
47 | - */ |
|
43 | + * The path to the directory. |
|
44 | + * |
|
45 | + * That contains your static files (javascript, css, images, etc.) |
|
46 | + * Note: the path must be relative to the file index.php (the front-end controller). |
|
47 | + */ |
|
48 | 48 | define('ASSETS_PATH', 'assets/'); |
49 | 49 | |
50 | 50 | /** |
51 | - * The path to the directory of your cache files. |
|
52 | - * |
|
53 | - * This feature is available currently for database and views. |
|
54 | - */ |
|
51 | + * The path to the directory of your cache files. |
|
52 | + * |
|
53 | + * This feature is available currently for database and views. |
|
54 | + */ |
|
55 | 55 | define('CACHE_PATH', ROOT_PATH . 'cache' . DS); |
56 | 56 | |
57 | 57 | /** |
58 | - * Custom application path for tests |
|
59 | - */ |
|
58 | + * Custom application path for tests |
|
59 | + */ |
|
60 | 60 | define('APPS_PATH', dirname(realpath(__FILE__)) . DS .'hmvc' . DS); |
61 | 61 | |
62 | 62 | /** |
63 | - * The path to the controller directory of your application. |
|
64 | - * |
|
65 | - * If you already know the MVC architecture you know what a controller means; |
|
66 | - * it is he who makes the business logic of your application in general. |
|
67 | - */ |
|
63 | + * The path to the controller directory of your application. |
|
64 | + * |
|
65 | + * If you already know the MVC architecture you know what a controller means; |
|
66 | + * it is he who makes the business logic of your application in general. |
|
67 | + */ |
|
68 | 68 | define('APPS_CONTROLLER_PATH', APPS_PATH . 'controllers' . DS); |
69 | 69 | |
70 | 70 | /** |
71 | - * The path to the directory of your model classes of your application. |
|
72 | - * |
|
73 | - * If you already know the MVC architecture you know what a model means; |
|
74 | - * it's the one who interacts with the database, in one word persistent data from your application. |
|
75 | - */ |
|
71 | + * The path to the directory of your model classes of your application. |
|
72 | + * |
|
73 | + * If you already know the MVC architecture you know what a model means; |
|
74 | + * it's the one who interacts with the database, in one word persistent data from your application. |
|
75 | + */ |
|
76 | 76 | define('APPS_MODEL_PATH', APPS_PATH . 'models' . DS); |
77 | 77 | |
78 | 78 | /** |
79 | - * The path to the directory of your views. |
|
80 | - * |
|
81 | - * If you already know the MVC architecture you know what a view means, |
|
82 | - * a view is just a user interface (html page, form, etc.) that is to say |
|
83 | - * everything displayed in the browser interface, etc. |
|
84 | - */ |
|
79 | + * The path to the directory of your views. |
|
80 | + * |
|
81 | + * If you already know the MVC architecture you know what a view means, |
|
82 | + * a view is just a user interface (html page, form, etc.) that is to say |
|
83 | + * everything displayed in the browser interface, etc. |
|
84 | + */ |
|
85 | 85 | define('APPS_VIEWS_PATH', APPS_PATH . 'views' . DS); |
86 | 86 | |
87 | 87 | /** |
88 | - * The path to the configuration directory. |
|
89 | - * |
|
90 | - * That contains most of the configuration files for your |
|
91 | - * application (database, class loading file, functions, etc.) |
|
92 | - */ |
|
88 | + * The path to the configuration directory. |
|
89 | + * |
|
90 | + * That contains most of the configuration files for your |
|
91 | + * application (database, class loading file, functions, etc.) |
|
92 | + */ |
|
93 | 93 | define('CONFIG_PATH', ROOT_PATH . 'config' . DS); |
94 | 94 | |
95 | 95 | /** |
96 | - * The core directory |
|
97 | - * |
|
98 | - * It is recommended to put this folder out of the web directory of your server and |
|
99 | - * you should not change its content because in case of update you could lose the modified files. |
|
100 | - */ |
|
96 | + * The core directory |
|
97 | + * |
|
98 | + * It is recommended to put this folder out of the web directory of your server and |
|
99 | + * you should not change its content because in case of update you could lose the modified files. |
|
100 | + */ |
|
101 | 101 | define('CORE_PATH', ROOT_PATH . 'core' . DS); |
102 | 102 | |
103 | 103 | /** |
104 | - * The path to the directory of core classes that used by the system. |
|
105 | - * |
|
106 | - * It contains PHP classes that are used by the framework internally. |
|
107 | - */ |
|
104 | + * The path to the directory of core classes that used by the system. |
|
105 | + * |
|
106 | + * It contains PHP classes that are used by the framework internally. |
|
107 | + */ |
|
108 | 108 | define('CORE_CLASSES_PATH', CORE_PATH . 'classes' . DS); |
109 | 109 | |
110 | 110 | /** |
111 | - * The path to the directory of core classes for the cache used by the system. |
|
112 | - * |
|
113 | - * It contains PHP classes for the cache drivers. |
|
114 | - */ |
|
111 | + * The path to the directory of core classes for the cache used by the system. |
|
112 | + * |
|
113 | + * It contains PHP classes for the cache drivers. |
|
114 | + */ |
|
115 | 115 | define('CORE_CLASSES_CACHE_PATH', CORE_CLASSES_PATH . 'cache' . DS); |
116 | 116 | |
117 | 117 | /** |
118 | - * The path to the directory of core classes for the model used by the system. |
|
119 | - * |
|
120 | - * It contains PHP classes for the models. |
|
121 | - */ |
|
118 | + * The path to the directory of core classes for the model used by the system. |
|
119 | + * |
|
120 | + * It contains PHP classes for the models. |
|
121 | + */ |
|
122 | 122 | define('CORE_CLASSES_MODEL_PATH', CORE_CLASSES_PATH . 'model' . DS); |
123 | 123 | |
124 | 124 | /** |
125 | - * The path to the directory of functions or helper systems. |
|
126 | - * |
|
127 | - * It contains PHP functions that perform a particular task: character string processing, URL, etc. |
|
128 | - */ |
|
125 | + * The path to the directory of functions or helper systems. |
|
126 | + * |
|
127 | + * It contains PHP functions that perform a particular task: character string processing, URL, etc. |
|
128 | + */ |
|
129 | 129 | define('CORE_FUNCTIONS_PATH', CORE_PATH . 'functions' . DS); |
130 | 130 | |
131 | 131 | /** |
132 | - * The path to the core directory of languages files. |
|
133 | - * |
|
134 | - */ |
|
132 | + * The path to the core directory of languages files. |
|
133 | + * |
|
134 | + */ |
|
135 | 135 | define('CORE_LANG_PATH', CORE_PATH . 'lang' . DS); |
136 | 136 | |
137 | 137 | /** |
138 | - * The path to the system library directory. |
|
139 | - * |
|
140 | - * Which contains the libraries most often used in your web application, as for the |
|
141 | - * core directory it is advisable to put it out of the root directory of your application. |
|
142 | - */ |
|
138 | + * The path to the system library directory. |
|
139 | + * |
|
140 | + * Which contains the libraries most often used in your web application, as for the |
|
141 | + * core directory it is advisable to put it out of the root directory of your application. |
|
142 | + */ |
|
143 | 143 | define('CORE_LIBRARY_PATH', CORE_PATH . 'libraries' . DS); |
144 | 144 | |
145 | 145 | /** |
146 | - * The path to the system view directory. |
|
147 | - * |
|
148 | - * That contains the views used for the system, such as error messages, and so on. |
|
149 | - */ |
|
146 | + * The path to the system view directory. |
|
147 | + * |
|
148 | + * That contains the views used for the system, such as error messages, and so on. |
|
149 | + */ |
|
150 | 150 | define('CORE_VIEWS_PATH', CORE_PATH . 'views' . DS); |
151 | 151 | |
152 | 152 | /** |
153 | - * The path to the directory of your PHP personal functions or helper. |
|
154 | - * |
|
155 | - * It contains your PHP functions that perform a particular task: utilities, etc. |
|
156 | - * Note: Do not put your personal functions or helpers in the system functions directory, |
|
157 | - * because if you update the system you may lose them. |
|
158 | - */ |
|
153 | + * The path to the directory of your PHP personal functions or helper. |
|
154 | + * |
|
155 | + * It contains your PHP functions that perform a particular task: utilities, etc. |
|
156 | + * Note: Do not put your personal functions or helpers in the system functions directory, |
|
157 | + * because if you update the system you may lose them. |
|
158 | + */ |
|
159 | 159 | define('FUNCTIONS_PATH', ROOT_PATH . 'functions' . DS); |
160 | 160 | |
161 | 161 | /** |
162 | - * The path to the app directory of personal language. |
|
163 | - * |
|
164 | - * This feature is not yet available. |
|
165 | - * You can help us do this if you are nice or wish to see the developed framework. |
|
166 | - */ |
|
162 | + * The path to the app directory of personal language. |
|
163 | + * |
|
164 | + * This feature is not yet available. |
|
165 | + * You can help us do this if you are nice or wish to see the developed framework. |
|
166 | + */ |
|
167 | 167 | define('APP_LANG_PATH', ROOT_PATH . 'lang' . DS); |
168 | 168 | |
169 | 169 | /** |
170 | - * The path to the directory of your personal libraries |
|
171 | - * |
|
172 | - * It contains your PHP classes, package, etc. |
|
173 | - * Note: you should not put your personal libraries in the system library directory, |
|
174 | - * because it is recalled in case of updating the system you might have surprises. |
|
175 | - */ |
|
170 | + * The path to the directory of your personal libraries |
|
171 | + * |
|
172 | + * It contains your PHP classes, package, etc. |
|
173 | + * Note: you should not put your personal libraries in the system library directory, |
|
174 | + * because it is recalled in case of updating the system you might have surprises. |
|
175 | + */ |
|
176 | 176 | define('LIBRARY_PATH', ROOT_PATH . 'libraries' . DS); |
177 | 177 | |
178 | 178 | /** |
179 | - * The path to the directory that contains the log files. |
|
180 | - * |
|
181 | - * Note: This directory must be available in writing and if possible must have as owner the user who launches your web server, |
|
182 | - * under unix or linux most often with the apache web server it is "www-data" or "httpd" even "nobody" for more |
|
183 | - * details see the documentation of your web server. |
|
184 | - * Example for Unix or linux with apache web server: |
|
185 | - * # chmod -R 700 /path/to/your/logs/directory/ |
|
186 | - * # chown -R www-data:www-data /path/to/your/logs/directory/ |
|
187 | - */ |
|
179 | + * The path to the directory that contains the log files. |
|
180 | + * |
|
181 | + * Note: This directory must be available in writing and if possible must have as owner the user who launches your web server, |
|
182 | + * under unix or linux most often with the apache web server it is "www-data" or "httpd" even "nobody" for more |
|
183 | + * details see the documentation of your web server. |
|
184 | + * Example for Unix or linux with apache web server: |
|
185 | + * # chmod -R 700 /path/to/your/logs/directory/ |
|
186 | + * # chown -R www-data:www-data /path/to/your/logs/directory/ |
|
187 | + */ |
|
188 | 188 | define('LOGS_PATH', ROOT_PATH . 'logs' . DS); |
189 | 189 | |
190 | 190 | /** |
191 | - * The path to the modules directory. |
|
192 | - * |
|
193 | - * It contains your modules used files (config, controllers, libraries, etc.) that is to say which contains your files of the modules, |
|
194 | - * in HMVC architecture (hierichical, controllers, models, views). |
|
195 | - */ |
|
191 | + * The path to the modules directory. |
|
192 | + * |
|
193 | + * It contains your modules used files (config, controllers, libraries, etc.) that is to say which contains your files of the modules, |
|
194 | + * in HMVC architecture (hierichical, controllers, models, views). |
|
195 | + */ |
|
196 | 196 | define('MODULE_PATH', dirname(realpath(__FILE__)) . DS .'hmvc' . DS . 'modules' . DS); |
197 | 197 | |
198 | 198 | /** |
199 | - * The path to the directory of sources external to your application. |
|
200 | - * |
|
201 | - * If you have already used "composer" you know what that means. |
|
202 | - */ |
|
199 | + * The path to the directory of sources external to your application. |
|
200 | + * |
|
201 | + * If you have already used "composer" you know what that means. |
|
202 | + */ |
|
203 | 203 | define('VENDOR_PATH', ROOT_PATH . 'vendor' . DS); |
204 | 204 | |
205 | 205 | /** |
206 | - * The front controller of your application. |
|
207 | - * |
|
208 | - * "index.php" it is through this file that all the requests come, there is a possibility to hidden it in the url of |
|
209 | - * your application by using the rewrite module URL of your web server . |
|
210 | - * For example, under apache web server, there is a configuration example file that is located at the root |
|
211 | - * of your framework folder : "htaccess.txt" rename it to ".htaccess". |
|
212 | - */ |
|
206 | + * The front controller of your application. |
|
207 | + * |
|
208 | + * "index.php" it is through this file that all the requests come, there is a possibility to hidden it in the url of |
|
209 | + * your application by using the rewrite module URL of your web server . |
|
210 | + * For example, under apache web server, there is a configuration example file that is located at the root |
|
211 | + * of your framework folder : "htaccess.txt" rename it to ".htaccess". |
|
212 | + */ |
|
213 | 213 | define('SELF', pathinfo(__FILE__, PATHINFO_BASENAME)); |
214 | 214 | |
215 | 215 | /** |
@@ -218,14 +218,14 @@ discard block |
||
218 | 218 | define('IS_CLI', stripos('cli', php_sapi_name()) !== false); |
219 | 219 | |
220 | 220 | /** |
221 | - * The environment of your application (production, test, development). |
|
222 | - * |
|
223 | - * if your application is still in development you use the value "development" |
|
224 | - * so you will have the display of the error messages, etc. |
|
225 | - * Once you finish the development of your application that is to put it online |
|
226 | - * you change this value to "production" or "testing", in this case there will be deactivation of error messages, |
|
227 | - * the loading of the system, will be fast. |
|
228 | - */ |
|
221 | + * The environment of your application (production, test, development). |
|
222 | + * |
|
223 | + * if your application is still in development you use the value "development" |
|
224 | + * so you will have the display of the error messages, etc. |
|
225 | + * Once you finish the development of your application that is to put it online |
|
226 | + * you change this value to "production" or "testing", in this case there will be deactivation of error messages, |
|
227 | + * the loading of the system, will be fast. |
|
228 | + */ |
|
229 | 229 | define('ENVIRONMENT', 'testing'); |
230 | 230 | |
231 | 231 | |
@@ -256,13 +256,13 @@ discard block |
||
256 | 256 | require_once 'include/testsUtil.php'; |
257 | 257 | |
258 | 258 | /** |
259 | - * Setting of the PHP error message handling function |
|
260 | - */ |
|
259 | + * Setting of the PHP error message handling function |
|
260 | + */ |
|
261 | 261 | set_error_handler('php_error_handler'); |
262 | 262 | |
263 | 263 | /** |
264 | - * Setting of the PHP error exception handling function |
|
265 | - */ |
|
264 | + * Setting of the PHP error exception handling function |
|
265 | + */ |
|
266 | 266 | set_exception_handler('php_exception_handler'); |
267 | 267 | |
268 | 268 | /** |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | * |
37 | 37 | * you can place this directory outside of your web directory, for example "/home/your_app", etc. |
38 | 38 | */ |
39 | - define('ROOT_PATH', dirname(realpath(__FILE__)) . DS .'..' . DS); |
|
39 | + define('ROOT_PATH', dirname(realpath(__FILE__)) . DS . '..' . DS); |
|
40 | 40 | |
41 | 41 | |
42 | 42 | /** |
@@ -57,7 +57,7 @@ discard block |
||
57 | 57 | /** |
58 | 58 | * Custom application path for tests |
59 | 59 | */ |
60 | - define('APPS_PATH', dirname(realpath(__FILE__)) . DS .'hmvc' . DS); |
|
60 | + define('APPS_PATH', dirname(realpath(__FILE__)) . DS . 'hmvc' . DS); |
|
61 | 61 | |
62 | 62 | /** |
63 | 63 | * The path to the controller directory of your application. |
@@ -193,7 +193,7 @@ discard block |
||
193 | 193 | * It contains your modules used files (config, controllers, libraries, etc.) that is to say which contains your files of the modules, |
194 | 194 | * in HMVC architecture (hierichical, controllers, models, views). |
195 | 195 | */ |
196 | - define('MODULE_PATH', dirname(realpath(__FILE__)) . DS .'hmvc' . DS . 'modules' . DS); |
|
196 | + define('MODULE_PATH', dirname(realpath(__FILE__)) . DS . 'hmvc' . DS . 'modules' . DS); |
|
197 | 197 | |
198 | 198 | /** |
199 | 199 | * The path to the directory of sources external to your application. |
@@ -232,7 +232,7 @@ discard block |
||
232 | 232 | //Fix to allow test as if application is running in CLI mode $_SESSION global variable is not available |
233 | 233 | $_SESSION = array(); |
234 | 234 | |
235 | - if(! isset($_SERVER['REMOTE_ADDR'])){ |
|
235 | + if (!isset($_SERVER['REMOTE_ADDR'])) { |
|
236 | 236 | $_SERVER['REMOTE_ADDR'] = '127.0.0.1'; |
237 | 237 | } |
238 | 238 | |
@@ -240,7 +240,7 @@ discard block |
||
240 | 240 | require_once 'include/autoloader.php'; |
241 | 241 | |
242 | 242 | //check for composer autoload file if exists include it |
243 | - if(file_exists(VENDOR_PATH . 'autoload.php')){ |
|
243 | + if (file_exists(VENDOR_PATH . 'autoload.php')) { |
|
244 | 244 | require_once VENDOR_PATH . 'autoload.php'; |
245 | 245 | |
246 | 246 | //define the class alias for vstream |
@@ -22,7 +22,7 @@ discard block |
||
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 | * check if the interface "SessionHandlerInterface" exists (normally in PHP 5.4 this already exists) |
@@ -76,27 +76,27 @@ discard block |
||
76 | 76 | private $logger; |
77 | 77 | |
78 | 78 | /** |
79 | - * Instance of the Loader class |
|
80 | - * @var Loader |
|
81 | - */ |
|
82 | - protected $loader = null; |
|
79 | + * Instance of the Loader class |
|
80 | + * @var Loader |
|
81 | + */ |
|
82 | + protected $loader = null; |
|
83 | 83 | |
84 | 84 | public function __construct(DBSessionHandlerModel $modelInstance = null, Log $logger = null, Loader $loader = null){ |
85 | 85 | /** |
86 | - * instance of the Log class |
|
87 | - */ |
|
88 | - if(is_object($logger)){ |
|
89 | - $this->setLogger($logger); |
|
90 | - } |
|
91 | - else{ |
|
92 | - $this->logger =& class_loader('Log', 'classes'); |
|
93 | - $this->logger->setLogger('Library::DBSessionHandler'); |
|
94 | - } |
|
95 | - |
|
96 | - if(is_object($loader)){ |
|
97 | - $this->setLoader($loader); |
|
98 | - } |
|
99 | - $this->OBJ = & get_instance(); |
|
86 | + * instance of the Log class |
|
87 | + */ |
|
88 | + if(is_object($logger)){ |
|
89 | + $this->setLogger($logger); |
|
90 | + } |
|
91 | + else{ |
|
92 | + $this->logger =& class_loader('Log', 'classes'); |
|
93 | + $this->logger->setLogger('Library::DBSessionHandler'); |
|
94 | + } |
|
95 | + |
|
96 | + if(is_object($loader)){ |
|
97 | + $this->setLoader($loader); |
|
98 | + } |
|
99 | + $this->OBJ = & get_instance(); |
|
100 | 100 | |
101 | 101 | |
102 | 102 | if(is_object($modelInstance)){ |
@@ -199,9 +199,9 @@ discard block |
||
199 | 199 | $this->getLoader()->library('Browser'); |
200 | 200 | } |
201 | 201 | else{ |
202 | - Loader::functions('user_agent'); |
|
203 | - Loader::library('Browser'); |
|
204 | - } |
|
202 | + Loader::functions('user_agent'); |
|
203 | + Loader::library('Browser'); |
|
204 | + } |
|
205 | 205 | |
206 | 206 | $ip = get_ip(); |
207 | 207 | $keyValue = $instance->getKeyValue(); |
@@ -239,9 +239,9 @@ discard block |
||
239 | 239 | $this->getLoader()->library('Browser'); |
240 | 240 | } |
241 | 241 | else{ |
242 | - Loader::functions('user_agent'); |
|
243 | - Loader::library('Browser'); |
|
244 | - } |
|
242 | + Loader::functions('user_agent'); |
|
243 | + Loader::library('Browser'); |
|
244 | + } |
|
245 | 245 | |
246 | 246 | $ip = get_ip(); |
247 | 247 | $keyValue = $instance->getKeyValue(); |
@@ -325,75 +325,75 @@ discard block |
||
325 | 325 | |
326 | 326 | |
327 | 327 | /** |
328 | - * Return the loader instance |
|
329 | - * @return Loader the loader instance |
|
330 | - */ |
|
331 | - public function getLoader(){ |
|
332 | - return $this->loader; |
|
333 | - } |
|
334 | - |
|
335 | - /** |
|
336 | - * set the loader instance for future use |
|
337 | - * @param Loader $loader the loader object |
|
338 | - */ |
|
339 | - public function setLoader($loader){ |
|
340 | - $this->loader = $loader; |
|
341 | - return $this; |
|
342 | - } |
|
343 | - |
|
344 | - /** |
|
345 | - * Return the model instance |
|
346 | - * @return DBSessionHandlerModel the model instance |
|
347 | - */ |
|
348 | - public function getModelInstance(){ |
|
349 | - return $this->modelInstanceName; |
|
350 | - } |
|
351 | - |
|
352 | - /** |
|
353 | - * set the model instance for future use |
|
354 | - * @param DBSessionHandlerModel $modelInstance the model object |
|
355 | - */ |
|
356 | - public function setModelInstance(DBSessionHandlerModel $modelInstance){ |
|
357 | - $this->modelInstanceName = $modelInstance; |
|
358 | - return $this; |
|
359 | - } |
|
360 | - |
|
361 | - /** |
|
362 | - * Return the Log instance |
|
363 | - * @return Log |
|
364 | - */ |
|
365 | - public function getLogger(){ |
|
366 | - return $this->logger; |
|
367 | - } |
|
368 | - |
|
369 | - /** |
|
370 | - * Set the log instance |
|
371 | - * @param Log $logger the log object |
|
372 | - */ |
|
373 | - public function setLogger(Log $logger){ |
|
374 | - $this->logger = $logger; |
|
375 | - return $this; |
|
376 | - } |
|
377 | - |
|
378 | - /** |
|
379 | - * Set the model instance using the configuration for session |
|
380 | - */ |
|
381 | - private function setModelInstanceFromConfig(){ |
|
382 | - $modelName = get_config('session_save_path'); |
|
328 | + * Return the loader instance |
|
329 | + * @return Loader the loader instance |
|
330 | + */ |
|
331 | + public function getLoader(){ |
|
332 | + return $this->loader; |
|
333 | + } |
|
334 | + |
|
335 | + /** |
|
336 | + * set the loader instance for future use |
|
337 | + * @param Loader $loader the loader object |
|
338 | + */ |
|
339 | + public function setLoader($loader){ |
|
340 | + $this->loader = $loader; |
|
341 | + return $this; |
|
342 | + } |
|
343 | + |
|
344 | + /** |
|
345 | + * Return the model instance |
|
346 | + * @return DBSessionHandlerModel the model instance |
|
347 | + */ |
|
348 | + public function getModelInstance(){ |
|
349 | + return $this->modelInstanceName; |
|
350 | + } |
|
351 | + |
|
352 | + /** |
|
353 | + * set the model instance for future use |
|
354 | + * @param DBSessionHandlerModel $modelInstance the model object |
|
355 | + */ |
|
356 | + public function setModelInstance(DBSessionHandlerModel $modelInstance){ |
|
357 | + $this->modelInstanceName = $modelInstance; |
|
358 | + return $this; |
|
359 | + } |
|
360 | + |
|
361 | + /** |
|
362 | + * Return the Log instance |
|
363 | + * @return Log |
|
364 | + */ |
|
365 | + public function getLogger(){ |
|
366 | + return $this->logger; |
|
367 | + } |
|
368 | + |
|
369 | + /** |
|
370 | + * Set the log instance |
|
371 | + * @param Log $logger the log object |
|
372 | + */ |
|
373 | + public function setLogger(Log $logger){ |
|
374 | + $this->logger = $logger; |
|
375 | + return $this; |
|
376 | + } |
|
377 | + |
|
378 | + /** |
|
379 | + * Set the model instance using the configuration for session |
|
380 | + */ |
|
381 | + private function setModelInstanceFromConfig(){ |
|
382 | + $modelName = get_config('session_save_path'); |
|
383 | 383 | $this->logger->info('The database session model: ' . $modelName); |
384 | 384 | if($this->getLoader()){ |
385 | 385 | $this->getLoader()->model($modelName, 'dbsessionhandlerinstance'); |
386 | 386 | } |
387 | 387 | //@codeCoverageIgnoreStart |
388 | 388 | else{ |
389 | - Loader::model($modelName, 'dbsessionhandlerinstance'); |
|
390 | - } |
|
391 | - if(isset($this->OBJ->dbsessionhandlerinstance) && ! $this->OBJ->dbsessionhandlerinstance instanceof DBSessionHandlerModel){ |
|
389 | + Loader::model($modelName, 'dbsessionhandlerinstance'); |
|
390 | + } |
|
391 | + if(isset($this->OBJ->dbsessionhandlerinstance) && ! $this->OBJ->dbsessionhandlerinstance instanceof DBSessionHandlerModel){ |
|
392 | 392 | show_error('To use database session handler, your class model "'.get_class($this->OBJ->dbsessionhandlerinstance).'" need extends "DBSessionHandlerModel"'); |
393 | 393 | } |
394 | 394 | //@codeCoverageIgnoreEnd |
395 | 395 | |
396 | 396 | //set model instance |
397 | 397 | $this->setModelInstance($this->OBJ->dbsessionhandlerinstance); |
398 | - } |
|
398 | + } |
|
399 | 399 | } |
@@ -27,11 +27,11 @@ discard block |
||
27 | 27 | /** |
28 | 28 | * check if the interface "SessionHandlerInterface" exists (normally in PHP 5.4 this already exists) |
29 | 29 | */ |
30 | - if( !interface_exists('SessionHandlerInterface')){ |
|
30 | + if (!interface_exists('SessionHandlerInterface')) { |
|
31 | 31 | show_error('"SessionHandlerInterface" interface does not exists or is disabled can not use it to handler database session.'); |
32 | 32 | } |
33 | 33 | |
34 | - class DBSessionHandler implements SessionHandlerInterface{ |
|
34 | + class DBSessionHandler implements SessionHandlerInterface { |
|
35 | 35 | |
36 | 36 | /** |
37 | 37 | * The encryption method to use to encrypt session data in database |
@@ -81,25 +81,25 @@ discard block |
||
81 | 81 | */ |
82 | 82 | protected $loader = null; |
83 | 83 | |
84 | - public function __construct(DBSessionHandlerModel $modelInstance = null, Log $logger = null, Loader $loader = null){ |
|
84 | + public function __construct(DBSessionHandlerModel $modelInstance = null, Log $logger = null, Loader $loader = null) { |
|
85 | 85 | /** |
86 | 86 | * instance of the Log class |
87 | 87 | */ |
88 | - if(is_object($logger)){ |
|
88 | + if (is_object($logger)) { |
|
89 | 89 | $this->setLogger($logger); |
90 | 90 | } |
91 | - else{ |
|
92 | - $this->logger =& class_loader('Log', 'classes'); |
|
91 | + else { |
|
92 | + $this->logger = & class_loader('Log', 'classes'); |
|
93 | 93 | $this->logger->setLogger('Library::DBSessionHandler'); |
94 | 94 | } |
95 | 95 | |
96 | - if(is_object($loader)){ |
|
96 | + if (is_object($loader)) { |
|
97 | 97 | $this->setLoader($loader); |
98 | 98 | } |
99 | 99 | $this->OBJ = & get_instance(); |
100 | 100 | |
101 | 101 | |
102 | - if(is_object($modelInstance)){ |
|
102 | + if (is_object($modelInstance)) { |
|
103 | 103 | $this->setModelInstance($modelInstance); |
104 | 104 | } |
105 | 105 | } |
@@ -108,7 +108,7 @@ discard block |
||
108 | 108 | * Set the session secret used to encrypt the data in database |
109 | 109 | * @param string $secret the base64 string secret |
110 | 110 | */ |
111 | - public function setSessionSecret($secret){ |
|
111 | + public function setSessionSecret($secret) { |
|
112 | 112 | $this->sessionSecret = $secret; |
113 | 113 | return $this; |
114 | 114 | } |
@@ -117,7 +117,7 @@ discard block |
||
117 | 117 | * Return the session secret |
118 | 118 | * @return string |
119 | 119 | */ |
120 | - public function getSessionSecret(){ |
|
120 | + public function getSessionSecret() { |
|
121 | 121 | return $this->sessionSecret; |
122 | 122 | } |
123 | 123 | |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | * Set the initializer vector for openssl |
127 | 127 | * @param string $key the session secret used |
128 | 128 | */ |
129 | - public function setInitializerVector($key){ |
|
129 | + public function setInitializerVector($key) { |
|
130 | 130 | $iv_length = openssl_cipher_iv_length(self::DB_SESSION_HASH_METHOD); |
131 | 131 | $key = base64_decode($key); |
132 | 132 | $this->iv = substr(hash('sha256', $key), 0, $iv_length); |
@@ -137,7 +137,7 @@ discard block |
||
137 | 137 | * Return the initializer vector |
138 | 138 | * @return string |
139 | 139 | */ |
140 | - public function getInitializerVector(){ |
|
140 | + public function getInitializerVector() { |
|
141 | 141 | return $this->iv; |
142 | 142 | } |
143 | 143 | |
@@ -147,16 +147,16 @@ discard block |
||
147 | 147 | * @param string $sessionName the session name |
148 | 148 | * @return boolean |
149 | 149 | */ |
150 | - public function open($savePath, $sessionName){ |
|
150 | + public function open($savePath, $sessionName) { |
|
151 | 151 | $this->logger->debug('Opening database session handler for [' . $sessionName . ']'); |
152 | 152 | //try to check if session secret is set before |
153 | - if(! $this->getSessionSecret()){ |
|
153 | + if (!$this->getSessionSecret()) { |
|
154 | 154 | $secret = get_config('session_secret', false); |
155 | 155 | $this->setSessionSecret($secret); |
156 | 156 | } |
157 | 157 | $this->logger->info('Session secret: ' . $this->getSessionSecret()); |
158 | 158 | |
159 | - if(! $this->getModelInstance()){ |
|
159 | + if (!$this->getModelInstance()) { |
|
160 | 160 | $this->setModelInstanceFromConfig(); |
161 | 161 | } |
162 | 162 | $this->setInitializerVector($this->getSessionSecret()); |
@@ -164,7 +164,7 @@ discard block |
||
164 | 164 | //set session tables columns |
165 | 165 | $this->sessionTableColumns = $this->getModelInstance()->getSessionTableColumns(); |
166 | 166 | |
167 | - if(empty($this->sessionTableColumns)){ |
|
167 | + if (empty($this->sessionTableColumns)) { |
|
168 | 168 | show_error('The session handler is "database" but the table columns not set'); |
169 | 169 | } |
170 | 170 | $this->logger->info('Database session, the model columns are listed below: ' . stringfy_vars($this->sessionTableColumns)); |
@@ -180,7 +180,7 @@ discard block |
||
180 | 180 | * Close the session |
181 | 181 | * @return boolean |
182 | 182 | */ |
183 | - public function close(){ |
|
183 | + public function close() { |
|
184 | 184 | $this->logger->debug('Closing database session handler'); |
185 | 185 | return true; |
186 | 186 | } |
@@ -190,15 +190,15 @@ discard block |
||
190 | 190 | * @param string $sid the session id to use |
191 | 191 | * @return mixed the session data in serialiaze format |
192 | 192 | */ |
193 | - public function read($sid){ |
|
193 | + public function read($sid) { |
|
194 | 194 | $this->logger->debug('Reading database session data for SID: ' . $sid); |
195 | 195 | $instance = $this->getModelInstance(); |
196 | 196 | $columns = $this->sessionTableColumns; |
197 | - if($this->getLoader()){ |
|
197 | + if ($this->getLoader()) { |
|
198 | 198 | $this->getLoader()->functions('user_agent'); |
199 | 199 | $this->getLoader()->library('Browser'); |
200 | 200 | } |
201 | - else{ |
|
201 | + else { |
|
202 | 202 | Loader::functions('user_agent'); |
203 | 203 | Loader::library('Browser'); |
204 | 204 | } |
@@ -206,13 +206,13 @@ discard block |
||
206 | 206 | $ip = get_ip(); |
207 | 207 | $keyValue = $instance->getKeyValue(); |
208 | 208 | $host = @gethostbyaddr($ip) or null; |
209 | - $browser = $this->OBJ->browser->getPlatform().', '.$this->OBJ->browser->getBrowser().' '.$this->OBJ->browser->getVersion(); |
|
209 | + $browser = $this->OBJ->browser->getPlatform() . ', ' . $this->OBJ->browser->getBrowser() . ' ' . $this->OBJ->browser->getVersion(); |
|
210 | 210 | |
211 | 211 | $data = $instance->get_by(array($columns['sid'] => $sid, $columns['shost'] => $host, $columns['sbrowser'] => $browser)); |
212 | - if($data && isset($data->{$columns['sdata']})){ |
|
212 | + if ($data && isset($data->{$columns['sdata']})) { |
|
213 | 213 | //checking inactivity |
214 | 214 | $timeInactivity = time() - get_config('session_inactivity_time', 100); |
215 | - if($data->{$columns['stime']} < $timeInactivity){ |
|
215 | + if ($data->{$columns['stime']} < $timeInactivity) { |
|
216 | 216 | $this->logger->info('Database session data for SID: ' . $sid . ' already expired, destroy it'); |
217 | 217 | $this->destroy($sid); |
218 | 218 | return false; |
@@ -229,16 +229,16 @@ discard block |
||
229 | 229 | * @param mixed $data the session data to save in serialize format |
230 | 230 | * @return boolean |
231 | 231 | */ |
232 | - public function write($sid, $data){ |
|
232 | + public function write($sid, $data) { |
|
233 | 233 | $this->logger->debug('Saving database session data for SID: ' . $sid . ', data: ' . stringfy_vars($data)); |
234 | 234 | $instance = $this->getModelInstance(); |
235 | 235 | $columns = $this->sessionTableColumns; |
236 | 236 | |
237 | - if($this->getLoader()){ |
|
237 | + if ($this->getLoader()) { |
|
238 | 238 | $this->getLoader()->functions('user_agent'); |
239 | 239 | $this->getLoader()->library('Browser'); |
240 | 240 | } |
241 | - else{ |
|
241 | + else { |
|
242 | 242 | Loader::functions('user_agent'); |
243 | 243 | Loader::library('Browser'); |
244 | 244 | } |
@@ -246,7 +246,7 @@ discard block |
||
246 | 246 | $ip = get_ip(); |
247 | 247 | $keyValue = $instance->getKeyValue(); |
248 | 248 | $host = @gethostbyaddr($ip) or null; |
249 | - $browser = $this->OBJ->browser->getPlatform().', '.$this->OBJ->browser->getBrowser().' '.$this->OBJ->browser->getVersion(); |
|
249 | + $browser = $this->OBJ->browser->getPlatform() . ', ' . $this->OBJ->browser->getBrowser() . ' ' . $this->OBJ->browser->getVersion(); |
|
250 | 250 | $data = $this->encode($data); |
251 | 251 | $params = array( |
252 | 252 | $columns['sid'] => $sid, |
@@ -259,13 +259,13 @@ discard block |
||
259 | 259 | ); |
260 | 260 | $this->logger->info('Database session data to save are listed below :' . stringfy_vars($params)); |
261 | 261 | $exists = $instance->get($sid); |
262 | - if($exists){ |
|
262 | + if ($exists) { |
|
263 | 263 | $this->logger->info('Session data for SID: ' . $sid . ' already exists, just update it'); |
264 | 264 | //update |
265 | 265 | unset($params[$columns['sid']]); |
266 | 266 | $instance->update($sid, $params); |
267 | 267 | } |
268 | - else{ |
|
268 | + else { |
|
269 | 269 | $this->logger->info('Session data for SID: ' . $sid . ' not yet exists, insert it now'); |
270 | 270 | $instance->insert($params); |
271 | 271 | } |
@@ -278,7 +278,7 @@ discard block |
||
278 | 278 | * @param string $sid the session id value |
279 | 279 | * @return boolean |
280 | 280 | */ |
281 | - public function destroy($sid){ |
|
281 | + public function destroy($sid) { |
|
282 | 282 | $this->logger->debug('Destroy of session data for SID: ' . $sid); |
283 | 283 | $instance = $this->modelInstanceName; |
284 | 284 | $instance->delete($sid); |
@@ -290,7 +290,7 @@ discard block |
||
290 | 290 | * @param ineteger $maxLifetime the max lifetime |
291 | 291 | * @return boolean |
292 | 292 | */ |
293 | - public function gc($maxLifetime){ |
|
293 | + public function gc($maxLifetime) { |
|
294 | 294 | $instance = $this->modelInstanceName; |
295 | 295 | $time = time() - $maxLifetime; |
296 | 296 | $this->logger->debug('Garbage collector of expired session. maxLifetime [' . $maxLifetime . '] sec, expired time [' . $time . ']'); |
@@ -303,9 +303,9 @@ discard block |
||
303 | 303 | * @param mixed $data the session data to encode |
304 | 304 | * @return mixed the encoded session data |
305 | 305 | */ |
306 | - public function encode($data){ |
|
306 | + public function encode($data) { |
|
307 | 307 | $key = base64_decode($this->sessionSecret); |
308 | - $dataEncrypted = openssl_encrypt($data , self::DB_SESSION_HASH_METHOD, $key, OPENSSL_RAW_DATA, $this->getInitializerVector()); |
|
308 | + $dataEncrypted = openssl_encrypt($data, self::DB_SESSION_HASH_METHOD, $key, OPENSSL_RAW_DATA, $this->getInitializerVector()); |
|
309 | 309 | $output = base64_encode($dataEncrypted); |
310 | 310 | return $output; |
311 | 311 | } |
@@ -316,7 +316,7 @@ discard block |
||
316 | 316 | * @param mixed $data the data to decode |
317 | 317 | * @return mixed the decoded data |
318 | 318 | */ |
319 | - public function decode($data){ |
|
319 | + public function decode($data) { |
|
320 | 320 | $key = base64_decode($this->sessionSecret); |
321 | 321 | $data = base64_decode($data); |
322 | 322 | $data = openssl_decrypt($data, self::DB_SESSION_HASH_METHOD, $key, OPENSSL_RAW_DATA, $this->getInitializerVector()); |
@@ -328,7 +328,7 @@ discard block |
||
328 | 328 | * Return the loader instance |
329 | 329 | * @return Loader the loader instance |
330 | 330 | */ |
331 | - public function getLoader(){ |
|
331 | + public function getLoader() { |
|
332 | 332 | return $this->loader; |
333 | 333 | } |
334 | 334 | |
@@ -336,7 +336,7 @@ discard block |
||
336 | 336 | * set the loader instance for future use |
337 | 337 | * @param Loader $loader the loader object |
338 | 338 | */ |
339 | - public function setLoader($loader){ |
|
339 | + public function setLoader($loader) { |
|
340 | 340 | $this->loader = $loader; |
341 | 341 | return $this; |
342 | 342 | } |
@@ -345,7 +345,7 @@ discard block |
||
345 | 345 | * Return the model instance |
346 | 346 | * @return DBSessionHandlerModel the model instance |
347 | 347 | */ |
348 | - public function getModelInstance(){ |
|
348 | + public function getModelInstance() { |
|
349 | 349 | return $this->modelInstanceName; |
350 | 350 | } |
351 | 351 | |
@@ -353,7 +353,7 @@ discard block |
||
353 | 353 | * set the model instance for future use |
354 | 354 | * @param DBSessionHandlerModel $modelInstance the model object |
355 | 355 | */ |
356 | - public function setModelInstance(DBSessionHandlerModel $modelInstance){ |
|
356 | + public function setModelInstance(DBSessionHandlerModel $modelInstance) { |
|
357 | 357 | $this->modelInstanceName = $modelInstance; |
358 | 358 | return $this; |
359 | 359 | } |
@@ -362,7 +362,7 @@ discard block |
||
362 | 362 | * Return the Log instance |
363 | 363 | * @return Log |
364 | 364 | */ |
365 | - public function getLogger(){ |
|
365 | + public function getLogger() { |
|
366 | 366 | return $this->logger; |
367 | 367 | } |
368 | 368 | |
@@ -370,7 +370,7 @@ discard block |
||
370 | 370 | * Set the log instance |
371 | 371 | * @param Log $logger the log object |
372 | 372 | */ |
373 | - public function setLogger(Log $logger){ |
|
373 | + public function setLogger(Log $logger) { |
|
374 | 374 | $this->logger = $logger; |
375 | 375 | return $this; |
376 | 376 | } |
@@ -378,18 +378,18 @@ discard block |
||
378 | 378 | /** |
379 | 379 | * Set the model instance using the configuration for session |
380 | 380 | */ |
381 | - private function setModelInstanceFromConfig(){ |
|
381 | + private function setModelInstanceFromConfig() { |
|
382 | 382 | $modelName = get_config('session_save_path'); |
383 | 383 | $this->logger->info('The database session model: ' . $modelName); |
384 | - if($this->getLoader()){ |
|
384 | + if ($this->getLoader()) { |
|
385 | 385 | $this->getLoader()->model($modelName, 'dbsessionhandlerinstance'); |
386 | 386 | } |
387 | 387 | //@codeCoverageIgnoreStart |
388 | - else{ |
|
388 | + else { |
|
389 | 389 | Loader::model($modelName, 'dbsessionhandlerinstance'); |
390 | 390 | } |
391 | - if(isset($this->OBJ->dbsessionhandlerinstance) && ! $this->OBJ->dbsessionhandlerinstance instanceof DBSessionHandlerModel){ |
|
392 | - show_error('To use database session handler, your class model "'.get_class($this->OBJ->dbsessionhandlerinstance).'" need extends "DBSessionHandlerModel"'); |
|
391 | + if (isset($this->OBJ->dbsessionhandlerinstance) && !$this->OBJ->dbsessionhandlerinstance instanceof DBSessionHandlerModel) { |
|
392 | + show_error('To use database session handler, your class model "' . get_class($this->OBJ->dbsessionhandlerinstance) . '" need extends "DBSessionHandlerModel"'); |
|
393 | 393 | } |
394 | 394 | //@codeCoverageIgnoreEnd |
395 | 395 |
@@ -87,8 +87,7 @@ discard block |
||
87 | 87 | */ |
88 | 88 | if(is_object($logger)){ |
89 | 89 | $this->setLogger($logger); |
90 | - } |
|
91 | - else{ |
|
90 | + } else{ |
|
92 | 91 | $this->logger =& class_loader('Log', 'classes'); |
93 | 92 | $this->logger->setLogger('Library::DBSessionHandler'); |
94 | 93 | } |
@@ -197,8 +196,7 @@ discard block |
||
197 | 196 | if($this->getLoader()){ |
198 | 197 | $this->getLoader()->functions('user_agent'); |
199 | 198 | $this->getLoader()->library('Browser'); |
200 | - } |
|
201 | - else{ |
|
199 | + } else{ |
|
202 | 200 | Loader::functions('user_agent'); |
203 | 201 | Loader::library('Browser'); |
204 | 202 | } |
@@ -237,8 +235,7 @@ discard block |
||
237 | 235 | if($this->getLoader()){ |
238 | 236 | $this->getLoader()->functions('user_agent'); |
239 | 237 | $this->getLoader()->library('Browser'); |
240 | - } |
|
241 | - else{ |
|
238 | + } else{ |
|
242 | 239 | Loader::functions('user_agent'); |
243 | 240 | Loader::library('Browser'); |
244 | 241 | } |
@@ -264,8 +261,7 @@ discard block |
||
264 | 261 | //update |
265 | 262 | unset($params[$columns['sid']]); |
266 | 263 | $instance->update($sid, $params); |
267 | - } |
|
268 | - else{ |
|
264 | + } else{ |
|
269 | 265 | $this->logger->info('Session data for SID: ' . $sid . ' not yet exists, insert it now'); |
270 | 266 | $instance->insert($params); |
271 | 267 | } |
@@ -1,595 +1,595 @@ discard block |
||
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 | - 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 | + protected $_temporary_return_type = NULL; |
|
116 | 116 | |
117 | 117 | |
118 | - /** |
|
118 | + /** |
|
119 | 119 | The database cache time |
120 | - */ |
|
121 | - protected $dbCacheTime = 0; |
|
122 | - |
|
123 | - /** |
|
124 | - * Instance of the Loader class |
|
125 | - * @var Loader |
|
126 | - */ |
|
127 | - protected $loaderInstance = null; |
|
128 | - |
|
129 | - /** |
|
130 | - * Instance of the FormValidation library |
|
131 | - * @var FormValidation |
|
132 | - */ |
|
133 | - protected $formValidationInstance = null; |
|
134 | - |
|
135 | - /* -------------------------------------------------------------- |
|
120 | + */ |
|
121 | + protected $dbCacheTime = 0; |
|
122 | + |
|
123 | + /** |
|
124 | + * Instance of the Loader class |
|
125 | + * @var Loader |
|
126 | + */ |
|
127 | + protected $loaderInstance = null; |
|
128 | + |
|
129 | + /** |
|
130 | + * Instance of the FormValidation library |
|
131 | + * @var FormValidation |
|
132 | + */ |
|
133 | + protected $formValidationInstance = null; |
|
134 | + |
|
135 | + /* -------------------------------------------------------------- |
|
136 | 136 | * GENERIC METHODS |
137 | 137 | * ------------------------------------------------------------ */ |
138 | 138 | |
139 | - /** |
|
140 | - * Initialise the model, tie into the CodeIgniter superobject and |
|
141 | - * try our best to guess the table name. |
|
142 | - */ |
|
143 | - public function __construct(Database $db = null){ |
|
144 | - if(is_object($db)){ |
|
145 | - $this->setDatabaseInstance($db); |
|
146 | - } |
|
147 | - else{ |
|
148 | - $obj = & get_instance(); |
|
149 | - if(isset($obj->database) && is_object($obj->database)){ |
|
150 | - /** |
|
151 | - * NOTE: Need use "clone" because some Model need have the personal instance of the database library |
|
152 | - * to prevent duplication |
|
153 | - */ |
|
154 | - $this->setDatabaseInstance(clone $obj->database); |
|
155 | - } |
|
156 | - } |
|
157 | - |
|
158 | - array_unshift($this->before_create, 'protect_attributes'); |
|
159 | - array_unshift($this->before_update, 'protect_attributes'); |
|
160 | - $this->_temporary_return_type = $this->return_type; |
|
161 | - } |
|
162 | - |
|
163 | - /* -------------------------------------------------------------- |
|
139 | + /** |
|
140 | + * Initialise the model, tie into the CodeIgniter superobject and |
|
141 | + * try our best to guess the table name. |
|
142 | + */ |
|
143 | + public function __construct(Database $db = null){ |
|
144 | + if(is_object($db)){ |
|
145 | + $this->setDatabaseInstance($db); |
|
146 | + } |
|
147 | + else{ |
|
148 | + $obj = & get_instance(); |
|
149 | + if(isset($obj->database) && is_object($obj->database)){ |
|
150 | + /** |
|
151 | + * NOTE: Need use "clone" because some Model need have the personal instance of the database library |
|
152 | + * to prevent duplication |
|
153 | + */ |
|
154 | + $this->setDatabaseInstance(clone $obj->database); |
|
155 | + } |
|
156 | + } |
|
157 | + |
|
158 | + array_unshift($this->before_create, 'protect_attributes'); |
|
159 | + array_unshift($this->before_update, 'protect_attributes'); |
|
160 | + $this->_temporary_return_type = $this->return_type; |
|
161 | + } |
|
162 | + |
|
163 | + /* -------------------------------------------------------------- |
|
164 | 164 | * CRUD INTERFACE |
165 | 165 | * ------------------------------------------------------------ */ |
166 | 166 | |
167 | - /** |
|
168 | - * Fetch a single record based on the primary key. Returns an object. |
|
169 | - */ |
|
170 | - public function get($primary_value) |
|
171 | - { |
|
172 | - return $this->get_by($this->primary_key, $primary_value); |
|
173 | - } |
|
174 | - |
|
175 | - /** |
|
176 | - * Fetch a single record based on an arbitrary WHERE call. Can be |
|
177 | - * any valid value to $this->_database->where(). |
|
178 | - */ |
|
179 | - public function get_by() |
|
180 | - { |
|
181 | - $where = func_get_args(); |
|
182 | - |
|
183 | - if ($this->soft_delete && $this->_temporary_with_deleted !== TRUE) |
|
184 | - { |
|
185 | - $this->_database->where($this->soft_delete_key, (bool)$this->_temporary_only_deleted); |
|
186 | - } |
|
187 | - |
|
188 | - $this->_set_where($where); |
|
189 | - |
|
190 | - $this->trigger('before_get'); |
|
167 | + /** |
|
168 | + * Fetch a single record based on the primary key. Returns an object. |
|
169 | + */ |
|
170 | + public function get($primary_value) |
|
171 | + { |
|
172 | + return $this->get_by($this->primary_key, $primary_value); |
|
173 | + } |
|
174 | + |
|
175 | + /** |
|
176 | + * Fetch a single record based on an arbitrary WHERE call. Can be |
|
177 | + * any valid value to $this->_database->where(). |
|
178 | + */ |
|
179 | + public function get_by() |
|
180 | + { |
|
181 | + $where = func_get_args(); |
|
182 | + |
|
183 | + if ($this->soft_delete && $this->_temporary_with_deleted !== TRUE) |
|
184 | + { |
|
185 | + $this->_database->where($this->soft_delete_key, (bool)$this->_temporary_only_deleted); |
|
186 | + } |
|
187 | + |
|
188 | + $this->_set_where($where); |
|
189 | + |
|
190 | + $this->trigger('before_get'); |
|
191 | 191 | $type = $this->_temporary_return_type == 'array' ? 'array':false; |
192 | - $row = $this->_database->from($this->_table)->get($type); |
|
193 | - $this->_temporary_return_type = $this->return_type; |
|
194 | - $row = $this->trigger('after_get', $row); |
|
195 | - $this->_with = array(); |
|
196 | - return $row; |
|
197 | - } |
|
198 | - |
|
199 | - /** |
|
200 | - * Fetch an array of records based on an array of primary values. |
|
201 | - */ |
|
202 | - public function get_many($values) |
|
203 | - { |
|
204 | - $this->_database->in($this->primary_key, $values); |
|
205 | - return $this->get_all(); |
|
206 | - } |
|
207 | - |
|
208 | - /** |
|
209 | - * Fetch an array of records based on an arbitrary WHERE call. |
|
210 | - */ |
|
211 | - public function get_many_by() |
|
212 | - { |
|
213 | - $where = func_get_args(); |
|
214 | - $this->_set_where($where); |
|
215 | - return $this->get_all(); |
|
216 | - } |
|
217 | - |
|
218 | - /** |
|
219 | - * Fetch all the records in the table. Can be used as a generic call |
|
220 | - * to $this->_database->get() with scoped methods. |
|
221 | - */ |
|
222 | - public function get_all() |
|
223 | - { |
|
224 | - $this->trigger('before_get'); |
|
225 | - if ($this->soft_delete && $this->_temporary_with_deleted !== TRUE) |
|
226 | - { |
|
227 | - $this->_database->where($this->soft_delete_key, (bool)$this->_temporary_only_deleted); |
|
228 | - } |
|
192 | + $row = $this->_database->from($this->_table)->get($type); |
|
193 | + $this->_temporary_return_type = $this->return_type; |
|
194 | + $row = $this->trigger('after_get', $row); |
|
195 | + $this->_with = array(); |
|
196 | + return $row; |
|
197 | + } |
|
198 | + |
|
199 | + /** |
|
200 | + * Fetch an array of records based on an array of primary values. |
|
201 | + */ |
|
202 | + public function get_many($values) |
|
203 | + { |
|
204 | + $this->_database->in($this->primary_key, $values); |
|
205 | + return $this->get_all(); |
|
206 | + } |
|
207 | + |
|
208 | + /** |
|
209 | + * Fetch an array of records based on an arbitrary WHERE call. |
|
210 | + */ |
|
211 | + public function get_many_by() |
|
212 | + { |
|
213 | + $where = func_get_args(); |
|
214 | + $this->_set_where($where); |
|
215 | + return $this->get_all(); |
|
216 | + } |
|
217 | + |
|
218 | + /** |
|
219 | + * Fetch all the records in the table. Can be used as a generic call |
|
220 | + * to $this->_database->get() with scoped methods. |
|
221 | + */ |
|
222 | + public function get_all() |
|
223 | + { |
|
224 | + $this->trigger('before_get'); |
|
225 | + if ($this->soft_delete && $this->_temporary_with_deleted !== TRUE) |
|
226 | + { |
|
227 | + $this->_database->where($this->soft_delete_key, (bool)$this->_temporary_only_deleted); |
|
228 | + } |
|
229 | 229 | $type = $this->_temporary_return_type == 'array' ? 'array':false; |
230 | - $result = $this->_database->from($this->_table)->getAll($type); |
|
231 | - $this->_temporary_return_type = $this->return_type; |
|
232 | - |
|
233 | - foreach ($result as $key => &$row) |
|
234 | - { |
|
235 | - $row = $this->trigger('after_get', $row, ($key == count($result) - 1)); |
|
236 | - } |
|
237 | - $this->_with = array(); |
|
238 | - return $result; |
|
239 | - } |
|
240 | - |
|
241 | - /** |
|
242 | - * Insert a new row into the table. $data should be an associative array |
|
243 | - * of data to be inserted. Returns newly created ID. |
|
244 | - */ |
|
245 | - public function insert($data = array(), $skip_validation = FALSE, $escape = true) |
|
246 | - { |
|
247 | - if ($skip_validation === FALSE) |
|
248 | - { |
|
249 | - $data = $this->validate($data); |
|
250 | - } |
|
251 | - |
|
252 | - if ($data !== FALSE) |
|
253 | - { |
|
254 | - $data = $this->trigger('before_create', $data); |
|
255 | - $this->_database->from($this->_table)->insert($data, $escape); |
|
256 | - $insert_id = $this->_database->insertId(); |
|
257 | - $this->trigger('after_create', $insert_id); |
|
258 | - return $insert_id; |
|
259 | - } |
|
260 | - else |
|
261 | - { |
|
262 | - return FALSE; |
|
263 | - } |
|
264 | - } |
|
265 | - |
|
266 | - /** |
|
267 | - * Insert multiple rows into the table. Returns an array of multiple IDs. |
|
268 | - */ |
|
269 | - public function insert_many($data = array(), $skip_validation = FALSE, $escape = true) |
|
270 | - { |
|
271 | - $ids = array(); |
|
272 | - foreach ($data as $key => $row) |
|
273 | - { |
|
274 | - $ids[] = $this->insert($row, $skip_validation, $escape); |
|
275 | - } |
|
276 | - return $ids; |
|
277 | - } |
|
278 | - |
|
279 | - /** |
|
280 | - * Updated a record based on the primary value. |
|
281 | - */ |
|
282 | - public function update($primary_value, $data = array(), $skip_validation = FALSE, $escape = true) |
|
283 | - { |
|
284 | - $data = $this->trigger('before_update', $data); |
|
285 | - if ($skip_validation === FALSE) |
|
286 | - { |
|
287 | - $data = $this->validate($data); |
|
288 | - } |
|
289 | - |
|
290 | - if ($data !== FALSE) |
|
291 | - { |
|
292 | - $result = $this->_database->where($this->primary_key, $primary_value) |
|
293 | - ->from($this->_table) |
|
294 | - ->update($data, $escape); |
|
295 | - $this->trigger('after_update', array($data, $result)); |
|
296 | - return $result; |
|
297 | - } |
|
298 | - else |
|
299 | - { |
|
300 | - return FALSE; |
|
301 | - } |
|
302 | - } |
|
303 | - |
|
304 | - /** |
|
305 | - * Update many records, based on an array of primary values. |
|
306 | - */ |
|
307 | - public function update_many($primary_values, $data = array(), $skip_validation = FALSE, $escape = true) |
|
308 | - { |
|
309 | - $data = $this->trigger('before_update', $data); |
|
310 | - if ($skip_validation === FALSE) |
|
311 | - { |
|
312 | - $data = $this->validate($data); |
|
313 | - } |
|
314 | - if ($data !== FALSE) |
|
315 | - { |
|
316 | - $result = $this->_database->in($this->primary_key, $primary_values) |
|
317 | - ->from($this->_table) |
|
318 | - ->update($data, $escape); |
|
319 | - $this->trigger('after_update', array($data, $result)); |
|
320 | - return $result; |
|
321 | - } |
|
322 | - else |
|
323 | - { |
|
324 | - return FALSE; |
|
325 | - } |
|
326 | - } |
|
327 | - |
|
328 | - /** |
|
329 | - * Updated a record based on an arbitrary WHERE clause. |
|
330 | - */ |
|
331 | - public function update_by() |
|
332 | - { |
|
333 | - $args = func_get_args(); |
|
334 | - $data = array(); |
|
335 | - if(count($args) == 2){ |
|
336 | - if(is_array($args[1])){ |
|
337 | - $data = array_pop($args); |
|
338 | - } |
|
339 | - } |
|
340 | - else if(count($args) == 3){ |
|
341 | - if(is_array($args[2])){ |
|
342 | - $data = array_pop($args); |
|
343 | - } |
|
344 | - } |
|
345 | - $data = $this->trigger('before_update', $data); |
|
346 | - if ($this->validate($data) !== FALSE) |
|
347 | - { |
|
348 | - $this->_set_where($args); |
|
349 | - $result = $this->_database->from($this->_table)->update($data); |
|
350 | - $this->trigger('after_update', array($data, $result)); |
|
351 | - return $result; |
|
352 | - } |
|
353 | - else |
|
354 | - { |
|
355 | - return FALSE; |
|
356 | - } |
|
357 | - } |
|
358 | - |
|
359 | - /** |
|
360 | - * Update all records |
|
361 | - */ |
|
362 | - public function update_all($data = array(), $escape = true) |
|
363 | - { |
|
364 | - $data = $this->trigger('before_update', $data); |
|
365 | - $result = $this->_database->from($this->_table)->update($data, $escape); |
|
366 | - $this->trigger('after_update', array($data, $result)); |
|
367 | - return $result; |
|
368 | - } |
|
369 | - |
|
370 | - /** |
|
371 | - * Delete a row from the table by the primary value |
|
372 | - */ |
|
373 | - public function delete($id) |
|
374 | - { |
|
375 | - $this->trigger('before_delete', $id); |
|
376 | - $this->_database->where($this->primary_key, $id); |
|
377 | - if ($this->soft_delete) |
|
378 | - { |
|
379 | - $result = $this->_database->from($this->_table)->update(array( $this->soft_delete_key => TRUE )); |
|
380 | - } |
|
381 | - else |
|
382 | - { |
|
383 | - $result = $this->_database->from($this->_table)->delete(); |
|
384 | - } |
|
385 | - |
|
386 | - $this->trigger('after_delete', $result); |
|
387 | - return $result; |
|
388 | - } |
|
389 | - |
|
390 | - /** |
|
391 | - * Delete a row from the database table by an arbitrary WHERE clause |
|
392 | - */ |
|
393 | - public function delete_by() |
|
394 | - { |
|
395 | - $where = func_get_args(); |
|
396 | - $where = $this->trigger('before_delete', $where); |
|
397 | - $this->_set_where($where); |
|
398 | - if ($this->soft_delete) |
|
399 | - { |
|
400 | - $result = $this->_database->from($this->_table)->update(array( $this->soft_delete_key => TRUE )); |
|
401 | - } |
|
402 | - else |
|
403 | - { |
|
404 | - $result = $this->_database->from($this->_table)->delete(); |
|
405 | - } |
|
406 | - $this->trigger('after_delete', $result); |
|
407 | - return $result; |
|
408 | - } |
|
409 | - |
|
410 | - /** |
|
411 | - * Delete many rows from the database table by multiple primary values |
|
412 | - */ |
|
413 | - public function delete_many($primary_values) |
|
414 | - { |
|
415 | - $primary_values = $this->trigger('before_delete', $primary_values); |
|
416 | - $this->_database->in($this->primary_key, $primary_values); |
|
417 | - if ($this->soft_delete) |
|
418 | - { |
|
419 | - $result = $this->_database->from($this->_table)->update(array( $this->soft_delete_key => TRUE )); |
|
420 | - } |
|
421 | - else |
|
422 | - { |
|
423 | - $result = $this->_database->from($this->_table)->delete(); |
|
424 | - } |
|
425 | - $this->trigger('after_delete', $result); |
|
426 | - return $result; |
|
427 | - } |
|
428 | - |
|
429 | - |
|
430 | - /** |
|
431 | - * Truncates the table |
|
432 | - */ |
|
433 | - public function truncate() |
|
434 | - { |
|
435 | - $result = $this->_database->from($this->_table)->delete(); |
|
436 | - return $result; |
|
437 | - } |
|
438 | - |
|
439 | - /* -------------------------------------------------------------- |
|
230 | + $result = $this->_database->from($this->_table)->getAll($type); |
|
231 | + $this->_temporary_return_type = $this->return_type; |
|
232 | + |
|
233 | + foreach ($result as $key => &$row) |
|
234 | + { |
|
235 | + $row = $this->trigger('after_get', $row, ($key == count($result) - 1)); |
|
236 | + } |
|
237 | + $this->_with = array(); |
|
238 | + return $result; |
|
239 | + } |
|
240 | + |
|
241 | + /** |
|
242 | + * Insert a new row into the table. $data should be an associative array |
|
243 | + * of data to be inserted. Returns newly created ID. |
|
244 | + */ |
|
245 | + public function insert($data = array(), $skip_validation = FALSE, $escape = true) |
|
246 | + { |
|
247 | + if ($skip_validation === FALSE) |
|
248 | + { |
|
249 | + $data = $this->validate($data); |
|
250 | + } |
|
251 | + |
|
252 | + if ($data !== FALSE) |
|
253 | + { |
|
254 | + $data = $this->trigger('before_create', $data); |
|
255 | + $this->_database->from($this->_table)->insert($data, $escape); |
|
256 | + $insert_id = $this->_database->insertId(); |
|
257 | + $this->trigger('after_create', $insert_id); |
|
258 | + return $insert_id; |
|
259 | + } |
|
260 | + else |
|
261 | + { |
|
262 | + return FALSE; |
|
263 | + } |
|
264 | + } |
|
265 | + |
|
266 | + /** |
|
267 | + * Insert multiple rows into the table. Returns an array of multiple IDs. |
|
268 | + */ |
|
269 | + public function insert_many($data = array(), $skip_validation = FALSE, $escape = true) |
|
270 | + { |
|
271 | + $ids = array(); |
|
272 | + foreach ($data as $key => $row) |
|
273 | + { |
|
274 | + $ids[] = $this->insert($row, $skip_validation, $escape); |
|
275 | + } |
|
276 | + return $ids; |
|
277 | + } |
|
278 | + |
|
279 | + /** |
|
280 | + * Updated a record based on the primary value. |
|
281 | + */ |
|
282 | + public function update($primary_value, $data = array(), $skip_validation = FALSE, $escape = true) |
|
283 | + { |
|
284 | + $data = $this->trigger('before_update', $data); |
|
285 | + if ($skip_validation === FALSE) |
|
286 | + { |
|
287 | + $data = $this->validate($data); |
|
288 | + } |
|
289 | + |
|
290 | + if ($data !== FALSE) |
|
291 | + { |
|
292 | + $result = $this->_database->where($this->primary_key, $primary_value) |
|
293 | + ->from($this->_table) |
|
294 | + ->update($data, $escape); |
|
295 | + $this->trigger('after_update', array($data, $result)); |
|
296 | + return $result; |
|
297 | + } |
|
298 | + else |
|
299 | + { |
|
300 | + return FALSE; |
|
301 | + } |
|
302 | + } |
|
303 | + |
|
304 | + /** |
|
305 | + * Update many records, based on an array of primary values. |
|
306 | + */ |
|
307 | + public function update_many($primary_values, $data = array(), $skip_validation = FALSE, $escape = true) |
|
308 | + { |
|
309 | + $data = $this->trigger('before_update', $data); |
|
310 | + if ($skip_validation === FALSE) |
|
311 | + { |
|
312 | + $data = $this->validate($data); |
|
313 | + } |
|
314 | + if ($data !== FALSE) |
|
315 | + { |
|
316 | + $result = $this->_database->in($this->primary_key, $primary_values) |
|
317 | + ->from($this->_table) |
|
318 | + ->update($data, $escape); |
|
319 | + $this->trigger('after_update', array($data, $result)); |
|
320 | + return $result; |
|
321 | + } |
|
322 | + else |
|
323 | + { |
|
324 | + return FALSE; |
|
325 | + } |
|
326 | + } |
|
327 | + |
|
328 | + /** |
|
329 | + * Updated a record based on an arbitrary WHERE clause. |
|
330 | + */ |
|
331 | + public function update_by() |
|
332 | + { |
|
333 | + $args = func_get_args(); |
|
334 | + $data = array(); |
|
335 | + if(count($args) == 2){ |
|
336 | + if(is_array($args[1])){ |
|
337 | + $data = array_pop($args); |
|
338 | + } |
|
339 | + } |
|
340 | + else if(count($args) == 3){ |
|
341 | + if(is_array($args[2])){ |
|
342 | + $data = array_pop($args); |
|
343 | + } |
|
344 | + } |
|
345 | + $data = $this->trigger('before_update', $data); |
|
346 | + if ($this->validate($data) !== FALSE) |
|
347 | + { |
|
348 | + $this->_set_where($args); |
|
349 | + $result = $this->_database->from($this->_table)->update($data); |
|
350 | + $this->trigger('after_update', array($data, $result)); |
|
351 | + return $result; |
|
352 | + } |
|
353 | + else |
|
354 | + { |
|
355 | + return FALSE; |
|
356 | + } |
|
357 | + } |
|
358 | + |
|
359 | + /** |
|
360 | + * Update all records |
|
361 | + */ |
|
362 | + public function update_all($data = array(), $escape = true) |
|
363 | + { |
|
364 | + $data = $this->trigger('before_update', $data); |
|
365 | + $result = $this->_database->from($this->_table)->update($data, $escape); |
|
366 | + $this->trigger('after_update', array($data, $result)); |
|
367 | + return $result; |
|
368 | + } |
|
369 | + |
|
370 | + /** |
|
371 | + * Delete a row from the table by the primary value |
|
372 | + */ |
|
373 | + public function delete($id) |
|
374 | + { |
|
375 | + $this->trigger('before_delete', $id); |
|
376 | + $this->_database->where($this->primary_key, $id); |
|
377 | + if ($this->soft_delete) |
|
378 | + { |
|
379 | + $result = $this->_database->from($this->_table)->update(array( $this->soft_delete_key => TRUE )); |
|
380 | + } |
|
381 | + else |
|
382 | + { |
|
383 | + $result = $this->_database->from($this->_table)->delete(); |
|
384 | + } |
|
385 | + |
|
386 | + $this->trigger('after_delete', $result); |
|
387 | + return $result; |
|
388 | + } |
|
389 | + |
|
390 | + /** |
|
391 | + * Delete a row from the database table by an arbitrary WHERE clause |
|
392 | + */ |
|
393 | + public function delete_by() |
|
394 | + { |
|
395 | + $where = func_get_args(); |
|
396 | + $where = $this->trigger('before_delete', $where); |
|
397 | + $this->_set_where($where); |
|
398 | + if ($this->soft_delete) |
|
399 | + { |
|
400 | + $result = $this->_database->from($this->_table)->update(array( $this->soft_delete_key => TRUE )); |
|
401 | + } |
|
402 | + else |
|
403 | + { |
|
404 | + $result = $this->_database->from($this->_table)->delete(); |
|
405 | + } |
|
406 | + $this->trigger('after_delete', $result); |
|
407 | + return $result; |
|
408 | + } |
|
409 | + |
|
410 | + /** |
|
411 | + * Delete many rows from the database table by multiple primary values |
|
412 | + */ |
|
413 | + public function delete_many($primary_values) |
|
414 | + { |
|
415 | + $primary_values = $this->trigger('before_delete', $primary_values); |
|
416 | + $this->_database->in($this->primary_key, $primary_values); |
|
417 | + if ($this->soft_delete) |
|
418 | + { |
|
419 | + $result = $this->_database->from($this->_table)->update(array( $this->soft_delete_key => TRUE )); |
|
420 | + } |
|
421 | + else |
|
422 | + { |
|
423 | + $result = $this->_database->from($this->_table)->delete(); |
|
424 | + } |
|
425 | + $this->trigger('after_delete', $result); |
|
426 | + return $result; |
|
427 | + } |
|
428 | + |
|
429 | + |
|
430 | + /** |
|
431 | + * Truncates the table |
|
432 | + */ |
|
433 | + public function truncate() |
|
434 | + { |
|
435 | + $result = $this->_database->from($this->_table)->delete(); |
|
436 | + return $result; |
|
437 | + } |
|
438 | + |
|
439 | + /* -------------------------------------------------------------- |
|
440 | 440 | * RELATIONSHIPS |
441 | 441 | * ------------------------------------------------------------ */ |
442 | 442 | |
443 | - public function with($relationship) |
|
444 | - { |
|
445 | - $this->_with[] = $relationship; |
|
446 | - if (!in_array('relate', $this->after_get)) |
|
447 | - { |
|
448 | - $this->after_get[] = 'relate'; |
|
449 | - } |
|
450 | - return $this; |
|
451 | - } |
|
452 | - |
|
453 | - public function relate($row) |
|
454 | - { |
|
455 | - if (empty($row)) |
|
456 | - { |
|
457 | - return $row; |
|
458 | - } |
|
459 | - |
|
460 | - foreach ($this->belongs_to as $key => $value) |
|
461 | - { |
|
462 | - if (is_string($value)) |
|
463 | - { |
|
464 | - $relationship = $value; |
|
465 | - $options = array( 'primary_key' => $value . '_id', 'model' => $value . '_model' ); |
|
466 | - } |
|
467 | - else |
|
468 | - { |
|
469 | - $relationship = $key; |
|
470 | - $options = $value; |
|
471 | - } |
|
472 | - |
|
473 | - if (in_array($relationship, $this->_with)) |
|
474 | - { |
|
475 | - if(is_object($this->loaderInstance)){ |
|
476 | - $this->loaderInstance->model($options['model'], $relationship . '_model'); |
|
477 | - } |
|
478 | - else{ |
|
479 | - Loader::model($options['model'], $relationship . '_model'); |
|
480 | - } |
|
481 | - if (is_object($row)) |
|
482 | - { |
|
483 | - $row->{$relationship} = $this->{$relationship . '_model'}->get($row->{$options['primary_key']}); |
|
484 | - } |
|
485 | - else |
|
486 | - { |
|
487 | - $row[$relationship] = $this->{$relationship . '_model'}->get($row[$options['primary_key']]); |
|
488 | - } |
|
489 | - } |
|
490 | - } |
|
491 | - |
|
492 | - foreach ($this->has_many as $key => $value) |
|
493 | - { |
|
494 | - if (is_string($value)) |
|
495 | - { |
|
496 | - $relationship = $value; |
|
497 | - $options = array( 'primary_key' => $this->_table . '_id', 'model' => $value . '_model' ); |
|
498 | - } |
|
499 | - else |
|
500 | - { |
|
501 | - $relationship = $key; |
|
502 | - $options = $value; |
|
503 | - } |
|
504 | - |
|
505 | - if (in_array($relationship, $this->_with)) |
|
506 | - { |
|
507 | - if(is_object($this->loaderInstance)){ |
|
508 | - $this->loaderInstance->model($options['model'], $relationship . '_model'); |
|
509 | - } |
|
510 | - else{ |
|
511 | - Loader::model($options['model'], $relationship . '_model'); |
|
512 | - } |
|
513 | - if (is_object($row)) |
|
514 | - { |
|
515 | - $row->{$relationship} = $this->{$relationship . '_model'}->get_many_by($options['primary_key'], $row->{$this->primary_key}); |
|
516 | - } |
|
517 | - else |
|
518 | - { |
|
519 | - $row[$relationship] = $this->{$relationship . '_model'}->get_many_by($options['primary_key'], $row[$this->primary_key]); |
|
520 | - } |
|
521 | - } |
|
522 | - } |
|
523 | - return $row; |
|
524 | - } |
|
525 | - |
|
526 | - /* -------------------------------------------------------------- |
|
443 | + public function with($relationship) |
|
444 | + { |
|
445 | + $this->_with[] = $relationship; |
|
446 | + if (!in_array('relate', $this->after_get)) |
|
447 | + { |
|
448 | + $this->after_get[] = 'relate'; |
|
449 | + } |
|
450 | + return $this; |
|
451 | + } |
|
452 | + |
|
453 | + public function relate($row) |
|
454 | + { |
|
455 | + if (empty($row)) |
|
456 | + { |
|
457 | + return $row; |
|
458 | + } |
|
459 | + |
|
460 | + foreach ($this->belongs_to as $key => $value) |
|
461 | + { |
|
462 | + if (is_string($value)) |
|
463 | + { |
|
464 | + $relationship = $value; |
|
465 | + $options = array( 'primary_key' => $value . '_id', 'model' => $value . '_model' ); |
|
466 | + } |
|
467 | + else |
|
468 | + { |
|
469 | + $relationship = $key; |
|
470 | + $options = $value; |
|
471 | + } |
|
472 | + |
|
473 | + if (in_array($relationship, $this->_with)) |
|
474 | + { |
|
475 | + if(is_object($this->loaderInstance)){ |
|
476 | + $this->loaderInstance->model($options['model'], $relationship . '_model'); |
|
477 | + } |
|
478 | + else{ |
|
479 | + Loader::model($options['model'], $relationship . '_model'); |
|
480 | + } |
|
481 | + if (is_object($row)) |
|
482 | + { |
|
483 | + $row->{$relationship} = $this->{$relationship . '_model'}->get($row->{$options['primary_key']}); |
|
484 | + } |
|
485 | + else |
|
486 | + { |
|
487 | + $row[$relationship] = $this->{$relationship . '_model'}->get($row[$options['primary_key']]); |
|
488 | + } |
|
489 | + } |
|
490 | + } |
|
491 | + |
|
492 | + foreach ($this->has_many as $key => $value) |
|
493 | + { |
|
494 | + if (is_string($value)) |
|
495 | + { |
|
496 | + $relationship = $value; |
|
497 | + $options = array( 'primary_key' => $this->_table . '_id', 'model' => $value . '_model' ); |
|
498 | + } |
|
499 | + else |
|
500 | + { |
|
501 | + $relationship = $key; |
|
502 | + $options = $value; |
|
503 | + } |
|
504 | + |
|
505 | + if (in_array($relationship, $this->_with)) |
|
506 | + { |
|
507 | + if(is_object($this->loaderInstance)){ |
|
508 | + $this->loaderInstance->model($options['model'], $relationship . '_model'); |
|
509 | + } |
|
510 | + else{ |
|
511 | + Loader::model($options['model'], $relationship . '_model'); |
|
512 | + } |
|
513 | + if (is_object($row)) |
|
514 | + { |
|
515 | + $row->{$relationship} = $this->{$relationship . '_model'}->get_many_by($options['primary_key'], $row->{$this->primary_key}); |
|
516 | + } |
|
517 | + else |
|
518 | + { |
|
519 | + $row[$relationship] = $this->{$relationship . '_model'}->get_many_by($options['primary_key'], $row[$this->primary_key]); |
|
520 | + } |
|
521 | + } |
|
522 | + } |
|
523 | + return $row; |
|
524 | + } |
|
525 | + |
|
526 | + /* -------------------------------------------------------------- |
|
527 | 527 | * UTILITY METHODS |
528 | 528 | * ------------------------------------------------------------ */ |
529 | 529 | |
530 | - /** |
|
531 | - * Retrieve and generate a form_dropdown friendly array |
|
532 | - */ |
|
533 | - public function dropdown() |
|
534 | - { |
|
535 | - $args = func_get_args(); |
|
536 | - if(count($args) == 2) |
|
537 | - { |
|
538 | - list($key, $value) = $args; |
|
539 | - } |
|
540 | - else |
|
541 | - { |
|
542 | - $key = $this->primary_key; |
|
543 | - $value = $args[0]; |
|
544 | - } |
|
545 | - $this->trigger('before_dropdown', array( $key, $value )); |
|
546 | - if ($this->soft_delete && $this->_temporary_with_deleted !== TRUE) |
|
547 | - { |
|
548 | - $this->_database->where($this->soft_delete_key, FALSE); |
|
549 | - } |
|
550 | - $result = $this->_database->select(array($key, $value)) |
|
551 | - ->from($this->_table) |
|
552 | - ->getAll(); |
|
553 | - $options = array(); |
|
554 | - foreach ($result as $row) |
|
555 | - { |
|
556 | - $options[$row->{$key}] = $row->{$value}; |
|
557 | - } |
|
558 | - $options = $this->trigger('after_dropdown', $options); |
|
559 | - return $options; |
|
560 | - } |
|
561 | - |
|
562 | - /** |
|
563 | - * Fetch a count of rows based on an arbitrary WHERE call. |
|
564 | - */ |
|
565 | - public function count_by() |
|
566 | - { |
|
567 | - if ($this->soft_delete && $this->_temporary_with_deleted !== TRUE) |
|
568 | - { |
|
569 | - $this->_database->where($this->soft_delete_key, (bool)$this->_temporary_only_deleted); |
|
570 | - } |
|
571 | - $where = func_get_args(); |
|
572 | - $this->_set_where($where); |
|
573 | - $this->_database->from($this->_table)->getAll(); |
|
574 | - return $this->_database->numRows(); |
|
575 | - } |
|
576 | - |
|
577 | - /** |
|
578 | - * Fetch a total count of rows, disregarding any previous conditions |
|
579 | - */ |
|
580 | - public function count_all() |
|
581 | - { |
|
582 | - if ($this->soft_delete && $this->_temporary_with_deleted !== TRUE) |
|
583 | - { |
|
584 | - $this->_database->where($this->soft_delete_key, (bool)$this->_temporary_only_deleted); |
|
585 | - } |
|
586 | - $this->_database->from($this->_table)->getAll(); |
|
587 | - return $this->_database->numRows(); |
|
588 | - } |
|
530 | + /** |
|
531 | + * Retrieve and generate a form_dropdown friendly array |
|
532 | + */ |
|
533 | + public function dropdown() |
|
534 | + { |
|
535 | + $args = func_get_args(); |
|
536 | + if(count($args) == 2) |
|
537 | + { |
|
538 | + list($key, $value) = $args; |
|
539 | + } |
|
540 | + else |
|
541 | + { |
|
542 | + $key = $this->primary_key; |
|
543 | + $value = $args[0]; |
|
544 | + } |
|
545 | + $this->trigger('before_dropdown', array( $key, $value )); |
|
546 | + if ($this->soft_delete && $this->_temporary_with_deleted !== TRUE) |
|
547 | + { |
|
548 | + $this->_database->where($this->soft_delete_key, FALSE); |
|
549 | + } |
|
550 | + $result = $this->_database->select(array($key, $value)) |
|
551 | + ->from($this->_table) |
|
552 | + ->getAll(); |
|
553 | + $options = array(); |
|
554 | + foreach ($result as $row) |
|
555 | + { |
|
556 | + $options[$row->{$key}] = $row->{$value}; |
|
557 | + } |
|
558 | + $options = $this->trigger('after_dropdown', $options); |
|
559 | + return $options; |
|
560 | + } |
|
561 | + |
|
562 | + /** |
|
563 | + * Fetch a count of rows based on an arbitrary WHERE call. |
|
564 | + */ |
|
565 | + public function count_by() |
|
566 | + { |
|
567 | + if ($this->soft_delete && $this->_temporary_with_deleted !== TRUE) |
|
568 | + { |
|
569 | + $this->_database->where($this->soft_delete_key, (bool)$this->_temporary_only_deleted); |
|
570 | + } |
|
571 | + $where = func_get_args(); |
|
572 | + $this->_set_where($where); |
|
573 | + $this->_database->from($this->_table)->getAll(); |
|
574 | + return $this->_database->numRows(); |
|
575 | + } |
|
576 | + |
|
577 | + /** |
|
578 | + * Fetch a total count of rows, disregarding any previous conditions |
|
579 | + */ |
|
580 | + public function count_all() |
|
581 | + { |
|
582 | + if ($this->soft_delete && $this->_temporary_with_deleted !== TRUE) |
|
583 | + { |
|
584 | + $this->_database->where($this->soft_delete_key, (bool)$this->_temporary_only_deleted); |
|
585 | + } |
|
586 | + $this->_database->from($this->_table)->getAll(); |
|
587 | + return $this->_database->numRows(); |
|
588 | + } |
|
589 | 589 | |
590 | 590 | /** |
591 | - * Enabled cache temporary |
|
592 | - */ |
|
591 | + * Enabled cache temporary |
|
592 | + */ |
|
593 | 593 | public function cached($ttl = 0){ |
594 | 594 | if($ttl > 0){ |
595 | 595 | $this->_database = $this->_database->cached($ttl); |
@@ -597,390 +597,390 @@ discard block |
||
597 | 597 | return $this; |
598 | 598 | } |
599 | 599 | |
600 | - /** |
|
601 | - * Tell the class to skip the insert validation |
|
602 | - */ |
|
603 | - public function skip_validation() |
|
604 | - { |
|
605 | - $this->skip_validation = TRUE; |
|
606 | - return $this; |
|
607 | - } |
|
608 | - |
|
609 | - /** |
|
610 | - * Get the skip validation status |
|
611 | - */ |
|
612 | - public function get_skip_validation() |
|
613 | - { |
|
614 | - return $this->skip_validation; |
|
615 | - } |
|
616 | - |
|
617 | - /** |
|
618 | - * Return the next auto increment of the table. Only tested on MySQL. |
|
619 | - */ |
|
620 | - public function get_next_id() |
|
621 | - { |
|
622 | - return (int) $this->_database->select('AUTO_INCREMENT') |
|
623 | - ->from('information_schema.TABLES') |
|
624 | - ->where('TABLE_NAME', $this->_table) |
|
625 | - ->where('TABLE_SCHEMA', $this->_database->getDatabaseName())->get()->AUTO_INCREMENT; |
|
626 | - } |
|
627 | - |
|
628 | - /** |
|
629 | - * Getter for the table name |
|
630 | - */ |
|
631 | - public function table() |
|
632 | - { |
|
633 | - return $this->_table; |
|
634 | - } |
|
635 | - |
|
636 | - /* -------------------------------------------------------------- |
|
600 | + /** |
|
601 | + * Tell the class to skip the insert validation |
|
602 | + */ |
|
603 | + public function skip_validation() |
|
604 | + { |
|
605 | + $this->skip_validation = TRUE; |
|
606 | + return $this; |
|
607 | + } |
|
608 | + |
|
609 | + /** |
|
610 | + * Get the skip validation status |
|
611 | + */ |
|
612 | + public function get_skip_validation() |
|
613 | + { |
|
614 | + return $this->skip_validation; |
|
615 | + } |
|
616 | + |
|
617 | + /** |
|
618 | + * Return the next auto increment of the table. Only tested on MySQL. |
|
619 | + */ |
|
620 | + public function get_next_id() |
|
621 | + { |
|
622 | + return (int) $this->_database->select('AUTO_INCREMENT') |
|
623 | + ->from('information_schema.TABLES') |
|
624 | + ->where('TABLE_NAME', $this->_table) |
|
625 | + ->where('TABLE_SCHEMA', $this->_database->getDatabaseName())->get()->AUTO_INCREMENT; |
|
626 | + } |
|
627 | + |
|
628 | + /** |
|
629 | + * Getter for the table name |
|
630 | + */ |
|
631 | + public function table() |
|
632 | + { |
|
633 | + return $this->_table; |
|
634 | + } |
|
635 | + |
|
636 | + /* -------------------------------------------------------------- |
|
637 | 637 | * GLOBAL SCOPES |
638 | 638 | * ------------------------------------------------------------ */ |
639 | 639 | |
640 | - /** |
|
641 | - * Return the next call as an array rather than an object |
|
642 | - */ |
|
643 | - public function as_array() |
|
644 | - { |
|
645 | - $this->_temporary_return_type = 'array'; |
|
646 | - return $this; |
|
647 | - } |
|
648 | - |
|
649 | - /** |
|
650 | - * Return the next call as an object rather than an array |
|
651 | - */ |
|
652 | - public function as_object() |
|
653 | - { |
|
654 | - $this->_temporary_return_type = 'object'; |
|
655 | - return $this; |
|
656 | - } |
|
657 | - |
|
658 | - /** |
|
659 | - * Don't care about soft deleted rows on the next call |
|
660 | - */ |
|
661 | - public function with_deleted() |
|
662 | - { |
|
663 | - $this->_temporary_with_deleted = TRUE; |
|
664 | - return $this; |
|
665 | - } |
|
666 | - |
|
667 | - /** |
|
668 | - * Only get deleted rows on the next call |
|
669 | - */ |
|
670 | - public function only_deleted() |
|
671 | - { |
|
672 | - $this->_temporary_only_deleted = TRUE; |
|
673 | - return $this; |
|
674 | - } |
|
675 | - |
|
676 | - /* -------------------------------------------------------------- |
|
640 | + /** |
|
641 | + * Return the next call as an array rather than an object |
|
642 | + */ |
|
643 | + public function as_array() |
|
644 | + { |
|
645 | + $this->_temporary_return_type = 'array'; |
|
646 | + return $this; |
|
647 | + } |
|
648 | + |
|
649 | + /** |
|
650 | + * Return the next call as an object rather than an array |
|
651 | + */ |
|
652 | + public function as_object() |
|
653 | + { |
|
654 | + $this->_temporary_return_type = 'object'; |
|
655 | + return $this; |
|
656 | + } |
|
657 | + |
|
658 | + /** |
|
659 | + * Don't care about soft deleted rows on the next call |
|
660 | + */ |
|
661 | + public function with_deleted() |
|
662 | + { |
|
663 | + $this->_temporary_with_deleted = TRUE; |
|
664 | + return $this; |
|
665 | + } |
|
666 | + |
|
667 | + /** |
|
668 | + * Only get deleted rows on the next call |
|
669 | + */ |
|
670 | + public function only_deleted() |
|
671 | + { |
|
672 | + $this->_temporary_only_deleted = TRUE; |
|
673 | + return $this; |
|
674 | + } |
|
675 | + |
|
676 | + /* -------------------------------------------------------------- |
|
677 | 677 | * OBSERVERS |
678 | 678 | * ------------------------------------------------------------ */ |
679 | 679 | |
680 | - /** |
|
681 | - * MySQL DATETIME created_at and updated_at |
|
682 | - */ |
|
683 | - public function created_at($row) |
|
684 | - { |
|
685 | - if (is_object($row)) |
|
686 | - { |
|
687 | - $row->created_at = date('Y-m-d H:i:s'); |
|
688 | - } |
|
689 | - else |
|
690 | - { |
|
691 | - $row['created_at'] = date('Y-m-d H:i:s'); |
|
692 | - } |
|
693 | - |
|
694 | - return $row; |
|
695 | - } |
|
696 | - |
|
697 | - public function updated_at($row) |
|
698 | - { |
|
699 | - if (is_object($row)) |
|
700 | - { |
|
701 | - $row->updated_at = date('Y-m-d H:i:s'); |
|
702 | - } |
|
703 | - else |
|
704 | - { |
|
705 | - $row['updated_at'] = date('Y-m-d H:i:s'); |
|
706 | - } |
|
707 | - return $row; |
|
708 | - } |
|
709 | - |
|
710 | - /** |
|
711 | - * Serialises data for you automatically, allowing you to pass |
|
712 | - * through objects and let it handle the serialisation in the background |
|
713 | - */ |
|
714 | - public function serialize($row) |
|
715 | - { |
|
716 | - foreach ($this->callback_parameters as $column) |
|
717 | - { |
|
718 | - $row[$column] = serialize($row[$column]); |
|
719 | - } |
|
720 | - return $row; |
|
721 | - } |
|
722 | - |
|
723 | - public function unserialize($row) |
|
724 | - { |
|
725 | - foreach ($this->callback_parameters as $column) |
|
726 | - { |
|
727 | - if (is_array($row)) |
|
728 | - { |
|
729 | - $row[$column] = unserialize($row[$column]); |
|
730 | - } |
|
731 | - else |
|
732 | - { |
|
733 | - $row->$column = unserialize($row->$column); |
|
734 | - } |
|
735 | - } |
|
736 | - return $row; |
|
737 | - } |
|
738 | - |
|
739 | - /** |
|
740 | - * Protect attributes by removing them from $row array |
|
741 | - */ |
|
742 | - public function protect_attributes($row) |
|
743 | - { |
|
744 | - foreach ($this->protected_attributes as $attr) |
|
745 | - { |
|
746 | - if (is_object($row)) |
|
747 | - { |
|
680 | + /** |
|
681 | + * MySQL DATETIME created_at and updated_at |
|
682 | + */ |
|
683 | + public function created_at($row) |
|
684 | + { |
|
685 | + if (is_object($row)) |
|
686 | + { |
|
687 | + $row->created_at = date('Y-m-d H:i:s'); |
|
688 | + } |
|
689 | + else |
|
690 | + { |
|
691 | + $row['created_at'] = date('Y-m-d H:i:s'); |
|
692 | + } |
|
693 | + |
|
694 | + return $row; |
|
695 | + } |
|
696 | + |
|
697 | + public function updated_at($row) |
|
698 | + { |
|
699 | + if (is_object($row)) |
|
700 | + { |
|
701 | + $row->updated_at = date('Y-m-d H:i:s'); |
|
702 | + } |
|
703 | + else |
|
704 | + { |
|
705 | + $row['updated_at'] = date('Y-m-d H:i:s'); |
|
706 | + } |
|
707 | + return $row; |
|
708 | + } |
|
709 | + |
|
710 | + /** |
|
711 | + * Serialises data for you automatically, allowing you to pass |
|
712 | + * through objects and let it handle the serialisation in the background |
|
713 | + */ |
|
714 | + public function serialize($row) |
|
715 | + { |
|
716 | + foreach ($this->callback_parameters as $column) |
|
717 | + { |
|
718 | + $row[$column] = serialize($row[$column]); |
|
719 | + } |
|
720 | + return $row; |
|
721 | + } |
|
722 | + |
|
723 | + public function unserialize($row) |
|
724 | + { |
|
725 | + foreach ($this->callback_parameters as $column) |
|
726 | + { |
|
727 | + if (is_array($row)) |
|
728 | + { |
|
729 | + $row[$column] = unserialize($row[$column]); |
|
730 | + } |
|
731 | + else |
|
732 | + { |
|
733 | + $row->$column = unserialize($row->$column); |
|
734 | + } |
|
735 | + } |
|
736 | + return $row; |
|
737 | + } |
|
738 | + |
|
739 | + /** |
|
740 | + * Protect attributes by removing them from $row array |
|
741 | + */ |
|
742 | + public function protect_attributes($row) |
|
743 | + { |
|
744 | + foreach ($this->protected_attributes as $attr) |
|
745 | + { |
|
746 | + if (is_object($row)) |
|
747 | + { |
|
748 | 748 | if(isset($row->$attr)){ |
749 | 749 | unset($row->$attr); |
750 | 750 | } |
751 | - } |
|
752 | - else |
|
753 | - { |
|
751 | + } |
|
752 | + else |
|
753 | + { |
|
754 | 754 | if(isset($row[$attr])){ |
755 | 755 | unset($row[$attr]); |
756 | 756 | } |
757 | - } |
|
758 | - } |
|
759 | - return $row; |
|
760 | - } |
|
757 | + } |
|
758 | + } |
|
759 | + return $row; |
|
760 | + } |
|
761 | 761 | |
762 | 762 | /** |
763 | - * Return the database instance |
|
764 | - * @return Database the database instance |
|
765 | - */ |
|
766 | - public function getDatabaseInstance(){ |
|
767 | - return $this->_database; |
|
768 | - } |
|
769 | - |
|
770 | - /** |
|
771 | - * set the Database instance for future use |
|
772 | - * @param Database $db the database object |
|
773 | - */ |
|
774 | - public function setDatabaseInstance($db){ |
|
775 | - $this->_database = $db; |
|
776 | - if($this->dbCacheTime > 0){ |
|
777 | - $this->_database->setCache($this->dbCacheTime); |
|
778 | - } |
|
779 | - return $this; |
|
780 | - } |
|
781 | - |
|
782 | - /** |
|
783 | - * Return the loader instance |
|
784 | - * @return Loader the loader instance |
|
785 | - */ |
|
786 | - public function getLoader(){ |
|
787 | - return $this->loaderInstance; |
|
788 | - } |
|
789 | - |
|
790 | - /** |
|
791 | - * set the loader instance for future use |
|
792 | - * @param Loader $loader the loader object |
|
793 | - */ |
|
794 | - public function setLoader($loader){ |
|
795 | - $this->loaderInstance = $loader; |
|
796 | - return $this; |
|
797 | - } |
|
798 | - |
|
799 | - /** |
|
800 | - * Return the FormValidation instance |
|
801 | - * @return FormValidation the form validation instance |
|
802 | - */ |
|
803 | - public function getFormValidation(){ |
|
804 | - return $this->formValidationInstance; |
|
805 | - } |
|
806 | - |
|
807 | - /** |
|
808 | - * set the form validation instance for future use |
|
809 | - * @param FormValidation $fv the form validation object |
|
810 | - */ |
|
811 | - public function setFormValidation($fv){ |
|
812 | - $this->formValidationInstance = $fv; |
|
813 | - return $this; |
|
814 | - } |
|
815 | - |
|
816 | - /* -------------------------------------------------------------- |
|
763 | + * Return the database instance |
|
764 | + * @return Database the database instance |
|
765 | + */ |
|
766 | + public function getDatabaseInstance(){ |
|
767 | + return $this->_database; |
|
768 | + } |
|
769 | + |
|
770 | + /** |
|
771 | + * set the Database instance for future use |
|
772 | + * @param Database $db the database object |
|
773 | + */ |
|
774 | + public function setDatabaseInstance($db){ |
|
775 | + $this->_database = $db; |
|
776 | + if($this->dbCacheTime > 0){ |
|
777 | + $this->_database->setCache($this->dbCacheTime); |
|
778 | + } |
|
779 | + return $this; |
|
780 | + } |
|
781 | + |
|
782 | + /** |
|
783 | + * Return the loader instance |
|
784 | + * @return Loader the loader instance |
|
785 | + */ |
|
786 | + public function getLoader(){ |
|
787 | + return $this->loaderInstance; |
|
788 | + } |
|
789 | + |
|
790 | + /** |
|
791 | + * set the loader instance for future use |
|
792 | + * @param Loader $loader the loader object |
|
793 | + */ |
|
794 | + public function setLoader($loader){ |
|
795 | + $this->loaderInstance = $loader; |
|
796 | + return $this; |
|
797 | + } |
|
798 | + |
|
799 | + /** |
|
800 | + * Return the FormValidation instance |
|
801 | + * @return FormValidation the form validation instance |
|
802 | + */ |
|
803 | + public function getFormValidation(){ |
|
804 | + return $this->formValidationInstance; |
|
805 | + } |
|
806 | + |
|
807 | + /** |
|
808 | + * set the form validation instance for future use |
|
809 | + * @param FormValidation $fv the form validation object |
|
810 | + */ |
|
811 | + public function setFormValidation($fv){ |
|
812 | + $this->formValidationInstance = $fv; |
|
813 | + return $this; |
|
814 | + } |
|
815 | + |
|
816 | + /* -------------------------------------------------------------- |
|
817 | 817 | * QUERY BUILDER DIRECT ACCESS METHODS |
818 | 818 | * ------------------------------------------------------------ */ |
819 | 819 | |
820 | - /** |
|
821 | - * A wrapper to $this->_database->orderBy() |
|
822 | - */ |
|
823 | - public function order_by($criteria, $order = 'ASC') |
|
824 | - { |
|
825 | - if ( is_array($criteria) ) |
|
826 | - { |
|
827 | - foreach ($criteria as $key => $value) |
|
828 | - { |
|
829 | - $this->_database->orderBy($key, $value); |
|
830 | - } |
|
831 | - } |
|
832 | - else |
|
833 | - { |
|
834 | - $this->_database->orderBy($criteria, $order); |
|
835 | - } |
|
836 | - return $this; |
|
837 | - } |
|
838 | - |
|
839 | - /** |
|
840 | - * A wrapper to $this->_database->limit() |
|
841 | - */ |
|
842 | - public function limit($offset = 0, $limit = 10) |
|
843 | - { |
|
844 | - $this->_database->limit($offset, $limit); |
|
845 | - return $this; |
|
846 | - } |
|
847 | - |
|
848 | - /* -------------------------------------------------------------- |
|
820 | + /** |
|
821 | + * A wrapper to $this->_database->orderBy() |
|
822 | + */ |
|
823 | + public function order_by($criteria, $order = 'ASC') |
|
824 | + { |
|
825 | + if ( is_array($criteria) ) |
|
826 | + { |
|
827 | + foreach ($criteria as $key => $value) |
|
828 | + { |
|
829 | + $this->_database->orderBy($key, $value); |
|
830 | + } |
|
831 | + } |
|
832 | + else |
|
833 | + { |
|
834 | + $this->_database->orderBy($criteria, $order); |
|
835 | + } |
|
836 | + return $this; |
|
837 | + } |
|
838 | + |
|
839 | + /** |
|
840 | + * A wrapper to $this->_database->limit() |
|
841 | + */ |
|
842 | + public function limit($offset = 0, $limit = 10) |
|
843 | + { |
|
844 | + $this->_database->limit($offset, $limit); |
|
845 | + return $this; |
|
846 | + } |
|
847 | + |
|
848 | + /* -------------------------------------------------------------- |
|
849 | 849 | * INTERNAL METHODS |
850 | 850 | * ------------------------------------------------------------ */ |
851 | 851 | |
852 | - /** |
|
853 | - * Trigger an event and call its observers. Pass through the event name |
|
854 | - * (which looks for an instance variable $this->event_name), an array of |
|
855 | - * parameters to pass through and an optional 'last in interation' boolean |
|
856 | - */ |
|
857 | - protected function trigger($event, $data = FALSE, $last = TRUE) |
|
858 | - { |
|
859 | - if (isset($this->$event) && is_array($this->$event)) |
|
860 | - { |
|
861 | - foreach ($this->$event as $method) |
|
862 | - { |
|
863 | - if (strpos($method, '(')) |
|
864 | - { |
|
865 | - preg_match('/([a-zA-Z0-9\_\-]+)(\(([a-zA-Z0-9\_\-\., ]+)\))?/', $method, $matches); |
|
866 | - |
|
867 | - $method = $matches[1]; |
|
868 | - $this->callback_parameters = explode(',', $matches[3]); |
|
869 | - } |
|
870 | - $data = call_user_func_array(array($this, $method), array($data, $last)); |
|
871 | - } |
|
872 | - } |
|
873 | - return $data; |
|
874 | - } |
|
875 | - |
|
876 | - /** |
|
877 | - * Run validation on the passed data |
|
878 | - */ |
|
879 | - protected function validate(array $data) |
|
880 | - { |
|
881 | - if($this->skip_validation) |
|
882 | - { |
|
883 | - return $data; |
|
884 | - } |
|
885 | - if(!empty($this->validate)) |
|
886 | - { |
|
887 | - $fv = null; |
|
888 | - if(is_object($this->formValidationInstance)){ |
|
889 | - $fv = $this->formValidationInstance; |
|
890 | - } |
|
891 | - else{ |
|
892 | - Loader::library('FormValidation'); |
|
893 | - $fv = $this->formvalidation; |
|
894 | - $this->setFormValidation($fv); |
|
895 | - } |
|
896 | - if(is_array($this->validate)) |
|
897 | - { |
|
898 | - $fv->setData($data); |
|
899 | - $fv->setRules($this->validate); |
|
900 | - |
|
901 | - if ($fv->run()) |
|
902 | - { |
|
903 | - return $data; |
|
904 | - } |
|
905 | - else |
|
906 | - { |
|
907 | - return FALSE; |
|
908 | - } |
|
909 | - } |
|
910 | - else { |
|
911 | - return $data; |
|
912 | - } |
|
913 | - } |
|
914 | - else |
|
915 | - { |
|
916 | - return $data; |
|
917 | - } |
|
918 | - } |
|
919 | - |
|
920 | - |
|
921 | - /** |
|
922 | - * Set WHERE parameters, cleverly |
|
923 | - */ |
|
924 | - protected function _set_where($params) |
|
925 | - { |
|
926 | - if (count($params) == 1 && is_array($params[0])) |
|
927 | - { |
|
928 | - foreach ($params[0] as $field => $filter) |
|
929 | - { |
|
930 | - if (is_array($filter)) |
|
931 | - { |
|
932 | - $this->_database->in($field, $filter); |
|
933 | - } |
|
934 | - else |
|
935 | - { |
|
936 | - if (is_int($field)) |
|
937 | - { |
|
938 | - $this->_database->where($filter); |
|
939 | - } |
|
940 | - else |
|
941 | - { |
|
942 | - $this->_database->where($field, $filter); |
|
943 | - } |
|
944 | - } |
|
945 | - } |
|
946 | - } |
|
947 | - else if (count($params) == 1) |
|
948 | - { |
|
949 | - $this->_database->where($params[0]); |
|
950 | - } |
|
951 | - else if(count($params) == 2) |
|
952 | - { |
|
953 | - if (is_array($params[1])) |
|
954 | - { |
|
955 | - $this->_database->in($params[0], $params[1]); |
|
956 | - } |
|
957 | - else |
|
958 | - { |
|
959 | - $this->_database->where($params[0], $params[1]); |
|
960 | - } |
|
961 | - } |
|
962 | - else if(count($params) == 3) |
|
963 | - { |
|
964 | - $this->_database->where($params[0], $params[1], $params[2]); |
|
965 | - } |
|
966 | - else |
|
967 | - { |
|
968 | - if (is_array($params[1])) |
|
969 | - { |
|
970 | - $this->_database->in($params[0], $params[1]); |
|
971 | - } |
|
972 | - else |
|
973 | - { |
|
974 | - $this->_database->where($params[0], $params[1]); |
|
975 | - } |
|
976 | - } |
|
977 | - } |
|
978 | - |
|
979 | - /** |
|
852 | + /** |
|
853 | + * Trigger an event and call its observers. Pass through the event name |
|
854 | + * (which looks for an instance variable $this->event_name), an array of |
|
855 | + * parameters to pass through and an optional 'last in interation' boolean |
|
856 | + */ |
|
857 | + protected function trigger($event, $data = FALSE, $last = TRUE) |
|
858 | + { |
|
859 | + if (isset($this->$event) && is_array($this->$event)) |
|
860 | + { |
|
861 | + foreach ($this->$event as $method) |
|
862 | + { |
|
863 | + if (strpos($method, '(')) |
|
864 | + { |
|
865 | + preg_match('/([a-zA-Z0-9\_\-]+)(\(([a-zA-Z0-9\_\-\., ]+)\))?/', $method, $matches); |
|
866 | + |
|
867 | + $method = $matches[1]; |
|
868 | + $this->callback_parameters = explode(',', $matches[3]); |
|
869 | + } |
|
870 | + $data = call_user_func_array(array($this, $method), array($data, $last)); |
|
871 | + } |
|
872 | + } |
|
873 | + return $data; |
|
874 | + } |
|
875 | + |
|
876 | + /** |
|
877 | + * Run validation on the passed data |
|
878 | + */ |
|
879 | + protected function validate(array $data) |
|
880 | + { |
|
881 | + if($this->skip_validation) |
|
882 | + { |
|
883 | + return $data; |
|
884 | + } |
|
885 | + if(!empty($this->validate)) |
|
886 | + { |
|
887 | + $fv = null; |
|
888 | + if(is_object($this->formValidationInstance)){ |
|
889 | + $fv = $this->formValidationInstance; |
|
890 | + } |
|
891 | + else{ |
|
892 | + Loader::library('FormValidation'); |
|
893 | + $fv = $this->formvalidation; |
|
894 | + $this->setFormValidation($fv); |
|
895 | + } |
|
896 | + if(is_array($this->validate)) |
|
897 | + { |
|
898 | + $fv->setData($data); |
|
899 | + $fv->setRules($this->validate); |
|
900 | + |
|
901 | + if ($fv->run()) |
|
902 | + { |
|
903 | + return $data; |
|
904 | + } |
|
905 | + else |
|
906 | + { |
|
907 | + return FALSE; |
|
908 | + } |
|
909 | + } |
|
910 | + else { |
|
911 | + return $data; |
|
912 | + } |
|
913 | + } |
|
914 | + else |
|
915 | + { |
|
916 | + return $data; |
|
917 | + } |
|
918 | + } |
|
919 | + |
|
920 | + |
|
921 | + /** |
|
922 | + * Set WHERE parameters, cleverly |
|
923 | + */ |
|
924 | + protected function _set_where($params) |
|
925 | + { |
|
926 | + if (count($params) == 1 && is_array($params[0])) |
|
927 | + { |
|
928 | + foreach ($params[0] as $field => $filter) |
|
929 | + { |
|
930 | + if (is_array($filter)) |
|
931 | + { |
|
932 | + $this->_database->in($field, $filter); |
|
933 | + } |
|
934 | + else |
|
935 | + { |
|
936 | + if (is_int($field)) |
|
937 | + { |
|
938 | + $this->_database->where($filter); |
|
939 | + } |
|
940 | + else |
|
941 | + { |
|
942 | + $this->_database->where($field, $filter); |
|
943 | + } |
|
944 | + } |
|
945 | + } |
|
946 | + } |
|
947 | + else if (count($params) == 1) |
|
948 | + { |
|
949 | + $this->_database->where($params[0]); |
|
950 | + } |
|
951 | + else if(count($params) == 2) |
|
952 | + { |
|
953 | + if (is_array($params[1])) |
|
954 | + { |
|
955 | + $this->_database->in($params[0], $params[1]); |
|
956 | + } |
|
957 | + else |
|
958 | + { |
|
959 | + $this->_database->where($params[0], $params[1]); |
|
960 | + } |
|
961 | + } |
|
962 | + else if(count($params) == 3) |
|
963 | + { |
|
964 | + $this->_database->where($params[0], $params[1], $params[2]); |
|
965 | + } |
|
966 | + else |
|
967 | + { |
|
968 | + if (is_array($params[1])) |
|
969 | + { |
|
970 | + $this->_database->in($params[0], $params[1]); |
|
971 | + } |
|
972 | + else |
|
973 | + { |
|
974 | + $this->_database->where($params[0], $params[1]); |
|
975 | + } |
|
976 | + } |
|
977 | + } |
|
978 | + |
|
979 | + /** |
|
980 | 980 | Shortcut to controller |
981 | - */ |
|
982 | - public function __get($key){ |
|
983 | - return get_instance()->{$key}; |
|
984 | - } |
|
981 | + */ |
|
982 | + public function __get($key){ |
|
983 | + return get_instance()->{$key}; |
|
984 | + } |
|
985 | 985 | |
986 | - } |
|
986 | + } |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | * @copyright Copyright (c) 2012, Jamie Rumbelow <http://jamierumbelow.net> |
34 | 34 | */ |
35 | 35 | |
36 | - class Model{ |
|
36 | + class Model { |
|
37 | 37 | |
38 | 38 | /* -------------------------------------------------------------- |
39 | 39 | * VARIABLES |
@@ -140,13 +140,13 @@ discard block |
||
140 | 140 | * Initialise the model, tie into the CodeIgniter superobject and |
141 | 141 | * try our best to guess the table name. |
142 | 142 | */ |
143 | - public function __construct(Database $db = null){ |
|
144 | - if(is_object($db)){ |
|
143 | + public function __construct(Database $db = null) { |
|
144 | + if (is_object($db)) { |
|
145 | 145 | $this->setDatabaseInstance($db); |
146 | 146 | } |
147 | - else{ |
|
147 | + else { |
|
148 | 148 | $obj = & get_instance(); |
149 | - if(isset($obj->database) && is_object($obj->database)){ |
|
149 | + if (isset($obj->database) && is_object($obj->database)) { |
|
150 | 150 | /** |
151 | 151 | * NOTE: Need use "clone" because some Model need have the personal instance of the database library |
152 | 152 | * to prevent duplication |
@@ -182,13 +182,13 @@ discard block |
||
182 | 182 | |
183 | 183 | if ($this->soft_delete && $this->_temporary_with_deleted !== TRUE) |
184 | 184 | { |
185 | - $this->_database->where($this->soft_delete_key, (bool)$this->_temporary_only_deleted); |
|
185 | + $this->_database->where($this->soft_delete_key, (bool) $this->_temporary_only_deleted); |
|
186 | 186 | } |
187 | 187 | |
188 | 188 | $this->_set_where($where); |
189 | 189 | |
190 | 190 | $this->trigger('before_get'); |
191 | - $type = $this->_temporary_return_type == 'array' ? 'array':false; |
|
191 | + $type = $this->_temporary_return_type == 'array' ? 'array' : false; |
|
192 | 192 | $row = $this->_database->from($this->_table)->get($type); |
193 | 193 | $this->_temporary_return_type = $this->return_type; |
194 | 194 | $row = $this->trigger('after_get', $row); |
@@ -224,9 +224,9 @@ discard block |
||
224 | 224 | $this->trigger('before_get'); |
225 | 225 | if ($this->soft_delete && $this->_temporary_with_deleted !== TRUE) |
226 | 226 | { |
227 | - $this->_database->where($this->soft_delete_key, (bool)$this->_temporary_only_deleted); |
|
227 | + $this->_database->where($this->soft_delete_key, (bool) $this->_temporary_only_deleted); |
|
228 | 228 | } |
229 | - $type = $this->_temporary_return_type == 'array' ? 'array':false; |
|
229 | + $type = $this->_temporary_return_type == 'array' ? 'array' : false; |
|
230 | 230 | $result = $this->_database->from($this->_table)->getAll($type); |
231 | 231 | $this->_temporary_return_type = $this->return_type; |
232 | 232 | |
@@ -332,13 +332,13 @@ discard block |
||
332 | 332 | { |
333 | 333 | $args = func_get_args(); |
334 | 334 | $data = array(); |
335 | - if(count($args) == 2){ |
|
336 | - if(is_array($args[1])){ |
|
335 | + if (count($args) == 2) { |
|
336 | + if (is_array($args[1])) { |
|
337 | 337 | $data = array_pop($args); |
338 | 338 | } |
339 | 339 | } |
340 | - else if(count($args) == 3){ |
|
341 | - if(is_array($args[2])){ |
|
340 | + else if (count($args) == 3) { |
|
341 | + if (is_array($args[2])) { |
|
342 | 342 | $data = array_pop($args); |
343 | 343 | } |
344 | 344 | } |
@@ -376,7 +376,7 @@ discard block |
||
376 | 376 | $this->_database->where($this->primary_key, $id); |
377 | 377 | if ($this->soft_delete) |
378 | 378 | { |
379 | - $result = $this->_database->from($this->_table)->update(array( $this->soft_delete_key => TRUE )); |
|
379 | + $result = $this->_database->from($this->_table)->update(array($this->soft_delete_key => TRUE)); |
|
380 | 380 | } |
381 | 381 | else |
382 | 382 | { |
@@ -397,7 +397,7 @@ discard block |
||
397 | 397 | $this->_set_where($where); |
398 | 398 | if ($this->soft_delete) |
399 | 399 | { |
400 | - $result = $this->_database->from($this->_table)->update(array( $this->soft_delete_key => TRUE )); |
|
400 | + $result = $this->_database->from($this->_table)->update(array($this->soft_delete_key => TRUE)); |
|
401 | 401 | } |
402 | 402 | else |
403 | 403 | { |
@@ -416,7 +416,7 @@ discard block |
||
416 | 416 | $this->_database->in($this->primary_key, $primary_values); |
417 | 417 | if ($this->soft_delete) |
418 | 418 | { |
419 | - $result = $this->_database->from($this->_table)->update(array( $this->soft_delete_key => TRUE )); |
|
419 | + $result = $this->_database->from($this->_table)->update(array($this->soft_delete_key => TRUE)); |
|
420 | 420 | } |
421 | 421 | else |
422 | 422 | { |
@@ -462,7 +462,7 @@ discard block |
||
462 | 462 | if (is_string($value)) |
463 | 463 | { |
464 | 464 | $relationship = $value; |
465 | - $options = array( 'primary_key' => $value . '_id', 'model' => $value . '_model' ); |
|
465 | + $options = array('primary_key' => $value . '_id', 'model' => $value . '_model'); |
|
466 | 466 | } |
467 | 467 | else |
468 | 468 | { |
@@ -472,10 +472,10 @@ discard block |
||
472 | 472 | |
473 | 473 | if (in_array($relationship, $this->_with)) |
474 | 474 | { |
475 | - if(is_object($this->loaderInstance)){ |
|
475 | + if (is_object($this->loaderInstance)) { |
|
476 | 476 | $this->loaderInstance->model($options['model'], $relationship . '_model'); |
477 | 477 | } |
478 | - else{ |
|
478 | + else { |
|
479 | 479 | Loader::model($options['model'], $relationship . '_model'); |
480 | 480 | } |
481 | 481 | if (is_object($row)) |
@@ -494,7 +494,7 @@ discard block |
||
494 | 494 | if (is_string($value)) |
495 | 495 | { |
496 | 496 | $relationship = $value; |
497 | - $options = array( 'primary_key' => $this->_table . '_id', 'model' => $value . '_model' ); |
|
497 | + $options = array('primary_key' => $this->_table . '_id', 'model' => $value . '_model'); |
|
498 | 498 | } |
499 | 499 | else |
500 | 500 | { |
@@ -504,10 +504,10 @@ discard block |
||
504 | 504 | |
505 | 505 | if (in_array($relationship, $this->_with)) |
506 | 506 | { |
507 | - if(is_object($this->loaderInstance)){ |
|
507 | + if (is_object($this->loaderInstance)) { |
|
508 | 508 | $this->loaderInstance->model($options['model'], $relationship . '_model'); |
509 | 509 | } |
510 | - else{ |
|
510 | + else { |
|
511 | 511 | Loader::model($options['model'], $relationship . '_model'); |
512 | 512 | } |
513 | 513 | if (is_object($row)) |
@@ -533,7 +533,7 @@ discard block |
||
533 | 533 | public function dropdown() |
534 | 534 | { |
535 | 535 | $args = func_get_args(); |
536 | - if(count($args) == 2) |
|
536 | + if (count($args) == 2) |
|
537 | 537 | { |
538 | 538 | list($key, $value) = $args; |
539 | 539 | } |
@@ -542,7 +542,7 @@ discard block |
||
542 | 542 | $key = $this->primary_key; |
543 | 543 | $value = $args[0]; |
544 | 544 | } |
545 | - $this->trigger('before_dropdown', array( $key, $value )); |
|
545 | + $this->trigger('before_dropdown', array($key, $value)); |
|
546 | 546 | if ($this->soft_delete && $this->_temporary_with_deleted !== TRUE) |
547 | 547 | { |
548 | 548 | $this->_database->where($this->soft_delete_key, FALSE); |
@@ -566,7 +566,7 @@ discard block |
||
566 | 566 | { |
567 | 567 | if ($this->soft_delete && $this->_temporary_with_deleted !== TRUE) |
568 | 568 | { |
569 | - $this->_database->where($this->soft_delete_key, (bool)$this->_temporary_only_deleted); |
|
569 | + $this->_database->where($this->soft_delete_key, (bool) $this->_temporary_only_deleted); |
|
570 | 570 | } |
571 | 571 | $where = func_get_args(); |
572 | 572 | $this->_set_where($where); |
@@ -581,7 +581,7 @@ discard block |
||
581 | 581 | { |
582 | 582 | if ($this->soft_delete && $this->_temporary_with_deleted !== TRUE) |
583 | 583 | { |
584 | - $this->_database->where($this->soft_delete_key, (bool)$this->_temporary_only_deleted); |
|
584 | + $this->_database->where($this->soft_delete_key, (bool) $this->_temporary_only_deleted); |
|
585 | 585 | } |
586 | 586 | $this->_database->from($this->_table)->getAll(); |
587 | 587 | return $this->_database->numRows(); |
@@ -590,8 +590,8 @@ discard block |
||
590 | 590 | /** |
591 | 591 | * Enabled cache temporary |
592 | 592 | */ |
593 | - public function cached($ttl = 0){ |
|
594 | - if($ttl > 0){ |
|
593 | + public function cached($ttl = 0) { |
|
594 | + if ($ttl > 0) { |
|
595 | 595 | $this->_database = $this->_database->cached($ttl); |
596 | 596 | } |
597 | 597 | return $this; |
@@ -745,13 +745,13 @@ discard block |
||
745 | 745 | { |
746 | 746 | if (is_object($row)) |
747 | 747 | { |
748 | - if(isset($row->$attr)){ |
|
748 | + if (isset($row->$attr)) { |
|
749 | 749 | unset($row->$attr); |
750 | 750 | } |
751 | 751 | } |
752 | 752 | else |
753 | 753 | { |
754 | - if(isset($row[$attr])){ |
|
754 | + if (isset($row[$attr])) { |
|
755 | 755 | unset($row[$attr]); |
756 | 756 | } |
757 | 757 | } |
@@ -763,7 +763,7 @@ discard block |
||
763 | 763 | * Return the database instance |
764 | 764 | * @return Database the database instance |
765 | 765 | */ |
766 | - public function getDatabaseInstance(){ |
|
766 | + public function getDatabaseInstance() { |
|
767 | 767 | return $this->_database; |
768 | 768 | } |
769 | 769 | |
@@ -771,9 +771,9 @@ discard block |
||
771 | 771 | * set the Database instance for future use |
772 | 772 | * @param Database $db the database object |
773 | 773 | */ |
774 | - public function setDatabaseInstance($db){ |
|
774 | + public function setDatabaseInstance($db) { |
|
775 | 775 | $this->_database = $db; |
776 | - if($this->dbCacheTime > 0){ |
|
776 | + if ($this->dbCacheTime > 0) { |
|
777 | 777 | $this->_database->setCache($this->dbCacheTime); |
778 | 778 | } |
779 | 779 | return $this; |
@@ -783,7 +783,7 @@ discard block |
||
783 | 783 | * Return the loader instance |
784 | 784 | * @return Loader the loader instance |
785 | 785 | */ |
786 | - public function getLoader(){ |
|
786 | + public function getLoader() { |
|
787 | 787 | return $this->loaderInstance; |
788 | 788 | } |
789 | 789 | |
@@ -791,7 +791,7 @@ discard block |
||
791 | 791 | * set the loader instance for future use |
792 | 792 | * @param Loader $loader the loader object |
793 | 793 | */ |
794 | - public function setLoader($loader){ |
|
794 | + public function setLoader($loader) { |
|
795 | 795 | $this->loaderInstance = $loader; |
796 | 796 | return $this; |
797 | 797 | } |
@@ -800,7 +800,7 @@ discard block |
||
800 | 800 | * Return the FormValidation instance |
801 | 801 | * @return FormValidation the form validation instance |
802 | 802 | */ |
803 | - public function getFormValidation(){ |
|
803 | + public function getFormValidation() { |
|
804 | 804 | return $this->formValidationInstance; |
805 | 805 | } |
806 | 806 | |
@@ -808,7 +808,7 @@ discard block |
||
808 | 808 | * set the form validation instance for future use |
809 | 809 | * @param FormValidation $fv the form validation object |
810 | 810 | */ |
811 | - public function setFormValidation($fv){ |
|
811 | + public function setFormValidation($fv) { |
|
812 | 812 | $this->formValidationInstance = $fv; |
813 | 813 | return $this; |
814 | 814 | } |
@@ -822,7 +822,7 @@ discard block |
||
822 | 822 | */ |
823 | 823 | public function order_by($criteria, $order = 'ASC') |
824 | 824 | { |
825 | - if ( is_array($criteria) ) |
|
825 | + if (is_array($criteria)) |
|
826 | 826 | { |
827 | 827 | foreach ($criteria as $key => $value) |
828 | 828 | { |
@@ -878,22 +878,22 @@ discard block |
||
878 | 878 | */ |
879 | 879 | protected function validate(array $data) |
880 | 880 | { |
881 | - if($this->skip_validation) |
|
881 | + if ($this->skip_validation) |
|
882 | 882 | { |
883 | 883 | return $data; |
884 | 884 | } |
885 | - if(!empty($this->validate)) |
|
885 | + if (!empty($this->validate)) |
|
886 | 886 | { |
887 | 887 | $fv = null; |
888 | - if(is_object($this->formValidationInstance)){ |
|
888 | + if (is_object($this->formValidationInstance)) { |
|
889 | 889 | $fv = $this->formValidationInstance; |
890 | 890 | } |
891 | - else{ |
|
891 | + else { |
|
892 | 892 | Loader::library('FormValidation'); |
893 | 893 | $fv = $this->formvalidation; |
894 | 894 | $this->setFormValidation($fv); |
895 | 895 | } |
896 | - if(is_array($this->validate)) |
|
896 | + if (is_array($this->validate)) |
|
897 | 897 | { |
898 | 898 | $fv->setData($data); |
899 | 899 | $fv->setRules($this->validate); |
@@ -948,7 +948,7 @@ discard block |
||
948 | 948 | { |
949 | 949 | $this->_database->where($params[0]); |
950 | 950 | } |
951 | - else if(count($params) == 2) |
|
951 | + else if (count($params) == 2) |
|
952 | 952 | { |
953 | 953 | if (is_array($params[1])) |
954 | 954 | { |
@@ -959,7 +959,7 @@ discard block |
||
959 | 959 | $this->_database->where($params[0], $params[1]); |
960 | 960 | } |
961 | 961 | } |
962 | - else if(count($params) == 3) |
|
962 | + else if (count($params) == 3) |
|
963 | 963 | { |
964 | 964 | $this->_database->where($params[0], $params[1], $params[2]); |
965 | 965 | } |
@@ -979,7 +979,7 @@ discard block |
||
979 | 979 | /** |
980 | 980 | Shortcut to controller |
981 | 981 | */ |
982 | - public function __get($key){ |
|
982 | + public function __get($key) { |
|
983 | 983 | return get_instance()->{$key}; |
984 | 984 | } |
985 | 985 |
@@ -143,8 +143,7 @@ discard block |
||
143 | 143 | public function __construct(Database $db = null){ |
144 | 144 | if(is_object($db)){ |
145 | 145 | $this->setDatabaseInstance($db); |
146 | - } |
|
147 | - else{ |
|
146 | + } else{ |
|
148 | 147 | $obj = & get_instance(); |
149 | 148 | if(isset($obj->database) && is_object($obj->database)){ |
150 | 149 | /** |
@@ -256,8 +255,7 @@ discard block |
||
256 | 255 | $insert_id = $this->_database->insertId(); |
257 | 256 | $this->trigger('after_create', $insert_id); |
258 | 257 | return $insert_id; |
259 | - } |
|
260 | - else |
|
258 | + } else |
|
261 | 259 | { |
262 | 260 | return FALSE; |
263 | 261 | } |
@@ -294,8 +292,7 @@ discard block |
||
294 | 292 | ->update($data, $escape); |
295 | 293 | $this->trigger('after_update', array($data, $result)); |
296 | 294 | return $result; |
297 | - } |
|
298 | - else |
|
295 | + } else |
|
299 | 296 | { |
300 | 297 | return FALSE; |
301 | 298 | } |
@@ -318,8 +315,7 @@ discard block |
||
318 | 315 | ->update($data, $escape); |
319 | 316 | $this->trigger('after_update', array($data, $result)); |
320 | 317 | return $result; |
321 | - } |
|
322 | - else |
|
318 | + } else |
|
323 | 319 | { |
324 | 320 | return FALSE; |
325 | 321 | } |
@@ -336,8 +332,7 @@ discard block |
||
336 | 332 | if(is_array($args[1])){ |
337 | 333 | $data = array_pop($args); |
338 | 334 | } |
339 | - } |
|
340 | - else if(count($args) == 3){ |
|
335 | + } else if(count($args) == 3){ |
|
341 | 336 | if(is_array($args[2])){ |
342 | 337 | $data = array_pop($args); |
343 | 338 | } |
@@ -349,8 +344,7 @@ discard block |
||
349 | 344 | $result = $this->_database->from($this->_table)->update($data); |
350 | 345 | $this->trigger('after_update', array($data, $result)); |
351 | 346 | return $result; |
352 | - } |
|
353 | - else |
|
347 | + } else |
|
354 | 348 | { |
355 | 349 | return FALSE; |
356 | 350 | } |
@@ -377,8 +371,7 @@ discard block |
||
377 | 371 | if ($this->soft_delete) |
378 | 372 | { |
379 | 373 | $result = $this->_database->from($this->_table)->update(array( $this->soft_delete_key => TRUE )); |
380 | - } |
|
381 | - else |
|
374 | + } else |
|
382 | 375 | { |
383 | 376 | $result = $this->_database->from($this->_table)->delete(); |
384 | 377 | } |
@@ -398,8 +391,7 @@ discard block |
||
398 | 391 | if ($this->soft_delete) |
399 | 392 | { |
400 | 393 | $result = $this->_database->from($this->_table)->update(array( $this->soft_delete_key => TRUE )); |
401 | - } |
|
402 | - else |
|
394 | + } else |
|
403 | 395 | { |
404 | 396 | $result = $this->_database->from($this->_table)->delete(); |
405 | 397 | } |
@@ -417,8 +409,7 @@ discard block |
||
417 | 409 | if ($this->soft_delete) |
418 | 410 | { |
419 | 411 | $result = $this->_database->from($this->_table)->update(array( $this->soft_delete_key => TRUE )); |
420 | - } |
|
421 | - else |
|
412 | + } else |
|
422 | 413 | { |
423 | 414 | $result = $this->_database->from($this->_table)->delete(); |
424 | 415 | } |
@@ -463,8 +454,7 @@ discard block |
||
463 | 454 | { |
464 | 455 | $relationship = $value; |
465 | 456 | $options = array( 'primary_key' => $value . '_id', 'model' => $value . '_model' ); |
466 | - } |
|
467 | - else |
|
457 | + } else |
|
468 | 458 | { |
469 | 459 | $relationship = $key; |
470 | 460 | $options = $value; |
@@ -474,15 +464,13 @@ discard block |
||
474 | 464 | { |
475 | 465 | if(is_object($this->loaderInstance)){ |
476 | 466 | $this->loaderInstance->model($options['model'], $relationship . '_model'); |
477 | - } |
|
478 | - else{ |
|
467 | + } else{ |
|
479 | 468 | Loader::model($options['model'], $relationship . '_model'); |
480 | 469 | } |
481 | 470 | if (is_object($row)) |
482 | 471 | { |
483 | 472 | $row->{$relationship} = $this->{$relationship . '_model'}->get($row->{$options['primary_key']}); |
484 | - } |
|
485 | - else |
|
473 | + } else |
|
486 | 474 | { |
487 | 475 | $row[$relationship] = $this->{$relationship . '_model'}->get($row[$options['primary_key']]); |
488 | 476 | } |
@@ -495,8 +483,7 @@ discard block |
||
495 | 483 | { |
496 | 484 | $relationship = $value; |
497 | 485 | $options = array( 'primary_key' => $this->_table . '_id', 'model' => $value . '_model' ); |
498 | - } |
|
499 | - else |
|
486 | + } else |
|
500 | 487 | { |
501 | 488 | $relationship = $key; |
502 | 489 | $options = $value; |
@@ -506,15 +493,13 @@ discard block |
||
506 | 493 | { |
507 | 494 | if(is_object($this->loaderInstance)){ |
508 | 495 | $this->loaderInstance->model($options['model'], $relationship . '_model'); |
509 | - } |
|
510 | - else{ |
|
496 | + } else{ |
|
511 | 497 | Loader::model($options['model'], $relationship . '_model'); |
512 | 498 | } |
513 | 499 | if (is_object($row)) |
514 | 500 | { |
515 | 501 | $row->{$relationship} = $this->{$relationship . '_model'}->get_many_by($options['primary_key'], $row->{$this->primary_key}); |
516 | - } |
|
517 | - else |
|
502 | + } else |
|
518 | 503 | { |
519 | 504 | $row[$relationship] = $this->{$relationship . '_model'}->get_many_by($options['primary_key'], $row[$this->primary_key]); |
520 | 505 | } |
@@ -536,8 +521,7 @@ discard block |
||
536 | 521 | if(count($args) == 2) |
537 | 522 | { |
538 | 523 | list($key, $value) = $args; |
539 | - } |
|
540 | - else |
|
524 | + } else |
|
541 | 525 | { |
542 | 526 | $key = $this->primary_key; |
543 | 527 | $value = $args[0]; |
@@ -685,8 +669,7 @@ discard block |
||
685 | 669 | if (is_object($row)) |
686 | 670 | { |
687 | 671 | $row->created_at = date('Y-m-d H:i:s'); |
688 | - } |
|
689 | - else |
|
672 | + } else |
|
690 | 673 | { |
691 | 674 | $row['created_at'] = date('Y-m-d H:i:s'); |
692 | 675 | } |
@@ -699,8 +682,7 @@ discard block |
||
699 | 682 | if (is_object($row)) |
700 | 683 | { |
701 | 684 | $row->updated_at = date('Y-m-d H:i:s'); |
702 | - } |
|
703 | - else |
|
685 | + } else |
|
704 | 686 | { |
705 | 687 | $row['updated_at'] = date('Y-m-d H:i:s'); |
706 | 688 | } |
@@ -727,8 +709,7 @@ discard block |
||
727 | 709 | if (is_array($row)) |
728 | 710 | { |
729 | 711 | $row[$column] = unserialize($row[$column]); |
730 | - } |
|
731 | - else |
|
712 | + } else |
|
732 | 713 | { |
733 | 714 | $row->$column = unserialize($row->$column); |
734 | 715 | } |
@@ -748,8 +729,7 @@ discard block |
||
748 | 729 | if(isset($row->$attr)){ |
749 | 730 | unset($row->$attr); |
750 | 731 | } |
751 | - } |
|
752 | - else |
|
732 | + } else |
|
753 | 733 | { |
754 | 734 | if(isset($row[$attr])){ |
755 | 735 | unset($row[$attr]); |
@@ -828,8 +808,7 @@ discard block |
||
828 | 808 | { |
829 | 809 | $this->_database->orderBy($key, $value); |
830 | 810 | } |
831 | - } |
|
832 | - else |
|
811 | + } else |
|
833 | 812 | { |
834 | 813 | $this->_database->orderBy($criteria, $order); |
835 | 814 | } |
@@ -887,8 +866,7 @@ discard block |
||
887 | 866 | $fv = null; |
888 | 867 | if(is_object($this->formValidationInstance)){ |
889 | 868 | $fv = $this->formValidationInstance; |
890 | - } |
|
891 | - else{ |
|
869 | + } else{ |
|
892 | 870 | Loader::library('FormValidation'); |
893 | 871 | $fv = $this->formvalidation; |
894 | 872 | $this->setFormValidation($fv); |
@@ -901,17 +879,14 @@ discard block |
||
901 | 879 | if ($fv->run()) |
902 | 880 | { |
903 | 881 | return $data; |
904 | - } |
|
905 | - else |
|
882 | + } else |
|
906 | 883 | { |
907 | 884 | return FALSE; |
908 | 885 | } |
909 | - } |
|
910 | - else { |
|
886 | + } else { |
|
911 | 887 | return $data; |
912 | 888 | } |
913 | - } |
|
914 | - else |
|
889 | + } else |
|
915 | 890 | { |
916 | 891 | return $data; |
917 | 892 | } |
@@ -930,46 +905,38 @@ discard block |
||
930 | 905 | if (is_array($filter)) |
931 | 906 | { |
932 | 907 | $this->_database->in($field, $filter); |
933 | - } |
|
934 | - else |
|
908 | + } else |
|
935 | 909 | { |
936 | 910 | if (is_int($field)) |
937 | 911 | { |
938 | 912 | $this->_database->where($filter); |
939 | - } |
|
940 | - else |
|
913 | + } else |
|
941 | 914 | { |
942 | 915 | $this->_database->where($field, $filter); |
943 | 916 | } |
944 | 917 | } |
945 | 918 | } |
946 | - } |
|
947 | - else if (count($params) == 1) |
|
919 | + } else if (count($params) == 1) |
|
948 | 920 | { |
949 | 921 | $this->_database->where($params[0]); |
950 | - } |
|
951 | - else if(count($params) == 2) |
|
922 | + } else if(count($params) == 2) |
|
952 | 923 | { |
953 | 924 | if (is_array($params[1])) |
954 | 925 | { |
955 | 926 | $this->_database->in($params[0], $params[1]); |
956 | - } |
|
957 | - else |
|
927 | + } else |
|
958 | 928 | { |
959 | 929 | $this->_database->where($params[0], $params[1]); |
960 | 930 | } |
961 | - } |
|
962 | - else if(count($params) == 3) |
|
931 | + } else if(count($params) == 3) |
|
963 | 932 | { |
964 | 933 | $this->_database->where($params[0], $params[1], $params[2]); |
965 | - } |
|
966 | - else |
|
934 | + } else |
|
967 | 935 | { |
968 | 936 | if (is_array($params[1])) |
969 | 937 | { |
970 | 938 | $this->_database->in($params[0], $params[1]); |
971 | - } |
|
972 | - else |
|
939 | + } else |
|
973 | 940 | { |
974 | 941 | $this->_database->where($params[0], $params[1]); |
975 | 942 | } |