forked from jacano1969/moodle-mod-360
-
Notifications
You must be signed in to change notification settings - Fork 1
/
edit.php
145 lines (116 loc) · 5.53 KB
/
edit.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
141
142
143
144
145
<?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/>.
/**
* Administration settings for a threesixty activity
*
* @author Francois Marier <[email protected]>
* @package mod/threesixty
*/
require_once('../../config.php');
require_once('locallib.php');
global $DB, $PAGE;
define('MAX_DESCRIPTION', 255); // ...max number of characters of the description to show in the table.
$strmoveup = get_string('moveup');
$strmovedown = get_string('movedown');
$a = required_param('a', PARAM_INT); // ...threesixty instance ID.
$move = optional_param('move', 0, PARAM_INT); // Reordering competencies.
if (!$activity = $DB->get_record('threesixty', array('id'=> $a))) {
print_error('Course module is incorrect');
}
if (!$course = $DB->get_record('course', array('id'=>$activity->course))) {
print_error('Course is misconfigured');
}
if (!$cm = get_coursemodule_from_instance('threesixty', $activity->id, $course->id)) {
print_error('Course Module ID was incorrect');
}
$context = context_module::instance($cm->id);
require_login($course, true, $cm);
require_capability('mod/threesixty:manage', $context);
$PAGE->set_url('/mod/threesixty/edit.php', array('a' => $a));
$PAGE->set_pagelayout('incourse');
// TODO add_to_log($course->id, 'threesixty', 'admin', "edit.php?a=$activity->id", $activity->id);
if ($move) {
$c = optional_param('c', 0, PARAM_INT); // The competency id that we're needing to move.
if (!$competency = $DB->get_record('threesixty_competency', array('id' => $c, 'activityid' => $activity->id))) {
print_error('Competency id incorrect');
}
move_competency($competency, $move);
}
/** @var core_renderer $OUTPUT */
echo $OUTPUT->header();
$strthreesixtys = get_string('modulenameplural', 'threesixty');
$strthreesixty = get_string('modulename', 'threesixty');
$navlinks = array();
$navlinks[] = array('name' => $strthreesixtys, 'link' => "index.php?id=$course->id", 'type' => 'activity');
$navlinks[] = array('name' => format_string($activity->name), 'link' => '', 'type' => 'activityinstance');
shim::build_navigation($navlinks);
/** @var moodle_page $PAGE */
$PAGE->set_title(format_string($activity->name));
// Main content.
$currenttab = 'edit';
$section = 'competencies';
require_once('tabs.php');
echo '<h2>'.get_string('competenciesheading', 'threesixty').'</h2>';
$competencies = threesixty_get_competency_listing($activity->id);
if (count($competencies) > 0) {
$table = new html_table();
$table->head = array(get_string('name'), get_string('description'),
get_string('skills', 'threesixty'), get_string('feedback', 'threesixty'), ' ');
$numcompetencies = count($competencies);
for ($i=0; $i<$numcompetencies; $i++) {
$competency = array_shift($competencies);
$links = '<a href="editcompetency.php?a='.$activity->id.'&c='.$competency->id.'">'.
get_string('edit', 'threesixty').'</a>';
$links .= ' | <a href="deletecompetency.php?a='.$activity->id.'&c='.$competency->id.'">'.
get_string('delete', 'threesixty').'</a>';
if ($i!=0) {
$links .= ' | <a href="edit.php?a='.$activity->id.'&c='.$competency->id.'&move=-1" title="'.$strmoveup.'">
<img src="'.$OUTPUT->pix_url('/t/up').'" alt="'.$strmoveup.'" /></a>';
}
if ($i<$numcompetencies-1) {
$links .= ' | <a href="edit.php?a='.$activity->id.'&c='.$competency->id.'&move=1" title="'.$strmovedown.'">
<img src="'.$OUTPUT->pix_url('/t/down').'" alt="'.$strmovedown.'" /></a>';
}
// Shorten the description field.
$shortdescription = substr($competency->description, 0, MAX_DESCRIPTION);
if (strlen($shortdescription) < strlen($competency->description)) {
$shortdescription .= '...';
}
$table->data[] = array(format_string($competency->name), format_text($shortdescription),
format_string($competency->skills),
$competency->showfeedback ? get_string('yes') : get_string('no') , $links);
}
// ...print_table($table);.
echo html_writer::table($table);
} else {
print_string('nocompetencies', 'threesixty');
}
print '<p><a href="editcompetency.php?a='.$activity->id.'&c=0">'.get_string('addnewcompetency', 'threesixty').'</a></p>';
// ...print_footer($course);.
echo $OUTPUT->footer();
function move_competency($competency, $moveto) {
global $DB;
$currentlocation = $competency->sortorder;
$newlocation = $currentlocation + $moveto;
$swapcomp = $DB->get_record('threesixty_competency', array('id' => $competency->id), $fields='sortorder');
if ($swapcomp) {
$swapcomp->sortorder = $currentlocation;
$swapcomp->id = $competency->id;
$DB->update_record('threesixty_competency', $swapcomp);
}
$competency->sortorder = $newlocation;
$DB->update_record('threesixty_competency', $competency);
}