Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/Abstractor/Eloquent/Model.php
  • Loading branch information
Carlos Morales committed Jan 30, 2017
2 parents d034acd + 5a40015 commit 056e325
Show file tree
Hide file tree
Showing 74 changed files with 913 additions and 673 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ language: php
php:
- 5.5
- 5.6
- 7.0
- hhvm

before_script:
Expand Down
9 changes: 9 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@


Copyright (c) 2016 A navalla suíza

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
5 changes: 2 additions & 3 deletions config/anavel-crud.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
'date' => 'd/m/Y',
'time' => 'H:i',
'datetime' => 'd/m/Y H:i:s',
'number' => '%.2f'
'number' => '%.2f',
],

/*
Expand Down Expand Up @@ -143,7 +143,6 @@
]
*/
],
'modelsGroups' =>
[/*'Blog' => ['Blog Posts', 'Blog Tags']*/]
'modelsGroups' => [/*'Blog' => ['Blog Posts', 'Blog Tags']*/],

];
2 changes: 1 addition & 1 deletion lang/ca/messages.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@
'alert_success_model_destroy_title' => 'Tot bé!',
'alert_success_model_destroy_text' => "L'element fou eliminat correctament",
'modal_delete_title' => 'Estàs segur?',
'modal_delete_text' => 'Aquesta acció esborrarà permanentment aquest contingut'
'modal_delete_text' => 'Aquesta acció esborrarà permanentment aquest contingut',
];
2 changes: 1 addition & 1 deletion lang/en/messages.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@
'alert_success_model_destroy_title' => 'Everything OK!',
'alert_success_model_destroy_text' => 'The item was deleted successfully',
'modal_delete_title' => 'Are you sure?',
'modal_delete_text' => 'This will permanently delete this content'
'modal_delete_text' => 'This will permanently delete this content',
];
2 changes: 1 addition & 1 deletion lang/es/messages.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@
'alert_success_model_destroy_title' => '¡Todo bien!',
'alert_success_model_destroy_text' => 'El elemento ha sido borrado correctamente',
'modal_delete_title' => 'Estás seguro/a?',
'modal_delete_text' => 'Esto borrará permanentemente este contenido'
'modal_delete_text' => 'Esto borrará permanentemente este contenido',
];
2 changes: 1 addition & 1 deletion lang/gl/messages.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@
'alert_success_model_destroy_title' => 'Todo ben!',
'alert_success_model_destroy_text' => 'Borrouse perfectamente o que querías',
'modal_delete_title' => 'Estás seguro/a?',
'modal_delete_text' => 'Así borrarás este contido para sempre'
'modal_delete_text' => 'Así borrarás este contido para sempre',
];
2 changes: 1 addition & 1 deletion public/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ $(function () {

//bootstrap WYSIHTML5 - text editor
$(".bootstrap-wysihtml5").wysihtml5();
$('select').selectize();
$('select[multiple]').selectize();
$("input[type=date]").pikaday({ format: 'YYYY-MM-DD'});
});
14 changes: 7 additions & 7 deletions src/Abstractor/ConfigurationReader.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
<?php

namespace Anavel\Crud\Abstractor;

trait ConfigurationReader
{
public function getConfigValue()
{
if (! property_exists($this, 'config') || ! is_array($this->config) || empty($this->config)) {
return null;
if (!property_exists($this, 'config') || !is_array($this->config) || empty($this->config)) {
return;
}

$params = func_get_args();
Expand All @@ -17,9 +18,10 @@ public function getConfigValue()

if (is_array($params) && count($params) > 0) {
foreach ($params as $configKey) {
if (! array_key_exists($configKey, $nestedConfig)) {
$nestedConfig = array();
return null;
if (!array_key_exists($configKey, $nestedConfig)) {
$nestedConfig = [];

return;
}

$nestedConfig = $nestedConfig[$configKey];
Expand All @@ -29,7 +31,5 @@ public function getConfigValue()
if (array_key_exists($lastParam, $nestedConfig)) {
return $nestedConfig[$lastParam];
}

return null;
}
}
37 changes: 16 additions & 21 deletions src/Abstractor/Eloquent/Field.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace Anavel\Crud\Abstractor\Eloquent;

use Anavel\Crud\Contracts\Abstractor\Field as FieldAbstractorContract;
Expand Down Expand Up @@ -32,8 +33,8 @@ public function __construct(Column $column, FormManagerField $formField, $name,
$this->formField = $formField;
$this->name = $name;
$this->presentation = $presentation;
$this->validationRules = array();
$this->functions = array();
$this->validationRules = [];
$this->functions = [];
$this->options = [];
$this->hideValue = false;
$this->saveIfEmpty = true;
Expand All @@ -44,7 +45,7 @@ public function __clone()
{
$formField = clone $this->formField;
$this->formField = $formField;
$field = new Field($this->dbal, $formField, $this->name, $this->presentation);
$field = new self($this->dbal, $formField, $this->name, $this->presentation);

return $field;
}
Expand Down Expand Up @@ -106,8 +107,8 @@ public function getValidationRulesArray()

public function setFunctions($functions)
{
if (! is_array($functions)) {
$functions = array($functions);
if (!is_array($functions)) {
$functions = [$functions];
}

$this->functions = $functions;
Expand All @@ -116,8 +117,8 @@ public function setFunctions($functions)
public function applyFunctions($value)
{
foreach ($this->functions as $function) {
if (! function_exists($function)) {
throw new \Exception("Function ".$function." does not exist");
if (!function_exists($function)) {
throw new \Exception('Function '.$function.' does not exist');
}

$value = call_user_func($function, $value);
Expand All @@ -128,13 +129,14 @@ public function applyFunctions($value)

/**
* @param string $value
*
* @return void
*/
public function setValue($value)
{
$this->value = $value;

if (! $this->hideValue()) {
if (!$this->hideValue()) {
$this->formField->val($this->value);
}
}
Expand All @@ -149,6 +151,7 @@ public function getValue()

/**
* @param array $options
*
* @return void
*/
public function setOptions(array $options)
Expand All @@ -168,7 +171,7 @@ public function getOptions()

public function getFormField()
{
if (! $this->hideValue()) {
if (!$this->hideValue()) {
if (Request::old($this->name)) {
$this->formField->val(Request::old($this->name));
}
Expand All @@ -177,36 +180,27 @@ public function getFormField()
return $this->formField;
}

/**
*
*/
public function hideValue($value = null)
{
if (! is_null($value)) {
if (!is_null($value)) {
$this->hideValue = $value;
}

return $this->hideValue;
}

/**
*
*/
public function saveIfEmpty($value = null)
{
if (! is_null($value)) {
if (!is_null($value)) {
$this->saveIfEmpty = $value;
}

return $this->saveIfEmpty;
}

/**
*
*/
public function noValidate($value = null)
{
if (! is_null($value)) {
if (!is_null($value)) {
$this->noValidate = $value;
}

Expand All @@ -215,6 +209,7 @@ public function noValidate($value = null)

/**
* @param array $attributes
*
* @return void
*/
public function setFormElementAttributes(array $attributes)
Expand Down
43 changes: 17 additions & 26 deletions src/Abstractor/Eloquent/FieldFactory.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<?php

namespace Anavel\Crud\Abstractor\Eloquent;

use Anavel\Crud\Contracts\Abstractor\FieldFactory as FieldAbstractorFactoryContract;
use Anavel\Crud\Abstractor\Exceptions\FactoryException;
use Anavel\Crud\Contracts\Abstractor\FieldFactory as FieldAbstractorFactoryContract;
use Doctrine\DBAL\Schema\Column;
use Doctrine\DBAL\Types\Type as DbalType;
use FormManager\FactoryInterface as FormManagerFactory;
Expand All @@ -27,7 +28,7 @@ class FieldFactory implements FieldAbstractorFactoryContract
/**
* @var array
*/
protected $databaseTypeToFormType = array(
protected $databaseTypeToFormType = [
DbalType::INTEGER => 'number',
DbalType::SMALLINT => 'number',
DbalType::BIGINT => 'number',
Expand All @@ -44,56 +45,47 @@ class FieldFactory implements FieldAbstractorFactoryContract
'hidden',
'select',
'file',
'money'
);
'money',
];

public function __construct(FormManagerFactory $factory)
{
$this->factory = $factory;
}

/**
*
*/
public function setColumn(Column $column)
{
$this->column = $column;

return $this;
}

/**
*
*/
public function setConfig(array $config)
{
$this->config = $config;

return $this;
}

/**
*
*/
public function get()
{
$formElement = $this->getFormElement();

$field = new Field($this->column, $formElement, $this->config['name'], $this->config['presentation']);

if (! empty($this->config['validation'])) {
if (!empty($this->config['validation'])) {
if ($this->config['validation'] === 'no_validate') {
$this->config['no_validate'] = true;
} else {
$field->setValidationRules($this->config['validation']);
}
}

if (! empty($this->config['functions'])) {
if (!empty($this->config['functions'])) {
$field->setFunctions($this->config['functions']);
}

if (! empty($this->config['no_validate']) && $this->config['no_validate'] === true) {
if (!empty($this->config['no_validate']) && $this->config['no_validate'] === true) {
$field->noValidate(true);
}

Expand All @@ -107,7 +99,7 @@ public function get()
if (in_array('required', $rules)) {
$field->setFormElementAttributes(
[
'required' => true
'required' => true,
]
);
}
Expand All @@ -118,15 +110,15 @@ public function get()

protected function getFormElement()
{
if (! empty($this->config['form_type'])) {
if (! in_array($this->config['form_type'], $this->databaseTypeToFormType)) {
throw new FactoryException("Unknown form type " . $this->config['form_type']);
if (!empty($this->config['form_type'])) {
if (!in_array($this->config['form_type'], $this->databaseTypeToFormType)) {
throw new FactoryException('Unknown form type '.$this->config['form_type']);
}

$formElementType = $this->config['form_type'];
} else {
if (! array_key_exists($this->column->getType()->getName(), $this->databaseTypeToFormType)) {
throw new FactoryException("No form type found for database type " . $this->column->getType()->getName());
if (!array_key_exists($this->column->getType()->getName(), $this->databaseTypeToFormType)) {
throw new FactoryException('No form type found for database type '.$this->column->getType()->getName());
}

$formElementType = $this->databaseTypeToFormType[$this->column->getType()->getName()];
Expand All @@ -136,10 +128,9 @@ protected function getFormElement()
$formElementType = 'select';
}


$formElement = $this->factory->get($formElementType, []);

if (! empty($this->config['attr']) && is_array($this->config['attr'])) {
if (!empty($this->config['attr']) && is_array($this->config['attr'])) {
$formElement->attr($this->config['attr']);
}

Expand All @@ -150,15 +141,15 @@ protected function getFormElement()
}

if ($formElementType === 'textarea') {
$formElement->class('form-control ' . config('anavel-crud.text_editor'));
$formElement->class('form-control '.config('anavel-crud.text_editor'));
}

if ($formElementType === 'checkbox') {
$formElement->class('checkbox');
}

if (isset($this->config['defaults'])) {
if (! is_array($this->config['defaults'])) {
if (!is_array($this->config['defaults'])) {
$formElement->val(transcrud($this->config['defaults']));
} else {
$defaults = [];
Expand Down
Loading

0 comments on commit 056e325

Please sign in to comment.