PageRenderTime 50ms CodeModel.GetById 25ms RepoModel.GetById 1ms app.codeStats 0ms

/fuel/packages/oil/views/admin/orm/model.php

https://bitbucket.org/codeyash/bootstrap
PHP | 57 lines | 50 code | 7 blank | 0 comment | 4 complexity | f7e5ec52bb2d6b200e686496d7cf7441 MD5 | raw file
Possible License(s): MIT, Apache-2.0
  1. <?php echo '<?php' ?>
  2. class Model_<?php echo $model_name; ?> extends \Orm\Model
  3. {
  4. protected static $_properties = array(
  5. 'id',
  6. <?php foreach ($fields as $field): ?>
  7. '<?php echo $field['name']; ?>',
  8. <?php endforeach; ?>
  9. <?php if ($include_timestamps): ?>
  10. 'created_at',
  11. 'updated_at',
  12. <?php endif; ?>
  13. );
  14. <?php if ($include_timestamps): ?>
  15. protected static $_observers = array(
  16. 'Orm\Observer_CreatedAt' => array(
  17. 'events' => array('before_insert'),
  18. 'mysql_timestamp' => false,
  19. ),
  20. 'Orm\Observer_UpdatedAt' => array(
  21. 'events' => array('before_save'),
  22. 'mysql_timestamp' => false,
  23. ),
  24. );
  25. <?php endif; ?>
  26. public static function validate($factory)
  27. {
  28. $val = Validation::forge($factory);
  29. <?php foreach ($fields as $field): ?>
  30. <?php
  31. $rules = array('required');
  32. if (in_array($field['type'], array('varchar', 'string', 'char')))
  33. {
  34. if ($field['name'] === 'email')
  35. {
  36. $rules[] = 'valid_email';
  37. }
  38. $rules[] = ! is_null($field['constraint']) ? "max_length[{$field['constraint']}]" : 'max_length[255]';
  39. }
  40. elseif (in_array($field['type'], array('int', 'intenger')))
  41. {
  42. $rules[] = 'valid_string[numeric]';
  43. }
  44. $rules = implode('|', $rules);
  45. ?>
  46. $val->add_field('<?php echo $field['name']; ?>', '<?php echo ucwords(str_replace('_', ' ', $field['name'])); ?>', '<?php echo $rules; ?>');
  47. <?php endforeach; ?>
  48. return $val;
  49. }
  50. }