From 3b0319fef828ed2ce7f8e86a92e2366ce0668e9a Mon Sep 17 00:00:00 2001 From: Malloc of Kuzkycyziklistan Date: Tue, 14 Mar 2017 16:03:41 -0500 Subject: [PATCH] thankswave woomwave --- AroMVC/Base/Controller.php | 2 +- AroMVC/Base/Model.php | 4 +-- AroMVC/Database/Deletable.php | 49 ++++++++++++++++++++++++++++++++- AroMVC/Routing/ActionResult.php | 6 ++++ 4 files changed, 57 insertions(+), 4 deletions(-) create mode 100644 AroMVC/Routing/ActionResult.php diff --git a/AroMVC/Base/Controller.php b/AroMVC/Base/Controller.php index a650fe4..60061ef 100644 --- a/AroMVC/Base/Controller.php +++ b/AroMVC/Base/Controller.php @@ -2,5 +2,5 @@ namespace AroMVC\Base; abstract class Controller { - + } \ No newline at end of file diff --git a/AroMVC/Base/Model.php b/AroMVC/Base/Model.php index 94e04e9..1bf1909 100644 --- a/AroMVC/Base/Model.php +++ b/AroMVC/Base/Model.php @@ -21,7 +21,7 @@ abstract class Model { ->asArray(); if(count($row) == 0) - throw new \Exception("Cannot instantiate new ". get_class(new static) ." with id '$id' because it does not exist"); + throw new \Exception("Cannot instantiate new ". static::class ." with id '$id' because it does not exist"); return self::withRow($row[0]); } @@ -36,7 +36,7 @@ abstract class Model { protected abstract function initialize(); protected static function getTable(): string { - $fqcn = get_class(new static); + $fqcn = static::class; return self::$table ?? substr($fqcn, strrpos($fqcn, "\\")+1); } diff --git a/AroMVC/Database/Deletable.php b/AroMVC/Database/Deletable.php index 2d9b1bd..fae17b5 100644 --- a/AroMVC/Database/Deletable.php +++ b/AroMVC/Database/Deletable.php @@ -2,5 +2,52 @@ namespace AroMVC\Database; class Deletable extends Queryable { - + protected $table = null; + protected $wheres = []; + protected $orders = []; + protected $limit = null; + + public function __construct(string $table) { + $this->table = $table; + } + + public function where(string $condition) : Deletable { + $this->wheres[] = $condition; + return $this; + } + + public function orderBy($columns): Deletable { + if(!is_array($columns)) + $columns = [$columns]; + + array_push($this->orders, $columns); + return $this; + } + + public function limit(int $count): Deletable { + $this->limit = $count; + return $this; + } + + public function execute() { + $sets = array_map(function($key) { + return "`$key` = :$key"; + }, array_keys($this->params)); + + $this->query = implode(" ", ["UPDATE", "`$this->table`", "SET", implode(", ", $sets)]); + if(count($this->wheres) > 0) { + $this->query .= " WHERE " . implode(" AND ", + array_map(function($val) { return "($val)"; }, + $this->wheres)); + } + + if(count($this->orders) > 0) + $this->query .= " ORDER BY " . implode(", ", $this->orders); + + if($this->limit != null) + $this->query .= " LIMIT $this->limit"; + + parent::execute(); + return $this; + } } \ No newline at end of file diff --git a/AroMVC/Routing/ActionResult.php b/AroMVC/Routing/ActionResult.php new file mode 100644 index 0000000..4d99f3a --- /dev/null +++ b/AroMVC/Routing/ActionResult.php @@ -0,0 +1,6 @@ +