Proyectos de Subversion Moodle

Rev

Rev 1 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 1 Rev 1441
Línea 52... Línea 52...
52
     *
52
     *
53
     * @return external_function_parameters
53
     * @return external_function_parameters
54
     * @since Moodle 3.0
54
     * @since Moodle 3.0
55
     */
55
     */
56
    public static function get_choice_results_parameters() {
56
    public static function get_choice_results_parameters() {
-
 
57
        return new external_function_parameters ([
57
        return new external_function_parameters (array('choiceid' => new external_value(PARAM_INT, 'choice instance id')));
58
            'choiceid' => new external_value(PARAM_INT, 'choice instance id'),
-
 
59
            'groupid' => new external_value(
-
 
60
                PARAM_INT,
-
 
61
                'Group ID. 0 for all participants, empty for active group.',
-
 
62
                VALUE_DEFAULT,
-
 
63
                null,
-
 
64
            ),
-
 
65
        ]);
58
    }
66
    }
59
    /**
67
    /**
60
     * Returns user's results for a specific choice
68
     * Returns user's results for a specific choice
61
     * and a list of those users that did not answered yet.
69
     * and a list of those users that did not answered yet.
62
     *
70
     *
63
     * @param int $choiceid the choice instance id
71
     * @param int $choiceid the choice instance id
-
 
72
     * @param int $groupid The group to use, 0 for all participants, null to calculate active group.
64
     * @return array of responses details
73
     * @return array of responses details
65
     * @since Moodle 3.0
74
     * @since Moodle 3.0
66
     */
75
     */
67
    public static function get_choice_results($choiceid) {
76
    public static function get_choice_results($choiceid, ?int $groupid = null) {
68
        global $USER, $PAGE;
77
        global $PAGE;
Línea 69... Línea 78...
69
 
78
 
-
 
79
        $params = self::validate_parameters(self::get_choice_results_parameters(), [
-
 
80
            'choiceid' => $choiceid,
-
 
81
            'groupid' => $groupid,
Línea 70... Línea 82...
70
        $params = self::validate_parameters(self::get_choice_results_parameters(), array('choiceid' => $choiceid));
82
        ]);
71
 
83
 
72
        if (!$choice = choice_get_choice($params['choiceid'])) {
84
        if (!$choice = choice_get_choice($params['choiceid'])) {
73
            throw new moodle_exception("invalidcoursemodule", "error");
85
            throw new moodle_exception("invalidcoursemodule", "error");
Línea 74... Línea 86...
74
        }
86
        }
75
        list($course, $cm) = get_course_and_cm_from_instance($choice, 'choice');
87
        list($course, $cm) = get_course_and_cm_from_instance($choice, 'choice');
Línea 76... Línea 88...
76
 
88
 
-
 
89
        $context = context_module::instance($cm->id);
-
 
90
        self::validate_context($context);
-
 
91
 
-
 
92
        if ($groupmode = groups_get_activity_groupmode($cm)) {
-
 
93
            if (is_null($groupid)) {
-
 
94
                $groupid = groups_get_activity_group($cm);
-
 
95
            }
-
 
96
 
-
 
97
            if (!groups_group_visible($groupid, $course, $cm)) {
-
 
98
                throw new moodle_exception('notingroup');
-
 
99
            }
77
        $context = context_module::instance($cm->id);
100
        } else {
78
        self::validate_context($context);
101
            $groupid = 0;
79
 
102
        }
80
        $groupmode = groups_get_activity_groupmode($cm);
103
 
81
        // Check if we have to include responses from inactive users.
104
        // Check if we have to include responses from inactive users.
82
        $onlyactive = $choice->includeinactive ? false : true;
105
        $onlyactive = $choice->includeinactive ? false : true;
83
        $users = choice_get_response_data($choice, $cm, $groupmode, $onlyactive);
106
        $users = choice_get_response_data($choice, $cm, $groupmode, $onlyactive, $groupid);
84
        // Show those who haven't answered the question.
107
        // Show those who haven't answered the question.