mirror of
https://github.com/Aviortheking/DeltaCMS.git
synced 2025-04-22 10:52:11 +00:00
Renamed AdminPanel to DeltaCMS
lot of changes :p
This commit is contained in:
parent
d73566086c
commit
e4d320e5e7
@ -60,8 +60,8 @@ steps:
|
|||||||
commands:
|
commands:
|
||||||
- chmod +x prepare.sh && ./prepare.sh
|
- chmod +x prepare.sh && ./prepare.sh
|
||||||
- php composer.phar install --no-dev --optimize-autoloader
|
- php composer.phar install --no-dev --optimize-autoloader
|
||||||
- cat production.txt | zip AdminPanel.zip -r -@
|
- cat production.txt | zip DeltaCMS.zip -r -@
|
||||||
- tar -cvzf AdminPanel.tar.gz -T production.txt
|
- tar -cvzf DeltaCMS.tar.gz -T production.txt
|
||||||
when:
|
when:
|
||||||
event: tag
|
event: tag
|
||||||
|
|
||||||
@ -72,8 +72,8 @@ steps:
|
|||||||
from_secret: gitea_token
|
from_secret: gitea_token
|
||||||
base_url: https://git.delta-wings.net/
|
base_url: https://git.delta-wings.net/
|
||||||
files:
|
files:
|
||||||
- AdminPanel.zip
|
- DeltaCMS.zip
|
||||||
- AdminPanel.tar.gz
|
- DeltaCMS.tar.gz
|
||||||
checksum:
|
checksum:
|
||||||
- md5
|
- md5
|
||||||
- sha1
|
- sha1
|
||||||
|
@ -54,14 +54,14 @@ _([ci.delta-wings.net](https://ci.delta-wings.net))_
|
|||||||
|
|
||||||
### Coverage
|
### 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`
|
`https://img.shields.io/codacy/coverage/bf7f9ac73707426e9afc4b9daa950039.svg?style=for-the-badge`
|
||||||
|
|
||||||
### Code Quality
|
### 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`
|
`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/)
|
- [PHP Mess Detector](https://phpmd.org/)
|
||||||
- Hosting
|
- Hosting
|
||||||
- [Gitlab](https://gitlab.com/) _Project url [here](https://gitlab.com/delta-wings/adminpanel)_
|
- [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/)_
|
- [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)_
|
||||||
|
@ -11,14 +11,14 @@
|
|||||||
],
|
],
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
"AdminPanel\\": "src/AdminPanel",
|
"DeltaCMS\\": "src/DeltaCMS",
|
||||||
"": "src/Modules"
|
"": "src/Modules"
|
||||||
},
|
},
|
||||||
"exclude-from-classmap": [
|
"exclude-from-classmap": [
|
||||||
"src/Modules"
|
"src/Modules"
|
||||||
],
|
],
|
||||||
"files": [
|
"files": [
|
||||||
"src/AdminPanel/Functions.php"
|
"src/DeltaCMS/Functions.php"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
|
@ -24,7 +24,7 @@
|
|||||||
"path": "cache/",
|
"path": "cache/",
|
||||||
|
|
||||||
// driver to use with cache
|
// driver to use with cache
|
||||||
"driver": "\\AdminPanel\\Cache\\FileCache",
|
"driver": "\\DeltaCMS\\Cache\\FileCache",
|
||||||
"options": {
|
"options": {
|
||||||
"ttl": null
|
"ttl": null
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0 http://pmd.sf.net/ruleset_xml_schema.xsd"
|
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"
|
xsi:noNamespaceSchemaLocation="http://pmd.sf.net/ruleset_xml_schema.xsd"
|
||||||
>
|
>
|
||||||
<description>AdminPanel rules</description>
|
<description>DeltaCMS rules</description>
|
||||||
<!-- <rule ref="rulesets/cleancode.xml"/> -->
|
<!-- <rule ref="rulesets/cleancode.xml"/> -->
|
||||||
<rule ref="rulesets/codesize.xml"/>
|
<rule ref="rulesets/codesize.xml"/>
|
||||||
<rule ref="rulesets/controversial.xml"/>
|
<rule ref="rulesets/controversial.xml"/>
|
||||||
|
@ -25,7 +25,7 @@
|
|||||||
verbose="false">
|
verbose="false">
|
||||||
<filter>
|
<filter>
|
||||||
<whitelist>
|
<whitelist>
|
||||||
<directory>src/AdminPanel</directory>
|
<directory>src/DeltaCMS</directory>
|
||||||
</whitelist>
|
</whitelist>
|
||||||
</filter>
|
</filter>
|
||||||
<testsuites>
|
<testsuites>
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use AdminPanel\AdminPanel;
|
use DeltaCMS\DeltaCMS;
|
||||||
|
|
||||||
session_start();
|
session_start();
|
||||||
ini_set('display_errors', 'On');
|
ini_set('display_errors', 'On');
|
||||||
@ -9,7 +9,7 @@ ini_set('display_errors', 'On');
|
|||||||
$loader = require_once __DIR__ . "/../vendor/autoload.php";
|
$loader = require_once __DIR__ . "/../vendor/autoload.php";
|
||||||
|
|
||||||
//die;
|
//die;
|
||||||
$ap = AdminPanel::getInstance();
|
$ap = DeltaCMS::getInstance();
|
||||||
// dd($ap);
|
// dd($ap);
|
||||||
/*
|
/*
|
||||||
1: get all the template folders
|
1: get all the template folders
|
||||||
@ -94,7 +94,7 @@ foreach ($caches['routes'] as $key => $value) {
|
|||||||
$loader->loadClass($value->controller);
|
$loader->loadClass($value->controller);
|
||||||
$function = $value->function;
|
$function = $value->function;
|
||||||
// dump($function);
|
// dump($function);
|
||||||
/** @var AdminPanel\Classes\Controller $controller */
|
/** @var DeltaCMS\Classes\Controller $controller */
|
||||||
$controller = new $value->controller();
|
$controller = new $value->controller();
|
||||||
// dd(new $routeArgs->controller());
|
// dd(new $routeArgs->controller());
|
||||||
if ($composants) {
|
if ($composants) {
|
||||||
|
@ -1,87 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace AdminPanel;
|
|
||||||
|
|
||||||
use AdminPanel\Cache\SessionCache;
|
|
||||||
|
|
||||||
class Form
|
|
||||||
{
|
|
||||||
|
|
||||||
private $session = null;
|
|
||||||
private $formname = null;
|
|
||||||
|
|
||||||
private function isSubmitting($fields)
|
|
||||||
{
|
|
||||||
$entity = $this->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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1 +0,0 @@
|
|||||||
{% extends "@AdminPanel/form/_default.twig" %}
|
|
@ -1 +0,0 @@
|
|||||||
{% extends "@AdminPanel/form/_default.twig" %}
|
|
@ -1 +0,0 @@
|
|||||||
{% extends "@AdminPanel/form/_default.twig" %}
|
|
@ -1,14 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html lang="en">
|
|
||||||
<head>
|
|
||||||
<meta charset="UTF-8">
|
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
||||||
<meta http-equiv="X-UA-Compatible" content="ie=edge">
|
|
||||||
<title>{{ title }}</title>
|
|
||||||
{% block styles %}{% endblock %}
|
|
||||||
{% block scripts %}{% endblock %}
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
{% block body %}{% endblock %}
|
|
||||||
</body>
|
|
||||||
</html>
|
|
@ -5,18 +5,18 @@
|
|||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace AdminPanel;
|
namespace DeltaCMS;
|
||||||
|
|
||||||
use Twig\Loader\FilesystemLoader;
|
use Twig\Loader\FilesystemLoader;
|
||||||
use Twig\Environment;
|
use Twig\Environment;
|
||||||
use AdminPanel\Cache\FileCache;
|
use DeltaCMS\Cache\FileCache;
|
||||||
use Doctrine\ORM\Tools\Setup;
|
use Doctrine\ORM\Tools\Setup;
|
||||||
use Doctrine\ORM\EntityManager;
|
use Doctrine\ORM\EntityManager;
|
||||||
use AdminPanel\Logger;
|
use DeltaCMS\Logger;
|
||||||
|
|
||||||
class AdminPanel
|
class DeltaCMS
|
||||||
{
|
{
|
||||||
/** @var AdminPanel $instance */
|
/** @var DeltaCMS $instance */
|
||||||
private static $instance = null;
|
private static $instance = null;
|
||||||
|
|
||||||
/** @var string $root */
|
/** @var string $root */
|
||||||
@ -25,12 +25,12 @@ class AdminPanel
|
|||||||
private $settings = null;
|
private $settings = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get actual AdminPanel instance
|
* Get actual DeltaCMS instance
|
||||||
*
|
*
|
||||||
* @param array $settings
|
* @param array $settings
|
||||||
* Settings to set to the software
|
* Settings to set to the software
|
||||||
*
|
*
|
||||||
* @return AdminPanel
|
* @return DeltaCMS
|
||||||
*/
|
*/
|
||||||
public static function getInstance()
|
public static function getInstance()
|
||||||
{
|
{
|
||||||
@ -40,7 +40,7 @@ class AdminPanel
|
|||||||
$ap->root = dirname(__DIR__);
|
$ap->root = dirname(__DIR__);
|
||||||
$ap->settings = jsonc_decode(dirname($ap->root) . "/config.jsonc", false);
|
$ap->settings = jsonc_decode(dirname($ap->root) . "/config.jsonc", false);
|
||||||
$ap->loader = new FilesystemLoader();
|
$ap->loader = new FilesystemLoader();
|
||||||
$ap->addLoaderFolder($ap->root . "/AdminPanel/Twig");
|
$ap->addLoaderFolder($ap->root . "/DeltaCMS/Twig");
|
||||||
// $ap->setLoader(new FilesystemLoader());
|
// $ap->setLoader(new FilesystemLoader());
|
||||||
}
|
}
|
||||||
return self::$instance;
|
return self::$instance;
|
||||||
@ -60,7 +60,7 @@ class AdminPanel
|
|||||||
// $this->loader = $loader;
|
// $this->loader = $loader;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
public function addLoaderFolder(string $path, string $prefix = "AdminPanel")
|
public function addLoaderFolder(string $path, string $prefix = "DeltaCMS")
|
||||||
{
|
{
|
||||||
$this->loader->addPath($path, $prefix);
|
$this->loader->addPath($path, $prefix);
|
||||||
}
|
}
|
||||||
@ -75,6 +75,12 @@ class AdminPanel
|
|||||||
}
|
}
|
||||||
|
|
||||||
private $cache;
|
private $cache;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the cache object used Site-wide
|
||||||
|
*
|
||||||
|
* @return \Psr\SimpleCache\CacheInterface
|
||||||
|
*/
|
||||||
public function getCache()
|
public function getCache()
|
||||||
{
|
{
|
||||||
if (!$this->cache) {
|
if (!$this->cache) {
|
@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace AdminPanel;
|
namespace DeltaCMS;
|
||||||
|
|
||||||
class Authentificator
|
class Authentificator
|
||||||
{
|
{
|
@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace AdminPanel\Cache;
|
namespace DeltaCMS\Cache;
|
||||||
|
|
||||||
use Psr\SimpleCache\CacheInterface;
|
use Psr\SimpleCache\CacheInterface;
|
||||||
|
|
@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace AdminPanel\Cache;
|
namespace DeltaCMS\Cache;
|
||||||
|
|
||||||
use Exception;
|
use Exception;
|
||||||
|
|
@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace AdminPanel\Cache;
|
namespace DeltaCMS\Cache;
|
||||||
|
|
||||||
class FileCache extends AbstractCache
|
class FileCache extends AbstractCache
|
||||||
{
|
{
|
@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace AdminPanel\Cache;
|
namespace DeltaCMS\Cache;
|
||||||
|
|
||||||
class InvalidArgumentException extends CacheException implements \Psr\SimpleCache\InvalidArgumentException
|
class InvalidArgumentException extends CacheException implements \Psr\SimpleCache\InvalidArgumentException
|
||||||
{
|
{
|
@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace AdminPanel\Cache;
|
namespace DeltaCMS\Cache;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Session Cache (different type of cache because is per-user cache)
|
* Session Cache (different type of cache because is per-user cache)
|
@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace AdminPanel;
|
namespace DeltaCMS;
|
||||||
|
|
||||||
class Controller
|
class Controller
|
||||||
{
|
{
|
||||||
@ -8,13 +8,13 @@ class Controller
|
|||||||
protected $urlArguments = array();
|
protected $urlArguments = array();
|
||||||
protected $moduleRoot = null;
|
protected $moduleRoot = null;
|
||||||
|
|
||||||
/** @var \AdminPanel\Cache\FileCache */
|
/** @var \DeltaCMS\Cache\FileCache */
|
||||||
|
|
||||||
protected $cache;
|
protected $cache;
|
||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
$this->cache = AdminPanel::getInstance()->getCache();
|
$this->cache = DeltaCMS::getInstance()->getCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setUrlArguments($args)
|
public function setUrlArguments($args)
|
||||||
@ -53,12 +53,12 @@ class Controller
|
|||||||
|
|
||||||
protected function render($template, $args)
|
protected function render($template, $args)
|
||||||
{
|
{
|
||||||
return AdminPanel::getInstance()->getTwig()->render($template, $args);
|
return DeltaCMS::getInstance()->getTwig()->render($template, $args);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getEM()
|
protected function getEM()
|
||||||
{
|
{
|
||||||
return AdminPanel::getInstance()->getEM();
|
return DeltaCMS::getInstance()->getEM();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace AdminPanel;
|
namespace DeltaCMS;
|
||||||
|
|
||||||
abstract class Enum
|
abstract class Enum
|
||||||
{
|
{
|
107
src/DeltaCMS/Form.php
Normal file
107
src/DeltaCMS/Form.php
Normal file
@ -0,0 +1,107 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace DeltaCMS;
|
||||||
|
|
||||||
|
use DeltaCMS\Cache\SessionCache;
|
||||||
|
use DeltaCMS\Form\Input;
|
||||||
|
|
||||||
|
class Form
|
||||||
|
{
|
||||||
|
|
||||||
|
private $session = null;
|
||||||
|
private $formname = null;
|
||||||
|
private $fields = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if form was submitted
|
||||||
|
*
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
public function isSubmitting()
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
$entity = $this->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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,8 +1,8 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace AdminPanel\Form;
|
namespace DeltaCMS\Form;
|
||||||
|
|
||||||
use AdminPanel\AdminPanel;
|
use DeltaCMS\DeltaCMS;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* this abstract class has default functionnality for all working
|
* this abstract class has default functionnality for all working
|
||||||
@ -79,6 +79,19 @@ abstract class AbstractInput implements Input
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function getValueFromPost($name = null)
|
||||||
|
{
|
||||||
|
if ($name !== null) {
|
||||||
|
return filter_input_array(INPUT_POST)[$this->attributes["name"]][$name];
|
||||||
|
}
|
||||||
|
return filter_input(INPUT_POST, $this->attributes["name"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getValue($name = null)
|
||||||
|
{
|
||||||
|
return $this->getValueFromPost($name);
|
||||||
|
}
|
||||||
|
|
||||||
public function render(): string
|
public function render(): string
|
||||||
{
|
{
|
||||||
$arr = explode('\\', get_class($this));
|
$arr = explode('\\', get_class($this));
|
||||||
@ -90,7 +103,7 @@ abstract class AbstractInput implements Input
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
return $this->getTwig()->render(
|
return $this->getTwig()->render(
|
||||||
"@AdminPanel/form/" . $tpName . ".twig",
|
"@DeltaCMS/form/" . $tpName . ".twig",
|
||||||
array(
|
array(
|
||||||
'attributes' => $this->attributes,
|
'attributes' => $this->attributes,
|
||||||
'options' => $this->options
|
'options' => $this->options
|
||||||
@ -100,6 +113,6 @@ abstract class AbstractInput implements Input
|
|||||||
|
|
||||||
protected function getTwig()
|
protected function getTwig()
|
||||||
{
|
{
|
||||||
return AdminPanel::getInstance()->getTwig();
|
return DeltaCMS::getInstance()->getTwig();
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace AdminPanel\Form;
|
namespace DeltaCMS\Form;
|
||||||
|
|
||||||
class ArrayInput extends AbstractInput
|
class ArrayInput extends AbstractInput
|
||||||
{
|
{
|
||||||
@ -49,6 +49,21 @@ class ArrayInput extends AbstractInput
|
|||||||
parent::setOption($name, $value);
|
parent::setOption($name, $value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getValue($name = null)
|
||||||
|
{
|
||||||
|
if (!isset($_POST[$this->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
|
public function render(): string
|
||||||
{
|
{
|
||||||
if (array_key_exists("array_type", $this->options) &&
|
if (array_key_exists("array_type", $this->options) &&
|
@ -1,8 +1,8 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace AdminPanel\Form;
|
namespace DeltaCMS\Form;
|
||||||
|
|
||||||
use AdminPanel\AdminPanel;
|
use DeltaCMS\DeltaCMS;
|
||||||
|
|
||||||
class ChoiceInput extends AbstractInput
|
class ChoiceInput extends AbstractInput
|
||||||
{
|
{
|
@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace AdminPanel\Form;
|
namespace DeltaCMS\Form;
|
||||||
|
|
||||||
class DatalistInput extends AbstractInput
|
class DatalistInput extends AbstractInput
|
||||||
{
|
{
|
@ -1,21 +1,11 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace AdminPanel\Form;
|
namespace DeltaCMS\Form;
|
||||||
|
|
||||||
use DateTime;
|
use DateTime;
|
||||||
|
|
||||||
class DateInput extends AbstractInput
|
class DateInput extends AbstractInput
|
||||||
{
|
{
|
||||||
|
|
||||||
public function getOption(string $name)
|
|
||||||
{
|
|
||||||
if ($name === "value") {
|
|
||||||
return new DateTime($this->options["name"]);
|
|
||||||
} else {
|
|
||||||
return parent::getOption($name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setOption($name, $value)
|
public function setOption($name, $value)
|
||||||
{
|
{
|
||||||
if ($name === "value") {
|
if ($name === "value") {
|
||||||
@ -24,4 +14,9 @@ class DateInput extends AbstractInput
|
|||||||
parent::setOption($name, $value);
|
parent::setOption($name, $value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getValue($name = null)
|
||||||
|
{
|
||||||
|
return new DateTime($this->getValueFromPost($name));
|
||||||
|
}
|
||||||
}
|
}
|
@ -1,8 +1,8 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace AdminPanel\Form;
|
namespace DeltaCMS\Form;
|
||||||
|
|
||||||
use AdminPanel\AdminPanel;
|
use DeltaCMS\DeltaCMS;
|
||||||
|
|
||||||
class EntityInput extends AbstractInput
|
class EntityInput extends AbstractInput
|
||||||
{
|
{
|
||||||
@ -16,7 +16,8 @@ class EntityInput extends AbstractInput
|
|||||||
return array_merge(
|
return array_merge(
|
||||||
parent::getOptionsList(),
|
parent::getOptionsList(),
|
||||||
array(
|
array(
|
||||||
'entity'
|
'entity',
|
||||||
|
'field'
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -24,22 +25,18 @@ class EntityInput extends AbstractInput
|
|||||||
public function setOption(string $name, $value)
|
public function setOption(string $name, $value)
|
||||||
{
|
{
|
||||||
if ($name === 'entity') {
|
if ($name === 'entity') {
|
||||||
$this->options["entities"] = AdminPanel::getInstance()->getEm()->getRepository($value)->findAll();
|
$this->options["entities"] = DeltaCMS::getInstance()->getEm()->getRepository($value)->findAll();
|
||||||
} elseif ($name === "name") {
|
} elseif ($name === "name") {
|
||||||
$this->attributes["list"] = $value . "_list";
|
$this->attributes["list"] = $value . "_list";
|
||||||
}
|
}
|
||||||
parent::setOption($name, $value);
|
parent::setOption($name, $value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getOption($name)
|
public function getValue($name = null)
|
||||||
{
|
{
|
||||||
if ($name === "value") {
|
$repo = DeltaCMS::getInstance()->getEm()->getRepository($this->options["entity"]);
|
||||||
$repo = AdminPanel::getInstance()->getEm()->getRepository($this->options["entity"]);
|
|
||||||
return $repo->findOneBy(array(
|
return $repo->findOneBy(array(
|
||||||
'name' => $this->options["value"]
|
$this->options['field'] => $this->getValueFromPost($name)
|
||||||
));
|
));
|
||||||
} else {
|
|
||||||
return parent::getOption($name);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace AdminPanel\Form;
|
namespace DeltaCMS\Form;
|
||||||
|
|
||||||
interface Input
|
interface Input
|
||||||
{
|
{
|
||||||
@ -55,6 +55,15 @@ interface Input
|
|||||||
*/
|
*/
|
||||||
public function setOption(string $name, $value);
|
public function setOption(string $name, $value);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the value from $_POST & transform it into the correct type
|
||||||
|
*
|
||||||
|
* @param mixed $name index used
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function getValue($name = null);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* return the html to render the current input
|
* return the html to render the current input
|
||||||
*
|
*
|
@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace AdminPanel\Form;
|
namespace DeltaCMS\Form;
|
||||||
|
|
||||||
class NumberInput extends AbstractInput
|
class NumberInput extends AbstractInput
|
||||||
{
|
{
|
||||||
@ -14,4 +14,9 @@ class NumberInput extends AbstractInput
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getValue($name = null)
|
||||||
|
{
|
||||||
|
return (float) $this->getValueFromPost($name);
|
||||||
|
}
|
||||||
}
|
}
|
@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace AdminPanel\Form;
|
namespace DeltaCMS\Form;
|
||||||
|
|
||||||
class TextInput extends AbstractInput
|
class TextInput extends AbstractInput
|
||||||
{
|
{
|
@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace AdminPanel;
|
namespace DeltaCMS;
|
||||||
|
|
||||||
use Psr\Log\AbstractLogger;
|
use Psr\Log\AbstractLogger;
|
||||||
use Psr\Log\InvalidArgumentException;
|
use Psr\Log\InvalidArgumentException;
|
@ -1,4 +1,4 @@
|
|||||||
{% extends "@AdminPanel/form/_default.twig" %}
|
{% extends "@DeltaCMS/form/_default.twig" %}
|
||||||
|
|
||||||
{% set name = "div" %}
|
{% set name = "div" %}
|
||||||
|
|
@ -1,4 +1,4 @@
|
|||||||
{% extends "@AdminPanel/form/_default.twig" %}
|
{% extends "@DeltaCMS/form/_default.twig" %}
|
||||||
|
|
||||||
{% set name = "select" %}
|
{% set name = "select" %}
|
||||||
|
|
@ -1,4 +1,4 @@
|
|||||||
{% extends "@AdminPanel/form/_default.twig" %}
|
{% extends "@DeltaCMS/form/_default.twig" %}
|
||||||
|
|
||||||
{% block after %}
|
{% block after %}
|
||||||
<datalist id="{{ attributes.list }}">
|
<datalist id="{{ attributes.list }}">
|
1
src/DeltaCMS/Twig/form/date.twig
Normal file
1
src/DeltaCMS/Twig/form/date.twig
Normal file
@ -0,0 +1 @@
|
|||||||
|
{% extends "@DeltaCMS/form/_default.twig" %}
|
@ -1,4 +1,4 @@
|
|||||||
{% extends "@AdminPanel/form/_default.twig" %}
|
{% extends "@DeltaCMS/form/_default.twig" %}
|
||||||
|
|
||||||
{% block after %}
|
{% block after %}
|
||||||
<datalist id="{{ attributes.list }}">
|
<datalist id="{{ attributes.list }}">
|
1
src/DeltaCMS/Twig/form/number.twig
Normal file
1
src/DeltaCMS/Twig/form/number.twig
Normal file
@ -0,0 +1 @@
|
|||||||
|
{% extends "@DeltaCMS/form/_default.twig" %}
|
1
src/DeltaCMS/Twig/form/text.twig
Normal file
1
src/DeltaCMS/Twig/form/text.twig
Normal file
@ -0,0 +1 @@
|
|||||||
|
{% extends "@DeltaCMS/form/_default.twig" %}
|
67
src/DeltaCMS/Twig/template.twig
Normal file
67
src/DeltaCMS/Twig/template.twig
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<meta http-equiv="X-UA-Compatible" content="ie=edge">
|
||||||
|
<title>{{ title }}</title>
|
||||||
|
{% block styles %}{% endblock %}
|
||||||
|
{% block scripts %}{% endblock %}
|
||||||
|
<script>
|
||||||
|
const deleteClick = (ev) => {
|
||||||
|
console.log(ev);
|
||||||
|
let btn = ev.target;
|
||||||
|
console.log(btn.parentElement);
|
||||||
|
btn.parentElement.remove();
|
||||||
|
}
|
||||||
|
|
||||||
|
const addClick = (ev) => {
|
||||||
|
let btn = ev.target;
|
||||||
|
let content = document.getElementById(btn.getAttribute("data-for"));
|
||||||
|
if (!content.hasAttribute("data-length")) {
|
||||||
|
content.setAttribute("data-length", content.children.length);
|
||||||
|
}
|
||||||
|
let length = parseInt(content.getAttribute("data-length"));
|
||||||
|
let placeholder = content.getAttribute("data-element").replace(/__unique__/g, length + 1);
|
||||||
|
let el = document.createElement("div");
|
||||||
|
el.innerHTML = placeholder;
|
||||||
|
content.appendChild(el);
|
||||||
|
content.setAttribute("data-length", length + 1);
|
||||||
|
reloadDeleteBtns();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
const reloadDeleteBtns = () => {
|
||||||
|
let ele = document.querySelectorAll("[data-element]");
|
||||||
|
ele.forEach(element => {
|
||||||
|
for (const child of element.children) {
|
||||||
|
if (child.children.item(1) === null) {
|
||||||
|
let deletebtn = document.createElement("button");
|
||||||
|
deletebtn.innerText = "Suprimmer";
|
||||||
|
deletebtn.type = "button";
|
||||||
|
deletebtn.addEventListener("click", deleteClick);
|
||||||
|
child.appendChild(deletebtn);
|
||||||
|
} else {
|
||||||
|
child.children.item(1).addEventListener("click", deleteClick);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function init() {
|
||||||
|
reloadDeleteBtns();
|
||||||
|
let fore = document.querySelectorAll("[data-for]");
|
||||||
|
fore.forEach(element => {
|
||||||
|
element.addEventListener("click", addClick);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
{% block body %}{% endblock %}
|
||||||
|
</body>
|
||||||
|
<script>
|
||||||
|
init();
|
||||||
|
</script>
|
||||||
|
</html>
|
@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
namespace ModuleName\Controller;
|
namespace ModuleName\Controller;
|
||||||
|
|
||||||
use AdminPanel\Controller;
|
use DeltaCMS\Controller;
|
||||||
use AdminPanel\Authentificator;
|
use DeltaCMS\Authentificator;
|
||||||
|
|
||||||
class ExampleController extends Controller
|
class ExampleController extends Controller
|
||||||
{
|
{
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
use AdminPanel\Cache\FileCache;
|
use DeltaCMS\Cache\FileCache;
|
||||||
use AdminPanel\Logger;
|
use DeltaCMS\Logger;
|
||||||
use Psr\Log\InvalidArgumentException;
|
use Psr\Log\InvalidArgumentException;
|
||||||
|
|
||||||
final class LoggerTest extends TestCase
|
final class LoggerTest extends TestCase
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
use AdminPanel\Cache\SessionCache;
|
use DeltaCMS\Cache\SessionCache;
|
||||||
|
|
||||||
final class SessionCacheTest extends TestCase
|
final class SessionCacheTest extends TestCase
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user