<?php class Template{ public static function all($template){ $templates = array(); foreach (glob(self::dir($template).'*') as $path) { $relativePath = str_replace(self::dir($template),'',$path); if(is_file($path)){ $f = fopen($path, 'r'); $line = fgets($f); fclose($f); $infos = json_decode($line,true); $templates[$infos['label']] = array('file'=>$path,'syntax'=>$infos['syntax']); }else{ $templates = array_merge($templates,self::all($template.SLASH.$relativePath)); } } return $templates; } public static function dir($tpl = null){ return __DIR__.SLASH.'template'.SLASH.(isset($tpl)? $tpl.SLASH:''); } public static function types(){ $types = array( 'string' => array( 'label'=>'Texte', 'sql-type'=>'string', 'input'=>'<input id="{{key}}" name="{{key}}" class="form-control" placeholder="" value="<?php echo ${{entity}}->{{key}}; ?>" type="text">'), 'user' => array( 'label'=>'Utilisateur', 'sql-type'=>'string', 'input'=>'<input id="{{key}}" name="{{key}}" data-type="user" class="form-control" placeholder="" value="<?php echo ${{entity}}->{{key}}; ?>" type="text">'), 'longstring' => array( 'label'=>'Texte Long', 'sql-type'=>'longstring', 'input'=>'<textarea id="{{key}}" name="{{key}}" class="form-control"><?php echo ${{entity}}->{{key}}; ?></textarea>'), 'wysiwyg' => array( 'label'=>'WYSIWYG', 'sql-type'=>'longstring', 'input'=>'<textarea id="{{key}}" data-type="wysiwyg" name="{{key}}" class="form-control"><?php echo ${{entity}}->{{key}}; ?></textarea>'), 'date' => array( 'label'=>'Date', 'sql-type'=>'date', 'input'=>'<input id="{{key}}" name="{{key}}" data-type="date" title="format jj/mm/aaaa" class="form-control" placeholder="JJ/MM/AAAA" value="<?php echo ${{entity}}->{{key}}; ?>" type="text">'), 'hour' => array( 'label'=>'Heure', 'sql-type'=>'string', 'input'=>'<input id="{{key}}" name="{{key}}" data-type="hour" title="format hh:mm" class="form-control" placeholder="13:37" value="<?php echo ${{entity}}->{{key}}; ?>" type="text">'), 'dictionnary' => array( 'label'=>'Liste configurable', 'sql-type'=>'int', 'input'=>'<select data-type="dictionnary" data-slug="{{key}}" data-depth="1" data-disable-label data-value="<?php echo ${{entity}}->{{key}}; ?>" class="form-control select-control" name="{{key}}" id="{{key}}"></select>'), 'int' => array( 'label'=>'Entier', 'sql-type'=>'int', 'input'=>'<input id="{{key}}" name="{{key}}" class="form-control" placeholder="" value="<?php echo ${{entity}}->{{key}}; ?>" type="number">'), 'float' => array( 'label'=>'Décimal', 'sql-type'=>'float', 'input'=>'<input id="{{key}}" name="{{key}}" class="form-control" placeholder="" value="<?php echo ${{entity}}->{{key}}; ?>" type="text">'), 'address' => array( 'label'=>'Adresse', 'sql-type'=>'longstring', 'input'=>'<input id="{{key}}" name="{{key}}" data-type="location" class="form-control" placeholder="" value="<?php echo ${{entity}}->{{key}}; ?>" type="text">'), 'password' => array( 'label'=>'Mot de passe', 'sql-type'=>'string', 'input'=>'<input id="{{key}}" name="{{key}}" data-type="password" class="form-control" placeholder="" value="<?php echo ${{entity}}->{{key}}; ?>" type="text">'), 'icon' => array( 'label'=>'Icône', 'sql-type'=>'string', 'input'=>'<input id="{{key}}" name="{{key}}" data-type="icon" class="form-control" placeholder="" value="<?php echo ${{entity}}->{{key}}; ?>" type="text">'), 'decimal' => array( 'label'=>'Prix', 'sql-type'=>'decimal', 'input'=>'<input id="{{key}}" name="{{key}}" class="form-control" placeholder="" value="<?php echo ${{entity}}->{{key}}; ?>" type="text">'), 'boolean' => array( 'label'=>'Booléen', 'sql-type'=>'boolean', 'input'=>'<input title="" type="checkbox" name="<?php echo ${{entity}}->{{key}}; ?>" id="<?php echo ${{entity}}->{{key}}; ?>" data-class="" data-type="checkbox">'), 'mail' => array( 'label'=>'E-mail', 'sql-type'=>'string', 'input'=>'<input id="{{key}}" name="{{key}}" data-type="mail" pattern=".+@.+" class="form-control" placeholder="" value="<?php echo ${{entity}}->{{key}}; ?>" type="email">'), ); return $types; } } ?>