@@ -17,48 +17,48 @@ discard block |
||
17 | 17 | */ |
18 | 18 | class InsertQueryBuilder extends QueryBuilder |
19 | 19 | { |
20 | - public function buildInsert($table, $obj){ |
|
20 | + public function buildInsert($table, $obj) { |
|
21 | 21 | $qb = new QueryBuilder(); |
22 | 22 | $query = "INSERT INTO ".$table." ("; |
23 | - foreach($obj as $key => $val){ |
|
24 | - $query.= $qb->quote($key).", "; |
|
23 | + foreach ($obj as $key => $val) { |
|
24 | + $query .= $qb->quote($key).", "; |
|
25 | 25 | } |
26 | 26 | |
27 | 27 | $query = rtrim($query, ", "); |
28 | - $query.= ") VALUES "; |
|
28 | + $query .= ") VALUES "; |
|
29 | 29 | |
30 | 30 | return $query; |
31 | 31 | } |
32 | 32 | |
33 | - public function buildInsertPlaceholder($rows){ |
|
33 | + public function buildInsertPlaceholder($rows) { |
|
34 | 34 | $ar = array(); |
35 | 35 | $query = "("; |
36 | 36 | |
37 | - foreach($rows as $key => $val){ |
|
37 | + foreach ($rows as $key => $val) { |
|
38 | 38 | $ar[$key] = $val; |
39 | - $query.= ":".$key.", "; |
|
39 | + $query .= ":".$key.", "; |
|
40 | 40 | } |
41 | 41 | |
42 | 42 | $query = rtrim($query, ", "); |
43 | - $query.=") "; |
|
43 | + $query .= ") "; |
|
44 | 44 | |
45 | 45 | return ['query' => $query, 'array' => $ar]; |
46 | 46 | } |
47 | 47 | |
48 | - public function buildInsertPlaceholders($rows){ |
|
48 | + public function buildInsertPlaceholders($rows) { |
|
49 | 49 | $bindAr = array(); |
50 | 50 | $query = ""; |
51 | 51 | |
52 | - foreach($rows as $i => $row){ |
|
53 | - $query.="("; |
|
54 | - foreach($row as $key => $val){ |
|
55 | - $param = ":" . $key . $i; |
|
56 | - $query.= $param.", "; |
|
52 | + foreach ($rows as $i => $row) { |
|
53 | + $query .= "("; |
|
54 | + foreach ($row as $key => $val) { |
|
55 | + $param = ":".$key.$i; |
|
56 | + $query .= $param.", "; |
|
57 | 57 | $bindAr[$param] = $val; |
58 | 58 | } |
59 | 59 | |
60 | 60 | $query = rtrim($query, ", "); |
61 | - $query.="), "; |
|
61 | + $query .= "), "; |
|
62 | 62 | } |
63 | 63 | |
64 | 64 | $query = rtrim($query, ", "); |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | $dataToBuild = $rows; |
83 | 83 | $methodToCall = 'buildInsertPlaceholder'; |
84 | 84 | |
85 | - if(is_array($rows) && isset($rows[0]) && is_array($rows[0])){ |
|
85 | + if (is_array($rows) && isset($rows[0]) && is_array($rows[0])) { |
|
86 | 86 | $dataToBuild = $rows[0]; |
87 | 87 | $methodToCall = 'buildInsertPlaceholders'; |
88 | 88 | } |
@@ -91,21 +91,21 @@ discard block |
||
91 | 91 | $dataRet = $this->$methodToCall($rows); |
92 | 92 | $returnQuery = $dataRet['query']; |
93 | 93 | $bindAr = $dataRet['array']; |
94 | - $query.= $returnQuery; |
|
94 | + $query .= $returnQuery; |
|
95 | 95 | |
96 | - try{ |
|
96 | + try { |
|
97 | 97 | $stmt = $db->prepare($qb->queryPrefix($query)); |
98 | 98 | |
99 | - if(is_array($rows) && isset($rows[0]) && is_array($rows[0])){ |
|
100 | - foreach($bindAr as $param => $val){ |
|
99 | + if (is_array($rows) && isset($rows[0]) && is_array($rows[0])) { |
|
100 | + foreach ($bindAr as $param => $val) { |
|
101 | 101 | $stmt->bindValue($param, $val); |
102 | 102 | } |
103 | 103 | |
104 | 104 | $stmt->execute(); |
105 | - } else{ |
|
105 | + } else { |
|
106 | 106 | $stmt->execute($bindAr); |
107 | 107 | } |
108 | - } catch(Exception $e){ |
|
108 | + } catch (Exception $e) { |
|
109 | 109 | throw new Exception($e->getMessage()); |
110 | 110 | } |
111 | 111 |
@@ -38,7 +38,9 @@ |
||
38 | 38 | $query = "UPDATE ".$this->table()." SET "; |
39 | 39 | foreach($row as $key => $val){ |
40 | 40 | $ar[':'.$key] = $val; |
41 | - if($key == 'id') continue; |
|
41 | + if($key == 'id') { |
|
42 | + continue; |
|
43 | + } |
|
42 | 44 | $query.= $qb->quote($key)." =:".$key.","; |
43 | 45 | } |
44 | 46 |
@@ -35,30 +35,30 @@ |
||
35 | 35 | // our object is set. Now we need to save it |
36 | 36 | $queryVal = ''; |
37 | 37 | $query = "INSERT INTO ".$this->table()." ("; |
38 | - foreach($row as $key => $val){ |
|
39 | - $query.= $qb->quote($key).", "; |
|
38 | + foreach ($row as $key => $val) { |
|
39 | + $query .= $qb->quote($key).", "; |
|
40 | 40 | $ar[$key] = $val; |
41 | - $queryVal.= ":".$key.", "; |
|
41 | + $queryVal .= ":".$key.", "; |
|
42 | 42 | } |
43 | 43 | |
44 | 44 | $query = rtrim($query, ", ").") VALUES (".$queryVal.rtrim($query, ", ").") "; |
45 | 45 | |
46 | - if(isset($row) && isset($row->id) && $row->id > 0 ){ |
|
46 | + if (isset($row) && isset($row->id) && $row->id > 0) { |
|
47 | 47 | $query = "UPDATE ".$this->table()." SET "; |
48 | - foreach($row as $key => $val){ |
|
48 | + foreach ($row as $key => $val) { |
|
49 | 49 | $ar[':'.$key] = $val; |
50 | - if($key == 'id') continue; |
|
51 | - $query.= $qb->quote($key)." =:".$key.","; |
|
50 | + if ($key == 'id') continue; |
|
51 | + $query .= $qb->quote($key)." =:".$key.","; |
|
52 | 52 | } |
53 | 53 | |
54 | 54 | $query = rtrim($query, ","); |
55 | - $query.= " WHERE ".$qb->quote('id')."=:id"; |
|
55 | + $query .= " WHERE ".$qb->quote('id')."=:id"; |
|
56 | 56 | } |
57 | 57 | |
58 | - try{ |
|
58 | + try { |
|
59 | 59 | $stmt = Connection::get()->prepare($qb->queryPrefix($query)); |
60 | 60 | $stmt->execute($ar); |
61 | - } catch(Exception $e){ |
|
61 | + } catch (Exception $e) { |
|
62 | 62 | throw new Exception($e->getMessage()); |
63 | 63 | } |
64 | 64 |
@@ -15,7 +15,7 @@ |
||
15 | 15 | $dbCredentials = require('database.php'); |
16 | 16 | $var = $arguments[0]; |
17 | 17 | |
18 | - if(array_key_exists($var, $dbCredentials)){ |
|
18 | + if (array_key_exists($var, $dbCredentials)) { |
|
19 | 19 | return $dbCredentials[$var]; |
20 | 20 | } |
21 | 21 |
@@ -26,7 +26,7 @@ |
||
26 | 26 | |
27 | 27 | public function __call($method, $parameters) |
28 | 28 | { |
29 | - if($method== 'asArray'){ |
|
29 | + if ($method == 'asArray') { |
|
30 | 30 | // $obj = new Utils(); |
31 | 31 | } |
32 | 32 | } |
@@ -50,16 +50,16 @@ |
||
50 | 50 | return $destination; |
51 | 51 | } |
52 | 52 | |
53 | - /** |
|
54 | - * Turn the stadClass object to the type of calling Model |
|
55 | - * |
|
56 | - * @param String $destination |
|
57 | - * @param Object $sourceObject |
|
58 | - * @return Object $destination |
|
59 | - * |
|
60 | - * @author RN Kushwaha <[email protected]> |
|
61 | - * @since v0.0.5 |
|
62 | - */ |
|
53 | + /** |
|
54 | + * Turn the stadClass object to the type of calling Model |
|
55 | + * |
|
56 | + * @param String $destination |
|
57 | + * @param Object $sourceObject |
|
58 | + * @return Object $destination |
|
59 | + * |
|
60 | + * @author RN Kushwaha <[email protected]> |
|
61 | + * @since v0.0.5 |
|
62 | + */ |
|
63 | 63 | public function turnObjects($destination, $data) |
64 | 64 | { |
65 | 65 | $destination = new $destination(); |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | public function turnObject($destination, $sourceObject) |
29 | 29 | { |
30 | 30 | $destination = new $destination(); |
31 | - if(is_object($sourceObject)){ |
|
31 | + if (is_object($sourceObject)) { |
|
32 | 32 | $sourceReflection = new \ReflectionObject($sourceObject); |
33 | 33 | $destinationReflection = new \ReflectionObject($destination); |
34 | 34 | $sourceProperties = $sourceReflection->getProperties(); |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | if ($destinationReflection->hasProperty($name)) { |
42 | 42 | $propDest = $destinationReflection->getProperty($name); |
43 | 43 | $propDest->setAccessible(true); |
44 | - $propDest->setValue($destination,$value); |
|
44 | + $propDest->setValue($destination, $value); |
|
45 | 45 | } else { |
46 | 46 | $destination->$name = $value; |
47 | 47 | } |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | public function turnObjects($destination, $data) |
64 | 64 | { |
65 | 65 | $destination = new $destination(); |
66 | - if(count($data)){ |
|
66 | + if (count($data)) { |
|
67 | 67 | $destination->data = json_decode(json_encode($data, true)); |
68 | 68 | } |
69 | 69 |
@@ -13,11 +13,11 @@ |
||
13 | 13 | */ |
14 | 14 | class WhereQueryBuilder extends QueryBuilder |
15 | 15 | { |
16 | - private $qb; |
|
16 | + private $qb; |
|
17 | 17 | |
18 | - public function __construct(){ |
|
18 | + public function __construct(){ |
|
19 | 19 | $this->qb = new QueryBuilder(); |
20 | - } |
|
20 | + } |
|
21 | 21 | |
22 | 22 | protected function prepareArrayForWhere($bindKey, $bindVal = null){ |
23 | 23 | $ar = $conditionAr = array(); |
@@ -15,11 +15,11 @@ discard block |
||
15 | 15 | { |
16 | 16 | private $qb; |
17 | 17 | |
18 | - public function __construct(){ |
|
18 | + public function __construct() { |
|
19 | 19 | $this->qb = new QueryBuilder(); |
20 | 20 | } |
21 | 21 | |
22 | - protected function prepareArrayForWhere($bindKey, $bindVal = null){ |
|
22 | + protected function prepareArrayForWhere($bindKey, $bindVal = null) { |
|
23 | 23 | $ar = $conditionAr = array(); |
24 | 24 | // expecting a string like 'status = :status' |
25 | 25 | if ($this->checkWherePrepareUsed($bindKey)) { |
@@ -70,7 +70,7 @@ discard block |
||
70 | 70 | |
71 | 71 | foreach ($conditions as $where) { |
72 | 72 | $sign = '='; |
73 | - if(count($where)==3) { |
|
73 | + if (count($where) == 3) { |
|
74 | 74 | $sign = $where[1]; |
75 | 75 | } |
76 | 76 | if ($firstTime) { |
@@ -164,11 +164,11 @@ discard block |
||
164 | 164 | public function where() |
165 | 165 | { |
166 | 166 | $args = func_get_args(); |
167 | - if(func_num_args()===2){ |
|
167 | + if (func_num_args() === 2) { |
|
168 | 168 | $this->where = array_merge($this->where, [[$args[0], '=', $args[1]]]); |
169 | - } elseif(func_num_args()===3){ |
|
169 | + } elseif (func_num_args() === 3) { |
|
170 | 170 | $this->where = array_merge($this->where, [[$args[0], $args[1], $args[2]]]); |
171 | - } else{ |
|
171 | + } else { |
|
172 | 172 | throw new Exception('Where parameter contains invalid number of parameters', 1); |
173 | 173 | } |
174 | 174 | |
@@ -442,7 +442,7 @@ discard block |
||
442 | 442 | |
443 | 443 | $row = $this->first(); |
444 | 444 | |
445 | - if($row == null ){ |
|
445 | + if ($row == null) { |
|
446 | 446 | throw new Exception("The record does not exists!"); |
447 | 447 | } |
448 | 448 | |
@@ -471,9 +471,9 @@ discard block |
||
471 | 471 | $qb = new QueryBuilder(); |
472 | 472 | $query = "TRUNCATE ".$this->table(); |
473 | 473 | |
474 | - try{ |
|
474 | + try { |
|
475 | 475 | Connection::get()->query($qb->queryPrefix($query)); |
476 | - } catch(Exception $e){ |
|
476 | + } catch (Exception $e) { |
|
477 | 477 | throw new Exception($e->getMessage()); |
478 | 478 | } |
479 | 479 | |
@@ -510,20 +510,20 @@ discard block |
||
510 | 510 | $query = "UPDATE ".$this->table()." SET "; |
511 | 511 | $ar = array(); |
512 | 512 | |
513 | - foreach($row as $key => $val){ |
|
513 | + foreach ($row as $key => $val) { |
|
514 | 514 | $ar[':'.$key] = $val; |
515 | - $query.= $qb->quote($key)." =:".$key.","; |
|
515 | + $query .= $qb->quote($key)." =:".$key.","; |
|
516 | 516 | } |
517 | 517 | |
518 | 518 | $query = rtrim($query, ","); |
519 | 519 | |
520 | - try{ |
|
520 | + try { |
|
521 | 521 | $whereQuery = $this->buildAllWhereQuery(); |
522 | - $query.= " ".join(" ", $whereQuery); |
|
522 | + $query .= " ".join(" ", $whereQuery); |
|
523 | 523 | $stmt = Connection::get()->prepare($qb->queryPrefix($query)); |
524 | 524 | $stmt->execute($ar); |
525 | 525 | $this->reset(); |
526 | - } catch(Exception $e){ |
|
526 | + } catch (Exception $e) { |
|
527 | 527 | throw new Exception($e->getMessage()); |
528 | 528 | } |
529 | 529 | |
@@ -543,12 +543,12 @@ discard block |
||
543 | 543 | $qb = new QueryBuilder(); |
544 | 544 | $query = "DELETE FROM ".$this->table(); |
545 | 545 | |
546 | - try{ |
|
546 | + try { |
|
547 | 547 | $whereQuery = $this->buildAllWhereQuery(); |
548 | - $query.= " ".join(" ", $whereQuery); |
|
548 | + $query .= " ".join(" ", $whereQuery); |
|
549 | 549 | Connection::get()->query($qb->queryPrefix($query)); |
550 | 550 | $this->reset(); |
551 | - } catch(Exception $e){ |
|
551 | + } catch (Exception $e) { |
|
552 | 552 | throw new Exception($e->getMessage()); |
553 | 553 | } |
554 | 554 |