Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
<?php
2
// This file is part of Moodle - http://moodle.org/
3
//
4
// Moodle is free software: you can redistribute it and/or modify
5
// it under the terms of the GNU General Public License as published by
6
// the Free Software Foundation, either version 3 of the License, or
7
// (at your option) any later version.
8
//
9
// Moodle is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
// GNU General Public License for more details.
13
//
14
// You should have received a copy of the GNU General Public License
15
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
16
 
17
/**
18
 * This file contains the functions for managing a users comments quicklist.
19
 *
20
 * @package   assignfeedback_editpdf
21
 * @copyright 2012 Davo Smith
22
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23
 */
24
 
25
namespace assignfeedback_editpdf;
26
 
27
/**
28
 * This class performs crud operations on a users quicklist comments.
29
 *
30
 * No capability checks are done - they should be done by the calling class.
31
 * @package   assignfeedback_editpdf
32
 * @copyright 2012 Davo Smith
33
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
34
 */
35
class comments_quick_list {
36
 
37
    /**
38
     * Get all comments for the current user.
39
     * @return array(comment)
40
     */
41
    public static function get_comments() {
42
        global $DB, $USER;
43
 
44
        $comments = array();
45
        $records = $DB->get_records('assignfeedback_editpdf_quick', array('userid'=>$USER->id));
46
 
47
        return $records;
48
    }
49
 
50
    /**
51
     * Add a comment to the quick list.
52
     * @param string $commenttext
53
     * @param int $width
54
     * @param string $colour
55
     * @return \stdClass - the comment record (with new id set)
56
     */
57
    public static function add_comment($commenttext, $width, $colour) {
58
        global $DB, $USER;
59
 
60
        $comment = new \stdClass();
61
        $comment->userid = $USER->id;
62
        $comment->rawtext = $commenttext;
63
        $comment->width = $width;
64
        $comment->colour = $colour;
65
 
66
        $comment->id = $DB->insert_record('assignfeedback_editpdf_quick', $comment);
67
        return $comment;
68
    }
69
 
70
    /**
71
     * Get a single comment by id.
72
     * @param int $commentid
73
     * @return comment or false
74
     */
75
    public static function get_comment($commentid) {
76
        global $DB;
77
 
78
        $record = $DB->get_record('assignfeedback_editpdf_quick', array('id'=>$commentid), '*', IGNORE_MISSING);
79
        if ($record) {
80
            return $record;
81
        }
82
        return false;
83
    }
84
 
85
    /**
86
     * Remove a comment from the quick list.
87
     * @param int $commentid
88
     * @return bool
89
     */
90
    public static function remove_comment($commentid) {
91
        global $DB, $USER;
92
        return $DB->delete_records('assignfeedback_editpdf_quick', array('id'=>$commentid, 'userid'=>$USER->id));
93
    }
94
}