PageRenderTime 59ms CodeModel.GetById 29ms RepoModel.GetById 1ms app.codeStats 0ms

/app/models/ca_tour_stops.php

https://bitbucket.org/Sinfin/pawtucket
PHP | 386 lines | 234 code | 36 blank | 116 comment | 13 complexity | d1407e63094c8d58816d99c16e66e125 MD5 | raw file
Possible License(s): LGPL-3.0, GPL-3.0
  1. <?php
  2. /** ---------------------------------------------------------------------
  3. * app/models/ca_tour_stops.php : table access class for table ca_tour_stops
  4. * ----------------------------------------------------------------------
  5. * CollectiveAccess
  6. * Open-source collections management software
  7. * ----------------------------------------------------------------------
  8. *
  9. * Software by Whirl-i-Gig (http://www.whirl-i-gig.com)
  10. * Copyright 2011 Whirl-i-Gig
  11. *
  12. * For more information visit http://www.CollectiveAccess.org
  13. *
  14. * This program is free software; you may redistribute it and/or modify it under
  15. * the terms of the provided license as published by Whirl-i-Gig
  16. *
  17. * CollectiveAccess is distributed in the hope that it will be useful, but
  18. * WITHOUT ANY WARRANTIES whatsoever, including any implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  20. *
  21. * This source code is free and modifiable under the terms of
  22. * GNU General Public License. (http://www.gnu.org/copyleft/gpl.html). See
  23. * the "license.txt" file for details, or visit the CollectiveAccess web site at
  24. * http://www.CollectiveAccess.org
  25. *
  26. * @package CollectiveAccess
  27. * @subpackage models
  28. * @license http://www.gnu.org/copyleft/gpl.html GNU Public License version 3
  29. *
  30. * ----------------------------------------------------------------------
  31. */
  32. /**
  33. *
  34. */
  35. require_once(__CA_LIB_DIR__.'/ca/BundlableLabelableBaseModelWithAttributes.php');
  36. require_once(__CA_LIB_DIR__.'/ca/IHierarchy.php');
  37. require_once(__CA_MODELS_DIR__.'/ca_tours.php');
  38. require_once(__CA_MODELS_DIR__.'/ca_locales.php');
  39. BaseModel::$s_ca_models_definitions['ca_tour_stops'] = array(
  40. 'NAME_SINGULAR' => _t('tour stop'),
  41. 'NAME_PLURAL' => _t('tour stops'),
  42. 'FIELDS' => array(
  43. 'stop_id' => array(
  44. 'FIELD_TYPE' => FT_NUMBER, 'DISPLAY_TYPE' => DT_HIDDEN,
  45. 'IDENTITY' => true, 'DISPLAY_WIDTH' => 10, 'DISPLAY_HEIGHT' => 1,
  46. 'IS_NULL' => false,
  47. 'DEFAULT' => '',
  48. 'LABEL' => 'Stop id', 'DESCRIPTION' => 'Identifier for stop'
  49. ),
  50. 'parent_id' => array(
  51. 'FIELD_TYPE' => FT_NUMBER, 'DISPLAY_TYPE' => DT_OMIT,
  52. 'DISPLAY_WIDTH' => 10, 'DISPLAY_HEIGHT' => 1,
  53. 'IS_NULL' => true,
  54. 'DEFAULT' => '',
  55. 'LABEL' => _t('Parent'), 'DESCRIPTION' => _t('Parent list item for this item')
  56. ),
  57. 'tour_id' => array(
  58. 'FIELD_TYPE' => FT_NUMBER, 'DISPLAY_TYPE' => DT_HIDDEN,
  59. 'DISPLAY_WIDTH' => 10, 'DISPLAY_HEIGHT' => 1,
  60. 'IS_NULL' => false,
  61. 'DEFAULT' => '',
  62. 'LABEL' => _t('Tour'), 'DESCRIPTION' => _t('Tour stop is part of')
  63. ),
  64. 'type_id' => array(
  65. 'FIELD_TYPE' => FT_NUMBER, 'DISPLAY_TYPE' => DT_SELECT,
  66. 'DISPLAY_WIDTH' => 40, 'DISPLAY_HEIGHT' => 1,
  67. 'DISPLAY_FIELD' => array('ca_list_items.item_value'),
  68. 'DISPLAY_ORDERBY' => array('ca_list_items.item_value'),
  69. 'IS_NULL' => true,
  70. 'LIST_CODE' => 'tour_stop_types',
  71. 'DEFAULT' => '',
  72. 'LABEL' => _t('Type'), 'DESCRIPTION' => _t('Indicates the type of the stop.')
  73. ),
  74. 'idno' => array(
  75. 'FIELD_TYPE' => FT_TEXT, 'DISPLAY_TYPE' => DT_FIELD,
  76. 'DISPLAY_WIDTH' => 70, 'DISPLAY_HEIGHT' => 1,
  77. 'IS_NULL' => false,
  78. 'DEFAULT' => '',
  79. 'LABEL' => _t('Id number'), 'DESCRIPTION' => _t('Unique identifier for this tour stop'),
  80. 'BOUNDS_LENGTH' => array(0,255)
  81. ),
  82. 'idno_sort' => array(
  83. 'FIELD_TYPE' => FT_TEXT, 'DISPLAY_TYPE' => DT_OMIT,
  84. 'DISPLAY_WIDTH' => 70, 'DISPLAY_HEIGHT' => 1,
  85. 'IS_NULL' => false,
  86. 'DEFAULT' => '',
  87. 'LABEL' => _t('Id number sort'), 'DESCRIPTION' => _t('Sortable value for id number'),
  88. 'BOUNDS_LENGTH' => array(0,255)
  89. ),
  90. 'color' => array(
  91. 'FIELD_TYPE' => FT_TEXT, 'DISPLAY_TYPE' => DT_COLORPICKER,
  92. 'DISPLAY_WIDTH' => 10, 'DISPLAY_HEIGHT' => 1,
  93. 'IS_NULL' => false,
  94. 'DEFAULT' => '',
  95. 'LABEL' => _t('Color'), 'DESCRIPTION' => _t('Color to display stop in')
  96. ),
  97. 'icon' => array(
  98. 'FIELD_TYPE' => FT_MEDIA, 'DISPLAY_TYPE' => DT_FIELD,
  99. 'DISPLAY_WIDTH' => 10, 'DISPLAY_HEIGHT' => 1,
  100. 'IS_NULL' => false,
  101. 'DEFAULT' => '',
  102. "MEDIA_PROCESSING_SETTING" => 'ca_icons',
  103. 'LABEL' => _t('Icon'), 'DESCRIPTION' => _t('Optional icon to use with stop')
  104. ),
  105. 'rank' => array(
  106. 'FIELD_TYPE' => FT_NUMBER, 'DISPLAY_TYPE' => DT_FIELD,
  107. 'DISPLAY_WIDTH' => 10, 'DISPLAY_HEIGHT' => 1,
  108. 'IS_NULL' => false,
  109. 'DEFAULT' => '',
  110. 'LABEL' => _t('Sort order'), 'DESCRIPTION' => _t('Sort order'),
  111. ),
  112. 'hier_left' => array(
  113. 'FIELD_TYPE' => FT_NUMBER, 'DISPLAY_TYPE' => DT_OMIT,
  114. 'DISPLAY_WIDTH' => 10, 'DISPLAY_HEIGHT' => 1,
  115. 'IS_NULL' => false,
  116. 'DEFAULT' => '',
  117. 'LABEL' => 'Hierarchical index - left bound', 'DESCRIPTION' => 'Left-side boundary for nested set-style hierarchical indexing; used to accelerate search and retrieval of hierarchical record sets.'
  118. ),
  119. 'hier_right' => array(
  120. 'FIELD_TYPE' => FT_NUMBER, 'DISPLAY_TYPE' => DT_OMIT,
  121. 'DISPLAY_WIDTH' => 10, 'DISPLAY_HEIGHT' => 1,
  122. 'IS_NULL' => false,
  123. 'DEFAULT' => '',
  124. 'LABEL' => 'Hierarchical index - right bound', 'DESCRIPTION' => 'Right-side boundary for nested set-style hierarchical indexing; used to accelerate search and retrieval of hierarchical record sets.'
  125. ),
  126. 'hier_stop_id' => array(
  127. 'FIELD_TYPE' => FT_NUMBER, 'DISPLAY_TYPE' => DT_OMIT,
  128. 'DISPLAY_WIDTH' => 10, 'DISPLAY_HEIGHT' => 1,
  129. 'IS_NULL' => false,
  130. 'DEFAULT' => '',
  131. 'LABEL' => 'Stop hierarchy', 'DESCRIPTION' => 'Identifier of stop that is root of the stop hierarchy.'
  132. ),
  133. 'access' => array(
  134. 'FIELD_TYPE' => FT_NUMBER, 'DISPLAY_TYPE' => DT_SELECT,
  135. 'DISPLAY_WIDTH' => 40, 'DISPLAY_HEIGHT' => 1,
  136. 'IS_NULL' => false,
  137. 'DEFAULT' => 0,
  138. 'BOUNDS_CHOICE_LIST' => array(
  139. _t('Not accessible to public') => 0,
  140. _t('Accessible to public') => 1
  141. ),
  142. 'LIST' => 'access_statuses',
  143. 'LABEL' => _t('Access'), 'DESCRIPTION' => _t('Indicates if the list item is accessible to the public or not. ')
  144. ),
  145. 'status' => array(
  146. 'FIELD_TYPE' => FT_NUMBER, 'DISPLAY_TYPE' => DT_SELECT,
  147. 'DISPLAY_WIDTH' => 40, 'DISPLAY_HEIGHT' => 1,
  148. 'IS_NULL' => false,
  149. 'DEFAULT' => 0,
  150. 'BOUNDS_CHOICE_LIST' => array(
  151. _t('Newly created') => 0,
  152. _t('Editing in progress') => 1,
  153. _t('Editing complete - pending review') => 2,
  154. _t('Review in progress') => 3,
  155. _t('Completed') => 4
  156. ),
  157. 'LIST' => 'workflow_statuses',
  158. 'LABEL' => _t('Status'), 'DESCRIPTION' => _t('Indicates the current state of the list item.')
  159. ),
  160. 'deleted' => array(
  161. 'FIELD_TYPE' => FT_BIT, 'DISPLAY_TYPE' => DT_OMIT,
  162. 'DISPLAY_WIDTH' => 10, 'DISPLAY_HEIGHT' => 1,
  163. 'IS_NULL' => false,
  164. 'DEFAULT' => 0,
  165. 'LABEL' => _t('Is deleted?'), 'DESCRIPTION' => _t('Indicates if list item is deleted or not.')
  166. )
  167. )
  168. );
  169. class ca_tour_stops extends BundlableLabelableBaseModelWithAttributes {
  170. # ---------------------------------
  171. # --- Object attribute properties
  172. # ---------------------------------
  173. # Describe structure of content object's properties - eg. database fields and their
  174. # associated types, what modes are supported, et al.
  175. #
  176. # ------------------------------------------------------
  177. # --- Basic object parameters
  178. # ------------------------------------------------------
  179. # what table does this class represent?
  180. protected $TABLE = 'ca_tour_stops';
  181. # what is the primary key of the table?
  182. protected $PRIMARY_KEY = 'stop_id';
  183. # ------------------------------------------------------
  184. # --- Properties used by standard editing scripts
  185. #
  186. # These class properties allow generic scripts to properly display
  187. # records from the table represented by this class
  188. #
  189. # ------------------------------------------------------
  190. # Array of fields to display in a listing of records from this table
  191. protected $LIST_FIELDS = array('idno');
  192. # When the list of "list fields" above contains more than one field,
  193. # the LIST_DELIMITER text is displayed between fields as a delimiter.
  194. # This is typically a comma or space, but can be any string you like
  195. protected $LIST_DELIMITER = ' ';
  196. # What you'd call a single record from this table (eg. a "person")
  197. protected $NAME_SINGULAR;
  198. # What you'd call more than one record from this table (eg. "people")
  199. protected $NAME_PLURAL;
  200. # List of fields to sort listing of records by; you can use
  201. # SQL 'ASC' and 'DESC' here if you like.
  202. protected $ORDER_BY = array('idno');
  203. # Maximum number of record to display per page in a listing
  204. protected $MAX_RECORDS_PER_PAGE = 20;
  205. # How do you want to page through records in a listing: by number pages ordered
  206. # according to your setting above? Or alphabetically by the letters of the first
  207. # LIST_FIELD?
  208. protected $PAGE_SCHEME = 'alpha'; # alpha [alphabetical] or num [numbered pages; default]
  209. # If you want to order records arbitrarily, add a numeric field to the table and place
  210. # its name here. The generic list scripts can then use it to order table records.
  211. protected $RANK = 'rank';
  212. # ------------------------------------------------------
  213. # Hierarchical table properties
  214. # ------------------------------------------------------
  215. protected $HIERARCHY_TYPE = __CA_HIER_TYPE_ADHOC_MONO__;
  216. protected $HIERARCHY_LEFT_INDEX_FLD = 'hier_left';
  217. protected $HIERARCHY_RIGHT_INDEX_FLD = 'hier_right';
  218. protected $HIERARCHY_PARENT_ID_FLD = 'parent_id';
  219. protected $HIERARCHY_DEFINITION_TABLE = 'ca_tour_stops';
  220. protected $HIERARCHY_ID_FLD = 'hier_stop_id';
  221. protected $HIERARCHY_POLY_TABLE = null;
  222. # ------------------------------------------------------
  223. # Change logging
  224. # ------------------------------------------------------
  225. protected $UNIT_ID_FIELD = null;
  226. protected $LOG_CHANGES_TO_SELF = true;
  227. protected $LOG_CHANGES_USING_AS_SUBJECT = array(
  228. "FOREIGN_KEYS" => array(
  229. 'tour_id'
  230. ),
  231. "RELATED_TABLES" => array(
  232. )
  233. );
  234. # ------------------------------------------------------
  235. # Attributes
  236. # ------------------------------------------------------
  237. protected $ATTRIBUTE_TYPE_ID_FLD = 'type_id'; // name of type field for this table - attributes system uses this to determine via ca_metadata_type_restrictions which attributes are applicable to rows of the given type
  238. protected $ATTRIBUTE_TYPE_LIST_CODE = 'tour_stop_types'; // list code (ca_lists.list_code) of list defining types for this table
  239. # ------------------------------------------------------
  240. # Labels
  241. # ------------------------------------------------------
  242. protected $LABEL_TABLE_NAME = 'ca_tour_stop_labels';
  243. # ------------------------------------------------------
  244. # Self-relations
  245. # ------------------------------------------------------
  246. protected $SELF_RELATION_TABLE_NAME = 'ca_tour_stops_x_tour_stops';
  247. # ------------------------------------------------------
  248. # ID numbering
  249. # ------------------------------------------------------
  250. protected $ID_NUMBERING_ID_FIELD = 'idno'; // name of field containing user-defined identifier
  251. protected $ID_NUMBERING_SORT_FIELD = 'idno_sort'; // name of field containing version of identifier for sorting (is normalized with padding to sort numbers properly)
  252. protected $ID_NUMBERING_CONTEXT_FIELD = 'tour_id'; // name of field to use value of for "context" when checking for duplicate identifier values; if not set identifer is assumed to be global in scope; if set identifer is checked for uniqueness (if required) within the value of this field
  253. # ------------------------------------------------------
  254. # Search
  255. # ------------------------------------------------------
  256. protected $SEARCH_CLASSNAME = 'TourStopSearch';
  257. protected $SEARCH_RESULT_CLASSNAME = 'TourStopSearchResult';
  258. # ------------------------------------------------------
  259. # $FIELDS contains information about each field in the table. The order in which the fields
  260. # are listed here is the order in which they will be returned using getFields()
  261. protected $FIELDS;
  262. # ------------------------------------------------------
  263. # --- Constructor
  264. #
  265. # This is a function called when a new instance of this object is created. This
  266. # standard constructor supports three calling modes:
  267. #
  268. # 1. If called without parameters, simply creates a new, empty objects object
  269. # 2. If called with a single, valid primary key value, creates a new objects object and loads
  270. # the record identified by the primary key value
  271. #
  272. # ------------------------------------------------------
  273. public function __construct($pn_id=null) {
  274. parent::__construct($pn_id); # call superclass constructor
  275. }
  276. # ------------------------------------------------------
  277. protected function initLabelDefinitions() {
  278. parent::initLabelDefinitions();
  279. $this->BUNDLES['ca_objects'] = array('type' => 'related_table', 'repeating' => true, 'label' => _t('Related objects'));
  280. $this->BUNDLES['ca_entities'] = array('type' => 'related_table', 'repeating' => true, 'label' => _t('Related entities'));
  281. $this->BUNDLES['ca_places'] = array('type' => 'related_table', 'repeating' => true, 'label' => _t('Related places'));
  282. $this->BUNDLES['ca_occurrences'] = array('type' => 'related_table', 'repeating' => true, 'label' => _t('Related occurrences'));
  283. $this->BUNDLES['ca_collections'] = array('type' => 'related_table', 'repeating' => true, 'label' => _t('Related collections'));
  284. $this->BUNDLES['ca_tour_stops'] = array('type' => 'related_table', 'repeating' => true, 'label' => _t('Related tour stops'));
  285. $this->BUNDLES['ca_list_items'] = array('type' => 'related_table', 'repeating' => true, 'label' => _t('Related vocabulary terms'));
  286. $this->BUNDLES['hierarchy_navigation'] = array('type' => 'special', 'repeating' => false, 'label' => _t('Hierarchy navigation'));
  287. $this->BUNDLES['hierarchy_location'] = array('type' => 'special', 'repeating' => false, 'label' => _t('Location in hierarchy'));
  288. }
  289. # ------------------------------------------------------
  290. /**
  291. * Return array containing information about all hierarchies, including their root_id's
  292. * For non-adhoc hierarchies such as places, this call returns the contents of the place_hierarchies list
  293. * with some extra information such as the # of top-level items in each hierarchy.
  294. *
  295. * For an ad-hoc hierarchy like that of a tour stop, there is only ever one hierarchy to display - that of the current stop.
  296. * So for adhoc hierarchies we just return a single entry corresponding to the root of the current tour stop hierarchy
  297. */
  298. public function getHierarchyList($pb_dummy=false) {
  299. $vn_pk = $this->getPrimaryKey();
  300. if (!$vn_pk) { return null; } // have to load a row first
  301. $vs_label = $this->getLabelForDisplay(false);
  302. $vs_hier_fld = $this->getProperty('HIERARCHY_ID_FLD');
  303. $vs_parent_fld = $this->getProperty('PARENT_ID_FLD');
  304. $vn_hier_id = $this->get($vs_hier_fld);
  305. if ($this->get($vs_parent_fld)) {
  306. // currently loaded row is not the root so get the root
  307. $va_ancestors = $this->getHierarchyAncestors();
  308. if (!is_array($va_ancestors) || sizeof($va_ancestors) == 0) { return null; }
  309. $t_stop = new ca_tour_stops($va_ancestors[0]);
  310. } else {
  311. $t_stop =& $this;
  312. }
  313. $va_children = $t_stop->getHierarchyChildren(null, array('idsOnly' => true));
  314. $va_stop_hierarchy_root = array(
  315. $t_stop->get($vs_hier_fld) => array(
  316. 'stop_id' => $vn_pk,
  317. 'name' => $vs_label,
  318. 'hierarchy_id' => $vn_hier_id,
  319. 'children' => sizeof($va_children)
  320. ),
  321. 'stop_id' => $vn_pk,
  322. 'name' => $vs_label,
  323. 'hierarchy_id' => $vn_hier_id,
  324. 'children' => sizeof($va_children)
  325. );
  326. return $va_stop_hierarchy_root;
  327. }
  328. # ------------------------------------------------------
  329. /**
  330. * Returns name of hierarchy for currently loaded row or, if specified, row identified by optional $pn_id parameter
  331. */
  332. public function getHierarchyName($pn_id=null) {
  333. if (!$pn_id) { $pn_id = $this->getPrimaryKey(); }
  334. $va_ancestors = $this->getHierarchyAncestors($pn_id, array('idsOnly' => true));
  335. if (is_array($va_ancestors) && sizeof($va_ancestors)) {
  336. $vn_parent_id = array_pop($va_ancestors);
  337. $t_stop = new ca_tour_stops($vn_parent_id);
  338. return $t_stop->getLabelForDisplay(false);
  339. } else {
  340. if ($pn_id == $this->getPrimaryKey()) {
  341. return $this->getLabelForDisplay(false);
  342. } else {
  343. $t_stop = new ca_tour_stops($pn_id);
  344. return $t_stop->getLabelForDisplay(false);
  345. }
  346. }
  347. }
  348. # ------------------------------------------------------
  349. }
  350. ?>