aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWilly Micieli <micieli@laposte.net>2019-10-24 19:14:41 +0200
committerWilly Micieli <micieli@laposte.net>2019-10-24 19:14:41 +0200
commit4cfad712a75e6573ea5a2e63ef8a2f5f0c0667d2 (patch)
tree3d2edabffaeba4cd53f76b1dacfd938747cfc6c5
parent0b983f3c8312e07f6ae3f6142aa89bf170e0f0a7 (diff)
downloadimperium-4cfad712a75e6573ea5a2e63ef8a2f5f0c0667d2.zip
imperium-4cfad712a75e6573ea5a2e63ef8a2f5f0c0667d2.tar.gz
fix bugs
-rw-r--r--helpers/web.php27
-rw-r--r--imperium/Action/Crud.php22
-rw-r--r--imperium/Html/Form/Form.php16
-rw-r--r--imperium/View/View.php4
4 files changed, 44 insertions, 25 deletions
diff --git a/helpers/web.php b/helpers/web.php
index b73b9d8..6073584 100644
--- a/helpers/web.php
+++ b/helpers/web.php
@@ -359,6 +359,7 @@ use Imperium\Model\Web;
* @method route
*
* @param mixed $name
+ * @param bool $web
* @param bool $admin
* @param bool $task
* @param mixed $args
@@ -369,19 +370,19 @@ use Imperium\Model\Web;
* @throws Kedavra
* @throws NotFoundException
*/
- function route(string $name,bool $admin = false,bool $task = false,array $args = []): string
+ function route(string $name,bool $web,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();
+ $web_r = Web::where('name', EQUAL, $name)->fetch(true)->all();
+ $task_r = Task::where('name',EQUAL,$name)->fetch(true)->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");
+ is_true(not_def($web_r),true,"The $name route was not found");
}
if ($task)
{
@@ -389,15 +390,21 @@ use Imperium\Model\Web;
}
+ if ($admin)
+
+ $x = $admin_r;
+ elseif ($web)
+ $x = $web_r;
+ else
+ $x = $task_r;
- $x = $admin ? $admin_r : $web ? $web : $task_r;
if (def($args))
{
$url = '';
-
+
$data = explode('/', $x->url);
$i = 0;
foreach ($data as $k => $v)
@@ -426,8 +433,12 @@ use Imperium\Model\Web;
return url(trim($url, '/'));
}
- foreach ($x as $url)
- return $url->url;
+ if (is_array($x))
+ {
+ foreach ($x as $url)
+ return $url->url;
+ }
+ return $x->url;
}
diff --git a/imperium/Action/Crud.php b/imperium/Action/Crud.php
index b846e2c..9467e8c 100644
--- a/imperium/Action/Crud.php
+++ b/imperium/Action/Crud.php
@@ -203,7 +203,7 @@
{
$this->init();
- return $this->truncate($table) ? $this->to(route('show',true,[$table]),$this->truncated) : $this->to(route('show',true,[$table]),$this->no_truncated,false);
+ return $this->truncate($table) ? $this->to(route('show',false,true,false,[$table]),$this->truncated) : $this->to(route('show',false,true,false,[$table]),$this->no_truncated,false);
}
/**
@@ -225,7 +225,7 @@
*/
public function edit(string $table,int $id): Response
{
- $form = $this->form()->start('update',true,[$table,$id])->generate($table,$this->config('crud','update_text'),'',Form::EDIT,$id);
+ $form = $this->form()->start('update',false,true,false,[$table,$id])->generate($table,$this->config('crud','update_text'),'',Form::EDIT,$id);
return $this->view('@crud/edit',compact('form','table'));
}
@@ -247,7 +247,7 @@
*/
public function create(string $table): Response
{
- $form = $this->form()->start('create',true,[$table])->generate($table,$this->config('crud','create_text'));
+ $form = $this->form()->start('create',false,true,false,[$table])->generate($table,$this->config('crud','create_text'));
return $this->view('@crud/create',compact('form','table'));
}
@@ -331,13 +331,21 @@
{
$x = collect(['/' => $this->config('crud','select_table_text')]);
foreach ($this->tables() as $table)
- $x->put(route('show',true,[$table,1]),$table);
+ $x->put(route('show',false,true,false,[$table,1]),$table);
$tables = $x->all();
$form = $this->form()->redirect('table',$tables)->get();
return $this->view('@crud/home',compact('tables','form'));
}
- public function display($key,$value)
+ /**
+ * @param $key
+ * @param $value
+ * @return string
+ * @throws DependencyException
+ * @throws Kedavra
+ * @throws NotFoundException
+ */
+ public function display($key,$value): string
{
$html = '<tr>';
foreach ($value as $v)
@@ -346,8 +354,8 @@
$confirm = $this->config('crud','sure');
$sure = "onclick=\"return confirm('$confirm');\"";
- append($html,'<td><a href="'.route('edit',true,[$this->current,$value->id]).'" class="'.$this->config('crud','edit_class').'">'.$this->config('crud','edit_text').'</a></td>');
- append($html,'<td><a href="'.route('remove',true,[$this->current,$value->id]).'" class="'.$this->config('crud','remove_class').'" '.$sure.'> '.$this->config('crud','remove_text').'</a></td>');
+ append($html,'<td><a href="'.route('edit',false,true,false,[$this->current,$value->id]).'" class="'.$this->config('crud','edit_class').'">'.$this->config('crud','edit_text').'</a></td>');
+ append($html,'<td><a href="'.route('remove',false,true,false,[$this->current,$value->id]).'" class="'.$this->config('crud','remove_class').'" '.$sure.'> '.$this->config('crud','remove_text').'</a></td>');
return $html . '</tr>';
}
/**
diff --git a/imperium/Html/Form/Form.php b/imperium/Html/Form/Form.php
index 9e2df37..14e46bd 100644
--- a/imperium/Html/Form/Form.php
+++ b/imperium/Html/Form/Form.php
@@ -594,16 +594,16 @@
if($enctype)
{
if(not_def($class))
- 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 . "'" . ')" >');
+ append($this->form, '<form action="' . route($route,$web,$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,$task,$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,$web,$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,$task,$args) . '" method="' . $method . '" class="' . self::VALIDATE . '" accept-charset="' . $charset . '" onsubmit="return confirm(' . "'" . $confirm . "'" . ')">');
+ append($this->form, '<form action="' . route($route,$web,$admin,$task,$args) . '" method="' . $method . '" class="' . self::VALIDATE . '" accept-charset="' . $charset . '" onsubmit="return confirm(' . "'" . $confirm . "'" . ')">');
else
- append($this->form, '<form action="' . route($route,$admin,$task,$args) . '" method="' . $method . '" accept-charset="' . $charset . '" class="' . $class . ' ' . self::VALIDATE . '" onsubmit="return confirm(' . "'" . $confirm . "'" . ')" >');
+ append($this->form, '<form action="' . route($route,$web,$admin,$task,$args) . '" method="' . $method . '" accept-charset="' . $charset . '" class="' . $class . ' ' . self::VALIDATE . '" onsubmit="return confirm(' . "'" . $confirm . "'" . ')" >');
}
}
else
@@ -611,16 +611,16 @@
if($enctype)
{
if(not_def($class))
- append($this->form, '<form action="' . route($route,$admin,$task,$args) . '" method="' . $method . '" accept-charset="' . $charset . '" enctype="multipart/form-data">');
+ append($this->form, '<form action="' . route($route,$web,$admin,$task,$args) . '" method="' . $method . '" accept-charset="' . $charset . '" enctype="multipart/form-data">');
else
- append($this->form, '<form action="' . route($route,$admin,$task,$args) . '" method="' . $method . '" accept-charset="' . $charset . '" class="' . $class . '" enctype="multipart/form-data">');
+ append($this->form, '<form action="' . route($route,$web,$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,$task,$args) . '" method="' . $method . '" accept-charset="' . $charset . '" >');
+ append($this->form, '<form action="' . route($route,$web,$admin,$task,$args) . '" method="' . $method . '" accept-charset="' . $charset . '" >');
else
- append($this->form, '<form action="' . route($route,$admin,$task,$args) . '" method="' . $method . '" accept-charset="' . $charset . '" class="' . $class . '" >');
+ append($this->form, '<form action="' . route($route,$web,$admin,$task,$args) . '" method="' . $method . '" accept-charset="' . $charset . '" class="' . $class . '" >');
}
}
if(config($this->file, 'large'))
diff --git a/imperium/View/View.php b/imperium/View/View.php
index e8741a0..cf7c3ee 100644
--- a/imperium/View/View.php
+++ b/imperium/View/View.php
@@ -172,10 +172,10 @@
}, [ 'is_safe' => [ 'html' ] ]),
- new TwigFunction('route', function(string $name, bool $admin = false,bool $task = false,...$args)
+ new TwigFunction('route', function(string $name, bool $web,bool $admin,bool $task,...$args)
{
- return route($name,$admin,$task, $args);
+ return route($name,$web,$admin,$task, $args);
}, [ 'is_safe' => [ 'html' ] ]),new TwigFunction('logged', function()
{