PageRenderTime 63ms CodeModel.GetById 27ms RepoModel.GetById 1ms app.codeStats 0ms

/lib/tablelib.php

https://github.com/thepurpleblob/gumoodle
PHP | 1761 lines | 1026 code | 212 blank | 523 comment | 167 complexity | cded82ba66a63f11d210b4f0c107e631 MD5 | raw file
Possible License(s): Apache-2.0, GPL-3.0, BSD-3-Clause, LGPL-2.1, AGPL-3.0, MPL-2.0-no-copyleft-exception, LGPL-3.0

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. // This file is part of Moodle - http://moodle.org/
  3. //
  4. // Moodle is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // Moodle is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License
  15. // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
  16. /**
  17. * @package core
  18. * @subpackage lib
  19. * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
  20. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  21. */
  22. defined('MOODLE_INTERNAL') || die();
  23. /**#@+
  24. * These constants relate to the table's handling of URL parameters.
  25. */
  26. define('TABLE_VAR_SORT', 1);
  27. define('TABLE_VAR_HIDE', 2);
  28. define('TABLE_VAR_SHOW', 3);
  29. define('TABLE_VAR_IFIRST', 4);
  30. define('TABLE_VAR_ILAST', 5);
  31. define('TABLE_VAR_PAGE', 6);
  32. /**#@-*/
  33. /**#@+
  34. * Constants that indicate whether the paging bar for the table
  35. * appears above or below the table.
  36. */
  37. define('TABLE_P_TOP', 1);
  38. define('TABLE_P_BOTTOM', 2);
  39. /**#@-*/
  40. /**
  41. * @package moodlecore
  42. * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
  43. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  44. */
  45. class flexible_table {
  46. var $uniqueid = NULL;
  47. var $attributes = array();
  48. var $headers = array();
  49. var $columns = array();
  50. var $column_style = array();
  51. var $column_class = array();
  52. var $column_suppress = array();
  53. var $column_nosort = array('userpic');
  54. var $setup = false;
  55. var $sess = NULL;
  56. var $baseurl = NULL;
  57. var $request = array();
  58. var $is_collapsible = false;
  59. var $is_sortable = false;
  60. var $use_pages = false;
  61. var $use_initials = false;
  62. var $maxsortkeys = 2;
  63. var $pagesize = 30;
  64. var $currpage = 0;
  65. var $totalrows = 0;
  66. var $sort_default_column = NULL;
  67. var $sort_default_order = SORT_ASC;
  68. /**
  69. * Array of positions in which to display download controls.
  70. */
  71. var $showdownloadbuttonsat= array(TABLE_P_TOP);
  72. /**
  73. * @var string Key of field returned by db query that is the id field of the
  74. * user table or equivalent.
  75. */
  76. public $useridfield = 'id';
  77. /**
  78. * @var string which download plugin to use. Default '' means none - print
  79. * html table with paging. Property set by is_downloading which typically
  80. * passes in cleaned data from $
  81. */
  82. var $download = '';
  83. /**
  84. * @var bool whether data is downloadable from table. Determines whether
  85. * to display download buttons. Set by method downloadable().
  86. */
  87. var $downloadable = false;
  88. /**
  89. * @var string which download plugin to use. Default '' means none - print
  90. * html table with paging.
  91. */
  92. var $defaultdownloadformat = 'csv';
  93. /**
  94. * @var bool Has start output been called yet?
  95. */
  96. var $started_output = false;
  97. var $exportclass = null;
  98. /**
  99. * Constructor
  100. * @param int $uniqueid all tables have to have a unique id, this is used
  101. * as a key when storing table properties like sort order in the session.
  102. */
  103. function __construct($uniqueid) {
  104. $this->uniqueid = $uniqueid;
  105. $this->request = array(
  106. TABLE_VAR_SORT => 'tsort',
  107. TABLE_VAR_HIDE => 'thide',
  108. TABLE_VAR_SHOW => 'tshow',
  109. TABLE_VAR_IFIRST => 'tifirst',
  110. TABLE_VAR_ILAST => 'tilast',
  111. TABLE_VAR_PAGE => 'page',
  112. );
  113. }
  114. /**
  115. * Call this to pass the download type. Use :
  116. * $download = optional_param('download', '', PARAM_ALPHA);
  117. * To get the download type. We assume that if you call this function with
  118. * params that this table's data is downloadable, so we call is_downloadable
  119. * for you (even if the param is '', which means no download this time.
  120. * Also you can call this method with no params to get the current set
  121. * download type.
  122. * @param string $download download type. One of csv, tsv, xhtml, ods, etc
  123. * @param string $filename filename for downloads without file extension.
  124. * @param string $sheettitle title for downloaded data.
  125. * @return string download type. One of csv, tsv, xhtml, ods, etc
  126. */
  127. function is_downloading($download = null, $filename='', $sheettitle='') {
  128. if ($download!==null) {
  129. $this->sheettitle = $sheettitle;
  130. $this->is_downloadable(true);
  131. $this->download = $download;
  132. $this->filename = clean_filename($filename);
  133. $this->export_class_instance();
  134. }
  135. return $this->download;
  136. }
  137. /**
  138. * Get, and optionally set, the export class.
  139. * @param $exportclass (optional) if passed, set the table to use this export class.
  140. * @return table_default_export_format_parent the export class in use (after any set).
  141. */
  142. function export_class_instance($exportclass = null) {
  143. if (!is_null($exportclass)) {
  144. $this->started_output = true;
  145. $this->exportclass = $exportclass;
  146. $this->exportclass->table = $this;
  147. } else if (is_null($this->exportclass) && !empty($this->download)) {
  148. $classname = 'table_'.$this->download.'_export_format';
  149. $this->exportclass = new $classname($this);
  150. if (!$this->exportclass->document_started()) {
  151. $this->exportclass->start_document($this->filename);
  152. }
  153. }
  154. return $this->exportclass;
  155. }
  156. /**
  157. * Probably don't need to call this directly. Calling is_downloading with a
  158. * param automatically sets table as downloadable.
  159. *
  160. * @param bool $downloadable optional param to set whether data from
  161. * table is downloadable. If ommitted this function can be used to get
  162. * current state of table.
  163. * @return bool whether table data is set to be downloadable.
  164. */
  165. function is_downloadable($downloadable = null) {
  166. if ($downloadable !== null) {
  167. $this->downloadable = $downloadable;
  168. }
  169. return $this->downloadable;
  170. }
  171. /**
  172. * Where to show download buttons.
  173. * @param array $showat array of postions in which to show download buttons.
  174. * Containing TABLE_P_TOP and/or TABLE_P_BOTTOM
  175. */
  176. function show_download_buttons_at($showat) {
  177. $this->showdownloadbuttonsat = $showat;
  178. }
  179. /**
  180. * Sets the is_sortable variable to the given boolean, sort_default_column to
  181. * the given string, and the sort_default_order to the given integer.
  182. * @param bool $bool
  183. * @param string $defaultcolumn
  184. * @param int $defaultorder
  185. * @return void
  186. */
  187. function sortable($bool, $defaultcolumn = NULL, $defaultorder = SORT_ASC) {
  188. $this->is_sortable = $bool;
  189. $this->sort_default_column = $defaultcolumn;
  190. $this->sort_default_order = $defaultorder;
  191. }
  192. /**
  193. * Do not sort using this column
  194. * @param string column name
  195. */
  196. function no_sorting($column) {
  197. $this->column_nosort[] = $column;
  198. }
  199. /**
  200. * Is the column sortable?
  201. * @param string column name, null means table
  202. * @return bool
  203. */
  204. function is_sortable($column = null) {
  205. if (empty($column)) {
  206. return $this->is_sortable;
  207. }
  208. if (!$this->is_sortable) {
  209. return false;
  210. }
  211. return !in_array($column, $this->column_nosort);
  212. }
  213. /**
  214. * Sets the is_collapsible variable to the given boolean.
  215. * @param bool $bool
  216. * @return void
  217. */
  218. function collapsible($bool) {
  219. $this->is_collapsible = $bool;
  220. }
  221. /**
  222. * Sets the use_pages variable to the given boolean.
  223. * @param bool $bool
  224. * @return void
  225. */
  226. function pageable($bool) {
  227. $this->use_pages = $bool;
  228. }
  229. /**
  230. * Sets the use_initials variable to the given boolean.
  231. * @param bool $bool
  232. * @return void
  233. */
  234. function initialbars($bool) {
  235. $this->use_initials = $bool;
  236. }
  237. /**
  238. * Sets the pagesize variable to the given integer, the totalrows variable
  239. * to the given integer, and the use_pages variable to true.
  240. * @param int $perpage
  241. * @param int $total
  242. * @return void
  243. */
  244. function pagesize($perpage, $total) {
  245. $this->pagesize = $perpage;
  246. $this->totalrows = $total;
  247. $this->use_pages = true;
  248. }
  249. /**
  250. * Assigns each given variable in the array to the corresponding index
  251. * in the request class variable.
  252. * @param array $variables
  253. * @return void
  254. */
  255. function set_control_variables($variables) {
  256. foreach ($variables as $what => $variable) {
  257. if (isset($this->request[$what])) {
  258. $this->request[$what] = $variable;
  259. }
  260. }
  261. }
  262. /**
  263. * Gives the given $value to the $attribute index of $this->attributes.
  264. * @param string $attribute
  265. * @param mixed $value
  266. * @return void
  267. */
  268. function set_attribute($attribute, $value) {
  269. $this->attributes[$attribute] = $value;
  270. }
  271. /**
  272. * What this method does is set the column so that if the same data appears in
  273. * consecutive rows, then it is not repeated.
  274. *
  275. * For example, in the quiz overview report, the fullname column is set to be suppressed, so
  276. * that when one student has made multiple attempts, their name is only printed in the row
  277. * for their first attempt.
  278. * @param int $column the index of a column.
  279. */
  280. function column_suppress($column) {
  281. if (isset($this->column_suppress[$column])) {
  282. $this->column_suppress[$column] = true;
  283. }
  284. }
  285. /**
  286. * Sets the given $column index to the given $classname in $this->column_class.
  287. * @param int $column
  288. * @param string $classname
  289. * @return void
  290. */
  291. function column_class($column, $classname) {
  292. if (isset($this->column_class[$column])) {
  293. $this->column_class[$column] = ' '.$classname; // This space needed so that classnames don't run together in the HTML
  294. }
  295. }
  296. /**
  297. * Sets the given $column index and $property index to the given $value in $this->column_style.
  298. * @param int $column
  299. * @param string $property
  300. * @param mixed $value
  301. * @return void
  302. */
  303. function column_style($column, $property, $value) {
  304. if (isset($this->column_style[$column])) {
  305. $this->column_style[$column][$property] = $value;
  306. }
  307. }
  308. /**
  309. * Sets all columns' $propertys to the given $value in $this->column_style.
  310. * @param int $property
  311. * @param string $value
  312. * @return void
  313. */
  314. function column_style_all($property, $value) {
  315. foreach (array_keys($this->columns) as $column) {
  316. $this->column_style[$column][$property] = $value;
  317. }
  318. }
  319. /**
  320. * Sets $this->baseurl.
  321. * @param moodle_url|string $url the url with params needed to call up this page
  322. */
  323. function define_baseurl($url) {
  324. $this->baseurl = new moodle_url($url);
  325. }
  326. /**
  327. * @param array $columns an array of identifying names for columns. If
  328. * columns are sorted then column names must correspond to a field in sql.
  329. */
  330. function define_columns($columns) {
  331. $this->columns = array();
  332. $this->column_style = array();
  333. $this->column_class = array();
  334. $colnum = 0;
  335. foreach ($columns as $column) {
  336. $this->columns[$column] = $colnum++;
  337. $this->column_style[$column] = array();
  338. $this->column_class[$column] = '';
  339. $this->column_suppress[$column] = false;
  340. }
  341. }
  342. /**
  343. * @param array $headers numerical keyed array of displayed string titles
  344. * for each column.
  345. */
  346. function define_headers($headers) {
  347. $this->headers = $headers;
  348. }
  349. /**
  350. * Must be called after table is defined. Use methods above first. Cannot
  351. * use functions below till after calling this method.
  352. * @return type?
  353. */
  354. function setup() {
  355. global $SESSION, $CFG;
  356. if (empty($this->columns) || empty($this->uniqueid)) {
  357. return false;
  358. }
  359. if (!isset($SESSION->flextable)) {
  360. $SESSION->flextable = array();
  361. }
  362. if (!isset($SESSION->flextable[$this->uniqueid])) {
  363. $SESSION->flextable[$this->uniqueid] = new stdClass;
  364. $SESSION->flextable[$this->uniqueid]->uniqueid = $this->uniqueid;
  365. $SESSION->flextable[$this->uniqueid]->collapse = array();
  366. $SESSION->flextable[$this->uniqueid]->sortby = array();
  367. $SESSION->flextable[$this->uniqueid]->i_first = '';
  368. $SESSION->flextable[$this->uniqueid]->i_last = '';
  369. }
  370. $this->sess = &$SESSION->flextable[$this->uniqueid];
  371. if (($showcol = optional_param($this->request[TABLE_VAR_SHOW], '', PARAM_ALPHANUMEXT)) &&
  372. isset($this->columns[$showcol])) {
  373. $this->sess->collapse[$showcol] = false;
  374. } else if (($hidecol = optional_param($this->request[TABLE_VAR_HIDE], '', PARAM_ALPHANUMEXT)) &&
  375. isset($this->columns[$hidecol])) {
  376. $this->sess->collapse[$hidecol] = true;
  377. if (array_key_exists($hidecol, $this->sess->sortby)) {
  378. unset($this->sess->sortby[$hidecol]);
  379. }
  380. }
  381. // Now, update the column attributes for collapsed columns
  382. foreach (array_keys($this->columns) as $column) {
  383. if (!empty($this->sess->collapse[$column])) {
  384. $this->column_style[$column]['width'] = '10px';
  385. }
  386. }
  387. if (($sortcol = optional_param($this->request[TABLE_VAR_SORT], '', PARAM_ALPHANUMEXT)) &&
  388. $this->is_sortable($sortcol) && empty($this->sess->collapse[$sortcol]) &&
  389. (isset($this->columns[$sortcol]) || in_array($sortcol, array('firstname', 'lastname')) && isset($this->columns['fullname']))) {
  390. if (array_key_exists($sortcol, $this->sess->sortby)) {
  391. // This key already exists somewhere. Change its sortorder and bring it to the top.
  392. $sortorder = $this->sess->sortby[$sortcol] == SORT_ASC ? SORT_DESC : SORT_ASC;
  393. unset($this->sess->sortby[$sortcol]);
  394. $this->sess->sortby = array_merge(array($sortcol => $sortorder), $this->sess->sortby);
  395. } else {
  396. // Key doesn't exist, so just add it to the beginning of the array, ascending order
  397. $this->sess->sortby = array_merge(array($sortcol => SORT_ASC), $this->sess->sortby);
  398. }
  399. // Finally, make sure that no more than $this->maxsortkeys are present into the array
  400. $this->sess->sortby = array_slice($this->sess->sortby, 0, $this->maxsortkeys);
  401. }
  402. // If we didn't sort just now, then use the default sort order if one is defined and the column exists
  403. if (empty($this->sess->sortby) && !empty($this->sort_default_column)) {
  404. $this->sess->sortby = array ($this->sort_default_column => ($this->sort_default_order == SORT_DESC ? SORT_DESC : SORT_ASC));
  405. }
  406. $ilast = optional_param($this->request[TABLE_VAR_ILAST], null, PARAM_RAW);
  407. if (!is_null($ilast) && ($ilast ==='' || strpos(get_string('alphabet', 'langconfig'), $ilast) !== false)) {
  408. $this->sess->i_last = $ilast;
  409. }
  410. $ifirst = optional_param($this->request[TABLE_VAR_IFIRST], null, PARAM_RAW);
  411. if (!is_null($ifirst) && ($ifirst === '' || strpos(get_string('alphabet', 'langconfig'), $ifirst) !== false)) {
  412. $this->sess->i_first = $ifirst;
  413. }
  414. if (empty($this->baseurl)) {
  415. debugging('You should set baseurl when using flexible_table.');
  416. global $PAGE;
  417. $this->baseurl = $PAGE->url;
  418. }
  419. $this->currpage = optional_param($this->request[TABLE_VAR_PAGE], 0, PARAM_INT);
  420. $this->setup = true;
  421. // Always introduce the "flexible" class for the table if not specified
  422. if (empty($this->attributes)) {
  423. $this->attributes['class'] = 'flexible';
  424. } else if (!isset($this->attributes['class'])) {
  425. $this->attributes['class'] = 'flexible';
  426. } else if (!in_array('flexible', explode(' ', $this->attributes['class']))) {
  427. $this->attributes['class'] = trim('flexible ' . $this->attributes['class']);
  428. }
  429. }
  430. /**
  431. * Get the order by clause from the session, for the table with id $uniqueid.
  432. * @param string $uniqueid the identifier for a table.
  433. * @return SQL fragment that can be used in an ORDER BY clause.
  434. */
  435. public static function get_sort_for_table($uniqueid) {
  436. global $SESSION;
  437. if (empty($SESSION->flextable[$uniqueid])) {
  438. return '';
  439. }
  440. $sess = &$SESSION->flextable[$uniqueid];
  441. if (empty($sess->sortby)) {
  442. return '';
  443. }
  444. return self::construct_order_by($sess->sortby);
  445. }
  446. /**
  447. * Prepare an an order by clause from the list of columns to be sorted.
  448. * @param array $cols column name => SORT_ASC or SORT_DESC
  449. * @return SQL fragment that can be used in an ORDER BY clause.
  450. */
  451. public static function construct_order_by($cols) {
  452. $bits = array();
  453. foreach ($cols as $column => $order) {
  454. if ($order == SORT_ASC) {
  455. $bits[] = $column . ' ASC';
  456. } else {
  457. $bits[] = $column . ' DESC';
  458. }
  459. }
  460. return implode(', ', $bits);
  461. }
  462. /**
  463. * @return SQL fragment that can be used in an ORDER BY clause.
  464. */
  465. public function get_sql_sort() {
  466. return self::construct_order_by($this->get_sort_columns());
  467. }
  468. /**
  469. * Get the columns to sort by, in the form required by {@link construct_order_by()}.
  470. * @return array column name => SORT_... constant.
  471. */
  472. public function get_sort_columns() {
  473. if (!$this->setup) {
  474. throw new coding_exception('Cannot call get_sort_columns until you have called setup.');
  475. }
  476. if (empty($this->sess->sortby)) {
  477. return array();
  478. }
  479. foreach ($this->sess->sortby as $column => $notused) {
  480. if (isset($this->columns[$column])) {
  481. continue; // This column is OK.
  482. }
  483. if (in_array($column, array('firstname', 'lastname')) &&
  484. isset($this->columns['fullname'])) {
  485. continue; // This column is OK.
  486. }
  487. // This column is not OK.
  488. unset($this->sess->sortby[$column]);
  489. }
  490. return $this->sess->sortby;
  491. }
  492. /**
  493. * @return int the offset for LIMIT clause of SQL
  494. */
  495. function get_page_start() {
  496. if (!$this->use_pages) {
  497. return '';
  498. }
  499. return $this->currpage * $this->pagesize;
  500. }
  501. /**
  502. * @return int the pagesize for LIMIT clause of SQL
  503. */
  504. function get_page_size() {
  505. if (!$this->use_pages) {
  506. return '';
  507. }
  508. return $this->pagesize;
  509. }
  510. /**
  511. * @return string sql to add to where statement.
  512. */
  513. function get_sql_where() {
  514. global $DB;
  515. $conditions = array();
  516. $params = array();
  517. if (isset($this->columns['fullname'])) {
  518. static $i = 0;
  519. $i++;
  520. if (!empty($this->sess->i_first)) {
  521. $conditions[] = $DB->sql_like('firstname', ':ifirstc'.$i, false, false);
  522. $params['ifirstc'.$i] = $this->sess->i_first.'%';
  523. }
  524. if (!empty($this->sess->i_last)) {
  525. $conditions[] = $DB->sql_like('lastname', ':ilastc'.$i, false, false);
  526. $params['ilastc'.$i] = $this->sess->i_last.'%';
  527. }
  528. }
  529. return array(implode(" AND ", $conditions), $params);
  530. }
  531. /**
  532. * Add a row of data to the table. This function takes an array with
  533. * column names as keys.
  534. * It ignores any elements with keys that are not defined as columns. It
  535. * puts in empty strings into the row when there is no element in the passed
  536. * array corresponding to a column in the table. It puts the row elements in
  537. * the proper order.
  538. * @param $rowwithkeys array
  539. * @param string $classname CSS class name to add to this row's tr tag.
  540. */
  541. function add_data_keyed($rowwithkeys, $classname = '') {
  542. $this->add_data($this->get_row_from_keyed($rowwithkeys), $classname);
  543. }
  544. /**
  545. * Add a seperator line to table.
  546. */
  547. function add_separator() {
  548. if (!$this->setup) {
  549. return false;
  550. }
  551. $this->add_data(NULL);
  552. }
  553. /**
  554. * This method actually directly echoes the row passed to it now or adds it
  555. * to the download. If this is the first row and start_output has not
  556. * already been called this method also calls start_output to open the table
  557. * or send headers for the downloaded.
  558. * Can be used as before. print_html now calls finish_html to close table.
  559. *
  560. * @param array $row a numerically keyed row of data to add to the table.
  561. * @param string $classname CSS class name to add to this row's tr tag.
  562. * @return bool success.
  563. */
  564. function add_data($row, $classname = '') {
  565. if (!$this->setup) {
  566. return false;
  567. }
  568. if (!$this->started_output) {
  569. $this->start_output();
  570. }
  571. if ($this->exportclass!==null) {
  572. if ($row === null) {
  573. $this->exportclass->add_seperator();
  574. } else {
  575. $this->exportclass->add_data($row);
  576. }
  577. } else {
  578. $this->print_row($row, $classname);
  579. }
  580. return true;
  581. }
  582. /**
  583. * You should call this to finish outputting the table data after adding
  584. * data to the table with add_data or add_data_keyed.
  585. *
  586. */
  587. function finish_output($closeexportclassdoc = true) {
  588. if ($this->exportclass!==null) {
  589. $this->exportclass->finish_table();
  590. if ($closeexportclassdoc) {
  591. $this->exportclass->finish_document();
  592. }
  593. } else {
  594. $this->finish_html();
  595. }
  596. }
  597. /**
  598. * Hook that can be overridden in child classes to wrap a table in a form
  599. * for example. Called only when there is data to display and not
  600. * downloading.
  601. */
  602. function wrap_html_start() {
  603. }
  604. /**
  605. * Hook that can be overridden in child classes to wrap a table in a form
  606. * for example. Called only when there is data to display and not
  607. * downloading.
  608. */
  609. function wrap_html_finish() {
  610. }
  611. /**
  612. *
  613. * @param array $row row of data from db used to make one row of the table.
  614. * @return array one row for the table, added using add_data_keyed method.
  615. */
  616. function format_row($row) {
  617. $formattedrow = array();
  618. foreach (array_keys($this->columns) as $column) {
  619. $colmethodname = 'col_'.$column;
  620. if (method_exists($this, $colmethodname)) {
  621. $formattedcolumn = $this->$colmethodname($row);
  622. } else {
  623. $formattedcolumn = $this->other_cols($column, $row);
  624. if ($formattedcolumn===NULL) {
  625. $formattedcolumn = $row->$column;
  626. }
  627. }
  628. $formattedrow[$column] = $formattedcolumn;
  629. }
  630. return $formattedrow;
  631. }
  632. /**
  633. * Fullname is treated as a special columname in tablelib and should always
  634. * be treated the same as the fullname of a user.
  635. * @uses $this->useridfield if the userid field is not expected to be id
  636. * then you need to override $this->useridfield to point at the correct
  637. * field for the user id.
  638. *
  639. */
  640. function col_fullname($row) {
  641. global $COURSE, $CFG;
  642. if (!$this->download) {
  643. $profileurl = new moodle_url('/user/profile.php', array('id' => $row->{$this->useridfield}));
  644. if ($COURSE->id != SITEID) {
  645. $profileurl->param('course', $COURSE->id);
  646. }
  647. return html_writer::link($profileurl, fullname($row));
  648. } else {
  649. return fullname($row);
  650. }
  651. }
  652. /**
  653. * You can override this method in a child class. See the description of
  654. * build_table which calls this method.
  655. */
  656. function other_cols($column, $row) {
  657. return NULL;
  658. }
  659. /**
  660. * Used from col_* functions when text is to be displayed. Does the
  661. * right thing - either converts text to html or strips any html tags
  662. * depending on if we are downloading and what is the download type. Params
  663. * are the same as format_text function in weblib.php but some default
  664. * options are changed.
  665. */
  666. function format_text($text, $format=FORMAT_MOODLE, $options=NULL, $courseid=NULL) {
  667. if (!$this->is_downloading()) {
  668. if (is_null($options)) {
  669. $options = new stdClass;
  670. }
  671. //some sensible defaults
  672. if (!isset($options->para)) {
  673. $options->para = false;
  674. }
  675. if (!isset($options->newlines)) {
  676. $options->newlines = false;
  677. }
  678. if (!isset($options->smiley)) {
  679. $options->smiley = false;
  680. }
  681. if (!isset($options->filter)) {
  682. $options->filter = false;
  683. }
  684. return format_text($text, $format, $options);
  685. } else {
  686. $eci =& $this->export_class_instance();
  687. return $eci->format_text($text, $format, $options, $courseid);
  688. }
  689. }
  690. /**
  691. * This method is deprecated although the old api is still supported.
  692. * @deprecated 1.9.2 - Jun 2, 2008
  693. */
  694. function print_html() {
  695. if (!$this->setup) {
  696. return false;
  697. }
  698. $this->finish_html();
  699. }
  700. /**
  701. * This function is not part of the public api.
  702. * @return string initial of first name we are currently filtering by
  703. */
  704. function get_initial_first() {
  705. if (!$this->use_initials) {
  706. return NULL;
  707. }
  708. return $this->sess->i_first;
  709. }
  710. /**
  711. * This function is not part of the public api.
  712. * @return string initial of last name we are currently filtering by
  713. */
  714. function get_initial_last() {
  715. if (!$this->use_initials) {
  716. return NULL;
  717. }
  718. return $this->sess->i_last;
  719. }
  720. /**
  721. * Helper function, used by {@link print_initials_bar()} to output one initial bar.
  722. * @param array $alpha of letters in the alphabet.
  723. * @param string $current the currently selected letter.
  724. * @param string $class class name to add to this initial bar.
  725. * @param string $title the name to put in front of this initial bar.
  726. * @param string $urlvar URL parameter name for this initial.
  727. */
  728. protected function print_one_initials_bar($alpha, $current, $class, $title, $urlvar) {
  729. echo html_writer::start_tag('div', array('class' => 'initialbar ' . $class)) .
  730. $title . ' : ';
  731. if ($current) {
  732. echo html_writer::link($this->baseurl->out(false, array($urlvar => '')), get_string('all'));
  733. } else {
  734. echo html_writer::tag('strong', get_string('all'));
  735. }
  736. foreach ($alpha as $letter) {
  737. if ($letter === $current) {
  738. echo html_writer::tag('strong', $letter);
  739. } else {
  740. echo html_writer::link($this->baseurl->out(false, array($urlvar => $letter)), $letter);
  741. }
  742. }
  743. echo html_writer::end_tag('div');
  744. }
  745. /**
  746. * This function is not part of the public api.
  747. */
  748. function print_initials_bar() {
  749. if ((!empty($this->sess->i_last) || !empty($this->sess->i_first) ||$this->use_initials)
  750. && isset($this->columns['fullname'])) {
  751. $alpha = explode(',', get_string('alphabet', 'langconfig'));
  752. // Bar of first initials
  753. if (!empty($this->sess->i_first)) {
  754. $ifirst = $this->sess->i_first;
  755. } else {
  756. $ifirst = '';
  757. }
  758. $this->print_one_initials_bar($alpha, $ifirst, 'firstinitial',
  759. get_string('firstname'), $this->request[TABLE_VAR_IFIRST]);
  760. // Bar of last initials
  761. if (!empty($this->sess->i_last)) {
  762. $ilast = $this->sess->i_last;
  763. } else {
  764. $ilast = '';
  765. }
  766. $this->print_one_initials_bar($alpha, $ilast, 'lastinitial',
  767. get_string('lastname'), $this->request[TABLE_VAR_ILAST]);
  768. }
  769. }
  770. /**
  771. * This function is not part of the public api.
  772. */
  773. function print_nothing_to_display() {
  774. global $OUTPUT;
  775. $this->print_initials_bar();
  776. echo $OUTPUT->heading(get_string('nothingtodisplay'));
  777. }
  778. /**
  779. * This function is not part of the public api.
  780. */
  781. function get_row_from_keyed($rowwithkeys) {
  782. if (is_object($rowwithkeys)) {
  783. $rowwithkeys = (array)$rowwithkeys;
  784. }
  785. $row = array();
  786. foreach (array_keys($this->columns) as $column) {
  787. if (isset($rowwithkeys[$column])) {
  788. $row [] = $rowwithkeys[$column];
  789. } else {
  790. $row[] ='';
  791. }
  792. }
  793. return $row;
  794. }
  795. /**
  796. * This function is not part of the public api.
  797. */
  798. function get_download_menu() {
  799. $allclasses= get_declared_classes();
  800. $exportclasses = array();
  801. foreach ($allclasses as $class) {
  802. $matches = array();
  803. if (preg_match('/^table\_([a-z]+)\_export\_format$/', $class, $matches)) {
  804. $type = $matches[1];
  805. $exportclasses[$type]= get_string("download$type", 'table');
  806. }
  807. }
  808. return $exportclasses;
  809. }
  810. /**
  811. * This function is not part of the public api.
  812. */
  813. function download_buttons() {
  814. if ($this->is_downloadable() && !$this->is_downloading()) {
  815. $downloadoptions = $this->get_download_menu();
  816. $html = '<form action="'. $this->baseurl .'" method="post">';
  817. $html .= '<div class="mdl-align">';
  818. $html .= '<input type="submit" value="'.get_string('downloadas', 'table').'"/>';
  819. $html .= html_writer::label(get_string('downloadoptions', 'table'), 'menudownload', false, array('class' => 'accesshide'));
  820. $html .= html_writer::select($downloadoptions, 'download', $this->defaultdownloadformat, false);
  821. $html .= '</div></form>';
  822. return $html;
  823. } else {
  824. return '';
  825. }
  826. }
  827. /**
  828. * This function is not part of the public api.
  829. * You don't normally need to call this. It is called automatically when
  830. * needed when you start adding data to the table.
  831. *
  832. */
  833. function start_output() {
  834. $this->started_output = true;
  835. if ($this->exportclass!==null) {
  836. $this->exportclass->start_table($this->sheettitle);
  837. $this->exportclass->output_headers($this->headers);
  838. } else {
  839. $this->start_html();
  840. $this->print_headers();
  841. }
  842. }
  843. /**
  844. * This function is not part of the public api.
  845. */
  846. function print_row($row, $classname = '') {
  847. static $suppress_lastrow = NULL;
  848. static $oddeven = 1;
  849. $rowclasses = array('r' . $oddeven);
  850. $oddeven = $oddeven ? 0 : 1;
  851. if ($classname) {
  852. $rowclasses[] = $classname;
  853. }
  854. echo html_writer::start_tag('tr', array('class' => implode(' ', $rowclasses)));
  855. // If we have a separator, print it
  856. if ($row === NULL) {
  857. $colcount = count($this->columns);
  858. echo html_writer::tag('td', html_writer::tag('div', '',
  859. array('class' => 'tabledivider')), array('colspan' => $colcount));
  860. } else {
  861. $colbyindex = array_flip($this->columns);
  862. foreach ($row as $index => $data) {
  863. $column = $colbyindex[$index];
  864. if (empty($this->sess->collapse[$column])) {
  865. if ($this->column_suppress[$column] && $suppress_lastrow !== NULL && $suppress_lastrow[$index] === $data) {
  866. $content = '&nbsp;';
  867. } else {
  868. $content = $data;
  869. }
  870. } else {
  871. $content = '&nbsp;';
  872. }
  873. echo html_writer::tag('td', $content, array(
  874. 'class' => 'cell c' . $index . $this->column_class[$column],
  875. 'style' => $this->make_styles_string($this->column_style[$column])));
  876. }
  877. }
  878. echo html_writer::end_tag('tr');
  879. $suppress_enabled = array_sum($this->column_suppress);
  880. if ($suppress_enabled) {
  881. $suppress_lastrow = $row;
  882. }
  883. }
  884. /**
  885. * This function is not part of the public api.
  886. */
  887. function finish_html() {
  888. global $OUTPUT;
  889. if (!$this->started_output) {
  890. //no data has been added to the table.
  891. $this->print_nothing_to_display();
  892. } else {
  893. echo html_writer::end_tag('table');
  894. echo html_writer::end_tag('div');
  895. $this->wrap_html_finish();
  896. // Paging bar
  897. if(in_array(TABLE_P_BOTTOM, $this->showdownloadbuttonsat)) {
  898. echo $this->download_buttons();
  899. }
  900. if($this->use_pages) {
  901. $pagingbar = new paging_bar($this->totalrows, $this->currpage, $this->pagesize, $this->baseurl);
  902. $pagingbar->pagevar = $this->request[TABLE_VAR_PAGE];
  903. echo $OUTPUT->render($pagingbar);
  904. }
  905. }
  906. }
  907. /**
  908. * Generate the HTML for the collapse/uncollapse icon. This is a helper method
  909. * used by {@link print_headers()}.
  910. * @param string $column the column name, index into various names.
  911. * @param int $index numerical index of the column.
  912. * @return string HTML fragment.
  913. */
  914. protected function show_hide_link($column, $index) {
  915. global $OUTPUT;
  916. // Some headers contain <br /> tags, do not include in title, hence the
  917. // strip tags.
  918. if (!empty($this->sess->collapse[$column])) {
  919. return html_writer::link($this->baseurl->out(false, array($this->request[TABLE_VAR_SHOW] => $column)),
  920. html_writer::empty_tag('img', array('src' => $OUTPUT->pix_url('t/switch_plus'), 'alt' => get_string('show'))),
  921. array('title' => get_string('show') . ' ' . strip_tags($this->headers[$index])));
  922. } else if ($this->headers[$index] !== NULL) {
  923. return html_writer::link($this->baseurl->out(false, array($this->request[TABLE_VAR_HIDE] => $column)),
  924. html_writer::empty_tag('img', array('src' => $OUTPUT->pix_url('t/switch_minus'), 'alt' => get_string('hide'))),
  925. array('title' => get_string('hide') . ' ' . strip_tags($this->headers[$index])));
  926. }
  927. }
  928. /**
  929. * This function is not part of the public api.
  930. */
  931. function print_headers() {
  932. global $CFG, $OUTPUT;
  933. echo html_writer::start_tag('thead');
  934. echo html_writer::start_tag('tr');
  935. foreach ($this->columns as $column => $index) {
  936. $icon_hide = '';
  937. if ($this->is_collapsible) {
  938. $icon_hide = $this->show_hide_link($column, $index);
  939. }
  940. $primary_sort_column = '';
  941. $primary_sort_order = '';
  942. if (reset($this->sess->sortby)) {
  943. $primary_sort_column = key($this->sess->sortby);
  944. $primary_sort_order = current($this->sess->sortby);
  945. }
  946. switch ($column) {
  947. case 'fullname':
  948. if ($this->is_sortable($column)) {
  949. $firstnamesortlink = $this->sort_link(get_string('firstname'),
  950. 'firstname', $primary_sort_column === 'firstname', $primary_sort_order);
  951. $lastnamesortlink = $this->sort_link(get_string('lastname'),
  952. 'lastname', $primary_sort_column === 'lastname', $primary_sort_order);
  953. $override = new stdClass();
  954. $override->firstname = 'firstname';
  955. $override->lastname = 'lastname';
  956. $fullnamelanguage = get_string('fullnamedisplay', '', $override);
  957. if (($CFG->fullnamedisplay == 'firstname lastname') or
  958. ($CFG->fullnamedisplay == 'firstname') or
  959. ($CFG->fullnamedisplay == 'language' and $fullnamelanguage == 'firstname lastname' )) {
  960. $this->headers[$index] = $firstnamesortlink . ' / ' . $lastnamesortlink;
  961. } else {
  962. $this->headers[$index] = $lastnamesortlink . ' / ' . $firstnamesortlink;
  963. }
  964. }
  965. break;
  966. case 'userpic':
  967. // do nothing, do not display sortable links
  968. break;
  969. default:
  970. if ($this->is_sortable($column)) {
  971. $this->headers[$index] = $this->sort_link($this->headers[$index],
  972. $column, $primary_sort_column == $column, $primary_sort_order);
  973. }
  974. }
  975. $attributes = array(
  976. 'class' => 'header c' . $index . $this->column_class[$column],
  977. 'scope' => 'col',
  978. );
  979. if ($this->headers[$index] === NULL) {
  980. $content = '&nbsp;';
  981. } else if (!empty($this->sess->collapse[$column])) {
  982. $content = $icon_hide;
  983. } else {
  984. if (is_array($this->column_style[$column])) {
  985. $attributes['style'] = $this->make_styles_string($this->column_style[$column]);
  986. }
  987. $content = $this->headers[$index] . html_writer::tag('div',
  988. $icon_hide, array('class' => 'commands'));
  989. }
  990. echo html_writer::tag('th', $content, $attributes);
  991. }
  992. echo html_writer::end_tag('tr');
  993. echo html_writer::end_tag('thead');
  994. }
  995. /**
  996. * Generate the HTML for the sort icon. This is a helper method used by {@link sort_link()}.
  997. * @param bool $isprimary whether an icon is needed (it is only needed for the primary sort column.)
  998. * @param int $order SORT_ASC or SORT_DESC
  999. * @return string HTML fragment.
  1000. */
  1001. protected function sort_icon($isprimary, $order) {
  1002. global $OUTPUT;
  1003. if (!$isprimary) {
  1004. return '';
  1005. }
  1006. if ($order == SORT_ASC) {
  1007. return html_writer::empty_tag('img',
  1008. array('src' => $OUTPUT->pix_url('t/down'), 'alt' => get_string('asc')));
  1009. } else {
  1010. return html_writer::empty_tag('img',
  1011. array('src' => $OUTPUT->pix_url('t/up'), 'alt' => get_string('desc')));
  1012. }
  1013. }
  1014. /**
  1015. * Generate the correct tool tip for changing the sort order. This is a
  1016. * helper method used by {@link sort_link()}.
  1017. * @param bool $isprimary whether the is column is the current primary sort column.
  1018. * @param int $order SORT_ASC or SORT_DESC
  1019. * @return string the correct title.
  1020. */
  1021. protected function sort_order_name($isprimary, $order) {
  1022. if ($isprimary && $order != SORT_ASC) {
  1023. return get_string('desc');
  1024. } else {
  1025. return get_string('asc');
  1026. }
  1027. }
  1028. /**
  1029. * Generate the HTML for the sort link. This is a helper method used by {@link print_headers()}.
  1030. * @param string $text the text for the link.
  1031. * @param string $column the column name, may be a fake column like 'firstname' or a real one.
  1032. * @param bool $isprimary whether the is column is the current primary sort column.
  1033. * @param int $order SORT_ASC or SORT_DESC
  1034. * @return string HTML fragment.
  1035. */
  1036. protected function sort_link($text, $column, $isprimary, $order) {
  1037. return html_writer::link($this->baseurl->out(false,
  1038. array($this->request[TABLE_VAR_SORT] => $column)),
  1039. $text . get_accesshide(get_string('sortby') . ' ' .
  1040. $text . ' ' . $this->sort_order_name($isprimary, $order))) . ' ' .
  1041. $this->sort_icon($isprimary, $order);
  1042. }
  1043. /**
  1044. * This function is not part of the public api.
  1045. */
  1046. function start_html() {
  1047. global $OUTPUT;
  1048. // Do we need to print initial bars?
  1049. $this->print_initials_bar();
  1050. // Paging bar
  1051. if ($this->use_pages) {
  1052. $pagingbar = new paging_bar($this->totalrows, $this->currpage, $this->pagesize, $this->baseurl);
  1053. $pagingbar->pagevar = $this->request[TABLE_VAR_PAGE];
  1054. echo $OUTPUT->render($pagingbar);
  1055. }
  1056. if (in_array(TABLE_P_TOP, $this->showdownloadbuttonsat)) {
  1057. echo $this->download_buttons();
  1058. }
  1059. $this->wrap_html_start();
  1060. // Start of main data table
  1061. echo html_writer::start_tag('div', array('class' => 'no-overflow'));
  1062. echo html_writer::start_tag('table', $this->attributes);
  1063. }
  1064. /**
  1065. * This function is not part of the public api.
  1066. * @param array $styles CSS-property => value
  1067. * @return string values suitably to go in a style="" attribute in HTML.
  1068. */
  1069. function make_styles_string($styles) {
  1070. if (empty($styles)) {
  1071. return null;
  1072. }
  1073. $string = '';
  1074. foreach($styles as $property => $value) {
  1075. $string .= $property . ':' . $value . ';';
  1076. }
  1077. return $string;
  1078. }
  1079. }
  1080. /**
  1081. * @package moodlecore
  1082. * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
  1083. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  1084. */
  1085. class table_sql extends flexible_table {
  1086. public $countsql = NULL;
  1087. public $countparams = NULL;
  1088. /**
  1089. * @var object sql for querying db. Has fields 'fields', 'from', 'where', 'params'.
  1090. */
  1091. public $sql = NULL;
  1092. /**
  1093. * @var array Data fetched from the db.
  1094. */
  1095. public $rawdata = NULL;
  1096. /**
  1097. * @var bool Overriding default for this.
  1098. */
  1099. public $is_sortable = true;
  1100. /**
  1101. * @var bool Overriding default for this.
  1102. */
  1103. public $is_collapsible = true;
  1104. /**
  1105. * @param string $uniqueid a string identifying this table.Used as a key in
  1106. * session vars.
  1107. */
  1108. function __construct($uniqueid) {
  1109. parent::__construct($uniqueid);
  1110. // some sensible defaults
  1111. $this->set_attribute('cellspacing', '0');
  1112. $this->set_attribute('class', 'generaltable generalbox');
  1113. }
  1114. /**
  1115. * Take the data returned from the db_query and go through all the rows
  1116. * processing each col using either col_{columnname} method or other_cols
  1117. * method or if other_cols returns NULL then put the data straight into the
  1118. * table.
  1119. */
  1120. function build_table() {
  1121. if ($this->rawdata) {
  1122. foreach ($this->rawdata as $row) {
  1123. $formattedrow = $this->format_row($row);
  1124. $this->add_data_keyed($formattedrow,
  1125. $this->get_row_class($row));
  1126. }
  1127. }
  1128. }
  1129. /**
  1130. * Get any extra classes names to add to this row in the HTML.
  1131. * @param $row array the data for this row.
  1132. * @return string added to the class="" attribute of the tr.
  1133. */
  1134. function get_row_class($row) {
  1135. return '';
  1136. }
  1137. /**
  1138. * This is only needed if you want to use different sql to count rows.
  1139. * Used for example when perhaps all db JOINS are not needed when counting
  1140. * records. You don't need to call this function the count_sql
  1141. * will be generated automatically.
  1142. *
  1143. * We need to count rows returned by the db seperately to the query itself
  1144. * as we need to know how many pages of data we have to display.
  1145. */
  1146. function set_count_sql($sql, array $params = NULL) {
  1147. $this->countsql = $sql;
  1148. $this->countparams = $params;
  1149. }
  1150. /**
  1151. * Set the sql to query the db. Query will be :
  1152. * SELECT $fields FROM $from WHERE $where
  1153. * Of course you can use sub-queries, JOINS etc. by putting them in the
  1154. * appropriate clause of the query.
  1155. */
  1156. function set_sql($fields, $from, $where, array $params = NULL) {
  1157. $this->sql = new stdClass();
  1158. $this->sql->fields = $fields;
  1159. $this->sql->from = $from;
  1160. $this->sql->where = $where;
  1161. $this->sql->params = $params;
  1162. }
  1163. /**
  1164. * Query the db. Store results in the table object for use by build_table.
  1165. *
  1166. * @param int $pagesize size of page for paginated displayed table.
  1167. * @param bool $useinitialsbar do you want to use the initials bar. Bar
  1168. * will only be used if there is a fullname column defined for the table.
  1169. */
  1170. function query_db($pagesize, $useinitialsbar=true) {
  1171. global $DB;
  1172. if (!$this->is_downloading()) {
  1173. if ($this->countsql === NULL) {
  1174. $this->countsql = 'SELECT COUNT(1) FROM '.$this->sql->from.' WHERE '.$this->sql->where;
  1175. $this->countparams = $this->sql->params;
  1176. }
  1177. $grandtotal = $DB->count_records_sql($this->countsql, $this->countparams);
  1178. if ($useinitialsbar && !$this->is_downloading()) {
  1179. $this->initialbars($grandtotal > $pagesize);
  1180. }
  1181. list($wsql, $wparams) = $this->get_sql_where();
  1182. if ($wsql) {
  1183. $this->countsql .= ' AND '.$wsql;
  1184. $this->countparams = array_merge($this->countparams, $wparams);
  1185. $this->sql->where .= ' AND '.$wsql;
  1186. $this->sql->params = array_merge($this->sql->params, $wparams);
  1187. $total = $DB->count_records_sql($this->countsql, $this->countparams);
  1188. } else {
  1189. $total = $grandtotal;
  1190. }
  1191. $this->pagesize($pagesize, $total);
  1192. }
  1193. // Fetch the attempts
  1194. $sort = $this->get_sql_sort();
  1195. if ($sort) {
  1196. $sort = "ORDER BY $sort";
  1197. }
  1198. $sql = "SELECT
  1199. {$this->sql->fields}
  1200. FROM {$this->sql->from}
  1201. WHERE {$this->sql->where}
  1202. {$sort}";
  1203. if (!$this->is_downloading()) {
  1204. $this->rawdata = $DB->get_records_sql($sql, $this->sql->params, $this->get_page_start(), $this->get_page_size());
  1205. } else {
  1206. $this->rawdata = $DB->get_records_sql($sql, $this->sql->params);
  1207. }
  1208. }
  1209. /**
  1210. * Convenience method to call a number of methods for you to display the
  1211. * table.
  1212. */
  1213. function out($pagesize, $useinitialsbar, $downloadhelpbutton='') {
  1214. global $DB;
  1215. if (!$this->columns) {
  1216. $onerow = $DB->get_record_sql("SELECT {$this->sql->fields} FROM {$this->sql->from} WHERE {$this->sql->where}", $this->sql->params);
  1217. //if columns is not set then define columns as the keys of the rows returned
  1218. //from the db.
  1219. $this->define_columns(array_keys((array)$onerow));
  1220. $this->define_headers(array_keys((array)$onerow));
  1221. }
  1222. $this->setup();
  1223. $this->query_db($pagesize, $useinitialsbar);
  1224. $this->build_table();
  1225. $this->finish_output();
  1226. }
  1227. }
  1228. /**
  1229. * @package moodlecore
  1230. * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
  1231. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  1232. */
  1233. class table_default_export_format_parent {
  1234. /**
  1235. * @var flexible_table or child class reference pointing to table class
  1236. * object from which to export data.
  1237. */
  1238. var $table;
  1239. /**
  1240. * @var bool output started. Keeps track of whether any output has been
  1241. * started yet.
  1242. */
  1243. var $documentstarted = false;
  1244. function table_default_export_format_parent(&$table) {
  1245. $this->table =& $table;
  1246. }
  1247. function set_table(&$table) {
  1248. $this->table =& $table;
  1249. }
  1250. function add_data($row) {
  1251. return false;
  1252. }
  1253. function add_seperator() {
  1254. return false;
  1255. }
  1256. function document_started() {
  1257. return $this->documentstarted;
  1258. }
  1259. /**
  1260. * Given text in a variety of format codings, this function returns
  1261. * the text as safe HTML or as plain text dependent on what is appropriate
  1262. * for the download format. The default removes all tags.
  1263. */
  1264. function format_text($text, $format=FORMAT_MOODLE, $options=NULL, $courseid=NULL) {
  1265. //use some whitespace to indicate where there was some line spacing.
  1266. $text = str_replace(array('</p>', "\n", "\r"), ' ', $text);
  1267. return strip_tags($text);
  1268. }
  1269. }
  1270. /**
  1271. * @package moodlecore
  1272. * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
  1273. * @license http://www.gnu.org/copyleft/gpl.htm…

Large files files are truncated, but you can click here to view the full file