model.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <?php
  2. /**
  3. *
  4. * @license see /license.txt
  5. * @author Laurent Opprecht <laurent@opprecht.info>, Nicolas Rod for the University of Geneva
  6. */
  7. echo '<?php';
  8. ?>
  9. namespace Shibboleth;
  10. /**
  11. * This file is autogenerated. Do not modifiy it.
  12. */
  13. /**
  14. *
  15. * Model for table <?php echo $table_name ?>
  16. *
  17. * @copyright (c) 2012 University of Geneva
  18. * @license GNU General Public License - http://www.gnu.org/copyleft/gpl.html
  19. * @author Laurent Opprecht <laurent@opprecht.info>
  20. */
  21. class <?php echo $prefix . $class_name ?>
  22. {
  23. /**
  24. * Store for <?php echo $class_name ?> objects. Interact with the database.
  25. *
  26. * @return <?php echo $class_name ?>Store
  27. */
  28. public static function store()
  29. {
  30. static $result = false;
  31. if (empty($result))
  32. {
  33. $result = new <?php echo $class_name ?>Store();
  34. }
  35. return $result;
  36. }
  37. /**
  38. *
  39. * @return <?php echo $class_name ?>
  40. */
  41. public static function create($data = null)
  42. {
  43. return self::store()->create_object($data);
  44. }
  45. <?php foreach($fields as $field){?>
  46. public $<?php echo $field->name; ?> = <?php echo $field->def ? $field->def : 'null'; ?>;
  47. <?php }?>
  48. /**
  49. *
  50. * @return bool
  51. */
  52. public function save()
  53. {
  54. return self::store()->save($this);
  55. }
  56. }
  57. /**
  58. * Store for <?php echo $class_name ?> objects. Interact with the database.
  59. *
  60. * @copyright (c) 2012 University of Geneva
  61. * @license GNU General Public License - http://www.gnu.org/copyleft/gpl.html
  62. * @author Laurent Opprecht <laurent@opprecht.info>
  63. */
  64. class <?php echo $prefix . $class_name ?>Store extends Store
  65. {
  66. /**
  67. *
  68. * @return <?php echo $class_name ?>Store
  69. */
  70. public static function instance()
  71. {
  72. static $result = false;
  73. if (empty($result))
  74. {
  75. $result = new self();
  76. }
  77. return $result;
  78. }
  79. public function __construct()
  80. {
  81. parent::__construct('<?php echo $table_name;?>', '<?php echo $class_name;?>', '<?php echo $id_name;?>');
  82. }
  83. /**
  84. *
  85. * @return <?php echo $class_name ?>
  86. */
  87. public function get($w)
  88. {
  89. $args = func_get_args();
  90. $f = array('parent', 'get');
  91. return call_user_func_array($f, $args);
  92. }
  93. /**
  94. *
  95. * @return <?php echo $class_name ?>
  96. */
  97. public function create_object($data)
  98. {
  99. return parent::create_object($data);
  100. }
  101. <?php foreach($keys as $key){?>
  102. /**
  103. *
  104. * @return <?php echo $class_name ?>
  105. */
  106. public function get_by_<?php echo $key ?>($value)
  107. {
  108. return $this->get(array('<?php echo $key; ?>' => $value));
  109. }
  110. /**
  111. *
  112. * @return bool
  113. */
  114. public function <?php echo $key ?>_exists($value)
  115. {
  116. return $this->exist(array('<?php echo $key; ?>' => $value));
  117. }
  118. /**
  119. *
  120. * @return bool
  121. */
  122. public function delete_by_<?php echo $key ?>($value)
  123. {
  124. return $this->delete(array('<?php echo $key; ?>' => $value));
  125. }
  126. <?php }?>
  127. }