Gitlab CSE Unil

externallib.php 22.1 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
30
31
32
33
<?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/>.

/**
 * External assign API
 *
 * @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;

require_once("$CFG->libdir/externallib.php");
require_once("$CFG->dirroot/user/externallib.php");
require_once("$CFG->dirroot/mod/assign/locallib.php");
require_once("locallib.php");
require_once("locallib_admin.php");

use \assignfeedback_editpdfplus\form\axis_form;
34
use \assignfeedback_editpdfplus\form\axis_del_form;
M. Chardon's avatar
M. Chardon committed
35
use \assignfeedback_editpdfplus\form\axis_import_form;
M. Chardon's avatar
M. Chardon committed
36
37
use \assignfeedback_editpdfplus\form\axis_export_form;
use \assignfeedback_editpdfplus\form\model_del_form;
M. Chardon's avatar
M. Chardon committed
38
39
40
41
use \assignfeedback_editpdfplus\admin_editor;

class assignfeedback_editpdfplus_external extends external_api {

42
43
44
45
    const PLUGINNAME = "assignfeedback_editpdfplus";
    const DATAJSON = 'jsonformdata';
    const MESSAGELIB = 'message';
    const COURSELIB = "course";
46
    const CONTEXTID = "contextid";
47
48
49
50
51
52
53
54
55
56
57
58
59
60
    const AXEID = "axeid";
    const AXEIDDESC = "Axe ID";
    const AXELIB = "axelabel";
    const AXELIBDESC = "Axe label";
    const TOOLID = "toolid";
    const TOOLIDDESC = "Tool ID";
    const TOOLLIBDESC = "Tool label";
    const TOOLTYPE = "typetool";
    const TOOLTYPEDESC = "Type of tool";
    const TOOLSELECTED = "selecttool";
    const BOUTONLIBTOOL = "button";
    const ENABLETOOL = "enable";
    const ENABLETOOLDESC = "Tool is enabled";

M. Chardon's avatar
M. Chardon committed
61
    /**
62
63
     * Returns description of method parameters for general calling
     * @return \external_function_parameters
M. Chardon's avatar
M. Chardon committed
64
     */
65
66
    public static function submit_generic_form_parameters() {
        $message = 'The data from the grading form, encoded as a json array';
M. Chardon's avatar
M. Chardon committed
67
68
        return new external_function_parameters(
                array(
69
            self::DATAJSON => new external_value(PARAM_RAW, $message)
M. Chardon's avatar
M. Chardon committed
70
71
72
73
                )
        );
    }

M. Chardon's avatar
M. Chardon committed
74
    /**
75
76
77
     * 
     * Form return generic structure
     * @return \external_single_structure
M. Chardon's avatar
M. Chardon committed
78
     */
79
80
81
82
83
84
85
    public static function submit_generic_form_returns() {
        return new external_single_structure(
                array(
            self::MESSAGELIB => new external_value(PARAM_TEXT, self::MESSAGELIB, VALUE_OPTIONAL)
                )
        );
    }
M. Chardon's avatar
M. Chardon committed
86

87
88
89
90
91
92
93
    /**
     * Form return tool structure
     * @return \external_multiple_structure
     */
    public static function submit_tool_form_returns() {
        return new external_multiple_structure(
                new external_single_structure(
M. Chardon's avatar
M. Chardon committed
94
95
96
97
98
99
100
101
102
                        array(
                    self::AXEID => new external_value(PARAM_INT, self::AXEIDDESC),
                    self::TOOLSELECTED => new external_value(PARAM_INT, self::TOOLIDDESC),
                    self::ENABLETOOL => new external_value(PARAM_INT, self::ENABLETOOLDESC, VALUE_OPTIONAL),
                    self::TOOLID => new external_value(PARAM_INT, self::TOOLIDDESC),
                    self::TOOLTYPE => new external_value(PARAM_INT, self::TOOLTYPEDESC, VALUE_OPTIONAL),
                    self::BOUTONLIBTOOL => new external_value(PARAM_TEXT, self::TOOLLIBDESC, VALUE_OPTIONAL),
                    self::MESSAGELIB => new external_value(PARAM_TEXT, self::MESSAGELIB, VALUE_OPTIONAL)
                        )
103
104
105
                )
        );
    }
M. Chardon's avatar
M. Chardon committed
106

107
108
109
110
111
112
113
114
115
116
117
    /**
     * Extract and parse json data string into an array
     * @param external_function_parameters $externalFunctionParameter
     * @param String $jsonformdata
     * @return array decoded data
     */
    public static function getParseData($externalFunctionParameter, $jsonformdata) {
        $params = self::validate_parameters($externalFunctionParameter, array(
                    self::DATAJSON => $jsonformdata
        ));
        $serialiseddata = json_decode($params[self::DATAJSON]);
M. Chardon's avatar
M. Chardon committed
118
119
        $data = array();
        parse_str($serialiseddata, $data);
120
121
        return $data;
    }
M. Chardon's avatar
M. Chardon committed
122

123
124
125
126
    /**
     * Set Page context from the course id given. It returns the context found.
     * @global $DB
     * @global $PAGE
127
     * @param int $contextid Current context id
128
129
     * @return context course's context 
     */
130
131
132
    public static function setPageContext($contextid) {
        global $PAGE;
        $context = context::instance_by_id($contextid, MUST_EXIST);
M. Chardon's avatar
M. Chardon committed
133
        $PAGE->set_context($context);
134
135
136
137
138
139
140
        return $context;
    }

    public static function getMessageError() {
        return array(self::MESSAGELIB => get_string("admin_messageko", self::PLUGINNAME));
    }

M. Chardon's avatar
M. Chardon committed
141
142
143
144
145
146
147
148
    /**
     * Returns description of method parameters
     * @return external_function_parameters
     */
    public static function submit_axis_form_parameters() {
        return self::submit_generic_form_parameters();
    }

149
150
151
152
153
154
155
156
    /**
     * Submit axis form for adding or edditing
     * @param String $jsonformdata
     * @return array
     */
    public static function submit_axis_form($jsonformdata) {
        $data = self::getParseData(self::submit_axis_form_parameters(), $jsonformdata);

157
        $context = self::setPageContext($data[self::CONTEXTID]);
M. Chardon's avatar
M. Chardon committed
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172

        $customdata = (object) $data;
        $formparams = array($customdata);

        // Data is injected into the form by the last param for the constructor.
        $mform = new axis_form(null, $formparams, 'post', '', null, true, $data);
        $validateddata = $mform->get_data();

        if ($validateddata) {
            if ($validateddata->axeid) {
                admin_editor::edit_axis($validateddata->axeid, $validateddata->label);
                $axeid = $validateddata->axeid;
            } else {
                $axeid = admin_editor::add_axis($validateddata->label, $context->id);
            }
173
            return array(array(self::AXEID => $axeid, self::AXELIB => $validateddata->label));
M. Chardon's avatar
M. Chardon committed
174
        }
175
        return array(self::getMessageError());
M. Chardon's avatar
M. Chardon committed
176
177
    }

M. Chardon's avatar
M. Chardon committed
178
179
180
181
    /**
     * Form return structure
     * @return \external_multiple_structure
     */
M. Chardon's avatar
M. Chardon committed
182
183
184
    public static function submit_axis_form_returns() {
        return new external_multiple_structure(
                new external_single_structure(
M. Chardon's avatar
M. Chardon committed
185
186
187
188
189
                        array(
                    self::AXEID => new external_value(PARAM_INT, self::AXEIDDESC),
                    self::AXELIB => new external_value(PARAM_TEXT, self::AXELIBDESC),
                    self::MESSAGELIB => new external_value(PARAM_TEXT, self::MESSAGELIB, VALUE_OPTIONAL)
                        )
M. Chardon's avatar
M. Chardon committed
190
191
192
193
                )
        );
    }

194
195
196
197
198
    /**
     * Returns description of method parameters
     * @return external_function_parameters
     */
    public static function submit_axis_del_form_parameters() {
199
        return self::submit_generic_form_parameters();
200
201
    }

M. Chardon's avatar
M. Chardon committed
202
203
204
205
206
    /**
     * Submit axis form for deleting
     * @param String $jsonformdata
     * @return array
     */
207
    public static function submit_axis_del_form($jsonformdata) {
208
        $data = self::getParseData(self::submit_axis_form_parameters(), $jsonformdata);
209

210
        self::setPageContext($data[self::CONTEXTID]);
211
212
213
214
215
216
217
218

        $customdata = (object) $data;
        $formparams = array($customdata);

        // Data is injected into the form by the last param for the constructor.
        $mform = new axis_del_form(null, $formparams, 'post', '', null, true, $data);
        $validateddata = $mform->get_data();

219
220
221
        if ($validateddata && $validateddata->axeid && admin_editor::del_axis($validateddata->axeid)) {
            $message = "1";
            return array(array(self::MESSAGELIB => $message));
222
        }
223
224
225
        $warnings = array();
        $message = get_string('admindeltool_messageko', self::PLUGINNAME);
        $warnings[] = array(self::MESSAGELIB => $message);
226
227
228
        return $warnings;
    }

M. Chardon's avatar
M. Chardon committed
229
230
231
232
    /**
     * Form return structure
     * @return \external_multiple_structure
     */
233
234
    public static function submit_axis_del_form_returns() {
        return new external_multiple_structure(
235
                self::submit_generic_form_returns()
236
237
238
        );
    }

M. Chardon's avatar
M. Chardon committed
239
    /**
240
241
242
     * Submit tool form for adding or edditing
     * @param String $jsonformdata json tool
     * @param String $mode add or edit the tool
M. Chardon's avatar
M. Chardon committed
243
244
     * @return array
     */
245
246
    public static function submit_tool_form($jsonformdata, $mode) {
        $data = self::getParseData(self::submit_axis_form_parameters(), $jsonformdata);
M. Chardon's avatar
M. Chardon committed
247

248
        $context = self::setPageContext($data[self::CONTEXTID]);
M. Chardon's avatar
M. Chardon committed
249
250
251
252

        $customdata = (object) $data;

        $sessionkey = sesskey();
253
254
255
256
257
258
259
        if ($sessionkey == $customdata->sesskey && $mode) {
            $tool = null;
            if ($mode == "add") {
                $tool = admin_editor::add_tool($customdata, $context->id);
            } elseif ($mode == "edit") {
                $tool = admin_editor::edit_tool($customdata);
            }
M. Chardon's avatar
M. Chardon committed
260
            if ($tool) {
M. Chardon's avatar
M. Chardon committed
261
                $tools = admin_editor::get_tools_by_axis($tool->axis);
M. Chardon's avatar
M. Chardon committed
262
263
                $res = array();
                foreach ($tools as $toolTmp) {
264
                    $res[] = array(self::AXEID => $tool->axis, self::TOOLSELECTED => $tool->id, self::ENABLETOOL => $toolTmp->enabled, self::TOOLID => $toolTmp->id, self::TOOLTYPE => $toolTmp->type, self::BOUTONLIBTOOL => $toolTmp->label, self::MESSAGELIB => '');
M. Chardon's avatar
M. Chardon committed
265
266
267
268
                }
                return $res;
            }
        }
269
270
        return array(self::getMessageError());
    }
M. Chardon's avatar
M. Chardon committed
271

272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
    /**
     * Returns description of method parameters
     * @return external_function_parameters
     */
    public static function submit_tool_edit_form_parameters() {
        return self::submit_generic_form_parameters();
    }

    /**
     * Submit tool form for edditing
     * @param String $jsonformdata
     * @return array
     */
    public static function submit_tool_edit_form($jsonformdata) {
        return self::submit_tool_form($jsonformdata, "edit");
M. Chardon's avatar
M. Chardon committed
287
288
    }

M. Chardon's avatar
M. Chardon committed
289
290
291
292
    /**
     * Form return structure
     * @return \external_multiple_structure
     */
M. Chardon's avatar
M. Chardon committed
293
    public static function submit_tool_edit_form_returns() {
294
        return self::submit_tool_form_returns();
M. Chardon's avatar
M. Chardon committed
295
296
297
298
299
300
301
    }

    /**
     * Returns description of method parameters
     * @return external_function_parameters
     */
    public static function submit_tool_add_form_parameters() {
302
        return self::submit_generic_form_parameters();
M. Chardon's avatar
M. Chardon committed
303
304
    }

M. Chardon's avatar
M. Chardon committed
305
306
307
308
309
    /**
     * Submit tool form for adding
     * @param String $jsonformdata
     * @return array
     */
M. Chardon's avatar
M. Chardon committed
310
    public static function submit_tool_add_form($jsonformdata) {
311
        return self::submit_tool_form($jsonformdata, "add");
M. Chardon's avatar
M. Chardon committed
312
313
    }

M. Chardon's avatar
M. Chardon committed
314
315
316
317
    /**
     * Form return structure
     * @return \external_multiple_structure
     */
M. Chardon's avatar
M. Chardon committed
318
    public static function submit_tool_add_form_returns() {
319
        return self::submit_tool_form_returns();
M. Chardon's avatar
M. Chardon committed
320
321
    }

M. Chardon's avatar
M. Chardon committed
322
323
324
325
326
    /**
     * Returns description of method parameters
     * @return external_function_parameters
     */
    public static function submit_tool_del_form_parameters() {
327
        return self::submit_generic_form_parameters();
M. Chardon's avatar
M. Chardon committed
328
329
    }

M. Chardon's avatar
M. Chardon committed
330
331
332
333
334
    /**
     * Submit tool form for deleting
     * @param String $jsonformdata
     * @return array
     */
M. Chardon's avatar
M. Chardon committed
335
    public static function submit_tool_del_form($jsonformdata) {
336
        $data = self::getParseData(self::submit_axis_form_parameters(), $jsonformdata);
M. Chardon's avatar
M. Chardon committed
337

338
        $context = self::setPageContext($data[self::CONTEXTID]);
M. Chardon's avatar
M. Chardon committed
339
340
341
342
343
344
345
346
347

        $customdata = (object) $data;

        $sessionkey = sesskey();
        if ($sessionkey == $customdata->sesskey) {
            $axisid = $customdata->axisid;
            if (admin_editor::del_tool($customdata, $context->id)) {
                $res = array();
                $tools = admin_editor::get_tools_by_axis($axisid);
348
349
                if (sizeof($tools) > 0) {
                    foreach ($tools as $toolTmp) {
350
                        $res[] = array(self::AXEID => $axisid, self::TOOLSELECTED => -1, self::ENABLETOOL => $toolTmp->enabled, self::TOOLID => $toolTmp->id, self::TOOLTYPE => $toolTmp->type, self::BOUTONLIBTOOL => $toolTmp->label, self::MESSAGELIB => '');
351
352
                    }
                } else {
353
                    $res[] = array(self::AXEID => $axisid, self::TOOLSELECTED => -1, self::TOOLID => -1, self::MESSAGELIB => '1');
M. Chardon's avatar
M. Chardon committed
354
355
356
357
                }
                return $res;
            }
        }
358
        return array(self::getMessageError());
M. Chardon's avatar
M. Chardon committed
359
360
    }

M. Chardon's avatar
M. Chardon committed
361
362
363
364
    /**
     * Form return structure
     * @return \external_multiple_structure
     */
M. Chardon's avatar
M. Chardon committed
365
    public static function submit_tool_del_form_returns() {
366
        return self::submit_tool_form_returns();
M. Chardon's avatar
M. Chardon committed
367
368
    }

M. Chardon's avatar
M. Chardon committed
369
370
371
372
373
    /**
     * Returns description of method parameters
     * @return external_function_parameters
     */
    public static function submit_axis_import_form_parameters() {
374
        return self::submit_generic_form_parameters();
M. Chardon's avatar
M. Chardon committed
375
376
    }

M. Chardon's avatar
M. Chardon committed
377
378
379
380
381
    /**
     * Submit axis form for importing
     * @param String $jsonformdata
     * @return array
     */
M. Chardon's avatar
M. Chardon committed
382
383
    public static function submit_axis_import_form($jsonformdata) {

384
        $data = self::getParseData(self::submit_axis_import_form_parameters(), $jsonformdata);
M. Chardon's avatar
M. Chardon committed
385

386
        $context = self::setPageContext($data[self::CONTEXTID]);
M. Chardon's avatar
M. Chardon committed
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406

        $customdata = (object) $data;
        $formparams = array($customdata);

        // Data is injected into the form by the last param for the constructor.
        $mform = new axis_import_form(null, $formparams, 'post', '', null, true, $data);
        $validateddata = $mform->get_data();

        if ($validateddata && $validateddata->axeid) {
            $axeToImport = admin_editor::getAxisById($validateddata->axeid);
            $axeNew = admin_editor::import_axis($axeToImport, $context->id);
            if ($axeNew) {
                $tools = admin_editor::get_tools_by_axis($axeToImport->id);
                foreach ($tools as $toolToImport) {
                    admin_editor::import_tool($toolToImport, $axeNew, $context->id);
                }
                $res = array();
                $toolsNew = admin_editor::get_tools_by_axis($axeNew);
                if (sizeof($toolsNew) > 0) {
                    foreach ($toolsNew as $tool) {
407
                        $res[] = array(self::AXEID => $axeNew, self::AXELIB => $axeToImport->label, self::MESSAGELIB => "", self::ENABLETOOL => $tool->enabled, self::TOOLID => $tool->id, self::TOOLTYPE => $tool->type, self::BOUTONLIBTOOL => $tool->label, self::MESSAGELIB => '');
M. Chardon's avatar
M. Chardon committed
408
409
                    }
                } else {
410
                    $res = array(array(self::AXEID => $axeNew, self::AXELIB => $axeToImport->label, self::MESSAGELIB => ""));
M. Chardon's avatar
M. Chardon committed
411
412
413
414
415
                }

                return $res;
            }
        }
416
        return array(self::getMessageError());
M. Chardon's avatar
M. Chardon committed
417
418
    }

M. Chardon's avatar
M. Chardon committed
419
420
421
422
    /**
     * Form return structure
     * @return \external_multiple_structure
     */
M. Chardon's avatar
M. Chardon committed
423
424
425
    public static function submit_axis_import_form_returns() {
        return new external_multiple_structure(
                new external_single_structure(
M. Chardon's avatar
M. Chardon committed
426
427
428
429
430
431
432
433
434
                        array(
                    self::AXEID => new external_value(PARAM_INT, self::AXEIDDESC, VALUE_OPTIONAL),
                    self::AXELIB => new external_value(PARAM_TEXT, self::AXELIBDESC, VALUE_OPTIONAL),
                    self::MESSAGELIB => new external_value(PARAM_TEXT, self::MESSAGELIB),
                    self::ENABLETOOL => new external_value(PARAM_INT, self::ENABLETOOLDESC, VALUE_OPTIONAL),
                    self::TOOLID => new external_value(PARAM_INT, self::TOOLIDDESC, VALUE_OPTIONAL),
                    self::TOOLTYPE => new external_value(PARAM_INT, self::TOOLTYPEDESC, VALUE_OPTIONAL),
                    self::BOUTONLIBTOOL => new external_value(PARAM_TEXT, self::TOOLLIBDESC, VALUE_OPTIONAL)
                        )
M. Chardon's avatar
M. Chardon committed
435
                )
M. Chardon's avatar
M. Chardon committed
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
        );
    }

    /**
     * Returns description of method parameters
     * @return external_function_parameters
     */
    public static function submit_axis_export_form_parameters() {
        return self::submit_generic_form_parameters();
    }

    /**
     * Submit axis form for exporting
     * @param String $jsonformdata
     * @return array
     */
    public static function submit_axis_export_form($jsonformdata) {
        global $USER;

        $data = self::getParseData(self::submit_axis_export_form_parameters(), $jsonformdata);

        $context = self::setPageContext($data[self::CONTEXTID]);

        $customdata = (object) $data;
        $formparams = array($customdata);

        // Data is injected into the form by the last param for the constructor.
        $mform = new axis_export_form(null, $formparams, 'post', '', null, true, $data);
        $validateddata = $mform->get_data();

        if ($validateddata && $validateddata->axeid) {
            $axeToExport = admin_editor::getAxisById($validateddata->axeid);
            $axeToExport->label = $validateddata->label;
            $axeNew = admin_editor::import_axis($axeToExport, -1);
            if ($axeNew) {
                $tools = admin_editor::get_tools_by_axis($axeToExport->id);
                foreach ($tools as $toolToImport) {
                    admin_editor::import_tool($toolToImport, $axeNew, $context->id);
                }
                $model = admin_editor::addModel($axeNew, $validateddata->label, $USER);
                if ($model > -1) {
                    $res = array();
                    $toolsNew = admin_editor::get_tools_by_axis($axeNew);
                    if (sizeof($toolsNew) > 0) {
                        foreach ($toolsNew as $tool) {
                            $tool->setDesign();
                            $res[] = array('modelid' => $model, self::AXEID => $axeNew, self::AXELIB => $validateddata->label, self::MESSAGELIB => "", self::ENABLETOOL => $tool->enabled, self::TOOLID => $tool->id, self::TOOLTYPE => $tool->type, self::BOUTONLIBTOOL => $tool->label, 'style' => $tool->style);
                        }
                    } else {
                        $res = array(array('modelid' => $model, self::AXEID => $axeNew, self::AXELIB => $validateddata->label, self::MESSAGELIB => ""));
                    }

                    return $res;
                }
            }
        }
        return array(self::getMessageError());
    }

    /**
     * Form return structure
     * @return \external_multiple_structure
     */
    public static function submit_axis_export_form_returns() {
        return new external_multiple_structure(
                new external_single_structure(
                        array(
                    'modelid' => new external_value(PARAM_INT, self::AXEIDDESC, VALUE_OPTIONAL),
                    self::AXEID => new external_value(PARAM_INT, self::AXEIDDESC, VALUE_OPTIONAL),
                    self::AXELIB => new external_value(PARAM_TEXT, self::AXELIBDESC, VALUE_OPTIONAL),
                    self::MESSAGELIB => new external_value(PARAM_TEXT, self::MESSAGELIB),
                    self::ENABLETOOL => new external_value(PARAM_INT, self::ENABLETOOLDESC, VALUE_OPTIONAL),
                    self::TOOLID => new external_value(PARAM_INT, self::TOOLIDDESC, VALUE_OPTIONAL),
                    self::TOOLTYPE => new external_value(PARAM_INT, self::TOOLTYPEDESC, VALUE_OPTIONAL),
                    self::BOUTONLIBTOOL => new external_value(PARAM_TEXT, self::TOOLLIBDESC, VALUE_OPTIONAL),
                    'style' => new external_value(PARAM_TEXT, self::TOOLLIBDESC, VALUE_OPTIONAL)
                        )
M. Chardon's avatar
M. Chardon committed
513
514
515
516
                )
        );
    }

517
518
519
    /**
     * Returns description of method parameters
     * @return external_function_parameters
M. Chardon's avatar
M. Chardon committed
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
     */
    public static function submit_model_del_form_parameters() {
        return self::submit_generic_form_parameters();
    }

    /**
     * Submit axis form for deleting
     * @param String $jsonformdata
     * @return array
     */
    public static function submit_model_del_form($jsonformdata) {
        $data = self::getParseData(self::submit_axis_form_parameters(), $jsonformdata);

        self::setPageContext($data[self::CONTEXTID]);

        $customdata = (object) $data;
        $formparams = array($customdata);

        // Data is injected into the form by the last param for the constructor.
        $mform = new model_del_form(null, $formparams, 'post', '', null, true, $data);
        $validateddata = $mform->get_data();

        if ($validateddata && $validateddata->modelid && admin_editor::delModel($validateddata->modelid)) {
            $message = "1";
            return array(array(self::MESSAGELIB => $message));
        }
        $warnings = array();
        $message = get_string('admindeltool_messageko', self::PLUGINNAME);
        $warnings[] = array(self::MESSAGELIB => $message);
        return $warnings;
    }

    /**
     * Form return structure
     * @return \external_multiple_structure
     */
    public static function submit_model_del_form_returns() {
        return new external_multiple_structure(
                self::submit_generic_form_returns()
        );
    }

    /**
     * Returns description of method parameters
     * @return external_function_parameters
565
566
     */
    public static function submit_tool_order_form_parameters() {
567
        return self::submit_generic_form_parameters();
568
569
570
571
572
573
574
575
    }

    /**
     * Submit tool form for changing order
     * @param String $jsonformdata
     * @return array
     */
    public static function submit_tool_order_form($jsonformdata) {
576
        $data = self::getParseData(self::submit_tool_order_form_parameters(), $jsonformdata);
577

578
        self::setPageContext($data[self::CONTEXTID]);
579
580
581
582
583
584

        $customdata = (object) $data;

        $sessionkey = sesskey();
        if ($sessionkey == $customdata->sesskey && $customdata->toolid) {
            admin_editor::edit_tool_order($customdata);
585
            return array(self::MESSAGELIB => 'ok');
586
        }
587
        return self::getMessageError();
588
589
590
591
592
593
594
    }

    /**
     * Form return structure
     * @return \external_multiple_structure
     */
    public static function submit_tool_order_form_returns() {
595
        return self::submit_generic_form_returns();
596
597
    }

M. Chardon's avatar
M. Chardon committed
598
}