Template.class.php 4.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php
  2. class Template{
  3. public static function all($template){
  4. $templates = array();
  5. foreach (glob(self::dir($template).'*') as $path) {
  6. $relativePath = str_replace(self::dir($template),'',$path);
  7. if(is_file($path)){
  8. $f = fopen($path, 'r');
  9. $line = fgets($f);
  10. fclose($f);
  11. $infos = json_decode($line,true);
  12. $templates[$infos['label']] = array('file'=>$path,'syntax'=>$infos['syntax']);
  13. }else{
  14. $templates = array_merge($templates,self::all($template.SLASH.$relativePath));
  15. }
  16. }
  17. return $templates;
  18. }
  19. public static function dir($tpl = null){
  20. return __DIR__.SLASH.'template'.SLASH.(isset($tpl)? $tpl.SLASH:'');
  21. }
  22. public static function types(){
  23. $types = array(
  24. 'string' => array(
  25. 'label'=>'Texte',
  26. 'sql-type'=>'string',
  27. 'input'=>'<input id="{{key}}" name="{{key}}" class="form-control" placeholder="" value="<?php echo ${{entity}}->{{key}}; ?>" type="text">'),
  28. 'user' => array(
  29. 'label'=>'Utilisateur',
  30. 'sql-type'=>'string',
  31. 'input'=>'<input id="{{key}}" name="{{key}}" data-type="user" class="form-control" placeholder="" value="<?php echo ${{entity}}->{{key}}; ?>" type="text">'),
  32. 'longstring' => array(
  33. 'label'=>'Texte Long',
  34. 'sql-type'=>'longstring',
  35. 'input'=>'<textarea id="{{key}}" name="{{key}}" class="form-control"><?php echo ${{entity}}->{{key}}; ?></textarea>'),
  36. 'wysiwyg' => array(
  37. 'label'=>'WYSIWYG',
  38. 'sql-type'=>'longstring',
  39. 'input'=>'<textarea id="{{key}}" data-type="wysiwyg" name="{{key}}" class="form-control"><?php echo ${{entity}}->{{key}}; ?></textarea>'),
  40. 'date' => array(
  41. 'label'=>'Date',
  42. 'sql-type'=>'date',
  43. '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">'),
  44. 'hour' => array(
  45. 'label'=>'Heure',
  46. 'sql-type'=>'string',
  47. '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">'),
  48. 'dictionnary' => array(
  49. 'label'=>'Liste configurable',
  50. 'sql-type'=>'int',
  51. '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>'),
  52. 'int' => array(
  53. 'label'=>'Entier',
  54. 'sql-type'=>'int',
  55. 'input'=>'<input id="{{key}}" name="{{key}}" class="form-control" placeholder="" value="<?php echo ${{entity}}->{{key}}; ?>" type="number">'),
  56. 'float' => array(
  57. 'label'=>'Décimal',
  58. 'sql-type'=>'float',
  59. 'input'=>'<input id="{{key}}" name="{{key}}" class="form-control" placeholder="" value="<?php echo ${{entity}}->{{key}}; ?>" type="text">'),
  60. 'address' => array(
  61. 'label'=>'Adresse',
  62. 'sql-type'=>'longstring',
  63. 'input'=>'<input id="{{key}}" name="{{key}}" data-type="location" class="form-control" placeholder="" value="<?php echo ${{entity}}->{{key}}; ?>" type="text">'),
  64. 'password' => array(
  65. 'label'=>'Mot de passe',
  66. 'sql-type'=>'string',
  67. 'input'=>'<input id="{{key}}" name="{{key}}" data-type="password" class="form-control" placeholder="" value="<?php echo ${{entity}}->{{key}}; ?>" type="text">'),
  68. 'icon' => array(
  69. 'label'=>'Icône',
  70. 'sql-type'=>'string',
  71. 'input'=>'<input id="{{key}}" name="{{key}}" data-type="icon" class="form-control" placeholder="" value="<?php echo ${{entity}}->{{key}}; ?>" type="text">'),
  72. 'decimal' => array(
  73. 'label'=>'Prix',
  74. 'sql-type'=>'decimal',
  75. 'input'=>'<input id="{{key}}" name="{{key}}" class="form-control" placeholder="" value="<?php echo ${{entity}}->{{key}}; ?>" type="text">'),
  76. 'boolean' => array(
  77. 'label'=>'Booléen',
  78. 'sql-type'=>'boolean',
  79. 'input'=>'<input title="" type="checkbox" name="<?php echo ${{entity}}->{{key}}; ?>" id="<?php echo ${{entity}}->{{key}}; ?>" data-class="" data-type="checkbox">'),
  80. 'mail' => array(
  81. 'label'=>'E-mail',
  82. 'sql-type'=>'string',
  83. 'input'=>'<input id="{{key}}" name="{{key}}" data-type="mail" pattern=".+@.+" class="form-control" placeholder="" value="<?php echo ${{entity}}->{{key}}; ?>" type="email">'),
  84. );
  85. return $types;
  86. }
  87. }
  88. ?>