Commit 70e718ea authored by Sylvain's avatar Sylvain

Ajout du service

parent 16e543dd
{
"name": "goldenscarab/modulus-service-field",
"description": "An helper to create html forms easily",
"require": {
"php": ">=7.1.3"
},
"license": "MIT",
"authors": [
{
"name": "Goldenscarab",
"email": "web@goldenscarab.fr"
}
],
"autoload": {
"psr-4": {
"Goldenscarab\\Modulus\\Service\\Field\\": "src/"
},
"files": [
]
},
"minimum-stability": "dev",
"prefer-stable": true,
"extra": {
"branch-alias": {
"dev-master": "3.2-dev"
},
"laravel": {
"providers": [
"Goldenscarab\\Modulus\\Service\\Field\\FieldServiceProvider"
],
"aliases": {
"Debugbar": "Goldenscarab\\Modulus\\Service\\Field\\Facade\\Field"
}
}
},
"require-dev": {
"laravel/framework": "5.5.x"
}
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
<?php
namespace Goldenscarab\Modulus\Service\Field\Facade;
use Illuminate\Support\Facades\Facade;
class Field extends Facade
{
protected static function getFacadeAccessor()
{
return 'Field';
}
}
<?php
namespace Goldenscarab\Modulus\Service\Field;
use Illuminate\Support\Facades\Request;
use Goldenscarab\Modulus\Service\Field\Compose\FieldBt4;
use Goldenscarab\Modulus\Service\Field\Compose\Field2Bt4;
class Field
{
/**
* Retourne un champs code source
*
* @param array $attrs Attributs du champs
* @return string Le HTML du champs code source
*/
public function code($attrs): string
{
$field = new FieldBt4($attrs);
$code = $field->renderCodeEditor();
$render = $field->renderWrapFieldEnvironment($code, true);
return $field->renderHTML($render);
}
/**
* Retourne un champs select de choix de publication
* @param boolean $status La valeur du champs
* @return string Le HTML du champs de publication
*/
public function publish($status): string
{
$render = $this->select([
'label' => 'Visibilité',
'name' => 'status',
'prefix' => '<i class="fa fa-globe"></i>',
'value' => $status,
'is_required' => true,
'options' => [
0 => 'Brouillon',
1 => 'En ligne'
]
]);
return $render;
}
/**
* Retourne un champs de recherche dans une liste
* @return string Le HTML du champs de recherche
*/
public function search(): string
{
$render = $this->input([
'name' => 'search',
'value' => Request::get('search'),
'class' => 'form-control-sm',
'placeholder' => 'Recherche...',
'suffix' => '<button class="btn btn-outline-secondary btn-sm" type="submit" id="button-search"><i class="fa fa-search"></i></button>',
]);
return $render;
}
/**
* Retourne un champs select pour choisir le nombre d'éléments d'une liste à afficher
* @return string Le HTML du menu déroulant
*/
public function perpage(): string
{
$render = $this->select([
'label' => 'Lignes par page',
'attributes' => ['onchange' => 'return document.location.href = this.value;'],
'value' => Request::fullUrlWithQuery(["perpage" => Request::get('perpage')]),
'class' => 'ml-2',
'placeholder' => 'Choisir...',
'options' => [
Request::fullUrlWithQuery(["perpage" => 10]) => '10',
Request::fullUrlWithQuery(["perpage" => 15]) => '15',
Request::fullUrlWithQuery(["perpage" => 50]) => '50',
Request::fullUrlWithQuery(["perpage" => 100]) => '100',
Request::fullUrlWithQuery(["perpage" => 200]) => '200',
Request::fullUrlWithQuery(["perpage" => 500]) => '500',
Request::fullUrlWithQuery(["perpage" => 1000]) => '1000'
]
]);
return $render;
}
/**
* Retourne un champs file avec son environnement
* @param array $attrs Les attributs du champs
* @return string le HTML du champs et de son environnement
*/
public function file($attrs = []): string
{
$field = new FieldBt4($attrs);
$file = $field->renderFile();
$render = $field->renderWrapFieldEnvironment($file);
return $field->renderHTML($render);
}
/**
* Retourne un champs pdf avec son environnement
* @param array $attrs Les attributs du champs
* @return string le HTML du champs et de son environnement
*/
public function pdf($attrs = []): string
{
$field = new FieldBt4($attrs);
$image = $field->renderPdf();
$render = $field->renderWrapFieldEnvironment($image);
return $field->renderHTML($render);
}
/**
* Retourne un champs video avec son environnement
* @param array $attrs Les attributs du champs
* @return string le HTML du champs et de son environnement
*/
public function video($attrs = []): string
{
$field = new FieldBt4($attrs);
$image = $field->renderVideo();
$render = $field->renderWrapFieldEnvironment($image);
return $field->renderHTML($render);
}
/**
* Retourne un champs image avec son environnement
* @param array $attrs Les attributs du champs
* @return string le HTML du champs et de son environnement
*/
public function image($attrs = []): string
{
$field = new FieldBt4($attrs);
$image = $field->renderImage();
$render = $field->renderWrapFieldEnvironment($image);
return $field->renderHTML($render);
}
/**
* Retourne un champs toggle avec son environnement
* @param array $attrs Les attributs du champs
* @return string Le HTML du champs et de son environnement
*/
public function toggle($attrs = []): string
{
$field = new FieldBt4($attrs);
$toggle = $field->renderToggle();
$render = $field->renderWrapFieldEnvironment($toggle);
return $field->renderHTML($render);
}
/**
* Retourne un champs radio avec son environnement
* @param array $attrs Les attributs du champs
* @return string Le HTML du champs et de son environnement
*/
public function radio($attrs = []): string
{
$field = new FieldBt4($attrs);
$radio = $field->renderRadio();
$render = $field->renderWrapFieldEnvironment($radio);
return $field->renderHTML($render);
}
/**
* Retourne un champs checkbox avec son environnement
* @param array $attrs Les attributs du champs
* @return string Le HTML du champs et de son environnement
*/
public function checkbox($attrs = []): string
{
$field = new FieldBt4($attrs);
$checkbox = $field->renderCheckbox();
$render = $field->renderWrapFieldEnvironment($checkbox);
return $field->renderHTML($render);
}
/**
* Retourne un champs range avec son environnement
* @param array $attrs Les attributs du champs
* @return string Le HTML du champs et de son environnement
*/
public function range($attrs = []): string
{
$field = new FieldBt4($attrs);
$range = $field->renderRange();
$render = $field->renderWrapFieldEnvironment($range);
return $field->renderHTML($render);
}
/**
* Retourne un champs pot de miel avec son environnement
* @return string Le HTML du champs et son environnement
*/
public function honeypot(): string
{
$field = new FieldBt4([
'name' => 'my-name',
'class' => 'd-none'
]);
$input = $field->renderInput();
$render1 = $field->renderWrapFieldEnvironment($input);
$field = new FieldBt4([
'name' => 'my-time',
'class' => 'd-none',
'value' => encrypt(time())
]);
$input = $field->renderInput();
$render2 = $field->renderWrapFieldEnvironment($input);
return $field->renderHTML($render1 . $render2);
}
/**
* Retourne un champs textarea avec son environnement
* @param array $attrs Les attributs du champs
* @return string Le HTML du champs et de son environnement
*/
public function textarea($attrs = []): string
{
$field = new FieldBt4($attrs);
$textarea = $field->renderTextarea();
$render = $field->renderWrapFieldEnvironment($textarea);
return str_replace('[CR]', PHP_EOL, $field->renderHTML($render));
}
/**
* Retourne un champs select avec son environnement
* @param array $attrs Les attributs du champs
* @return string Le HTML du champs et de son environnement
*/
public function select($attrs = []): string
{
$field = new FieldBt4($attrs);
$select = $field->renderSelect();
$render = $field->renderWrapFieldEnvironment($select);
return $field->renderHTML($render);
}
/**
* Retourne un champs input avec son environnement
* @param array $attrs Les attributs du champs
* @return string Le HTML du champs et de son environnement
*/
public function input($attrs = []): string
{
$field = new FieldBt4($attrs);
$input = $field->renderInput();
$render = $field->renderWrapFieldEnvironment($input);
return $field->renderHTML($render);
}
public function input2($attrs = []): string
{
$field = new Field2Bt4($attrs);
$input = $field->renderInput();
$render = $field->renderWrapFieldEnvironment($input);
return $field->renderHTML($render);
}
}
<?php
namespace Goldenscarab\Modulus\Service\Field;
use Illuminate\Support\ServiceProvider;
use Illuminate\Foundation\AliasLoader;
class FieldServiceProvider extends ServiceProvider
{
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
}
/**
* Register any application services.
*
* @return void
*/
public function register()
{
$this->app->bind('Field', function() {
return new \Goldenscarab\Modulus\Service\Field\Field;
});
}
}
<?php
namespace Goldenscarab\Modulus\Service\Field;
use \Illuminate\Support\HtmlString;
class Option extends FieldBt4 {
private $is_dynamic;
private $source;
private $label_param;
private $value_param;
private $datas;
private $template;
private $attributes;
private $class;
private $callback;
public function __construct()
{
}
public function setSource($source)
{
$this->source = $source;
}
public function setLabelParam($value)
{
$this->label_param = $value;
}
public function setValueParam($value)
{
$this->value_param = $value;
}
public function setDatas($value)
{
$this->datas = $value;
}
public function setTemplate($value)
{
$this->template = $value;
}
public function setAttributes($value)
{
$this->attributes = $value;
}
public function setClass($value)
{
$this->class = $value;
}
public function setCallback($value)
{
$this->callback = $value;
}
public function getOptionValue()
{
if (is_null($this->value_param)) {
return collect($this->source)->keys()->first();
} else {
return $this->objectToString(
null,
$this->value_param,
$this->callback,
$this->source
);
}
}
public function getOptionLabel()
{
if (is_null($this->label_param)) {
return collect($this->source)->first();
} else {
return $this->objectToString(
$this->template,
$this->label_param,
$this->callback,
$this->source
);
}
}
public function getDatasRender()
{
$render = '';
if (!is_null($this->datas)) {
$render = ' ';
foreach ($this->datas as $attr => $value) {
$render .= $this->renderDatas([$attr => data_get($this->source, $value)]);
}
}
return $render;
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment