PageRenderTime 50ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

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

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