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
 * Exporting a comment area.
19
 *
20
 * A comment area is the set of information about a defined comments area.
21
 *
22
 * @package    core_comment
23
 * @copyright  2015 Frédéric Massart - FMCorz.net
24
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25
 */
26
namespace core_comment\external;
27
defined('MOODLE_INTERNAL') || die();
28
 
29
require_once($CFG->dirroot . '/comment/lib.php');
30
 
31
use comment;
32
use renderer_base;
33
use stdClass;
34
 
35
/**
36
 * Class for exporting a comment area.
37
 *
38
 * @package    core_comment
39
 * @copyright  2015 Frédéric Massart - FMCorz.net
40
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
41
 */
42
class comment_area_exporter extends \core\external\exporter {
43
 
44
    /** @var comment The comment instance. */
45
    protected $comment = null;
46
 
47
    public function __construct(comment $comment, $related = array()) {
48
        $this->comment = $comment;
49
        $data = new stdClass();
50
        $data->component = $comment->get_component();
51
        $data->commentarea = $comment->get_commentarea();
52
        $data->itemid = $comment->get_itemid();
53
        $data->courseid = $comment->get_courseid();
54
        $data->contextid = $comment->get_context()->id;
55
        $data->cid = $comment->get_cid();
56
 
57
        parent::__construct($data, $related);
58
    }
59
 
60
    protected static function define_properties() {
61
        return array(
62
            'component' => array(
63
                'type' => PARAM_COMPONENT,
64
            ),
65
            'commentarea' => array(
66
                'type' => PARAM_AREA,
67
            ),
68
            'itemid' => array(
69
                'type' => PARAM_INT,
70
            ),
71
            'courseid' => array(
72
                'type' => PARAM_INT,
73
            ),
74
            'contextid' => array(
75
                'type' => PARAM_INT,
76
            ),
77
            'cid' => array(
78
                'type' => PARAM_ALPHANUMEXT,
79
            ),
80
        );
81
    }
82
 
83
    protected static function define_other_properties() {
84
        return array(
85
            'autostart' => array(
86
                'type' => PARAM_BOOL,
87
            ),
88
            'canpost' => array(
89
                'type' => PARAM_BOOL,
90
            ),
91
            'canview' => array(
92
                'type' => PARAM_BOOL,
93
            ),
94
            'count' => array(
95
                'type' => PARAM_INT,
96
            ),
97
            'collapsediconkey' => array(
98
                'type' => PARAM_RAW,
99
            ),
100
            'displaytotalcount' => array(
101
                'type' => PARAM_BOOL,
102
            ),
103
            'displaycancel' => array(
104
                'type' => PARAM_BOOL,
105
            ),
106
            'fullwidth' => array(
107
                'type' => PARAM_BOOL,
108
            ),
109
            'linktext' => array(
110
                'type' => PARAM_RAW,
111
            ),
112
            'notoggle' => array(
113
                'type' => PARAM_BOOL,
114
            ),
115
            'template' => array(
116
                'type' => PARAM_RAW,
117
            ),
118
            'canpostorhascomments' => array(
119
                'type' => PARAM_BOOL
120
            )
121
        );
122
    }
123
 
124
    public function get_other_values(renderer_base $output) {
125
        $values = array();
126
        $values['autostart'] = $this->comment->get_autostart();
127
        $values['canpost'] = $this->comment->can_post();
128
        $values['canview'] = $this->comment->can_view();
129
        $values['collapsediconkey'] = right_to_left() ? 't/collapsed_rtl' : 't/collapsed';
130
        $values['count'] = $this->comment->count();
131
        $values['displaycancel'] = $this->comment->get_displaycancel();
132
        $values['displaytotalcount'] = $this->comment->get_displaytotalcount();
133
        $values['fullwidth'] = $this->comment->get_fullwidth();
134
        $values['linktext'] = $this->comment->get_linktext();
135
        $values['notoggle'] = $this->comment->get_notoggle();
136
        $values['template'] = $this->comment->get_template();
137
        $values['canpostorhascomments'] = $values['canpost'] || ($values['canview'] && $values['count'] > 0);
138
        return $values;
139
    }
140
}