Template.class.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. );
  81. return $types;
  82. }
  83. }
  84. ?>