Proyectos de Subversion Moodle

Rev

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

Rev 1436 Rev 1441
Línea 33... Línea 33...
33
 *
33
 *
34
 * @package    core_completion
34
 * @package    core_completion
35
 * @copyright  2017 Mark Nelson <markn@moodle.com>
35
 * @copyright  2017 Mark Nelson <markn@moodle.com>
36
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
36
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
37
 */
37
 */
38
class progress
38
class progress {
39
{
-
 
Línea 40... Línea 39...
40
 
39
 
41
    /**
40
    /**
42
     * Returns the course percentage completed by a certain user, returns null if no completion data is available.
41
     * Returns the course percentage completed by a certain user, returns null if no completion data is available.
43
     *
42
     *
44
     * @param \stdClass $course Moodle course object
43
     * @param \stdClass $course Moodle course object
45
     * @param int $userid The id of the user, 0 for the current user
44
     * @param int $userid The id of the user, 0 for the current user
46
     * @return null|float The percentage, or null if completion is not supported in the course,
45
     * @return null|float The percentage, or null if completion is not supported in the course,
47
     *         or there are no activities that support completion.
46
     *         or there are no activities that support completion.
48
     */
47
     */
49
    public static function get_course_progress_percentage($course, $userid = 0)
-
 
50
    {
48
    public static function get_course_progress_percentage($course, $userid = 0) {
Línea 51... Línea 49...
51
        global $USER;
49
        global $USER;
52
 
50
 
53
        // Make sure we continue with a valid userid.
51
        // Make sure we continue with a valid userid.
Línea 77... Línea 75...
77
        if (!$count) {
75
        if (!$count) {
78
            return null;
76
            return null;
79
        }
77
        }
Línea 80... Línea 78...
80
 
78
 
81
        // Get the number of modules that have been completed.
-
 
82
        $completed = 0;
-
 
83
        foreach ($modules as $module) {
79
        // Get the number of modules that have been completed.
84
            $data = $completion->get_data($module, true, $userid);
-
 
85
            if (($data->completionstate == COMPLETION_INCOMPLETE) || ($data->completionstate == COMPLETION_COMPLETE_FAIL)) {
-
 
86
                $completed += 0;
-
 
87
            } else {
-
 
88
                $completed += 1;
-
 
89
            };
-
 
90
        }
-
 
91
        if ($count == 0) {
-
 
92
            return 0;
80
        $totalcompleted = $completion->count_modules_completed($userid);
93
        }
81
 
94
        return ($completed / $count) * 100;
82
        return ($totalcompleted / $count) * 100;
95
    }
83
    }