Open Journal Systems  3.3.0
PagingFeature.inc.php
1 <?php
2 
17 import('lib.pkp.classes.controllers.grid.feature.GeneralPagingFeature');
18 
20 
26  function __construct($id = 'paging') {
27  parent::__construct($id);
28  }
29 
30 
31  //
32  // Extended methods from GridFeature.
33  //
37  function getJSClass() {
38  return '$.pkp.classes.features.PagingFeature';
39  }
40 
41 
45  function fetchUIElements($request, $grid) {
46  $options = $this->getOptions();
47  $templateMgr = TemplateManager::getManager($request);
48  $templateMgr->assign(array(
49  'iterator' => $this->getItemIterator(),
50  'currentItemsPerPage' => $options['currentItemsPerPage'],
51  'grid' => $grid,
52  ));
53  return array('pagingMarkup' => $templateMgr->fetch('controllers/grid/feature/gridPaging.tpl'));
54  }
55 
56 
57  //
58  // Hooks implementation.
59  //
74  function fetchRow($args) {
75  $request = $args['request'];
76  $grid = $args['grid'];
77  $row = $args['row'];
78  $jsonMessage = $args['jsonMessage'];
79  $pagingAttributes = array();
80 
81  if (is_null($row)) {
82  $gridData = $grid->getGridDataElements($request);
83  $iterator = $this->getItemIterator();
84  $rangeInfo = $grid->getGridRangeInfo($request, $grid->getId());
85 
86  // Check if row was really deleted or if the requested row is
87  // just not inside the requested range.
88  $deleted = true;
89  $topLimitRowId = (int) $request->getUserVar('topLimitRowId');
90  $bottomLimitRowId = (int) $request->getUserVar('bottomLimitRowId');
91 
92  reset($gridData);
93  $firstDataId = key($gridData);
94  next($gridData);
95  $secondDataId = key($gridData);
96  end($gridData);
97  $lastDataId = key($gridData);
98 
99  if ($secondDataId == $topLimitRowId) {
100  $deleted = false;
101  // Case 1.
102  // Row was added but it's on previous pages, so the first
103  // item of the grid was moved to the second place by the added
104  // row. Render the first one that's currently not visible yet in
105  // grid.
106  $args = array('rowId' => $firstDataId);
107  $row = $grid->getRequestedRow($request, $args);
108  $pagingAttributes['newTopRow'] = $grid->renderRow($request, $row);
109  }
110 
111  if ($firstDataId == $topLimitRowId && $lastDataId == $bottomLimitRowId) {
112  $deleted = false;
113  }
114 
115  if ($deleted) {
116  if ((empty($gridData) ||
117  // When DAOResultFactory, it seems that if no items were found for the current
118  // range information, the last page is fetched, which give us grid data even if
119  // the current page is empty. So we check for iterator and rangeInfo current pages.
120  $iterator->getPage() != $rangeInfo->getPage())
121  && $iterator->getPageCount() >= 1) {
122  // Case 3.
123  $pagingAttributes['loadLastPage'] = true;
124  } else {
125  if (count($gridData) >= $rangeInfo->getCount()) {
126  // Case 2.
127  // Get the last data element id of the current page.
128  end($gridData);
129  $firstRowId = key($gridData);
130 
131  // Get the row and render it.
132  $args = array('rowId' => $firstRowId);
133  $row = $grid->getRequestedRow($request, $args);
134  $pagingAttributes['deletedRowReplacement'] = $grid->renderRow($request, $row);
135  }
136  }
137  }
138  }
139 
140  // Render the paging options, including updated markup.
141  $this->setOptions($request, $grid);
142  $pagingAttributes['pagingInfo'] = $this->getOptions();
143 
144  // Add paging attributes to json so grid can update UI.
145  $additionalAttributes = $jsonMessage->getAdditionalAttributes();
146  $jsonMessage->setAdditionalAttributes(array_merge(
147  $pagingAttributes,
148  $additionalAttributes)
149  );
150  }
151 }
152 
153 
PagingFeature\getJSClass
getJSClass()
Definition: PagingFeature.inc.php:37
GeneralPagingFeature
Base class that implements common functionality for paging features.
Definition: GeneralPagingFeature.inc.php:20
GeneralPagingFeature\getItemIterator
getItemIterator()
Definition: GeneralPagingFeature.inc.php:54
PagingFeature\fetchRow
fetchRow($args)
Definition: PagingFeature.inc.php:74
PagingFeature
Add paging functionality to grids.
Definition: PagingFeature.inc.php:19
PagingFeature\fetchUIElements
fetchUIElements($request, $grid)
Definition: PagingFeature.inc.php:45
PKPTemplateManager\getManager
static & getManager($request=null)
Definition: PKPTemplateManager.inc.php:1239
PagingFeature\__construct
__construct($id='paging')
Definition: PagingFeature.inc.php:26
GridFeature\getOptions
getOptions()
Definition: GridFeature.inc.php:66
GeneralPagingFeature\setOptions
setOptions($request, $grid)
Definition: GeneralPagingFeature.inc.php:65