PageRenderTime 43ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/pkp/classes/controllers/grid/GridColumn.inc.php

https://github.com/lib-uoguelph-ca/ocs
PHP | 209 lines | 78 code | 27 blank | 104 comment | 4 complexity | 8a4f38a56fae53cc0e8155ac3b2ac64e MD5 | raw file
Possible License(s): GPL-2.0
  1. <?php
  2. /**
  3. * @file classes/controllers/grid/GridColumn.inc.php
  4. *
  5. * Copyright (c) 2000-2012 John Willinsky
  6. * Distributed under the GNU GPL v2. For full terms see the file docs/COPYING.
  7. *
  8. * @class GridColumn
  9. * @ingroup controllers_grid
  10. *
  11. * @brief Represents a column within a grid. It is used to configure the way
  12. * cells within a column are displayed (cell provider) and can also be used
  13. * to configure a editing strategy (not yet implemented). Contains all column-
  14. * specific configuration (e.g. column title).
  15. */
  16. // $Id$
  17. class GridColumn {
  18. /** @var string the column id */
  19. var $_id;
  20. /** @var string the column title i18n key */
  21. var $_title;
  22. /** @var string the column title (translated) */
  23. var $_titleLocalized;
  24. /**
  25. * @var array actions of the grid column, the first key represents
  26. * the position of the action in the controller
  27. */
  28. var $_actions;
  29. /**
  30. * @var array flags that can be set by the handler to trigger layout
  31. * options in the template.
  32. */
  33. var $_flags;
  34. /** @var string the controller template for the cells in this column */
  35. var $_template;
  36. /** @var GridCellProvider a cell provider for cells in this column */
  37. var $_cellProvider;
  38. /**
  39. * Constructor
  40. */
  41. function GridColumn($id = '', $title = null, $titleLocalized = null, $actions = array(),
  42. $template = 'controllers/grid/gridCell.tpl', $cellProvider = null, $flags = array()) {
  43. $this->_id = $id;
  44. $this->_title = $title;
  45. $this->_titleLocalized = $titleLocalized;
  46. $this->_actions = array(GRID_ACTION_POSITION_DEFAULT => &$actions);
  47. $this->_template = $template;
  48. $this->_cellProvider =& $cellProvider;
  49. $this->_flags = $flags;
  50. }
  51. //
  52. // Setters/Getters
  53. //
  54. /**
  55. * Get the column id
  56. * @return string
  57. */
  58. function getId() {
  59. return $this->_id;
  60. }
  61. /**
  62. * Set the column id
  63. * @param $id string
  64. */
  65. function setId($id) {
  66. $this->_id = $id;
  67. }
  68. /**
  69. * Get the column title
  70. * @return string
  71. */
  72. function getTitle() {
  73. return $this->_title;
  74. }
  75. /**
  76. * Set the column title (already translated)
  77. * @param $title string
  78. */
  79. function setTitle($title) {
  80. $this->_title = $title;
  81. }
  82. /**
  83. * Set the column title (already translated)
  84. * @param $title string
  85. */
  86. function setTitleTranslated($titleLocalized) {
  87. $this->_titleLocalized = $titleLocalized;
  88. }
  89. /**
  90. * Get the translated column title
  91. * @return string
  92. */
  93. function getLocalizedTitle() {
  94. if ( $this->_titleLocalized ) return $this->_titleLocalized;
  95. return __($this->_title);;
  96. }
  97. /**
  98. * Get all actions for a given position within the column
  99. * @param $position string the position of the actions
  100. * @return array the GridActions for the given position
  101. */
  102. function getActions($position = GRID_ACTION_POSITION_DEFAULT) {
  103. assert(isset($this->_actions[$position]));
  104. return $this->_actions[$position];
  105. }
  106. /**
  107. * Add an action
  108. * @param $position string the position of the action
  109. * @param $action mixed a single action
  110. */
  111. function addAction($action, $position = GRID_ACTION_POSITION_DEFAULT) {
  112. if (!isset($this->_actions[$position])) $this->_actions[$position] = array();
  113. $this->_actions[$position][] = $action;
  114. }
  115. /**
  116. * Get all layout flags
  117. * @return array
  118. */
  119. function getFlags() {
  120. return $this->_flags;
  121. }
  122. /**
  123. * Get a single layout flags
  124. * @param $flag string
  125. * @return mixed
  126. */
  127. function getFlag($flag) {
  128. assert(isset($this->flags[$flag]));
  129. return $this->_flags[$flag];
  130. }
  131. /**
  132. * Check whether a flag is set to true
  133. * @param $flag string
  134. * @return boolean
  135. */
  136. function hasFlag($flag) {
  137. if (!isset($this->_flags[$flag])) return false;
  138. return (boolean)$this->_flags[$flag];
  139. }
  140. /**
  141. * Add a flag
  142. * @param $flag string
  143. * @param $value mixed
  144. */
  145. function addFlag($flag, $value) {
  146. $this->_flags[$flag] = $value;
  147. }
  148. /**
  149. * get the column's cell template
  150. * @return string
  151. */
  152. function getTemplate() {
  153. return $this->_template;
  154. }
  155. /**
  156. * set the column's cell template
  157. * @param $template string
  158. */
  159. function setTemplate($template) {
  160. $this->_template = $template;
  161. }
  162. /**
  163. * Get the cell provider
  164. * @return GridCellProvider
  165. */
  166. function &getCellProvider() {
  167. if (is_null($this->_cellProvider)) {
  168. // provide a sensible default cell provider
  169. import('controllers.grid.ArrayGridCellProvider');
  170. $cellProvider =& new ArrayGridCellProvider();
  171. $this->setCellProvider($cellProvider);
  172. }
  173. return $this->_cellProvider;
  174. }
  175. /**
  176. * Set the cell provider
  177. * @param $cellProvider GridCellProvider
  178. */
  179. function setCellProvider(&$cellProvider) {
  180. $this->_cellProvider =& $cellProvider;
  181. }
  182. }