PageRenderTime 41ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://github.com/lib-uoguelph-ca/ocs
PHP | 156 lines | 48 code | 21 blank | 87 comment | 3 complexity | b659cc93c8a6af355c85af8a6041cf0d MD5 | raw file
Possible License(s): GPL-2.0
  1. <?php
  2. /**
  3. * @file classes/controllers/grid/GridRow.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 GridRow
  9. * @ingroup controllers_grid
  10. *
  11. * @brief Class defining basic operations for handling HTML gridRows.
  12. *
  13. * NB: If you want row-level refresh then you must override the getData() method
  14. * so that it fetches data (e.g. from the database) when called. The data to be
  15. * fetched can be determined from the id (=row id) which is always set.
  16. */
  17. class GridRow {
  18. /**
  19. * @var string identifier of the row instance - must be unique
  20. * among all row instances within a grid.
  21. */
  22. var $_id;
  23. /** @var the grid this row belongs to */
  24. var $_gridId;
  25. /** @var mixed the row's data source */
  26. var $_data;
  27. /**
  28. * @var array row actions, the first key represents
  29. * the position of the action in the row template,
  30. * the second key represents the action id.
  31. */
  32. var $_actions = array(GRID_ACTION_POSITION_DEFAULT => array());
  33. /** @var string the row template */
  34. var $_template;
  35. /**
  36. * Constructor.
  37. */
  38. function GridRow() {
  39. }
  40. //
  41. // Getters/Setters
  42. //
  43. /**
  44. * Set the grid id
  45. * @param $id string
  46. */
  47. function setId($id) {
  48. $this->_id = $id;
  49. }
  50. /**
  51. * Get the grid id
  52. * @return string
  53. */
  54. function getId() {
  55. return $this->_id;
  56. }
  57. /**
  58. * Set the grid id
  59. * @param $gridId string
  60. */
  61. function setGridId($gridId) {
  62. $this->_gridId = $gridId;
  63. }
  64. /**
  65. * Get the grid id
  66. * @return string
  67. */
  68. function getGridId() {
  69. return $this->_gridId;
  70. }
  71. /**
  72. * Set the data element(s) for this controller
  73. * @param $data mixed
  74. */
  75. function setData(&$data) {
  76. $this->_data =& $data;
  77. }
  78. /**
  79. * Get the data element(s) for this controller
  80. * @return mixed
  81. */
  82. function &getData() {
  83. return $this->_data;
  84. }
  85. /**
  86. * Get all actions for a given position within the controller
  87. * @param $position string the position of the actions
  88. * @return array the GridActions for the given position
  89. */
  90. function getActions($position = GRID_ACTION_POSITION_DEFAULT) {
  91. if(!isset($this->_actions[$position])) return array();
  92. return $this->_actions[$position];
  93. }
  94. /**
  95. * Add an action
  96. * @param $position string the position of the action
  97. * @param $action mixed a single action
  98. */
  99. function addAction($action, $position = GRID_ACTION_POSITION_DEFAULT) {
  100. if (!isset($this->_actions[$position])) $this->_actions[$position] = array();
  101. $this->_actions[$position][$action->getId()] = $action;
  102. }
  103. /**
  104. * Get the row template - override base
  105. * implementation to provide a sensible default.
  106. * @return string
  107. */
  108. function getTemplate() {
  109. if (is_null($this->_template)) {
  110. $this->setTemplate('controllers/grid/gridRow.tpl');
  111. }
  112. return $this->_template;
  113. }
  114. /**
  115. * Set the controller template
  116. * @param $template string
  117. */
  118. function setTemplate($template) {
  119. $this->_template = $template;
  120. }
  121. //
  122. // Public methods
  123. //
  124. /**
  125. * Initialize a row instance.
  126. *
  127. * Subclasses can override this method.
  128. *
  129. * @param $request Request
  130. */
  131. function initialize($request) {
  132. // Default implementation does nothing
  133. }
  134. }
  135. ?>