Gitlab CSE Unil

locallib_admin.php 7.86 KB
Newer Older
M. Chardon's avatar
M. Chardon committed
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
<?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/>.

/**
 * Description of locallib_admin
 *
 * @package   assignfeedback_editpdfplus
 * @copyright  2017 Université de Lausanne
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */
defined('MOODLE_INTERNAL') || die();

use \assignfeedback_editpdfplus\page_editor;
use \assignfeedback_editpdfplus\widget_admin;
use \assignfeedback_editpdfplus\form\axis_form;
30
use \assignfeedback_editpdfplus\form\axis_del_form;
M. Chardon's avatar
M. Chardon committed
31
use \assignfeedback_editpdfplus\form\tool_form;
M. Chardon's avatar
M. Chardon committed
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
use \assignfeedback_editpdfplus\admin_editor;

class assign_feedback_editpdfplus_admin {

    private $course = null;
    private $context = null;

    function __construct(stdClass $context, stdClass $course) {
        $this->context = $context;
        $this->course = $course;
    }

    /**
     * todo.
     *
     * @return string
     */
    public function view() {
        global $PAGE;

        //$PAGE->requires->js_call_amd('assignfeedback_editpdfplus/admin_panel', 'init');

        $html = '';
        //$toform = null;
        $renderer = $PAGE->get_renderer('assignfeedback_editpdfplus');
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
        /* $formAddAxis = new axis_form(new moodle_url('/mod/assign/feedback/editpdfplus/view_admin.php?id=' . $this->course->id, array('id' => $this->course->id))); //Form processing and displaying is done here
          if ($formAddAxis->is_cancelled()) {
          //Handle form cancel operation, if cancel button is present on form
          } else if ($fromform = $formAddAxis->get_data()) {
          //In this case you process validated data. $mform->get_data() returns data posted in form.
          $label = $fromform->label;
          $axe = $this->addAxis($label);
          $formAddAxis->set_data($toform);
          return $axe; //"<option>tutu</option>";
          } else {
          // this branch is executed if the form is submitted but the data doesn't validate and the form should be redisplayed
          // or on the first display of the form.
          //Set default data (if any)
          $formAddAxis->set_data($toform);
          } */
M. Chardon's avatar
M. Chardon committed
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
        $widget = $this->get_widget();
        //$widget->axisaddform = $formAddAxis;
        $html .= $renderer->render_assignfeedback_editpdfplus_widget_admin($widget);
        return $html;
    }

    public function getAxisForm($axeid = null) {
        global $PAGE, $DB;

        $html = '';
        $toform = null;
        $formAxis = null;
        $axis = null;
        if ($axeid != null) {
            $axis = $DB->get_record('assignfeedback_editpp_axis', array('id' => $axeid), '*', MUST_EXIST);
        }
        if ($axis != null) {
            $formAxis = new axis_form(null, array('id' => $this->course->id), null, null, array('id' => "assignfeedback_editpdfplus_edit_axis")); //Form processing and displaying is done here
90
            $formAxis->set_data(array('axeid' => $axeid, 'label' => $axis->label));
M. Chardon's avatar
M. Chardon committed
91
            $formAxis->id = "assignfeedback_editpdfplus_edit_axis";
92
93
            $formAxis->title = "Renommer l'axe";
            $formAxis->action = "edit";
M. Chardon's avatar
M. Chardon committed
94
95
96
97
        } else {
            $formAxis = new axis_form(null, array('id' => $this->course->id), null, null, array('id' => "assignfeedback_editpdfplus_add_axis")); //Form processing and displaying is done here
            $formAxis->set_data($toform);
            $formAxis->id = "assignfeedback_editpdfplus_add_axis";
98
99
            $formAxis->title = "Ajouter un nouvel axe";
            $formAxis->action = "add";
M. Chardon's avatar
M. Chardon committed
100
101
102
103
104
105
106
        }
        $renderer = $PAGE->get_renderer('assignfeedback_editpdfplus');
        $formAxis->courseid = $this->course->id;
        $html .= $renderer->render_assignfeedback_editpdfplus_widget_admin_axisform($formAxis);
        return $html;
    }

107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
    public function getAxisDelForm($axeid) {
        global $PAGE, $DB;

        $html = '';
        $formAxis = null;
        $axis = null;
        if ($axeid != null) {
            $axis = $DB->get_record('assignfeedback_editpp_axis', array('id' => $axeid), '*', MUST_EXIST);
        }
        if ($axis != null) {
            $formAxis = new axis_del_form(null, array('id' => $this->course->id), null, null, array('id' => "assignfeedback_editpdfplus_del_axis")); //Form processing and displaying is done here
            $formAxis->set_data(array('axeid' => $axeid, 'label' => $axis->label));
        }
        $formAxis->id = "assignfeedback_editpdfplus_del_axis";
        $formAxis->title = "Supprimer l'axe";
        $formAxis->action = "del";
        $renderer = $PAGE->get_renderer('assignfeedback_editpdfplus');
        $formAxis->courseid = $this->course->id;
        $html .= $renderer->render_assignfeedback_editpdfplus_widget_admin_axisdelform($formAxis);
        return $html;
    }

M. Chardon's avatar
M. Chardon committed
129
    public function getToolForm($toolid = null, $axisid = null) {
M. Chardon's avatar
M. Chardon committed
130
131
132
133
134
135
136
137
138
139
        global $PAGE, $DB;

        $html = '';
        $data = new stdClass;
        $data->courseid = $this->course->id;
        $data->sesskey = sesskey();
        $data->actionurl = "http://localhost/moodle33/moodle/lib/ajax/service.php";
        $data->formid = "assignfeedback_editpdfplus_edit_tool";
        if ($toolid != null) {
            $data->tool = $DB->get_record('assignfeedback_editpp_tool', array('id' => $toolid), '*', MUST_EXIST);
M. Chardon's avatar
M. Chardon committed
140
141
142
143
144
145
        } else {
            $tool = new \assignfeedback_editpdfplus\tool();
            $tool->contextid = $this->context->id;
            $tool->enabled = true;
            $tool->axis = $axisid;
            $data->tool = $tool;
M. Chardon's avatar
M. Chardon committed
146
147
148
149
150
151
152
153
        }
        $data->tools = page_editor::get_typetools(null);
        $renderer = $PAGE->get_renderer('assignfeedback_editpdfplus');
        //$formTool->courseid = $this->course->id;
        $html .= $renderer->render_assignfeedback_editpdfplus_widget_admin_toolform($data);
        return $html;
    }

M. Chardon's avatar
M. Chardon committed
154
155
156
157
158
159
160
161
162
163
    private function get_widget() {
        global $USER;

        // get the costum toolbars
        $toolbars = array();
        $coursecontext = context::instance_by_id($this->context->id);
        $coursecontexts = array_filter(explode('/', $coursecontext->path), 'strlen');
        $tools = page_editor::get_tools($coursecontexts);
        $axis = page_editor::get_axis(array($this->context->id));
        foreach ($axis as $ax) {
164
            $ax->children = 0;
M. Chardon's avatar
M. Chardon committed
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
            $toolbar = new stdClass();
            $toolbar->axis = $ax;
            $toolbar->tools = array();
            //$toolbars[$ax->id]['label'] = $ax->label;
            foreach ($tools as $tool) {
                if ($tool->axis == $ax->id) {
                    if ($tool->enabled == "1") {
                        $tool->button = "btn-default";
                    } else {
                        $tool->button = "";
                    }
                    if ($tool->type == "4") {
                        $tool->label = '| ' . $tool->label . ' |';
                    } elseif ($tool->type == "5") {
                        $tool->label = '| ' . $tool->label;
                    }
                    if ($tool->type == "4" || $tool->type == "1") {
                        $tool->style = "text-decoration: underline;";
                    }
                    $toolbar->tools[] = $tool;
185
                    $ax->children++;
M. Chardon's avatar
M. Chardon committed
186
187
188
189
190
191
192
193
194
                }
            }
            $toolbars[] = $toolbar;
        }
        $widget = new widget_admin($this->context, $this->course, $USER, $toolbars, $axis);
        return $widget;
    }

}