-
Notifications
You must be signed in to change notification settings - Fork 29
/
export.php
140 lines (123 loc) · 5.49 KB
/
export.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Export posts page.
*
* @package mod_oublog
* @copyright 2018 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once('../../config.php');
require_once('locallib.php');
require_once($CFG->dirroot . '/lib/tablelib.php');
// Required params.
$oublogid = required_param('ca_oublogid', PARAM_INT);
$currentgroup = required_param('ca_currentgroup', PARAM_INT);
$currentindividual = required_param('ca_currentindividual', PARAM_INT);
$oubloguserid = required_param('ca_oubloguserid', PARAM_INT);
$canaudit = required_param('ca_canaudit', PARAM_INT);
$cmid = required_param('ca_cmid', PARAM_INT);
$issharedblog = optional_param('ca_issharedblog', 0, PARAM_INT);
// Optional params.
$page = optional_param('page', 0, PARAM_INT);
$offset = $page * OUBLOG_POSTS_PER_PAGE_EXPORT;
// Load efficiently (and with full $cm data) using get_fast_modinfo.
$course = $DB->get_record_select('course',
'id = (SELECT course FROM {course_modules} WHERE id = ?)', array($cmid),
'*', MUST_EXIST);
$modinfo = get_fast_modinfo($course);
$cm = $modinfo->get_cm($cmid);
if ($cm->modname !== 'oublog') {
throw new moodle_exception('invalidcoursemodule');
}
if (!$oublog = $DB->get_record('oublog', array('id' => $cm->instance))) {
throw new moodle_exception('invalidcoursemodule');
}
$context = context_module::instance($cm->id);
oublog_check_view_permissions($oublog, $context, $cm);
if (empty($CFG->enableportfolios) || !has_capability('mod/oublog:exportpost', $context)) {
throw new moodle_exception('accessdenied', 'oublog');
}
$oublogoutput = $PAGE->get_renderer('mod_oublog');
$url = new moodle_url('/mod/oublog/export.php',
array('ca_oublogid' => $oublogid,
'ca_offset' => $offset,
'ca_currentgroup' => $currentgroup,
'ca_currentindividual' => $currentindividual,
'ca_oubloguserid' => $oubloguserid,
'ca_canaudit' => $canaudit,
'ca_cmid' => $cmid,
'ca_issharedblog' => $issharedblog
));
$exporturl = new moodle_url('/portfolio/add.php',
array('ca_oublogid' => $cm->instance,
'ca_oubloguserid' => $oubloguserid,
'ca_cmid' => $cmid,
'ca_cmsharedblogid' => $issharedblog,
'sesskey' => sesskey(),
'callbackcomponent' => 'mod_oublog',
'callbackclass' => 'oublog_export_portfolio_caller',
'courseid' => $course->id,
'callerformats' => 'file,richhtml,plainhtml'
));
$PAGE->set_url($url);
$PAGE->set_title(get_string('export:title', 'oublog'));
$PAGE->navbar->add(get_string('export:header', 'oublog'));
$PAGE->set_heading(get_string('export:header', 'oublog'));
$oublogoutput->pre_display($cm, $oublog, 'viewpost');
echo $OUTPUT->header();
echo $oublogoutput->render_export_header($cm, $oublog, 'export');
echo $oublogoutput->render_export_select_button();
echo html_writer::div(get_string('export:description', 'oublog'), 'oublog-export-description');
echo $oublogoutput->render_export_type($exporturl);
$table = new \flexible_table('oublog_export_posts_table');
$table->define_headers(array(
html_writer::img($OUTPUT->image_url('tick', 'oublog'), '', ['class' => 'export-icon-check']),
get_string('export:header_title', 'oublog'),
get_string('export:header_date_posted', 'oublog'),
get_string('export:header_tags', 'oublog'),
get_string('export:header_author', 'oublog')
));
$table->define_columns(array('select', 'title', 'timeposted', 'tags', 'author'));
$table->define_baseurl($url);
$table->set_attribute('width', '100%');
$table->set_attribute('class', 'oublog-posts-table');
$table->sortable(true, 'timeposted', SORT_DESC);
$table->no_sorting('select');
$table->no_sorting('tags');
$table->setup();
$orderby = $table->get_sql_sort();
list($listposts, $recordcount) = $oublogoutput->render_table_posts(
$oublogid, $canaudit, $oubloguserid, $currentindividual, $offset, $currentgroup, $orderby, $issharedblog, $cmid);
foreach ($listposts as $listpost) {
$table->add_data($listpost);
}
if ($recordcount > OUBLOG_POSTS_PER_PAGE_EXPORT) {
echo html_writer::start_div('oublog-paging');
echo $OUTPUT->paging_bar($recordcount, $page, OUBLOG_POSTS_PER_PAGE_EXPORT, $url);
echo html_writer::end_div();
}
$table->finish_output();
if ($recordcount > OUBLOG_POSTS_PER_PAGE_EXPORT) {
echo html_writer::start_div('oublog-paging');
echo $OUTPUT->paging_bar($recordcount, $page, OUBLOG_POSTS_PER_PAGE_EXPORT, $url);
echo html_writer::end_div();
}
echo $oublogoutput->render_export_select_button();
echo $oublogoutput->render_export_type($exporturl);
echo html_writer::div('', 'clearfix');
$PAGE->requires->js_call_amd('mod_oublog/export', 'init', [["newsession" => !isset($_GET['page'])]]);
echo $OUTPUT->footer();