Skip to content

Commit

Permalink
removed sanity text and added order method
Browse files Browse the repository at this point in the history
  • Loading branch information
josephmancuso committed Sep 2, 2017
1 parent 3bbccd9 commit 1bd62fc
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class Model
private $update = false;
public $structure = array();
private $db_engine = false;
private $order_by = '';

public function __construct($default_database = null)
{
Expand Down Expand Up @@ -246,6 +247,7 @@ private function getClassCreateVariables()
unset($allClassProperties['structure']);
unset($defaultClassProperties['structure']);
unset($allClassProperties['information']);
unset($allClassProperties['order_by']);

return array_diff($allClassProperties, $defaultClassProperties);
}
Expand Down Expand Up @@ -415,7 +417,6 @@ public function __call($method, $value)
if (isset($this->$method)) {
return $cl->find($this->$method);
}
echo $method;
return $cl;
} elseif (is_integer($value[0])) {

Expand Down Expand Up @@ -493,7 +494,6 @@ public function createUpdateQuery()
$id = $this->id;
unset($this->id);
$values = "";
var_dump($this->getClassCreateVariables());
foreach ($this->getClassCreateVariables() as $key => $value) {
$values .= " `".$key."` = :".$key.",";
}
Expand Down Expand Up @@ -757,14 +757,35 @@ public function triggerEvent($event)
}
}
}

public function order($order)
{
$explode = explode(',', $order);

$orderby = "ORDER BY ";

foreach ($explode as $order) {
if (strpos($order, "-") !== false) {
$order = str_replace('-', '', $order);

$orderby .= $order . ' DESC,';
} else {
$orderby .= $order . ' ASC,';
}
}

$this->order_by = $orderby = rtrim($orderby, ',');

return $this;
}

#### READ
public function all()
{
$this->triggerEvent('fetching');
$table = $this->getTableName();

$queryString = "SELECT * FROM `$table` WHERE 1";
$queryString = "SELECT * FROM `$table` WHERE 1 $this->order_by";

if ($this->fetchCache($queryString)) {
return $this->fetchCache($queryString);
Expand Down

0 comments on commit 1bd62fc

Please sign in to comment.