Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1441 ariadna 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
namespace core_table;
18
 
19
use flexible_table;
20
 
21
defined('MOODLE_INTERNAL') || die();
22
 
23
global $CFG;
24
 
25
require_once("{$CFG->libdir}/tablelib.php");
26
 
27
/**
28
 * The table base export format.
29
 *
30
 * @package   core_table
31
 * @copyright 1999 onwards Martin Dougiamas  {@link http://moodle.com}
32
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
33
 */
34
class base_export_format {
35
    /**
36
     * @var flexible_table or child class reference pointing to table class object from which to export data.
37
     */
38
    public $table;
39
 
40
    /**
41
     * @var bool output started. Keeps track of whether any output has been started yet.
42
     */
43
    public $documentstarted = false;
44
 
45
    /**
46
     * Constructor.
47
     *
48
     * @param flexible_table $table
49
     */
50
    public function __construct(&$table) {
51
        $this->table =& $table;
52
    }
53
 
54
    public function set_table(&$table) {
55
        $this->table =& $table;
56
    }
57
 
58
    public function add_data($row) {
59
        return false;
60
    }
61
 
62
    public function add_seperator() {
63
        return false;
64
    }
65
 
66
    public function document_started() {
67
        return $this->documentstarted;
68
    }
69
 
70
    /**
71
     * Format the text.
72
     *
73
     * Given text in a variety of format codings, this function returns
74
     * the text as safe HTML or as plain text dependent on what is appropriate
75
     * for the download format. The default removes all tags.
76
     *
77
     * @param string $text
78
     * @param int $format
79
     * @param null|array $options
80
     * @param null|int $courseid
81
     */
82
    public function format_text($text, $format = FORMAT_MOODLE, $options = null, $courseid = null) {
83
        // Use some whitespace to indicate where there was some line spacing.
84
        $text = str_replace(['</p>', "\n", "\r"], '   ', $text);
85
        return html_entity_decode(strip_tags($text), ENT_COMPAT);
86
    }
87
 
88
    /**
89
     * Format a row of data, removing HTML tags and entities from each of the cells
90
     *
91
     * @param array $row
92
     * @return array
93
     */
94
    public function format_data(array $row): array {
95
        return array_map([$this, 'format_text'], $row);
96
    }
97
}
98
 
99
// Alias this class to the old name.
100
// This file will be autoloaded by the legacyclasses autoload system.
101
// In future all uses of this class will be corrected and the legacy references will be removed.
102
class_alias(base_export_format::class, \table_default_export_format_parent::class);