aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWilly Micieli <micieli@laposte.net>2019-10-24 18:44:21 +0200
committerWilly Micieli <micieli@laposte.net>2019-10-24 18:44:21 +0200
commit0b983f3c8312e07f6ae3f6142aa89bf170e0f0a7 (patch)
tree4f3c85a52ff4dd935b77ab5451de0c7cf4c15f39
parentf06c6b7a03920c7029394af03e63c727ff2d29ef (diff)
downloadimperium-0b983f3c8312e07f6ae3f6142aa89bf170e0f0a7.zip
imperium-0b983f3c8312e07f6ae3f6142aa89bf170e0f0a7.tar.gz
fix bugs add todo
-rw-r--r--helpers/web.php50
-rw-r--r--imperium/Action/Todo.php2
-rw-r--r--imperium/Command/UpdateRoute.php17
-rw-r--r--imperium/Flash/Flash.php2
-rw-r--r--imperium/Html/Form/Form.php23
-rw-r--r--imperium/Model/Model.php2
-rw-r--r--imperium/Routing/Router.php34
-rw-r--r--imperium/View/View.php12
8 files changed, 95 insertions, 47 deletions
diff --git a/helpers/web.php b/helpers/web.php
index 8591f06..b73b9d8 100644
--- a/helpers/web.php
+++ b/helpers/web.php
@@ -6,7 +6,8 @@
use DI\NotFoundException;
use Imperium\Html\Pagination\Pagination;
use Imperium\Model\Admin;
- use Imperium\Model\Web;
+use Imperium\Model\Task;
+use Imperium\Model\Web;
use Imperium\Exception\Kedavra;
use Sinergi\BrowserDetector\Os;
use Imperium\Collection\Collect;
@@ -359,6 +360,7 @@
*
* @param mixed $name
* @param bool $admin
+ * @param bool $task
* @param mixed $args
*
* @return string
@@ -367,16 +369,28 @@
* @throws Kedavra
* @throws NotFoundException
*/
- function route(string $name,bool $admin = false,array $args = []): string
+ function route(string $name,bool $admin = false,bool $task = false,array $args = []): string
{
$admin_r = Admin::where('name', EQUAL, $name)->fetch(true)->all();
$web = Web::where('name', EQUAL, $name)->fetch(true)->all();
+ $task_r = Task::where('name',EQUAL,$name)->fetch()->all();
+ if ($admin)
+ {
+ is_true(not_def($admin_r),true,"The $name route was not found");
+ }
+ if ($web)
+ {
+ is_true(not_def($web),true,"The $name route was not found");
+ }
+ if ($task)
+ {
+ is_true(not_def($task_r),true,"The $name route was not found");
+ }
- is_true($admin && not_def($admin_r) || !$admin && not_def($web),true,"The $name route was not found");
- $x = $admin ? $admin_r : $web;
+ $x = $admin ? $admin_r : $web ? $web : $task_r;
if (def($args))
@@ -412,19 +426,35 @@
return url(trim($url, '/'));
}
-
- return url(trim($x->url, '/'));
+ foreach ($x as $url)
+ return $url->url;
+
}
}
if (!function_exists('detect_method'))
{
- function detect_method(string $route)
+ function detect_method(string $route,bool $web = true,bool $admin =false,bool $task = false)
{
- $web = Web::where('name',EQUAL,$route)->fetch(true)->all();
- $admin = Admin::where('name',EQUAL,$route)->fetch(true)->all();
- return def($web) ? $web->method : $admin->method;
+ if ($web)
+ {
+ $web = Web::where('name',EQUAL,$route)->fetch(true)->all();
+ return $web->method;
+ }
+ if ($admin)
+ {
+ $admin = Admin::where('name',EQUAL,$route)->fetch(true)->all();
+ return $admin->method;
+ }
+
+ if ($task)
+ {
+ $task = Task::where('name',EQUAL,$route)->fetch(true)->all();
+ return $task->method;
+ }
+
+ return 'POST';
}
}
diff --git a/imperium/Action/Todo.php b/imperium/Action/Todo.php
index 110be62..04624d5 100644
--- a/imperium/Action/Todo.php
+++ b/imperium/Action/Todo.php
@@ -11,7 +11,7 @@ use Imperium\Model\Model;
class Todo extends Model
{
- protected $table = "toto";
+ protected $table = "todo";
protected $todo = true;
diff --git a/imperium/Command/UpdateRoute.php b/imperium/Command/UpdateRoute.php
index b563471..5785287 100644
--- a/imperium/Command/UpdateRoute.php
+++ b/imperium/Command/UpdateRoute.php
@@ -201,6 +201,7 @@
}while(is_null($action));
$this->entry->put('id', $route->id);
+
}elseif( $this->choose == 'admin')
{
do {
@@ -280,7 +281,7 @@
$this->search = $helper->ask($input, $output, $question);
- } while (is_null($this->search) && not_def(Admin::where('name', EQUAL, $this->search)->all()));
+ } while (is_null($this->search) && not_def(Task::where('name', EQUAL, $this->search)->all()));
$route = Task::by('name', $this->search);
@@ -338,8 +339,18 @@
$this->entry->put('id', $route->id);
}
-
- $this->choose == 'admin' ? $this->routes->push(Admin::update($this->entry->get('id'),$this->entry->all())) : $this->routes->push(Web::update($this->entry->get('id'),$this->entry->all()));
+ switch ($this->choose)
+ {
+ case 'admin':
+ $this->routes->push(Admin::update($this->entry->get('id'),$this->entry->all()));
+ break;
+ case 'task':
+ $this->routes->push(Task::update($this->entry->get('id'),$this->entry->all()));
+ break;
+ default:
+ $this->routes->push(Web::update($this->entry->get('id'),$this->entry->all()));
+ break;
+ }
$this->entry->clear();
diff --git a/imperium/Flash/Flash.php b/imperium/Flash/Flash.php
index 31993a3..3ccb79f 100644
--- a/imperium/Flash/Flash.php
+++ b/imperium/Flash/Flash.php
@@ -128,7 +128,7 @@
if(def($message))
{
- return $success ? '<div class="'.$success_class.'" role="alert">'.$message.'</div>':'<div class="'.$failure_class.'" role="alert">'.$message.'<div>';
+ return $success ? '<div class="'.$success_class.'" role="alert">'.$message.'</div>':'<div class="'.$failure_class.'" role="alert">'.$message.'</div>';
}
return '';
diff --git a/imperium/Html/Form/Form.php b/imperium/Html/Form/Form.php
index 0a1a1a5..9e2df37 100644
--- a/imperium/Html/Form/Form.php
+++ b/imperium/Html/Form/Form.php
@@ -567,7 +567,9 @@
* @method start
*
* @param string $route
+ * @param bool $web
* @param bool $admin
+ * @param bool $task
* @param array $args
* @param string $confirm The confirm text
* @param string $class The form class
@@ -579,10 +581,11 @@
* @throws Kedavra
* @throws NotFoundException
*/
- public function start(string $route,bool $admin,array $args,string $confirm = '', string $class = '', bool $enctype = false, string $charset = 'utf-8') : Form
+ public function start(string $route,bool $web,bool $admin,bool $task,array $args= [],string $confirm = '', string $class = '', bool $enctype = false, string $charset = 'utf-8') : Form
{
- $this->method = detect_method($route);
+ $this->method = detect_method($route,$web,$admin,$task);
+
$method = POST;
if($this->validate)
@@ -591,16 +594,16 @@
if($enctype)
{
if(not_def($class))
- append($this->form, '<form action="' . route($route,$admin,$args) . '" method="' . $method . '" class="' . self::VALIDATE . '" accept-charset="' . $charset . '" enctype="multipart/form-data" onsubmit="return confirm(' . "'" . $confirm . "'" . ')" >');
+ append($this->form, '<form action="' . route($route,$admin,$task,$args) . '" method="' . $method . '" class="' . self::VALIDATE . '" accept-charset="' . $charset . '" enctype="multipart/form-data" onsubmit="return confirm(' . "'" . $confirm . "'" . ')" >');
else
- append($this->form, '<form action="' . route($route,$admin,$args) . '" method="' . $method . '" accept-charset="' . $charset . '" class="' . $class . ' ' . self::VALIDATE . '" enctype="multipart/form-data" onsubmit="return confirm(' . "'" . $confirm . "'" . ')">');
+ append($this->form, '<form action="' . route($route,$admin,$task,$args) . '" method="' . $method . '" accept-charset="' . $charset . '" class="' . $class . ' ' . self::VALIDATE . '" enctype="multipart/form-data" onsubmit="return confirm(' . "'" . $confirm . "'" . ')">');
}
else
{
if(not_def($class))
- append($this->form, '<form action="' . route($route,$admin,$args) . '" method="' . $method . '" class="' . self::VALIDATE . '" accept-charset="' . $charset . '" onsubmit="return confirm(' . "'" . $confirm . "'" . ')">');
+ append($this->form, '<form action="' . route($route,$admin,$task,$args) . '" method="' . $method . '" class="' . self::VALIDATE . '" accept-charset="' . $charset . '" onsubmit="return confirm(' . "'" . $confirm . "'" . ')">');
else
- append($this->form, '<form action="' . route($route,$admin,$args) . '" method="' . $method . '" accept-charset="' . $charset . '" class="' . $class . ' ' . self::VALIDATE . '" onsubmit="return confirm(' . "'" . $confirm . "'" . ')" >');
+ append($this->form, '<form action="' . route($route,$admin,$task,$args) . '" method="' . $method . '" accept-charset="' . $charset . '" class="' . $class . ' ' . self::VALIDATE . '" onsubmit="return confirm(' . "'" . $confirm . "'" . ')" >');
}
}
else
@@ -608,16 +611,16 @@
if($enctype)
{
if(not_def($class))
- append($this->form, '<form action="' . route($route,$admin,$args) . '" method="' . $method . '" accept-charset="' . $charset . '" enctype="multipart/form-data">');
+ append($this->form, '<form action="' . route($route,$admin,$task,$args) . '" method="' . $method . '" accept-charset="' . $charset . '" enctype="multipart/form-data">');
else
- append($this->form, '<form action="' . route($route,$admin,$args) . '" method="' . $method . '" accept-charset="' . $charset . '" class="' . $class . '" enctype="multipart/form-data">');
+ append($this->form, '<form action="' . route($route,$admin,$task,$args) . '" method="' . $method . '" accept-charset="' . $charset . '" class="' . $class . '" enctype="multipart/form-data">');
}
else
{
if(not_def($class))
- append($this->form, '<form action="' . route($route,$admin,$args) . '" method="' . $method . '" accept-charset="' . $charset . '" >');
+ append($this->form, '<form action="' . route($route,$admin,$task,$args) . '" method="' . $method . '" accept-charset="' . $charset . '" >');
else
- append($this->form, '<form action="' . route($route,$admin,$args) . '" method="' . $method . '" accept-charset="' . $charset . '" class="' . $class . '" >');
+ append($this->form, '<form action="' . route($route,$admin,$task,$args) . '" method="' . $method . '" accept-charset="' . $charset . '" class="' . $class . '" >');
}
}
if(config($this->file, 'large'))
diff --git a/imperium/Model/Model.php b/imperium/Model/Model.php
index b83ffad..76eeb1c 100644
--- a/imperium/Model/Model.php
+++ b/imperium/Model/Model.php
@@ -70,7 +70,7 @@
*/
protected static $create_route_table_query = "CREATE TABLE IF NOT EXISTS routes ( id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT(255) NOT NULL UNIQUE,url TEXT(255) NOT NULL UNIQUE, controller TEXT(255) NOT NULL,action TEXT(255) NOT NULL,method TEXT(255) NOT NULL);";
- protected static $create_todo = "CREATE TABLE IF NOT EXISTS todo ( id INTEGER PRIMARY KEY AUTOINCREMENT, task TEXT(255) NOT NULL UNIQUE, priority TEXT(255) NOT NULL, description TEXT(255) NOT NULL,done TEXT(255));";
+ protected static $create_todo = "CREATE TABLE IF NOT EXISTS todo ( id INTEGER PRIMARY KEY AUTOINCREMENT , task TEXT(255) NOT NULL UNIQUE , description TEXT(255) NOT NULL , priority TEXT(255) NOT NULL ,due TEXT(255) NOT NULL);";
/**
* @var bool
diff --git a/imperium/Routing/Router.php b/imperium/Routing/Router.php
index 5660a07..ac99c41 100644
--- a/imperium/Routing/Router.php
+++ b/imperium/Routing/Router.php
@@ -64,7 +64,7 @@
*/
public function __construct(ServerRequestInterface $request)
{
-
+
$this->method = $request->getMethod() !== GET ? def($request->getParsedBody()) ? strtoupper(collect($request->getParsedBody())->get('method')) : $request->getMethod() : GET;
$this->url = $request->getUri()->getPath();
@@ -86,6 +86,7 @@
if (equal(config('mode', 'mode'), 'admin'))
{
+
foreach(Admin::where('method', EQUAL, $this->method)->all() as $route)
{
@@ -97,34 +98,35 @@
}
}
- }else
+ }
+
+ if (equal(config('mode', 'mode'), 'todo'))
{
- if (equal(config('mode', 'mode'), 'todo'))
+ foreach (Task::where('method',EQUAL,$this->method)->all() as $route)
{
- foreach (Task::where('method',EQUAL,$this->method) as $route)
+ if($this->match($route->url))
{
- if($this->match($route->url))
- {
- $this->route = $route;
+ $this->route = $route;
- return $this->result();
- }
+ return $this->result();
}
}
- else
+ }
+
+ if (equal(config('mode','mode'),'up'))
+ {
+ foreach(Web::where('method', EQUAL, $this->method)->all() as $route)
{
- foreach(Web::where('method', EQUAL, $this->method)->all() as $route)
+ if($this->match($route->url))
{
- if($this->match($route->url))
- {
- $this->route = $route;
+ $this->route = $route;
- return $this->result();
- }
+ return $this->result();
}
}
}
+
return to(route('404'));
diff --git a/imperium/View/View.php b/imperium/View/View.php
index 434cba4..e8741a0 100644
--- a/imperium/View/View.php
+++ b/imperium/View/View.php
@@ -96,11 +96,13 @@
$this->twig->addExtension(new TranslationExtension());
- $this->loader()->addPath($views_path . DIRECTORY_SEPARATOR . 'Admin', 'admin');
+ $this->loader()->addPath($views_path . DIRECTORY_SEPARATOR . 'admin', 'admin');
- $this->loader()->addPath($views_path . DIRECTORY_SEPARATOR . 'Users', 'users');
+ $this->loader()->addPath($views_path . DIRECTORY_SEPARATOR . 'users', 'users');
- $this->loader()->addPath($views_path . DIRECTORY_SEPARATOR . 'Crud', 'crud');
+ $this->loader()->addPath($views_path . DIRECTORY_SEPARATOR . 'crud', 'crud');
+
+ $this->loader()->addPath($views_path . DIRECTORY_SEPARATOR . 'todo', 'todo');
if(def($this->namespaces))
{
@@ -170,10 +172,10 @@
}, [ 'is_safe' => [ 'html' ] ]),
- new TwigFunction('route', function(string $name, bool $admin = false,...$args)
+ new TwigFunction('route', function(string $name, bool $admin = false,bool $task = false,...$args)
{
- return route($name,$admin, $args);
+ return route($name,$admin,$task, $args);
}, [ 'is_safe' => [ 'html' ] ]),new TwigFunction('logged', function()
{