From 715f5d616040d1080d1b7230100cf73da8e348a3 Mon Sep 17 00:00:00 2001 From: DaviMenezes Date: Fri, 29 Nov 2019 20:33:26 -0300 Subject: [PATCH] new features, bug fix, refactorings and more --- src/Corda.php | 1 + src/Helpers/general.php | 2 +- src/Http/Redirect.php | 2 +- src/Model/ModelAdianti.php | 10 ++++- src/Service/Controller/Base/ControlBase.php | 1 - .../Base/Form/ControlFormLayout.php | 3 +- .../Base/Listing/ControlDviListTrait.php | 6 +-- .../Base/Listing/ControlListBase.php | 1 + .../ControlStructureBaseService.php | 10 +---- src/Service/Database/Transaction.php | 4 +- .../Layout/Form/Field/Facade/FormField.php | 2 + .../Form/Field/Facade/FormFieldCheck.php | 17 +++++++++ .../Form/Field/Facade/FormFieldDateTime.php | 19 ++++++++++ .../Form/Field/Facade/FormFieldFacade.php | 20 ++++++++-- src/Service/ReflectionHelpers.php | 37 ++++++++++++++++--- 15 files changed, 108 insertions(+), 27 deletions(-) create mode 100644 src/Service/Layout/Form/Field/Facade/FormFieldCheck.php create mode 100644 src/Service/Layout/Form/Field/Facade/FormFieldDateTime.php diff --git a/src/Corda.php b/src/Corda.php index e4b67f5..b29d49b 100644 --- a/src/Corda.php +++ b/src/Corda.php @@ -2,6 +2,7 @@ namespace Dvi\Corda\Support; +use Dvi\Support\Collection; use Stringy\Stringy; /** diff --git a/src/Helpers/general.php b/src/Helpers/general.php index afef292..40caa4e 100755 --- a/src/Helpers/general.php +++ b/src/Helpers/general.php @@ -166,7 +166,7 @@ function props(string $class) * @param string $class * @return \Dvi\Support\Http\Redirect */ -function redirect(string $class = null) +function redirect(string $class) { return new \Dvi\Support\Http\Redirect($class); } diff --git a/src/Http/Redirect.php b/src/Http/Redirect.php index 9405b53..8f7afb8 100644 --- a/src/Http/Redirect.php +++ b/src/Http/Redirect.php @@ -33,7 +33,7 @@ public function method($method) public function params(array $params) { - $this->param = $params; + $this->param = array_merge($this->param ?? [], $params); return $this; } diff --git a/src/Model/ModelAdianti.php b/src/Model/ModelAdianti.php index c1db181..266de5e 100644 --- a/src/Model/ModelAdianti.php +++ b/src/Model/ModelAdianti.php @@ -3,7 +3,7 @@ namespace Dvi\Support\Model; use Adianti\Core\AdiantiCoreTranslator; -use Adianti\Database\TRecord; +use Adianti\Base\Lib\Database\TRecord; use Adianti\Database\TRepository; use Dvi\Support\Service\ReflectionHelpers; use Exception; @@ -299,4 +299,12 @@ public function __get($property) return $result; } } + + /** + * @return mixed + */ + public function getData() + { + return $this->data; + } } diff --git a/src/Service/Controller/Base/ControlBase.php b/src/Service/Controller/Base/ControlBase.php index 9ffcb02..81b52f8 100644 --- a/src/Service/Controller/Base/ControlBase.php +++ b/src/Service/Controller/Base/ControlBase.php @@ -12,7 +12,6 @@ abstract class ControlBase extends TPage { protected static $database; public static $currentObject; - protected $loggedUser; protected $already_create_layout; protected $panel; /**@var Request*/ diff --git a/src/Service/Controller/Base/Form/ControlFormLayout.php b/src/Service/Controller/Base/Form/ControlFormLayout.php index 3cd621c..cf95d53 100644 --- a/src/Service/Controller/Base/Form/ControlFormLayout.php +++ b/src/Service/Controller/Base/Form/ControlFormLayout.php @@ -30,9 +30,10 @@ abstract protected static function getFormName(); protected function getFieldId() { - $field = FormFieldFacade::hidden('id'); if (notEmpty(http()->request('id'))) { $field = FormFieldFacade::varchar('id', 'Id')->disable()->size('20%'); + } else { + $field = FormFieldFacade::hidden('id'); } $field->value(http()->query('id', static::$currentObject->id)); return $field->get(); diff --git a/src/Service/Controller/Base/Listing/ControlDviListTrait.php b/src/Service/Controller/Base/Listing/ControlDviListTrait.php index 475355c..566fe68 100644 --- a/src/Service/Controller/Base/Listing/ControlDviListTrait.php +++ b/src/Service/Controller/Base/Listing/ControlDviListTrait.php @@ -1,10 +1,11 @@ form->addActionLink('Novo', new TAction([$this->getFormClass(), 'index']), 'fa:plus'); $btn->class = 'btn btn-primary'; + return $btn; } protected function createActionSearch(): void diff --git a/src/Service/Controller/ControlStructureBaseService.php b/src/Service/Controller/ControlStructureBaseService.php index cf2c8c3..ff8dc42 100644 --- a/src/Service/Controller/ControlStructureBaseService.php +++ b/src/Service/Controller/ControlStructureBaseService.php @@ -3,6 +3,7 @@ namespace Dvi\Support\Service\Controller; use Adianti\Core\AdiantiApplicationConfig; +use Adianti\Database\TTransaction; use Adianti\Registry\TSession; use App\Control\User\Model\User; use Dvi\Support\Http\Request; @@ -20,8 +21,6 @@ protected function initialize($param) $this->http = Request::instance(); self::$flashbag = new FlashBag(); $this->setCurrentObject(); - - $this->setLoggedUser(); } catch (Exception $e) { throw new Exception($e->getMessage()); } @@ -45,18 +44,13 @@ protected function setCurrentObject() } $class = get_called_class(); $model = $class::getModel(); - $id = http()->query('id'); + $id = http()->request('id'); $this->createCurrentObject($model, $id); } catch (Exception $e) { throw new Exception('Criando objeto corrente: '.$e->getMessage()); } } - protected function setLoggedUser() - { - $this->loggedUser = User::find(TSession::getValue('userid')); - } - abstract protected static function getModel():string; protected function createCurrentObject($model, $id): void diff --git a/src/Service/Database/Transaction.php b/src/Service/Database/Transaction.php index a4ab499..c12e9d6 100644 --- a/src/Service/Database/Transaction.php +++ b/src/Service/Database/Transaction.php @@ -2,8 +2,8 @@ namespace Dvi\Support\Service\Database; -use Adianti\Database\TTransaction; -use Adianti\Widget\Dialog\TMessage; +use Adianti\Base\Lib\Database\TTransaction; +use Adianti\Base\Lib\Widget\Dialog\TMessage; /** * Transaction diff --git a/src/Service/Layout/Form/Field/Facade/FormField.php b/src/Service/Layout/Form/Field/Facade/FormField.php index f4e5042..bd5110d 100644 --- a/src/Service/Layout/Form/Field/Facade/FormField.php +++ b/src/Service/Layout/Form/Field/Facade/FormField.php @@ -33,6 +33,7 @@ public function __construct(TField $field, $label = null) public function required() { $this->field->addValidation($this->getLabel(), new RequiredValidator()); + $this->field->setProperty('required', 'required'); return $this; } @@ -64,6 +65,7 @@ public function size($size, $height = null) public function value($value) { $this->field->setValue($value); + $this->field->setProperty('value', $value); return $this; } diff --git a/src/Service/Layout/Form/Field/Facade/FormFieldCheck.php b/src/Service/Layout/Form/Field/Facade/FormFieldCheck.php new file mode 100644 index 0000000..c8fc721 --- /dev/null +++ b/src/Service/Layout/Form/Field/Facade/FormFieldCheck.php @@ -0,0 +1,17 @@ +field->setUseButton(); + return $this; + } +} diff --git a/src/Service/Layout/Form/Field/Facade/FormFieldDateTime.php b/src/Service/Layout/Form/Field/Facade/FormFieldDateTime.php new file mode 100644 index 0000000..8cff758 --- /dev/null +++ b/src/Service/Layout/Form/Field/Facade/FormFieldDateTime.php @@ -0,0 +1,19 @@ +field->setDatabaseMask($mask); + return $this; + } +} diff --git a/src/Service/Layout/Form/Field/Facade/FormFieldFacade.php b/src/Service/Layout/Form/Field/Facade/FormFieldFacade.php index 66f52c7..c1148a1 100644 --- a/src/Service/Layout/Form/Field/Facade/FormFieldFacade.php +++ b/src/Service/Layout/Form/Field/Facade/FormFieldFacade.php @@ -2,14 +2,16 @@ namespace Dvi\Support\Service\Layout\Form\Field\Facade; +use Adianti\Base\Lib\Widget\Form\TCheckGroup; +use Adianti\Base\Lib\Widget\Form\TDateTime; use Adianti\Base\Lib\Widget\Form\TFile; -use Adianti\Base\Lib\Widget\Form\TRadioGroup; use Adianti\Widget\Form\TDate; use Adianti\Widget\Form\TSpinner; use Dvi\Adianti\Componente\Model\Form\Fields\Numeric; use Dvi\Component\Widget\Form\Field\Combo\Combo; use Dvi\Component\Widget\Form\Field\Hidden\Hidden; use Dvi\Component\Widget\Form\Field\HtmlEditor; +use Dvi\Component\Widget\Form\Field\RadioGroup\RadioGroup; use Dvi\Component\Widget\Form\Field\Text; use Dvi\Component\Widget\Form\Field\UniqueSearch; use Dvi\Component\Widget\Form\Field\Varchar; @@ -84,9 +86,15 @@ public static function spinner(string $name, $label = null, $class = TSpinner::c return $formField; } - public static function radio(string $name, $label = null, $class = TRadioGroup::class) + public static function radio(string $name, $label = null, $class = RadioGroup::class) { - $formField = new FormFieldRadio(new $class($name), $label); + $formField = new FormFieldRadio(new $class($name, $label), $label); + return $formField; + } + + public static function check(string $name, $label = null, $class = TCheckGroup::class) + { + $formField = new FormFieldCheck(new $class($name, $label), $label); return $formField; } @@ -96,6 +104,12 @@ public static function date(string $name, $label = null, $class = TDate::class) return $field; } + public static function dateHour(string $name, $label = null, $class = TDateTime::class) + { + $field = new FormFieldDateTime(new $class($name), $label); + return $field; + } + public static function uniqueSearch(UniqueSearch $field) { $formField = new FormFieldUniqueSearch($field); diff --git a/src/Service/ReflectionHelpers.php b/src/Service/ReflectionHelpers.php index 6c4a396..1aea628 100644 --- a/src/Service/ReflectionHelpers.php +++ b/src/Service/ReflectionHelpers.php @@ -2,6 +2,7 @@ namespace Dvi\Support\Service; +use BaconQrCode\Common\Mode; use Dvi\Support\Model\ModelAdianti; use stdClass; @@ -24,11 +25,15 @@ public static function properties($alias = null) /**@var ModelAdianti $called_class*/ $called_class = get_called_class(); - $props = self::getReflectionProperties($called_class); + $props = self::getReflectionProperties($called_class, $alias); if (!$alias or ($props and isset($alias) and isset($props->alias))) { - return $props; + if (is_a($props, stdClass::class)) { + return self::getCalledClassAsModel($props); + } + return $props; } //clear alias in properties + $props = is_a($props, stdClass::class) ? $props : (object)$props->getData(); foreach ($props as $key => $prop) { if (strrpos($prop, '.') !== false) { $array = explode('.', $prop); @@ -46,18 +51,38 @@ public static function properties($alias = null) $properties->$key = $alias . '.' . $prop; } - return self::$reflection_properties[$called_class] = $properties; + $alias = '_alias-'.$alias; + $key = $called_class.$alias; + return self::$reflection_properties[$key] = $properties; } - public static function getReflectionProperties($class = null) + private static function getCalledClassAsModel($properties):ModelAdianti + { + $called_class = get_called_class(); + /**@var ModelAdianti $obj*/ + $obj = new $called_class(); + $obj->fromArray((array)$properties); + + self::$reflection_properties[$called_class] = $obj; + return $obj; + } + + + public static function getReflectionProperties($class = null, $alias = null) { $class = $class ?? get_called_class(); - return self::$reflection_properties[$class] = self::$reflection_properties[$class] ?? props($class); + $alias = $alias ? '-alias_' . $alias : null; + $key = $class . $alias; + + if (!isset(self::$reflection_properties[$key])) { + self::$reflection_properties[$key] = props($class); + } + return self::$reflection_properties[$key]; } public function alias() { - return $this->alias; + return $this->alias ?? null; } /**