11
11
* @version 2.2
12
12
*
13
13
* @method int count ()
14
+ * @method dbObject ArrayBuilder()
15
+ * @method dbObject JsonBuilder()
16
+ * @method dbObject ObjectBuilder()
14
17
* @method mixed byId (string $id, mixed $fields)
15
18
* @method mixed get (mixed $limit, mixed $fields)
16
19
* @method mixed getOne (mixed $fields)
@@ -181,21 +184,19 @@ public function __unset ($name) {
181
184
*
182
185
* @return dbObject
183
186
*/
184
- public static function JsonBuilder () {
185
- $ obj = new static ;
186
- $ obj ->returnType = 'Json ' ;
187
- return $ obj ;
187
+ private function JsonBuilder () {
188
+ $ this ->returnType = 'Json ' ;
189
+ return $ return ;
188
190
}
189
191
190
192
/**
191
193
* Helper function to create dbObject with Array return type
192
194
*
193
195
* @return dbObject
194
196
*/
195
- public static function ArrayBuilder () {
196
- $ obj = new static ;
197
- $ obj ->returnType = 'Array ' ;
198
- return $ obj ;
197
+ private function ArrayBuilder () {
198
+ $ this ->returnType = 'Array ' ;
199
+ return $ this ;
199
200
}
200
201
201
202
/**
@@ -204,8 +205,9 @@ public static function ArrayBuilder () {
204
205
*
205
206
* @return dbObject
206
207
*/
207
- public static function ObjectBuilder () {
208
- return new static ;
208
+ private function ObjectBuilder () {
209
+ $ this ->returnType = 'Object ' ;
210
+ return $ this ;
209
211
}
210
212
211
213
/**
@@ -297,7 +299,7 @@ public function delete () {
297
299
*
298
300
* @return dbObject|array
299
301
*/
300
- private function byId ($ id , $ fields = null ) {
302
+ protected function byId ($ id , $ fields = null ) {
301
303
$ this ->db ->where (MysqliDb::$ prefix . $ this ->dbTable . '. ' . $ this ->primaryKey , $ id );
302
304
return $ this ->getOne ($ fields );
303
305
}
@@ -310,7 +312,7 @@ private function byId ($id, $fields = null) {
310
312
*
311
313
* @return dbObject
312
314
*/
313
- private function getOne ($ fields = null ) {
315
+ protected function getOne ($ fields = null ) {
314
316
$ this ->processHasOneWith ();
315
317
$ results = $ this ->db ->ArrayBuilder ()->getOne ($ this ->dbTable , $ fields );
316
318
if ($ this ->db ->count == 0 )
@@ -340,7 +342,7 @@ private function getOne ($fields = null) {
340
342
*
341
343
* @return array Array of dbObjects
342
344
*/
343
- private function get ($ limit = null , $ fields = null ) {
345
+ protected function get ($ limit = null , $ fields = null ) {
344
346
$ objects = Array ();
345
347
$ this ->processHasOneWith ();
346
348
$ results = $ this ->db ->ArrayBuilder ()->get ($ this ->dbTable , $ limit , $ fields );
@@ -409,9 +411,11 @@ private function join ($objectName, $key = null, $joinType = 'LEFT') {
409
411
*
410
412
* @return int
411
413
*/
412
- private function count () {
414
+ protected function count () {
413
415
$ res = $ this ->db ->ArrayBuilder ()->getValue ($ this ->dbTable , "count(*) " );
414
- return $ res ['cnt ' ];
416
+ if (!$ res )
417
+ return 0 ;
418
+ return $ res ;
415
419
}
416
420
417
421
/**
@@ -608,6 +612,9 @@ private function validate ($data) {
608
612
case "int " :
609
613
$ regexp = "/^[0-9]*$/ " ;
610
614
break ;
615
+ case "double " :
616
+ $ regexp = "/^[0-9\.]*$/ " ;
617
+ break ;
611
618
case "bool " :
612
619
$ regexp = '/^[yes|no|0|1|true|false]$/i ' ;
613
620
break ;
0 commit comments