@@ -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 | |
@@ -33,35 +33,35 @@ |
||
| 33 | 33 | $ar = array(); |
| 34 | 34 | |
| 35 | 35 | // our object is set. Now we need to save it |
| 36 | - if(isset($row) && isset($row->id) && $row->id > 0 ){ |
|
| 36 | + if (isset($row) && isset($row->id) && $row->id > 0) { |
|
| 37 | 37 | $query = "UPDATE ".$this->table()." SET "; |
| 38 | - foreach($row as $key => $val){ |
|
| 38 | + foreach ($row as $key => $val) { |
|
| 39 | 39 | $ar[':'.$key] = $val; |
| 40 | - if($key == 'id') continue; |
|
| 41 | - $query.= $qb->quote($key)." =:".$key.","; |
|
| 40 | + if ($key == 'id') continue; |
|
| 41 | + $query .= $qb->quote($key)." =:".$key.","; |
|
| 42 | 42 | } |
| 43 | 43 | |
| 44 | 44 | $query = rtrim($query, ","); |
| 45 | - $query.= " WHERE ".$qb->quote('id')."=:id"; |
|
| 46 | - } else{ |
|
| 45 | + $query .= " WHERE ".$qb->quote('id')."=:id"; |
|
| 46 | + } else { |
|
| 47 | 47 | $queryVal = ''; |
| 48 | 48 | $query = "INSERT INTO ".$this->table()." ("; |
| 49 | - foreach($row as $key => $val){ |
|
| 50 | - $query.= $qb->quote($key).", "; |
|
| 49 | + foreach ($row as $key => $val) { |
|
| 50 | + $query .= $qb->quote($key).", "; |
|
| 51 | 51 | $ar[$key] = $val; |
| 52 | - $queryVal.= ":".$key.", "; |
|
| 52 | + $queryVal .= ":".$key.", "; |
|
| 53 | 53 | } |
| 54 | 54 | |
| 55 | 55 | $query = rtrim($query, ", "); |
| 56 | - $query.= ") VALUES (".$queryVal; |
|
| 56 | + $query .= ") VALUES (".$queryVal; |
|
| 57 | 57 | $query = rtrim($query, ", "); |
| 58 | - $query.=") "; |
|
| 58 | + $query .= ") "; |
|
| 59 | 59 | } |
| 60 | 60 | |
| 61 | - try{ |
|
| 61 | + try { |
|
| 62 | 62 | $stmt = Connection::get()->prepare($qb->queryPrefix($query)); |
| 63 | 63 | $stmt->execute($ar); |
| 64 | - } catch(Exception $e){ |
|
| 64 | + } catch (Exception $e) { |
|
| 65 | 65 | throw new Exception($e->getMessage()); |
| 66 | 66 | } |
| 67 | 67 | |