/application/models/contacts/base/BaseContacts.class.php

https://gitlab.com/x33n/ProjectPier-Core · PHP · 260 lines · 106 code · 20 blank · 134 comment · 24 complexity · 25611db62a0e7c9361cb67f008d70ad1 MD5 · raw file

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