Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 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
/**
18
 * The table that displays the templates in a given context.
19
 *
20
 * @package    mod_customcert
21
 * @copyright  2017 Mark Nelson <markn@moodle.com>
22
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23
 */
24
 
25
namespace mod_customcert;
26
 
27
defined('MOODLE_INTERNAL') || die;
28
 
29
global $CFG;
30
 
31
require_once($CFG->libdir . '/tablelib.php');
32
 
33
/**
34
 * Class for the table that displays the templates in a given context.
35
 *
36
 * @package    mod_customcert
37
 * @copyright  2017 Mark Nelson <markn@moodle.com>
38
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
39
 */
40
class manage_templates_table extends \table_sql {
41
 
42
    /**
43
     * @var \context $context
44
     */
45
    protected $context;
46
 
47
    /**
48
     * Sets up the table.
49
     *
50
     * @param \context $context
51
     */
52
    public function __construct($context) {
53
        parent::__construct('mod_customcert_manage_templates_table');
54
 
55
        $columns = [
56
            'name',
57
            'actions',
58
        ];
59
 
60
        $headers = [
61
            get_string('name'),
62
            '',
63
        ];
64
 
65
        $this->define_columns($columns);
66
        $this->define_headers($headers);
67
        $this->collapsible(false);
68
        $this->sortable(true);
69
 
70
        $this->context = $context;
71
    }
72
 
73
    /**
74
     * Generate the name column.
75
     *
76
     * @param \stdClass $template
77
     * @return string
78
     */
79
    public function col_name($template) {
80
        return format_string($template->name, true, ['context' => $this->context]);
81
    }
82
 
83
    /**
84
     * Generate the actions column.
85
     *
86
     * @param \stdClass $template
87
     * @return string
88
     */
89
    public function col_actions($template) {
90
        global $OUTPUT;
91
 
92
        // Link to edit the template.
93
        $editlink = new \moodle_url('/mod/customcert/edit.php', ['tid' => $template->id]);
94
        $editicon = $OUTPUT->action_icon($editlink, new \pix_icon('t/edit', get_string('edit')));
95
 
96
        // Link to duplicate the template.
97
        $duplicatelink = new \moodle_url('/mod/customcert/manage_templates.php',
98
            [
99
                'tid' => $template->id,
100
                'action' => 'duplicate',
101
                'sesskey' => sesskey(),
102
            ]
103
        );
104
        $duplicateicon = $OUTPUT->action_icon($duplicatelink, new \pix_icon('t/copy', get_string('duplicate')), null,
105
            ['class' => 'action-icon duplicate-icon']);
106
 
107
        // Link to delete the template.
108
        $deletelink = new \moodle_url('/mod/customcert/manage_templates.php',
109
            [
110
                'tid' => $template->id,
111
                'action' => 'delete',
112
                'sesskey' => sesskey(),
113
            ]
114
        );
115
        $deleteicon = $OUTPUT->action_icon($deletelink, new \pix_icon('t/delete', get_string('delete')), null,
116
            ['class' => 'action-icon delete-icon']);
117
 
118
        return $editicon . $duplicateicon . $deleteicon;
119
    }
120
 
121
    /**
122
     * Query the reader.
123
     *
124
     * @param int $pagesize size of page for paginated displayed table.
125
     * @param bool $useinitialsbar do you want to use the initials bar.
126
     */
127
    public function query_db($pagesize, $useinitialsbar = true) {
128
        global $DB;
129
 
130
        $total = $DB->count_records('customcert_templates', ['contextid' => $this->context->id]);
131
 
132
        $this->pagesize($pagesize, $total);
133
 
134
        $this->rawdata = $DB->get_records('customcert_templates', ['contextid' => $this->context->id],
135
            $this->get_sql_sort(), '*', $this->get_page_start(), $this->get_page_size());
136
 
137
        // Set initial bars.
138
        if ($useinitialsbar) {
139
            $this->initialbars($total > $pagesize);
140
        }
141
    }
142
}