diff --git a/.drone.yml b/.drone.yml
index b7f45bf..dbd9f63 100644
--- a/.drone.yml
+++ b/.drone.yml
@@ -60,8 +60,8 @@ steps:
commands:
- chmod +x prepare.sh && ./prepare.sh
- php composer.phar install --no-dev --optimize-autoloader
- - cat production.txt | zip AdminPanel.zip -r -@
- - tar -cvzf AdminPanel.tar.gz -T production.txt
+ - cat production.txt | zip DeltaCMS.zip -r -@
+ - tar -cvzf DeltaCMS.tar.gz -T production.txt
when:
event: tag
@@ -72,8 +72,8 @@ steps:
from_secret: gitea_token
base_url: https://git.delta-wings.net/
files:
- - AdminPanel.zip
- - AdminPanel.tar.gz
+ - DeltaCMS.zip
+ - DeltaCMS.tar.gz
checksum:
- md5
- sha1
diff --git a/README.md b/README.md
index 0d70204..cb0b89d 100644
--- a/README.md
+++ b/README.md
@@ -54,14 +54,14 @@ _([ci.delta-wings.net](https://ci.delta-wings.net))_
### Coverage
-_([Codacy](https://app.codacy.com/project/Aviorleking/AdminPanel/dashboard))_
+_([Codacy](https://app.codacy.com/project/Aviorleking/DeltaCMS/dashboard))_

`https://img.shields.io/codacy/coverage/bf7f9ac73707426e9afc4b9daa950039.svg?style=for-the-badge`
### Code Quality
-_([Codacy](https://app.codacy.com/project/Aviorleking/AdminPanel/dashboard))_
+_([Codacy](https://app.codacy.com/project/Aviorleking/DeltaCMS/dashboard))_

`https://img.shields.io/codacy/grade/bf7f9ac73707426e9afc4b9daa950039.svg?style=for-the-badge`
@@ -84,6 +84,6 @@ _([Codacy](https://app.codacy.com/project/Aviorleking/AdminPanel/dashboard))_
- [PHP Mess Detector](https://phpmd.org/)
- Hosting
- [Gitlab](https://gitlab.com/) _Project url [here](https://gitlab.com/delta-wings/adminpanel)_
- - [Gitea](https://gitea.io/) _Current server [here](https://git.delta-wings.net/Avior/AdminPanel)_
+ - [Gitea](https://gitea.io/) _Current server [here](https://git.delta-wings.net/Avior/DeltaCMS)_
- [Drone](https://drone.io/) _Current server [here](https://ci.delta-wings.net/)_
- - [Codacy](https://codacy.com/) _Project Dashboard [here](https://app.codacy.com/project/Aviorleking/AdminPanel/dashboard)_
+ - [Codacy](https://codacy.com/) _Project Dashboard [here](https://app.codacy.com/project/Aviorleking/DeltaCMS/dashboard)_
diff --git a/composer.json b/composer.json
index 1f02f76..a2e78ab 100644
--- a/composer.json
+++ b/composer.json
@@ -11,14 +11,14 @@
],
"autoload": {
"psr-4": {
- "AdminPanel\\": "src/AdminPanel",
+ "DeltaCMS\\": "src/DeltaCMS",
"": "src/Modules"
},
"exclude-from-classmap": [
"src/Modules"
],
"files": [
- "src/AdminPanel/Functions.php"
+ "src/DeltaCMS/Functions.php"
]
},
"require": {
diff --git a/config.jsonc b/config.jsonc
index 291febc..3139508 100644
--- a/config.jsonc
+++ b/config.jsonc
@@ -24,7 +24,7 @@
"path": "cache/",
// driver to use with cache
- "driver": "\\AdminPanel\\Cache\\FileCache",
+ "driver": "\\DeltaCMS\\Cache\\FileCache",
"options": {
"ttl": null
}
diff --git a/phpmd.xml b/phpmd.xml
index 8357783..0037914 100644
--- a/phpmd.xml
+++ b/phpmd.xml
@@ -5,7 +5,7 @@
xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0 http://pmd.sf.net/ruleset_xml_schema.xsd"
xsi:noNamespaceSchemaLocation="http://pmd.sf.net/ruleset_xml_schema.xsd"
>
- AdminPanel rules
+ DeltaCMS rules
diff --git a/phpunit.xml b/phpunit.xml
index 26f4d9e..1716d41 100644
--- a/phpunit.xml
+++ b/phpunit.xml
@@ -25,7 +25,7 @@
verbose="false">
- src/AdminPanel
+ src/DeltaCMS
diff --git a/public/index.php b/public/index.php
index 614421b..8c3ea70 100644
--- a/public/index.php
+++ b/public/index.php
@@ -1,6 +1,6 @@
$value) {
$loader->loadClass($value->controller);
$function = $value->function;
// dump($function);
- /** @var AdminPanel\Classes\Controller $controller */
+ /** @var DeltaCMS\Classes\Controller $controller */
$controller = new $value->controller();
// dd(new $routeArgs->controller());
if ($composants) {
diff --git a/src/AdminPanel/Form.php b/src/AdminPanel/Form.php
deleted file mode 100644
index 4996c4d..0000000
--- a/src/AdminPanel/Form.php
+++ /dev/null
@@ -1,87 +0,0 @@
-session->get("form_" . $this->formname);
- if (isset($entity)) {
- foreach (array_keys((array) $fields) as $name) {
- if (filter_input(INPUT_POST, $name) === null) {
- return false;
- }
- }
- return true;
- }
- return false;
- }
-
- private function addField($name, $settings)
- {
- // get class
- if (strstr($settings->type, "\\") === false) {
- $settings->type = "\\AdminPanel\\Form\\" . ucfirst($settings->type) . "Input";
- }
- /** @var \AdminPanel\Form\Input */
- $field = new $settings->type();
-
- $entity = $this->session->get("form_" . $this->formname);
- // dd($entity);
- $func = "get" . ucfirst($name);
- $options = array(
- 'name' => $name,
- 'attr' => array(),
- 'label' => isset($settings->label) ? $settings->label : null,
- 'value' => $entity !== null && $entity->$func() !== null ? $entity->$func() : null
- );
-
- $fieldOptions = array_merge(
- $field->getOptions(),
- array_keys($options)
- );
-
- foreach ($settings as $opt => $value) {
- if (in_array($opt, $fieldOptions)) {
- $options = array_merge(
- $options,
- $field->processOption($opt, $value)
- );
- } else {
- $options["attr"][$opt] = $value;
- }
- }
- $this->$name = AdminPanel::getInstance()->getTwig()->render($field->getTemplate(), $options);
- }
-
- public function __construct(string $formname, $entity = null)
- {
- // dd($entity);
- $cache = AdminPanel::getInstance()->getCache();
- $forms = $cache->get("forms");
- $this->session = new SessionCache();
-
- if (isset($forms[$formname])) {
- $this->formname = $formname;
- $form = $forms[$formname];
- if ($this->isSubmitting($form->fields)) {
- dd("submitting");
- }
- dump("not submitting");
- if (isset($form->entity) && (!isset($entity) || !($entity instanceof $form->entity))) {
- $entity = new $form->entity();
- }
- $this->session->set("form_" . $this->formname, $entity);
- foreach ($form->fields as $name => $settings) {
- $this->addField($name, $settings);
- }
- }
- }
-}
diff --git a/src/AdminPanel/Twig/form/date.twig b/src/AdminPanel/Twig/form/date.twig
deleted file mode 100644
index 1586fdb..0000000
--- a/src/AdminPanel/Twig/form/date.twig
+++ /dev/null
@@ -1 +0,0 @@
-{% extends "@AdminPanel/form/_default.twig" %}
diff --git a/src/AdminPanel/Twig/form/number.twig b/src/AdminPanel/Twig/form/number.twig
deleted file mode 100644
index 1586fdb..0000000
--- a/src/AdminPanel/Twig/form/number.twig
+++ /dev/null
@@ -1 +0,0 @@
-{% extends "@AdminPanel/form/_default.twig" %}
diff --git a/src/AdminPanel/Twig/form/text.twig b/src/AdminPanel/Twig/form/text.twig
deleted file mode 100644
index 1586fdb..0000000
--- a/src/AdminPanel/Twig/form/text.twig
+++ /dev/null
@@ -1 +0,0 @@
-{% extends "@AdminPanel/form/_default.twig" %}
diff --git a/src/AdminPanel/Twig/template.twig b/src/AdminPanel/Twig/template.twig
deleted file mode 100644
index 4a91053..0000000
--- a/src/AdminPanel/Twig/template.twig
+++ /dev/null
@@ -1,14 +0,0 @@
-
-
-
-
-
-
- {{ title }}
- {% block styles %}{% endblock %}
- {% block scripts %}{% endblock %}
-
-
- {% block body %}{% endblock %}
-
-
diff --git a/src/AdminPanel/AdminPanel.php b/src/DeltaCMS/AdminPanel.php
similarity index 89%
rename from src/AdminPanel/AdminPanel.php
rename to src/DeltaCMS/AdminPanel.php
index 17f3004..0f1ba9f 100644
--- a/src/AdminPanel/AdminPanel.php
+++ b/src/DeltaCMS/AdminPanel.php
@@ -5,18 +5,18 @@
* @since 1.0.0
*/
-namespace AdminPanel;
+namespace DeltaCMS;
use Twig\Loader\FilesystemLoader;
use Twig\Environment;
-use AdminPanel\Cache\FileCache;
+use DeltaCMS\Cache\FileCache;
use Doctrine\ORM\Tools\Setup;
use Doctrine\ORM\EntityManager;
-use AdminPanel\Logger;
+use DeltaCMS\Logger;
-class AdminPanel
+class DeltaCMS
{
- /** @var AdminPanel $instance */
+ /** @var DeltaCMS $instance */
private static $instance = null;
/** @var string $root */
@@ -25,12 +25,12 @@ class AdminPanel
private $settings = null;
/**
- * Get actual AdminPanel instance
+ * Get actual DeltaCMS instance
*
* @param array $settings
* Settings to set to the software
*
- * @return AdminPanel
+ * @return DeltaCMS
*/
public static function getInstance()
{
@@ -40,7 +40,7 @@ class AdminPanel
$ap->root = dirname(__DIR__);
$ap->settings = jsonc_decode(dirname($ap->root) . "/config.jsonc", false);
$ap->loader = new FilesystemLoader();
- $ap->addLoaderFolder($ap->root . "/AdminPanel/Twig");
+ $ap->addLoaderFolder($ap->root . "/DeltaCMS/Twig");
// $ap->setLoader(new FilesystemLoader());
}
return self::$instance;
@@ -60,7 +60,7 @@ class AdminPanel
// $this->loader = $loader;
// }
- public function addLoaderFolder(string $path, string $prefix = "AdminPanel")
+ public function addLoaderFolder(string $path, string $prefix = "DeltaCMS")
{
$this->loader->addPath($path, $prefix);
}
@@ -75,6 +75,12 @@ class AdminPanel
}
private $cache;
+
+ /**
+ * Get the cache object used Site-wide
+ *
+ * @return \Psr\SimpleCache\CacheInterface
+ */
public function getCache()
{
if (!$this->cache) {
diff --git a/src/AdminPanel/Authentificator.php b/src/DeltaCMS/Authentificator.php
similarity index 94%
rename from src/AdminPanel/Authentificator.php
rename to src/DeltaCMS/Authentificator.php
index b65fb22..44c5840 100644
--- a/src/AdminPanel/Authentificator.php
+++ b/src/DeltaCMS/Authentificator.php
@@ -1,6 +1,6 @@
cache = AdminPanel::getInstance()->getCache();
+ $this->cache = DeltaCMS::getInstance()->getCache();
}
public function setUrlArguments($args)
@@ -53,12 +53,12 @@ class Controller
protected function render($template, $args)
{
- return AdminPanel::getInstance()->getTwig()->render($template, $args);
+ return DeltaCMS::getInstance()->getTwig()->render($template, $args);
}
protected function getEM()
{
- return AdminPanel::getInstance()->getEM();
+ return DeltaCMS::getInstance()->getEM();
}
diff --git a/src/AdminPanel/Enum.php b/src/DeltaCMS/Enum.php
similarity index 98%
rename from src/AdminPanel/Enum.php
rename to src/DeltaCMS/Enum.php
index 87c45dd..e52fff9 100644
--- a/src/AdminPanel/Enum.php
+++ b/src/DeltaCMS/Enum.php
@@ -1,6 +1,6 @@
session->get("form_" . $this->formname);
+ if (isset($entity)) {
+ foreach (array_keys((array) $this->fields) as $name) {
+ if (filter_input(INPUT_POST, $name) === null) {
+ return false;
+ }
+ }
+ return true;
+ }
+ return false;
+ }
+
+ private function putFieldsInEntity($entity, $fields)
+ {
+ foreach ($fields as $name => $settings) {
+ $setter = "set" . ucfirst($name);
+ $adder = "add" . ucfirst($name);
+ $value = filter_input(INPUT_POST, $name);
+ $field = $this->getField($settings->type);
+ $value = $field->processValue($value, $settings);
+ if (is_callable(array($entity, $setter))) {
+ $entity->$setter($value);
+ } elseif (is_callable(array($entity, $adder))) {
+ $entity->$adder($value);
+ }
+ }
+ }
+
+ private function getField(string $type): Input
+ {
+ if (strstr($type, "\\") === false) {
+ $type = "\\DeltaCMS\\Form\\" . ucfirst($type) . "Input";
+ }
+ return new $type();
+ }
+
+ private function addField($name, $settings)
+ {
+ /** @var \DeltaCMS\Form\Input */
+ $field = $this->getField($settings->type);
+
+ $entity = $this->session->get("form_" . $this->formname, null);
+ $func = "get" . ucfirst($name);
+
+ $field->setOption("name", $name);
+ $entity !== null && method_exists($entity, $func) ? $field->setOption("value", $entity->$func()) : null;
+ foreach ($settings as $settingName => $value) {
+ $field->setOption($settingName, $value);
+ }
+ // dump($_POST[$name]);
+ dump($name, $field->getValue());
+ $this->$name = $field->render();
+ }
+
+ public function __construct(string $formname, $entity = null)
+ {
+ // dd($entity);
+ $cache = DeltaCMS::getInstance()->getCache();
+ $forms = $cache->get("forms");
+ $this->session = new SessionCache();
+
+ if (isset($forms[$formname])) {
+ $this->formname = $formname;
+ $form = $forms[$formname];
+ $this->fields = $form->fields;
+ // dd($this->fields);
+ if ($this->isSubmitting($this->fields)) {
+ if ($entity !== null) {
+ $this->putFieldsInEntity(
+ $entity,
+ $this->fields
+ );
+ }
+ }
+ if (isset($form->entity) && (!isset($entity) || !($entity instanceof $form->entity))) {
+ $entity = new $form->entity();
+ }
+ // send entity to session cache
+ $this->session->set("form_" . $this->formname, $entity);
+ foreach ($this->fields as $name => $settings) {
+ $this->addField($name, $settings);
+ }
+ }
+ }
+}
diff --git a/src/AdminPanel/Form/AbstractInput.php b/src/DeltaCMS/Form/AbstractInput.php
similarity index 81%
rename from src/AdminPanel/Form/AbstractInput.php
rename to src/DeltaCMS/Form/AbstractInput.php
index a459c11..0dcc770 100644
--- a/src/AdminPanel/Form/AbstractInput.php
+++ b/src/DeltaCMS/Form/AbstractInput.php
@@ -1,8 +1,8 @@
attributes["name"]][$name];
+ }
+ return filter_input(INPUT_POST, $this->attributes["name"]);
+ }
+
+ public function getValue($name = null)
+ {
+ return $this->getValueFromPost($name);
+ }
+
public function render(): string
{
$arr = explode('\\', get_class($this));
@@ -90,7 +103,7 @@ abstract class AbstractInput implements Input
)
);
return $this->getTwig()->render(
- "@AdminPanel/form/" . $tpName . ".twig",
+ "@DeltaCMS/form/" . $tpName . ".twig",
array(
'attributes' => $this->attributes,
'options' => $this->options
@@ -100,6 +113,6 @@ abstract class AbstractInput implements Input
protected function getTwig()
{
- return AdminPanel::getInstance()->getTwig();
+ return DeltaCMS::getInstance()->getTwig();
}
}
diff --git a/src/AdminPanel/Form/ArrayInput.php b/src/DeltaCMS/Form/ArrayInput.php
similarity index 79%
rename from src/AdminPanel/Form/ArrayInput.php
rename to src/DeltaCMS/Form/ArrayInput.php
index a774e29..46fc433 100644
--- a/src/AdminPanel/Form/ArrayInput.php
+++ b/src/DeltaCMS/Form/ArrayInput.php
@@ -1,6 +1,6 @@
attributes["name"]]) || empty($_POST[$this->attributes["name"]])) {
+ return array();
+ }
+ $clas = $this->options["array_type"];
+ $arr = array();
+ foreach ($_POST[$this->attributes["name"]] as $name => $value) {
+ $input = new $clas();
+ $input->setOption("name", $this->attributes["name"]);
+ $arr[] = $input->getValue($name);
+ }
+ return $arr;
+ }
+
public function render(): string
{
if (array_key_exists("array_type", $this->options) &&
diff --git a/src/AdminPanel/Form/ChoiceInput.php b/src/DeltaCMS/Form/ChoiceInput.php
similarity index 87%
rename from src/AdminPanel/Form/ChoiceInput.php
rename to src/DeltaCMS/Form/ChoiceInput.php
index db99650..610453f 100644
--- a/src/AdminPanel/Form/ChoiceInput.php
+++ b/src/DeltaCMS/Form/ChoiceInput.php
@@ -1,8 +1,8 @@
options["name"]);
- } else {
- return parent::getOption($name);
- }
- }
-
public function setOption($name, $value)
{
if ($name === "value") {
@@ -24,4 +14,9 @@ class DateInput extends AbstractInput
parent::setOption($name, $value);
}
}
+
+ public function getValue($name = null)
+ {
+ return new DateTime($this->getValueFromPost($name));
+ }
}
diff --git a/src/AdminPanel/Form/EntityInput.php b/src/DeltaCMS/Form/EntityInput.php
similarity index 51%
rename from src/AdminPanel/Form/EntityInput.php
rename to src/DeltaCMS/Form/EntityInput.php
index 178a99f..4dcabb1 100644
--- a/src/AdminPanel/Form/EntityInput.php
+++ b/src/DeltaCMS/Form/EntityInput.php
@@ -1,8 +1,8 @@
options["entities"] = AdminPanel::getInstance()->getEm()->getRepository($value)->findAll();
+ $this->options["entities"] = DeltaCMS::getInstance()->getEm()->getRepository($value)->findAll();
} elseif ($name === "name") {
$this->attributes["list"] = $value . "_list";
}
parent::setOption($name, $value);
}
- public function getOption($name)
+ public function getValue($name = null)
{
- if ($name === "value") {
- $repo = AdminPanel::getInstance()->getEm()->getRepository($this->options["entity"]);
- return $repo->findOneBy(array(
- 'name' => $this->options["value"]
- ));
- } else {
- return parent::getOption($name);
- }
+ $repo = DeltaCMS::getInstance()->getEm()->getRepository($this->options["entity"]);
+ return $repo->findOneBy(array(
+ $this->options['field'] => $this->getValueFromPost($name)
+ ));
}
}
diff --git a/src/AdminPanel/Form/Input.php b/src/DeltaCMS/Form/Input.php
similarity index 85%
rename from src/AdminPanel/Form/Input.php
rename to src/DeltaCMS/Form/Input.php
index 6e638d9..9491cae 100644
--- a/src/AdminPanel/Form/Input.php
+++ b/src/DeltaCMS/Form/Input.php
@@ -1,6 +1,6 @@
getValueFromPost($name);
+ }
}
diff --git a/src/AdminPanel/Form/TextInput.php b/src/DeltaCMS/Form/TextInput.php
similarity index 64%
rename from src/AdminPanel/Form/TextInput.php
rename to src/DeltaCMS/Form/TextInput.php
index abf5b07..7929b72 100644
--- a/src/AdminPanel/Form/TextInput.php
+++ b/src/DeltaCMS/Form/TextInput.php
@@ -1,6 +1,6 @@
diff --git a/src/DeltaCMS/Twig/form/date.twig b/src/DeltaCMS/Twig/form/date.twig
new file mode 100644
index 0000000..86cae42
--- /dev/null
+++ b/src/DeltaCMS/Twig/form/date.twig
@@ -0,0 +1 @@
+{% extends "@DeltaCMS/form/_default.twig" %}
diff --git a/src/AdminPanel/Twig/form/entity.twig b/src/DeltaCMS/Twig/form/entity.twig
similarity index 88%
rename from src/AdminPanel/Twig/form/entity.twig
rename to src/DeltaCMS/Twig/form/entity.twig
index cde70cb..5d76d8e 100644
--- a/src/AdminPanel/Twig/form/entity.twig
+++ b/src/DeltaCMS/Twig/form/entity.twig
@@ -1,4 +1,4 @@
-{% extends "@AdminPanel/form/_default.twig" %}
+{% extends "@DeltaCMS/form/_default.twig" %}
{% block after %}