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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
|
<?php
/**
* coursewizardsteps.php
* Controller for managing available course creation wizard steps.
*
* This program 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 2 of
* the License, or (at your option) any later version.
*
* @author Thomas Hackl <thomas.hackl@uni-passau.de>
* @copyright 2015 Stud.IP Core-Group
* @license http://www.gnu.org/licenses/gpl-2.0.html GPL version 2
* @category Stud.IP
* @since 3.3
*/
$stepdir = "../lib/classes/coursewizardsteps";
foreach (scandir($stepdir) as $file) {
if (mb_stripos($file, ".php") !== false) {
require_once $stepdir . "/" . $file;
}
}
class Admin_CourseWizardStepsController extends AuthenticatedController
{
public function before_filter(&$action, &$args)
{
parent::before_filter($action, $args);
// Check permissions to be on this site
if (!$GLOBALS['perm']->have_perm('root')) {
throw new AccessDeniedException();
}
PageLayout::setTitle(_('Schritte im Veranstaltungsanlegeassistenten'));
Navigation::activateItem('/admin/config/coursewizardsteps');
}
/**
* Show all available course wizard steps and their status.
*/
public function index_action()
{
$this->steps = CourseWizardStepRegistry::findBySQL("1 ORDER BY `number`");
$this->has_enabled = CourseWizardStepRegistry::hasEnabledSteps();
}
/**
* Shows a dialog for creating or editing a course wizard step.
* @param string $id ID of step to edit, or null if new step
*/
public function edit_action($id='')
{
if ($id) {
$title = _('Schritt bearbeiten');
$this->step = CourseWizardStepRegistry::find($id);
} else {
$title = _('Schritt hinzufügen');
$this->step = new CourseWizardStepRegistry();
$this->step->name = '';
$this->step->classname = '';
$this->step->number = 0;
$this->step->enabled = false;
$this->availableClasses = [];
foreach (get_declared_classes() as $className) {
if (is_a($className, "CourseWizardStep", true)
&& $className !== "CourseWizardStep") {
$collection = new SimpleCollection(CourseWizardStepRegistry::findBySQL("1 ORDER BY `number`"));
if (!in_array($className, $collection->pluck("classname"))) {
$this->availableClasses[] = $className;
}
}
}
}
PageLayout::setTitle($title);
}
/**
* Saves data for a new or existing step.
* @param string $id ID of the step to save; if empty, create new step.
*/
public function save_action($id = '')
{
CSRFProtection::verifyUnsafeRequest();
if (Request::submitted('submit')) {
if ($id) {
$step = CourseWizardStepRegistry::find($id);
$step->name = Request::get('name');
$step->classname = Request::get('classname');
$step->number = Request::int('number');
$step->enabled = Request::option('enabled') ? 1 : 0;
if ($step->store()) {
PageLayout::postSuccess(_('Die Daten wurden gespeichert.'));
} else {
PageLayout::postError(_('Die Daten konnten nicht gespeichert werden.'));
}
} else {
$classname = Request::get('classname');
// Check if given class name can be found in system.
if (!class_exists($classname)) {
PageLayout::postError(sprintf(_('Die angegebene PHP-Klasse "%s" wurde nicht gefunden.'), htmlReady($classname)));
// Class found, now check if it implements the interface definition for wizard steps.
} else if (!in_array('CourseWizardStep', class_implements($classname) ?: [])) {
PageLayout::postError(sprintf(_('Die angegebene PHP-Klasse "%s" implementiert nicht das Interface CourseWizardStep.'),
htmlReady($classname)));
// All ok, create new database entry.
} else {
$step = new CourseWizardStepRegistry();
$step->name = Request::get('name');
$step->classname = $classname;
$step->number = Request::int('number');
$step->enabled = Request::option('enabled') ? 1 : 0;
if ($step->store()) {
PageLayout::postSuccess(_('Die Daten wurden gespeichert.'));
} else {
PageLayout::postError(_('Die Daten konnten nicht gespeichert werden.'));
}
}
}
}
$this->redirect($this->url_for('admin/coursewizardsteps'));
}
/**
* Deletes the given entry from step registry.
* @param $id ID of the entry to delete
*/
public function delete_action($id)
{
CSRFProtection::verifyUnsafeRequest();
$step = CourseWizardStepRegistry::find($id);
if ($step) {
$name = $step->name;
if (CourseWizardStepRegistry::unregisterStep($id)) {
PageLayout::postSuccess(sprintf(_('Der Schritt "%s" wurde gelöscht.'), htmlReady($name)));
} else {
PageLayout::postError(sprintf(_('Der Schritt %s konnte nicht gelöscht werden.'), htmlReady($name)));
}
}
$this->redirect($this->url_for('admin/coursewizardsteps'));
}
/**
* Toggles the activation state of a step.
*
* @param string $id Id of the step
*/
public function toggle_enabled_action($id)
{
$step = CourseWizardStepRegistry::find($id);
$step->enabled = !$step->enabled;
$step->store();
if (!Request::isXhr()) {
$message = $step->enabled
? _('Der Schritt wurde aktiviert')
: _('Der Schritt wurde deaktiviert');
PageLayout::postSuccess($message);
}
$this->redirect("admin/coursewizardsteps#wizard-step-{$id}");
}
}
|