function backup_get_needed_users($courseid, $includemessages = false, $includeblogs = false)
{
    global $CFG;
    $result = false;
    $course_modules = get_records_sql("SELECT cm.id, m.name, cm.instance\n                                            FROM {$CFG->prefix}modules m,\n                                                 {$CFG->prefix}course_modules cm\n                                            WHERE m.id = cm.module and\n                                                  cm.course = '{$courseid}'");
    if ($course_modules) {
        //Iterate over each module
        foreach ($course_modules as $course_module) {
            $modlib = "{$CFG->dirroot}/mod/{$course_module->name}/lib.php";
            $modgetparticipants = $course_module->name . "_get_participants";
            if (file_exists($modlib)) {
                include_once $modlib;
                if (function_exists($modgetparticipants)) {
                    $module_participants = $modgetparticipants($course_module->instance);
                    //Add them to result
                    if ($module_participants) {
                        foreach ($module_participants as $module_participant) {
                            $result[$module_participant->id]->id = $module_participant->id;
                        }
                    }
                }
            }
        }
    }
    //Now, add message users if necessary
    if ($includemessages) {
        include_once "{$CFG->dirroot}/message/lib.php";
        //Get users
        $messageusers = message_get_participants();
        //Add message users to results
        if ($messageusers) {
            foreach ($messageusers as $messageuser) {
                //If id != 0
                if ($messageuser->id != 0) {
                    $result[$messageuser->id]->id = $messageuser->id;
                }
            }
        }
    }
    //Now, add blog users if necessary
    if ($includeblogs) {
        include_once "{$CFG->dirroot}/blog/lib.php";
        //Get users
        $blogusers = blog_get_participants();
        //Add blog users to results
        if ($blogusers) {
            foreach ($blogusers as $bloguser) {
                //If id != 0
                if ($bloguser->id != 0) {
                    $result[$bloguser->id]->id = $bloguser->id;
                }
            }
        }
    }
    return $result;
}
Esempio n. 2
0
function backup_get_needed_users($courseid, $includemessages = false, $includeblogs = false)
{
    global $CFG, $DB;
    $result = false;
    $course_modules = $DB->get_records_sql("SELECT cm.id, m.name, cm.instance\n                                                  FROM {modules} m, {course_modules} cm\n                                                 WHERE m.id = cm.module and\n                                                       cm.course = ?", array($courseid));
    if ($course_modules) {
        //Iterate over each module
        foreach ($course_modules as $course_module) {
            $modlib = "{$CFG->dirroot}/mod/{$course_module->name}/lib.php";
            $modgetparticipants = $course_module->name . "_get_participants";
            if (file_exists($modlib)) {
                include_once $modlib;
                if (function_exists($modgetparticipants)) {
                    $module_participants = $modgetparticipants($course_module->instance);
                    //Add them to result
                    if ($module_participants) {
                        foreach ($module_participants as $module_participant) {
                            $result[$module_participant->id]->id = $module_participant->id;
                        }
                    }
                }
            }
        }
    }
    //Now, add scale users (from site and course scales)
    //Get users
    $scaleusers = $DB->get_records_sql("SELECT DISTINCT userid,userid\n                                              FROM {scale}\n                                             WHERE courseid = 0 or courseid = ?", array($courseid));
    //Add scale users to results
    if ($scaleusers) {
        foreach ($scaleusers as $scaleuser) {
            //If userid != 0
            if ($scaleuser->userid != 0) {
                $result[$scaleuser->userid]->id = $scaleuser->userid;
            }
        }
    }
    //Now, add message users if necessary
    if ($includemessages) {
        include_once "{$CFG->dirroot}/message/lib.php";
        //Get users
        $messageusers = message_get_participants();
        //Add message users to results
        if ($messageusers) {
            foreach ($messageusers as $messageuser) {
                //If id != 0
                if ($messageuser->id != 0) {
                    $result[$messageuser->id]->id = $messageuser->id;
                }
            }
        }
    }
    //Now, add blog users if necessary
    if ($includeblogs) {
        include_once "{$CFG->dirroot}/blog/lib.php";
        //Get users
        $blogusers = blog_get_participants();
        //Add blog users to results
        if ($blogusers) {
            foreach ($blogusers as $bloguser) {
                //If id != 0
                if ($bloguser->id != 0) {
                    $result[$bloguser->id]->id = $bloguser->id;
                }
            }
        }
    }
    return $result;
}