Gitlab CSE Unil

page_editor.php 23.7 KB
Newer Older
M. Chardon's avatar
init  
M. Chardon committed
1
<?php
2

M. Chardon's avatar
init  
M. Chardon committed
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
// 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/>.

/**
 * This file contains the editor class for the assignfeedback_editpdfplus plugin
 *
 * @package   assignfeedback_editpdfplus
M. Chardon's avatar
GPL3    
M. Chardon committed
22
 * @copyright  2016 Université de Lausanne
M. Chardon's avatar
init  
M. Chardon committed
23
24
25
26
27
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */

namespace assignfeedback_editpdfplus;

28
29
use assignfeedback_editpdfplus\tool;

M. Chardon's avatar
init  
M. Chardon committed
30
31
32
33
34
35
36
37
38
39
40
/**
 * This class performs crud operations on comments and annotations from a page of a response.
 *
 * No capability checks are done - they should be done by the calling class.
 *
 * @package   assignfeedback_editpdfplus
 * @copyright 2012 Davo Smith
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */
class page_editor {

41
42
43
44
45
46
47
48
49
    /**
     * Get all tools for a page.
     * @param int $contextid
     * @param int $axis
     * @return tool[]
     */
    public static function get_tools($contextidlist) {
        global $DB;
        $tools = array();
50
51
52
53
54
        if ($contextidlist) {
            $records = $DB->get_records_list('assignfeedback_editpp_tool', 'contextid', $contextidlist);
        } else {
            $records = $DB->get_records('assignfeedback_editpp_tool');
        }
55
        foreach ($records as $record) {
M. Chardon's avatar
M. Chardon committed
56
            //if ($record->enabled == 1) {
57
            array_push($tools, new tool($record));
M. Chardon's avatar
M. Chardon committed
58
            //}
59
        }
M. Chardon's avatar
M. Chardon committed
60
        usort($tools, function($a, $b) {
M. Chardon's avatar
M. Chardon committed
61
62
            $al = $a->order_tool;
            $bl = $b->order_tool;
M. Chardon's avatar
M. Chardon committed
63
64
65
66
67
            if ($al == $bl) {
                return 0;
            }
            return ($al > $bl) ? +1 : -1;
        });
68
        return $tools;
M. Chardon's avatar
init  
M. Chardon committed
69
70
    }

M. Chardon's avatar
M. Chardon committed
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
    /**
     * Get a single tool by id.
     * @param int $toolid
     * @return tool or false
     */
    public static function get_tool($toolid) {
        global $DB;
        $record = $DB->get_record('assignfeedback_editpp_tool', array('id' => $toolid), '*', IGNORE_MISSING);
        if ($record) {
            return new tool($record);
        }
        return false;
    }

    /**
86
     * Get the tool type with id tooltypeid.
M. Chardon's avatar
M. Chardon committed
87
88
89
90
91
92
93
     * @param int $tooltypeid
     * @return type_tool
     */
    public static function get_type_tool($tooltypeid) {
        global $DB;
        $record = $DB->get_record('assignfeedback_editpp_typet', array('id' => $tooltypeid));
        if ($record) {
94
95
            $newTypeTool = new type_tool($record);
            return page_editor::custom_type_tool($newTypeTool);
M. Chardon's avatar
M. Chardon committed
96
97
98
99
        }
        return false;
    }

100
101
102
103
104
    /**
     * Get all the type tools.
     * @param array $contextidlist
     * @return type_tool
     */
M. Chardon's avatar
M. Chardon committed
105
106
107
108
109
110
111
112
113
    public static function get_typetools($contextidlist) {
        global $DB;
        $typetools = array();
        if ($contextidlist) {
            $records = $DB->get_records_list('assignfeedback_editpp_typet', 'contextid', $contextidlist);
        } else {
            $records = $DB->get_records('assignfeedback_editpp_typet');
        }
        foreach ($records as $record) {
114
115
            $newToolType = new type_tool($record);
            array_push($typetools, page_editor::custom_type_tool($newToolType));
M. Chardon's avatar
M. Chardon committed
116
117
118
119
        }
        return $typetools;
    }

M. Chardon's avatar
M. Chardon committed
120
    /**
121
122
     * Get all axis for contextid.
     * @param array $contextidlist optional
M. Chardon's avatar
M. Chardon committed
123
     * @return axis[]
M. Chardon's avatar
M. Chardon committed
124
125
126
127
128
129
130
131
132
133
     */
    public static function get_axis($contextidlist) {
        global $DB;
        $axis = array();
        if ($contextidlist) {
            $records = $DB->get_records_list('assignfeedback_editpp_axis', 'contextid', $contextidlist);
        } else {
            $records = $DB->get_records('assignfeedback_editpp_axis');
        }
        foreach ($records as $record) {
M. Chardon's avatar
M. Chardon committed
134
            array_push($axis, new axis($record));
M. Chardon's avatar
M. Chardon committed
135
136
        }
        usort($axis, function($a, $b) {
M. Chardon's avatar
M. Chardon committed
137
138
            $al = $a->order_axis;
            $bl = $b->order_axis;
M. Chardon's avatar
M. Chardon committed
139
140
141
142
143
144
145
146
            if ($al == $bl) {
                return 0;
            }
            return ($al > $bl) ? +1 : -1;
        });
        return $axis;
    }

M. Chardon's avatar
init  
M. Chardon committed
147
148
149
150
151
152
153
154
155
156
    /**
     * Get all annotations for a page.
     * @param int $gradeid
     * @param int $pageno
     * @param bool $draft
     * @return annotation[]
     */
    public static function get_annotations($gradeid, $pageno, $draft) {
        global $DB;

157
        $params = array('gradeid' => $gradeid, 'pageno' => $pageno, 'draft' => 1);
M. Chardon's avatar
init  
M. Chardon committed
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
        if (!$draft) {
            $params['draft'] = 0;
        }
        $annotations = array();
        $records = $DB->get_records('assignfeedback_editpp_annot', $params);
        foreach ($records as $record) {
            array_push($annotations, new annotation($record));
        }

        return $annotations;
    }

    /**
     * Set all annotations for a page.
     * @param int $gradeid
     * @param int $pageno
     * @param annotation[] $annotations
     * @return int - the number of annotations.
     */
    public static function set_annotations($gradeid, $pageno, $annotations) {
        global $DB;

        $DB->delete_records('assignfeedback_editpp_annot', array('gradeid' => $gradeid, 'pageno' => $pageno, 'draft' => 1));
        $added = 0;
182
        $annotationdiv = array();
M. Chardon's avatar
init  
M. Chardon committed
183
        foreach ($annotations as $record) {
184
185
186
187
188
189
            $currentdiv = $record->divcartridge;
            if ($record->parent_annot_div != '') {
                //on est dans le cas d'une annotation liee
                $idparent = $annotationdiv[$record->parent_annot_div];
                $record->parent_annot = intval($idparent);
            }
M. Chardon's avatar
init  
M. Chardon committed
190
191
192
193
194
195
196
197
198
            // Force these.
            if (!($record instanceof annotation)) {
                $annotation = new annotation($record);
            } else {
                $annotation = $record;
            }
            $annotation->gradeid = $gradeid;
            $annotation->pageno = $pageno;
            $annotation->draft = 1;
199
200
201
202
203
            $newid = self::add_annotation($annotation);
            if ($newid) {
                if ($currentdiv != '') {
                    $annotationdiv[$currentdiv] = $newid;
                }
M. Chardon's avatar
init  
M. Chardon committed
204
205
206
207
208
209
210
                $added++;
            }
        }

        return $added;
    }

211
212
213
214
215
216
217
    /**
     * Update a set of annotations to database
     * @global $DB
     * @param annotation[] $annotations
     * @return int number of rows updated
     */
    public static function update_annotations_status($annotations) {
218
219
220
221
        global $DB;
        $added = 0;
        foreach ($annotations as $recordtmp) {
            $record = page_editor::get_annotation($recordtmp->id);
222
            //$old = $record->studentstatus;
223
            $record->studentstatus = $recordtmp->studentstatus;
224
            $record->studentanswer = $recordtmp->studentanswer;
225
            //debugging($recordtmp->id . ' - ' . $record->id . ' - ' . $old . ' | ' . $recordtmp->studentstatus . ' - ' . $record->studentstatus . ' | ' . $recordtmp->studentanswer . ' - ' . $record->studentanswer);
226
227
228
229
230
231
232
            $DB->update_record('assignfeedback_editpp_annot', $record);
            $added++;
        }

        return $added;
    }

M. Chardon's avatar
init  
M. Chardon committed
233
234
235
236
237
238
239
240
    /**
     * Get a single annotation by id.
     * @param int $annotationid
     * @return annotation or false
     */
    public static function get_annotation($annotationid) {
        global $DB;

241
        $record = $DB->get_record('assignfeedback_editpp_annot', array('id' => $annotationid), '*', IGNORE_MISSING);
M. Chardon's avatar
init  
M. Chardon committed
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
        if ($record) {
            return new annotation($record);
        }
        return false;
    }

    /**
     * Unrelease drafts
     * @param int $gradeid
     * @return bool
     */
    public static function unrelease_drafts($gradeid) {
        global $DB;

        // Delete the non-draft annotations and comments.
257
258
        $result = $DB->delete_records('assignfeedback_editpp_cmnt', array('gradeid' => $gradeid, 'draft' => 0));
        $result = $DB->delete_records('assignfeedback_editpp_annot', array('gradeid' => $gradeid, 'draft' => 0)) && $result;
M. Chardon's avatar
init  
M. Chardon committed
259
260
261
262
263
264
265
266
267
268
269
270
        return $result;
    }

    /**
     * Release the draft comments and annotations to students.
     * @param int $gradeid
     * @return bool
     */
    public static function release_drafts($gradeid) {
        global $DB;

        // Delete the previous non-draft annotations and comments.
271
272
        $DB->delete_records('assignfeedback_editpp_cmnt', array('gradeid' => $gradeid, 'draft' => 0));
        $DB->delete_records('assignfeedback_editpp_annot', array('gradeid' => $gradeid, 'draft' => 0));
M. Chardon's avatar
init  
M. Chardon committed
273
274

        // Copy all the draft annotations and comments to non-drafts.
275
        $parentlink = [];
276
        $records = $DB->get_records('assignfeedback_editpp_annot', array('gradeid' => $gradeid, 'draft' => 1));
M. Chardon's avatar
init  
M. Chardon committed
277
        foreach ($records as $record) {
278
            $oldid = $record->id;
M. Chardon's avatar
init  
M. Chardon committed
279
280
            unset($record->id);
            $record->draft = 0;
281
282
283
284
285
286
            $oldparentrecord = $record->parent_annot;
            if ($record->parent_annot > 0) {
                $record->parent_annot = $parentlink[$record->parent_annot];
            }
            $newid = $DB->insert_record('assignfeedback_editpp_annot', $record);
            $parentlink[$oldid] = $newid;
M. Chardon's avatar
init  
M. Chardon committed
287
        }
288
289
290
291
292
293
        /* $records = $DB->get_records('assignfeedback_editpp_cmnt', array('gradeid' => $gradeid, 'draft' => 1));
          foreach ($records as $record) {
          unset($record->id);
          $record->draft = 0;
          $DB->insert_record('assignfeedback_editpp_cmnt', $record);
          } */
M. Chardon's avatar
init  
M. Chardon committed
294
295
296
297
298
299
300
301
302
303
304

        return true;
    }

    /**
     * Has annotations or comments.
     * @param int $gradeid
     * @return bool
     */
    public static function has_annotations_or_comments($gradeid, $includedraft) {
        global $DB;
305
        $params = array('gradeid' => $gradeid);
M. Chardon's avatar
init  
M. Chardon committed
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
        if (!$includedraft) {
            $params['draft'] = 0;
        }
        if ($DB->count_records('assignfeedback_editpp_cmnt', $params)) {
            return true;
        }
        if ($DB->count_records('assignfeedback_editpp_annot', $params)) {
            return true;
        }
        return false;
    }

    /**
     * Aborts all draft annotations and reverts to the last version released to students.
     * @param int $gradeid
     * @return bool
     */
    public static function revert_drafts($gradeid) {
        global $DB;

        // Delete the previous non-draft annotations and comments.
327
328
        $DB->delete_records('assignfeedback_editpp_cmnt', array('gradeid' => $gradeid, 'draft' => 1));
        $DB->delete_records('assignfeedback_editpp_annot', array('gradeid' => $gradeid, 'draft' => 1));
M. Chardon's avatar
init  
M. Chardon committed
329
330

        // Copy all the draft annotations and comments to non-drafts.
331
        $records = $DB->get_records('assignfeedback_editpp_annot', array('gradeid' => $gradeid, 'draft' => 0));
M. Chardon's avatar
init  
M. Chardon committed
332
333
334
335
336
        foreach ($records as $record) {
            unset($record->id);
            $record->draft = 0;
            $DB->insert_record('assignfeedback_editpp_annot', $record);
        }
337
338
339
340
341
342
        /* $records = $DB->get_records('assignfeedback_editpp_cmnt', array('gradeid' => $gradeid, 'draft' => 0));
          foreach ($records as $record) {
          unset($record->id);
          $record->draft = 0;
          $DB->insert_record('assignfeedback_editpp_annot', $record);
          } */
M. Chardon's avatar
init  
M. Chardon committed
343
344
345
346
347
348
349
350
351
352
353
354
355

        return true;
    }

    /**
     * Add a annotation to a page.
     * @param annotation $annotation
     * @return bool
     */
    public static function add_annotation(annotation $annotation) {
        global $DB;

        $annotation->id = null;
356
357
358
        if ($annotation->parent_annot == 0) {
            $annotation->parent_annot = null;
        }
M. Chardon's avatar
init  
M. Chardon committed
359
360
361
362
363
364
365
366
367
368
369
        return $DB->insert_record('assignfeedback_editpp_annot', $annotation);
    }

    /**
     * Remove a annotation from a page.
     * @param int $annotationid
     * @return bool
     */
    public static function remove_annotation($annotationid) {
        global $DB;

370
        return $DB->delete_records('assignfeedback_editpp_annot', array('id' => $annotationid));
M. Chardon's avatar
init  
M. Chardon committed
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
    }

    /**
     * Copy annotations, comments, pages, and other required content from the source user to the current group member
     * being procssed when using applytoall.
     *
     * @param int|\assign $assignment
     * @param stdClass $grade
     * @param int $sourceuserid
     * @return bool
     */
    public static function copy_drafts_from_to($assignment, $grade, $sourceuserid) {
        global $DB;

        // Delete any existing annotations and comments from current user.
        $DB->delete_records('assignfeedback_editpp_annot', array('gradeid' => $grade->id));
387
        //$DB->delete_records('assignfeedback_editpp_cmnt', array('gradeid' => $grade->id));
M. Chardon's avatar
init  
M. Chardon committed
388
389
390
        // Get gradeid, annotations and comments from sourceuserid.
        $sourceusergrade = $assignment->get_user_grade($sourceuserid, true, $grade->attemptnumber);
        $annotations = $DB->get_records('assignfeedback_editpp_annot', array('gradeid' => $sourceusergrade->id, 'draft' => 1));
391
        //$comments = $DB->get_records('assignfeedback_editpp_cmnt', array('gradeid' => $sourceusergrade->id, 'draft' => 1));
M. Chardon's avatar
init  
M. Chardon committed
392
393
394
395
396
397
398
399
        $contextid = $assignment->get_context()->id;
        $sourceitemid = $sourceusergrade->id;

        // Add annotations and comments to current user to generate feedback file.
        foreach ($annotations as $annotation) {
            $annotation->gradeid = $grade->id;
            $DB->insert_record('assignfeedback_editpp_annot', $annotation);
        }
400
401
402
403
        /* foreach ($comments as $comment) {
          $comment->gradeid = $grade->id;
          $DB->insert_record('assignfeedback_editpp_cmnt', $comment);
          } */
M. Chardon's avatar
init  
M. Chardon committed
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431

        $fs = get_file_storage();

        // Copy the stamp files.
        self::replace_files_from_to($fs, $contextid, $sourceitemid, $grade->id, document_services::STAMPS_FILEAREA, true);

        // Copy the PAGE_IMAGE_FILEAREA files.
        self::replace_files_from_to($fs, $contextid, $sourceitemid, $grade->id, document_services::PAGE_IMAGE_FILEAREA);

        return true;
    }

    /**
     * Replace the area files in the specified area with those in the source item id.
     *
     * @param \file_storage $fs The file storage class
     * @param int $contextid The ID of the context for the assignment.
     * @param int $sourceitemid The itemid to copy from - typically the source grade id.
     * @param int $itemid The itemid to copy to - typically the target grade id.
     * @param string $area The file storage area.
     * @param bool $includesubdirs Whether to copy the content of sub-directories too.
     */
    public static function replace_files_from_to($fs, $contextid, $sourceitemid, $itemid, $area, $includesubdirs = false) {
        $component = 'assignfeedback_editpdfplus';
        // Remove the existing files within this area.
        $fs->delete_area_files($contextid, $component, $area, $itemid);

        // Copy the files from the source area.
432
        if ($files = $fs->get_area_files($contextid, $component, $area, $sourceitemid, "filename", $includesubdirs)) {
M. Chardon's avatar
init  
M. Chardon committed
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
            foreach ($files as $file) {
                $newrecord = new \stdClass();
                $newrecord->contextid = $contextid;
                $newrecord->itemid = $itemid;
                $fs->create_file_from_storedfile($newrecord, $file);
            }
        }
    }

    /**
     * Delete the draft annotations and comments.
     *
     * This is intended to be used when the version of the PDF has changed and the annotations
     * might not be relevant any more, therefore we should delete them.
     *
     * @param int $gradeid The grade ID.
     * @return bool
     */
    public static function delete_draft_content($gradeid) {
        global $DB;
        $conditions = array('gradeid' => $gradeid, 'draft' => 1);
        $result = $DB->delete_records('assignfeedback_editpp_annot', $conditions);
        $result = $result && $DB->delete_records('assignfeedback_editpp_cmnt', $conditions);
        return $result;
    }
458

459
460
461
462
463
464
465
466
467
    /**
     * Get the feedback comment from the database.
     *
     * @param int $gradeid
     * @return stdClass|false The feedback comments for the given grade if it exists.
     *                        False if it doesn't.
     */
    public function get_feedback_comments($gradeid) {
        global $DB;
468
        return $DB->get_record('assignfeedback_comments', array('grade' => $gradeid));
469
470
    }

471
472
473
474
    public static function custom_type_tool(type_tool $newToolType) {
        global $CFG;
        switch ($newToolType->label) {
            case 'highlightplus':
M. Chardon's avatar
M. Chardon committed
475
                /*if (isset($CFG->highlightplus_configurable) && (intval($CFG->highlightplus_configurable) == 0 || intval($CFG->highlightplus_configurable) == 1)) {
476
477
478
479
480
                    if (intval($CFG->highlightplus_configurable) == 0) {
                        $newToolType->configurable = 1;
                    } else {
                        $newToolType->configurable = 0;
                    }
M. Chardon's avatar
M. Chardon committed
481
                }*/
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
                if (isset($CFG->highlightplus_color) && $CFG->highlightplus_color != null && strlen($CFG->highlightplus_color) > 4) {
                    $newToolType->color = $CFG->highlightplus_color;
                }
                if (isset($CFG->highlightplus_cartridge_color) && $CFG->highlightplus_cartridge_color != null && strlen($CFG->highlightplus_cartridge_color) > 4) {
                    $newToolType->cartridge_color = $CFG->highlightplus_cartridge_color;
                }
                if (isset($CFG->highlightplus_cartridge_x) && (intval($CFG->highlightplus_cartridge_x) || $CFG->highlightplus_cartridge_x == '0')) {
                    $newToolType->cartridge_x = intval($CFG->highlightplus_cartridge_x);
                }
                if (isset($CFG->highlightplus_cartridge_y) && (intval($CFG->highlightplus_cartridge_y) || $CFG->highlightplus_cartridge_y == '0')) {
                    $newToolType->cartridge_y = intval($CFG->highlightplus_cartridge_y);
                }
                break;

            case 'stampplus':
M. Chardon's avatar
M. Chardon committed
497
                /*if (isset($CFG->stampplus_configurable) && (intval($CFG->stampplus_configurable) == 0 || intval($CFG->stampplus_configurable) == 1)) {
498
499
500
501
502
                    if (intval($CFG->stampplus_configurable) == 0) {
                        $newToolType->configurable = 1;
                    } else {
                        $newToolType->configurable = 0;
                    }
M. Chardon's avatar
M. Chardon committed
503
                }*/
504
505
506
507
508
509
                if (isset($CFG->stampplus_color) && $CFG->stampplus_color != null && strlen($CFG->stampplus_color) > 4) {
                    $newToolType->color = $CFG->stampplus_color;
                }
                break;

            case 'frame':
M. Chardon's avatar
M. Chardon committed
510
                /*if (isset($CFG->frame_configurable) && (intval($CFG->frame_configurable) == 0 || intval($CFG->frame_configurable) == 1)) {
511
512
513
514
515
                    if (intval($CFG->frame_configurable) == 0) {
                        $newToolType->configurable = 1;
                    } else {
                        $newToolType->configurable = 0;
                    }
M. Chardon's avatar
M. Chardon committed
516
                }*/
517
518
519
520
521
522
523
524
525
                if (isset($CFG->frame_cartridge_x) && (intval($CFG->frame_cartridge_x) || $CFG->frame_cartridge_x == '0')) {
                    $newToolType->cartridge_x = intval($CFG->frame_cartridge_x);
                }
                if (isset($CFG->frame_cartridge_y) && (intval($CFG->frame_cartridge_y) || $CFG->frame_cartridge_y == '0')) {
                    $newToolType->cartridge_y = intval($CFG->frame_cartridge_y);
                }
                break;

            case 'verticalline':
M. Chardon's avatar
M. Chardon committed
526
                /*if (isset($CFG->verticalline_configurable) && (intval($CFG->verticalline_configurable) == 0 || intval($CFG->verticalline_configurable) == 1)) {
527
528
529
530
531
                    if (intval($CFG->verticalline_configurable) == 0) {
                        $newToolType->configurable = 1;
                    } else {
                        $newToolType->configurable = 0;
                    }
M. Chardon's avatar
M. Chardon committed
532
                }*/
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
                if (isset($CFG->verticalline_color) && $CFG->verticalline_color != null && strlen($CFG->verticalline_color) > 4) {
                    $newToolType->color = $CFG->verticalline_color;
                }
                if (isset($CFG->verticalline_cartridge_color) && $CFG->verticalline_cartridge_color != null && strlen($CFG->verticalline_cartridge_color) > 4) {
                    $newToolType->cartridge_color = $CFG->verticalline_cartridge_color;
                }
                if (isset($CFG->verticalline_cartridge_x) && (intval($CFG->verticalline_cartridge_x) || $CFG->verticalline_cartridge_x == '0')) {
                    $newToolType->cartridge_x = intval($CFG->verticalline_cartridge_x);
                }
                if (isset($CFG->verticalline_cartridge_y) && (intval($CFG->verticalline_cartridge_y) || $CFG->verticalline_cartridge_y == '0')) {
                    $newToolType->cartridge_y = intval($CFG->verticalline_cartridge_y);
                }
                break;

            case 'stampcomment':
M. Chardon's avatar
M. Chardon committed
548
                /*if (isset($CFG->stampcomment_configurable) && (intval($CFG->stampcomment_configurable) == 0 || intval($CFG->stampcomment_configurable) == 1)) {
549
550
551
552
553
                    if (intval($CFG->stampcomment_configurable) == 0) {
                        $newToolType->configurable = 1;
                    } else {
                        $newToolType->configurable = 0;
                    }
M. Chardon's avatar
M. Chardon committed
554
                }*/
M. Chardon's avatar
M. Chardon committed
555
                /*if (isset($CFG->stampcomment_color) && $CFG->stampcomment_color != null && strlen($CFG->stampcomment_color) > 4) {
556
                    $newToolType->color = $CFG->stampcomment_color;
M. Chardon's avatar
M. Chardon committed
557
                }*/
558
559
560
561
562
563
564
565
566
567
568
569
                if (isset($CFG->stampcomment_cartridge_color) && $CFG->stampcomment_cartridge_color != null && strlen($CFG->stampcomment_cartridge_color) > 4) {
                    $newToolType->cartridge_color = $CFG->stampcomment_cartridge_color;
                }
                if (isset($CFG->stampcomment_cartridge_x) && (intval($CFG->stampcomment_cartridge_x) || $CFG->stampcomment_cartridge_x == '0')) {
                    $newToolType->cartridge_x = intval($CFG->stampcomment_cartridge_x);
                }
                if (isset($CFG->stampcomment_cartridge_y) && (intval($CFG->stampcomment_cartridge_y) || $CFG->stampcomment_cartridge_y == '0')) {
                    $newToolType->cartridge_y = intval($CFG->stampcomment_cartridge_y);
                }
                break;

            case 'commentplus':
M. Chardon's avatar
M. Chardon committed
570
                /*if (isset($CFG->commentplus_configurable) && (intval($CFG->commentplus_configurable) == 0 || intval($CFG->commentplus_configurable) == 1)) {
571
572
573
574
575
                    if (intval($CFG->commentplus_configurable) == 0) {
                        $newToolType->configurable = 1;
                    } else {
                        $newToolType->configurable = 0;
                    }
M. Chardon's avatar
M. Chardon committed
576
                }*/
577
                if (isset($CFG->commentplus_cartridge_color) && $CFG->commentplus_cartridge_color != null && strlen($CFG->commentplus_cartridge_color) > 4) {
M. Chardon's avatar
M. Chardon committed
578
                    $newToolType->cartridge_color = $CFG->commentplus_cartridge_color;
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
                }
                if (isset($CFG->commentplus_cartridge_x) && (intval($CFG->commentplus_cartridge_x) || $CFG->commentplus_cartridge_x == '0')) {
                    $newToolType->cartridge_x = intval($CFG->commentplus_cartridge_x);
                }
                if (isset($CFG->commentplus_cartridge_y) && (intval($CFG->commentplus_cartridge_y) || $CFG->commentplus_cartridge_y == '0')) {
                    $newToolType->cartridge_y = intval($CFG->commentplus_cartridge_y);
                }
                break;

            default:
                break;
        }
        return $newToolType;
    }

M. Chardon's avatar
init  
M. Chardon committed
594
}