views_plugin_pager_full.inc

  1. cis7 sites/all/modules/ulmus/views/plugins/views_plugin_pager_full.inc
  2. cle7 sites/all/modules/ulmus/views/plugins/views_plugin_pager_full.inc
  3. ecd7 sites/all/modules/ulmus/views/plugins/views_plugin_pager_full.inc
  4. elmsmedia7 sites/all/modules/ulmus/views/plugins/views_plugin_pager_full.inc
  5. harmony7 sites/all/modules/ulmus/views/plugins/views_plugin_pager_full.inc
  6. icor7 sites/all/modules/ulmus/views/plugins/views_plugin_pager_full.inc
  7. meedjum_blog7 sites/all/modules/ulmus/views/plugins/views_plugin_pager_full.inc
  8. mooc7 sites/all/modules/ulmus/views/plugins/views_plugin_pager_full.inc

Definition of views_plugin_pager_full.

Classes

Namesort descending Description
views_plugin_pager_full The plugin to handle full pager.

File

sites/all/modules/ulmus/views/plugins/views_plugin_pager_full.inc
View source
  1. <?php
  2. /**
  3. * @file
  4. * Definition of views_plugin_pager_full.
  5. */
  6. /**
  7. * The plugin to handle full pager.
  8. *
  9. * @ingroup views_pager_plugins
  10. */
  11. class views_plugin_pager_full extends views_plugin_pager {
  12. function summary_title() {
  13. if (!empty($this->options['offset'])) {
  14. return format_plural($this->options['items_per_page'], '@count item, skip @skip', 'Paged, @count items, skip @skip', array('@count' => $this->options['items_per_page'], '@skip' => $this->options['offset']));
  15. }
  16. return format_plural($this->options['items_per_page'], '@count item', 'Paged, @count items', array('@count' => $this->options['items_per_page']));
  17. }
  18. function option_definition() {
  19. $options = parent::option_definition();
  20. $options['items_per_page'] = array('default' => 10);
  21. $options['offset'] = array('default' => 0);
  22. $options['id'] = array('default' => 0);
  23. $options['total_pages'] = array('default' => '');
  24. // Use the same default quantity that core uses by default.
  25. $options['quantity'] = array('default' => 9);
  26. $options['expose'] = array(
  27. 'contains' => array(
  28. 'items_per_page' => array('default' => FALSE, 'bool' => TRUE),
  29. 'items_per_page_label' => array('default' => 'Items per page', 'translatable' => TRUE),
  30. 'items_per_page_options' => array('default' => '5, 10, 20, 40, 60'),
  31. 'items_per_page_options_all' => array('default' => FALSE, 'bool' => TRUE),
  32. 'items_per_page_options_all_label' => array('default' => '- All -', 'translatable' => TRUE),
  33. 'offset' => array('default' => FALSE, 'bool' => TRUE),
  34. 'offset_label' => array('default' => 'Offset', 'translatable' => TRUE),
  35. ),
  36. );
  37. $options['tags'] = array(
  38. 'contains' => array(
  39. 'first' => array('default' => '« first', 'translatable' => TRUE),
  40. 'previous' => array('default' => '‹ previous', 'translatable' => TRUE),
  41. 'next' => array('default' => 'next ›', 'translatable' => TRUE),
  42. 'last' => array('default' => 'last »', 'translatable' => TRUE),
  43. ),
  44. );
  45. return $options;
  46. }
  47. /**
  48. * Provide the default form for setting options.
  49. */
  50. function options_form(&$form, &$form_state) {
  51. parent::options_form($form, $form_state);
  52. $pager_text = $this->display->handler->get_pager_text();
  53. $form['items_per_page'] = array(
  54. '#title' => $pager_text['items per page title'],
  55. '#type' => 'textfield',
  56. '#description' => $pager_text['items per page description'],
  57. '#default_value' => $this->options['items_per_page'],
  58. );
  59. $form['offset'] = array(
  60. '#type' => 'textfield',
  61. '#title' => t('Offset'),
  62. '#description' => t('The number of items to skip. For example, if this field is 3, the first 3 items will be skipped and not displayed.'),
  63. '#default_value' => $this->options['offset'],
  64. );
  65. $form['id'] = array(
  66. '#type' => 'textfield',
  67. '#title' => t('Pager ID'),
  68. '#description' => t("Unless you're experiencing problems with pagers related to this view, you should leave this at 0. If using multiple pagers on one page you may need to set this number to a higher value so as not to conflict within the ?page= array. Large values will add a lot of commas to your URLs, so avoid if possible."),
  69. '#default_value' => $this->options['id'],
  70. );
  71. $form['total_pages'] = array(
  72. '#type' => 'textfield',
  73. '#title' => t('Number of pages'),
  74. '#description' => t('The total number of pages. Leave empty to show all pages.'),
  75. '#default_value' => $this->options['total_pages'],
  76. );
  77. $form['quantity'] = array(
  78. '#type' => 'textfield',
  79. '#title' => t('Number of pager links visible'),
  80. '#description' => t('Specify the number of links to pages to display in the pager.'),
  81. '#default_value' => $this->options['quantity'],
  82. );
  83. $form['tags'] = array (
  84. '#type' => 'fieldset',
  85. '#collapsible' => FALSE,
  86. '#collapsed' => FALSE,
  87. '#tree' => TRUE,
  88. '#title' => t('Tags'),
  89. '#input' => TRUE,
  90. '#description' => t('A lists of labels for the controls in the pager'),
  91. );
  92. $form['tags']['first'] = array(
  93. '#type' => 'textfield',
  94. '#title' => t('Text for "first"-link'),
  95. '#description' => t('Text for "first"-link'),
  96. '#default_value' => $this->options['tags']['first'],
  97. );
  98. $form['tags']['previous'] = array(
  99. '#type' => 'textfield',
  100. '#title' => t('Text for "previous"-link'),
  101. '#description' => t('Text for "previous"-link'),
  102. '#default_value' => $this->options['tags']['previous'],
  103. );
  104. $form['tags']['next'] = array(
  105. '#type' => 'textfield',
  106. '#title' => t('Text for "next"-link'),
  107. '#description' => t('Text for "next"-link'),
  108. '#default_value' => $this->options['tags']['next'],
  109. );
  110. $form['tags']['last'] = array(
  111. '#type' => 'textfield',
  112. '#title' => t('Text for "last"-link'),
  113. '#description' => t('Text for "last"-link'),
  114. '#default_value' => $this->options['tags']['last'],
  115. );
  116. $form['expose'] = array (
  117. '#type' => 'fieldset',
  118. '#collapsible' => FALSE,
  119. '#collapsed' => FALSE,
  120. '#tree' => TRUE,
  121. '#title' => t('Exposed options'),
  122. '#input' => TRUE,
  123. '#description' => t('Exposing this options allows users to define their values in a exposed form when view is displayed'),
  124. );
  125. $form['expose']['items_per_page'] = array(
  126. '#type' => 'checkbox',
  127. '#title' => t('Expose items per page'),
  128. '#description' => t('When checked, users can determine how many items per page show in a view'),
  129. '#default_value' => $this->options['expose']['items_per_page'],
  130. );
  131. $form['expose']['items_per_page_label'] = array(
  132. '#type' => 'textfield',
  133. '#title' => t('Items per page label'),
  134. '#required' => TRUE,
  135. '#description' => t('Label to use in the exposed items per page form element.'),
  136. '#default_value' => $this->options['expose']['items_per_page_label'],
  137. '#dependency' => array(
  138. 'edit-pager-options-expose-items-per-page' => array(1)
  139. ),
  140. );
  141. $form['expose']['items_per_page_options'] = array(
  142. '#type' => 'textfield',
  143. '#title' => t('Exposed items per page options'),
  144. '#required' => TRUE,
  145. '#description' => t('Set between which values the user can choose when determining the items per page. Separated by comma.'),
  146. '#default_value' => $this->options['expose']['items_per_page_options'],
  147. '#dependency' => array(
  148. 'edit-pager-options-expose-items-per-page' => array(1)
  149. ),
  150. );
  151. $form['expose']['items_per_page_options_all'] = array(
  152. '#type' => 'checkbox',
  153. '#title' => t('Include all items option'),
  154. '#description' => t('If checked, an extra item will be included to items per page to display all items'),
  155. '#default_value' => $this->options['expose']['items_per_page_options_all'],
  156. );
  157. $form['expose']['items_per_page_options_all_label'] = array(
  158. '#type' => 'textfield',
  159. '#title' => t('All items label'),
  160. '#description' => t('Which label will be used to display all items'),
  161. '#default_value' => $this->options['expose']['items_per_page_options_all_label'],
  162. '#dependency' => array(
  163. 'edit-items-per-page-options-all' => array(1),
  164. ),
  165. );
  166. $form['expose']['offset'] = array(
  167. '#type' => 'checkbox',
  168. '#title' => t('Expose Offset'),
  169. '#description' => t('When checked, users can determine how many items should be skipped at the beginning.'),
  170. '#default_value' => $this->options['expose']['offset'],
  171. );
  172. $form['expose']['offset_label'] = array(
  173. '#type' => 'textfield',
  174. '#title' => t('Offset label'),
  175. '#required' => TRUE,
  176. '#description' => t('Label to use in the exposed offset form element.'),
  177. '#default_value' => $this->options['expose']['offset_label'],
  178. '#dependency' => array(
  179. 'edit-pager-options-expose-offset' => array(1)
  180. ),
  181. );
  182. }
  183. function options_validate(&$form, &$form_state) {
  184. // Only accept integer values.
  185. $error = FALSE;
  186. $exposed_options = $form_state['values']['pager_options']['expose']['items_per_page_options'];
  187. if (strpos($exposed_options, '.') !== FALSE) {
  188. $error = TRUE;
  189. }
  190. $options = explode(',',$exposed_options);
  191. if (!$error && is_array($options)) {
  192. foreach ($options as $option) {
  193. if (!is_numeric($option) || intval($option) == 0) {
  194. $error = TRUE;
  195. }
  196. }
  197. }
  198. else {
  199. $error = TRUE;
  200. }
  201. if ($error) {
  202. form_set_error('pager_options][expose][items_per_page_options', t('Please insert a list of integer numeric values separated by commas: e.g: 10, 20, 50, 100'));
  203. }
  204. // Take sure that the items_per_page is part of the expose settings.
  205. if (!empty($form_state['values']['pager_options']['expose']['items_per_page']) && !empty($form_state['values']['pager_options']['items_per_page'])) {
  206. $items_per_page = $form_state['values']['pager_options']['items_per_page'];
  207. if (array_search($items_per_page, $options) === FALSE) {
  208. form_set_error('pager_options][expose][items_per_page_options', t('Please insert the items per page (@items_per_page) from above.',
  209. array('@items_per_page' => $items_per_page))
  210. );
  211. }
  212. }
  213. }
  214. function query() {
  215. if ($this->items_per_page_exposed()) {
  216. if (!empty($_GET['items_per_page']) && $_GET['items_per_page'] > 0) {
  217. $this->options['items_per_page'] = $_GET['items_per_page'];
  218. }
  219. elseif (!empty($_GET['items_per_page']) && $_GET['items_per_page'] == 'All' && $this->options['expose']['items_per_page_options_all']) {
  220. $this->options['items_per_page'] = 0;
  221. }
  222. }
  223. if ($this->offset_exposed()) {
  224. if (isset($_GET['offset']) && $_GET['offset'] >= 0) {
  225. $this->options['offset'] = $_GET['offset'];
  226. }
  227. }
  228. $limit = $this->options['items_per_page'];
  229. $offset = $this->current_page * $this->options['items_per_page'] + $this->options['offset'];
  230. if (!empty($this->options['total_pages'])) {
  231. if ($this->current_page >= $this->options['total_pages']) {
  232. $limit = $this->options['items_per_page'];
  233. $offset = $this->options['total_pages'] * $this->options['items_per_page'];
  234. }
  235. }
  236. $this->view->query->set_limit($limit);
  237. $this->view->query->set_offset($offset);
  238. }
  239. function render($input) {
  240. $pager_theme = views_theme_functions('pager', $this->view, $this->display);
  241. // The 0, 1, 3, 4 index are correct. See theme_pager documentation.
  242. $tags = array(
  243. 0 => $this->options['tags']['first'],
  244. 1 => $this->options['tags']['previous'],
  245. 3 => $this->options['tags']['next'],
  246. 4 => $this->options['tags']['last'],
  247. );
  248. $output = theme($pager_theme, array(
  249. 'tags' => $tags,
  250. 'element' => $this->options['id'],
  251. 'parameters' => $input,
  252. 'quantity' => $this->options['quantity'],
  253. ));
  254. return $output;
  255. }
  256. /**
  257. * Set the current page.
  258. *
  259. * @param $number
  260. * If provided, the page number will be set to this. If NOT provided,
  261. * the page number will be set from the global page array.
  262. */
  263. function set_current_page($number = NULL) {
  264. if (isset($number)) {
  265. $this->current_page = $number;
  266. return;
  267. }
  268. // If the current page number was not specified, extract it from the global
  269. // page array.
  270. global $pager_page_array;
  271. if (empty($pager_page_array)) {
  272. $pager_page_array = array();
  273. }
  274. // Fill in missing values in the global page array, in case the global page
  275. // array hasn't been initialized before.
  276. $page = isset($_GET['page']) ? explode(',', $_GET['page']) : array();
  277. for ($i = 0; $i <= $this->options['id'] || $i < count($pager_page_array); $i++) {
  278. $pager_page_array[$i] = empty($page[$i]) ? 0 : $page[$i];
  279. }
  280. $this->current_page = intval($pager_page_array[$this->options['id']]);
  281. if ($this->current_page < 0) {
  282. $this->current_page = 0;
  283. }
  284. }
  285. function get_pager_total() {
  286. if ($items_per_page = intval($this->get_items_per_page())) {
  287. return ceil($this->total_items / $items_per_page);
  288. }
  289. else {
  290. return 1;
  291. }
  292. }
  293. /**
  294. * Update global paging info.
  295. *
  296. * This is called after the count query has been run to set the total
  297. * items available and to update the current page if the requested
  298. * page is out of range.
  299. */
  300. function update_page_info() {
  301. if (!empty($this->options['total_pages'])) {
  302. if (($this->options['total_pages'] * $this->options['items_per_page']) < $this->total_items) {
  303. $this->total_items = $this->options['total_pages'] * $this->options['items_per_page'];
  304. }
  305. }
  306. // Don't set pager settings for items per page = 0.
  307. $items_per_page = $this->get_items_per_page();
  308. if (!empty($items_per_page)) {
  309. // Dump information about what we already know into the globals.
  310. global $pager_page_array, $pager_total, $pager_total_items, $pager_limits;
  311. // Set the limit.
  312. $pager_limits[$this->options['id']] = $this->options['items_per_page'];
  313. // Set the item count for the pager.
  314. $pager_total_items[$this->options['id']] = $this->total_items;
  315. // Calculate and set the count of available pages.
  316. $pager_total[$this->options['id']] = $this->get_pager_total();
  317. // See if the requested page was within range:
  318. if ($this->current_page < 0) {
  319. $this->current_page = 0;
  320. }
  321. else if ($this->current_page >= $pager_total[$this->options['id']]) {
  322. // Pages are numbered from 0 so if there are 10 pages, the last page is 9.
  323. $this->current_page = $pager_total[$this->options['id']] - 1;
  324. }
  325. // Put this number in to guarantee that we do not generate notices when the pager
  326. // goes to look for it later.
  327. $pager_page_array[$this->options['id']] = $this->current_page;
  328. }
  329. }
  330. function uses_exposed() {
  331. return $this->items_per_page_exposed() || $this->offset_exposed();
  332. }
  333. function items_per_page_exposed() {
  334. return !empty($this->options['expose']['items_per_page']);
  335. }
  336. function offset_exposed() {
  337. return !empty($this->options['expose']['offset']);
  338. }
  339. function exposed_form_alter(&$form, &$form_state) {
  340. if ($this->items_per_page_exposed()) {
  341. $options = explode(',', $this->options['expose']['items_per_page_options']);
  342. $sanitized_options = array();
  343. if (is_array($options)) {
  344. foreach ($options as $option) {
  345. $sanitized_options[intval($option)] = intval($option);
  346. }
  347. if (!empty($this->options['expose']['items_per_page_options_all']) && !empty($this->options['expose']['items_per_page_options_all_label'])) {
  348. $sanitized_options['All'] = $this->options['expose']['items_per_page_options_all_label'];
  349. }
  350. $form['items_per_page'] = array(
  351. '#type' => 'select',
  352. '#title' => $this->options['expose']['items_per_page_label'],
  353. '#options' => $sanitized_options,
  354. '#default_value' => $this->get_items_per_page(),
  355. );
  356. }
  357. }
  358. if ($this->offset_exposed()) {
  359. $form['offset'] = array(
  360. '#type' => 'textfield',
  361. '#size' => 10,
  362. '#maxlength' => 10,
  363. '#title' => $this->options['expose']['offset_label'],
  364. '#default_value' => $this->get_offset(),
  365. );
  366. }
  367. }
  368. function exposed_form_validate(&$form, &$form_state) {
  369. if (!empty($form_state['values']['offset']) && trim($form_state['values']['offset'])) {
  370. if (!is_numeric($form_state['values']['offset']) || $form_state['values']['offset'] < 0) {
  371. form_set_error('offset', t('Offset must be an number greather or equal than 0.'));
  372. }
  373. }
  374. }
  375. }
Error | ELMSLN API

Error

×

Error message

  • Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/elmsln_community/api.elmsln.org/includes/common.inc:2791) in drupal_send_headers() (line 1499 of /var/www/html/elmsln_community/api.elmsln.org/includes/bootstrap.inc).
  • Error: Call to undefined function apc_delete() in DrupalAPCCache->clear() (line 289 of /var/www/html/elmsln_community/api.elmsln.org/sites/all/modules/apc/drupal_apc_cache.inc).
The website encountered an unexpected error. Please try again later.