Fixed multiple things

This commit is contained in:
Florian Bouillon 2019-05-07 14:36:33 +02:00
parent 0b3694d14d
commit 308cd29e79
No known key found for this signature in database
GPG Key ID: B143FF27EF555D16
11 changed files with 30 additions and 35 deletions

View File

@ -22,8 +22,7 @@ class ExampleController extends Controller
{ {
if (Authentificator::getInstance()->isLoggedIn()) { if (Authentificator::getInstance()->isLoggedIn()) {
return "test is false!"; return "test is false!";
} else { }
return "test is true"; return "test is true";
} }
} }
}

View File

@ -73,7 +73,7 @@ abstract class AbstractCache implements CacheInterface
{ {
if (is_int($ttl)) { if (is_int($ttl)) {
return $ttl; return $ttl;
} else { }
return return
((($ttl->y * 365 + $ttl->m * 30 + $ttl->d //translate to days ((($ttl->y * 365 + $ttl->m * 30 + $ttl->d //translate to days
) * 24 + $ttl->h //translate to hours ) * 24 + $ttl->h //translate to hours
@ -82,4 +82,3 @@ abstract class AbstractCache implements CacheInterface
; ;
} }
} }
}

View File

@ -32,17 +32,15 @@ class FileCache extends AbstractCache
$file = $this->folder . DIRECTORY_SEPARATOR . $key; $file = $this->folder . DIRECTORY_SEPARATOR . $key;
if (is_file($file)) { if (is_file($file)) {
$content = file_get_contents($file); $content = file_get_contents($file);
if ($content !== false) { if ($content === false) {
throw new Exception("Cache file couldn't be read", 1);
}
$res = unserialize($content); $res = unserialize($content);
if ($res["ttl"] > time() && $res['value'] !== null) { if ($res["ttl"] > time() && $res['value'] !== null) {
return $res["value"]; return $res["value"];
} else { }
$this->delete($key); $this->delete($key);
} }
} else {
throw new Exception("Cache file couldn't be read", 1);
}
}
return $default; return $default;
} }
@ -51,7 +49,7 @@ class FileCache extends AbstractCache
if (!$this->checkKey($key)) { if (!$this->checkKey($key)) {
throw new InvalidArgumentException("key is not valid"); 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( $arr = array(
"value" => $value, "value" => $value,
'ttl' => time() + $tl 'ttl' => time() + $tl

View File

@ -28,9 +28,8 @@ class SessionCache extends AbstractCache
$item = $_SESSION[$key]; $item = $_SESSION[$key];
if ($item["ttl"] > time() && $item["value"] !== null) { if ($item["ttl"] > time() && $item["value"] !== null) {
return $item["value"]; return $item["value"];
} else {
$this->delete($key);
} }
$this->delete($key);
} }
return $default; return $default;
} }
@ -58,7 +57,6 @@ class SessionCache extends AbstractCache
public function clear() public function clear()
{ {
dump(phpversion());
if (phpversion() !== false && version_compare(phpversion(), '7.2.0', '>=')) { if (phpversion() !== false && version_compare(phpversion(), '7.2.0', '>=')) {
return session_reset(); return session_reset();
} }

View File

@ -59,7 +59,7 @@ class Form
private function addField($name, $settings) private function addField($name, $settings)
{ {
/** @var \DeltaCMS\Form\Input */ /** @var \DeltaCMS\Form\Input */
$field = $this->getField($settings->type); $field = $this->getField($settings["type"]);
$entity = $this->session->get("form_" . $this->formname, null); $entity = $this->session->get("form_" . $this->formname, null);
$func = "get" . ucfirst($name); $func = "get" . ucfirst($name);
@ -69,8 +69,6 @@ class Form
foreach ($settings as $settingName => $value) { foreach ($settings as $settingName => $value) {
$field->setOption($settingName, $value); $field->setOption($settingName, $value);
} }
// dump($_POST[$name]);
dump($name, $field->getValue());
$this->$name = $field->render(); $this->$name = $field->render();
} }
@ -84,7 +82,7 @@ class Form
if (isset($forms[$formname])) { if (isset($forms[$formname])) {
$this->formname = $formname; $this->formname = $formname;
$form = $forms[$formname]; $form = $forms[$formname];
$this->fields = $form->fields; $this->fields = $form["fields"];
// dd($this->fields); // dd($this->fields);
if ($this->isSubmitting()) { if ($this->isSubmitting()) {
if ($entity !== null) { if ($entity !== null) {

View File

@ -34,7 +34,8 @@ abstract class AbstractInput implements Input
'id', 'id',
'value', 'value',
'placeholder', 'placeholder',
'style' 'style',
'disabled'
); );
} }

View File

@ -21,7 +21,7 @@ class ArrayInput extends AbstractInput
array( array(
"array_type", "array_type",
"item", "item",
"script" "click"
) )
); );
} }

View File

@ -17,7 +17,7 @@ class DatalistInput extends AbstractInput
public function setOption(string $name, $value) public function setOption(string $name, $value)
{ {
if ($name === "name") { if ($name === "name") {
$this->attributes["list"] = $name . "_list"; $this->attributes["list"] = $value . "_list";
} }
parent::setOption($name, $value); parent::setOption($name, $value);
} }

View File

@ -8,11 +8,11 @@ class DateInput extends AbstractInput
{ {
public function setOption(string $name, $value) public function setOption(string $name, $value)
{ {
if ($name === "value") { if ($name === "value" && $value !== null) {
$this->attributes["value"] = (new DateTime($value))->format('Y-m-d'); $this->attributes["value"] = (new DateTime($value))->format('Y-m-d');
} else { return;
parent::setOption($name, $value);
} }
parent::setOption($name, $value);
} }
public function getValue($name = null) public function getValue($name = null)

View File

@ -11,5 +11,5 @@
{% endblock %} {% endblock %}
{% block after %} {% block after %}
<button type="button" data-for="{{ attributes.name }}">Ajouter</button> <button type="button" data-for="{{ attributes.name }}" onclick="{{ options.click }}">Ajouter</button>
{% endblock %} {% endblock %}

View File

@ -3,13 +3,15 @@
{% block after %} {% block after %}
<datalist id="{{ attributes.list }}"> <datalist id="{{ attributes.list }}">
{% for entity in options.entities %} {% for entity in options.entities %}
<option data-id="{{ entity.id }}">
{% if entity.name is not null %} {% if entity.name is not null %}
<option>{{entity.name}}</option> {{entity.name}}
{% elseif entity.firstname is not null %} {% elseif entity.firstname is not null %}
<option>{{entity.firstname}}</option> {{entity.firstname}} {{ entity.lastname }}
{% else %} {% else %}
<option>{{entity.id}}</option> {{entity.id}}
{% endif %} {% endif %}
</option>
{% endfor %} {% endfor %}
</datalist> </datalist>
{% endblock %} {% endblock %}