public static function get_default_backup_filename($format, $type, $id, $users, $anonymised, $useidonly = false) {
        global $DB;

        // Calculate backup word
        $backupword = str_replace(' ', '_', core_text::strtolower(get_string('backupfilename')));
        $backupword = trim(clean_filename($backupword), '_');

        // Not $useidonly, lets fetch the name
        $shortname = '';
        if (!$useidonly) {
            // Calculate proper name element (based on type)
            switch ($type) {
                case backup::TYPE_1COURSE:
                    $shortname = $DB->get_field('course', 'shortname', array('id' => $id));
                    $context = context_course::instance($id);
                    $shortname = format_string($shortname, true, array('context' => $context));
                    break;
                case backup::TYPE_1SECTION:
                    if (!$shortname = $DB->get_field('course_sections', 'name', array('id' => $id))) {
                        $shortname = $DB->get_field('course_sections', 'section', array('id' => $id));
                    }
                    break;
                case backup::TYPE_1ACTIVITY:
                    $cm = get_coursemodule_from_id(null, $id);
                    $shortname = $cm->modname . $id;
                    break;
            }
            $shortname = str_replace(' ', '_', $shortname);
            $shortname = core_text::strtolower(trim(clean_filename($shortname), '_'));
        }

        // The name will always contain the ID, but we append the course short name if requested.
        $name = $id;
        if (!$useidonly && $shortname != '') {
            $name .= '-' . $shortname;
        }

        // Calculate date
        $backupdateformat = str_replace(' ', '_', get_string('backupnameformat', 'langconfig'));
        $date = userdate(time(), $backupdateformat, 99, false);
        $date = core_text::strtolower(trim(clean_filename($date), '_'));

        // Calculate info
        $info = '';
        if (!$users) {
            $info = '-nu';
        } else if ($anonymised) {
            $info = '-an';
        }

        return $backupword . '-' . $format . '-' . $type . '-' .
               $name . '-' . $date . $info . '.mbz';
    }
public static function get_default_backup_filename($format, $type, $id, $users, $anonymised, $useidonly = false) {
        global $DB;

        // Calculate backup word
        $backupword = str_replace(' ', '_', core_text::strtolower(get_string('backupfilename')));
        $backupword = trim(clean_filename($backupword), '_');

        // Not $useidonly, lets fetch the name
        $shortname = '';
        if (!$useidonly) {
            // Calculate proper name element (based on type)
            switch ($type) {
                case backup::TYPE_1COURSE:
                    $shortname = $DB->get_field('course', 'shortname', array('id' => $id));
                    $context = context_course::instance($id);
                    $shortname = format_string($shortname, true, array('context' => $context));
                    break;
                case backup::TYPE_1SECTION:
                    if (!$shortname = $DB->get_field('course_sections', 'name', array('id' => $id))) {
                        $shortname = $DB->get_field('course_sections', 'section', array('id' => $id));
                    }
                    break;
                case backup::TYPE_1ACTIVITY:
                    $cm = get_coursemodule_from_id(null, $id);
                    $shortname = $cm->modname . $id;
                    break;
            }
            $shortname = str_replace(' ', '_', $shortname);
            $shortname = core_text::strtolower(trim(clean_filename($shortname), '_'));
        }

        // The name will always contain the ID, but we append the course short name if requested.
        $name = $id;
        if (!$useidonly && $shortname != '') {
            $name .= '-' . $shortname;
        }

        // Calculate date
        $backupdateformat = str_replace(' ', '_', get_string('backupnameformat', 'langconfig'));
        $date = userdate(time(), $backupdateformat, 99, false);
        $date = core_text::strtolower(trim(clean_filename($date), '_'));

        // Calculate info
        $info = '';
        if (!$users) {
            $info = '-nu';
        } else if ($anonymised) {
            $info = '-an';
        }

        return $backupword . '-' . $format . '-' . $type . '-' .
               $name . '-' . $date . $info . '.mbz';
    }
public static function get_default_backup_filename ( $ format , $ type , $ id , $ users , $ anonymised , $ useidonly = false ) { global $ DB ; // Calculate backup word $ backupword = str_replace ( ' ' , '_' , core_text :: strtolower ( get_string ( 'backupfilename' ) ) ) ; $ backupword = trim ( clean_filename ( $ backupword ) , '_' ) ; // Not $useidonly, lets fetch the name $ shortname = '' ; if ( ! $ useidonly ) { // Calculate proper name element (based on type) switch ( $ type ) { case backup :: TYPE_1COURSE : $ shortname = $ DB -> get_field ( 'course' , 'shortname' , array ( 'id' => $ id ) ) ; $ context = context_course :: instance ( $ id ) ; $ shortname = format_string ( $ shortname , true , array ( 'context' => $ context ) ) ; break ; case backup :: TYPE_1SECTION : if ( ! $ shortname = $ DB -> get_field ( 'course_sections' , 'name' , array ( 'id' => $ id ) ) ) { $ shortname = $ DB -> get_field ( 'course_sections' , 'section' , array ( 'id' => $ id ) ) ; } break ; case backup :: TYPE_1ACTIVITY : $ cm = get_coursemodule_from_id ( null , $ id ) ; $ shortname = $ cm -> modname . $ id ; break ; } $ shortname = str_replace ( ' ' , '_' , $ shortname ) ; $ shortname = core_text :: strtolower ( trim ( clean_filename ( $ shortname ) , '_' ) ) ; } // The name will always contain the ID, but we append the course short name if requested. $ name = $ id ; if ( ! $ useidonly && $ shortname != '' ) { $ name .= '-' . $ shortname ; } // Calculate date $ backupdateformat = str_replace ( ' ' , '_' , get_string ( 'backupnameformat' , 'langconfig' ) ) ; $ date = userdate ( time ( ) , $ backupdateformat , 99 , false ) ; $ date = core_text :: strtolower ( trim ( clean_filename ( $ date ) , '_' ) ) ; // Calculate info $ info = '' ; if ( ! $ users ) { $ info = '-nu' ; } else if ( $ anonymised ) { $ info = '-an' ; } return $ backupword . '-' . $ format . '-' . $ type . '-' . $ name . '-' . $ date . $ info . '.mbz' ; }
Returns the default backup filename, based in passed params.

Default format is (see MDL-22145)
backup word - format - type - name - date - info . mbz
where name is variable (course shortname, section name/id, activity modulename + cmid)
and info can be (nu = no user info, an = anonymized). The last param $useidasname,
defaulting to false, allows to replace the course shortname by the course id (used
by automated backups, to avoid non-ascii chars in OS filesystem)

@param string $format One of backup::FORMAT_
@param string $type One of backup::TYPE_
@param int $courseid/$sectionid/$cmid
@param bool $users Should be true is users were included in the backup
@param bool $anonymised Should be true is user information was anonymized.
@param bool $useidonly only use the ID in the file name
@return string The filename to use
Returns the default backup filename based in passed params .