Proyectos de Subversion Moodle

Rev

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

Rev 1 Rev 1441
Línea 776... Línea 776...
776
     * @param string $groupsql SQL to limit the query by group
776
     * @param string $groupsql SQL to limit the query by group
777
     * @param array $params SQL params for $groupsql
777
     * @param array $params SQL params for $groupsql
778
     * @param string $groupwheresql Where conditions for $groupsql
778
     * @param string $groupwheresql Where conditions for $groupsql
779
     * @return int The number of hidden grades
779
     * @return int The number of hidden grades
780
     */
780
     */
781
    public function has_hidden_grades($groupsql="", array $params=null, $groupwheresql="") {
781
    public function has_hidden_grades($groupsql="", ?array $params=null, $groupwheresql="") {
782
        global $DB;
782
        global $DB;
783
        $params = (array)$params;
783
        $params = (array)$params;
784
        $params['itemid'] = $this->id;
784
        $params['itemid'] = $this->id;
Línea 785... Línea 785...
785
 
785
 
Línea 1220... Línea 1220...
1220
     */
1220
     */
1221
    public function is_aggregate_item() {
1221
    public function is_aggregate_item() {
1222
        return ($this->is_category_item() || $this->is_course_item());
1222
        return ($this->is_category_item() || $this->is_course_item());
1223
    }
1223
    }
Línea -... Línea 1224...
-
 
1224
 
-
 
1225
 
-
 
1226
    /**
-
 
1227
     * Returns whether the item is gradable or not. It's considered gradable when there is at least one gradeitem
-
 
1228
     * set as GRADE_TYPE_VALUE or GRADE_TYPE_SCALE.
-
 
1229
     *
-
 
1230
     * @return bool
-
 
1231
     */
-
 
1232
    public function is_gradable(): bool {
-
 
1233
        return $this->gradetype == GRADE_TYPE_VALUE || $this->gradetype == GRADE_TYPE_SCALE;
-
 
1234
    }
1224
 
1235
 
1225
    /**
1236
    /**
1226
     * Returns the grade item associated with the course
1237
     * Returns the grade item associated with the course
1227
     *
1238
     *
1228
     * @param int $courseid
1239
     * @param int $courseid
Línea 1715... Línea 1726...
1715
 
1726
 
1716
        } else if ($grade_category = $this->load_item_category()) {
1727
        } else if ($grade_category = $this->load_item_category()) {
Línea 1717... Línea 1728...
1717
            $params = array();
1728
            $params = array();
1718
 
1729
 
1719
            //only items with numeric or scale values can be aggregated
1730
            //only items with numeric or scale values can be aggregated
1720
            if ($this->gradetype != GRADE_TYPE_VALUE and $this->gradetype != GRADE_TYPE_SCALE) {
1731
            if (!$this->is_gradable()) {
1721
                $this->dependson_cache = array();
1732
                $this->dependson_cache = array();
Línea 1722... Línea 1733...
1722
                return $this->dependson_cache;
1733
                return $this->dependson_cache;
Línea 2084... Línea 2095...
2084
        } else {
2095
        } else {
2085
            //keep original graded date
2096
            //keep original graded date
2086
        }
2097
        }
2087
        // end of hack alert
2098
        // end of hack alert
Línea -... Línea 2099...
-
 
2099
 
-
 
2100
        // Only reset the deducted mark if the grade has changed.
-
 
2101
        if ($grade->timemodified !== $oldgrade->timemodified) {
-
 
2102
            $grade->deductedmark = 0;
-
 
2103
        }
2088
 
2104
 
2089
        $gradechanged = false;
2105
        $gradechanged = false;
2090
        if (empty($grade->id)) {
2106
        if (empty($grade->id)) {
Línea 2091... Línea 2107...
2091
            $result = (bool)$grade->insert($source, $isbulkupdate);
2107
            $result = (bool)$grade->insert($source, $isbulkupdate);
Línea 2145... Línea 2161...
2145
 
2161
 
2146
        return $result;
2162
        return $result;
Línea 2147... Línea 2163...
2147
    }
2163
    }
-
 
2164
 
-
 
2165
    /**
-
 
2166
     * Update penalty value for given user
-
 
2167
     *
-
 
2168
     * @param int $userid The graded user
-
 
2169
     * @param float $deductedmark The mark deducted from final grade
-
 
2170
     */
-
 
2171
    public function update_deducted_mark(int $userid, float $deductedmark): void {
-
 
2172
        $grade = new grade_grade([
-
 
2173
                'itemid' => $this->id,
-
 
2174
                'userid' => $userid,
-
 
2175
            ]);
-
 
2176
        $grade->deductedmark = $deductedmark;
-
 
2177
        $grade->update();
-
 
2178
    }
2148
 
2179
 
2149
    /**
2180
    /**
2150
     * Calculates final grade values using the formula in the calculation property.
2181
     * Calculates final grade values using the formula in the calculation property.
2151
     * The parameters are taken from final grades of grade items in current course only.
2182
     * The parameters are taken from final grades of grade items in current course only.
2152
     *
2183
     *
Línea 2209... Línea 2240...
2209
        // this itemid is added so that we use only one query for source and final grades
2240
        // this itemid is added so that we use only one query for source and final grades
2210
        $gis = array_merge($useditems, array($this->id));
2241
        $gis = array_merge($useditems, array($this->id));
2211
        list($usql, $params) = $DB->get_in_or_equal($gis);
2242
        list($usql, $params) = $DB->get_in_or_equal($gis);
Línea 2212... Línea 2243...
2212
 
2243
 
2213
        if ($userid) {
2244
        if ($userid) {
2214
            $usersql = "AND g.userid=?";
2245
            $usersql = "AND userid=?";
2215
            $params[] = $userid;
2246
            $params[] = $userid;
2216
        } else {
2247
        } else {
2217
            $usersql = "";
2248
            $usersql = "";
Línea 2218... Línea 2249...
2218
        }
2249
        }
2219
 
2250
 
Línea 2220... Línea 2251...
2220
        $grade_inst = new grade_grade();
2251
        $gradeinst = new grade_grade();
2221
        $fields = 'g.'.implode(',g.', $grade_inst->required_fields);
-
 
2222
 
-
 
2223
        $params[] = $this->courseid;
-
 
2224
        $sql = "SELECT $fields
-
 
Línea 2225... Línea 2252...
2225
                  FROM {grade_grades} g, {grade_items} gi
2252
        $fields = implode(',', $gradeinst->required_fields);
Línea 2226... Línea 2253...
2226
                 WHERE gi.id = g.itemid AND gi.id $usql $usersql AND gi.courseid=?
2253
 
2227
                 ORDER BY g.userid";
2254
        $params[] = $this->courseid;
2228
 
2255
 
2229
        $return = true;
2256
        $return = true;
2230
 
2257
 
2231
        // group the grades by userid and use formula on the group
2258
        // group the grades by userid and use formula on the group
2232
        $rs = $DB->get_recordset_sql($sql, $params);
2259
        $rs = $DB->get_recordset_select('grade_grades', "itemid $usql $usersql", $params, 'userid', $fields);