1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486 |
- <?php
- /**
- * Type de champs possibles dans l'application
- * @author valentin carruesco
- * @category Core
- * @license MIT
- */
- class FieldType{
- public $label,$slug,$sqlType,$description,$icon,$default,$input;
- public function toArray(){
- return json_decode(json_encode($this), true);
- }
- public function __toString() {
- return json_encode($this->toArray());
- }
- //traduit une valeur en champ/label/légende HTML en fonction de son type
- public static function toHtml($field,$types=null,$options = array('allowCustomLabel'=>true)){
- if(!isset($types)) $types = self::available();
- if(!isset($field['id'])) $field['id'] = '';
- $type = isset($field['type']) && isset($types[$field['type']]) ? $types[$field['type']] : $types['text'];
- $label = '';
- if(!empty($field['label'])){
- $label = '<label class="mb-0"';
- if(!empty($field['id'])) $label .= 'for="'.$field['id'].'"';
- $label .= '>'.$field['label'].'</label>';
- }
- if(!isset($field['attributes'])) $field['attributes'] = array();
- $field['attributes'] = array_merge($type->default_attributes,$field['attributes']);
- if(empty($field['value']) && !empty($field['default'])) $field['value'] = $field['default'];
- if(!empty($field['placeholder'])) $field['attributes']['placeholder'] = $field['placeholder'];
- if(!empty($field['required'])) $field['attributes']['required'] = $field['required'];
- $func = $type->onInput;
- $inputOptions = array_merge(array('type'=>$type,'label'=>$label), $options);
- $input = $func($field,$inputOptions);
- return array(
- 'label' => isset($type->customLabel) && $type->customLabel && $options['allowCustomLabel'] ? '' : $label,
- 'legend' => isset($field['legend']) ? $field['legend'] : '',
- 'input' => $input,
- 'data' => $field
- );
- }
- public static function toForm($fields,$types=null){
- $htmlFields = array();
- if(!isset($types)) $types = self::available();
- uasort ($fields,function($a,$b){
- if(!isset($a['sort'])) $a['sort'] = 100;
- if(!isset($b['sort'])) $b['sort'] = 100;
- return $a['sort'] - $b['sort'];
- });
- foreach ($fields as $key => $field) {
- if(!isset($field['id'])) $field['id'] = $key;
- $htmlFields[] = self::toHtml($field,$types);
- }
- return $htmlFields;
- }
- //liste des types de champs disponibles
- public static function available($key=null){
- $types = array();
- //Texte
- $type_text = new self();
- $type_text->slug = 'text';
- $type_text->label = 'Texte';
- $type_text->sqlType = 'string';
- $type_text->label = 'Texte';
- $type_text->icon = 'fas fa-font';
- $type_text->description = 'Texte court mono ligne';
- $type_text->default = '';
- $type_text->default_attributes = array(
- 'class'=>'"form-control"',
- 'type'=>'"text"'
- );
- $type_text->filter = array(
- 'operators' => array(
- 'like' =>array("view" =>'text'),
- 'not like' =>array("view" =>'text'),
- '=' =>array("view" =>'text'),
- '!=' =>array("view" =>'text'),
- 'null' =>array(),
- 'not null' =>array()
- )
- );
- /* Exemples d'utilisation des méthodes de convertion de types
- Type | BDD | onLoad | onRawDisplay | onHtmlDisplay | onInput | fromRawDisplay
- ====================================================================================================================================================================
- Date | 12345 | d/m/y | d/m/y | d/m/y | <input data-type="date" ... value="{{onLoad}}"> | 12345
- User | theo.lecoq | theo.lecoq | Théo Lecoq | Théo Lecoq | <input data-type="user" ... value="{{onLoad}}"> | theo.lecoq
- Dictionary | 6 | 6 | Véhicules > bateau | Véhicules > bateau | <input data-type="dictionary" ... value="{{onLoad}}"> | 6
- password | ==x$yh.. | toto | toto | toto | <input data-type="password" ... value="{{onLoad}}"> | ==x$yh..
- url | http://... | http://... | http://... | <a href="http://..."></a> | <input data-type="url" ... value="{{onLoad}}"> | http://..
- onLoad : Utilisé pour converti une valeur de la base en une valeur comprehensible par l'erp et
- ses composants (pas forcement human readable)
- onRawDisplay : Valeur human readable brute sans mise en forme ou html, utilisé par exemple dans les export text/ excel
- fromRawDisplay : utilisé pour convertir la valeur affichée brute en valeur technique BDD (inverse de onRawDisplay) utilisé apr exemple pour les import depuis excel
- onHtmlDisplay : Valeur human readable avec mise en forme ou html, utilisé pour affichage sur les pages, un parametre decoration peut être mise a true pour avoir des décoration contextuelles (ex : une icone de calendrier devant la date)
- onInput : utilisé pour afficher l'input approprié, cette méthode doit s'appuyer sur le onLoad
- onSave : utilisé pour une transformation de la valeur avant enregistrement en base
- */
- $type_text->onLoad = function($value,$options = array()){
- return $value;
- };
- $type_text->onRawDisplay = function($value,$options = array()){
- return $value;
- };
- $type_text->onHtmlDisplay = function($value,$options = array()){
- $raw = $options['type']->onRawDisplay;
- $html = $raw($value,$options);
- return $html;
- };
- $type_text->onInput = function($field=array(),$options=array()){
- $attributes = array_merge($options['type']->default_attributes,$field['attributes']);
- if(isset($field['id'])) $field['attributes']['id'] ='"'.$field['id'].'"';
- $html = '';
- $html.= '<input value="'.(isset($field['value']) ? str_replace('"','"',$field['value']) : '').'"';
- foreach ($field['attributes'] as $key => $value) {
- $html.= ' ';
- $html.= $key;
- if(!empty($value) && is_string($value)) $html.= '='.$value;
- $html.= ' ';
- }
- $html.= '>';
- return $html;
- };
- $types[$type_text->slug] = $type_text;
- //File
- $type_file = new self();
- $type_file->slug = 'file';
- $type_file->label = 'Fichier';
- $type_file->sqlType = '';
- $type_file->default_attributes = array_merge($type_text->default_attributes,array(
- 'class'=>'"component-file-default bg-white shadow-sm rounded-sm"',
- 'data-type'=>'"file"',
- 'data-extension'=>'"jpg,png,bmp,jpeg,gif,svg,webp,docx,xlsx,pptx,msg,eml,pdf,zip,doc,xls,ppt,txt,csv,mp3,wav,mp4,avi,flv"',
- 'data-action'=>'{{action}}',
- 'data-id'=>'"'.uniqid(rand(0,100)).'"',
- 'data-data'=> "'{}'",
- ));
- $type_file->settings = array(
- 'action'=>array('type'=>'text','default'=>"dynamicform_handle_file",'attributes'=> array('class'=>'"form-control hidden"','disabled'=>true)),
- 'extension'=> array('type'=>'text','label'=>'Extensions permises','placeholder'=>'"Séparation par \',\'"','attributes'=> array('class'=>'"form-control"')),
- 'size'=> array('type'=>'integer','label'=>'Taille max (octets)','attributes'=> array('class'=>'"form-control"')),
- 'limit'=> array('type'=>'integer','label'=>'Nombre max de fichiers','attributes'=> array('class'=>'"form-control"')),
- 'storage'=> array('type'=>'filepicker','label'=>'Dossier d\'enregistrement','attributes'=> array('class'=>'"form-control"','data-editable'=>true)),
- 'access'=> array(
- 'type'=>'list',
- 'label'=>'Contrôle des droits et accès à faire sur la section',
- 'values'=>function(){
- $scopes = array();
- foreach(Right::availables() as $slug=>$scope)
- $scopes[$slug] = $scope['label'];
- return $scopes;
- },
- 'attributes'=> array('class'=>'"form-control"')
- ),
- /*'label'=> array('type'=>'text','label'=>'Libellé visible dans la dropzone du composant','placeholder'=>'"Faites glisser vos fichiers ici"','attributes'=> array('class'=>'"form-control"')),
- 'readonly'=> array('type'=>'boolean','label'=>'Lecture seule','attributes'=> array('class'=>'"form-control"')),*/
- );
- $type_file->onInput = function($field=array(),$options=array()){
- $attributes = array_merge($options['type']->default_attributes,$field['attributes']);
- if(isset($field['id'])) $field['attributes']['id'] ='"'.$field['id'].'"';
- //gestion des scopes, uid et slug si dynamics
- $data = array();
- //id entité si présente
- $data['id'] = isset($field['options']['uid']) ? $field['options']['uid'] : '';
- //id scope de l'entité si présente
- $data['scope'] = isset($field['options']['scope']) ? $field['options']['scope'] : '';
- //slug du composant
- $data['slug'] = isset($field['slug']) ? $field['slug'] : '';
- //Gestion des data-data depuis le champ (ex: type image en settings globaux)
- if(!empty($field['attributes']) && !empty($field['attributes']['data-data'])){
- $fieldData = json_decode($field['attributes']['data-data'], true);
- $data = !empty($fieldData) ? json_encode(array_merge($data, $fieldData)) : json_encode($data);
- }
- $field['attributes']['data-data'] = $data;
- $html = '';
- $html.= '<input ';
- foreach ($field['attributes'] as $key => $value) {
- $html.= ' ';
- $html.= $key;
- if(!empty($value)) $html.= '='.$value;
- $html.= ' ';
- }
- $html.= '>';
- return $html;
- };
- $type_file->onSave = function($value,$options=array()){
- $path = $options['options']['scope'].SLASH.$options['options']['uid'];
- $limit = 1;
- if(!empty($options['field']->meta)){
- $meta = json_decode($options['field']->meta,true);
- if(!empty($meta['limit']) && $meta['limit']>1) $limit =$meta['limit'] ;
- if(!empty($meta['storage'])) $path = template($meta['storage'],$options['options'],true);
- }
- File::save_component($options['field']->slug,$path.($limit==1?'':SLASH.$options['field']->slug).SLASH.'{{label}}');
- return null;
- };
- $type_file->onRawDisplay = function($value,$options = array()){
- $value = '';
- $meta = json_decode($options['meta'],true);
- $templateData = array();
- foreach($options as $key=>$option){
- if(!is_string($option)) continue;
- $templateData[$key] = $option;
- }
- $path = File::dir().template($meta['storage'],$templateData,true).'/*';
- foreach (glob($path) as $file) {
- $filePath = str_replace(File::dir(),'',$file);
- $value .= PHP_EOL.basename($file).' ('.ROOT_URL.'action.php?action='.$meta['action'].'&type=download&path='.base64_encode($filePath).')';
- }
- return $value;
- };
- $type_file->onHtmlDisplay = function($value,$options = array()){
- $html = '';
- $meta = json_decode($options['meta'],true);
- $templateData = array();
- foreach($options as $key=>$option){
- if(!is_string($option)) continue;
- $templateData[$key] = $option;
- }
- $path = File::dir().template($meta['storage'],$templateData,true).'/*';
- $html .= '<ul class="list-group list-group-flush shadow-sm">';
- foreach (glob($path) as $file) {
- $filePath = str_replace(File::dir(),'',$file);
- $html .= '<li class="list-group-item p-1"><a href="';
- $html .= 'action.php?action='.$meta['action'].'&type=download&path='.base64_encode($filePath);
- $html.= '">'.basename($file).'<a></li>';
- }
- $html.='</ul>';
- return $html;
- };
- $type_file->icon = 'fas fa-file-upload';
- $type_file->description = 'Envoi de fichier';
- $type_file->default = '';
- $types[$type_file->slug] = $type_file;
- //Image
- $type = new self();
- $type->slug = 'image';
- $type->label = 'Image';
- $type->sqlType = '';
- $type->default_attributes = array_merge($type_text->default_attributes,array(
- 'class'=>'"component-file-cover bg-white shadow-sm rounded-sm"',
- 'data-type'=>'"file"',
- 'data-limit'=>'"1"',
- 'data-extension'=>'"jpg,png,bmp,jpeg,gif,svg,webp"',
- 'data-action'=>'{{action}}',
- 'data-id'=>'"'.uniqid(rand(0,100)).'"',
- 'data-data'=> "'{}'" ,
- ));
- $type->settings = array(
- 'action'=>array('type'=>'text','default'=>"dynamicform_handle_file",'attributes'=> array('class'=>'"form-control hidden"','disabled'=>true)),
- 'extension'=> array('type'=>'text','label'=>'Extensions permises','placeholder'=>'"Séparation par \',\'"','attributes'=> array('class'=>'"form-control"')),
- 'size'=> array('type'=>'integer','label'=>'Taille max (octets)','attributes'=> array('class'=>'"form-control"')),
- 'storage'=> array('type'=>'filepicker','label'=>'Dossier d\'enregistrement','attributes'=> array('class'=>'"form-control"','data-editable'=>true)),
- 'access'=> array(
- 'type'=>'list',
- 'label'=>'Contrôle des droits et accès à faire sur la section',
- 'values'=>function(){
- $scopes = array();
- foreach(Right::availables() as $slug=>$scope)
- $scopes[$slug] = $scope['label'];
- return $scopes;
- },
- 'attributes'=> array('class'=>'"form-control"')
- ),
- /*'label'=> array('type'=>'text','label'=>'Libellé visible dans la dropzone du composant','placeholder'=>'"Faites glisser vos fichiers ici"','attributes'=> array('class'=>'"form-control"')),
- 'readonly'=> array('type'=>'boolean','label'=>'Lecture seule','attributes'=> array('class'=>'"form-control"')),*/
- );
- $type->onInput = $type_file->onInput;
- $type->onSave = $type_file->onSave;
- $type->onHtmlDisplay = function($value,$options = array()){
- $html = '<div class="fieldtype-image-cover">';
- $meta = json_decode($options['meta'],true);
- $templateData = array();
- foreach($options as $key=>$option){
- if(!is_string($option)) continue;
- $templateData[$key] = $option;
- }
- $path = File::dir().template($meta['storage'],$templateData,true).'/*';
- $files = glob($path);
- $file = $files[0];
- $filePath = str_replace(File::dir(),'',$file);
- $action = 'action.php?action='.$meta['action'].'&type=download&path='.base64_encode($filePath);
- $html .= '<img class="shadow-sm rounded-sm" style="max-width: 100px;height: auto;" src="'.$action.'">';
- if(count($files)>1) $html .= '<span><i class="far fa-file-image"></i> +'.count($files).' </span>';
- $html .= '</div>';
- return $html;
- };
- $type->onRawDisplay = $type_file->onRawDisplay;
- $type->icon = 'far fa-image';
- $type->description = "Envoi d'image";
- $type->default = '';
- $types[$type->slug] = $type;
- //User
- $type = new self();
- $type->slug = 'user';
- $type->label = 'Utilisateur';
- $type->sqlType = 'string';
- $type->default_attributes = array_merge($type_text->default_attributes,array(
- 'data-type'=>'"user"',
- ));
- $type->filter = array(
- 'operators' => array(
- '=' =>array("view" =>'user'),
- '!=' =>array("view" =>'user'),
- 'like' =>array("view" =>'user'),
- 'not like' =>array("view" =>'user'),
- 'null' =>array(),
- 'not null' =>array()
- )
- );
- $type->onInput = $type_text->onInput;
- $type->onRawDisplay = function($value,$options = array()){
- if(empty($value)) return '';
- $user = User::byLogin($value);
- return !$user? '':$user->fullName();
- };
- $type->onHtmlDisplay = function($value,$options = array()){
- $raw = $options['type']->onRawDisplay;
- $html = $raw($value,$options);
- if(isset($options['decoration']) && $options['decoration']) $html = '<img src="action.php?action=core_account_avatar_download&user='.$value.'&extension=jpg" class="avatar-mini avatar-rounded avatar-login" title="'.$html.'"> '.$html;
- return $html;
- };
- $type->icon = 'fas fa-user';
- $type->description = 'Autocompletion sur les comptes utilisateurs';
- $type->default = '';
- $types[$type->slug] = $type;
- //Firm
- $type = new self();
- $type->slug = 'firm';
- $type->label = 'Etablissement';
- $type->sqlType = 'string';
- $type->default_attributes = array_merge($type_text->default_attributes,array(
- 'data-type'=>'"firm"',
- ));
- $type->onInput = $type_text->onInput;
- $type->icon = 'fas fa-building';
- $type->description = 'Autocompletion sur les établissements';
- $type->default = '';
- $type->onRawDisplay = function($value,$options = array()){
- if(empty($value) || !is_numeric($value)) return '';
- $firm = Firm::getById($value);
- return !$firm? '':$firm->label;
- };
- $type->filter = array(
- 'operators' => array(
- '=' =>array("view" =>'firm'),
- '!=' =>array("view" =>'firm'),
- 'null' =>array(),
- 'not null' =>array()
- )
- );
- $types[$type->slug] = $type;
- //Rank
- $type = new self();
- $type->slug = 'rank';
- $type->label = 'Rang';
- $type->sqlType = 'int';
- $type->default_attributes = array_merge($type_text->default_attributes,array(
- 'data-type'=>'"user"',
- 'data-types'=>'"rank"',
- ));
- $type->onInput = $type_text->onInput;
- $type->icon = 'fas fa-user-lock';
- $type->description = 'Autocompletion sur les rangs';
- $type->default = '';
- $type->onRawDisplay = function($value,$options = array()){
- if(empty($value) || !is_numeric($value)) return '';
- $rank = Rank::getById($value);
- return !$rank? '':$rank->label;
- };
- $type->filter = array(
- 'operators' => array(
- '=' =>array("view" =>'rank'),
- '!=' =>array("view" =>'rank'),
- 'null' =>array(),
- 'not null' =>array()
- )
- );
- $types[$type->slug] = $type;
- //Textarea
- $type_longstring = new self();
- $type_longstring->slug = 'textarea';
- $type_longstring->label = 'Texte Long';
- $type_longstring->sqlType = 'longstring';
- $type_longstring->default_attributes = $type_text->default_attributes;
- $type_longstring->onInput = function($field=array(),$options=array()){
- $html = '';
- $html .= '<textarea ';
- if(isset($field['id'])) $field['attributes']['id'] ='"'.$field['id'].'"';
- foreach ($field['attributes'] as $key=>$attribute) {
- if( $key=='value' ) continue;
- $html .= ' '.$key;
- if(!empty($attribute))
- $html .= '='.$attribute;
- }
- if(isset($field['value']) && is_array($field['value']))
- $field['value'] = json_encode($field['value']);
- $html .='>'.(isset($field['value']) && !empty($field['value']) ? (is_callable($field['value']) ? $field['value']() : $field['value']) : '').'</textarea>';
- return $html ;
- };
- $type_longstring->filter = array(
- 'operators' => array(
- 'like' =>array("view" =>'text'),
- 'not like' =>array("view" =>'text'),
- '=' =>array("view" =>'text'),
- '!=' =>array("view" =>'text'),
- 'null' =>array(),
- 'not null' =>array()
- )
- );
- $type_longstring->icon = 'fas fa-text-width';
- $type_longstring->description = 'Texte long multi ligne';
- $type_longstring->default = '';
- $types[$type_longstring->slug] = $type_longstring;
- //Wysiwyg
- $type = new self();
- $type->slug = 'wysiwyg';
- $type->label = 'Texte enrichi';
- $type->sqlType = 'longstring';
- $type->default_attributes = array_merge($type_longstring->default_attributes,array(
- 'data-type'=>'"wysiwyg"',
- 'class'=>'""',
- ));
- $type->onInput = $type_longstring->onInput;
- $type->onRawDisplay = function($value,$options = array()){
- if(empty($value)) return '';
- return strip_tags($value);
- };
- $type->onHtmlDisplay = function($value,$options = array()){
- $html = html_entity_decode($value);
- return $html;
- };
- $type->filter = $type_longstring->filter;
- $type->icon = 'fas fa-spell-check';
- $type->description = 'Texte riche multi ligne';
- $type->default = '';
- $types[$type->slug] = $type;
- //Date
- $type = new self();
- $type->slug = 'date';
- $type->label = 'Date';
- $type->sqlType = 'date';
- $type->default_attributes = array_merge($type_text->default_attributes,array(
- 'data-type'=>'"date"',
- 'title'=>'"format jj/mm/aaaa"',
- 'placeholder'=>'"JJ/MM/AAAA"',
- ));
- $type->onLoad = function($value){
- return !is_null($value) || is_numeric($value) ? date('d/m/Y',$value) : '';
- };
- $type->onSave = function($value,$options=array()){
- return !empty($value) ? timestamp_date($value) : null;
- };
- $type->onRawDisplay = function($value,$options = array()){
- $html = !is_null($value) && is_numeric($value) ? date('d/m/Y',$value) : '';
- return $html;
- };
- $type->fromRawDisplay = function($value,$options = array()){
- return timestamp_date($value);
- };
- $type->filter = array(
- 'operators' => array(
- 'between' =>array("view" =>'date'),
- '=' =>array("view" =>'date'),
- '!=' =>array("view" =>'date'),
- 'null' =>array(),
- 'not null' =>array()
- )
- );
- $type->onInput = $type_text->onInput;
- $type->icon = 'far fa-calendar';
- $type->description = 'Date au format jj/mm/aaaa';
- $type->default = '';
- $types[$type->slug] = $type;
- //Tags
- $type = new self();
- $type->slug = 'tag';
- $type->label = 'Etiquettes';
- $type->sqlType = 'string';
- $type->default_attributes = array_merge($type_text->default_attributes,array(
- 'data-type'=>'"tag"',
- 'data-multiple'=>'true'
- ));
- $type->onInput = $type_text->onInput;
- $type->icon = 'fas fa-tags';
- $type->description = 'Etiquettes (tags) séparés par virgules, espace ou tabulation';
- $type->default = '';
- $type->onHtmlDisplay = function($value,$options = array()){
- $html = '';
- $tags = explode(',',$value);
- $html = '<span class="badge">'.implode('</span><span class="badge">',$tags).'</span>';
- return $html;
- };
- $type->filter = array(
- 'operators' => array(
- 'in' =>array("view" =>'tag'),
- 'not in' =>array("view" =>'tag'),
- 'inline-and' =>array("view" =>'tag'),
- 'inline-or' =>array("view" =>'tag'),
- 'null' =>array(),
- 'not null' =>array()
- )
- );
- $type->onSave = function($value,$options=array()){
- $value = explode(',',$value);
- $value = array_filter($value);
- $value = ','.implode(',',$value).',';
- if($value==',,') $value = '';
- return $value;
- };
- $types[$type->slug] = $type;
- //File picker
- $type = new self();
- $type->slug = 'filepicker';
- $type->label = 'Parcourir';
- $type->sqlType = 'longstring';
- $type->default_attributes = array_merge($type_text->default_attributes,array(
- 'data-type'=>'"filepicker"',
- ));
- $type->onInput = $type_text->onInput;
- $type->icon = 'far fa-folder-open';
- $type->description = 'Rechercher dans un dossier';
- $type->default = '';
- $type->settings = array(
- 'root'=> array(
- 'type'=>'filepicker',
- 'label'=>'Racine ciblée',
- 'attributes'=> array('class'=>'"form-control"', 'data-root'=>"")
- )
- );
- $type->filter = array(
- 'operators' => array(
- '=' =>array("view" =>'filepicker'),
- '!=' =>array("view" =>'filepicker'),
- 'null' =>array(),
- 'not null' =>array()
- )
- );
- $types[$type->slug] = $type;
- //Heure
- $type = new self();
- $type->slug = 'hour';
- $type->label = 'Heure';
- $type->sqlType = 'string';
- $type->default_attributes = array_merge($type_text->default_attributes,array(
- 'data-type'=>'"hour"',
- 'title'=>'"format hh:mm"',
- 'placeholder'=>'"13:37"',
- ));
- $type->onInput = $type_text->onInput;
- $type->icon = 'far fa-clock';
- $type->description = 'Combo Heures/minutes';
- $type->default = '';
- $type->filter = array(
- 'operators' => array(
- '<' =>array("view" =>'hour'),
- '>' =>array("view" =>'hour'),
- '=' =>array("view" =>'hour'),
- 'null' =>array(),
- 'not null' =>array()
- )
- );
- $types[$type->slug] = $type;
- //Dictionnaire
- $type_dictionary = new self();
- $type_dictionary->slug = 'dictionary';
- $type_dictionary->label = 'Liste configurable';
- $type_dictionary->sqlType = 'int';
- $type_dictionary->default_attributes = array_merge($type_text->default_attributes,array(
- 'data-type'=>'"dictionary"',
- 'data-slug'=>'"{{key}}"',
- 'data-depth'=>'"1"',
- 'key'=>'data-disable-label',
- 'data-value'=>'',
- 'class'=>'"form-control select-control"'
- ));
- $type_dictionary->settings = array(
- 'slug'=> array(
- 'type'=>'dictionary',
- 'label'=>'Liste ciblée',
- 'attributes'=> array(
- 'class'=>'"form-control"',
- 'data-slug'=>"",
- 'data-output'=>"slug"
- )
- )
- );
- $type_dictionary->onRawDisplay = function($value,$options = array()){
- if(empty($value) || !is_numeric($value)) return '';
- $dictionary = Dictionary::getById($value);
- return !$dictionary? '':$dictionary->label;
- };
- $type_dictionary->fromRawDisplay = function($value,$options = array()){
- $filters = array('label'=>$value);
- if(isset($options['parent'])) $filters['parent'] = $options['parent'];
- $dictionary = Dictionary::load($filters);
- return !$dictionary ? 0 : $dictionary->id;
- };
- $type_dictionary->onInput = function($field = array(),$options = array()){
- if(isset($field['id'])) $field['attributes']['id'] ='"'.$field['id'].'"';
- if(isset($field['value'])) $field['attributes']['data-value'] = $field['value'];
- //gestion des metas de dynamiques fields pour listes simples
- if(isset($field['attributes']['data-values'])){
- $field['values'] = $field['attributes']['data-values'];
- unset($field['attributes']['data-values']);
- }
- $html = '';
- $html .= '<select ';
- foreach ($field['attributes'] as $key=>$attribute) {
- $html .= $key;
- if(!empty($attribute))
- $html .= '='.$attribute;
- $html .= ' ';
- }
- $html .='>';
- if(isset($field['values'])){
- $values = is_callable($field['values']) ? $field['values']() : $field['values'];
- if(!empty($values) && is_array($values)){
- foreach($values as $key=>$value){
- $html .='<option '.(isset($field['value']) && $field['value']==$key?' selected="selected" ':'').' value="'.$key.'">'.$value.'</option>';
- }
- }
- }
- $html .='</select>';
- return $html ;
- };
- $type_dictionary->icon = 'fas fa-list-ol';
- $type_dictionary->description = 'Liste de sélection configurable récursive';
- $type_dictionary->default = '';
- $type_dictionary->filter = array(
- 'attributes' => array(
- 'data-display'=>'"dropdown"',
- 'data-slug'=>'"{{slug}}"',
- 'data-depth'=>'"{{depth}}"',
- 'data-value-selector'=>'".filter-value:last-child"'
- ),
- 'operators' => array(
- 'in' =>array(
- "view" => "checkbox-list",
- "value-separator" => ","
- ),
- 'not in' =>array(
- "view" => "checkbox-list",
- "value-separator" => ","
- ),
- '=' =>array("view" =>'dictionary'),
- '!=' =>array("view" =>'dictionary'),
- 'null' =>array(),
- 'not null' =>array()
- )
- );
- $types[$type_dictionary->slug] = $type_dictionary;
- //Table JSON clé / valeur
- $type = new self();
- $type->slug = 'jsontable';
- $type->label = 'Table clé/valeur';
- $type->sqlType = 'longstring';
- $type->default_attributes = array(
- 'type'=>'"text"',
- 'data-type'=>'"jsontable"',
- 'data-format'=>'"key-value"',
- );
- $type->onInput = $type_text->onInput;
- $type->icon = 'fas fa-table';
- $type->description = 'Table clé/valeur enregistré en JSON';
- $type->default = '';
- $type->onRawDisplay = function($value){
- $stream = '';
- $table = json_decode($value,true);
- if(!is_array($table)) return '';
- foreach($table as $key=>$value){
- $stream .= ''.$key.' : '.$value.',';
- }
- return $stream;
- };
- $type->onHtmlDisplay = function($value){
- $html = '<ul class="list-group">';
- $table = json_decode($value,true);
- if(!is_array($table)) return '';
- foreach($table as $key=>$value){
- $html .= '<li class="list-group-item p-1"><strong>'.$key.'</strong> : '.$value.'</li>';
- }
- $html .= '</ul>';
- return $html;
- };
- $types[$type->slug] = $type;
- //Liste
- $type_list = new self();
- $type_list->slug = 'list';
- $type_list->label = 'Liste classique';
- $type_list->sqlType = 'string';
- $type_list->default_attributes = array_merge($type_text->default_attributes,array(
- 'class'=>'"form-control select-control"'
- ));
- $type_list->filter = array(
- 'attributes' => array(
- 'data-values'=>'"{{filterTypeValue}}"',
- ),
- 'operators' => array(
- 'in' =>array(
- "view" => "checkbox-list",
- "value-separator" => ",",
- ),
- 'not in' =>array(
- "view" => "checkbox-list",
- "value-separator" => ",",
- ),
- 'inline-and' =>array(
- "view" => "checkbox-list",
- "value-separator" => ",",
- ),
- 'inline-or' =>array(
- "view" => "checkbox-list",
- "value-separator" => ",",
- ),
- '=' =>array("view" =>'list'),
- '!=' =>array("view" =>'list'),
- 'null' =>array(),
- 'not null' =>array()
- )
- );
- $type_list->onInput = $type_dictionary->onInput;
- $type_list->onRawDisplay = function($value,$options = array()){
- if(!isset($options['meta'])) return '';
- $list = json_decode($options['meta'],true);
- return isset($list['values']) && isset($list['values'][$value]) ? $list['values'][$value] : '';
- };
- $type_list->icon = 'fas fa-list-ol';
- $type_list->description = 'Liste de sélection classique';
- $type_list->default = '';
- $type_list->settings = array(
- 'values'=> array(
- 'type'=>'jsontable',
- 'label'=>'Valeurs possibles',
- 'attributes'=> array(
- 'data-columns' => '\'{"key":"Clé","value":"Valeur"}\'',
- 'data-format' => '"key-value"'
- ))
- );
- $types[$type_list->slug] = $type_list;
- //Checkbox list
- $type_checkbox = new self();
- $type_checkbox->slug = 'checkbox-list';
- $type_checkbox->label = 'Liste de cases à cocher';
- $type_checkbox->sqlType = 'longtext';
- $type_checkbox->default_attributes = array_merge($type_text->default_attributes,array(
- 'data-type'=>'"checkbox-list"',
- 'data-slug'=>'"{{key}}"',
- 'data-display'=>'"dropdown"',
- 'value'=>'"{{value}}"',
- 'class'=>'"form-control"'
- ));
- $type_checkbox->settings = array(
- 'slug'=> array(
- 'type'=>'dictionary',
- 'label'=>'Liste ciblée',
- 'attributes'=> array(
- 'class'=>'"form-control"',
- 'data-slug'=>"",
- 'data-output'=>"slug",
- 'data-format'=>"slug"
- )
- ),
- 'values'=> array(
- 'type'=>'jsontable',
- 'label'=>'Valeurs possibles',
- 'attributes'=> array(
- 'data-columns' => '\'{"key":"Clé","value":"Valeur"}\'',
- 'data-format' => '"key-value"'
- )),
- 'operator-delete'=> array(
- 'type'=>'text',
- 'value'=>'["in","not in"]',
- 'attributes'=> array(
- 'class' => '"hidden"',
- ))
- );
- $type_checkbox->filter = array(
- 'attributes' => array(
- 'data-display'=>'"dropdown"',
- 'data-slug'=>'"{{slug}}"',
- 'data-depth'=>'"{{depth}}"',
- //'data-display'=>'"{{display}}"',
- 'data-values'=>'"{{filterTypeValue}}"',
- 'data-multi-level-select'=>'"{{multiLevelSelect}}"',
- ),
- 'operators' => array(
- 'in' =>array(
- "view" => "checkbox-list",
- "value-separator" => ","
- ),
- 'not in' =>array(
- "view" => "checkbox-list",
- "value-separator" => ","
- ),
- 'inline-and' =>array(
- "view" => "checkbox-list"
- ),
- 'inline-or' =>array(
- "view" => "checkbox-list"
- ),
- '=' =>array("view" =>'dictionary'),
- '!=' =>array("view" =>'dictionary'),
- 'null' =>array(),
- 'not null' =>array()
- )
- );
- $type_checkbox->onInput = function($field=array(),$options=array()){
- $attributes = array_merge($options['type']->default_attributes,$field['attributes']);
- if(isset($field['id'])) $field['attributes']['id'] ='"'.$field['id'].'"';
- $html = '';
- $html.= '<input value="'.(isset($field['value']) ? str_replace('"','"',$field['value']) : '').'"';
- foreach ($field['attributes'] as $key => $value) {
- $html.= ' ';
- $html.= $key;
- if(!empty($value)) $html.= '='.(is_string($value)?$value:"'".json_encode($value)."'");
- $html.= ' ';
- }
- $html.= '>';
- return $html;
- };
- $type_checkbox->onSave = function($value,$options=array()){
- $value = explode(',',$value);
- $value = array_filter($value);
- $value = ','.implode(',',$value).',';
- if($value==',,') $value = '';
- return $value;
- };
- $type_checkbox->onLoad = function($value){
- $value = explode(',',$value);
- $value = array_filter($value);
- $value = implode(',',$value);
- return $value;
- };
- $type_checkbox->onRawDisplay = function($value,$field) use($type_checkbox){
- $onLoad = $type_checkbox->onLoad;
- $value = $onLoad($value);
- $values = explode(',',$value);
- if(count($values)==0) return '';
- $results = array();
- //dictionary
- $ids = array();
- foreach($values as $i=>$id){
- if(empty($id) || !is_numeric($id)) continue;
- unset($values[$i]);
- $ids[] = $id ;
- }
- if(count($ids)!=0){
- $dictionnaries = Dictionary::loadAll(array('id:IN'=>$ids));
- foreach($dictionnaries as $dictionary){
- $results[] = $dictionary->label;
- }
- }
- //valeur en dur
- if(!empty($field['meta'])){
- $meta = json_decode($field['meta'],true);
- if(!empty($meta['values'])){
- $availableValues = $meta['values'];
- foreach($values as $id){
- if(isset($availableValues[$id])) $results[] = $availableValues[$id];
- }
- }
- };
- $value = implode(',',$results);
- return $value;
- };
- $type_checkbox->onHtmlDisplay = function($value,$field) use($type_checkbox){
- $onRawDisplay = $type_checkbox->onRawDisplay;
- $value = explode(',',$onRawDisplay($value,$field));
- $value = array_filter($value);
- $value = '<span class="badge badge-secondary">'.implode('</span> <span class="badge badge-secondary">',$value).'</span>';
- return $value;
- };
- $type_checkbox->fromRawDisplay = function($value,$options = array()){
- $filters = array('label'=>$value);
- if(isset($options['parent'])) $filters['parent'] = $options['parent'];
- $dictionary = Dictionary::load($filters);
- return !$dictionary ? 0 : $dictionary->id;
- };
- $type_checkbox->icon = 'fas fa-list';
- $type_checkbox->description = 'Liste de cases à cocher configurable';
- $type_checkbox->default = '';
- $types[$type_checkbox->slug] = $type_checkbox;
- //Entier
- $type = new self();
- $type->slug = 'integer';
- $type->label = 'Nombre Entier';
- $type->sqlType = 'int';
- $type->default_attributes = array_merge($type_text->default_attributes,array(
- 'type'=>'"number"',
- ));
- $type->onInput = $type_text->onInput;
- $type->icon = 'fas fa-sort-numeric-down';
- $type->description = 'Nombre entier';
- $type->onSave = function($value,$options=array()){
- $value = trim($value);
- if(!empty($value) && !is_numeric($value)) throw new Exception("Ce champ ne doit contenir que des chiffres et être entier");
- return $value;
- };
- $type->filter = array(
- 'operators' => array(
- 'in' => array(
- "view" =>'tag',
- "value-separator" => ","
- ),
- 'not in' => array(
- "view" =>'tag',
- "value-separator" => ","
- ),
- '<' => array("view" =>'decimal'),
- '>' => array("view" =>'decimal'),
- '=' => array("view" =>'decimal'),
- '!=' => array("view" =>'decimal'),
- 'between' => array("view" =>'decimal'),
- 'null' => array(),
- 'not null' => array()
- )
- );
- $type->default = '';
- $types[$type->slug] = $type;
- //Flottant
- $type = new self();
- $type->slug = 'decimal';
- $type->label = 'Décimal';
- $type->sqlType = 'decimal';
- $type->default_attributes = array_merge($type_text->default_attributes,array(
- 'data-type'=>'"decimal"'
- ));
- $type->onInput = $type_text->onInput;
- $type->icon = 'fas fa-sort-numeric-down';
- $type->description = 'Nombre décimal';
- $type->onSave = function($value,$options=array()){
- $value = trim(str_replace(',', '.', $value));
- if(!empty($value) && !is_numeric($value)) throw new Exception("Ce champ ne doit contenir que des chiffres");
- return $value;
- };
- $type->filter = array(
- 'operators' => array(
- 'in' => array(
- "view" =>'tag',
- "value-separator" => ","
- ),
- 'not in' => array(
- "view" =>'tag',
- "value-separator" => ","
- ),
- '<' => array("view" =>'decimal'),
- '>' => array("view" =>'decimal'),
- '=' => array("view" =>'decimal'),
- '!=' => array("view" =>'decimal'),
- 'between' => array("view" =>'decimal'),
- 'null' => array(),
- 'not null' => array()
- )
- );
- $type->default = '';
- $types[$type->slug] = $type;
- //Adresse
- $type = new self();
- $type->slug = 'address';
- $type->label = 'Adresse';
- $type->sqlType = 'longstring';
- $type->default_attributes = array_merge($type_text->default_attributes,array(
- 'data-type'=>'"location"',
- ));
- $type->onInput = $type_text->onInput;
- $type->icon = 'fas fa-street-view';
- $type->description = 'Adresse postale';
- $type->default = '';
- $type->filter = array(
- 'operators' => array(
- 'like' => array("view" =>'text'),
- '=' => array("view" =>'text'),
- '!=' => array("view" =>'text'),
- 'null' => array(),
- 'not null' => array()
- )
- );
- $types[$type->slug] = $type;
- //Password
- $type = new self();
- $type->slug = 'password';
- $type->label = 'Mot de passe';
- $type->sqlType = 'string';
- $type->default_attributes = array_merge($type_text->default_attributes,array(
- 'data-type'=>'"password"',
- 'autocomplete'=>'"new-password"',
- ));
- $type->onInput = $type_text->onInput;
- $type->onSave = function($value,$options=array()){
- return encrypt($value);
- };
- $type->onLoad = function($value){
- $value = decrypt($value);
- return $value === false ? '' : $value;
- };
- $type->onRawDisplay = function($value,$options = array()){
- $value = decrypt($value);
- return $value === false ? '' : $value;
- };
- $type->icon = 'fas fa-unlock-alt';
- $type->description = 'Mot de passe caché';
- $type->default = '';
- $types[$type->slug] = $type;
- //Couleur
- $type = new self();
- $type->slug = 'color';
- $type->label = 'Couleur';
- $type->sqlType = 'string';
- $type->default_attributes = array_merge($type_text->default_attributes,array(
- 'data-type'=>'"color"',
- ));
- $type->onHtmlDisplay = function($value,$options = array()){
- if(empty($value)){
- $html = '<span class="fa-stack">
- <i class="far fa-circle fa-stack-1x"></i>
- <i class="fas fa-slash text-danger fa-stack-1x"></i>
- </span>';
- }else{
- $html = '<i class="fas fa-circle" style="color:'.$value.'"></i>';
- }
- return $html;
- };
- $type->filter = array(
- 'operators' => array(
- '=' => array("view" =>'text'),
- '!=' => array("view" =>'text'),
- 'null' => array(),
- 'not null' => array()
- )
- );
- $type->onInput = $type_text->onInput;
- $type->icon = 'fas fa-palette';
- $type->description = 'Couleur';
- $type->default = '';
- $types[$type->slug] = $type;
- //Icône
- $type = new self();
- $type->slug = 'icon';
- $type->label = 'Icône';
- $type->sqlType = 'string';
- $type->default_attributes = array_merge($type_text->default_attributes,array(
- 'data-type'=>'"icon"',
- ));
- $type->onInput = $type_text->onInput;
- $type->onHtmlDisplay = function($value,$options = array()){
- $html = '<i class="'.$value.'"></i>';
- return $html;
- };
- $type->filter = array(
- 'operators' => array(
- '=' => array("view" =>'icon'),
- '!=' => array("view" =>'icon'),
- 'null' => array(),
- 'not null' => array()
- )
- );
- $type->icon = 'fas fa-icons';
- $type->description = 'Icône d\'illustration';
- $type->default = '';
- $types[$type->slug] = $type;
- //Prix
- $type = new self();
- $type->slug = 'price';
- $type->label = 'Prix';
- $type->sqlType = 'decimal';
- $type->onInput = $type_text->onInput;
- $type->icon = 'fas fa-euro-sign';
- $type->description = 'Devis monetaire';
- $type->default = '';
- $type->default_attributes = array_merge($type_text->default_attributes,array(
- 'data-type'=>'"price"',
- 'step'=>'"0.01"',
- 'type'=>'number'
- ));
- $type->filter = array(
- 'operators' => array(
- '=' => array("view" =>'price'),
- '!=' => array("view" =>'price'),
- '<' => array("view" =>'price'),
- '>' => array("view" =>'price'),
- 'between' =>array("view" =>'price'),
- 'in' => array(
- "view" =>'tag',
- "value-separator" => ","
- ),
- 'not in' => array(
- "view" =>'tag',
- "value-separator" => ","
- ),
- 'null' => array(),
- 'not null' => array()
- )
- );
- $type->onSave = function($value,$options=array()){
- $value = trim(str_replace(',', '.', $value));
- if(!empty($value) && !is_numeric($value)) throw new Exception("Le prix ne doit contenir que des chiffres");
- return $value;
- };
- $types[$type->slug] = $type;
- //Choix
- $type = new self();
- $type->slug = 'choice';
- $type->label = 'Choix';
- $type->customLabel = false;
- $type->sqlType = 'longstring';
- $type->default_attributes = array_merge($type_text->default_attributes,array(
- 'data-type'=>'"choice"',
- 'class'=>''
- ));
- $type->filter = array(
- 'attributes' => array('data-values'=>'"{{filterTypeValue}}"'),
- 'operators' => array(
- '=' => array("view" =>'choice'),
- '!=' => array("view" =>'choice'),
- 'null' => array(),
- 'not null' => array()
- )
- );
- $type->settings = array(
- 'values'=> array(
- 'type'=>'jsontable',
- 'label'=>'Options possibles',
- 'attributes'=> array(
- 'data-columns' => '\'{"key":"Clé","value":"Valeur"}\'',
- 'data-format' => '"key-value"'
- )
- )
- );
- $type->onInput = function($field=array(),$options=array()){
- $attributes = array_merge($options['type']->default_attributes,$field['attributes']);
- if(isset($field['id'])) $field['attributes']['id'] ='"'.$field['id'].'"';
- $html = '';
- $html.= '<input value="'.(isset($field['value']) ? str_replace('"','"',$field['value']) : '').'" data-values="'.(isset($field['values']) ? htmlspecialchars(json_encode($field['values']), ENT_QUOTES, 'UTF-8') : '').'"';
- foreach ($field['attributes'] as $key => $value) {
- $html.= ' ';
- $html.= $key;
- if(!empty($value)) $html.= '='.(is_string($value)?$value:"'".json_encode($value)."'");
- $html.= ' ';
- }
- $html.= '>';
- return $html;
- };
- $type->onRawDisplay = function($value,$options = array()){
- if(isset($options['meta'])){
- $meta = is_string($options['meta']) ? json_decode($options['meta'],true) : $options['meta'];
- if(isset($meta['values']) && isset($meta['values'][$value])){
- $value = $meta['values'][$value];
- }
- }
- return $value;
- };
- $type->onHtmlDisplay = $type->onRawDisplay;
- $type->icon = 'far fa-dot-circle';
- $type->description = 'Choix unique';
- $type->default = '';
- $types[$type->slug] = $type;
- //Booléen
- $type = new self();
- $type->slug = 'boolean';
- $type->label = 'Vrai ou Faux';
- $type->customLabel = true;
- $type->sqlType = 'boolean';
- $type->default_attributes = array_merge($type_text->default_attributes,array(
- 'data-type'=>'"checkbox"',
- 'class'=>'',
- 'type'=>'"checkbox"'
- ));
- $type->filter = array(
- 'operators' => array(
- '=' => array("view" =>'boolean'),
- 'null' => array(),
- 'not null' => array()
- )
- );
- $type->onRawDisplay = function($value,$options = array()){
- return $value ? 'VRAI' : 'FAUX';
- };
- $type->onHtmlDisplay = function($value,$options = array()){
- $html = $value ? '<i class="fas fa-check text-success"></i>' : '<i class="fas fa-times text-danger"></i>' ;
- return $html;
- };
- $type->onInput = function($field=array(),$option=array()){
- $html = '';
- $html.= '<div><label><input id="'.(isset($field['id'])?$field['id']:'').'" ';
- if(isset($field['value']) && $field['value'] == 1){
- $field['attributes']['checked'] = '"checked"';
- }
- foreach ($field['attributes'] as $key => $value) {
- $html.= ' ';
- $html.= $key;
- if(!empty($value)) $html.= '='.$value;
- $html.= ' ';
- }
- $html.= '>';
- if(!empty($field['label']) && $option['allowCustomLabel']) $html.= ' '.$field['label'];
- $html.= '</label></div>';
- return $html;
- };
- $type->icon = 'far fa-check-square';
- $type->description = 'Vrai ou Faux';
- $type->default = '';
- $types[$type->slug] = $type;
- //Url
- $type = new self();
- $type->slug = 'url';
- $type->label = 'Adresse web';
- $type->sqlType = 'string';
- $type->default_attributes = array_merge($type_text->default_attributes,array(
- 'data-type'=>'"url"',
- ));
- $type->onSave = function($value,$options=array()){
- if(!empty($value) && !filter_var($value, FILTER_VALIDATE_URL) ) throw new Exception("Mauvais format d'adresse web");
- return $value;
- };
- $type->onInput = $type_text->onInput;
- $type->onHtmlDisplay = function($value,$options = array()){
- if(empty($value)) return $value;
- $html = '<a href="'.$value.'">';
- $html .= $value;
- $html.= '</a>';
- return $html;
- };
- $type->filter = array(
- 'operators' => array(
- '=' => array("view" =>'url'),
- '!=' => array("view" =>'url'),
- 'like' => array("view" =>'text'),
- 'not like' => array("view" =>'text'),
- 'null' => array(),
- 'not null' => array()
- )
- );
- $type->icon = 'fas fa-globe';
- $type->description = 'Adresse Url (web)';
- $type->default = '';
- $types[$type->slug] = $type;
- //Mail
- $type = new self();
- $type->slug = 'mail';
- $type->label = 'E-mail';
- $type->sqlType = 'string';
- $type->default_attributes = array_merge($type_text->default_attributes,array(
- 'data-type'=>'"mail"',
- 'type'=>'"mail"',
- 'pattern'=>'".+@.+"'
- ));
- $type->onSave = function($value,$options=array()){
- if(!empty($value) && !check_mail($value)) throw new Exception("Mauvais format d'e-mail");
- return $value;
- };
- $type->onHtmlDisplay = function($value,$options = array()){
- $html = '<a href="mailto:'.$value.'">';
- $html .= $value;
- $html.= '</a>';
- return $html;
- };
- $type->filter = array(
- 'operators' => array(
- '=' => array("view" =>'mail'),
- '!=' => array("view" =>'mail'),
- 'like' => array("view" =>'text'),
- 'not like' => array("view" =>'text'),
- 'null' => array(),
- 'not null' => array()
- )
- );
- $type->onInput = $type_text->onInput;
- $type->icon = 'far fa-envelope-open';
- $type->description = 'E-mail';
- $type->default = '';
- $types[$type->slug] = $type;
- //Téléphone
- $type = new self();
- $type->slug = 'phone';
- $type->label = 'Téléphone';
- $type->sqlType = 'string';
- $type->default_attributes = array_merge($type_text->default_attributes,array(
- 'data-type'=>'"phone"'
- ));
- $type->onSave = function($value,$options=array()){
- if(!empty($value) && !check_phone_number($value)) throw new Exception("Mauvais format de téléphone");
- $value = normalize_phone_number($value);
- return $value;
- };
- $type->onInput = $type_text->onInput;
- $type->icon = 'fas fa-mobile-alt';
- $type->description = 'N° Téléphone';
- $type->default = '';
- $type->filter = array(
- 'operators' => array(
- 'like' =>array("view" =>'text'),
- 'not like' =>array("view" =>'text'),
- '=' =>array("view" =>'phone'),
- '!=' =>array("view" =>'phone'),
- 'null' =>array(),
- 'not null' =>array()
- )
- );
- $types[$type->slug] = $type;
- Plugin::callHook('field_types',array(&$types));
- if(isset($key)) return isset($types[$key])? $types[$key] : $types['text'];
- return $types;
- }
- }
|