From 308cd29e79922e5e538e71a40703a6054df6868a Mon Sep 17 00:00:00 2001 From: Avior Date: Tue, 7 May 2019 14:36:33 +0200 Subject: [PATCH] Fixed multiple things --- .../ModuleName/Controller/ExampleController.php | 3 +-- src/DeltaCMS/Cache/AbstractCache.php | 13 ++++++------- src/DeltaCMS/Cache/FileCache.php | 16 +++++++--------- src/DeltaCMS/Cache/SessionCache.php | 4 +--- src/DeltaCMS/Form.php | 6 ++---- src/DeltaCMS/Form/AbstractInput.php | 3 ++- src/DeltaCMS/Form/ArrayInput.php | 2 +- src/DeltaCMS/Form/DatalistInput.php | 2 +- src/DeltaCMS/Form/DateInput.php | 6 +++--- src/DeltaCMS/Twig/form/array.twig | 2 +- src/DeltaCMS/Twig/form/entity.twig | 8 +++++--- 11 files changed, 30 insertions(+), 35 deletions(-) diff --git a/modules/ModuleName/Controller/ExampleController.php b/modules/ModuleName/Controller/ExampleController.php index d6e6658..14cb40d 100644 --- a/modules/ModuleName/Controller/ExampleController.php +++ b/modules/ModuleName/Controller/ExampleController.php @@ -22,8 +22,7 @@ class ExampleController extends Controller { if (Authentificator::getInstance()->isLoggedIn()) { return "test is false!"; - } else { - return "test is true"; } + return "test is true"; } } diff --git a/src/DeltaCMS/Cache/AbstractCache.php b/src/DeltaCMS/Cache/AbstractCache.php index a7097e8..eebc536 100644 --- a/src/DeltaCMS/Cache/AbstractCache.php +++ b/src/DeltaCMS/Cache/AbstractCache.php @@ -73,13 +73,12 @@ abstract class AbstractCache implements CacheInterface { if (is_int($ttl)) { return $ttl; - } else { - return - ((($ttl->y * 365 + $ttl->m * 30 + $ttl->d //translate to days - ) * 24 + $ttl->h //translate to hours - ) * 60 + $ttl->i //translate to minutes - ) * 60 + $ttl->s //translate to seconds - ; } + return + ((($ttl->y * 365 + $ttl->m * 30 + $ttl->d //translate to days + ) * 24 + $ttl->h //translate to hours + ) * 60 + $ttl->i //translate to minutes + ) * 60 + $ttl->s //translate to seconds + ; } } diff --git a/src/DeltaCMS/Cache/FileCache.php b/src/DeltaCMS/Cache/FileCache.php index 95c2295..3a7b6ec 100644 --- a/src/DeltaCMS/Cache/FileCache.php +++ b/src/DeltaCMS/Cache/FileCache.php @@ -32,16 +32,14 @@ class FileCache extends AbstractCache $file = $this->folder . DIRECTORY_SEPARATOR . $key; if (is_file($file)) { $content = file_get_contents($file); - if ($content !== false) { - $res = unserialize($content); - if ($res["ttl"] > time() && $res['value'] !== null) { - return $res["value"]; - } else { - $this->delete($key); - } - } else { + if ($content === false) { throw new Exception("Cache file couldn't be read", 1); } + $res = unserialize($content); + if ($res["ttl"] > time() && $res['value'] !== null) { + return $res["value"]; + } + $this->delete($key); } return $default; } @@ -51,7 +49,7 @@ class FileCache extends AbstractCache if (!$this->checkKey($key)) { throw new InvalidArgumentException("key is not valid"); } - $tl = $ttl != null ? $this->getTTL($ttl) : $this->ttl; + $tl = isset($ttl) ? $this->getTTL($ttl) : $this->ttl; $arr = array( "value" => $value, 'ttl' => time() + $tl diff --git a/src/DeltaCMS/Cache/SessionCache.php b/src/DeltaCMS/Cache/SessionCache.php index d929411..3d2fd81 100644 --- a/src/DeltaCMS/Cache/SessionCache.php +++ b/src/DeltaCMS/Cache/SessionCache.php @@ -28,9 +28,8 @@ class SessionCache extends AbstractCache $item = $_SESSION[$key]; if ($item["ttl"] > time() && $item["value"] !== null) { return $item["value"]; - } else { - $this->delete($key); } + $this->delete($key); } return $default; } @@ -58,7 +57,6 @@ class SessionCache extends AbstractCache public function clear() { - dump(phpversion()); if (phpversion() !== false && version_compare(phpversion(), '7.2.0', '>=')) { return session_reset(); } diff --git a/src/DeltaCMS/Form.php b/src/DeltaCMS/Form.php index 8dafad8..67f3f62 100644 --- a/src/DeltaCMS/Form.php +++ b/src/DeltaCMS/Form.php @@ -59,7 +59,7 @@ class Form private function addField($name, $settings) { /** @var \DeltaCMS\Form\Input */ - $field = $this->getField($settings->type); + $field = $this->getField($settings["type"]); $entity = $this->session->get("form_" . $this->formname, null); $func = "get" . ucfirst($name); @@ -69,8 +69,6 @@ class Form foreach ($settings as $settingName => $value) { $field->setOption($settingName, $value); } - // dump($_POST[$name]); - dump($name, $field->getValue()); $this->$name = $field->render(); } @@ -84,7 +82,7 @@ class Form if (isset($forms[$formname])) { $this->formname = $formname; $form = $forms[$formname]; - $this->fields = $form->fields; + $this->fields = $form["fields"]; // dd($this->fields); if ($this->isSubmitting()) { if ($entity !== null) { diff --git a/src/DeltaCMS/Form/AbstractInput.php b/src/DeltaCMS/Form/AbstractInput.php index 0dcc770..3c7c5ce 100644 --- a/src/DeltaCMS/Form/AbstractInput.php +++ b/src/DeltaCMS/Form/AbstractInput.php @@ -34,7 +34,8 @@ abstract class AbstractInput implements Input 'id', 'value', 'placeholder', - 'style' + 'style', + 'disabled' ); } diff --git a/src/DeltaCMS/Form/ArrayInput.php b/src/DeltaCMS/Form/ArrayInput.php index 1d2a38f..8565780 100644 --- a/src/DeltaCMS/Form/ArrayInput.php +++ b/src/DeltaCMS/Form/ArrayInput.php @@ -21,7 +21,7 @@ class ArrayInput extends AbstractInput array( "array_type", "item", - "script" + "click" ) ); } diff --git a/src/DeltaCMS/Form/DatalistInput.php b/src/DeltaCMS/Form/DatalistInput.php index a30c71e..4430c7b 100644 --- a/src/DeltaCMS/Form/DatalistInput.php +++ b/src/DeltaCMS/Form/DatalistInput.php @@ -17,7 +17,7 @@ class DatalistInput extends AbstractInput public function setOption(string $name, $value) { if ($name === "name") { - $this->attributes["list"] = $name . "_list"; + $this->attributes["list"] = $value . "_list"; } parent::setOption($name, $value); } diff --git a/src/DeltaCMS/Form/DateInput.php b/src/DeltaCMS/Form/DateInput.php index e95efc1..329589a 100644 --- a/src/DeltaCMS/Form/DateInput.php +++ b/src/DeltaCMS/Form/DateInput.php @@ -8,11 +8,11 @@ class DateInput extends AbstractInput { public function setOption(string $name, $value) { - if ($name === "value") { + if ($name === "value" && $value !== null) { $this->attributes["value"] = (new DateTime($value))->format('Y-m-d'); - } else { - parent::setOption($name, $value); + return; } + parent::setOption($name, $value); } public function getValue($name = null) diff --git a/src/DeltaCMS/Twig/form/array.twig b/src/DeltaCMS/Twig/form/array.twig index 231274a..dbe8ba1 100644 --- a/src/DeltaCMS/Twig/form/array.twig +++ b/src/DeltaCMS/Twig/form/array.twig @@ -11,5 +11,5 @@ {% endblock %} {% block after %} - + {% endblock %} diff --git a/src/DeltaCMS/Twig/form/entity.twig b/src/DeltaCMS/Twig/form/entity.twig index 5d76d8e..1b86796 100644 --- a/src/DeltaCMS/Twig/form/entity.twig +++ b/src/DeltaCMS/Twig/form/entity.twig @@ -3,13 +3,15 @@ {% block after %} {% for entity in options.entities %} + + {{entity.name}} {% elseif entity.firstname is not null %} - + {{entity.firstname}} {{ entity.lastname }} {% else %} - + {{entity.id}} {% endif %} + {% endfor %} {% endblock %}