/application/plugins/reminders/models/base/BaseReminders.class.php

https://github.com/dbernar1/Project-Pier · PHP · 231 lines · 80 code · 18 blank · 133 comment · 24 complexity · b68a02afa10b2fdebe58d5f736ffa48d MD5 · raw file

  1. <?php
  2. abstract class BaseReminders extends DataManager {
  3. /**
  4. * Column name => Column type map
  5. *
  6. * @var array
  7. * @static
  8. */
  9. static private $columns = array('user_id' => DATA_TYPE_INTEGER, 'reminders_enabled' => DATA_TYPE_BOOLEAN, 'summarized_by' => DATA_TYPE_STRING, 'days_in_future' => DATA_TYPE_INTEGER, 'include_everyone' => DATA_TYPE_BOOLEAN, 'reminder_days' => DATA_TYPE_STRING, 'reports_enabled' => DATA_TYPE_BOOLEAN, 'reports_summarized_by' => DATA_TYPE_BOOLEAN, 'reports_include' => DATA_TYPE_BOOLEAN, 'reports_activity' => DATA_TYPE_BOOLEAN, 'report_day' => DATA_TYPE_STRING);
  10. // `user_id` int(10) unsigned NOT NULL default '0',
  11. // `reminders_enabled` boolean,
  12. // `summarize_by` ENUM('all', 'project', 'milestone','task') NOT NULL,
  13. // `days_in_future` int unsigned not null default '0',
  14. // `include_everyone` boolean,
  15. // `reminder_days` SET('Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'),
  16. /**
  17. * Construct
  18. *
  19. * @return Reminder
  20. */
  21. function __construct() {
  22. parent::__construct('Reminder', 'reminders', true);
  23. } // __construct
  24. // -------------------------------------------------------
  25. // Description methods
  26. // -------------------------------------------------------
  27. /**
  28. * Return array of object columns
  29. *
  30. * @access public
  31. * @param void
  32. * @return array
  33. */
  34. function getColumns() {
  35. return array_keys(self::$columns);
  36. } // getColumns
  37. /**
  38. * Return column type
  39. *
  40. * @access public
  41. * @param string $column_name
  42. * @return string
  43. */
  44. function getColumnType($column_name) {
  45. if (isset(self::$columns[$column_name])) {
  46. return self::$columns[$column_name];
  47. } else {
  48. return DATA_TYPE_STRING;
  49. } // if
  50. } // getColumnType
  51. /**
  52. * Return array of PK columns. If only one column is PK returns its name as string
  53. *
  54. * @access public
  55. * @param void
  56. * @return array or string
  57. */
  58. function getPkColumns() {
  59. return 'user_id';
  60. } // getPkColumns
  61. /**
  62. * Return name of first auto_incremenent column if it exists
  63. *
  64. * @access public
  65. * @param void
  66. * @return string
  67. */
  68. function getAutoIncrementColumn() {
  69. return null;
  70. } // getAutoIncrementColumn
  71. // -------------------------------------------------------
  72. // Finders
  73. // -------------------------------------------------------
  74. /**
  75. * Do a SELECT query over database with specified arguments
  76. *
  77. * @access public
  78. * @param array $arguments Array of query arguments. Fields:
  79. *
  80. * - one - select first row
  81. * - conditions - additional conditions
  82. * - order - order by string
  83. * - offset - limit offset, valid only if limit is present
  84. * - limit
  85. *
  86. * @return one or Reminders objects
  87. * @throws DBQueryError
  88. */
  89. function find($arguments = null) {
  90. if (isset($this) && instance_of($this, 'Reminders')) {
  91. return parent::find($arguments);
  92. } else {
  93. return Reminders::instance()->find($arguments);
  94. } // if
  95. } // find
  96. /**
  97. * Find all records
  98. *
  99. * @access public
  100. * @param array $arguments
  101. * @return one or Reminders objects
  102. */
  103. function findAll($arguments = null) {
  104. if (isset($this) && instance_of($this, 'Reminders')) {
  105. return parent::findAll($arguments);
  106. } else {
  107. return Reminders::instance()->findAll($arguments);
  108. //$instance =& Reminders::instance();
  109. //return $instance->findAll($arguments);
  110. } // if
  111. } // findAll
  112. /**
  113. * Find one specific record
  114. *
  115. * @access public
  116. * @param array $arguments
  117. * @return ProjectForm
  118. */
  119. function findOne($arguments = null) {
  120. if (isset($this) && instance_of($this, 'Reminders')) {
  121. return parent::findOne($arguments);
  122. } else {
  123. return Reminders::instance()->findOne($arguments);
  124. //$instance =& Reminders::instance();
  125. //return $instance->findOne($arguments);
  126. } // if
  127. } // findOne
  128. /**
  129. * Return object by its PK value
  130. *
  131. * @access public
  132. * @param mixed $id
  133. * @param boolean $force_reload If true cache will be skipped and data will be loaded from database
  134. * @return ProjectForm
  135. */
  136. function findById($id, $force_reload = false) {
  137. if (isset($this) && instance_of($this, 'Reminders')) {
  138. return parent::findById($id, $force_reload);
  139. } else {
  140. return Reminders::instance()->findById($id, $force_reload);
  141. //$instance =& Reminders::instance();
  142. //return $instance->findById($id, $force_reload);
  143. } // if
  144. } // findById
  145. /**
  146. * Return number of rows in this table
  147. *
  148. * @access public
  149. * @param string $conditions Query conditions
  150. * @return integer
  151. */
  152. function count($condition = null) {
  153. if (isset($this) && instance_of($this, 'Reminders')) {
  154. return parent::count($condition);
  155. } else {
  156. return Reminders::instance()->count($condition);
  157. //$instance =& Reminders::instance();
  158. //return $instance->count($condition);
  159. } // if
  160. } // count
  161. /**
  162. * Delete rows that match specific conditions. If $conditions is NULL all rows from table will be deleted
  163. *
  164. * @access public
  165. * @param string $conditions Query conditions
  166. * @return boolean
  167. */
  168. function delete($condition = null) {
  169. if (isset($this) && instance_of($this, 'Reminders')) {
  170. return parent::delete($condition);
  171. } else {
  172. return Reminders::instance()->delete($condition);
  173. //$instance =& Reminders::instance();
  174. //return $instance->delete($condition);
  175. } // if
  176. } // delete
  177. /**
  178. * This function will return paginated result. Result is an array where first element is
  179. * array of returned object and second populated pagination object that can be used for
  180. * obtaining and rendering pagination data using various helpers.
  181. *
  182. * Items and pagination array vars are indexed with 0 for items and 1 for pagination
  183. * because you can't use associative indexing with list() construct
  184. *
  185. * @access public
  186. * @param array $arguments Query argumens (@see find()) Limit and offset are ignored!
  187. * @param integer $items_per_page Number of items per page
  188. * @param integer $current_page Current page number
  189. * @return array
  190. */
  191. function paginate($arguments = null, $items_per_page = 10, $current_page = 1) {
  192. if (isset($this) && instance_of($this, 'Reminders')) {
  193. return parent::paginate($arguments, $items_per_page, $current_page);
  194. } else {
  195. return Reminders::instance()->paginate($arguments, $items_per_page, $current_page);
  196. //$instance =& Reminders::instance();
  197. //return $instance->paginate($arguments, $items_per_page, $current_page);
  198. } // if
  199. } // paginate
  200. /**
  201. * Return manager instance
  202. *
  203. * @return Reminders
  204. */
  205. function instance() {
  206. static $instance;
  207. if (!instance_of($instance, 'Reminders')) {
  208. $instance = new Reminders();
  209. } // if
  210. return $instance;
  211. } // instance
  212. } // Reminders
  213. ?>