-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrenderer.php
130 lines (114 loc) · 4.79 KB
/
renderer.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
<?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/>.
/**
* General renderer
*
* @package mod_sharedresource
* @author Valery Fremaux <[email protected]>
* @copyright Valery Fremaux (activeprolearn.com)
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
*/
/**
* Sharedresource renderer
*/
class mod_sharedresource_renderer extends plugin_renderer_base {
/**
* Used to go to the library for searching a sharedresource entry for publishing.
* @param int $section
* @param string $returnpage
* @see mod/sharedresource/search.php
*/
public function add_instance_form($section, $returnpage) {
global $COURSE;
if ($COURSE->id == SITEID) {
$context = context_system::instance();
} else {
$context = context_course::instance($COURSE->id);
}
$template = new StdClass();
$params = [
'course' => $COURSE->id,
'section' => $section,
'returnpage' => $returnpage,
'fromlibrary' => 0,
];
$libraryurl = new moodle_url('/local/sharedresources/index.php', $params);
$template->searchbutton = $this->output->single_button($libraryurl, get_string('searchinlibrary', 'sharedresource'));
$template->searchdesc = get_string('addinstance_search_desc', 'sharedresource');
if (has_capability('repository/sharedresources:create', $context)) {
$template->cancreate = true;
$params = [
'course' => $COURSE->id,
'section' => $section,
'returnpage' => $returnpage,
'fromlibrary' => 0,
'mode' => 'add',
];
$editurl = new moodle_url('/mod/sharedresource/edit.php', $params);
$template->createbutton = $this->output->single_button($editurl, get_string('addsharedresource', 'sharedresource'));
$template->createdesc = get_string('addinstance_create_desc', 'sharedresource');
}
return $this->output->render_from_template('mod_sharedresource/addinstance', $template);
}
/**
* Print resource comparison board.
* @param object $new
* @param object $old
* @param string $step
*/
public function resourcecompare($new, $old, $step = 'postdata') {
$config = get_config('sharedresource');
if (!$config->schema) {
return;
}
$plugin = sharedresource_get_plugin($config->schema);
$template = new StdClass;
$template->olddescriptionstr = get_string('resourceolddescription', 'sharedresource');
$template->newdescriptionstr = get_string('resourcenewdescription', 'sharedresource');
$attributes = [];
foreach ($old->metadataelements as $elm) {
$elmkey = $elm->get_element_key();
$stdelm = $plugin->get_element($elm->get_node_id());
$attribute = new StdClass;
$attribute->id = $elmkey;
$attribute->name = $stdelm->name;
$attribute->oldvalue = $elm->get_value();
$attribute->newvalue = '';
$attributes[$elmkey] = $attribute;
}
foreach ($new->metadataelements as $elm) {
$elmkey = $elm->get_element_key();
$stdelm = $plugin->get_element($elm->get_node_id());
if (!array_key_exists($elmkey, $attributes)) {
$attribute = new StdClass;
$attribute->id = $elmkey;
$attribute->name = $stdelm->name;
$attribute->oldvalue = '';
$attribute->newvalue = $elm->get_value();
$attributes[$elmkey] = $attribute;
} else {
if ($step == 'predata') {
$attributes[$elm->get_element_key()]->newvalue = get_string('predatanotprovided', 'sharedesource');
} else {
$attributes[$elm->get_element_key()]->newvalue = $elm->get_value();
}
}
}
asort($attributes);
$template->attributes = array_values($attributes);
return $this->output->render_from_template('mod_sharedresource/resourcecompare', $template);
}
}