~ubuntu-branches/ubuntu/utopic/moodle/utopic

« back to all changes in this revision

Viewing changes to mod/feedback/classes/event/response_submitted.php

  • Committer: Package Import Robot
  • Author(s): Thijs Kinkhorst
  • Date: 2014-05-12 16:10:38 UTC
  • mfrom: (36.1.3 sid)
  • Revision ID: package-import@ubuntu.com-20140512161038-puyqf65k4e0s8ytz
Tags: 2.6.3-1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 * Event to be triggered when a feedback response is submitted.
 
19
 *
 
20
 * @package    mod_feedback
 
21
 * @copyright  2013 Ankit Agarwal
 
22
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later.
 
23
 */
 
24
 
 
25
namespace mod_feedback\event;
 
26
defined('MOODLE_INTERNAL') || die();
 
27
 
 
28
/**
 
29
 * Class response_submitted
 
30
 *
 
31
 * Class for event to be triggered when a feedback response is submitted.
 
32
 *
 
33
 * @package    mod_feedback
 
34
 * @since      Moodle 2.6
 
35
 * @copyright  2013 Ankit Agarwal
 
36
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later.
 
37
 */
 
38
class response_submitted extends \core\event\base {
 
39
 
 
40
    /**
 
41
     * Set basic properties for the event.
 
42
     */
 
43
    protected function init() {
 
44
        global $CFG;
 
45
 
 
46
        require_once($CFG->dirroot.'/mod/feedback/lib.php');
 
47
        $this->data['objecttable'] = 'feedback_completed';
 
48
        $this->data['crud'] = 'c';
 
49
        $this->data['level'] = self::LEVEL_PARTICIPATING;
 
50
    }
 
51
 
 
52
    /**
 
53
     * Returns localised general event name.
 
54
     *
 
55
     * @return string
 
56
     */
 
57
    public static function get_name() {
 
58
        return get_string('eventresponsesubmitted', 'mod_feedback');
 
59
    }
 
60
 
 
61
    /**
 
62
     * Returns non-localised event description with id's for admin use only.
 
63
     *
 
64
     * @return string
 
65
     */
 
66
    public function get_description() {
 
67
        return 'The user ' . $this->other['relateduserid']. ' submited a feedback';
 
68
    }
 
69
 
 
70
    /**
 
71
     * Returns relevant URL based on the anonymous mode of the response.
 
72
     * @return \moodle_url
 
73
     */
 
74
    public function get_url() {
 
75
        if ($this->other['anonymous'] == FEEDBACK_ANONYMOUS_YES) {
 
76
            return new \moodle_url('/mod/feedback/show_entries.php' , array('id' => $this->other['cmid'],
 
77
                    'do_show' => 'showoneentry' , 'userid' => $this->relateduserid));
 
78
        } else {
 
79
            return new \moodle_url('/mod/feedback/show_entries_anonym.php', array('id' => $this->other['cmid'],
 
80
                    'do_show' => 'showoneentry', 'showall', 'showcompleted' => $this->objectid));
 
81
        }
 
82
    }
 
83
 
 
84
    /**
 
85
     * Replace add_to_log() statement. Do this only for the case when anonymous mode is off,
 
86
     * since this is what was happening before.
 
87
     *
 
88
     * @return array of parameters to be passed to legacy add_to_log() function.
 
89
     */
 
90
    protected function get_legacy_logdata() {
 
91
        if ($this->other['anonymous'] == FEEDBACK_ANONYMOUS_YES) {
 
92
            return null;
 
93
        } else {
 
94
            return array($this->courseid, 'feedback', 'submit', 'view.php?id=' . $this->other['cmid'],
 
95
                    $this->other['instanceid'], $this->other['cmid'], $this->relateduserid);
 
96
        }
 
97
    }
 
98
 
 
99
    /**
 
100
     * Define whether a user can view the event or not. Make sure no one except admin can see details of an anonymous response.
 
101
     *
 
102
     * @param int|\stdClass $userorid ID of the user.
 
103
     * @return bool True if the user can view the event, false otherwise.
 
104
     */
 
105
    public function can_view($userorid = null) {
 
106
        global $USER;
 
107
 
 
108
        if (empty($userorid)) {
 
109
            $userorid = $USER;
 
110
        }
 
111
        if ($this->other['anonymous'] == FEEDBACK_ANONYMOUS_YES) {
 
112
            return is_siteadmin($userorid);
 
113
        } else {
 
114
            return has_capability('mod/feedback:viewreports', $this->context, $userorid);
 
115
        }
 
116
    }
 
117
 
 
118
    /**
 
119
     * Custom validations.
 
120
     *
 
121
     * @throws \coding_exception in case of any problems.
 
122
     */
 
123
    protected function validate_data() {
 
124
        if (!isset($this->other['anonymous'])) {
 
125
            throw new \coding_exception("Field other['anonymous'] cannot be empty");
 
126
        }
 
127
        if (!isset($this->other['cmid'])) {
 
128
            throw new \coding_exception("Field other['cmid'] cannot be empty");
 
129
        }
 
130
        if (!isset($this->other['instanceid'])) {
 
131
            throw new \coding_exception("Field other['instanceid'] cannot be empty");
 
132
        }
 
133
    }
 
134
}
 
135