Skip to content
This repository has been archived by the owner on May 17, 2022. It is now read-only.

Commit

Permalink
new features, bug fix, refactorings and more
Browse files Browse the repository at this point in the history
  • Loading branch information
DaviMenezes committed Nov 29, 2019
1 parent 2c52b52 commit 715f5d6
Show file tree
Hide file tree
Showing 15 changed files with 108 additions and 27 deletions.
1 change: 1 addition & 0 deletions src/Corda.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Dvi\Corda\Support;

use Dvi\Support\Collection;
use Stringy\Stringy;

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Helpers/general.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Http/Redirect.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
10 changes: 9 additions & 1 deletion src/Model/ModelAdianti.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -299,4 +299,12 @@ public function __get($property)
return $result;
}
}

/**
* @return mixed
*/
public function getData()
{
return $this->data;
}
}
1 change: 0 additions & 1 deletion src/Service/Controller/Base/ControlBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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*/
Expand Down
3 changes: 2 additions & 1 deletion src/Service/Controller/Base/Form/ControlFormLayout.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
6 changes: 3 additions & 3 deletions src/Service/Controller/Base/Listing/ControlDviListTrait.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<?php
namespace Dvi\Support\Acl\Service\Controller\Base\Listing;

use Adianti\Base\Lib\Wrapper\BootstrapFormBuilder;
use Adianti\Control\TAction;
use Adianti\Database\TCriteria;
use Adianti\Base\Lib\Database\TCriteria;
use Adianti\Database\TFilter;
use Adianti\Database\TRepository;
use Adianti\Base\Lib\Database\TRepository;
use Adianti\Database\TTransaction;
use Adianti\Registry\TSession;
use Adianti\Widget\Datagrid\TDataGrid;
Expand All @@ -13,7 +14,6 @@
use Adianti\Widget\Datagrid\TPageNavigation;
use Adianti\Widget\Dialog\TMessage;
use Adianti\Wrapper\BootstrapDatagridWrapper;
use Adianti\Wrapper\BootstrapFormBuilder;
use Dvi\Support\Service\Database\Transaction;
use Exception;

Expand Down
1 change: 1 addition & 0 deletions src/Service/Controller/Base/Listing/ControlListBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ protected function createFormActionNew()
{
$btn = $this->form->addActionLink('Novo', new TAction([$this->getFormClass(), 'index']), 'fa:plus');
$btn->class = 'btn btn-primary';
return $btn;
}

protected function createActionSearch(): void
Expand Down
10 changes: 2 additions & 8 deletions src/Service/Controller/ControlStructureBaseService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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());
}
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/Service/Database/Transaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/Service/Layout/Form/Field/Facade/FormField.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand Down
17 changes: 17 additions & 0 deletions src/Service/Layout/Form/Field/Facade/FormFieldCheck.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace Dvi\Support\Service\Layout\Form\Field\Facade;

/**
* @author Davi Menezes
* @copyright Copyright (c) 2019. ([email protected])
* @see https://github.com/DaviMenezes
*/
class FormFieldCheck extends FormFieldItems
{
public function asButton()
{
$this->field->setUseButton();
return $this;
}
}
19 changes: 19 additions & 0 deletions src/Service/Layout/Form/Field/Facade/FormFieldDateTime.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace Dvi\Support\Service\Layout\Form\Field\Facade;

/**
* @author Davi Menezes
* @copyright Copyright (c) 2019. ([email protected])
* @see https://github.com/DaviMenezes
*/
class FormFieldDateTime extends FormField
{
use FieldWithMask;

public function databaseMask($mask)
{
$this->field->setDatabaseMask($mask);
return $this;
}
}
20 changes: 17 additions & 3 deletions src/Service/Layout/Form/Field/Facade/FormFieldFacade.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand All @@ -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);
Expand Down
37 changes: 31 additions & 6 deletions src/Service/ReflectionHelpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Dvi\Support\Service;

use BaconQrCode\Common\Mode;
use Dvi\Support\Model\ModelAdianti;
use stdClass;

Expand All @@ -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);
Expand All @@ -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;
}

/**
Expand Down

0 comments on commit 715f5d6

Please sign in to comment.