Passed
Push — 1.0.0-dev ( 93958a...e1c8ef )
by nguereza
02:26
created
core/libraries/Upload.php 3 patches
Braces   +2 added lines, -4 removed lines patch added patch discarded remove patch
@@ -477,8 +477,7 @@  discard block
 block discarded – undo
477 477
                     if (mkdir($destination_directory, 0775, true)) {
478 478
                         $this->destination_directory = $destination_directory;
479 479
                         chdir($destination_directory);
480
-                    }
481
-                    else{
480
+                    } else{
482 481
                         $this->logger->warning('Can not create the upload directory [' .$destination_directory. ']');
483 482
                     }
484 483
                 }
@@ -630,8 +629,7 @@  discard block
 block discarded – undo
630 629
                 // set original filename if not have a new name
631 630
                 if (empty($this->filename)) {
632 631
                     $this->filename = $this->file_array[$this->input]['name'];
633
-                }
634
-                else{
632
+                } else{
635 633
                     // Replace %s for extension in filename
636 634
                     // Before: /[\w\d]*(.[\d\w]+)$/i
637 635
                     // After: /^[\s[:alnum:]\-\_\.]*\.([\d\w]+)$/iu
Please login to merge, or discard this patch.
Indentation   +293 added lines, -293 removed lines patch added patch discarded remove patch
@@ -22,139 +22,139 @@  discard block
 block discarded – undo
22 22
      * You should have received a copy of the GNU General Public License
23 23
      * along with this program; if not, write to the Free Software
24 24
      * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25
-    */
25
+     */
26 26
 
27 27
 
28 28
 
29 29
     /**
30
-    *    Upload
31
-    *
32
-    *    A complete class to upload files with php 5 or higher, but the best: very simple to use.
33
-    *
34
-    *    @author Olaf Erlandsen <[email protected]>
35
-    *    @author http://www.webdevfreelance.com/
36
-    *
37
-    *    @package FileUpload
38
-    *    @version 1.5
39
-    */
30
+     *    Upload
31
+     *
32
+     *    A complete class to upload files with php 5 or higher, but the best: very simple to use.
33
+     *
34
+     *    @author Olaf Erlandsen <[email protected]>
35
+     *    @author http://www.webdevfreelance.com/
36
+     *
37
+     *    @package FileUpload
38
+     *    @version 1.5
39
+     */
40 40
     class Upload extends BaseClass{
41 41
 
42 42
         /**
43
-        *   Version
44
-        *
45
-        *   @since      1.5
46
-        *   @version    1.0
47
-        */
43
+         *   Version
44
+         *
45
+         *   @since      1.5
46
+         *   @version    1.0
47
+         */
48 48
         const VERSION = '1.5';
49 49
 
50 50
         /**
51
-        *    Upload function name
52
-        *    Remember:
53
-        *        Default function: move_uploaded_file
54
-        *        Native options:
55
-        *            - move_uploaded_file (Default and best option)
56
-        *            - copy
57
-        *
58
-        *    @since        1.0
59
-        *    @version    1.0
60
-        *    @var        string
61
-        */
51
+         *    Upload function name
52
+         *    Remember:
53
+         *        Default function: move_uploaded_file
54
+         *        Native options:
55
+         *            - move_uploaded_file (Default and best option)
56
+         *            - copy
57
+         *
58
+         *    @since        1.0
59
+         *    @version    1.0
60
+         *    @var        string
61
+         */
62 62
         private $upload_function = 'move_uploaded_file';
63 63
 
64 64
         /**
65
-        *    Array with the information obtained from the
66
-        *    variable $_FILES or $HTTP_POST_FILES.
67
-        *
68
-        *    @since        1.0
69
-        *    @version    1.0
70
-        *    @var        array
71
-        */
65
+         *    Array with the information obtained from the
66
+         *    variable $_FILES or $HTTP_POST_FILES.
67
+         *
68
+         *    @since        1.0
69
+         *    @version    1.0
70
+         *    @var        array
71
+         */
72 72
         private $file_array    = array();
73 73
 
74 74
         /**
75
-        *    If the file you are trying to upload already exists it will
76
-        *    be overwritten if you set the variable to true.
77
-        *
78
-        *    @since        1.0
79
-        *    @version    1.0
80
-        *    @var        boolean
81
-        */
75
+         *    If the file you are trying to upload already exists it will
76
+         *    be overwritten if you set the variable to true.
77
+         *
78
+         *    @since        1.0
79
+         *    @version    1.0
80
+         *    @var        boolean
81
+         */
82 82
         private $overwrite_file = false;
83 83
 
84 84
         /**
85
-        *    Input element
86
-        *    Example:
87
-        *        <input type="file" name="file" />
88
-        *    Result:
89
-        *        FileUpload::$input = file
90
-        *
91
-        *    @since        1.0
92
-        *    @version    1.0
93
-        *    @var        string
94
-        */
85
+         *    Input element
86
+         *    Example:
87
+         *        <input type="file" name="file" />
88
+         *    Result:
89
+         *        FileUpload::$input = file
90
+         *
91
+         *    @since        1.0
92
+         *    @version    1.0
93
+         *    @var        string
94
+         */
95 95
         private $input;
96 96
 
97 97
         /**
98
-        *    Path output
99
-        *
100
-        *    @since        1.0
101
-        *    @version    1.0
102
-        *    @var        string
103
-        */
98
+         *    Path output
99
+         *
100
+         *    @since        1.0
101
+         *    @version    1.0
102
+         *    @var        string
103
+         */
104 104
         private $destination_directory;
105 105
 
106 106
         /**
107
-        *    Output filename
108
-        *
109
-        *    @since        1.0
110
-        *    @version    1.0
111
-        *    @var        string
112
-        */
107
+         *    Output filename
108
+         *
109
+         *    @since        1.0
110
+         *    @version    1.0
111
+         *    @var        string
112
+         */
113 113
         private $filename;
114 114
 
115 115
         /**
116
-        *    Max file size
117
-        *
118
-        *    @since        1.0
119
-        *    @version    1.0
120
-        *    @var        float
121
-        */
116
+         *    Max file size
117
+         *
118
+         *    @since        1.0
119
+         *    @version    1.0
120
+         *    @var        float
121
+         */
122 122
         private $max_file_size= 0.0;
123 123
 
124 124
         /**
125
-        *    List of allowed mime types
126
-        *
127
-        *    @since        1.0
128
-        *    @version    1.0
129
-        *    @var        array
130
-        */
125
+         *    List of allowed mime types
126
+         *
127
+         *    @since        1.0
128
+         *    @version    1.0
129
+         *    @var        array
130
+         */
131 131
         private $allowed_mime_types = array();
132 132
 
133 133
         /**
134
-        *    Callbacks
135
-        *
136
-        *    @since        1.0
137
-        *    @version    1.0
138
-        *    @var        array
139
-        */
134
+         *    Callbacks
135
+         *
136
+         *    @since        1.0
137
+         *    @version    1.0
138
+         *    @var        array
139
+         */
140 140
         private $callbacks = array('before' => null, 'after' => null);
141 141
 
142 142
         /**
143
-        *    File object
144
-        *
145
-        *    @since        1.0
146
-        *    @version    1.0
147
-        *    @var        object
148
-        */
143
+         *    File object
144
+         *
145
+         *    @since        1.0
146
+         *    @version    1.0
147
+         *    @var        object
148
+         */
149 149
         private $file;
150 150
 
151 151
         /**
152
-        *    Helping mime types
153
-        *
154
-        *    @since        1.0
155
-        *    @version    1.0
156
-        *    @var        array
157
-        */
152
+         *    Helping mime types
153
+         *
154
+         *    @since        1.0
155
+         *    @version    1.0
156
+         *    @var        array
157
+         */
158 158
         private $mime_helping = array(
159 159
             'text'      =>    array('text/plain',),
160 160
             'image'     =>    array(
@@ -204,13 +204,13 @@  discard block
 block discarded – undo
204 204
 
205 205
 
206 206
         /**
207
-        *    Construct
208
-        *
209
-        *    @since     0.1
210
-        *    @version   1.0.1
211
-        *    @return    object
212
-        *    @method    object    __construct
213
-        */
207
+         *    Construct
208
+         *
209
+         *    @since     0.1
210
+         *    @version   1.0.1
211
+         *    @return    object
212
+         *    @method    object    __construct
213
+         */
214 214
         public function __construct(){
215 215
             parent::__construct();
216 216
 
@@ -253,17 +253,17 @@  discard block
 block discarded – undo
253 253
             $this->logger->info('The upload file information are : ' .stringfy_vars($this->file_array));
254 254
         }
255 255
         /**
256
-        *    Set input.
257
-        *    If you have $_FILES["file"], you must use the key "file"
258
-        *    Example:
259
-        *        $object->setInput("file");
260
-        *
261
-        *    @since     1.0
262
-        *    @version   1.0
263
-        *    @param     string      $input
264
-        *    @return    object
265
-        *    @method    boolean     setInput
266
-        */
256
+         *    Set input.
257
+         *    If you have $_FILES["file"], you must use the key "file"
258
+         *    Example:
259
+         *        $object->setInput("file");
260
+         *
261
+         *    @since     1.0
262
+         *    @version   1.0
263
+         *    @param     string      $input
264
+         *    @return    object
265
+         *    @method    boolean     setInput
266
+         */
267 267
         public function setInput($input)
268 268
         {
269 269
             if (!empty($input) && (is_string($input) || is_numeric($input) )) {
@@ -272,18 +272,18 @@  discard block
 block discarded – undo
272 272
             return $this;
273 273
         }
274 274
         /**
275
-        *    Set new filename
276
-        *    Example:
277
-        *        FileUpload::setFilename("new file.txt")
278
-        *    Remember:
279
-        *        Use %s to retrive file extension
280
-        *
281
-        *    @since     1.0
282
-        *    @version   1.0
283
-        *    @param     string      $filename
284
-        *    @return    object
285
-        *    @method    boolean     setFilename
286
-        */
275
+         *    Set new filename
276
+         *    Example:
277
+         *        FileUpload::setFilename("new file.txt")
278
+         *    Remember:
279
+         *        Use %s to retrive file extension
280
+         *
281
+         *    @since     1.0
282
+         *    @version   1.0
283
+         *    @param     string      $filename
284
+         *    @return    object
285
+         *    @method    boolean     setFilename
286
+         */
287 287
         public function setFilename($filename)
288 288
         {
289 289
             if ($this->isFilename($filename)) {
@@ -292,14 +292,14 @@  discard block
 block discarded – undo
292 292
             return $this;
293 293
         }
294 294
         /**
295
-        *    Set automatic filename
296
-        *
297
-        *    @since     1.0
298
-        *    @version   1.5
299
-        *    @param     string      $extension
300
-        *    @return    object
301
-        *    @method    boolean     setAutoFilename
302
-        */
295
+         *    Set automatic filename
296
+         *
297
+         *    @since     1.0
298
+         *    @version   1.5
299
+         *    @param     string      $extension
300
+         *    @return    object
301
+         *    @method    boolean     setAutoFilename
302
+         */
303 303
         public function setAutoFilename()
304 304
         {
305 305
             $this->filename = sha1(mt_rand(1, 9999).uniqid());
@@ -307,14 +307,14 @@  discard block
 block discarded – undo
307 307
             return $this;
308 308
         }
309 309
         /**
310
-        *    Set file size limit
311
-        *
312
-        *    @since     1.0
313
-        *    @version   1.0
314
-        *    @param     double     $file_size
315
-        *    @return    object
316
-        *    @method    boolean     setMaxFileSize
317
-        */
310
+         *    Set file size limit
311
+         *
312
+         *    @since     1.0
313
+         *    @version   1.0
314
+         *    @param     double     $file_size
315
+         *    @return    object
316
+         *    @method    boolean     setMaxFileSize
317
+         */
318 318
         public function setMaxFileSize($file_size)
319 319
         {
320 320
             $file_size = $this->sizeInBytes($file_size);
@@ -330,14 +330,14 @@  discard block
 block discarded – undo
330 330
             return $this;
331 331
         }
332 332
         /**
333
-        *    Set array mime types
334
-        *
335
-        *    @since     1.0
336
-        *    @version   1.0
337
-        *    @param     array       $mimes
338
-        *    @return    object
339
-        *    @method    boolean     setAllowedMimeTypes
340
-        */
333
+         *    Set array mime types
334
+         *
335
+         *    @since     1.0
336
+         *    @version   1.0
337
+         *    @param     array       $mimes
338
+         *    @return    object
339
+         *    @method    boolean     setAllowedMimeTypes
340
+         */
341 341
         public function setAllowedMimeTypes(array $mimes)
342 342
         {
343 343
             if (count($mimes) > 0) {
@@ -346,14 +346,14 @@  discard block
 block discarded – undo
346 346
             return $this;
347 347
         }
348 348
         /**
349
-        *    Set input callback
350
-        *
351
-        *    @since     1.0
352
-        *    @version   1.0
353
-        *    @param     mixed       $callback
354
-        *    @return    object
355
-        *    @method    boolean     setCallbackInput
356
-        */
349
+         *    Set input callback
350
+         *
351
+         *    @since     1.0
352
+         *    @version   1.0
353
+         *    @param     mixed       $callback
354
+         *    @return    object
355
+         *    @method    boolean     setCallbackInput
356
+         */
357 357
         public function setCallbackInput($callback)
358 358
         {
359 359
             if (is_callable($callback, false)) {
@@ -362,14 +362,14 @@  discard block
 block discarded – undo
362 362
             return $this;
363 363
         }
364 364
         /**
365
-        *    Set output callback
366
-        *
367
-        *    @since     1.0
368
-        *    @version   1.0
369
-        *    @param     mixed       $callback
370
-        *    @return    object
371
-        *    @method    boolean     setCallbackOutput
372
-        */
365
+         *    Set output callback
366
+         *
367
+         *    @since     1.0
368
+         *    @version   1.0
369
+         *    @param     mixed       $callback
370
+         *    @return    object
371
+         *    @method    boolean     setCallbackOutput
372
+         */
373 373
         public function setCallbackOutput($callback)
374 374
         {
375 375
             if (is_callable($callback, false)) {
@@ -378,14 +378,14 @@  discard block
 block discarded – undo
378 378
             return $this;
379 379
         }
380 380
         /**
381
-        *    Append a mime type to allowed mime types
382
-        *
383
-        *    @since     1.0
384
-        *    @version   1.0.1
385
-        *    @param     string      $mime
386
-        *    @return    object
387
-        *    @method    boolean     setAllowMimeType
388
-        */
381
+         *    Append a mime type to allowed mime types
382
+         *
383
+         *    @since     1.0
384
+         *    @version   1.0.1
385
+         *    @param     string      $mime
386
+         *    @return    object
387
+         *    @method    boolean     setAllowMimeType
388
+         */
389 389
         public function setAllowMimeType($mime)
390 390
         {
391 391
             if (!empty($mime) && is_string($mime)) {
@@ -395,13 +395,13 @@  discard block
 block discarded – undo
395 395
             return $this;
396 396
         }
397 397
         /**
398
-        *    Set allowed mime types from mime helping
399
-        *
400
-        *    @since     1.0.1
401
-        *    @version   1.0.1
402
-        *    @return    object
403
-        *    @method    boolean    setMimeHelping
404
-        */
398
+         *    Set allowed mime types from mime helping
399
+         *
400
+         *    @since     1.0.1
401
+         *    @version   1.0.1
402
+         *    @return    object
403
+         *    @method    boolean    setMimeHelping
404
+         */
405 405
         public function setMimeHelping($name)
406 406
         {
407 407
             if (!empty($name) && is_string($name)) {
@@ -412,17 +412,17 @@  discard block
 block discarded – undo
412 412
             return $this;
413 413
         }
414 414
         /**
415
-        *    Set function to upload file
416
-        *    Examples:
417
-        *        1.- FileUpload::setUploadFunction("move_uploaded_file");
418
-        *        2.- FileUpload::setUploadFunction("copy");
419
-        *
420
-        *    @since     1.0
421
-        *    @version   1.0
422
-        *    @param     string      $function
423
-        *    @return    object
424
-        *    @method    boolean     setUploadFunction
425
-        */
415
+         *    Set function to upload file
416
+         *    Examples:
417
+         *        1.- FileUpload::setUploadFunction("move_uploaded_file");
418
+         *        2.- FileUpload::setUploadFunction("copy");
419
+         *
420
+         *    @since     1.0
421
+         *    @version   1.0
422
+         *    @param     string      $function
423
+         *    @return    object
424
+         *    @method    boolean     setUploadFunction
425
+         */
426 426
         public function setUploadFunction($function)
427 427
         {
428 428
             if (!empty($function) && (is_array($function) || is_string($function) )) {
@@ -433,13 +433,13 @@  discard block
 block discarded – undo
433 433
             return $this;
434 434
         }
435 435
         /**
436
-        *    Clear allowed mime types cache
437
-        *
438
-        *    @since     1.0
439
-        *    @version   1.0
440
-        *    @return    object
441
-        *    @method    boolean    clearAllowedMimeTypes
442
-        */
436
+         *    Clear allowed mime types cache
437
+         *
438
+         *    @since     1.0
439
+         *    @version   1.0
440
+         *    @return    object
441
+         *    @method    boolean    clearAllowedMimeTypes
442
+         */
443 443
         public function clearAllowedMimeTypes()
444 444
         {
445 445
             $this->allowed_mime_types = array();
@@ -447,15 +447,15 @@  discard block
 block discarded – undo
447 447
             return $this;
448 448
         }
449 449
         /**
450
-        *    Set destination output
451
-        *
452
-        *    @since     1.0
453
-        *    @version   1.0
454
-        *    @param     string      $destination_directory      Destination path
455
-        *    @param     boolean     $create_if_not_exist
456
-        *    @return    object
457
-        *    @method    boolean     setDestinationDirectory
458
-        */
450
+         *    Set destination output
451
+         *
452
+         *    @since     1.0
453
+         *    @version   1.0
454
+         *    @param     string      $destination_directory      Destination path
455
+         *    @param     boolean     $create_if_not_exist
456
+         *    @return    object
457
+         *    @method    boolean     setDestinationDirectory
458
+         */
459 459
         public function setDestinationDirectory($destination_directory, $create_if_not_exist = false) {
460 460
             $destination_directory = realpath($destination_directory);
461 461
             if (substr($destination_directory, -1) != DIRECTORY_SEPARATOR) {
@@ -479,14 +479,14 @@  discard block
 block discarded – undo
479 479
             return $this;
480 480
         }
481 481
         /**
482
-        *    Check file exists
483
-        *
484
-        *    @since      1.0
485
-        *    @version    1.0.1
486
-        *    @param      string     $file_destination
487
-        *    @return     boolean
488
-        *    @method     boolean    fileExists
489
-        */
482
+         *    Check file exists
483
+         *
484
+         *    @since      1.0
485
+         *    @version    1.0.1
486
+         *    @param      string     $file_destination
487
+         *    @return     boolean
488
+         *    @method     boolean    fileExists
489
+         */
490 490
         public function fileExists($file_destination)
491 491
         {
492 492
             if ($this->isFilename($file_destination)) {
@@ -495,14 +495,14 @@  discard block
 block discarded – undo
495 495
             return false;
496 496
         }
497 497
         /**
498
-        *    Check dir exists
499
-        *
500
-        *    @since        1.0
501
-        *    @version    1.0.1
502
-        *    @param      string     $path
503
-        *    @return     boolean
504
-        *    @method     boolean    dirExists
505
-        */
498
+         *    Check dir exists
499
+         *
500
+         *    @since        1.0
501
+         *    @version    1.0.1
502
+         *    @param      string     $path
503
+         *    @return     boolean
504
+         *    @method     boolean    dirExists
505
+         */
506 506
         public function dirExists($path)
507 507
         {
508 508
             if ($this->isDirpath($path)) {
@@ -511,29 +511,29 @@  discard block
 block discarded – undo
511 511
             return false;
512 512
         }
513 513
         /**
514
-        *    Check valid filename
515
-        *
516
-        *    @since     1.0
517
-        *    @version   1.0.1
518
-        *    @param     string      $filename
519
-        *    @return    boolean
520
-        *    @method    boolean     isFilename
521
-        */
514
+         *    Check valid filename
515
+         *
516
+         *    @since     1.0
517
+         *    @version   1.0.1
518
+         *    @param     string      $filename
519
+         *    @return    boolean
520
+         *    @method    boolean     isFilename
521
+         */
522 522
         public function isFilename($filename)
523 523
         {
524 524
             $filename = basename($filename);
525 525
             return (!empty($filename) && (is_string( $filename) || is_numeric($filename)));
526 526
         }
527 527
         /**
528
-        *    Validate mime type with allowed mime types,
529
-        *    but if allowed mime types is empty, this method return true
530
-        *
531
-        *    @since     1.0
532
-        *    @version   1.0
533
-        *    @param     string      $mime
534
-        *    @return    boolean
535
-        *    @method    boolean     checkMimeType
536
-        */
528
+         *    Validate mime type with allowed mime types,
529
+         *    but if allowed mime types is empty, this method return true
530
+         *
531
+         *    @since     1.0
532
+         *    @version   1.0
533
+         *    @param     string      $mime
534
+         *    @return    boolean
535
+         *    @method    boolean     checkMimeType
536
+         */
537 537
         public function checkMimeType($mime)
538 538
         {
539 539
             if (count($this->allowed_mime_types) == 0) {
@@ -542,26 +542,26 @@  discard block
 block discarded – undo
542 542
             return in_array(strtolower($mime), $this->allowed_mime_types);
543 543
         }
544 544
         /**
545
-        *    Retrive status of upload
546
-        *
547
-        *    @since     1.0
548
-        *    @version   1.0
549
-        *    @return    boolean
550
-        *    @method    boolean    getStatus
551
-        */
545
+         *    Retrive status of upload
546
+         *
547
+         *    @since     1.0
548
+         *    @version   1.0
549
+         *    @return    boolean
550
+         *    @method    boolean    getStatus
551
+         */
552 552
         public function getStatus()
553 553
         {
554 554
             return $this->file['status'];
555 555
         }
556 556
         /**
557
-        *    Check valid path
558
-        *
559
-        *    @since        1.0
560
-        *    @version    1.0.1
561
-        *    @param        string    $filename
562
-        *    @return     boolean
563
-        *    @method     boolean    isDirpath
564
-        */
557
+         *    Check valid path
558
+         *
559
+         *    @since        1.0
560
+         *    @version    1.0.1
561
+         *    @param        string    $filename
562
+         *    @return     boolean
563
+         *    @method     boolean    isDirpath
564
+         */
565 565
         public function isDirpath($path)
566 566
         {
567 567
             if (!empty( $path) && (is_string( $path) || is_numeric($path) )) {
@@ -574,26 +574,26 @@  discard block
 block discarded – undo
574 574
             return false;
575 575
         }
576 576
         /**
577
-        *    Allow overwriting files
578
-        *
579
-        *    @since      1.0
580
-        *    @version    1.0
581
-        *    @return     object
582
-        *    @method     boolean    allowOverwriting
583
-        */
577
+         *    Allow overwriting files
578
+         *
579
+         *    @since      1.0
580
+         *    @version    1.0
581
+         *    @return     object
582
+         *    @method     boolean    allowOverwriting
583
+         */
584 584
         public function allowOverwriting()
585 585
         {
586 586
             $this->overwrite_file = true;
587 587
             return $this;
588 588
         }
589 589
         /**
590
-        *    File info
591
-        *
592
-        *    @since      1.0
593
-        *    @version    1.0
594
-        *    @return     object
595
-        *    @method     object    getInfo
596
-        */
590
+         *    File info
591
+         *
592
+         *    @since      1.0
593
+         *    @version    1.0
594
+         *    @return     object
595
+         *    @method     object    getInfo
596
+         */
597 597
         public function getInfo()
598 598
         {
599 599
             return (object)$this->file;
@@ -611,13 +611,13 @@  discard block
 block discarded – undo
611 611
 
612 612
         
613 613
         /**
614
-        *    Upload file
615
-        *
616
-        *    @since     1.0
617
-        *    @version   1.0.1
618
-        *    @return    boolean
619
-        *    @method    boolean    save
620
-        */
614
+         *    Upload file
615
+         *
616
+         *    @since     1.0
617
+         *    @version   1.0.1
618
+         *    @return    boolean
619
+         *    @method    boolean    save
620
+         */
621 621
         public function save(){
622 622
             if (count($this->file_array) > 0 && array_key_exists($this->input, $this->file_array)) {
623 623
                 // set original filename if not have a new name
@@ -674,15 +674,15 @@  discard block
 block discarded – undo
674 674
 
675 675
 
676 676
         /**
677
-        *    File size for humans.
678
-        *
679
-        *    @since      1.0
680
-        *    @version    1.0
681
-        *    @param      integer    $bytes
682
-        *    @param      integer    $precision
683
-        *    @return     string
684
-        *    @method     string     sizeFormat
685
-        */
677
+         *    File size for humans.
678
+         *
679
+         *    @since      1.0
680
+         *    @version    1.0
681
+         *    @param      integer    $bytes
682
+         *    @param      integer    $precision
683
+         *    @return     string
684
+         *    @method     string     sizeFormat
685
+         */
686 686
         public function sizeFormat($size, $precision = 2)
687 687
         {
688 688
             if($size > 0){
@@ -695,14 +695,14 @@  discard block
 block discarded – undo
695 695
 
696 696
         
697 697
         /**
698
-        *    Convert human file size to bytes
699
-        *
700
-        *    @since      1.0
701
-        *    @version    1.0.1
702
-        *    @param      integer|double    $size
703
-        *    @return     integer|double
704
-        *    @method     string     sizeInBytes
705
-        */
698
+         *    Convert human file size to bytes
699
+         *
700
+         *    @since      1.0
701
+         *    @version    1.0.1
702
+         *    @param      integer|double    $size
703
+         *    @return     integer|double
704
+         *    @method     string     sizeInBytes
705
+         */
706 706
         public function sizeInBytes($size)
707 707
         {
708 708
             $unit = 'B';
@@ -754,7 +754,7 @@  discard block
 block discarded – undo
754 754
                 return true;
755 755
             }
756 756
 
757
-             //check for php upload error
757
+                //check for php upload error
758 758
             if(is_numeric($this->file['error']) && $this->file['error'] > 0){
759 759
                 $this->setError($this->getPhpUploadErrorMessageByCode($this->file['error']));
760 760
                 return true;
@@ -766,7 +766,7 @@  discard block
 block discarded – undo
766 766
                 return true;
767 767
             }
768 768
 
769
-             // Check file size
769
+                // Check file size
770 770
             if ($this->max_file_size > 0 && $this->max_file_size < $this->file['size']) {
771 771
                 $this->setError(sprintf($this->error_messages['max_file_size'], $this->sizeFormat($this->max_file_size)));
772 772
                 return true;
Please login to merge, or discard this patch.
Spacing   +47 added lines, -47 removed lines patch added patch discarded remove patch
@@ -37,7 +37,7 @@  discard block
 block discarded – undo
37 37
     *    @package FileUpload
38 38
     *    @version 1.5
39 39
     */
40
-    class Upload extends BaseClass{
40
+    class Upload extends BaseClass {
41 41
 
42 42
         /**
43 43
         *   Version
@@ -69,7 +69,7 @@  discard block
 block discarded – undo
69 69
         *    @version    1.0
70 70
         *    @var        array
71 71
         */
72
-        private $file_array    = array();
72
+        private $file_array = array();
73 73
 
74 74
         /**
75 75
         *    If the file you are trying to upload already exists it will
@@ -119,7 +119,7 @@  discard block
 block discarded – undo
119 119
         *    @version    1.0
120 120
         *    @var        float
121 121
         */
122
-        private $max_file_size= 0.0;
122
+        private $max_file_size = 0.0;
123 123
 
124 124
         /**
125 125
         *    List of allowed mime types
@@ -211,11 +211,11 @@  discard block
 block discarded – undo
211 211
         *    @return    object
212 212
         *    @method    object    __construct
213 213
         */
214
-        public function __construct(){
214
+        public function __construct() {
215 215
             parent::__construct();
216 216
 
217 217
             Loader::lang('file_upload');
218
-            $obj =& get_instance();
218
+            $obj = & get_instance();
219 219
 
220 220
             $this->error_messages = array(
221 221
                 'upload_err_ini_size' => $obj->lang->get('fu_upload_err_ini_size'),
@@ -232,15 +232,15 @@  discard block
 block discarded – undo
232 232
             );
233 233
 
234 234
             $this->file = array(
235
-                'status'                =>    false,    // True: success upload
236
-                'mime'                  =>    '',       // Empty string
237
-                'filename'              =>    '',       // Empty string
238
-                'original'              =>    '',       // Empty string
239
-                'size'                  =>    0,        // 0 Bytes
240
-                'sizeFormated'          =>    '0B',     // 0 Bytes
241
-                'destination'           =>    './',     // Default: ./
242
-                'allowed_mime_types'    =>    array(),  // Allowed mime types
243
-                'error'                 =>    null,        // File error
235
+                'status'                =>    false, // True: success upload
236
+                'mime'                  =>    '', // Empty string
237
+                'filename'              =>    '', // Empty string
238
+                'original'              =>    '', // Empty string
239
+                'size'                  =>    0, // 0 Bytes
240
+                'sizeFormated'          =>    '0B', // 0 Bytes
241
+                'destination'           =>    './', // Default: ./
242
+                'allowed_mime_types'    =>    array(), // Allowed mime types
243
+                'error'                 =>    null, // File error
244 244
             );
245 245
 
246 246
             // Change dir to current dir
@@ -250,7 +250,7 @@  discard block
 block discarded – undo
250 250
             if (isset($_FILES) && is_array($_FILES)) {
251 251
                 $this->file_array = $_FILES;
252 252
             }
253
-            $this->logger->info('The upload file information are : ' .stringfy_vars($this->file_array));
253
+            $this->logger->info('The upload file information are : ' . stringfy_vars($this->file_array));
254 254
         }
255 255
         /**
256 256
         *    Set input.
@@ -266,7 +266,7 @@  discard block
 block discarded – undo
266 266
         */
267 267
         public function setInput($input)
268 268
         {
269
-            if (!empty($input) && (is_string($input) || is_numeric($input) )) {
269
+            if (!empty($input) && (is_string($input) || is_numeric($input))) {
270 270
                 $this->input = $input;
271 271
             }
272 272
             return $this;
@@ -302,7 +302,7 @@  discard block
 block discarded – undo
302 302
         */
303 303
         public function setAutoFilename()
304 304
         {
305
-            $this->filename = sha1(mt_rand(1, 9999).uniqid());
305
+            $this->filename = sha1(mt_rand(1, 9999) . uniqid());
306 306
             $this->filename .= time();
307 307
             return $this;
308 308
         }
@@ -323,7 +323,7 @@  discard block
 block discarded – undo
323 323
                 $php_size = $this->sizeInBytes((int) ini_get('upload_max_filesize'));
324 324
                 // Calculate difference
325 325
                 if ($php_size < $file_size) {
326
-                    $this->logger->warning('The upload max file size you set [' .$file_size. '] is greather than the PHP configuration for upload max file size [' .$php_size. ']');
326
+                    $this->logger->warning('The upload max file size you set [' . $file_size . '] is greather than the PHP configuration for upload max file size [' . $php_size . ']');
327 327
                 }
328 328
                 $this->max_file_size = $file_size;
329 329
             }
@@ -341,7 +341,7 @@  discard block
 block discarded – undo
341 341
         public function setAllowedMimeTypes(array $mimes)
342 342
         {
343 343
             if (count($mimes) > 0) {
344
-                array_map(array($this , 'setAllowMimeType'), $mimes);
344
+                array_map(array($this, 'setAllowMimeType'), $mimes);
345 345
             }
346 346
             return $this;
347 347
         }
@@ -406,7 +406,7 @@  discard block
 block discarded – undo
406 406
         {
407 407
             if (!empty($name) && is_string($name)) {
408 408
                 if (array_key_exists($name, $this->mime_helping)) {
409
-                    return $this->setAllowedMimeTypes($this->mime_helping[ $name ]);
409
+                    return $this->setAllowedMimeTypes($this->mime_helping[$name]);
410 410
                 }
411 411
             }
412 412
             return $this;
@@ -425,8 +425,8 @@  discard block
 block discarded – undo
425 425
         */
426 426
         public function setUploadFunction($function)
427 427
         {
428
-            if (!empty($function) && (is_array($function) || is_string($function) )) {
429
-                if (is_callable( $function)) {
428
+            if (!empty($function) && (is_array($function) || is_string($function))) {
429
+                if (is_callable($function)) {
430 430
                     $this->upload_function = $function;
431 431
                 }
432 432
             }
@@ -471,8 +471,8 @@  discard block
 block discarded – undo
471 471
                         $this->destination_directory = $destination_directory;
472 472
                         chdir($destination_directory);
473 473
                     }
474
-                    else{
475
-                        $this->logger->warning('Can not create the upload directory [' .$destination_directory. ']');
474
+                    else {
475
+                        $this->logger->warning('Can not create the upload directory [' . $destination_directory . ']');
476 476
                     }
477 477
                 }
478 478
             }
@@ -522,7 +522,7 @@  discard block
 block discarded – undo
522 522
         public function isFilename($filename)
523 523
         {
524 524
             $filename = basename($filename);
525
-            return (!empty($filename) && (is_string( $filename) || is_numeric($filename)));
525
+            return (!empty($filename) && (is_string($filename) || is_numeric($filename)));
526 526
         }
527 527
         /**
528 528
         *    Validate mime type with allowed mime types,
@@ -564,11 +564,11 @@  discard block
 block discarded – undo
564 564
         */
565 565
         public function isDirpath($path)
566 566
         {
567
-            if (!empty( $path) && (is_string( $path) || is_numeric($path) )) {
567
+            if (!empty($path) && (is_string($path) || is_numeric($path))) {
568 568
                 if (DIRECTORY_SEPARATOR == '/') {
569
-                    return (preg_match( '/^[^*?"<>|:]*$/' , $path) == 1 );
569
+                    return (preg_match('/^[^*?"<>|:]*$/', $path) == 1);
570 570
                 } else {
571
-                    return (preg_match( "/^[^*?\"<>|:]*$/" , substr($path,2) ) == 1);
571
+                    return (preg_match("/^[^*?\"<>|:]*$/", substr($path, 2)) == 1);
572 572
                 }
573 573
             }
574 574
             return false;
@@ -596,7 +596,7 @@  discard block
 block discarded – undo
596 596
         */
597 597
         public function getInfo()
598 598
         {
599
-            return (object)$this->file;
599
+            return (object) $this->file;
600 600
         }
601 601
 
602 602
 
@@ -604,7 +604,7 @@  discard block
 block discarded – undo
604 604
          * Check if the file is uploaded
605 605
          * @return boolean
606 606
          */
607
-        public function isUploaded(){
607
+        public function isUploaded() {
608 608
             return isset($this->file_array[$this->input])
609 609
             && is_uploaded_file($this->file_array[$this->input]['tmp_name']);
610 610
         }
@@ -618,13 +618,13 @@  discard block
 block discarded – undo
618 618
         *    @return    boolean
619 619
         *    @method    boolean    save
620 620
         */
621
-        public function save(){
621
+        public function save() {
622 622
             if (count($this->file_array) > 0 && array_key_exists($this->input, $this->file_array)) {
623 623
                 // set original filename if not have a new name
624 624
                 if (empty($this->filename)) {
625 625
                     $this->filename = $this->file_array[$this->input]['name'];
626 626
                 }
627
-                else{
627
+                else {
628 628
                     // Replace %s for extension in filename
629 629
                     // Before: /[\w\d]*(.[\d\w]+)$/i
630 630
                     // After: /^[\s[:alnum:]\-\_\.]*\.([\d\w]+)$/iu
@@ -648,10 +648,10 @@  discard block
 block discarded – undo
648 648
                 $this->file['filename']     = $this->filename;
649 649
                 $this->file['error']        = $this->file_array[$this->input]['error'];
650 650
 
651
-                $this->logger->info('The upload file information to process is : ' .stringfy_vars($this->file));
651
+                $this->logger->info('The upload file information to process is : ' . stringfy_vars($this->file));
652 652
 
653 653
                 $error = $this->uploadHasError();
654
-                if($error){
654
+                if ($error) {
655 655
                     return false;
656 656
                 }
657 657
                 // Execute input callback
@@ -685,10 +685,10 @@  discard block
 block discarded – undo
685 685
         */
686 686
         public function sizeFormat($size, $precision = 2)
687 687
         {
688
-            if($size > 0){
688
+            if ($size > 0) {
689 689
                 $base       = log($size) / log(1024);
690 690
                 $suffixes   = array('B', 'K', 'M', 'G', 'T');
691
-                return round(pow(1024, $base - floor($base)), $precision) . ( isset($suffixes[floor($base)]) ? $suffixes[floor($base)] : '');
691
+                return round(pow(1024, $base - floor($base)), $precision) . (isset($suffixes[floor($base)]) ? $suffixes[floor($base)] : '');
692 692
             }
693 693
             return null;
694 694
         }
@@ -712,14 +712,14 @@  discard block
 block discarded – undo
712 712
             if (array_key_exists('unit', $matches)) {
713 713
                 $unit = strtoupper($matches['unit']);
714 714
             }
715
-            return (floatval($matches['size']) * pow(1024, $units[$unit]) ) ;
715
+            return (floatval($matches['size']) * pow(1024, $units[$unit]));
716 716
         }
717 717
 
718 718
         /**
719 719
          * Get the upload error message
720 720
          * @return string
721 721
          */
722
-        public function getError(){
722
+        public function getError() {
723 723
             return $this->error;
724 724
         }
725 725
 
@@ -727,7 +727,7 @@  discard block
 block discarded – undo
727 727
          * Set the upload error message
728 728
          * @param string $message the upload error message to set
729 729
          */
730
-        public function setError($message){
730
+        public function setError($message) {
731 731
             $this->logger->info('The file upload got error : ' . $message);
732 732
             $this->error = $message;
733 733
         }
@@ -737,9 +737,9 @@  discard block
 block discarded – undo
737 737
          * @param string $type the type of callback "input" or "output"
738 738
          * @return void 
739 739
          */
740
-        protected function runCallback($type){
741
-            if (!empty( $this->callbacks[$type])) {
742
-                call_user_func($this->callbacks[$type], (object)$this->file);
740
+        protected function runCallback($type) {
741
+            if (!empty($this->callbacks[$type])) {
742
+                call_user_func($this->callbacks[$type], (object) $this->file);
743 743
             }
744 744
         }
745 745
 
@@ -747,21 +747,21 @@  discard block
 block discarded – undo
747 747
          * Check if file upload has error
748 748
          * @return boolean
749 749
          */
750
-        protected function uploadHasError(){
750
+        protected function uploadHasError() {
751 751
             //check if file upload is  allowed in the configuration
752
-            if(! ini_get('file_uploads')){
752
+            if (!ini_get('file_uploads')) {
753 753
                 $this->setError($this->error_messages['file_uploads']);
754 754
                 return true;
755 755
             }
756 756
 
757 757
              //check for php upload error
758
-            if(is_numeric($this->file['error']) && $this->file['error'] > 0){
758
+            if (is_numeric($this->file['error']) && $this->file['error'] > 0) {
759 759
                 $this->setError($this->getPhpUploadErrorMessageByCode($this->file['error']));
760 760
                 return true;
761 761
             }
762 762
             
763 763
             //check for mime type
764
-            if (! $this->checkMimeType($this->file['mime'])) {
764
+            if (!$this->checkMimeType($this->file['mime'])) {
765 765
                 $this->setError($this->error_messages['accept_file_types']);
766 766
                 return true;
767 767
             }
@@ -785,7 +785,7 @@  discard block
 block discarded – undo
785 785
          * @param  int $code the error code
786 786
          * @return string the error message
787 787
          */
788
-        private function getPhpUploadErrorMessageByCode($code){
788
+        private function getPhpUploadErrorMessageByCode($code) {
789 789
             $codeMessageMaps = array(
790 790
                 1 => $this->error_messages['upload_err_ini_size'],
791 791
                 2 => $this->error_messages['upload_err_form_size'],
Please login to merge, or discard this patch.
classes/controllers/Home.php 1 patch
Indentation   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -1,25 +1,25 @@
 block discarded – undo
1 1
 <?php
2
-	defined('ROOT_PATH') || exit('Access denied');
2
+    defined('ROOT_PATH') || exit('Access denied');
3 3
 
4
-	/**
5
-	 * 
6
-	 */
7
-	class Home extends Controller {
4
+    /**
5
+     * 
6
+     */
7
+    class Home extends Controller {
8 8
 
9
-		/**
10
-		 * the class constructor
11
-		 */
12
-		public function __construct() {
13
-			parent::__construct();
14
-		}
9
+        /**
10
+         * the class constructor
11
+         */
12
+        public function __construct() {
13
+            parent::__construct();
14
+        }
15 15
 
16
-		/**
17
-		 * The default method
18
-		 * @return null
19
-		 */
20
-		public function index() {
21
-			Loader::library('Assets');
22
-			Loader::library('Html');
23
-			$this->response->render('home');
24
-		}
25
-	}
16
+        /**
17
+         * The default method
18
+         * @return null
19
+         */
20
+        public function index() {
21
+            Loader::library('Assets');
22
+            Loader::library('Html');
23
+            $this->response->render('home');
24
+        }
25
+    }
Please login to merge, or discard this patch.
config/autoload.php 1 patch
Indentation   +86 added lines, -86 removed lines patch added patch discarded remove patch
@@ -1,94 +1,94 @@
 block discarded – undo
1 1
 <?php
2
-	defined('ROOT_PATH') || exit('Access denied');
3
-	/**
4
-	 * TNH Framework
5
-	 *
6
-	 * A simple PHP framework created using the concept of codeigniter with bootstrap twitter
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
-	*/
2
+    defined('ROOT_PATH') || exit('Access denied');
3
+    /**
4
+     * TNH Framework
5
+     *
6
+     * A simple PHP framework created using the concept of codeigniter with bootstrap twitter
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 26
 
27
-	/**
28
-	* This file contains the configuration of resources that you want to load automatically: 
29
-	* personal or system libraries, configuration files, models, 
30
-	* personal functions or systems that are used most often in your application 
31
-	* instead of loading them every time you want to use it.
32
-	* Note: loading a lot of resources can decrease the performance of your application.
33
-	*/
27
+    /**
28
+     * This file contains the configuration of resources that you want to load automatically: 
29
+     * personal or system libraries, configuration files, models, 
30
+     * personal functions or systems that are used most often in your application 
31
+     * instead of loading them every time you want to use it.
32
+     * Note: loading a lot of resources can decrease the performance of your application.
33
+     */
34 34
 
35 35
 
36
-	/**
37
-	* If you have personal libraries or systems to load automatically, then list them in the following array.
38
-	* For example :
39
-	*
40
-	*	$autoload['libraries'] = array('library1', 'library1');
41
-	*
42
-	* Note: Personal libraries have priority over system libraries, 
43
-	* ie the loading order is as follows: it looks in the folder of the personal libraries, 
44
-	* if it is found, it is loaded, if not , we search in the system libraries folder, 
45
-	* before returning an error in case it does not find it.
46
-	*/
47
-	$autoload['libraries'] = array();
36
+    /**
37
+     * If you have personal libraries or systems to load automatically, then list them in the following array.
38
+     * For example :
39
+     *
40
+     *	$autoload['libraries'] = array('library1', 'library1');
41
+     *
42
+     * Note: Personal libraries have priority over system libraries, 
43
+     * ie the loading order is as follows: it looks in the folder of the personal libraries, 
44
+     * if it is found, it is loaded, if not , we search in the system libraries folder, 
45
+     * before returning an error in case it does not find it.
46
+     */
47
+    $autoload['libraries'] = array();
48 48
 
49
-	/**
50
-	* If you have configuration files to load automatically, then list them in the following array.
51
-	* For example :
52
-	*
53
-	*	$autoload['config'] = array('config1', 'config2');
54
-	*
55
-	* Note 1: the file name must have as prefix "config_" 
56
-	* for example "config_name_of_the_file_config.php" and contains as configuration variable the array $config,
57
-	* otherwise the system can not find this configuration file.
58
-	* For example :
59
-	*
60
-	*	$config['key1'] = value1;
61
-	* 	$config['key2'] = value2;
62
-	*
63
-	* Note 2: the files to be loaded must be in the folder defined by the constant "CONFIG_PATH" in "index.php".
64
-	*/
65
-	$autoload['config'] = array();
49
+    /**
50
+     * If you have configuration files to load automatically, then list them in the following array.
51
+     * For example :
52
+     *
53
+     *	$autoload['config'] = array('config1', 'config2');
54
+     *
55
+     * Note 1: the file name must have as prefix "config_" 
56
+     * for example "config_name_of_the_file_config.php" and contains as configuration variable the array $config,
57
+     * otherwise the system can not find this configuration file.
58
+     * For example :
59
+     *
60
+     *	$config['key1'] = value1;
61
+     * 	$config['key2'] = value2;
62
+     *
63
+     * Note 2: the files to be loaded must be in the folder defined by the constant "CONFIG_PATH" in "index.php".
64
+     */
65
+    $autoload['config'] = array();
66 66
 
67
-	/**
68
-	* If you have models to load automatically, then list them in the following table.
69
-	* For example :
70
-	*
71
-	*	$autoload['models'] = array('model1', 'model2');
72
-	*/
73
-	$autoload['models'] = array();
67
+    /**
68
+     * If you have models to load automatically, then list them in the following table.
69
+     * For example :
70
+     *
71
+     *	$autoload['models'] = array('model1', 'model2');
72
+     */
73
+    $autoload['models'] = array();
74 74
 
75
-	/**
76
-	* If you have system or personal functions to load automatically, specify them in the following array.
77
-	* For example :
78
-	*
79
-	* 	$autoload['functions'] = array('function1', 'function2');
80
-	*
81
-	* Note: Personal functions have priority over system functions,
82
-	* that is to say that the order of loading is the following : it looks in the directory of the personal functions,
83
-	* if it is found, it is loaded, otherwise, it looks in the directory of the system functions,
84
-	* before returning an error in case he does not find it.
85
-	*/
86
-	$autoload['functions'] = array();
75
+    /**
76
+     * If you have system or personal functions to load automatically, specify them in the following array.
77
+     * For example :
78
+     *
79
+     * 	$autoload['functions'] = array('function1', 'function2');
80
+     *
81
+     * Note: Personal functions have priority over system functions,
82
+     * that is to say that the order of loading is the following : it looks in the directory of the personal functions,
83
+     * if it is found, it is loaded, otherwise, it looks in the directory of the system functions,
84
+     * before returning an error in case he does not find it.
85
+     */
86
+    $autoload['functions'] = array();
87 87
 	
88
-	/**
89
-	* If you have system or personal language to load automatically, specify them in the following array.
90
-	* For example :
91
-	*
92
-	* 	$autoload['languages'] = array('lang1', 'lang2');
93
-	*/
94
-	$autoload['languages'] = array();
88
+    /**
89
+     * If you have system or personal language to load automatically, specify them in the following array.
90
+     * For example :
91
+     *
92
+     * 	$autoload['languages'] = array('lang1', 'lang2');
93
+     */
94
+    $autoload['languages'] = array();
Please login to merge, or discard this patch.
config/database.php 1 patch
Indentation   +114 added lines, -114 removed lines patch added patch discarded remove patch
@@ -1,127 +1,127 @@
 block discarded – undo
1 1
 <?php
2
-	defined('ROOT_PATH') || exit('Access denied');
3
-	/**
4
-	 * TNH Framework
5
-	 *
6
-	 * A simple PHP framework created using the concept of codeigniter with bootstrap twitter
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
-	*/
2
+    defined('ROOT_PATH') || exit('Access denied');
3
+    /**
4
+     * TNH Framework
5
+     *
6
+     * A simple PHP framework created using the concept of codeigniter with bootstrap twitter
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 26
 	
27
-	/**
28
-	* This file contains the connection information to your database, this file is read when you load the "Database" library.
29
-	* You will find all its configuration parameters at your web hosting.
30
-	*/
27
+    /**
28
+     * This file contains the connection information to your database, this file is read when you load the "Database" library.
29
+     * You will find all its configuration parameters at your web hosting.
30
+     */
31 31
 	
32
-	/**
33
-	* The type or driver of your database.
34
-	*
35
-	* Note: the "Database" library uses the PHP PDO extension to interact with your database, 
36
-	* so most of the PDO supported drivers namely: mysql, pgsql, sqlite, oracle are accepted.
37
-	* For example :
38
-	*
39
-	* 	$db['driver'] = 'mysql'; // for MySQL Database
40
-	* or
41
-	* 	$db['driver'] = 'pgsql'; // for PostgreSQL Database
42
-	* or
43
-	* 	$db['driver'] = 'sqlite'; // for SQLite Database
44
-	* or
45
-	* 	$db['driver'] = 'oracle'; // for Oracle Database
46
-	*
47
-	*/
48
-	$db['driver'] = 'mysql';
32
+    /**
33
+     * The type or driver of your database.
34
+     *
35
+     * Note: the "Database" library uses the PHP PDO extension to interact with your database, 
36
+     * so most of the PDO supported drivers namely: mysql, pgsql, sqlite, oracle are accepted.
37
+     * For example :
38
+     *
39
+     * 	$db['driver'] = 'mysql'; // for MySQL Database
40
+     * or
41
+     * 	$db['driver'] = 'pgsql'; // for PostgreSQL Database
42
+     * or
43
+     * 	$db['driver'] = 'sqlite'; // for SQLite Database
44
+     * or
45
+     * 	$db['driver'] = 'oracle'; // for Oracle Database
46
+     *
47
+     */
48
+    $db['driver'] = 'mysql';
49 49
 	
50
-	/**
51
-	 *  The address of your database server
52
-	 *
53
-	 * It can be a domain name or IP address, for example:
54
-	 *	$db['hostname'] = 'localhost';
55
-	 * or
56
-	 *	$db['hostname'] = 'mysql.host.com';
57
-	 * or
58
-	 *	$db['hostname'] = '187.15.14.17';
59
-	 *	* or if port is not a standart port
60
-	 *	$db['hostname'] = 'mydb.server.com:6356';
61
-	 */
62
-	$db['hostname'] = 'localhost';
50
+    /**
51
+     *  The address of your database server
52
+     *
53
+     * It can be a domain name or IP address, for example:
54
+     *	$db['hostname'] = 'localhost';
55
+     * or
56
+     *	$db['hostname'] = 'mysql.host.com';
57
+     * or
58
+     *	$db['hostname'] = '187.15.14.17';
59
+     *	* or if port is not a standart port
60
+     *	$db['hostname'] = 'mydb.server.com:6356';
61
+     */
62
+    $db['hostname'] = 'localhost';
63 63
 	
64
-	/**
65
-	* The username of your database server
66
-	* for example :
67
-	*
68
-	*	$db['username'] = 'root';
69
-	* or
70
-	*	$db['username'] = 'myusername';
71
-	*/
72
-	$db['username'] = 'root';
64
+    /**
65
+     * The username of your database server
66
+     * for example :
67
+     *
68
+     *	$db['username'] = 'root';
69
+     * or
70
+     *	$db['username'] = 'myusername';
71
+     */
72
+    $db['username'] = 'root';
73 73
 	
74 74
 	
75
-	/**
76
-	* The password of your database server.
77
-	*
78
-	* Note: Some configuration settings on some database management systems do not allow 
79
-	* connection with a user without password, so it is recommended to set a password for this user for a security measure.
80
-	* for example :
81
-	*
82
-	*	$db['password'] = ''; //for an empty password, this is the case most often, if you are in local, ie for the user "root".
83
-	* or
84
-	* 	$db['password'] = 'M@5CUR3P@$$W0rd';
85
-	*/
86
-	$db['password'] = '';
75
+    /**
76
+     * The password of your database server.
77
+     *
78
+     * Note: Some configuration settings on some database management systems do not allow 
79
+     * connection with a user without password, so it is recommended to set a password for this user for a security measure.
80
+     * for example :
81
+     *
82
+     *	$db['password'] = ''; //for an empty password, this is the case most often, if you are in local, ie for the user "root".
83
+     * or
84
+     * 	$db['password'] = 'M@5CUR3P@$$W0rd';
85
+     */
86
+    $db['password'] = '';
87 87
 	
88
-	/**
89
-	* The name of your database
90
-	*
91
-	* for example :
92
-	*
93
-	*	$db['database'] = 'database_name';
94
-	*/
95
-	$db['database'] = '';
88
+    /**
89
+     * The name of your database
90
+     *
91
+     * for example :
92
+     *
93
+     *	$db['database'] = 'database_name';
94
+     */
95
+    $db['database'] = '';
96 96
 	
97 97
 	
98
-	/**
99
-	* The character set that will be used by the database server.
100
-	* for example :
101
-	*
102
-	* $db['charset'] = 'utf8';
103
-	*/
104
-	$db['charset'] = 'utf8';
98
+    /**
99
+     * The character set that will be used by the database server.
100
+     * for example :
101
+     *
102
+     * $db['charset'] = 'utf8';
103
+     */
104
+    $db['charset'] = 'utf8';
105 105
 	
106
-	/**
107
-	* In addition to the character set, a certain database management system allows you to 
108
-	* choose how the data will be classified (ORDER BY) by what is called a "COLLATE". 
109
-	* This makes it possible, for example, to answer the classic problem of case sensitivity.
110
-	* for example :
111
-	*	$db['collation'] = 'utf8_general_ci';
112
-	*/
113
-	$db['collation'] = 'utf8_general_ci';
106
+    /**
107
+     * In addition to the character set, a certain database management system allows you to 
108
+     * choose how the data will be classified (ORDER BY) by what is called a "COLLATE". 
109
+     * This makes it possible, for example, to answer the classic problem of case sensitivity.
110
+     * for example :
111
+     *	$db['collation'] = 'utf8_general_ci';
112
+     */
113
+    $db['collation'] = 'utf8_general_ci';
114 114
 	
115 115
 	
116
-	/**
117
-	* If your tables in your database contain prefixes, this is the case most on some application, 
118
-	* to avoid the conflict of name of the tables between different database, 
119
-	* it is possible to define prefixes for the tables.
120
-	* for example :
121
-	*
122
-	* $db['prefix'] = 'pf_';
123
-	* or
124
-	*
125
-	* $db['prefix'] = 'my_db_';
126
-	*/
127
-	$db['prefix'] = '';
128 116
\ No newline at end of file
117
+    /**
118
+     * If your tables in your database contain prefixes, this is the case most on some application, 
119
+     * to avoid the conflict of name of the tables between different database, 
120
+     * it is possible to define prefixes for the tables.
121
+     * for example :
122
+     *
123
+     * $db['prefix'] = 'pf_';
124
+     * or
125
+     *
126
+     * $db['prefix'] = 'my_db_';
127
+     */
128
+    $db['prefix'] = '';
129 129
\ No newline at end of file
Please login to merge, or discard this patch.
config/routes.php 1 patch
Indentation   +85 added lines, -85 removed lines patch added patch discarded remove patch
@@ -1,88 +1,88 @@
 block discarded – undo
1 1
 <?php
2
-	defined('ROOT_PATH') || exit('Access denied');
3
-	/**
4
-	 * TNH Framework
5
-	 *
6
-	 * A simple PHP framework created using the concept of codeigniter with bootstrap twitter
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
-	*/
2
+    defined('ROOT_PATH') || exit('Access denied');
3
+    /**
4
+     * TNH Framework
5
+     *
6
+     * A simple PHP framework created using the concept of codeigniter with bootstrap twitter
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 26
 	
27
-	/**
28
-	* This file contains the configuration of your routes that is to say that links to your URLs.
29
-	* The index of the $route array contains the url address to capture and the value contains 
30
-	* the name of the module, controller and the method to call.
31
-	* For example :
32
-	*
33
-	* $route['/users/login'] = 'moduleUsers#UsersController@login_action';
34
-	*
35
-	* it means, if the user type in the address bar an URL like http://yoursite.com/users/login, 
36
-	* that will call the module "moduleUsers", the controller "UsersController" and the method "login_action".
37
-	* Note 1: it is recommended that each index in the $route array start with a slash "/" 
38
-	* otherwise on some system this will not work.
39
-	* Note 2: to define the default controller route (homepage) of your application you use only the index "/" 
40
-	* for example the following route represents the homepage:
41
-	* 
42
-	* $route['/'] = 'Home'; //only the controller or module name
43
-	*
44
-	* $route['/'] = 'Home@index'; //only the controller or module name with the method
45
-	*
46
-	* $route['/'] = 'module#Home@index'; //with module name, controller and method
47
-	*
48
-	* Note 3: If the method is not specified then the "index" method will be used as 
49
-	* default method. For example in the case of our homepage, this will be able to make:
50
-	* 
51
-	* $route['/'] = 'Home';
52
-	*
53
-	* Note 4: All methods called must have "public" visibility if you know the principle of 
54
-	* Object Oriented Programming, you know what visibility means (public, protected, private).
55
-	*
56
-	* In the index of your route, you can use the markers (:num), (:alpha), (:alnum) and (:any) which correspond 
57
-	* respectively to the regular expression [0-9], [a-zA-Z], [a-zA-Z0-9] and. *.
58
-	* For example :
59
-	*
60
-	* - $route['/profile/(:num)'] = 'UsersController@profile'; => http://yoursite.com/profile/4 will be captured but 
61
-	* http://yoursite.com/profile/a will not captured.
62
-	*
63
-	* - $route['/profile/(:alpha)'] = 'UsersController@profile'; => http://yoursite.com/profile/a will be captured 
64
-	* but http://yoursite.com/profile/1457 will not captured.
65
-	*
66
-	* - $route['/profile/(:alnum)'] = 'UsersController@profile'; => http://yoursite.com/profile/4a, 
67
-	* http://yoursite.com/profile/7 will be captured but http://yoursite.com/profile/7-dangerous will not captured.
68
-	*
69
-	* - $route['/(:any)'] = 'ArticleController@read'; => http://yoursite.com/1-my-super-article, 
70
-	* http://yoursite.com/7, will be captured.
71
-	* 
72
-	* Note 5: The order of definition of each route is important. 
73
-	* For example, the following definitions work:
74
-	*
75
-	* $route['/article/add'] = 'Article@add';
76
-	* $route['article/(:any)'] = 'Article@read';
77
-	*
78
-	* however, the following definitions does not work as intended
79
-	*
80
-	* $route['article/(:any)'] = 'Article@read';
81
-	* $route['/article/add'] = 'Article@add';
82
-	*
83
-	*/
27
+    /**
28
+     * This file contains the configuration of your routes that is to say that links to your URLs.
29
+     * The index of the $route array contains the url address to capture and the value contains 
30
+     * the name of the module, controller and the method to call.
31
+     * For example :
32
+     *
33
+     * $route['/users/login'] = 'moduleUsers#UsersController@login_action';
34
+     *
35
+     * it means, if the user type in the address bar an URL like http://yoursite.com/users/login, 
36
+     * that will call the module "moduleUsers", the controller "UsersController" and the method "login_action".
37
+     * Note 1: it is recommended that each index in the $route array start with a slash "/" 
38
+     * otherwise on some system this will not work.
39
+     * Note 2: to define the default controller route (homepage) of your application you use only the index "/" 
40
+     * for example the following route represents the homepage:
41
+     * 
42
+     * $route['/'] = 'Home'; //only the controller or module name
43
+     *
44
+     * $route['/'] = 'Home@index'; //only the controller or module name with the method
45
+     *
46
+     * $route['/'] = 'module#Home@index'; //with module name, controller and method
47
+     *
48
+     * Note 3: If the method is not specified then the "index" method will be used as 
49
+     * default method. For example in the case of our homepage, this will be able to make:
50
+     * 
51
+     * $route['/'] = 'Home';
52
+     *
53
+     * Note 4: All methods called must have "public" visibility if you know the principle of 
54
+     * Object Oriented Programming, you know what visibility means (public, protected, private).
55
+     *
56
+     * In the index of your route, you can use the markers (:num), (:alpha), (:alnum) and (:any) which correspond 
57
+     * respectively to the regular expression [0-9], [a-zA-Z], [a-zA-Z0-9] and. *.
58
+     * For example :
59
+     *
60
+     * - $route['/profile/(:num)'] = 'UsersController@profile'; => http://yoursite.com/profile/4 will be captured but 
61
+     * http://yoursite.com/profile/a will not captured.
62
+     *
63
+     * - $route['/profile/(:alpha)'] = 'UsersController@profile'; => http://yoursite.com/profile/a will be captured 
64
+     * but http://yoursite.com/profile/1457 will not captured.
65
+     *
66
+     * - $route['/profile/(:alnum)'] = 'UsersController@profile'; => http://yoursite.com/profile/4a, 
67
+     * http://yoursite.com/profile/7 will be captured but http://yoursite.com/profile/7-dangerous will not captured.
68
+     *
69
+     * - $route['/(:any)'] = 'ArticleController@read'; => http://yoursite.com/1-my-super-article, 
70
+     * http://yoursite.com/7, will be captured.
71
+     * 
72
+     * Note 5: The order of definition of each route is important. 
73
+     * For example, the following definitions work:
74
+     *
75
+     * $route['/article/add'] = 'Article@add';
76
+     * $route['article/(:any)'] = 'Article@read';
77
+     *
78
+     * however, the following definitions does not work as intended
79
+     *
80
+     * $route['article/(:any)'] = 'Article@read';
81
+     * $route['/article/add'] = 'Article@add';
82
+     *
83
+     */
84 84
 	
85
-	/**
86
-	 *  The default route like your home page
87
-	 */
88
-	$route['/'] = 'Home';
89 85
\ No newline at end of file
86
+    /**
87
+     *  The default route like your home page
88
+     */
89
+    $route['/'] = 'Home';
90 90
\ No newline at end of file
Please login to merge, or discard this patch.
config/config_pagination.php 1 patch
Indentation   +76 added lines, -76 removed lines patch added patch discarded remove patch
@@ -1,90 +1,90 @@
 block discarded – undo
1 1
 <?php
2
-	defined('ROOT_PATH') || exit('Access denied');
3
-	/**
4
-	 * TNH Framework
5
-	 *
6
-	 * A simple PHP framework created using the concept of codeigniter with bootstrap twitter
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
-	*/
2
+    defined('ROOT_PATH') || exit('Access denied');
3
+    /**
4
+     * TNH Framework
5
+     *
6
+     * A simple PHP framework created using the concept of codeigniter with bootstrap twitter
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 26
 	
27
-	/**
28
-	* This file contains the pagination library configuration of your application
29
-	*/
27
+    /**
28
+     * This file contains the pagination library configuration of your application
29
+     */
30 30
 
31
-	/**
32
-	 * Number of pagination digit
33
-	 */
34
-	$config['nb_link'] = 10;
31
+    /**
32
+     * Number of pagination digit
33
+     */
34
+    $config['nb_link'] = 10;
35 35
 
36
-	/**
37
-	* The pagination.
38
-	*
39
-	* Represents the number of data to display per page.
40
-	* Note: this value must be strictly greater than zero (0)
41
-	*/
42
-	$config['pagination_per_page'] = 10;
36
+    /**
37
+     * The pagination.
38
+     *
39
+     * Represents the number of data to display per page.
40
+     * Note: this value must be strictly greater than zero (0)
41
+     */
42
+    $config['pagination_per_page'] = 10;
43 43
 	
44 44
 
45
-	/**
46
-	 * The query string name used to fetch the current page
47
-	 */
48
-	$config['page_query_string_name'] = 'page';
45
+    /**
46
+     * The query string name used to fetch the current page
47
+     */
48
+    $config['page_query_string_name'] = 'page';
49 49
 
50
-	/**
51
-	 * The opened and closed tag for active link
52
-	 */
53
-	$config['active_link_open'] = '<li class = "active"><a href = "#">';
54
-	$config['active_link_close'] = '</a></li>';
50
+    /**
51
+     * The opened and closed tag for active link
52
+     */
53
+    $config['active_link_open'] = '<li class = "active"><a href = "#">';
54
+    $config['active_link_close'] = '</a></li>';
55 55
 
56
-	/**
57
-	 * The opened and closed tag for previous link
58
-	 */
59
-	$config['previous_open'] = '<li>';
60
-	$config['previous_close'] = '</li>';
56
+    /**
57
+     * The opened and closed tag for previous link
58
+     */
59
+    $config['previous_open'] = '<li>';
60
+    $config['previous_close'] = '</li>';
61 61
 
62
-	/**
63
-	 * The opened and closed tag for next link
64
-	 */
65
-	$config['next_open'] = '<li>';
66
-	$config['next_close'] = '</li>';
62
+    /**
63
+     * The opened and closed tag for next link
64
+     */
65
+    $config['next_open'] = '<li>';
66
+    $config['next_close'] = '</li>';
67 67
 
68 68
 
69
-	/**
70
-	 * The displayed text for previous and next link
71
-	 */
72
-	$config['previous_text'] = '&laquo;&laquo;';	
73
-	$config['next_text'] = '&raquo;&raquo;';
69
+    /**
70
+     * The displayed text for previous and next link
71
+     */
72
+    $config['previous_text'] = '&laquo;&laquo;';	
73
+    $config['next_text'] = '&raquo;&raquo;';
74 74
 
75
-	/**
76
-	 * The opened and closed tag for the pagination bloc
77
-	 */
78
-	$config['pagination_open'] = '<ul class = "pagination">';
79
-	$config['pagination_close'] = '</ul>';
75
+    /**
76
+     * The opened and closed tag for the pagination bloc
77
+     */
78
+    $config['pagination_open'] = '<ul class = "pagination">';
79
+    $config['pagination_close'] = '</ul>';
80 80
 
81
-	/**
82
-	 * The opened and closed tag for each link digit
83
-	 */
84
-	$config['digit_open'] = '<li>';
85
-	$config['digit_close'] = '</li>';
81
+    /**
82
+     * The opened and closed tag for each link digit
83
+     */
84
+    $config['digit_open'] = '<li>';
85
+    $config['digit_close'] = '</li>';
86 86
 
87
-	/**
88
-	 * The HTML attributes to use in each link
89
-	 */
90
-	$config['attributes'] = array();
91 87
\ No newline at end of file
88
+    /**
89
+     * The HTML attributes to use in each link
90
+     */
91
+    $config['attributes'] = array();
92 92
\ No newline at end of file
Please login to merge, or discard this patch.
core/classes/database/DatabaseQueryResult.php 2 patches
Indentation   +47 added lines, -47 removed lines patch added patch discarded remove patch
@@ -1,43 +1,43 @@  discard block
 block discarded – undo
1 1
 <?php
2 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
-  */
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 26
   
27
-  class DatabaseQueryResult{
27
+    class DatabaseQueryResult{
28 28
   	
29
-  	/**
30
-  	 * The database query result
31
-  	 * @var mixed
32
-  	 */
33
-     private $result  = null;
29
+        /**
30
+         * The database query result
31
+         * @var mixed
32
+         */
33
+        private $result  = null;
34 34
   	
35 35
     
36
-  	/**
37
-	 * The number of rows returned by the last query
38
-	 * @var int
39
-     */
40
-     private $numRows = 0;
36
+        /**
37
+         * The number of rows returned by the last query
38
+         * @var int
39
+         */
40
+        private $numRows = 0;
41 41
   	
42 42
 	
43 43
     /**
@@ -51,24 +51,24 @@  discard block
 block discarded – undo
51 51
     }
52 52
 
53 53
     
54
-     /**
55
-     * Return the query result
56
-     *
57
-     * @return mixed
58
-     */
54
+        /**
55
+         * Return the query result
56
+         *
57
+         * @return mixed
58
+         */
59 59
     public function getResult(){
60
-      return $this->result;
60
+        return $this->result;
61 61
     }
62 62
 
63 63
     /**
64 64
      * Set the query result
65 65
      * @param mixed $result the query result
66 66
      *
67
-	 * @return object DatabaseQueryResult
67
+     * @return object DatabaseQueryResult
68 68
      */
69 69
     public function setResult($result){
70
-      $this->result = $result;
71
-      return $this;
70
+        $this->result = $result;
71
+        return $this;
72 72
     }
73 73
     
74 74
     /**
@@ -77,18 +77,18 @@  discard block
 block discarded – undo
77 77
      * @return int
78 78
      */
79 79
     public function getNumRows(){
80
-      return $this->numRows;
80
+        return $this->numRows;
81 81
     }
82 82
 
83 83
     /**
84 84
      * Set the number of rows returned by the query
85 85
      * @param int $numRows the number of rows returned
86 86
      *
87
-	 * @return object DatabaseQueryResult
87
+     * @return object DatabaseQueryResult
88 88
      */
89 89
     public function setNumRows($numRows){
90
-      $this->numRows = $numRows;
91
-      return $this;
90
+        $this->numRows = $numRows;
91
+        return $this;
92 92
     }
93 93
    
94 94
 }
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -24,13 +24,13 @@  discard block
 block discarded – undo
24 24
    * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25 25
   */
26 26
   
27
-  class DatabaseQueryResult{
27
+  class DatabaseQueryResult {
28 28
   	
29 29
   	/**
30 30
   	 * The database query result
31 31
   	 * @var mixed
32 32
   	 */
33
-     private $result  = null;
33
+     private $result = null;
34 34
   	
35 35
     
36 36
   	/**
@@ -45,7 +45,7 @@  discard block
 block discarded – undo
45 45
      * @param mixed $result the query result
46 46
      * @param int $numRows the number of rows returned by the query
47 47
      */
48
-    public function __construct($result = null, $numRows = 0){
48
+    public function __construct($result = null, $numRows = 0) {
49 49
         $this->result = $result;
50 50
         $this->numRows = $numRows;
51 51
     }
@@ -56,7 +56,7 @@  discard block
 block discarded – undo
56 56
      *
57 57
      * @return mixed
58 58
      */
59
-    public function getResult(){
59
+    public function getResult() {
60 60
       return $this->result;
61 61
     }
62 62
 
@@ -66,7 +66,7 @@  discard block
 block discarded – undo
66 66
      *
67 67
 	 * @return object DatabaseQueryResult
68 68
      */
69
-    public function setResult($result){
69
+    public function setResult($result) {
70 70
       $this->result = $result;
71 71
       return $this;
72 72
     }
@@ -76,7 +76,7 @@  discard block
 block discarded – undo
76 76
      *
77 77
      * @return int
78 78
      */
79
-    public function getNumRows(){
79
+    public function getNumRows() {
80 80
       return $this->numRows;
81 81
     }
82 82
 
@@ -86,7 +86,7 @@  discard block
 block discarded – undo
86 86
      *
87 87
 	 * @return object DatabaseQueryResult
88 88
      */
89
-    public function setNumRows($numRows){
89
+    public function setNumRows($numRows) {
90 90
       $this->numRows = $numRows;
91 91
       return $this;
92 92
     }
Please login to merge, or discard this patch.
core/classes/database/DatabaseQueryBuilder.php 3 patches
Braces   +7 added lines, -14 removed lines patch added patch discarded remove patch
@@ -225,8 +225,7 @@  discard block
 block discarded – undo
225 225
       }
226 226
       if (empty($this->join)){
227 227
         $this->join = ' ' . $type . 'JOIN' . ' ' . $table . ' ON ' . $on;
228
-      }
229
-      else{
228
+      } else{
230 229
         $this->join = $this->join . ' ' . $type . 'JOIN' . ' ' . $table . ' ON ' . $on;
231 230
       }
232 231
       return $this;
@@ -334,8 +333,7 @@  discard block
 block discarded – undo
334 333
       $whereStr = '';
335 334
       if (is_array($where)){
336 335
         $whereStr = $this->getWhereStrIfIsArray($where, $type, $andOr, $escape);
337
-      }
338
-      else{
336
+      } else{
339 337
         if (is_array($op)){
340 338
           $whereStr = $this->getWhereStrIfOperatorIsArray($where, $op, $type, $escape);
341 339
         } else {
@@ -585,8 +583,7 @@  discard block
 block discarded – undo
585 583
       }
586 584
       if (! is_null($limitEnd)){
587 585
         $this->limit = $limit . ', ' . $limitEnd;
588
-      }
589
-      else{
586
+      } else{
590 587
         $this->limit = $limit;
591 588
       }
592 589
       return $this;
@@ -601,8 +598,7 @@  discard block
 block discarded – undo
601 598
     public function orderBy($orderBy, $orderDir = ' ASC'){
602 599
       if (stristr($orderBy, ' ') || $orderBy == 'rand()'){
603 600
         $this->orderBy = empty($this->orderBy) ? $orderBy : $this->orderBy . ', ' . $orderBy;
604
-      }
605
-      else{
601
+      } else{
606 602
         $this->orderBy = empty($this->orderBy) 
607 603
 						? ($orderBy . ' ' . strtoupper($orderDir)) 
608 604
 						: $this->orderBy . ', ' . $orderBy . ' ' . strtoupper($orderDir);
@@ -618,8 +614,7 @@  discard block
 block discarded – undo
618 614
     public function groupBy($field){
619 615
       if (is_array($field)){
620 616
         $this->groupBy = implode(', ', $field);
621
-      }
622
-      else{
617
+      } else{
623 618
         $this->groupBy = $field;
624 619
       }
625 620
       return $this;
@@ -636,14 +631,12 @@  discard block
 block discarded – undo
636 631
     public function having($field, $op = null, $val = null, $escape = true){
637 632
       if (is_array($op)){
638 633
         $this->having = $this->getHavingStrIfOperatorIsArray($field, $op, $escape);
639
-      }
640
-      else if (! in_array($op, $this->operatorList)){
634
+      } else if (! in_array($op, $this->operatorList)){
641 635
         if (is_null($op)){
642 636
           $op = '';
643 637
         }
644 638
         $this->having = $field . ' > ' . ($this->escape($op, $escape));
645
-      }
646
-      else{
639
+      } else{
647 640
         if (is_null($val)){
648 641
           $val = '';
649 642
         }
Please login to merge, or discard this patch.
Indentation   +391 added lines, -391 removed lines patch added patch discarded remove patch
@@ -1,108 +1,108 @@  discard block
 block discarded – undo
1 1
 <?php
2 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
-  class DatabaseQueryBuilder{
27
-  	/**
28
-  	 * The SQL SELECT statment
29
-  	 * @var string
30
-  	*/
31
-  	private $select              = '*';
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
+    class DatabaseQueryBuilder{
27
+        /**
28
+         * The SQL SELECT statment
29
+         * @var string
30
+         */
31
+        private $select              = '*';
32 32
   	
33
-  	/**
34
-  	 * The SQL FROM statment
35
-  	 * @var string
36
-  	*/
37
-      private $from              = null;
33
+        /**
34
+         * The SQL FROM statment
35
+         * @var string
36
+         */
37
+        private $from              = null;
38 38
   	
39
-  	/**
40
-  	 * The SQL WHERE statment
41
-  	 * @var string
42
-  	*/
43
-      private $where               = null;
39
+        /**
40
+         * The SQL WHERE statment
41
+         * @var string
42
+         */
43
+        private $where               = null;
44 44
   	
45
-  	/**
46
-  	 * The SQL LIMIT statment
47
-  	 * @var string
48
-  	*/
49
-      private $limit               = null;
45
+        /**
46
+         * The SQL LIMIT statment
47
+         * @var string
48
+         */
49
+        private $limit               = null;
50 50
   	
51
-  	/**
52
-  	 * The SQL JOIN statment
53
-  	 * @var string
54
-  	*/
55
-      private $join                = null;
51
+        /**
52
+         * The SQL JOIN statment
53
+         * @var string
54
+         */
55
+        private $join                = null;
56 56
   	
57
-  	/**
58
-  	 * The SQL ORDER BY statment
59
-  	 * @var string
60
-  	*/
61
-      private $orderBy             = null;
57
+        /**
58
+         * The SQL ORDER BY statment
59
+         * @var string
60
+         */
61
+        private $orderBy             = null;
62 62
   	
63
-  	/**
64
-  	 * The SQL GROUP BY statment
65
-  	 * @var string
66
-  	*/
67
-      private $groupBy             = null;
63
+        /**
64
+         * The SQL GROUP BY statment
65
+         * @var string
66
+         */
67
+        private $groupBy             = null;
68 68
   	
69
-  	/**
70
-  	 * The SQL HAVING statment
71
-  	 * @var string
72
-  	*/
73
-      private $having              = null;
69
+        /**
70
+         * The SQL HAVING statment
71
+         * @var string
72
+         */
73
+        private $having              = null;
74 74
   	
75
-  	/**
76
-  	 * The full SQL query statment after build for each command
77
-  	 * @var string
78
-  	*/
79
-      private $query               = null;
75
+        /**
76
+         * The full SQL query statment after build for each command
77
+         * @var string
78
+         */
79
+        private $query               = null;
80 80
   	
81
-  	/**
82
-  	 * The list of SQL valid operators
83
-  	 * @var array
84
-  	*/
81
+        /**
82
+         * The list of SQL valid operators
83
+         * @var array
84
+         */
85 85
     private $operatorList        = array('=','!=','<','>','<=','>=','<>');
86 86
   	
87 87
 	
88
-	/**
89
-	 * The prefix used in each database table
90
-	 * @var string
91
-	*/
88
+    /**
89
+     * The prefix used in each database table
90
+     * @var string
91
+     */
92 92
     private $prefix              = null;
93 93
     
94 94
 
95 95
     /**
96
-  	 * The PDO instance
97
-  	 * @var object
98
-  	*/
96
+     * The PDO instance
97
+     * @var object
98
+     */
99 99
     private $pdo                 = null;
100 100
 	
101
-  	/**
102
-  	 * The database driver name used
103
-  	 * @var string
104
-  	*/
105
-  	private $driver              = null;
101
+        /**
102
+         * The database driver name used
103
+         * @var string
104
+         */
105
+        private $driver              = null;
106 106
   	
107 107
 	
108 108
     /**
@@ -111,7 +111,7 @@  discard block
 block discarded – undo
111 111
      */
112 112
     public function __construct(PDO $pdo = null){
113 113
         if (is_object($pdo)){
114
-          $this->setPdo($pdo);
114
+            $this->setPdo($pdo);
115 115
         }
116 116
     }
117 117
 
@@ -121,16 +121,16 @@  discard block
 block discarded – undo
121 121
      * @return object        the current DatabaseQueryBuilder instance
122 122
      */
123 123
     public function from($table){
124
-	  if (is_array($table)){
124
+        if (is_array($table)){
125 125
         $froms = '';
126 126
         foreach($table as $key){
127
-          $froms .= $this->getPrefix() . $key . ', ';
127
+            $froms .= $this->getPrefix() . $key . ', ';
128 128
         }
129 129
         $this->from = rtrim($froms, ', ');
130
-      } else {
130
+        } else {
131 131
         $this->from = $this->getPrefix() . $table;
132
-      }
133
-      return $this;
132
+        }
133
+        return $this;
134 134
     }
135 135
 
136 136
     /**
@@ -139,9 +139,9 @@  discard block
 block discarded – undo
139 139
      * @return object        the current DatabaseQueryBuilder instance
140 140
      */
141 141
     public function select($fields){
142
-      $select = (is_array($fields) ? implode(', ', $fields) : $fields);
143
-      $this->select = (($this->select == '*' || empty($this->select)) ? $select : $this->select . ', ' . $select);
144
-      return $this;
142
+        $select = (is_array($fields) ? implode(', ', $fields) : $fields);
143
+        $this->select = (($this->select == '*' || empty($this->select)) ? $select : $this->select . ', ' . $select);
144
+        return $this;
145 145
     }
146 146
 
147 147
     /**
@@ -150,19 +150,19 @@  discard block
 block discarded – undo
150 150
      * @return object        the current DatabaseQueryBuilder instance
151 151
      */
152 152
     public function distinct($field){
153
-      $distinct = ' DISTINCT ' . $field;
154
-      $this->select = (($this->select == '*' || empty($this->select)) ? $distinct : $this->select . ', ' . $distinct);
155
-      return $this;
153
+        $distinct = ' DISTINCT ' . $field;
154
+        $this->select = (($this->select == '*' || empty($this->select)) ? $distinct : $this->select . ', ' . $distinct);
155
+        return $this;
156 156
     }
157 157
 
158
-     /**
159
-     * Set the SQL function COUNT in SELECT statment
160
-     * @param  string $field the field name
161
-     * @param  string $name  if is not null represent the alias used for this field in the result
162
-     * @return object        the current DatabaseQueryBuilder instance
163
-     */
158
+        /**
159
+         * Set the SQL function COUNT in SELECT statment
160
+         * @param  string $field the field name
161
+         * @param  string $name  if is not null represent the alias used for this field in the result
162
+         * @return object        the current DatabaseQueryBuilder instance
163
+         */
164 164
     public function count($field = '*', $name = null){
165
-      return $this->select_min_max_sum_count_avg('COUNT', $field, $name);
165
+        return $this->select_min_max_sum_count_avg('COUNT', $field, $name);
166 166
     }
167 167
     
168 168
     /**
@@ -172,7 +172,7 @@  discard block
 block discarded – undo
172 172
      * @return object        the current DatabaseQueryBuilder instance
173 173
      */
174 174
     public function min($field, $name = null){
175
-      return $this->select_min_max_sum_count_avg('MIN', $field, $name);
175
+        return $this->select_min_max_sum_count_avg('MIN', $field, $name);
176 176
     }
177 177
 
178 178
     /**
@@ -182,7 +182,7 @@  discard block
 block discarded – undo
182 182
      * @return object        the current DatabaseQueryBuilder instance
183 183
      */
184 184
     public function max($field, $name = null){
185
-      return $this->select_min_max_sum_count_avg('MAX', $field, $name);
185
+        return $this->select_min_max_sum_count_avg('MAX', $field, $name);
186 186
     }
187 187
 
188 188
     /**
@@ -192,7 +192,7 @@  discard block
 block discarded – undo
192 192
      * @return object        the current DatabaseQueryBuilder instance
193 193
      */
194 194
     public function sum($field, $name = null){
195
-      return $this->select_min_max_sum_count_avg('SUM', $field, $name);
195
+        return $this->select_min_max_sum_count_avg('SUM', $field, $name);
196 196
     }
197 197
 
198 198
     /**
@@ -202,7 +202,7 @@  discard block
 block discarded – undo
202 202
      * @return object        the current DatabaseQueryBuilder instance
203 203
      */
204 204
     public function avg($field, $name = null){
205
-      return $this->select_min_max_sum_count_avg('AVG', $field, $name);
205
+        return $this->select_min_max_sum_count_avg('AVG', $field, $name);
206 206
     }
207 207
 
208 208
 
@@ -216,20 +216,20 @@  discard block
 block discarded – undo
216 216
      * @return object        the current DatabaseQueryBuilder instance
217 217
      */
218 218
     public function join($table, $field1 = null, $op = null, $field2 = null, $type = ''){
219
-      $on = $field1;
220
-      $table = $this->getPrefix() . $table;
221
-      if (! is_null($op)){
219
+        $on = $field1;
220
+        $table = $this->getPrefix() . $table;
221
+        if (! is_null($op)){
222 222
         $on = (! in_array($op, $this->operatorList) 
223
-													? ($this->getPrefix() . $field1 . ' = ' . $this->getPrefix() . $op) 
224
-													: ($this->getPrefix() . $field1 . ' ' . $op . ' ' . $this->getPrefix() . $field2));
225
-      }
226
-      if (empty($this->join)){
223
+                                                    ? ($this->getPrefix() . $field1 . ' = ' . $this->getPrefix() . $op) 
224
+                                                    : ($this->getPrefix() . $field1 . ' ' . $op . ' ' . $this->getPrefix() . $field2));
225
+        }
226
+        if (empty($this->join)){
227 227
         $this->join = ' ' . $type . 'JOIN' . ' ' . $table . ' ON ' . $on;
228
-      }
229
-      else{
228
+        }
229
+        else{
230 230
         $this->join = $this->join . ' ' . $type . 'JOIN' . ' ' . $table . ' ON ' . $on;
231
-      }
232
-      return $this;
231
+        }
232
+        return $this;
233 233
     }
234 234
 
235 235
     /**
@@ -238,7 +238,7 @@  discard block
 block discarded – undo
238 238
      * @return object        the current DatabaseQueryBuilder instance
239 239
      */
240 240
     public function innerJoin($table, $field1, $op = null, $field2 = ''){
241
-      return $this->join($table, $field1, $op, $field2, 'INNER ');
241
+        return $this->join($table, $field1, $op, $field2, 'INNER ');
242 242
     }
243 243
 
244 244
     /**
@@ -247,16 +247,16 @@  discard block
 block discarded – undo
247 247
      * @return object        the current DatabaseQueryBuilder instance
248 248
      */
249 249
     public function leftJoin($table, $field1, $op = null, $field2 = ''){
250
-      return $this->join($table, $field1, $op, $field2, 'LEFT ');
251
-	}
250
+        return $this->join($table, $field1, $op, $field2, 'LEFT ');
251
+    }
252 252
 
253
-	/**
253
+    /**
254 254
      * Set the SQL RIGHT JOIN statment
255 255
      * @see  DatabaseQueryBuilder::join()
256 256
      * @return object        the current DatabaseQueryBuilder instance
257 257
      */
258 258
     public function rightJoin($table, $field1, $op = null, $field2 = ''){
259
-      return $this->join($table, $field1, $op, $field2, 'RIGHT ');
259
+        return $this->join($table, $field1, $op, $field2, 'RIGHT ');
260 260
     }
261 261
 
262 262
     /**
@@ -265,7 +265,7 @@  discard block
 block discarded – undo
265 265
      * @return object        the current DatabaseQueryBuilder instance
266 266
      */
267 267
     public function fullOuterJoin($table, $field1, $op = null, $field2 = ''){
268
-    	return $this->join($table, $field1, $op, $field2, 'FULL OUTER ');
268
+        return $this->join($table, $field1, $op, $field2, 'FULL OUTER ');
269 269
     }
270 270
 
271 271
     /**
@@ -274,7 +274,7 @@  discard block
 block discarded – undo
274 274
      * @return object        the current DatabaseQueryBuilder instance
275 275
      */
276 276
     public function leftOuterJoin($table, $field1, $op = null, $field2 = ''){
277
-      return $this->join($table, $field1, $op, $field2, 'LEFT OUTER ');
277
+        return $this->join($table, $field1, $op, $field2, 'LEFT OUTER ');
278 278
     }
279 279
 
280 280
     /**
@@ -283,7 +283,7 @@  discard block
 block discarded – undo
283 283
      * @return object        the current DatabaseQueryBuilder instance
284 284
      */
285 285
     public function rightOuterJoin($table, $field1, $op = null, $field2 = ''){
286
-      return $this->join($table, $field1, $op, $field2, 'RIGHT OUTER ');
286
+        return $this->join($table, $field1, $op, $field2, 'RIGHT OUTER ');
287 287
     }
288 288
 
289 289
     /**
@@ -293,14 +293,14 @@  discard block
 block discarded – undo
293 293
      * @return object        the current DatabaseQueryBuilder instance
294 294
      */
295 295
     public function whereIsNull($field, $andOr = 'AND'){
296
-      if (is_array($field)){
296
+        if (is_array($field)){
297 297
         foreach($field as $f){
298
-        	$this->whereIsNull($f, $andOr);
298
+            $this->whereIsNull($f, $andOr);
299 299
         }
300
-      } else {
301
-          $this->setWhereStr($field.' IS NULL ', $andOr);
302
-      }
303
-      return $this;
300
+        } else {
301
+            $this->setWhereStr($field.' IS NULL ', $andOr);
302
+        }
303
+        return $this;
304 304
     }
305 305
 
306 306
     /**
@@ -310,14 +310,14 @@  discard block
 block discarded – undo
310 310
      * @return object        the current DatabaseQueryBuilder instance
311 311
      */
312 312
     public function whereIsNotNull($field, $andOr = 'AND'){
313
-      if (is_array($field)){
313
+        if (is_array($field)){
314 314
         foreach($field as $f){
315
-          $this->whereIsNotNull($f, $andOr);
315
+            $this->whereIsNotNull($f, $andOr);
316
+        }
317
+        } else {
318
+            $this->setWhereStr($field.' IS NOT NULL ', $andOr);
316 319
         }
317
-      } else {
318
-          $this->setWhereStr($field.' IS NOT NULL ', $andOr);
319
-      }
320
-      return $this;
320
+        return $this;
321 321
     }
322 322
     
323 323
     /**
@@ -331,19 +331,19 @@  discard block
 block discarded – undo
331 331
      * @return object        the current DatabaseQueryBuilder instance
332 332
      */
333 333
     public function where($where, $op = null, $val = null, $type = '', $andOr = 'AND', $escape = true){
334
-      $whereStr = '';
335
-      if (is_array($where)){
334
+        $whereStr = '';
335
+        if (is_array($where)){
336 336
         $whereStr = $this->getWhereStrIfIsArray($where, $type, $andOr, $escape);
337
-      }
338
-      else{
337
+        }
338
+        else{
339 339
         if (is_array($op)){
340
-          $whereStr = $this->getWhereStrIfOperatorIsArray($where, $op, $type, $escape);
340
+            $whereStr = $this->getWhereStrIfOperatorIsArray($where, $op, $type, $escape);
341 341
         } else {
342
-          $whereStr = $this->getWhereStrForOperator($where, $op, $val, $type, $escape);
342
+            $whereStr = $this->getWhereStrForOperator($where, $op, $val, $type, $escape);
343
+        }
343 344
         }
344
-      }
345
-      $this->setWhereStr($whereStr, $andOr);
346
-      return $this;
345
+        $this->setWhereStr($whereStr, $andOr);
346
+        return $this;
347 347
     }
348 348
 
349 349
     /**
@@ -352,7 +352,7 @@  discard block
 block discarded – undo
352 352
      * @return object        the current DatabaseQueryBuilder instance
353 353
      */
354 354
     public function orWhere($where, $op = null, $val = null, $escape = true){
355
-      return $this->where($where, $op, $val, '', 'OR', $escape);
355
+        return $this->where($where, $op, $val, '', 'OR', $escape);
356 356
     }
357 357
 
358 358
 
@@ -362,7 +362,7 @@  discard block
 block discarded – undo
362 362
      * @return object        the current DatabaseQueryBuilder instance
363 363
      */
364 364
     public function notWhere($where, $op = null, $val = null, $escape = true){
365
-      return $this->where($where, $op, $val, 'NOT ', 'AND', $escape);
365
+        return $this->where($where, $op, $val, 'NOT ', 'AND', $escape);
366 366
     }
367 367
 
368 368
     /**
@@ -371,7 +371,7 @@  discard block
 block discarded – undo
371 371
      * @return object        the current DatabaseQueryBuilder instance
372 372
      */
373 373
     public function orNotWhere($where, $op = null, $val = null, $escape = true){
374
-    	return $this->where($where, $op, $val, 'NOT ', 'OR', $escape);
374
+        return $this->where($where, $op, $val, 'NOT ', 'OR', $escape);
375 375
     }
376 376
 
377 377
     /**
@@ -381,16 +381,16 @@  discard block
 block discarded – undo
381 381
      * @return object        the current DatabaseQueryBuilder instance
382 382
      */
383 383
     public function groupStart($type = '', $andOr = ' AND'){
384
-      if (empty($this->where)){
384
+        if (empty($this->where)){
385 385
         $this->where = $type . ' (';
386
-      } else {
387
-          if (substr(trim($this->where), -1) == '('){
386
+        } else {
387
+            if (substr(trim($this->where), -1) == '('){
388 388
             $this->where .= $type . ' (';
389
-          } else {
390
-          	$this->where .= $andOr . ' ' . $type . ' (';
391
-          }
392
-      }
393
-      return $this;
389
+            } else {
390
+                $this->where .= $andOr . ' ' . $type . ' (';
391
+            }
392
+        }
393
+        return $this;
394 394
     }
395 395
 
396 396
     /**
@@ -399,7 +399,7 @@  discard block
 block discarded – undo
399 399
      * @return object        the current DatabaseQueryBuilder instance
400 400
      */
401 401
     public function notGroupStart(){
402
-      return $this->groupStart('NOT');
402
+        return $this->groupStart('NOT');
403 403
     }
404 404
 
405 405
     /**
@@ -408,16 +408,16 @@  discard block
 block discarded – undo
408 408
      * @return object        the current DatabaseQueryBuilder instance
409 409
      */
410 410
     public function orGroupStart(){
411
-      return $this->groupStart('', ' OR');
411
+        return $this->groupStart('', ' OR');
412 412
     }
413 413
 
414
-     /**
415
-     * Set the opened parenthesis for the complex SQL query using OR for separator and NOT for type
416
-     * @see  DatabaseQueryBuilder::groupStart()
417
-     * @return object        the current DatabaseQueryBuilder instance
418
-     */
414
+        /**
415
+         * Set the opened parenthesis for the complex SQL query using OR for separator and NOT for type
416
+         * @see  DatabaseQueryBuilder::groupStart()
417
+         * @return object        the current DatabaseQueryBuilder instance
418
+         */
419 419
     public function orNotGroupStart(){
420
-      return $this->groupStart('NOT', ' OR');
420
+        return $this->groupStart('NOT', ' OR');
421 421
     }
422 422
 
423 423
     /**
@@ -425,8 +425,8 @@  discard block
 block discarded – undo
425 425
      * @return object        the current DatabaseQueryBuilder instance
426 426
      */
427 427
     public function groupEnd(){
428
-      $this->where .= ')';
429
-      return $this;
428
+        $this->where .= ')';
429
+        return $this;
430 430
     }
431 431
 
432 432
     /**
@@ -439,17 +439,17 @@  discard block
 block discarded – undo
439 439
      * @return object        the current DatabaseQueryBuilder instance
440 440
      */
441 441
     public function in($field, array $keys, $type = '', $andOr = 'AND', $escape = true){
442
-      $_keys = array();
443
-      foreach ($keys as $k => $v){
442
+        $_keys = array();
443
+        foreach ($keys as $k => $v){
444 444
         if (is_null($v)){
445
-          $v = '';
445
+            $v = '';
446 446
         }
447 447
         $_keys[] = (is_numeric($v) ? $v : $this->escape($v, $escape));
448
-      }
449
-      $keys = implode(', ', $_keys);
450
-      $whereStr = $field . ' ' . $type . ' IN (' . $keys . ')';
451
-      $this->setWhereStr($whereStr, $andOr);
452
-      return $this;
448
+        }
449
+        $keys = implode(', ', $_keys);
450
+        $whereStr = $field . ' ' . $type . ' IN (' . $keys . ')';
451
+        $this->setWhereStr($whereStr, $andOr);
452
+        return $this;
453 453
     }
454 454
 
455 455
     /**
@@ -458,7 +458,7 @@  discard block
 block discarded – undo
458 458
      * @return object        the current DatabaseQueryBuilder instance
459 459
      */
460 460
     public function notIn($field, array $keys, $escape = true){
461
-      return $this->in($field, $keys, 'NOT ', 'AND', $escape);
461
+        return $this->in($field, $keys, 'NOT ', 'AND', $escape);
462 462
     }
463 463
 
464 464
     /**
@@ -467,7 +467,7 @@  discard block
 block discarded – undo
467 467
      * @return object        the current DatabaseQueryBuilder instance
468 468
      */
469 469
     public function orIn($field, array $keys, $escape = true){
470
-      return $this->in($field, $keys, '', 'OR', $escape);
470
+        return $this->in($field, $keys, '', 'OR', $escape);
471 471
     }
472 472
 
473 473
     /**
@@ -476,7 +476,7 @@  discard block
 block discarded – undo
476 476
      * @return object        the current DatabaseQueryBuilder instance
477 477
      */
478 478
     public function orNotIn($field, array $keys, $escape = true){
479
-      return $this->in($field, $keys, 'NOT ', 'OR', $escape);
479
+        return $this->in($field, $keys, 'NOT ', 'OR', $escape);
480 480
     }
481 481
 
482 482
     /**
@@ -490,15 +490,15 @@  discard block
 block discarded – undo
490 490
      * @return object        the current DatabaseQueryBuilder instance
491 491
      */
492 492
     public function between($field, $value1, $value2, $type = '', $andOr = 'AND', $escape = true){
493
-      if (is_null($value1)){
493
+        if (is_null($value1)){
494 494
         $value1 = '';
495
-      }
496
-      if (is_null($value2)){
495
+        }
496
+        if (is_null($value2)){
497 497
         $value2 = '';
498
-      }
499
-      $whereStr = $field . ' ' . $type . ' BETWEEN ' . $this->escape($value1, $escape) . ' AND ' . $this->escape($value2, $escape);
500
-      $this->setWhereStr($whereStr, $andOr);
501
-      return $this;
498
+        }
499
+        $whereStr = $field . ' ' . $type . ' BETWEEN ' . $this->escape($value1, $escape) . ' AND ' . $this->escape($value2, $escape);
500
+        $this->setWhereStr($whereStr, $andOr);
501
+        return $this;
502 502
     }
503 503
 
504 504
     /**
@@ -507,7 +507,7 @@  discard block
 block discarded – undo
507 507
      * @return object        the current DatabaseQueryBuilder instance
508 508
      */
509 509
     public function notBetween($field, $value1, $value2, $escape = true){
510
-      return $this->between($field, $value1, $value2, 'NOT ', 'AND', $escape);
510
+        return $this->between($field, $value1, $value2, 'NOT ', 'AND', $escape);
511 511
     }
512 512
 
513 513
     /**
@@ -516,7 +516,7 @@  discard block
 block discarded – undo
516 516
      * @return object        the current DatabaseQueryBuilder instance
517 517
      */
518 518
     public function orBetween($field, $value1, $value2, $escape = true){
519
-      return $this->between($field, $value1, $value2, '', 'OR', $escape);
519
+        return $this->between($field, $value1, $value2, '', 'OR', $escape);
520 520
     }
521 521
 
522 522
     /**
@@ -525,7 +525,7 @@  discard block
 block discarded – undo
525 525
      * @return object        the current DatabaseQueryBuilder instance
526 526
      */
527 527
     public function orNotBetween($field, $value1, $value2, $escape = true){
528
-      return $this->between($field, $value1, $value2, 'NOT ', 'OR', $escape);
528
+        return $this->between($field, $value1, $value2, 'NOT ', 'OR', $escape);
529 529
     }
530 530
 
531 531
     /**
@@ -538,11 +538,11 @@  discard block
 block discarded – undo
538 538
      * @return object        the current DatabaseQueryBuilder instance
539 539
      */
540 540
     public function like($field, $data, $type = '', $andOr = 'AND', $escape = true){
541
-      if (empty($data)){
541
+        if (empty($data)){
542 542
         $data = '';
543
-      }
544
-      $this->setWhereStr($field . ' ' . $type . ' LIKE ' . ($this->escape($data, $escape)), $andOr);
545
-      return $this;
543
+        }
544
+        $this->setWhereStr($field . ' ' . $type . ' LIKE ' . ($this->escape($data, $escape)), $andOr);
545
+        return $this;
546 546
     }
547 547
 
548 548
     /**
@@ -551,7 +551,7 @@  discard block
 block discarded – undo
551 551
      * @return object        the current DatabaseQueryBuilder instance
552 552
      */
553 553
     public function orLike($field, $data, $escape = true){
554
-      return $this->like($field, $data, '', 'OR', $escape);
554
+        return $this->like($field, $data, '', 'OR', $escape);
555 555
     }
556 556
 
557 557
     /**
@@ -560,7 +560,7 @@  discard block
 block discarded – undo
560 560
      * @return object        the current DatabaseQueryBuilder instance
561 561
      */
562 562
     public function notLike($field, $data, $escape = true){
563
-      return $this->like($field, $data, 'NOT ', 'AND', $escape);
563
+        return $this->like($field, $data, 'NOT ', 'AND', $escape);
564 564
     }
565 565
 
566 566
     /**
@@ -569,7 +569,7 @@  discard block
 block discarded – undo
569 569
      * @return object        the current DatabaseQueryBuilder instance
570 570
      */
571 571
     public function orNotLike($field, $data, $escape = true){
572
-      return $this->like($field, $data, 'NOT ', 'OR', $escape);
572
+        return $this->like($field, $data, 'NOT ', 'OR', $escape);
573 573
     }
574 574
 
575 575
     /**
@@ -580,16 +580,16 @@  discard block
 block discarded – undo
580 580
      * @return object        the current DatabaseQueryBuilder instance
581 581
      */
582 582
     public function limit($limit, $limitEnd = null){
583
-      if (empty($limit)){
583
+        if (empty($limit)){
584 584
         $limit = 0;
585
-      }
586
-      if (! is_null($limitEnd)){
585
+        }
586
+        if (! is_null($limitEnd)){
587 587
         $this->limit = $limit . ', ' . $limitEnd;
588
-      }
589
-      else{
588
+        }
589
+        else{
590 590
         $this->limit = $limit;
591
-      }
592
-      return $this;
591
+        }
592
+        return $this;
593 593
     }
594 594
 
595 595
     /**
@@ -599,15 +599,15 @@  discard block
 block discarded – undo
599 599
      * @return object        the current DatabaseQueryBuilder instance
600 600
      */
601 601
     public function orderBy($orderBy, $orderDir = ' ASC'){
602
-      if (stristr($orderBy, ' ') || $orderBy == 'rand()'){
602
+        if (stristr($orderBy, ' ') || $orderBy == 'rand()'){
603 603
         $this->orderBy = empty($this->orderBy) ? $orderBy : $this->orderBy . ', ' . $orderBy;
604
-      }
605
-      else{
604
+        }
605
+        else{
606 606
         $this->orderBy = empty($this->orderBy) 
607
-						? ($orderBy . ' ' . strtoupper($orderDir)) 
608
-						: $this->orderBy . ', ' . $orderBy . ' ' . strtoupper($orderDir);
609
-      }
610
-      return $this;
607
+                        ? ($orderBy . ' ' . strtoupper($orderDir)) 
608
+                        : $this->orderBy . ', ' . $orderBy . ' ' . strtoupper($orderDir);
609
+        }
610
+        return $this;
611 611
     }
612 612
 
613 613
     /**
@@ -616,13 +616,13 @@  discard block
 block discarded – undo
616 616
      * @return object        the current DatabaseQueryBuilder instance
617 617
      */
618 618
     public function groupBy($field){
619
-      if (is_array($field)){
619
+        if (is_array($field)){
620 620
         $this->groupBy = implode(', ', $field);
621
-      }
622
-      else{
621
+        }
622
+        else{
623 623
         $this->groupBy = $field;
624
-      }
625
-      return $this;
624
+        }
625
+        return $this;
626 626
     }
627 627
 
628 628
     /**
@@ -634,22 +634,22 @@  discard block
 block discarded – undo
634 634
      * @return object        the current DatabaseQueryBuilder instance
635 635
      */
636 636
     public function having($field, $op = null, $val = null, $escape = true){
637
-      if (is_array($op)){
637
+        if (is_array($op)){
638 638
         $this->having = $this->getHavingStrIfOperatorIsArray($field, $op, $escape);
639
-      }
640
-      else if (! in_array($op, $this->operatorList)){
639
+        }
640
+        else if (! in_array($op, $this->operatorList)){
641 641
         if (is_null($op)){
642
-          $op = '';
642
+            $op = '';
643 643
         }
644 644
         $this->having = $field . ' > ' . ($this->escape($op, $escape));
645
-      }
646
-      else{
645
+        }
646
+        else{
647 647
         if (is_null($val)){
648
-          $val = '';
648
+            $val = '';
649 649
         }
650 650
         $this->having = $field . ' ' . $op . ' ' . ($this->escape($val, $escape));
651
-      }
652
-      return $this;
651
+        }
652
+        return $this;
653 653
     }
654 654
 
655 655
     /**
@@ -659,12 +659,12 @@  discard block
 block discarded – undo
659 659
      * @return object  the current DatabaseQueryBuilder instance        
660 660
      */
661 661
     public function insert($data = array(), $escape = true){
662
-      $columns = array_keys($data);
663
-      $column = implode(', ', $columns);
664
-      $val = implode(', ', ($escape ? array_map(array($this, 'escape'), $data) : $data));
662
+        $columns = array_keys($data);
663
+        $column = implode(', ', $columns);
664
+        $val = implode(', ', ($escape ? array_map(array($this, 'escape'), $data) : $data));
665 665
 
666
-      $this->query = 'INSERT INTO ' . $this->from . ' (' . $column . ') VALUES (' . $val . ')';
667
-      return $this;
666
+        $this->query = 'INSERT INTO ' . $this->from . ' (' . $column . ') VALUES (' . $val . ')';
667
+        return $this;
668 668
     }
669 669
 
670 670
     /**
@@ -674,25 +674,25 @@  discard block
 block discarded – undo
674 674
      * @return object  the current DatabaseQueryBuilder instance 
675 675
      */
676 676
     public function update($data = array(), $escape = true){
677
-      $query = 'UPDATE ' . $this->from . ' SET ';
678
-      $values = array();
679
-      foreach ($data as $column => $val){
677
+        $query = 'UPDATE ' . $this->from . ' SET ';
678
+        $values = array();
679
+        foreach ($data as $column => $val){
680 680
         $values[] = $column . ' = ' . ($this->escape($val, $escape));
681
-      }
682
-      $query .= implode(', ', $values);
683
-      if (! empty($this->where)){
681
+        }
682
+        $query .= implode(', ', $values);
683
+        if (! empty($this->where)){
684 684
         $query .= ' WHERE ' . $this->where;
685
-      }
685
+        }
686 686
 
687
-      if (! empty($this->orderBy)){
687
+        if (! empty($this->orderBy)){
688 688
         $query .= ' ORDER BY ' . $this->orderBy;
689
-      }
689
+        }
690 690
 
691
-      if (! empty($this->limit)){
691
+        if (! empty($this->limit)){
692 692
         $query .= ' LIMIT ' . $this->limit;
693
-      }
694
-      $this->query = $query;
695
-      return $this;
693
+        }
694
+        $this->query = $query;
695
+        return $this;
696 696
     }
697 697
 
698 698
     /**
@@ -700,25 +700,25 @@  discard block
 block discarded – undo
700 700
      * @return object  the current DatabaseQueryBuilder instance 
701 701
      */
702 702
     public function delete(){
703
-    	$query = 'DELETE FROM ' . $this->from;
704
-      $isTruncate = $query;
705
-    	if (! empty($this->where)){
706
-  		  $query .= ' WHERE ' . $this->where;
707
-    	}
703
+        $query = 'DELETE FROM ' . $this->from;
704
+        $isTruncate = $query;
705
+        if (! empty($this->where)){
706
+            $query .= ' WHERE ' . $this->where;
707
+        }
708 708
 
709
-    	if (! empty($this->orderBy)){
710
-    	  $query .= ' ORDER BY ' . $this->orderBy;
711
-      }
709
+        if (! empty($this->orderBy)){
710
+            $query .= ' ORDER BY ' . $this->orderBy;
711
+        }
712 712
 
713
-    	if (! empty($this->limit)){
714
-    		$query .= ' LIMIT ' . $this->limit;
715
-      }
713
+        if (! empty($this->limit)){
714
+            $query .= ' LIMIT ' . $this->limit;
715
+        }
716 716
 
717
-  		if ($isTruncate == $query && $this->driver != 'sqlite'){  
718
-      	$query = 'TRUNCATE TABLE ' . $this->from;
719
-  		}
720
-	   $this->query = $query;
721
-	   return $this;
717
+            if ($isTruncate == $query && $this->driver != 'sqlite'){  
718
+            $query = 'TRUNCATE TABLE ' . $this->from;
719
+            }
720
+        $this->query = $query;
721
+        return $this;
722 722
     }
723 723
 
724 724
     /**
@@ -728,11 +728,11 @@  discard block
 block discarded – undo
728 728
      * @return mixed       the data after escaped or the same data if not
729 729
      */
730 730
     public function escape($data, $escaped = true){
731
-      $data = trim($data);
732
-      if($escaped){
731
+        $data = trim($data);
732
+        if($escaped){
733 733
         return $this->pdo->quote($data);
734
-      }
735
-      return $data;  
734
+        }
735
+        return $data;  
736 736
     }
737 737
 
738 738
 
@@ -741,126 +741,126 @@  discard block
 block discarded – undo
741 741
      * @return string
742 742
      */
743 743
     public function getQuery(){
744
-  	  //INSERT, UPDATE, DELETE already set it, if is the SELECT we need set it now
745
-  	  if(empty($this->query)){
746
-  		  $query = 'SELECT ' . $this->select . ' FROM ' . $this->from;
747
-  		  if (! empty($this->join)){
748
-          $query .= $this->join;
749
-  		  }
744
+        //INSERT, UPDATE, DELETE already set it, if is the SELECT we need set it now
745
+        if(empty($this->query)){
746
+            $query = 'SELECT ' . $this->select . ' FROM ' . $this->from;
747
+            if (! empty($this->join)){
748
+            $query .= $this->join;
749
+            }
750 750
   		  
751
-  		  if (! empty($this->where)){
752
-          $query .= ' WHERE ' . $this->where;
753
-  		  }
751
+            if (! empty($this->where)){
752
+            $query .= ' WHERE ' . $this->where;
753
+            }
754 754
 
755
-  		  if (! empty($this->groupBy)){
756
-          $query .= ' GROUP BY ' . $this->groupBy;
757
-  		  }
755
+            if (! empty($this->groupBy)){
756
+            $query .= ' GROUP BY ' . $this->groupBy;
757
+            }
758 758
 
759
-  		  if (! empty($this->having)){
760
-          $query .= ' HAVING ' . $this->having;
761
-  		  }
759
+            if (! empty($this->having)){
760
+            $query .= ' HAVING ' . $this->having;
761
+            }
762 762
 
763
-  		  if (! empty($this->orderBy)){
764
-  			  $query .= ' ORDER BY ' . $this->orderBy;
765
-  		  }
763
+            if (! empty($this->orderBy)){
764
+                $query .= ' ORDER BY ' . $this->orderBy;
765
+            }
766 766
 
767
-  		  if (! empty($this->limit)){
768
-          $query .= ' LIMIT ' . $this->limit;
769
-  		  }
770
-  		  $this->query = $query;
771
-  	  }
772
-      return $this->query;
767
+            if (! empty($this->limit)){
768
+            $query .= ' LIMIT ' . $this->limit;
769
+            }
770
+            $this->query = $query;
771
+        }
772
+        return $this->query;
773 773
     }
774 774
 
775 775
 	
776
-	 /**
777
-     * Return the PDO instance
778
-     * @return object
779
-     */
776
+        /**
777
+         * Return the PDO instance
778
+         * @return object
779
+         */
780 780
     public function getPdo(){
781
-      return $this->pdo;
781
+        return $this->pdo;
782 782
     }
783 783
 
784 784
     /**
785 785
      * Set the PDO instance
786 786
      * @param PDO $pdo the pdo object
787
-	   * @return object DatabaseQueryBuilder
787
+     * @return object DatabaseQueryBuilder
788 788
      */
789 789
     public function setPdo(PDO $pdo = null){
790
-      $this->pdo = $pdo;
791
-      return $this;
790
+        $this->pdo = $pdo;
791
+        return $this;
792 792
     }
793 793
 	
794
-   /**
795
-   * Return the database table prefix
796
-   * @return string
797
-   */
794
+    /**
795
+     * Return the database table prefix
796
+     * @return string
797
+     */
798 798
     public function getPrefix(){
799
-      return $this->prefix;
799
+        return $this->prefix;
800 800
     }
801 801
 
802 802
     /**
803 803
      * Set the database table prefix
804 804
      * @param string $prefix the new prefix
805
-	   * @return object DatabaseQueryBuilder
805
+     * @return object DatabaseQueryBuilder
806 806
      */
807 807
     public function setPrefix($prefix){
808
-      $this->prefix = $prefix;
809
-      return $this;
808
+        $this->prefix = $prefix;
809
+        return $this;
810 810
     }
811 811
 	
812
-	   /**
813
-     * Return the database driver
814
-     * @return string
815
-     */
812
+        /**
813
+         * Return the database driver
814
+         * @return string
815
+         */
816 816
     public function getDriver(){
817
-      return $this->driver;
817
+        return $this->driver;
818 818
     }
819 819
 
820 820
     /**
821 821
      * Set the database driver
822 822
      * @param string $driver the new driver
823
-	   * @return object DatabaseQueryBuilder
823
+     * @return object DatabaseQueryBuilder
824 824
      */
825 825
     public function setDriver($driver){
826
-      $this->driver = $driver;
827
-      return $this;
826
+        $this->driver = $driver;
827
+        return $this;
828 828
     }
829 829
 	
830
-	   /**
831
-     * Reset the DatabaseQueryBuilder class attributs to the initial values before each query.
832
-	   * @return object  the current DatabaseQueryBuilder instance 
833
-     */
830
+        /**
831
+         * Reset the DatabaseQueryBuilder class attributs to the initial values before each query.
832
+         * @return object  the current DatabaseQueryBuilder instance 
833
+         */
834 834
     public function reset(){
835
-      $this->select   = '*';
836
-      $this->from     = null;
837
-      $this->where    = null;
838
-      $this->limit    = null;
839
-      $this->orderBy  = null;
840
-      $this->groupBy  = null;
841
-      $this->having   = null;
842
-      $this->join     = null;
843
-      $this->query    = null;
844
-      return $this;
845
-    }
846
-
847
-	   /**
848
-     * Get the SQL HAVING clause when operator argument is an array
849
-     * @see DatabaseQueryBuilder::having
850
-     *
851
-     * @return string
852
-     */
835
+        $this->select   = '*';
836
+        $this->from     = null;
837
+        $this->where    = null;
838
+        $this->limit    = null;
839
+        $this->orderBy  = null;
840
+        $this->groupBy  = null;
841
+        $this->having   = null;
842
+        $this->join     = null;
843
+        $this->query    = null;
844
+        return $this;
845
+    }
846
+
847
+        /**
848
+         * Get the SQL HAVING clause when operator argument is an array
849
+         * @see DatabaseQueryBuilder::having
850
+         *
851
+         * @return string
852
+         */
853 853
     protected function getHavingStrIfOperatorIsArray($field, $op = null, $escape = true){
854 854
         $x = explode('?', $field);
855 855
         $w = '';
856 856
         foreach($x as $k => $v){
857
-  	      if (!empty($v)){
857
+            if (!empty($v)){
858 858
             if (! isset($op[$k])){
859
-              $op[$k] = '';
859
+                $op[$k] = '';
860
+            }
861
+                $w .= $v . (isset($op[$k]) ? $this->escape($op[$k], $escape) : '');
862
+            }
860 863
             }
861
-  	      	$w .= $v . (isset($op[$k]) ? $this->escape($op[$k], $escape) : '');
862
-  	      }
863
-      	}
864 864
         return $w;
865 865
     }
866 866
 
@@ -872,35 +872,35 @@  discard block
 block discarded – undo
872 872
      * @return string
873 873
      */
874 874
     protected function getWhereStrIfIsArray(array $where, $type = '', $andOr = 'AND', $escape = true){
875
-      $_where = array();
876
-      foreach ($where as $column => $data){
875
+        $_where = array();
876
+        foreach ($where as $column => $data){
877 877
         if (is_null($data)){
878
-          $data = '';
878
+            $data = '';
879 879
         }
880 880
         $_where[] = $type . $column . ' = ' . ($this->escape($data, $escape));
881
-      }
882
-      $where = implode(' '.$andOr.' ', $_where);
883
-      return $where;
881
+        }
882
+        $where = implode(' '.$andOr.' ', $_where);
883
+        return $where;
884 884
     }
885 885
 
886
-     /**
887
-     * Get the SQL WHERE clause when operator argument is an array
888
-     * @see DatabaseQueryBuilder::where
889
-     *
890
-     * @return string
891
-     */
886
+        /**
887
+         * Get the SQL WHERE clause when operator argument is an array
888
+         * @see DatabaseQueryBuilder::where
889
+         *
890
+         * @return string
891
+         */
892 892
     protected function getWhereStrIfOperatorIsArray($where, array $op, $type = '', $escape = true){
893
-     $x = explode('?', $where);
894
-     $w = '';
895
-      foreach($x as $k => $v){
893
+        $x = explode('?', $where);
894
+        $w = '';
895
+        foreach($x as $k => $v){
896 896
         if (! empty($v)){
897 897
             if (isset($op[$k]) && is_null($op[$k])){
898
-              $op[$k] = '';
898
+                $op[$k] = '';
899 899
             }
900 900
             $w .= $type . $v . (isset($op[$k]) ? ($this->escape($op[$k], $escape)) : '');
901 901
         }
902
-      }
903
-      return $w;
902
+        }
903
+        return $w;
904 904
     }
905 905
 
906 906
     /**
@@ -910,53 +910,53 @@  discard block
 block discarded – undo
910 910
      * @return string
911 911
      */
912 912
     protected function getWhereStrForOperator($where, $op = null, $val = null, $type = '', $escape = true){
913
-       $w = '';
914
-       if (! in_array((string)$op, $this->operatorList)){
915
-          if (is_null($op)){
913
+        $w = '';
914
+        if (! in_array((string)$op, $this->operatorList)){
915
+            if (is_null($op)){
916 916
             $op = '';
917
-          }
918
-          $w = $type . $where . ' = ' . ($this->escape($op, $escape));
917
+            }
918
+            $w = $type . $where . ' = ' . ($this->escape($op, $escape));
919 919
         } else {
920
-          if (is_null($val)){
920
+            if (is_null($val)){
921 921
             $val = '';
922
-          }
923
-          $w = $type . $where . $op . ($this->escape($val, $escape));
922
+            }
923
+            $w = $type . $where . $op . ($this->escape($val, $escape));
924 924
         }
925 925
         return $w;
926
-      }
927
-
928
-      /**
929
-       * Set the $this->where property 
930
-       * @param string $whereStr the WHERE clause string
931
-       * @param  string  $andOr the separator type used 'AND', 'OR', etc.
932
-       */
933
-      protected function setWhereStr($whereStr, $andOr = 'AND'){
926
+        }
927
+
928
+        /**
929
+         * Set the $this->where property 
930
+         * @param string $whereStr the WHERE clause string
931
+         * @param  string  $andOr the separator type used 'AND', 'OR', etc.
932
+         */
933
+        protected function setWhereStr($whereStr, $andOr = 'AND'){
934 934
         if (empty($this->where)){
935
-          $this->where = $whereStr;
935
+            $this->where = $whereStr;
936 936
         } else {
937
-          if (substr(trim($this->where), -1) == '('){
937
+            if (substr(trim($this->where), -1) == '('){
938 938
             $this->where = $this->where . ' ' . $whereStr;
939
-          } else {
939
+            } else {
940 940
             $this->where = $this->where . ' '.$andOr.' ' . $whereStr;
941
-          }
941
+            }
942
+        }
942 943
         }
943
-      }
944 944
 
945 945
 
946
-	 /**
947
-     * Set the SQL SELECT for function MIN, MAX, SUM, AVG, COUNT, AVG
948
-     * @param  string $clause the clause type like MIN, MAX, etc.
949
-     * @see  DatabaseQueryBuilder::min
950
-     * @see  DatabaseQueryBuilder::max
951
-     * @see  DatabaseQueryBuilder::sum
952
-     * @see  DatabaseQueryBuilder::count
953
-     * @see  DatabaseQueryBuilder::avg
954
-     * @return object
955
-     */
946
+        /**
947
+         * Set the SQL SELECT for function MIN, MAX, SUM, AVG, COUNT, AVG
948
+         * @param  string $clause the clause type like MIN, MAX, etc.
949
+         * @see  DatabaseQueryBuilder::min
950
+         * @see  DatabaseQueryBuilder::max
951
+         * @see  DatabaseQueryBuilder::sum
952
+         * @see  DatabaseQueryBuilder::count
953
+         * @see  DatabaseQueryBuilder::avg
954
+         * @return object
955
+         */
956 956
     protected function select_min_max_sum_count_avg($clause, $field, $name = null){
957
-      $clause = strtoupper($clause);
958
-      $func = $clause . '(' . $field . ')' . (!is_null($name) ? ' AS ' . $name : '');
959
-      $this->select = ($this->select == '*' ? $func : $this->select . ', ' . $func);
960
-      return $this;
957
+        $clause = strtoupper($clause);
958
+        $func = $clause . '(' . $field . ')' . (!is_null($name) ? ' AS ' . $name : '');
959
+        $this->select = ($this->select == '*' ? $func : $this->select . ', ' . $func);
960
+        return $this;
961 961
     }
962 962
 }
Please login to merge, or discard this patch.
Spacing   +141 added lines, -141 removed lines patch added patch discarded remove patch
@@ -23,94 +23,94 @@  discard block
 block discarded – undo
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
-  class DatabaseQueryBuilder{
26
+  class DatabaseQueryBuilder {
27 27
   	/**
28 28
   	 * The SQL SELECT statment
29 29
   	 * @var string
30 30
   	*/
31
-  	private $select              = '*';
31
+  	private $select = '*';
32 32
   	
33 33
   	/**
34 34
   	 * The SQL FROM statment
35 35
   	 * @var string
36 36
   	*/
37
-      private $from              = null;
37
+      private $from = null;
38 38
   	
39 39
   	/**
40 40
   	 * The SQL WHERE statment
41 41
   	 * @var string
42 42
   	*/
43
-      private $where               = null;
43
+      private $where = null;
44 44
   	
45 45
   	/**
46 46
   	 * The SQL LIMIT statment
47 47
   	 * @var string
48 48
   	*/
49
-      private $limit               = null;
49
+      private $limit = null;
50 50
   	
51 51
   	/**
52 52
   	 * The SQL JOIN statment
53 53
   	 * @var string
54 54
   	*/
55
-      private $join                = null;
55
+      private $join = null;
56 56
   	
57 57
   	/**
58 58
   	 * The SQL ORDER BY statment
59 59
   	 * @var string
60 60
   	*/
61
-      private $orderBy             = null;
61
+      private $orderBy = null;
62 62
   	
63 63
   	/**
64 64
   	 * The SQL GROUP BY statment
65 65
   	 * @var string
66 66
   	*/
67
-      private $groupBy             = null;
67
+      private $groupBy = null;
68 68
   	
69 69
   	/**
70 70
   	 * The SQL HAVING statment
71 71
   	 * @var string
72 72
   	*/
73
-      private $having              = null;
73
+      private $having = null;
74 74
   	
75 75
   	/**
76 76
   	 * The full SQL query statment after build for each command
77 77
   	 * @var string
78 78
   	*/
79
-      private $query               = null;
79
+      private $query = null;
80 80
   	
81 81
   	/**
82 82
   	 * The list of SQL valid operators
83 83
   	 * @var array
84 84
   	*/
85
-    private $operatorList        = array('=','!=','<','>','<=','>=','<>');
85
+    private $operatorList = array('=', '!=', '<', '>', '<=', '>=', '<>');
86 86
   	
87 87
 	
88 88
 	/**
89 89
 	 * The prefix used in each database table
90 90
 	 * @var string
91 91
 	*/
92
-    private $prefix              = null;
92
+    private $prefix = null;
93 93
     
94 94
 
95 95
     /**
96 96
   	 * The PDO instance
97 97
   	 * @var object
98 98
   	*/
99
-    private $pdo                 = null;
99
+    private $pdo = null;
100 100
 	
101 101
   	/**
102 102
   	 * The database driver name used
103 103
   	 * @var string
104 104
   	*/
105
-  	private $driver              = null;
105
+  	private $driver = null;
106 106
   	
107 107
 	
108 108
     /**
109 109
      * Construct new DatabaseQueryBuilder
110 110
      * @param object $pdo the PDO object
111 111
      */
112
-    public function __construct(PDO $pdo = null){
113
-        if (is_object($pdo)){
112
+    public function __construct(PDO $pdo = null) {
113
+        if (is_object($pdo)) {
114 114
           $this->setPdo($pdo);
115 115
         }
116 116
     }
@@ -120,10 +120,10 @@  discard block
 block discarded – undo
120 120
      * @param  string|array $table the table name or array of table list
121 121
      * @return object        the current DatabaseQueryBuilder instance
122 122
      */
123
-    public function from($table){
124
-	  if (is_array($table)){
123
+    public function from($table) {
124
+	  if (is_array($table)) {
125 125
         $froms = '';
126
-        foreach($table as $key){
126
+        foreach ($table as $key) {
127 127
           $froms .= $this->getPrefix() . $key . ', ';
128 128
         }
129 129
         $this->from = rtrim($froms, ', ');
@@ -138,7 +138,7 @@  discard block
 block discarded – undo
138 138
      * @param  string|array $fields the field name or array of field list
139 139
      * @return object        the current DatabaseQueryBuilder instance
140 140
      */
141
-    public function select($fields){
141
+    public function select($fields) {
142 142
       $select = (is_array($fields) ? implode(', ', $fields) : $fields);
143 143
       $this->select = (($this->select == '*' || empty($this->select)) ? $select : $this->select . ', ' . $select);
144 144
       return $this;
@@ -149,7 +149,7 @@  discard block
 block discarded – undo
149 149
      * @param  string $field the field name to distinct
150 150
      * @return object        the current DatabaseQueryBuilder instance
151 151
      */
152
-    public function distinct($field){
152
+    public function distinct($field) {
153 153
       $distinct = ' DISTINCT ' . $field;
154 154
       $this->select = (($this->select == '*' || empty($this->select)) ? $distinct : $this->select . ', ' . $distinct);
155 155
       return $this;
@@ -161,7 +161,7 @@  discard block
 block discarded – undo
161 161
      * @param  string $name  if is not null represent the alias used for this field in the result
162 162
      * @return object        the current DatabaseQueryBuilder instance
163 163
      */
164
-    public function count($field = '*', $name = null){
164
+    public function count($field = '*', $name = null) {
165 165
       return $this->select_min_max_sum_count_avg('COUNT', $field, $name);
166 166
     }
167 167
     
@@ -171,7 +171,7 @@  discard block
 block discarded – undo
171 171
      * @param  string $name  if is not null represent the alias used for this field in the result
172 172
      * @return object        the current DatabaseQueryBuilder instance
173 173
      */
174
-    public function min($field, $name = null){
174
+    public function min($field, $name = null) {
175 175
       return $this->select_min_max_sum_count_avg('MIN', $field, $name);
176 176
     }
177 177
 
@@ -181,7 +181,7 @@  discard block
 block discarded – undo
181 181
      * @param  string $name  if is not null represent the alias used for this field in the result
182 182
      * @return object        the current DatabaseQueryBuilder instance
183 183
      */
184
-    public function max($field, $name = null){
184
+    public function max($field, $name = null) {
185 185
       return $this->select_min_max_sum_count_avg('MAX', $field, $name);
186 186
     }
187 187
 
@@ -191,7 +191,7 @@  discard block
 block discarded – undo
191 191
      * @param  string $name  if is not null represent the alias used for this field in the result
192 192
      * @return object        the current DatabaseQueryBuilder instance
193 193
      */
194
-    public function sum($field, $name = null){
194
+    public function sum($field, $name = null) {
195 195
       return $this->select_min_max_sum_count_avg('SUM', $field, $name);
196 196
     }
197 197
 
@@ -201,7 +201,7 @@  discard block
 block discarded – undo
201 201
      * @param  string $name  if is not null represent the alias used for this field in the result
202 202
      * @return object        the current DatabaseQueryBuilder instance
203 203
      */
204
-    public function avg($field, $name = null){
204
+    public function avg($field, $name = null) {
205 205
       return $this->select_min_max_sum_count_avg('AVG', $field, $name);
206 206
     }
207 207
 
@@ -215,18 +215,18 @@  discard block
 block discarded – undo
215 215
      * @param  string $type   the type of join (INNER, LEFT, RIGHT)
216 216
      * @return object        the current DatabaseQueryBuilder instance
217 217
      */
218
-    public function join($table, $field1 = null, $op = null, $field2 = null, $type = ''){
218
+    public function join($table, $field1 = null, $op = null, $field2 = null, $type = '') {
219 219
       $on = $field1;
220 220
       $table = $this->getPrefix() . $table;
221
-      if (! is_null($op)){
222
-        $on = (! in_array($op, $this->operatorList) 
221
+      if (!is_null($op)) {
222
+        $on = (!in_array($op, $this->operatorList) 
223 223
 													? ($this->getPrefix() . $field1 . ' = ' . $this->getPrefix() . $op) 
224 224
 													: ($this->getPrefix() . $field1 . ' ' . $op . ' ' . $this->getPrefix() . $field2));
225 225
       }
226
-      if (empty($this->join)){
226
+      if (empty($this->join)) {
227 227
         $this->join = ' ' . $type . 'JOIN' . ' ' . $table . ' ON ' . $on;
228 228
       }
229
-      else{
229
+      else {
230 230
         $this->join = $this->join . ' ' . $type . 'JOIN' . ' ' . $table . ' ON ' . $on;
231 231
       }
232 232
       return $this;
@@ -237,7 +237,7 @@  discard block
 block discarded – undo
237 237
      * @see  DatabaseQueryBuilder::join()
238 238
      * @return object        the current DatabaseQueryBuilder instance
239 239
      */
240
-    public function innerJoin($table, $field1, $op = null, $field2 = ''){
240
+    public function innerJoin($table, $field1, $op = null, $field2 = '') {
241 241
       return $this->join($table, $field1, $op, $field2, 'INNER ');
242 242
     }
243 243
 
@@ -246,7 +246,7 @@  discard block
 block discarded – undo
246 246
      * @see  DatabaseQueryBuilder::join()
247 247
      * @return object        the current DatabaseQueryBuilder instance
248 248
      */
249
-    public function leftJoin($table, $field1, $op = null, $field2 = ''){
249
+    public function leftJoin($table, $field1, $op = null, $field2 = '') {
250 250
       return $this->join($table, $field1, $op, $field2, 'LEFT ');
251 251
 	}
252 252
 
@@ -255,7 +255,7 @@  discard block
 block discarded – undo
255 255
      * @see  DatabaseQueryBuilder::join()
256 256
      * @return object        the current DatabaseQueryBuilder instance
257 257
      */
258
-    public function rightJoin($table, $field1, $op = null, $field2 = ''){
258
+    public function rightJoin($table, $field1, $op = null, $field2 = '') {
259 259
       return $this->join($table, $field1, $op, $field2, 'RIGHT ');
260 260
     }
261 261
 
@@ -264,7 +264,7 @@  discard block
 block discarded – undo
264 264
      * @see  DatabaseQueryBuilder::join()
265 265
      * @return object        the current DatabaseQueryBuilder instance
266 266
      */
267
-    public function fullOuterJoin($table, $field1, $op = null, $field2 = ''){
267
+    public function fullOuterJoin($table, $field1, $op = null, $field2 = '') {
268 268
     	return $this->join($table, $field1, $op, $field2, 'FULL OUTER ');
269 269
     }
270 270
 
@@ -273,7 +273,7 @@  discard block
 block discarded – undo
273 273
      * @see  DatabaseQueryBuilder::join()
274 274
      * @return object        the current DatabaseQueryBuilder instance
275 275
      */
276
-    public function leftOuterJoin($table, $field1, $op = null, $field2 = ''){
276
+    public function leftOuterJoin($table, $field1, $op = null, $field2 = '') {
277 277
       return $this->join($table, $field1, $op, $field2, 'LEFT OUTER ');
278 278
     }
279 279
 
@@ -282,7 +282,7 @@  discard block
 block discarded – undo
282 282
      * @see  DatabaseQueryBuilder::join()
283 283
      * @return object        the current DatabaseQueryBuilder instance
284 284
      */
285
-    public function rightOuterJoin($table, $field1, $op = null, $field2 = ''){
285
+    public function rightOuterJoin($table, $field1, $op = null, $field2 = '') {
286 286
       return $this->join($table, $field1, $op, $field2, 'RIGHT OUTER ');
287 287
     }
288 288
 
@@ -292,13 +292,13 @@  discard block
 block discarded – undo
292 292
      * @param  string $andOr the separator type used 'AND', 'OR', etc.
293 293
      * @return object        the current DatabaseQueryBuilder instance
294 294
      */
295
-    public function whereIsNull($field, $andOr = 'AND'){
296
-      if (is_array($field)){
297
-        foreach($field as $f){
295
+    public function whereIsNull($field, $andOr = 'AND') {
296
+      if (is_array($field)) {
297
+        foreach ($field as $f) {
298 298
         	$this->whereIsNull($f, $andOr);
299 299
         }
300 300
       } else {
301
-          $this->setWhereStr($field.' IS NULL ', $andOr);
301
+          $this->setWhereStr($field . ' IS NULL ', $andOr);
302 302
       }
303 303
       return $this;
304 304
     }
@@ -309,13 +309,13 @@  discard block
 block discarded – undo
309 309
      * @param  string $andOr the separator type used 'AND', 'OR', etc.
310 310
      * @return object        the current DatabaseQueryBuilder instance
311 311
      */
312
-    public function whereIsNotNull($field, $andOr = 'AND'){
313
-      if (is_array($field)){
314
-        foreach($field as $f){
312
+    public function whereIsNotNull($field, $andOr = 'AND') {
313
+      if (is_array($field)) {
314
+        foreach ($field as $f) {
315 315
           $this->whereIsNotNull($f, $andOr);
316 316
         }
317 317
       } else {
318
-          $this->setWhereStr($field.' IS NOT NULL ', $andOr);
318
+          $this->setWhereStr($field . ' IS NOT NULL ', $andOr);
319 319
       }
320 320
       return $this;
321 321
     }
@@ -330,13 +330,13 @@  discard block
 block discarded – undo
330 330
      * @param  boolean $escape whether to escape or not the $val
331 331
      * @return object        the current DatabaseQueryBuilder instance
332 332
      */
333
-    public function where($where, $op = null, $val = null, $type = '', $andOr = 'AND', $escape = true){
333
+    public function where($where, $op = null, $val = null, $type = '', $andOr = 'AND', $escape = true) {
334 334
       $whereStr = '';
335
-      if (is_array($where)){
335
+      if (is_array($where)) {
336 336
         $whereStr = $this->getWhereStrIfIsArray($where, $type, $andOr, $escape);
337 337
       }
338
-      else{
339
-        if (is_array($op)){
338
+      else {
339
+        if (is_array($op)) {
340 340
           $whereStr = $this->getWhereStrIfOperatorIsArray($where, $op, $type, $escape);
341 341
         } else {
342 342
           $whereStr = $this->getWhereStrForOperator($where, $op, $val, $type, $escape);
@@ -351,7 +351,7 @@  discard block
 block discarded – undo
351 351
      * @see  DatabaseQueryBuilder::where()
352 352
      * @return object        the current DatabaseQueryBuilder instance
353 353
      */
354
-    public function orWhere($where, $op = null, $val = null, $escape = true){
354
+    public function orWhere($where, $op = null, $val = null, $escape = true) {
355 355
       return $this->where($where, $op, $val, '', 'OR', $escape);
356 356
     }
357 357
 
@@ -361,7 +361,7 @@  discard block
 block discarded – undo
361 361
      * @see  DatabaseQueryBuilder::where()
362 362
      * @return object        the current DatabaseQueryBuilder instance
363 363
      */
364
-    public function notWhere($where, $op = null, $val = null, $escape = true){
364
+    public function notWhere($where, $op = null, $val = null, $escape = true) {
365 365
       return $this->where($where, $op, $val, 'NOT ', 'AND', $escape);
366 366
     }
367 367
 
@@ -370,7 +370,7 @@  discard block
 block discarded – undo
370 370
      * @see  DatabaseQueryBuilder::where()
371 371
      * @return object        the current DatabaseQueryBuilder instance
372 372
      */
373
-    public function orNotWhere($where, $op = null, $val = null, $escape = true){
373
+    public function orNotWhere($where, $op = null, $val = null, $escape = true) {
374 374
     	return $this->where($where, $op, $val, 'NOT ', 'OR', $escape);
375 375
     }
376 376
 
@@ -380,11 +380,11 @@  discard block
 block discarded – undo
380 380
      * @param  string $andOr the multiple conditions separator (AND, OR, etc.)
381 381
      * @return object        the current DatabaseQueryBuilder instance
382 382
      */
383
-    public function groupStart($type = '', $andOr = ' AND'){
384
-      if (empty($this->where)){
383
+    public function groupStart($type = '', $andOr = ' AND') {
384
+      if (empty($this->where)) {
385 385
         $this->where = $type . ' (';
386 386
       } else {
387
-          if (substr(trim($this->where), -1) == '('){
387
+          if (substr(trim($this->where), -1) == '(') {
388 388
             $this->where .= $type . ' (';
389 389
           } else {
390 390
           	$this->where .= $andOr . ' ' . $type . ' (';
@@ -398,7 +398,7 @@  discard block
 block discarded – undo
398 398
      * @see  DatabaseQueryBuilder::groupStart()
399 399
      * @return object        the current DatabaseQueryBuilder instance
400 400
      */
401
-    public function notGroupStart(){
401
+    public function notGroupStart() {
402 402
       return $this->groupStart('NOT');
403 403
     }
404 404
 
@@ -407,7 +407,7 @@  discard block
 block discarded – undo
407 407
      * @see  DatabaseQueryBuilder::groupStart()
408 408
      * @return object        the current DatabaseQueryBuilder instance
409 409
      */
410
-    public function orGroupStart(){
410
+    public function orGroupStart() {
411 411
       return $this->groupStart('', ' OR');
412 412
     }
413 413
 
@@ -416,7 +416,7 @@  discard block
 block discarded – undo
416 416
      * @see  DatabaseQueryBuilder::groupStart()
417 417
      * @return object        the current DatabaseQueryBuilder instance
418 418
      */
419
-    public function orNotGroupStart(){
419
+    public function orNotGroupStart() {
420 420
       return $this->groupStart('NOT', ' OR');
421 421
     }
422 422
 
@@ -424,7 +424,7 @@  discard block
 block discarded – undo
424 424
      * Close the parenthesis for the grouped SQL
425 425
      * @return object        the current DatabaseQueryBuilder instance
426 426
      */
427
-    public function groupEnd(){
427
+    public function groupEnd() {
428 428
       $this->where .= ')';
429 429
       return $this;
430 430
     }
@@ -438,10 +438,10 @@  discard block
 block discarded – undo
438 438
      * @param  boolean $escape whether to escape or not the values
439 439
      * @return object        the current DatabaseQueryBuilder instance
440 440
      */
441
-    public function in($field, array $keys, $type = '', $andOr = 'AND', $escape = true){
441
+    public function in($field, array $keys, $type = '', $andOr = 'AND', $escape = true) {
442 442
       $_keys = array();
443
-      foreach ($keys as $k => $v){
444
-        if (is_null($v)){
443
+      foreach ($keys as $k => $v) {
444
+        if (is_null($v)) {
445 445
           $v = '';
446 446
         }
447 447
         $_keys[] = (is_numeric($v) ? $v : $this->escape($v, $escape));
@@ -457,7 +457,7 @@  discard block
 block discarded – undo
457 457
      * @see  DatabaseQueryBuilder::in()
458 458
      * @return object        the current DatabaseQueryBuilder instance
459 459
      */
460
-    public function notIn($field, array $keys, $escape = true){
460
+    public function notIn($field, array $keys, $escape = true) {
461 461
       return $this->in($field, $keys, 'NOT ', 'AND', $escape);
462 462
     }
463 463
 
@@ -466,7 +466,7 @@  discard block
 block discarded – undo
466 466
      * @see  DatabaseQueryBuilder::in()
467 467
      * @return object        the current DatabaseQueryBuilder instance
468 468
      */
469
-    public function orIn($field, array $keys, $escape = true){
469
+    public function orIn($field, array $keys, $escape = true) {
470 470
       return $this->in($field, $keys, '', 'OR', $escape);
471 471
     }
472 472
 
@@ -475,7 +475,7 @@  discard block
 block discarded – undo
475 475
      * @see  DatabaseQueryBuilder::in()
476 476
      * @return object        the current DatabaseQueryBuilder instance
477 477
      */
478
-    public function orNotIn($field, array $keys, $escape = true){
478
+    public function orNotIn($field, array $keys, $escape = true) {
479 479
       return $this->in($field, $keys, 'NOT ', 'OR', $escape);
480 480
     }
481 481
 
@@ -489,11 +489,11 @@  discard block
 block discarded – undo
489 489
      * @param  boolean $escape whether to escape or not the values
490 490
      * @return object        the current DatabaseQueryBuilder instance
491 491
      */
492
-    public function between($field, $value1, $value2, $type = '', $andOr = 'AND', $escape = true){
493
-      if (is_null($value1)){
492
+    public function between($field, $value1, $value2, $type = '', $andOr = 'AND', $escape = true) {
493
+      if (is_null($value1)) {
494 494
         $value1 = '';
495 495
       }
496
-      if (is_null($value2)){
496
+      if (is_null($value2)) {
497 497
         $value2 = '';
498 498
       }
499 499
       $whereStr = $field . ' ' . $type . ' BETWEEN ' . $this->escape($value1, $escape) . ' AND ' . $this->escape($value2, $escape);
@@ -506,7 +506,7 @@  discard block
 block discarded – undo
506 506
      * @see  DatabaseQueryBuilder::between()
507 507
      * @return object        the current DatabaseQueryBuilder instance
508 508
      */
509
-    public function notBetween($field, $value1, $value2, $escape = true){
509
+    public function notBetween($field, $value1, $value2, $escape = true) {
510 510
       return $this->between($field, $value1, $value2, 'NOT ', 'AND', $escape);
511 511
     }
512 512
 
@@ -515,7 +515,7 @@  discard block
 block discarded – undo
515 515
      * @see  DatabaseQueryBuilder::between()
516 516
      * @return object        the current DatabaseQueryBuilder instance
517 517
      */
518
-    public function orBetween($field, $value1, $value2, $escape = true){
518
+    public function orBetween($field, $value1, $value2, $escape = true) {
519 519
       return $this->between($field, $value1, $value2, '', 'OR', $escape);
520 520
     }
521 521
 
@@ -524,7 +524,7 @@  discard block
 block discarded – undo
524 524
      * @see  DatabaseQueryBuilder::between()
525 525
      * @return object        the current DatabaseQueryBuilder instance
526 526
      */
527
-    public function orNotBetween($field, $value1, $value2, $escape = true){
527
+    public function orNotBetween($field, $value1, $value2, $escape = true) {
528 528
       return $this->between($field, $value1, $value2, 'NOT ', 'OR', $escape);
529 529
     }
530 530
 
@@ -537,8 +537,8 @@  discard block
 block discarded – undo
537 537
      * @param  boolean $escape whether to escape or not the values
538 538
      * @return object        the current DatabaseQueryBuilder instance
539 539
      */
540
-    public function like($field, $data, $type = '', $andOr = 'AND', $escape = true){
541
-      if (empty($data)){
540
+    public function like($field, $data, $type = '', $andOr = 'AND', $escape = true) {
541
+      if (empty($data)) {
542 542
         $data = '';
543 543
       }
544 544
       $this->setWhereStr($field . ' ' . $type . ' LIKE ' . ($this->escape($data, $escape)), $andOr);
@@ -550,7 +550,7 @@  discard block
 block discarded – undo
550 550
      * @see  DatabaseQueryBuilder::like()
551 551
      * @return object        the current DatabaseQueryBuilder instance
552 552
      */
553
-    public function orLike($field, $data, $escape = true){
553
+    public function orLike($field, $data, $escape = true) {
554 554
       return $this->like($field, $data, '', 'OR', $escape);
555 555
     }
556 556
 
@@ -559,7 +559,7 @@  discard block
 block discarded – undo
559 559
      * @see  DatabaseQueryBuilder::like()
560 560
      * @return object        the current DatabaseQueryBuilder instance
561 561
      */
562
-    public function notLike($field, $data, $escape = true){
562
+    public function notLike($field, $data, $escape = true) {
563 563
       return $this->like($field, $data, 'NOT ', 'AND', $escape);
564 564
     }
565 565
 
@@ -568,7 +568,7 @@  discard block
 block discarded – undo
568 568
      * @see  DatabaseQueryBuilder::like()
569 569
      * @return object        the current DatabaseQueryBuilder instance
570 570
      */
571
-    public function orNotLike($field, $data, $escape = true){
571
+    public function orNotLike($field, $data, $escape = true) {
572 572
       return $this->like($field, $data, 'NOT ', 'OR', $escape);
573 573
     }
574 574
 
@@ -579,14 +579,14 @@  discard block
 block discarded – undo
579 579
      * @param  int $limitEnd the limit count
580 580
      * @return object        the current DatabaseQueryBuilder instance
581 581
      */
582
-    public function limit($limit, $limitEnd = null){
583
-      if (empty($limit)){
582
+    public function limit($limit, $limitEnd = null) {
583
+      if (empty($limit)) {
584 584
         $limit = 0;
585 585
       }
586
-      if (! is_null($limitEnd)){
586
+      if (!is_null($limitEnd)) {
587 587
         $this->limit = $limit . ', ' . $limitEnd;
588 588
       }
589
-      else{
589
+      else {
590 590
         $this->limit = $limit;
591 591
       }
592 592
       return $this;
@@ -598,11 +598,11 @@  discard block
 block discarded – undo
598 598
      * @param  string $orderDir the order direction (ASC or DESC)
599 599
      * @return object        the current DatabaseQueryBuilder instance
600 600
      */
601
-    public function orderBy($orderBy, $orderDir = ' ASC'){
602
-      if (stristr($orderBy, ' ') || $orderBy == 'rand()'){
601
+    public function orderBy($orderBy, $orderDir = ' ASC') {
602
+      if (stristr($orderBy, ' ') || $orderBy == 'rand()') {
603 603
         $this->orderBy = empty($this->orderBy) ? $orderBy : $this->orderBy . ', ' . $orderBy;
604 604
       }
605
-      else{
605
+      else {
606 606
         $this->orderBy = empty($this->orderBy) 
607 607
 						? ($orderBy . ' ' . strtoupper($orderDir)) 
608 608
 						: $this->orderBy . ', ' . $orderBy . ' ' . strtoupper($orderDir);
@@ -615,11 +615,11 @@  discard block
 block discarded – undo
615 615
      * @param  string|array $field the field name used or array of field list
616 616
      * @return object        the current DatabaseQueryBuilder instance
617 617
      */
618
-    public function groupBy($field){
619
-      if (is_array($field)){
618
+    public function groupBy($field) {
619
+      if (is_array($field)) {
620 620
         $this->groupBy = implode(', ', $field);
621 621
       }
622
-      else{
622
+      else {
623 623
         $this->groupBy = $field;
624 624
       }
625 625
       return $this;
@@ -633,18 +633,18 @@  discard block
 block discarded – undo
633 633
      * @param  boolean $escape whether to escape or not the values
634 634
      * @return object        the current DatabaseQueryBuilder instance
635 635
      */
636
-    public function having($field, $op = null, $val = null, $escape = true){
637
-      if (is_array($op)){
636
+    public function having($field, $op = null, $val = null, $escape = true) {
637
+      if (is_array($op)) {
638 638
         $this->having = $this->getHavingStrIfOperatorIsArray($field, $op, $escape);
639 639
       }
640
-      else if (! in_array($op, $this->operatorList)){
641
-        if (is_null($op)){
640
+      else if (!in_array($op, $this->operatorList)) {
641
+        if (is_null($op)) {
642 642
           $op = '';
643 643
         }
644 644
         $this->having = $field . ' > ' . ($this->escape($op, $escape));
645 645
       }
646
-      else{
647
-        if (is_null($val)){
646
+      else {
647
+        if (is_null($val)) {
648 648
           $val = '';
649 649
         }
650 650
         $this->having = $field . ' ' . $op . ' ' . ($this->escape($val, $escape));
@@ -658,7 +658,7 @@  discard block
 block discarded – undo
658 658
      * @param  boolean $escape  whether to escape or not the values
659 659
      * @return object  the current DatabaseQueryBuilder instance        
660 660
      */
661
-    public function insert($data = array(), $escape = true){
661
+    public function insert($data = array(), $escape = true) {
662 662
       $columns = array_keys($data);
663 663
       $column = implode(', ', $columns);
664 664
       $val = implode(', ', ($escape ? array_map(array($this, 'escape'), $data) : $data));
@@ -673,22 +673,22 @@  discard block
 block discarded – undo
673 673
      * @param  boolean $escape  whether to escape or not the values
674 674
      * @return object  the current DatabaseQueryBuilder instance 
675 675
      */
676
-    public function update($data = array(), $escape = true){
676
+    public function update($data = array(), $escape = true) {
677 677
       $query = 'UPDATE ' . $this->from . ' SET ';
678 678
       $values = array();
679
-      foreach ($data as $column => $val){
679
+      foreach ($data as $column => $val) {
680 680
         $values[] = $column . ' = ' . ($this->escape($val, $escape));
681 681
       }
682 682
       $query .= implode(', ', $values);
683
-      if (! empty($this->where)){
683
+      if (!empty($this->where)) {
684 684
         $query .= ' WHERE ' . $this->where;
685 685
       }
686 686
 
687
-      if (! empty($this->orderBy)){
687
+      if (!empty($this->orderBy)) {
688 688
         $query .= ' ORDER BY ' . $this->orderBy;
689 689
       }
690 690
 
691
-      if (! empty($this->limit)){
691
+      if (!empty($this->limit)) {
692 692
         $query .= ' LIMIT ' . $this->limit;
693 693
       }
694 694
       $this->query = $query;
@@ -699,22 +699,22 @@  discard block
 block discarded – undo
699 699
      * Delete the record in database
700 700
      * @return object  the current DatabaseQueryBuilder instance 
701 701
      */
702
-    public function delete(){
702
+    public function delete() {
703 703
     	$query = 'DELETE FROM ' . $this->from;
704 704
       $isTruncate = $query;
705
-    	if (! empty($this->where)){
705
+    	if (!empty($this->where)) {
706 706
   		  $query .= ' WHERE ' . $this->where;
707 707
     	}
708 708
 
709
-    	if (! empty($this->orderBy)){
709
+    	if (!empty($this->orderBy)) {
710 710
     	  $query .= ' ORDER BY ' . $this->orderBy;
711 711
       }
712 712
 
713
-    	if (! empty($this->limit)){
713
+    	if (!empty($this->limit)) {
714 714
     		$query .= ' LIMIT ' . $this->limit;
715 715
       }
716 716
 
717
-  		if ($isTruncate == $query && $this->driver != 'sqlite'){  
717
+  		if ($isTruncate == $query && $this->driver != 'sqlite') {  
718 718
       	$query = 'TRUNCATE TABLE ' . $this->from;
719 719
   		}
720 720
 	   $this->query = $query;
@@ -727,9 +727,9 @@  discard block
 block discarded – undo
727 727
      * @param boolean $escaped whether we can do escape of not 
728 728
      * @return mixed       the data after escaped or the same data if not
729 729
      */
730
-    public function escape($data, $escaped = true){
730
+    public function escape($data, $escaped = true) {
731 731
       $data = trim($data);
732
-      if($escaped){
732
+      if ($escaped) {
733 733
         return $this->pdo->quote($data);
734 734
       }
735 735
       return $data;  
@@ -740,31 +740,31 @@  discard block
 block discarded – undo
740 740
      * Return the current SQL query string
741 741
      * @return string
742 742
      */
743
-    public function getQuery(){
743
+    public function getQuery() {
744 744
   	  //INSERT, UPDATE, DELETE already set it, if is the SELECT we need set it now
745
-  	  if(empty($this->query)){
745
+  	  if (empty($this->query)) {
746 746
   		  $query = 'SELECT ' . $this->select . ' FROM ' . $this->from;
747
-  		  if (! empty($this->join)){
747
+  		  if (!empty($this->join)) {
748 748
           $query .= $this->join;
749 749
   		  }
750 750
   		  
751
-  		  if (! empty($this->where)){
751
+  		  if (!empty($this->where)) {
752 752
           $query .= ' WHERE ' . $this->where;
753 753
   		  }
754 754
 
755
-  		  if (! empty($this->groupBy)){
755
+  		  if (!empty($this->groupBy)) {
756 756
           $query .= ' GROUP BY ' . $this->groupBy;
757 757
   		  }
758 758
 
759
-  		  if (! empty($this->having)){
759
+  		  if (!empty($this->having)) {
760 760
           $query .= ' HAVING ' . $this->having;
761 761
   		  }
762 762
 
763
-  		  if (! empty($this->orderBy)){
763
+  		  if (!empty($this->orderBy)) {
764 764
   			  $query .= ' ORDER BY ' . $this->orderBy;
765 765
   		  }
766 766
 
767
-  		  if (! empty($this->limit)){
767
+  		  if (!empty($this->limit)) {
768 768
           $query .= ' LIMIT ' . $this->limit;
769 769
   		  }
770 770
   		  $this->query = $query;
@@ -777,7 +777,7 @@  discard block
 block discarded – undo
777 777
      * Return the PDO instance
778 778
      * @return object
779 779
      */
780
-    public function getPdo(){
780
+    public function getPdo() {
781 781
       return $this->pdo;
782 782
     }
783 783
 
@@ -786,7 +786,7 @@  discard block
 block discarded – undo
786 786
      * @param PDO $pdo the pdo object
787 787
 	   * @return object DatabaseQueryBuilder
788 788
      */
789
-    public function setPdo(PDO $pdo = null){
789
+    public function setPdo(PDO $pdo = null) {
790 790
       $this->pdo = $pdo;
791 791
       return $this;
792 792
     }
@@ -795,7 +795,7 @@  discard block
 block discarded – undo
795 795
    * Return the database table prefix
796 796
    * @return string
797 797
    */
798
-    public function getPrefix(){
798
+    public function getPrefix() {
799 799
       return $this->prefix;
800 800
     }
801 801
 
@@ -804,7 +804,7 @@  discard block
 block discarded – undo
804 804
      * @param string $prefix the new prefix
805 805
 	   * @return object DatabaseQueryBuilder
806 806
      */
807
-    public function setPrefix($prefix){
807
+    public function setPrefix($prefix) {
808 808
       $this->prefix = $prefix;
809 809
       return $this;
810 810
     }
@@ -813,7 +813,7 @@  discard block
 block discarded – undo
813 813
      * Return the database driver
814 814
      * @return string
815 815
      */
816
-    public function getDriver(){
816
+    public function getDriver() {
817 817
       return $this->driver;
818 818
     }
819 819
 
@@ -822,7 +822,7 @@  discard block
 block discarded – undo
822 822
      * @param string $driver the new driver
823 823
 	   * @return object DatabaseQueryBuilder
824 824
      */
825
-    public function setDriver($driver){
825
+    public function setDriver($driver) {
826 826
       $this->driver = $driver;
827 827
       return $this;
828 828
     }
@@ -831,7 +831,7 @@  discard block
 block discarded – undo
831 831
      * Reset the DatabaseQueryBuilder class attributs to the initial values before each query.
832 832
 	   * @return object  the current DatabaseQueryBuilder instance 
833 833
      */
834
-    public function reset(){
834
+    public function reset() {
835 835
       $this->select   = '*';
836 836
       $this->from     = null;
837 837
       $this->where    = null;
@@ -850,12 +850,12 @@  discard block
 block discarded – undo
850 850
      *
851 851
      * @return string
852 852
      */
853
-    protected function getHavingStrIfOperatorIsArray($field, $op = null, $escape = true){
853
+    protected function getHavingStrIfOperatorIsArray($field, $op = null, $escape = true) {
854 854
         $x = explode('?', $field);
855 855
         $w = '';
856
-        foreach($x as $k => $v){
857
-  	      if (!empty($v)){
858
-            if (! isset($op[$k])){
856
+        foreach ($x as $k => $v) {
857
+  	      if (!empty($v)) {
858
+            if (!isset($op[$k])) {
859 859
               $op[$k] = '';
860 860
             }
861 861
   	      	$w .= $v . (isset($op[$k]) ? $this->escape($op[$k], $escape) : '');
@@ -871,15 +871,15 @@  discard block
 block discarded – undo
871 871
      *
872 872
      * @return string
873 873
      */
874
-    protected function getWhereStrIfIsArray(array $where, $type = '', $andOr = 'AND', $escape = true){
874
+    protected function getWhereStrIfIsArray(array $where, $type = '', $andOr = 'AND', $escape = true) {
875 875
       $_where = array();
876
-      foreach ($where as $column => $data){
877
-        if (is_null($data)){
876
+      foreach ($where as $column => $data) {
877
+        if (is_null($data)) {
878 878
           $data = '';
879 879
         }
880 880
         $_where[] = $type . $column . ' = ' . ($this->escape($data, $escape));
881 881
       }
882
-      $where = implode(' '.$andOr.' ', $_where);
882
+      $where = implode(' ' . $andOr . ' ', $_where);
883 883
       return $where;
884 884
     }
885 885
 
@@ -889,12 +889,12 @@  discard block
 block discarded – undo
889 889
      *
890 890
      * @return string
891 891
      */
892
-    protected function getWhereStrIfOperatorIsArray($where, array $op, $type = '', $escape = true){
892
+    protected function getWhereStrIfOperatorIsArray($where, array $op, $type = '', $escape = true) {
893 893
      $x = explode('?', $where);
894 894
      $w = '';
895
-      foreach($x as $k => $v){
896
-        if (! empty($v)){
897
-            if (isset($op[$k]) && is_null($op[$k])){
895
+      foreach ($x as $k => $v) {
896
+        if (!empty($v)) {
897
+            if (isset($op[$k]) && is_null($op[$k])) {
898 898
               $op[$k] = '';
899 899
             }
900 900
             $w .= $type . $v . (isset($op[$k]) ? ($this->escape($op[$k], $escape)) : '');
@@ -909,15 +909,15 @@  discard block
 block discarded – undo
909 909
      *
910 910
      * @return string
911 911
      */
912
-    protected function getWhereStrForOperator($where, $op = null, $val = null, $type = '', $escape = true){
912
+    protected function getWhereStrForOperator($where, $op = null, $val = null, $type = '', $escape = true) {
913 913
        $w = '';
914
-       if (! in_array((string)$op, $this->operatorList)){
915
-          if (is_null($op)){
914
+       if (!in_array((string) $op, $this->operatorList)) {
915
+          if (is_null($op)) {
916 916
             $op = '';
917 917
           }
918 918
           $w = $type . $where . ' = ' . ($this->escape($op, $escape));
919 919
         } else {
920
-          if (is_null($val)){
920
+          if (is_null($val)) {
921 921
             $val = '';
922 922
           }
923 923
           $w = $type . $where . $op . ($this->escape($val, $escape));
@@ -930,14 +930,14 @@  discard block
 block discarded – undo
930 930
        * @param string $whereStr the WHERE clause string
931 931
        * @param  string  $andOr the separator type used 'AND', 'OR', etc.
932 932
        */
933
-      protected function setWhereStr($whereStr, $andOr = 'AND'){
934
-        if (empty($this->where)){
933
+      protected function setWhereStr($whereStr, $andOr = 'AND') {
934
+        if (empty($this->where)) {
935 935
           $this->where = $whereStr;
936 936
         } else {
937
-          if (substr(trim($this->where), -1) == '('){
937
+          if (substr(trim($this->where), -1) == '(') {
938 938
             $this->where = $this->where . ' ' . $whereStr;
939 939
           } else {
940
-            $this->where = $this->where . ' '.$andOr.' ' . $whereStr;
940
+            $this->where = $this->where . ' ' . $andOr . ' ' . $whereStr;
941 941
           }
942 942
         }
943 943
       }
@@ -953,7 +953,7 @@  discard block
 block discarded – undo
953 953
      * @see  DatabaseQueryBuilder::avg
954 954
      * @return object
955 955
      */
956
-    protected function select_min_max_sum_count_avg($clause, $field, $name = null){
956
+    protected function select_min_max_sum_count_avg($clause, $field, $name = null) {
957 957
       $clause = strtoupper($clause);
958 958
       $func = $clause . '(' . $field . ')' . (!is_null($name) ? ' AS ' . $name : '');
959 959
       $this->select = ($this->select == '*' ? $func : $this->select . ', ' . $func);
Please login to merge, or discard this patch.
core/classes/database/DatabaseQueryRunner.php 3 patches
Braces   +5 added lines, -10 removed lines patch added patch discarded remove patch
@@ -149,8 +149,7 @@  discard block
 block discarded – undo
149 149
           $isSqlSELECTQuery = stristr($this->query, 'SELECT') !== false;
150 150
           if($isSqlSELECTQuery){
151 151
               $this->setResultForSelect();              
152
-          }
153
-          else{
152
+          } else{
154 153
               $this->setResultForNonSelect();
155 154
           }
156 155
           return $this->queryResult;
@@ -172,15 +171,13 @@  discard block
 block discarded – undo
172 171
       }
173 172
       if ($this->returnAsList){
174 173
           $result = $this->pdoStatment->fetchAll($fetchMode);
175
-      }
176
-      else{
174
+      } else{
177 175
           $result = $this->pdoStatment->fetch($fetchMode);
178 176
       }
179 177
       //Sqlite and pgsql always return 0 when using rowCount()
180 178
       if (in_array($this->driver, array('sqlite', 'pgsql'))){
181 179
         $numRows = count($result);  
182
-      }
183
-      else{
180
+      } else{
184 181
         $numRows = $this->pdoStatment->rowCount(); 
185 182
       }
186 183
       if(! is_object($this->queryResult)){
@@ -201,8 +198,7 @@  discard block
 block discarded – undo
201 198
       if (in_array($this->driver, array('sqlite', 'pgsql'))){
202 199
         $result = true; //to test the result for the query like UPDATE, INSERT, DELETE
203 200
         $numRows = 1; //TODO use the correct method to get the exact affected row
204
-      }
205
-      else{
201
+      } else{
206 202
           //to test the result for the query like UPDATE, INSERT, DELETE
207 203
           $result  = $this->pdoStatment->rowCount() >= 0; 
208 204
           $numRows = $this->pdoStatment->rowCount(); 
@@ -380,8 +376,7 @@  discard block
 block discarded – undo
380 376
     protected function setLoggerFromParamOrCreateNewInstance(Log $logger = null){
381 377
       if ($logger !== null){
382 378
         $this->logger = $logger;
383
-      }
384
-      else{
379
+      } else{
385 380
           $this->logger =& class_loader('Log', 'classes');
386 381
           $this->logger->setLogger('Library::DatabaseQueryRunner');
387 382
       }
Please login to merge, or discard this patch.
Indentation   +156 added lines, -156 removed lines patch added patch discarded remove patch
@@ -1,85 +1,85 @@  discard block
 block discarded – undo
1 1
 <?php
2 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
-  class DatabaseQueryRunner extends BaseClass{
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
+    class DatabaseQueryRunner extends BaseClass{
27 27
       
28 28
    
29
-  	/**
30
-  	 * The last query result
31
-  	 * @var object
32
-  	*/
33
-  	private $queryResult       = null;
29
+        /**
30
+         * The last query result
31
+         * @var object
32
+         */
33
+        private $queryResult       = null;
34 34
   	
35
-  	/**
36
-    * The benchmark instance
37
-    * @var object
38
-    */
35
+        /**
36
+         * The benchmark instance
37
+         * @var object
38
+         */
39 39
     private $benchmarkInstance = null;
40 40
     
41 41
     /**
42
-	 * The SQL query statment to execute
43
-	 * @var string
44
-	*/
42
+     * The SQL query statment to execute
43
+     * @var string
44
+     */
45 45
     private $query             = null;
46 46
     
47 47
     /**
48
-	 * Indicate if we need return result as list (boolean) 
48
+     * Indicate if we need return result as list (boolean) 
49 49
      * or the data used to replace the placeholder (array)
50
-	 * @var array|boolean
51
-	 */
52
-     private $returnAsList     = true;
50
+     * @var array|boolean
51
+     */
52
+        private $returnAsList     = true;
53 53
      
54 54
      
55
-     /**
56
-	   * Indicate if we need return result as array or not
57
-     * @var boolean
58
-	   */
59
-     private $returnAsArray     = true;
55
+        /**
56
+         * Indicate if we need return result as array or not
57
+         * @var boolean
58
+         */
59
+        private $returnAsArray     = true;
60 60
      
61
-     /**
62
-     * The last PDOStatment instance
63
-     * @var object
64
-     */
65
-     private $pdoStatment       = null;
61
+        /**
62
+         * The last PDOStatment instance
63
+         * @var object
64
+         */
65
+        private $pdoStatment       = null;
66 66
      
67
-     /**
68
-  	 * The error returned for the last query
69
-  	 * @var string
70
-  	 */
71
-     private $error             = null;
67
+        /**
68
+         * The error returned for the last query
69
+         * @var string
70
+         */
71
+        private $error             = null;
72 72
 	
73 73
     /**
74 74
      * The PDO instance
75 75
      * @var object
76
-    */
76
+     */
77 77
     private $pdo                = null;
78 78
   
79 79
     /**
80 80
      * The database driver name used
81 81
      * @var string
82
-    */
82
+     */
83 83
     private $driver             = null;
84 84
 
85 85
 
@@ -94,7 +94,7 @@  discard block
 block discarded – undo
94 94
     public function __construct(PDO $pdo = null, $query = null, $returnAsList = true, $returnAsArray = false){
95 95
         parent::__construct();
96 96
         if (is_object($pdo)){
97
-          $this->pdo = $pdo;
97
+            $this->pdo = $pdo;
98 98
         }
99 99
         $this->query         = $query;
100 100
         $this->returnAsList  = $returnAsList;
@@ -112,10 +112,10 @@  discard block
 block discarded – undo
112 112
         //reset instance
113 113
         $this->reset();
114 114
        
115
-       //for database query execution time
115
+        //for database query execution time
116 116
         $benchmarkMarkerKey = $this->getBenchmarkKey();
117 117
         if (! is_object($this->benchmarkInstance)){
118
-          $this->benchmarkInstance = & class_loader('Benchmark');
118
+            $this->benchmarkInstance = & class_loader('Benchmark');
119 119
         }
120 120
         
121 121
         $this->logger->info('Execute SQL query [' . $this->query . ']');
@@ -128,101 +128,101 @@  discard block
 block discarded – undo
128 128
         $responseTime = $this->benchmarkInstance->elapsedTime(
129 129
                                                                 'DATABASE_QUERY_START(' . $benchmarkMarkerKey . ')', 
130 130
                                                                 'DATABASE_QUERY_END(' . $benchmarkMarkerKey . ')'
131
-                                                              );
132
-		    //TODO use the configuration value for the high response time currently is 1 second
131
+                                                                );
132
+            //TODO use the configuration value for the high response time currently is 1 second
133 133
         if ($responseTime >= 1 ){
134 134
             $this->logger->warning(
135 135
                                     'High response time while processing database query [' . $this->query . ']. 
136 136
                                      The response time is [' .$responseTime. '] sec.'
137
-                                  );
137
+                                    );
138 138
         }
139 139
 		
140 140
         if ($this->pdoStatment !== false){
141
-          $isSqlSELECTQuery = stristr($this->query, 'SELECT') !== false;
142
-          if($isSqlSELECTQuery){
143
-              $this->setResultForSelect();              
144
-          }
145
-          else{
146
-              $this->setResultForNonSelect();
147
-          }
148
-          return $this->queryResult;
141
+            $isSqlSELECTQuery = stristr($this->query, 'SELECT') !== false;
142
+            if($isSqlSELECTQuery){
143
+                $this->setResultForSelect();              
144
+            }
145
+            else{
146
+                $this->setResultForNonSelect();
147
+            }
148
+            return $this->queryResult;
149 149
         }
150 150
         $this->setQueryRunnerError();
151 151
     }
152 152
 	
153
-   /**
154
-   * Return the result for SELECT query
155
-   * @see DatabaseQueryRunner::execute
156
-   */
153
+    /**
154
+     * Return the result for SELECT query
155
+     * @see DatabaseQueryRunner::execute
156
+     */
157 157
     protected function setResultForSelect(){
158
-      //if need return all result like list of record
159
-      $result = null;
160
-      $numRows = 0;
161
-      $fetchMode = PDO::FETCH_OBJ;
162
-      if($this->returnAsArray){
158
+        //if need return all result like list of record
159
+        $result = null;
160
+        $numRows = 0;
161
+        $fetchMode = PDO::FETCH_OBJ;
162
+        if($this->returnAsArray){
163 163
         $fetchMode = PDO::FETCH_ASSOC;
164
-      }
165
-      if ($this->returnAsList){
166
-          $result = $this->pdoStatment->fetchAll($fetchMode);
167
-      }
168
-      else{
169
-          $result = $this->pdoStatment->fetch($fetchMode);
170
-      }
171
-      //Sqlite and pgsql always return 0 when using rowCount()
172
-      if (in_array($this->driver, array('sqlite', 'pgsql'))){
164
+        }
165
+        if ($this->returnAsList){
166
+            $result = $this->pdoStatment->fetchAll($fetchMode);
167
+        }
168
+        else{
169
+            $result = $this->pdoStatment->fetch($fetchMode);
170
+        }
171
+        //Sqlite and pgsql always return 0 when using rowCount()
172
+        if (in_array($this->driver, array('sqlite', 'pgsql'))){
173 173
         $numRows = count($result);  
174
-      }
175
-      else{
174
+        }
175
+        else{
176 176
         $numRows = $this->pdoStatment->rowCount(); 
177
-      }
178
-      if(! is_object($this->queryResult)){
179
-          $this->queryResult = & class_loader('DatabaseQueryResult', 'classes/database');
180
-      }
181
-      $this->queryResult->setResult($result);
182
-      $this->queryResult->setNumRows($numRows);
177
+        }
178
+        if(! is_object($this->queryResult)){
179
+            $this->queryResult = & class_loader('DatabaseQueryResult', 'classes/database');
180
+        }
181
+        $this->queryResult->setResult($result);
182
+        $this->queryResult->setNumRows($numRows);
183 183
     }
184 184
 
185 185
     /**
186
-   * Return the result for non SELECT query
187
-   * @see DatabaseQueryRunner::execute
188
-   */
186
+     * Return the result for non SELECT query
187
+     * @see DatabaseQueryRunner::execute
188
+     */
189 189
     protected function setResultForNonSelect(){
190
-      //Sqlite and pgsql always return 0 when using rowCount()
191
-      $result = false;
192
-      $numRows = 0;
193
-      if (in_array($this->driver, array('sqlite', 'pgsql'))){
190
+        //Sqlite and pgsql always return 0 when using rowCount()
191
+        $result = false;
192
+        $numRows = 0;
193
+        if (in_array($this->driver, array('sqlite', 'pgsql'))){
194 194
         $result = true; //to test the result for the query like UPDATE, INSERT, DELETE
195 195
         $numRows = 1; //TODO use the correct method to get the exact affected row
196
-      }
197
-      else{
198
-          //to test the result for the query like UPDATE, INSERT, DELETE
199
-          $result  = $this->pdoStatment->rowCount() >= 0; 
200
-          $numRows = $this->pdoStatment->rowCount(); 
201
-      }
202
-      if(! is_object($this->queryResult)){
203
-          $this->queryResult = & class_loader('DatabaseQueryResult', 'classes/database');
204
-      }
205
-      $this->queryResult->setResult($result);
206
-      $this->queryResult->setNumRows($numRows);
196
+        }
197
+        else{
198
+            //to test the result for the query like UPDATE, INSERT, DELETE
199
+            $result  = $this->pdoStatment->rowCount() >= 0; 
200
+            $numRows = $this->pdoStatment->rowCount(); 
201
+        }
202
+        if(! is_object($this->queryResult)){
203
+            $this->queryResult = & class_loader('DatabaseQueryResult', 'classes/database');
204
+        }
205
+        $this->queryResult->setResult($result);
206
+        $this->queryResult->setNumRows($numRows);
207 207
     }
208 208
 
209 209
 
210
-	/**
210
+    /**
211 211
      * Return the benchmark instance
212 212
      * @return Benchmark
213 213
      */
214 214
     public function getBenchmark(){
215
-      return $this->benchmarkInstance;
215
+        return $this->benchmarkInstance;
216 216
     }
217 217
 
218 218
     /**
219 219
      * Set the benchmark instance
220 220
      * @param Benchmark $benchmark the benchmark object
221
-	 * @return object DatabaseQueryRunner
221
+     * @return object DatabaseQueryRunner
222 222
      */
223 223
     public function setBenchmark($benchmark){
224
-      $this->benchmarkInstance = $benchmark;
225
-      return $this;
224
+        $this->benchmarkInstance = $benchmark;
225
+        return $this;
226 226
     }
227 227
     
228 228
     /**
@@ -231,18 +231,18 @@  discard block
 block discarded – undo
231 231
      * @return object DatabaseQueryResult
232 232
      */
233 233
     public function getQueryResult(){
234
-      return $this->queryResult;
234
+        return $this->queryResult;
235 235
     }
236 236
 
237 237
     /**
238 238
      * Set the database query result instance
239 239
      * @param object $queryResult the query result
240 240
      *
241
-	 * @return object DatabaseQueryRunner
241
+     * @return object DatabaseQueryRunner
242 242
      */
243 243
     public function setQueryResult(DatabaseQueryResult $queryResult){
244
-      $this->queryResult = $queryResult;
245
-      return $this;
244
+        $this->queryResult = $queryResult;
245
+        return $this;
246 246
     }
247 247
     
248 248
     /**
@@ -250,7 +250,7 @@  discard block
 block discarded – undo
250 250
      * @return string
251 251
      */
252 252
     public function getQuery(){
253
-      return $this->query;
253
+        return $this->query;
254 254
     }
255 255
     
256 256
     /**
@@ -259,8 +259,8 @@  discard block
 block discarded – undo
259 259
      * @return object DatabaseQueryRunner
260 260
      */
261 261
     public function setQuery($query){
262
-       $this->query = $query;
263
-       return $this;
262
+        $this->query = $query;
263
+        return $this;
264 264
     }
265 265
     
266 266
     /**
@@ -269,8 +269,8 @@  discard block
 block discarded – undo
269 269
      * @return object DatabaseQueryRunner
270 270
      */
271 271
     public function setReturnType($returnType){
272
-       $this->returnAsList = $returnType;
273
-       return $this;
272
+        $this->returnAsList = $returnType;
273
+        return $this;
274 274
     }
275 275
     
276 276
     /**
@@ -279,8 +279,8 @@  discard block
 block discarded – undo
279 279
      * @return object DatabaseQueryRunner
280 280
      */
281 281
     public function setReturnAsArray($status = true){
282
-       $this->returnAsArray = $status;
283
-       return $this;
282
+        $this->returnAsArray = $status;
283
+        return $this;
284 284
     }
285 285
     
286 286
     /**
@@ -288,7 +288,7 @@  discard block
 block discarded – undo
288 288
      * @return string
289 289
      */
290 290
     public function getQueryError(){
291
-      return $this->error;
291
+        return $this->error;
292 292
     }
293 293
 
294 294
     /**
@@ -296,7 +296,7 @@  discard block
 block discarded – undo
296 296
      * @return object
297 297
      */
298 298
     public function getPdo(){
299
-      return $this->pdo;
299
+        return $this->pdo;
300 300
     }
301 301
 
302 302
     /**
@@ -305,16 +305,16 @@  discard block
 block discarded – undo
305 305
      * @return object DatabaseQueryRunner
306 306
      */
307 307
     public function setPdo(PDO $pdo = null){
308
-      $this->pdo = $pdo;
309
-      return $this;
308
+        $this->pdo = $pdo;
309
+        return $this;
310 310
     }
311 311
   
312
-     /**
313
-     * Return the database driver
314
-     * @return string
315
-     */
312
+        /**
313
+         * Return the database driver
314
+         * @return string
315
+         */
316 316
     public function getDriver(){
317
-      return $this->driver;
317
+        return $this->driver;
318 318
     }
319 319
 
320 320
     /**
@@ -323,8 +323,8 @@  discard block
 block discarded – undo
323 323
      * @return object DatabaseQueryRunner
324 324
      */
325 325
     public function setDriver($driver){
326
-      $this->driver = $driver;
327
-      return $this;
326
+        $this->driver = $driver;
327
+        return $this;
328 328
     }
329 329
     
330 330
     /**
@@ -333,18 +333,18 @@  discard block
 block discarded – undo
333 333
      *  @return string
334 334
      */
335 335
     protected function getBenchmarkKey(){
336
-      return md5($this->query . $this->returnAsList . $this->returnAsArray);
336
+        return md5($this->query . $this->returnAsList . $this->returnAsArray);
337 337
     }
338 338
     
339 339
     /**
340 340
      * Set error for database query execution
341 341
      */
342 342
     protected function setQueryRunnerError(){
343
-      $error = $this->pdo->errorInfo();
344
-      $this->error = isset($error[2]) ? $error[2] : '';
345
-      $this->logger->error('The database query execution got an error: ' . stringfy_vars($error));
346
-	  //show error message
347
-      show_error('Query: "' . $this->query . '" Error: ' . $this->error, 'Database Error');
343
+        $error = $this->pdo->errorInfo();
344
+        $this->error = isset($error[2]) ? $error[2] : '';
345
+        $this->logger->error('The database query execution got an error: ' . stringfy_vars($error));
346
+        //show error message
347
+        show_error('Query: "' . $this->query . '" Error: ' . $this->error, 'Database Error');
348 348
     }
349 349
     
350 350
     /**
@@ -352,19 +352,19 @@  discard block
 block discarded – undo
352 352
      * @param object $logger the Log instance if not null
353 353
      */
354 354
     protected function setLoggerFromParamOrCreateNewInstance(Log $logger = null){
355
-      if ($logger !== null){
355
+        if ($logger !== null){
356 356
         $this->logger = $logger;
357
-      }
358
-      else{
359
-          $this->logger =& class_loader('Log', 'classes');
360
-          $this->logger->setLogger('Library::DatabaseQueryRunner');
361
-      }
357
+        }
358
+        else{
359
+            $this->logger =& class_loader('Log', 'classes');
360
+            $this->logger->setLogger('Library::DatabaseQueryRunner');
361
+        }
362 362
     }
363 363
     
364 364
     
365 365
     /**
366
-    * Reset the instance before run each query
367
-    */
366
+     * Reset the instance before run each query
367
+     */
368 368
     private function reset(){
369 369
         $this->error = null;
370 370
         $this->pdoStatment = null;
Please login to merge, or discard this patch.
Spacing   +49 added lines, -49 removed lines patch added patch discarded remove patch
@@ -23,14 +23,14 @@  discard block
 block discarded – undo
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
-  class DatabaseQueryRunner extends BaseClass{
26
+  class DatabaseQueryRunner extends BaseClass {
27 27
       
28 28
    
29 29
   	/**
30 30
   	 * The last query result
31 31
   	 * @var object
32 32
   	*/
33
-  	private $queryResult       = null;
33
+  	private $queryResult = null;
34 34
   	
35 35
   	/**
36 36
     * The benchmark instance
@@ -42,45 +42,45 @@  discard block
 block discarded – undo
42 42
 	 * The SQL query statment to execute
43 43
 	 * @var string
44 44
 	*/
45
-    private $query             = null;
45
+    private $query = null;
46 46
     
47 47
     /**
48 48
 	 * Indicate if we need return result as list (boolean) 
49 49
      * or the data used to replace the placeholder (array)
50 50
 	 * @var array|boolean
51 51
 	 */
52
-     private $returnAsList     = true;
52
+     private $returnAsList = true;
53 53
      
54 54
      
55 55
      /**
56 56
 	   * Indicate if we need return result as array or not
57 57
      * @var boolean
58 58
 	   */
59
-     private $returnAsArray     = true;
59
+     private $returnAsArray = true;
60 60
      
61 61
      /**
62 62
      * The last PDOStatment instance
63 63
      * @var object
64 64
      */
65
-     private $pdoStatment       = null;
65
+     private $pdoStatment = null;
66 66
      
67 67
      /**
68 68
   	 * The error returned for the last query
69 69
   	 * @var string
70 70
   	 */
71
-     private $error             = null;
71
+     private $error = null;
72 72
 	
73 73
     /**
74 74
      * The PDO instance
75 75
      * @var object
76 76
     */
77
-    private $pdo                = null;
77
+    private $pdo = null;
78 78
   
79 79
     /**
80 80
      * The database driver name used
81 81
      * @var string
82 82
     */
83
-    private $driver             = null;
83
+    private $driver = null;
84 84
 
85 85
 
86 86
 	
@@ -91,9 +91,9 @@  discard block
 block discarded – undo
91 91
      * @param boolean $returnAsList if need return as list or just one row
92 92
      * @param boolean $returnAsArray whether to return the result as array or not
93 93
      */
94
-    public function __construct(PDO $pdo = null, $query = null, $returnAsList = true, $returnAsArray = false){
94
+    public function __construct(PDO $pdo = null, $query = null, $returnAsList = true, $returnAsArray = false) {
95 95
         parent::__construct();
96
-        if (is_object($pdo)){
96
+        if (is_object($pdo)) {
97 97
           $this->pdo = $pdo;
98 98
         }
99 99
         $this->query         = $query;
@@ -108,13 +108,13 @@  discard block
 block discarded – undo
108 108
      * 
109 109
      * @return object|void
110 110
      */
111
-    public function execute(){
111
+    public function execute() {
112 112
         //reset instance
113 113
         $this->reset();
114 114
        
115 115
        //for database query execution time
116 116
         $benchmarkMarkerKey = $this->getBenchmarkKey();
117
-        if (! is_object($this->benchmarkInstance)){
117
+        if (!is_object($this->benchmarkInstance)) {
118 118
           $this->benchmarkInstance = & class_loader('Benchmark');
119 119
         }
120 120
         
@@ -130,19 +130,19 @@  discard block
 block discarded – undo
130 130
                                                                 'DATABASE_QUERY_END(' . $benchmarkMarkerKey . ')'
131 131
                                                               );
132 132
 		    //TODO use the configuration value for the high response time currently is 1 second
133
-        if ($responseTime >= 1 ){
133
+        if ($responseTime >= 1) {
134 134
             $this->logger->warning(
135 135
                                     'High response time while processing database query [' . $this->query . ']. 
136
-                                     The response time is [' .$responseTime. '] sec.'
136
+                                     The response time is [' .$responseTime . '] sec.'
137 137
                                   );
138 138
         }
139 139
 		
140
-        if ($this->pdoStatment !== false){
140
+        if ($this->pdoStatment !== false) {
141 141
           $isSqlSELECTQuery = stristr($this->query, 'SELECT') !== false;
142
-          if($isSqlSELECTQuery){
142
+          if ($isSqlSELECTQuery) {
143 143
               $this->setResultForSelect();              
144 144
           }
145
-          else{
145
+          else {
146 146
               $this->setResultForNonSelect();
147 147
           }
148 148
           return $this->queryResult;
@@ -154,28 +154,28 @@  discard block
 block discarded – undo
154 154
    * Return the result for SELECT query
155 155
    * @see DatabaseQueryRunner::execute
156 156
    */
157
-    protected function setResultForSelect(){
157
+    protected function setResultForSelect() {
158 158
       //if need return all result like list of record
159 159
       $result = null;
160 160
       $numRows = 0;
161 161
       $fetchMode = PDO::FETCH_OBJ;
162
-      if($this->returnAsArray){
162
+      if ($this->returnAsArray) {
163 163
         $fetchMode = PDO::FETCH_ASSOC;
164 164
       }
165
-      if ($this->returnAsList){
165
+      if ($this->returnAsList) {
166 166
           $result = $this->pdoStatment->fetchAll($fetchMode);
167 167
       }
168
-      else{
168
+      else {
169 169
           $result = $this->pdoStatment->fetch($fetchMode);
170 170
       }
171 171
       //Sqlite and pgsql always return 0 when using rowCount()
172
-      if (in_array($this->driver, array('sqlite', 'pgsql'))){
172
+      if (in_array($this->driver, array('sqlite', 'pgsql'))) {
173 173
         $numRows = count($result);  
174 174
       }
175
-      else{
175
+      else {
176 176
         $numRows = $this->pdoStatment->rowCount(); 
177 177
       }
178
-      if(! is_object($this->queryResult)){
178
+      if (!is_object($this->queryResult)) {
179 179
           $this->queryResult = & class_loader('DatabaseQueryResult', 'classes/database');
180 180
       }
181 181
       $this->queryResult->setResult($result);
@@ -186,20 +186,20 @@  discard block
 block discarded – undo
186 186
    * Return the result for non SELECT query
187 187
    * @see DatabaseQueryRunner::execute
188 188
    */
189
-    protected function setResultForNonSelect(){
189
+    protected function setResultForNonSelect() {
190 190
       //Sqlite and pgsql always return 0 when using rowCount()
191 191
       $result = false;
192 192
       $numRows = 0;
193
-      if (in_array($this->driver, array('sqlite', 'pgsql'))){
193
+      if (in_array($this->driver, array('sqlite', 'pgsql'))) {
194 194
         $result = true; //to test the result for the query like UPDATE, INSERT, DELETE
195 195
         $numRows = 1; //TODO use the correct method to get the exact affected row
196 196
       }
197
-      else{
197
+      else {
198 198
           //to test the result for the query like UPDATE, INSERT, DELETE
199 199
           $result  = $this->pdoStatment->rowCount() >= 0; 
200 200
           $numRows = $this->pdoStatment->rowCount(); 
201 201
       }
202
-      if(! is_object($this->queryResult)){
202
+      if (!is_object($this->queryResult)) {
203 203
           $this->queryResult = & class_loader('DatabaseQueryResult', 'classes/database');
204 204
       }
205 205
       $this->queryResult->setResult($result);
@@ -211,7 +211,7 @@  discard block
 block discarded – undo
211 211
      * Return the benchmark instance
212 212
      * @return Benchmark
213 213
      */
214
-    public function getBenchmark(){
214
+    public function getBenchmark() {
215 215
       return $this->benchmarkInstance;
216 216
     }
217 217
 
@@ -220,7 +220,7 @@  discard block
 block discarded – undo
220 220
      * @param Benchmark $benchmark the benchmark object
221 221
 	 * @return object DatabaseQueryRunner
222 222
      */
223
-    public function setBenchmark($benchmark){
223
+    public function setBenchmark($benchmark) {
224 224
       $this->benchmarkInstance = $benchmark;
225 225
       return $this;
226 226
     }
@@ -230,7 +230,7 @@  discard block
 block discarded – undo
230 230
      *
231 231
      * @return object DatabaseQueryResult
232 232
      */
233
-    public function getQueryResult(){
233
+    public function getQueryResult() {
234 234
       return $this->queryResult;
235 235
     }
236 236
 
@@ -240,7 +240,7 @@  discard block
 block discarded – undo
240 240
      *
241 241
 	 * @return object DatabaseQueryRunner
242 242
      */
243
-    public function setQueryResult(DatabaseQueryResult $queryResult){
243
+    public function setQueryResult(DatabaseQueryResult $queryResult) {
244 244
       $this->queryResult = $queryResult;
245 245
       return $this;
246 246
     }
@@ -249,7 +249,7 @@  discard block
 block discarded – undo
249 249
      * Return the current query SQL string
250 250
      * @return string
251 251
      */
252
-    public function getQuery(){
252
+    public function getQuery() {
253 253
       return $this->query;
254 254
     }
255 255
     
@@ -258,7 +258,7 @@  discard block
 block discarded – undo
258 258
      * @param string $query the SQL query to set
259 259
      * @return object DatabaseQueryRunner
260 260
      */
261
-    public function setQuery($query){
261
+    public function setQuery($query) {
262 262
        $this->query = $query;
263 263
        return $this;
264 264
     }
@@ -268,7 +268,7 @@  discard block
 block discarded – undo
268 268
      * @param boolean $returnType
269 269
      * @return object DatabaseQueryRunner
270 270
      */
271
-    public function setReturnType($returnType){
271
+    public function setReturnType($returnType) {
272 272
        $this->returnAsList = $returnType;
273 273
        return $this;
274 274
     }
@@ -278,7 +278,7 @@  discard block
 block discarded – undo
278 278
      * @param boolean $status the status if true will return as array
279 279
      * @return object DatabaseQueryRunner
280 280
      */
281
-    public function setReturnAsArray($status = true){
281
+    public function setReturnAsArray($status = true) {
282 282
        $this->returnAsArray = $status;
283 283
        return $this;
284 284
     }
@@ -287,7 +287,7 @@  discard block
 block discarded – undo
287 287
      * Return the error for last query execution
288 288
      * @return string
289 289
      */
290
-    public function getQueryError(){
290
+    public function getQueryError() {
291 291
       return $this->error;
292 292
     }
293 293
 
@@ -295,7 +295,7 @@  discard block
 block discarded – undo
295 295
      * Return the PDO instance
296 296
      * @return object
297 297
      */
298
-    public function getPdo(){
298
+    public function getPdo() {
299 299
       return $this->pdo;
300 300
     }
301 301
 
@@ -304,7 +304,7 @@  discard block
 block discarded – undo
304 304
      * @param PDO $pdo the pdo object
305 305
      * @return object DatabaseQueryRunner
306 306
      */
307
-    public function setPdo(PDO $pdo = null){
307
+    public function setPdo(PDO $pdo = null) {
308 308
       $this->pdo = $pdo;
309 309
       return $this;
310 310
     }
@@ -313,7 +313,7 @@  discard block
 block discarded – undo
313 313
      * Return the database driver
314 314
      * @return string
315 315
      */
316
-    public function getDriver(){
316
+    public function getDriver() {
317 317
       return $this->driver;
318 318
     }
319 319
 
@@ -322,7 +322,7 @@  discard block
 block discarded – undo
322 322
      * @param string $driver the new driver
323 323
      * @return object DatabaseQueryRunner
324 324
      */
325
-    public function setDriver($driver){
325
+    public function setDriver($driver) {
326 326
       $this->driver = $driver;
327 327
       return $this;
328 328
     }
@@ -332,14 +332,14 @@  discard block
 block discarded – undo
332 332
      * 
333 333
      *  @return string
334 334
      */
335
-    protected function getBenchmarkKey(){
335
+    protected function getBenchmarkKey() {
336 336
       return md5($this->query . $this->returnAsList . $this->returnAsArray);
337 337
     }
338 338
     
339 339
     /**
340 340
      * Set error for database query execution
341 341
      */
342
-    protected function setQueryRunnerError(){
342
+    protected function setQueryRunnerError() {
343 343
       $error = $this->pdo->errorInfo();
344 344
       $this->error = isset($error[2]) ? $error[2] : '';
345 345
       $this->logger->error('The database query execution got an error: ' . stringfy_vars($error));
@@ -351,12 +351,12 @@  discard block
 block discarded – undo
351 351
      * Set the Log instance using argument or create new instance
352 352
      * @param object $logger the Log instance if not null
353 353
      */
354
-    protected function setLoggerFromParamOrCreateNewInstance(Log $logger = null){
355
-      if ($logger !== null){
354
+    protected function setLoggerFromParamOrCreateNewInstance(Log $logger = null) {
355
+      if ($logger !== null) {
356 356
         $this->logger = $logger;
357 357
       }
358
-      else{
359
-          $this->logger =& class_loader('Log', 'classes');
358
+      else {
359
+          $this->logger = & class_loader('Log', 'classes');
360 360
           $this->logger->setLogger('Library::DatabaseQueryRunner');
361 361
       }
362 362
     }
@@ -365,7 +365,7 @@  discard block
 block discarded – undo
365 365
     /**
366 366
     * Reset the instance before run each query
367 367
     */
368
-    private function reset(){
368
+    private function reset() {
369 369
         $this->error = null;
370 370
         $this->pdoStatment = null;
371 371
     }
Please login to merge, or discard this patch.