sortabletable.class.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613
  1. <?php
  2. /*
  3. ==============================================================================
  4. Dokeos - elearning and course management software
  5. Copyright (c) 2005 Dokeos S.A.
  6. Copyright (c) Bart Mollet (bart.mollet@hogent.be)
  7. For a full list of contributors, see "credits.txt".
  8. The full license can be read in "license.txt".
  9. This program is free software; you can redistribute it and/or
  10. modify it under the terms of the GNU General Public License
  11. as published by the Free Software Foundation; either version 2
  12. of the License, or (at your option) any later version.
  13. See the GNU General Public License for more details.
  14. Contact address: Dokeos, 44 rue des palais, B-1030 Brussels, Belgium
  15. Mail: info@dokeos.com
  16. ==============================================================================
  17. */
  18. require_once "HTML/Table.php"; //See http://pear.php.net/package/HTML_Table
  19. require_once "Pager/Pager.php"; //See http://pear.php.net/package/Pager
  20. require_once 'tablesort.lib.php';
  21. /**
  22. * This class allows you to display a sortable data-table. It is possible to
  23. * split the data in several pages.
  24. * Using this class you can:
  25. * - automatically create checkboxes of the first table column
  26. * - a "select all" and "deselect all" link is added
  27. * - only if you provide a list of actions for the selected items
  28. * - click on the table header to sort the data
  29. * - choose how many items you see per page
  30. * - navigate through all data-pages
  31. */
  32. class SortableTable extends HTML_Table
  33. {
  34. /**
  35. * A name for this table
  36. */
  37. var $table_name;
  38. /**
  39. * The page to display
  40. */
  41. var $page_nr;
  42. /**
  43. * The column to sort the data
  44. */
  45. var $column;
  46. /**
  47. * The sorting direction (ASC or DESC)
  48. */
  49. var $direction;
  50. /**
  51. * Number of items to display per page
  52. */
  53. var $per_page;
  54. /**
  55. * The default number of items to display per page
  56. */
  57. var $default_items_per_page;
  58. /**
  59. * A prefix for the URL-parameters, can be used on pages with multiple
  60. * SortableTables
  61. */
  62. var $param_prefix;
  63. /**
  64. * The pager object to split the data in several pages
  65. */
  66. var $pager;
  67. /**
  68. * The total number of items in the table
  69. */
  70. var $total_number_of_items;
  71. /**
  72. * The function to get the total number of items
  73. */
  74. var $get_total_number_function;
  75. /**
  76. * The function to the the data to display
  77. */
  78. var $get_data_function;
  79. /**
  80. * An array with defined column-filters
  81. */
  82. var $column_filters;
  83. /**
  84. * A list of actions which will be available through a select list
  85. */
  86. var $form_actions;
  87. /**
  88. * Additional parameters to pass in the URL
  89. */
  90. var $additional_parameters;
  91. /**
  92. * Additional attributes for the th-tags
  93. */
  94. var $th_attributes;
  95. /**
  96. * Additional attributes for the td-tags
  97. */
  98. var $td_attributes;
  99. /**
  100. * Array with names of the other tables defined on the same page of this
  101. * table
  102. */
  103. var $other_tables;
  104. /**
  105. * Create a new SortableTable
  106. * @param string $table_name A name for the table (default = 'table')
  107. * @param string $get_total_number_function A user defined function to get
  108. * the total number of items in the table
  109. * @param string $get_data_function A function to get the data to display on
  110. * the current page
  111. * @param int $default_column The default column on which the data should be
  112. * sorted
  113. * @param int $default_items_per_page The default number of items to show
  114. * on one page
  115. * @param string $default_order_direction The default order direction;
  116. * either the constant 'ASC' or 'DESC'
  117. */
  118. function SortableTable($table_name = 'table', $get_total_number_function = null, $get_data_function = null, $default_column = 1, $default_items_per_page = 20, $default_order_direction = 'ASC')
  119. {
  120. parent :: HTML_Table(array ('class' => 'data_table'));
  121. $this->table_name = $table_name;
  122. $this->additional_parameters = array ();
  123. $this->param_prefix = $table_name.'_';
  124. $this->page_nr = isset ($_SESSION[$this->param_prefix.'page_nr']) ? $_SESSION[$this->param_prefix.'page_nr'] : 1;
  125. $this->page_nr = isset ($_GET[$this->param_prefix.'page_nr']) ? $_GET[$this->param_prefix.'page_nr'] : $this->page_nr;
  126. $this->column = isset ($_SESSION[$this->param_prefix.'column']) ? $_SESSION[$this->param_prefix.'column'] : $default_column;
  127. $this->column = isset ($_GET[$this->param_prefix.'column']) ? $_GET[$this->param_prefix.'column'] : $this->column;
  128. $this->direction = isset ($_SESSION[$this->param_prefix.'direction']) ? $_SESSION[$this->param_prefix.'direction'] : $default_order_direction;
  129. $this->direction = isset ($_GET[$this->param_prefix.'direction']) ? $_GET[$this->param_prefix.'direction'] : $this->direction;
  130. $this->per_page = isset ($_SESSION[$this->param_prefix.'per_page']) ? $_SESSION[$this->param_prefix.'per_page'] : $default_items_per_page;
  131. $this->per_page = isset ($_GET[$this->param_prefix.'per_page']) ? $_GET[$this->param_prefix.'per_page'] : $this->per_page;
  132. $_SESSION[$this->param_prefix.'per_page'] = $this->per_page;
  133. $_SESSION[$this->param_prefix.'direction'] = $this->direction ;
  134. $_SESSION[$this->param_prefix.'page_nr'] = $this->page_nr;
  135. $_SESSION[$this->param_prefix.'column'] = $this->column;
  136. $this->pager = null;
  137. $this->default_items_per_page = $default_items_per_page;
  138. $this->total_number_of_items = -1;
  139. $this->get_total_number_function = $get_total_number_function;
  140. $this->get_data_function = $get_data_function;
  141. $this->column_filters = array ();
  142. $this->form_actions = array ();
  143. $this->checkbox_name = null;
  144. $this->td_attributes = array ();
  145. $this->th_attributes = array ();
  146. $this->other_tables = array();
  147. }
  148. /**
  149. * Get the Pager object to split the showed data in several pages
  150. */
  151. function get_pager()
  152. {
  153. if (is_null($this->pager))
  154. {
  155. $total_number_of_items = $this->get_total_number_of_items();
  156. $params['mode'] = 'Sliding';
  157. $params['perPage'] = $this->per_page;
  158. $params['totalItems'] = $total_number_of_items;
  159. $params['urlVar'] = $this->param_prefix.'page_nr';
  160. $params['currentPage'] = $this->page_nr;
  161. $params['prevImg'] = '<img src="'.api_get_path(WEB_CODE_PATH).'img/prev.png" style="vertical-align: middle;"/>';
  162. $params['nextImg'] = '<img src="'.api_get_path(WEB_CODE_PATH).'img/next.png" style="vertical-align: middle;"/>';
  163. $params['firstPageText'] = '<img src="'.api_get_path(WEB_CODE_PATH).'img/first.png" style="vertical-align: middle;"/>';
  164. $params['lastPageText'] = '<img src="'.api_get_path(WEB_CODE_PATH).'img/last.png" style="vertical-align: middle;"/>';
  165. $params['firstPagePre'] = '';
  166. $params['lastPagePre'] = '';
  167. $params['firstPagePost'] = '';
  168. $params['lastPagePost'] = '';
  169. $params['spacesBeforeSeparator'] = '';
  170. $params['spacesAfterSeparator'] = '';
  171. $query_vars = array_keys($_GET);
  172. $query_vars_needed = array ($this->param_prefix.'column', $this->param_prefix.'direction', $this->param_prefix.'per_page');
  173. if (count($this->additional_parameters) > 0)
  174. {
  175. $query_vars_needed = array_merge($query_vars_needed, array_keys($this->additional_parameters));
  176. }
  177. $query_vars_exclude = array_diff($query_vars, $query_vars_needed);
  178. $params['excludeVars'] = $query_vars_exclude;
  179. $this->pager = & Pager :: factory($params);
  180. }
  181. return $this->pager;
  182. }
  183. /**
  184. * Displays the table, complete with navigation buttons to browse through
  185. * the data-pages.
  186. */
  187. function display()
  188. {
  189. $empty_table = false;
  190. if ($this->get_total_number_of_items() == 0)
  191. {
  192. $cols = $this->getColCount();
  193. $this->setCellAttributes(1, 0, 'style="font-style: italic;text-align:center;" colspan='.$cols);
  194. $this->setCellContents(1, 0, get_lang('TheListIsEmpty'));
  195. $empty_table = true;
  196. }
  197. if (!$empty_table)
  198. {
  199. $form = $this->get_page_select_form();
  200. $nav = $this->get_navigation_html();
  201. $html = '<table style="width:100%;">';
  202. $html .= '<tr>';
  203. $html .= '<td style="width:25%;">';
  204. $html .= $form;
  205. $html .= '</td>';
  206. $html .= '<td style="text-align:center;">';
  207. $html .= $this->get_table_title();
  208. $html .= '</td>';
  209. $html .= '<td style="text-align:right;width:25%;">';
  210. $html .= $nav;
  211. $html .= '</td>';
  212. $html .= '</tr>';
  213. $html .= '</table>';
  214. if (count($this->form_actions) > 0)
  215. {
  216. $html .= '<script language="JavaScript" type="text/javascript">
  217. /*<![CDATA[*/
  218. function setCheckbox(value) {
  219. d = document.form_'.$this->table_name.';
  220. for (i = 0; i < d.elements.length; i++) {
  221. if (d.elements[i].type == "checkbox") {
  222. d.elements[i].checked = value;
  223. }
  224. }
  225. }
  226. /*]]>*/
  227. </script>';
  228. $params = $this->get_sortable_table_param_string.'&amp;'.$this->get_additional_url_paramstring();
  229. $html .= '<form method="post" action="'.api_get_self().'?'.$params.'" name="form_'.$this->table_name.'">';
  230. }
  231. }
  232. $html .= $this->get_table_html();
  233. if (!$empty_table)
  234. {
  235. $html .= '<table style="width:100%;">';
  236. $html .= '<tr>';
  237. $html .= '<td colspan="2">';
  238. if (count($this->form_actions) > 0)
  239. {
  240. $html .= '<a href="?'.$params.'&amp;'.$this->param_prefix.'selectall=1" onclick="javascript:setCheckbox(true);return false;">'.get_lang('SelectAll').'</a> - ';
  241. $html .= '<a href="?'.$params.'" onclick="javascript:setCheckbox(false);return false;">'.get_lang('UnSelectAll').'</a> ';
  242. $html .= '<select name="action">';
  243. foreach ($this->form_actions as $action => $label)
  244. {
  245. $html .= '<option value="'.$action.'">'.$label.'</option>';
  246. }
  247. $html .= '</select>';
  248. $html .= '<input type="submit" value="'.get_lang('Ok').'" onclick="javascript:if(!confirm('."'".addslashes(htmlentities(get_lang("ConfirmYourChoice")))."'".')) return false;"/>';
  249. }
  250. else
  251. {
  252. $html .= $form;
  253. }
  254. $html .= '</td>';
  255. $html .= '<td style="text-align:right;">';
  256. $html .= $nav;
  257. $html .= '</td>';
  258. $html .= '</tr>';
  259. $html .= '</table>';
  260. if (count($this->form_actions) > 0)
  261. {
  262. $html .= '</form>';
  263. }
  264. }
  265. echo $html;
  266. }
  267. /**
  268. * Get the HTML-code with the navigational buttons to browse through the
  269. * data-pages.
  270. */
  271. function get_navigation_html()
  272. {
  273. $pager = $this->get_pager();
  274. $pager_links = $pager->getLinks();
  275. $showed_items = $pager->getOffsetByPageId();
  276. $nav = $pager_links['first'].' '.$pager_links['back'];
  277. $nav .= ' '.$pager->getCurrentPageId().' / '.$pager->numPages().' ';
  278. $nav .= $pager_links['next'].' '.$pager_links['last'];
  279. return $nav;
  280. }
  281. /**
  282. * Get the HTML-code with the data-table.
  283. */
  284. function get_table_html()
  285. {
  286. $pager = $this->get_pager();
  287. $offset = $pager->getOffsetByPageId();
  288. $from = $offset[0] - 1;
  289. $table_data = $this->get_table_data($from);
  290. foreach ($table_data as $index => $row)
  291. {
  292. $row = $this->filter_data($row);
  293. $this->addRow($row);
  294. }
  295. $this->altRowAttributes(0, array ('class' => 'row_odd'), array ('class' => 'row_even'), true);
  296. foreach ($this->th_attributes as $column => $attributes)
  297. {
  298. $this->setCellAttributes(0, $column, $attributes);
  299. }
  300. foreach ($this->td_attributes as $column => $attributes)
  301. {
  302. $this->setColAttributes($column, $attributes);
  303. }
  304. return $this->toHTML();
  305. }
  306. /**
  307. * Get the HTML-code wich represents a form to select how many items a page
  308. * should contain.
  309. */
  310. function get_page_select_form()
  311. {
  312. $total_number_of_items = $this->get_total_number_of_items();
  313. if ($total_number_of_items <= $this->default_items_per_page)
  314. {
  315. return '';
  316. }
  317. $result[] = '<form method="get" action="'.api_get_self().'" style="display:inline;">';
  318. $param[$this->param_prefix.'direction'] = $this->direction;
  319. $param[$this->param_prefix.'page_nr'] = $this->page_nr;
  320. $param[$this->param_prefix.'column'] = $this->column;
  321. $param = array_merge($param, $this->additional_parameters);
  322. foreach ($param as $key => $value)
  323. {
  324. $result[] = '<input type="hidden" name="'.$key.'" value="'.$value.'"/>';
  325. }
  326. $result[] = '<select name="'.$this->param_prefix.'per_page" onchange="javascript:this.form.submit();">';
  327. for ($nr = 10; $nr <= min(50, $total_number_of_items); $nr += 10)
  328. {
  329. $result[] = '<option value="'.$nr.'" '. ($nr == $this->per_page ? 'selected="selected"' : '').'>'.$nr.'</option>';
  330. }
  331. if ($total_number_of_items < 500)
  332. {
  333. $result[] = '<option value="'.$total_number_of_items.'" '. ($total_number_of_items == $this->per_page ? 'selected="selected"' : '').'>ALL</option>';
  334. }
  335. $result[] = '</select>';
  336. $result[] = '<noscript>';
  337. $result[] = '<input type="submit" value="ok"/>';
  338. $result[] = '</noscript>';
  339. $result[] = '</form>';
  340. $result = implode("\n", $result);
  341. return $result;
  342. }
  343. /**
  344. * Get the table title.
  345. */
  346. function get_table_title()
  347. {
  348. $pager = $this->get_pager();
  349. $showed_items = $pager->getOffsetByPageId();
  350. return $showed_items[0].' - '.$showed_items[1].' / '.$this->get_total_number_of_items();
  351. }
  352. /**
  353. * Set the header-label
  354. * @param int $column The column number
  355. * @param string $label The label
  356. * @param boolean $sortable Is the table sortable by this column? (defatult
  357. * = true)
  358. * @param string $th_attributes Additional attributes for the th-tag of the
  359. * table header
  360. * @param string $td_attributes Additional attributes for the td-tags of the
  361. * column
  362. */
  363. function set_header($column, $label, $sortable = true, $th_attributes = null, $td_attributes = null)
  364. {
  365. $param['direction'] = 'ASC';
  366. if ($this->column == $column && $this->direction == 'ASC')
  367. {
  368. $param['direction'] = 'DESC';
  369. }
  370. $param['page_nr'] = $this->page_nr;
  371. $param['per_page'] = $this->per_page;
  372. $param['column'] = $column;
  373. if ($sortable)
  374. {
  375. $link = '<a href="'.api_get_self().'?';
  376. foreach ($param as $key => $value)
  377. {
  378. $link .= $this->param_prefix.$key.'='.urlencode($value).'&amp;';
  379. }
  380. $link .= $this->get_additional_url_paramstring();
  381. $link .= '">'.$label.'</a>';
  382. if ($this->column == $column)
  383. {
  384. $link .= $this->direction == 'ASC' ? ' &#8595;' : ' &#8593;';
  385. }
  386. }
  387. else
  388. {
  389. $link = $label;
  390. }
  391. $this->setHeaderContents(0, $column, $link);
  392. if (!is_null($td_attributes))
  393. {
  394. $this->td_attributes[$column] = $td_attributes;
  395. }
  396. if (!is_null($th_attributes))
  397. {
  398. $this->th_attributes[$column] = $th_attributes;
  399. }
  400. }
  401. /**
  402. * Get the parameter-string with additional parameters to use in the URLs
  403. * generated by this SortableTable
  404. */
  405. function get_additional_url_paramstring()
  406. {
  407. $param_string_parts = array ();
  408. if(is_array($this->additional_parameters) && count($this->additional_parameters)>0)
  409. {
  410. foreach ($this->additional_parameters as $key => $value)
  411. {
  412. $param_string_parts[] = urlencode($key).'='.urlencode($value);
  413. }
  414. }
  415. $result = implode('&amp;', $param_string_parts);
  416. foreach($this->other_tables as $index => $tablename)
  417. {
  418. if( isset($_GET[$tablename.'_direction']))
  419. $param[$tablename.'_direction'] = $_GET[$tablename.'_direction'];
  420. if( isset($_GET[$tablename.'_page_nr']))
  421. $param[$tablename.'_page_nr'] = $_GET[$tablename.'_page_nr'];
  422. if( isset($_GET[$tablename.'_per_page']))
  423. $param[$tablename.'_per_page'] = $_GET[$tablename.'_per_page'];
  424. if( isset($_GET[$tablename.'_column']))
  425. $param[$tablename.'_column'] = $_GET[$tablename.'_column'];
  426. $param_string_parts = array ();
  427. foreach ($param as $key => $value)
  428. {
  429. $param_string_parts[] = urlencode($key).'='.urlencode($value);
  430. }
  431. if(count($param_string_parts) > 0)
  432. $result .= '&amp;'.implode('&amp;', $param_string_parts);
  433. }
  434. return $result;
  435. }
  436. /**
  437. * Get the parameter-string with the SortableTable-related parameters to use
  438. * in URLs
  439. */
  440. function get_sortable_table_param_string()
  441. {
  442. $param[$this->param_prefix.'direction'] = $this->direction;
  443. $param[$this->param_prefix.'page_nr'] = $this->page_nr;
  444. $param[$this->param_prefix.'per_page'] = $this->per_page;
  445. $param[$this->param_prefix.'column'] = $this->column;
  446. $param_string_parts = array ();
  447. foreach ($param as $key => $value)
  448. {
  449. $param_string_parts[] = urlencode($key).'='.urlencode($value);
  450. }
  451. $res = implode('&amp;', $param_string_parts);
  452. return $res;
  453. }
  454. /**
  455. * Add a filter to a column. If another filter was allready defined for the
  456. * given column, it will be overwritten.
  457. * @param int $column The number of the column
  458. * @param string $function The name of the filter-function. This should be a
  459. * function wich requires 1 parameter and returns the filtered value.
  460. */
  461. function set_column_filter($column, $function)
  462. {
  463. $this->column_filters[$column] = $function;
  464. }
  465. /**
  466. * Define a list of actions which can be performed on the table-date.
  467. * If you define a list of actions, the first column of the table will be
  468. * converted into checkboxes.
  469. * @param array $actions A list of actions. The key is the name of the
  470. * action. The value is the label to show in the select-box
  471. * @param string $checkbox_name The name of the generated checkboxes. The
  472. * value of the checkbox will be the value of the first column.
  473. */
  474. function set_form_actions($actions, $checkbox_name = 'id')
  475. {
  476. $this->form_actions = $actions;
  477. $this->checkbox_name = $checkbox_name;
  478. }
  479. /**
  480. * Define a list of additional parameters to use in the generated URLs
  481. * @param array $parameters
  482. */
  483. function set_additional_parameters($parameters)
  484. {
  485. $this->additional_parameters = $parameters;
  486. }
  487. /**
  488. * Set other tables on the same page.
  489. * If you have other sortable tables on the page displaying this sortable
  490. * tables, you can define those other tables with this function. If you
  491. * don't define the other tables, there sorting and pagination will return
  492. * to their default state when sorting this table.
  493. * @param array $tablenames An array of table names.
  494. */
  495. function set_other_tables($tablenames)
  496. {
  497. $this->other_tables = $tablenames;
  498. }
  499. /**
  500. * Transform all data in a table-row, using the filters defined by the
  501. * function set_column_filter(...) defined elsewhere in this class.
  502. * If you've defined actions, the first element of the given row will be
  503. * converted into a checkbox
  504. * @param array $row A row from the table.
  505. */
  506. function filter_data($row)
  507. {
  508. $url_params = $this->get_sortable_table_param_string().'&amp;'.$this->get_additional_url_paramstring();
  509. foreach ($this->column_filters as $column => $function)
  510. {
  511. $row[$column] = call_user_func($function, $row[$column], $url_params, $row);
  512. }
  513. if (count($this->form_actions) > 0)
  514. {
  515. if (strlen($row[0]) > 0)
  516. {
  517. $row[0] = '<input type="checkbox" name="'.$this->checkbox_name.'[]" value="'.$row[0].'"';
  518. if (isset ($_GET[$this->param_prefix.'selectall']))
  519. {
  520. $row[0] .= ' checked="checked"';
  521. }
  522. $row[0] .= '/>';
  523. }
  524. }
  525. foreach ($row as $index => $value)
  526. {
  527. if (strlen($row[$index]) == 0)
  528. {
  529. $row[$index] = '-';
  530. }
  531. }
  532. return $row;
  533. }
  534. /**
  535. * Get the total number of items. This function calls the function given as
  536. * 2nd argument in the constructor of a SortableTable. Make sure your
  537. * function has the same parameters as defined here.
  538. */
  539. function get_total_number_of_items()
  540. {
  541. if ($this->total_number_of_items == -1 && !is_null($this->get_total_number_function))
  542. {
  543. $this->total_number_of_items = call_user_func($this->get_total_number_function);
  544. }
  545. return $this->total_number_of_items;
  546. }
  547. /**
  548. * Get the data to display. This function calls the function given as
  549. * 2nd argument in the constructor of a SortableTable. Make sure your
  550. * function has the same parameters as defined here.
  551. * @param int $from Index of the first item to return.
  552. * @param int $per_page The number of items to return
  553. * @param int $column The number of the column on which the data should be
  554. * sorted
  555. * @param string $direction In which order should the data be sorted (ASC
  556. * or DESC)
  557. */
  558. function get_table_data($from = null, $per_page = null, $column = null, $direction = null)
  559. {
  560. if (!is_null($this->get_data_function))
  561. {
  562. return call_user_func($this->get_data_function, $from, $this->per_page, $this->column, $this->direction);
  563. }
  564. return array ();
  565. }
  566. }
  567. /**
  568. * Sortable table which can be used for data available in an array
  569. */
  570. class SortableTableFromArray extends SortableTable
  571. {
  572. /**
  573. * The array containing all data for this table
  574. */
  575. var $table_data;
  576. /**
  577. * Constructor
  578. * @param array $table_data
  579. * @param int $default_column
  580. * @param int $default_items_per_page
  581. */
  582. function SortableTableFromArray($table_data, $default_column = 1, $default_items_per_page = 20, $tablename = 'tablename')
  583. {
  584. parent :: SortableTable($tablename, null, null, $default_column, $default_items_per_page);
  585. $this->table_data = $table_data;
  586. }
  587. /**
  588. * Get table data to show on current page
  589. * @see SortableTable#get_table_data
  590. */
  591. function get_table_data($from = 1)
  592. {
  593. $content = TableSort :: sort_table($this->table_data, $this->column, $this->direction == 'ASC' ? SORT_ASC : SORT_DESC);
  594. return array_slice($content, $from, $this->per_page);
  595. }
  596. /**
  597. * Get total number of items
  598. * @see SortableTable#get_total_number_of_items
  599. */
  600. function get_total_number_of_items()
  601. {
  602. return count($this->table_data);
  603. }
  604. }
  605. ?>