예제 #1
0
파일: lib.php 프로젝트: nadavkav/MoodleTAO
function local_postinst()
{
    global $db, $CFG;
    $olddebug = $db->debug;
    $db->debug = $CFG->debug;
    set_config('theme', 'intel');
    $db->debug = $olddebug;
    // set frontpage blocks
    tao_reset_frontpage_blocks();
    // set sticky blocks
    tao_reset_stickyblocks();
    // create the TAO Site Forum
    $forum = local_create_forum(SITEID, NOGROUPS, get_string('siteforumname', 'local'), get_string('siteforumintro', 'local'));
    // remove guest access to the site level forum
    $required = array("mod/forum:addnews", "mod/forum:createattachment", "mod/forum:deleteanypost", "mod/forum:deleteownpost", "mod/forum:editanypost", "mod/forum:initialsubscriptions", "mod/forum:managesubscriptions", "mod/forum:movediscussions", "mod/forum:rate", "mod/forum:replynews", "mod/forum:replypost", "mod/forum:splitdiscussions", "mod/forum:startdiscussion", "mod/forum:throttlingapplies", "mod/forum:viewanyrating", "mod/forum:viewdiscussion", "mod/forum:viewhiddentimedposts", "mod/forum:viewqandawithoutposting", "mod/forum:viewrating", "mod/forum:viewsubscribers");
    if (!($cm = get_coursemodule_from_id("forum", $forum->coursemodule, SITEID))) {
        error("Could not determine which course module this belonged to!");
    }
    $context = get_context_instance(CONTEXT_MODULE, $cm->id);
    // find the exisiting list of capabilities
    $capabilities = fetch_context_capabilities($context);
    if ($roles = get_records_select('role', 'shortname IN (\'guest\')')) {
        foreach ($roles as $role) {
            foreach ($capabilities as $capability) {
                // check against the list of capabilities that we want to block
                if (!in_array($capability->name, $required)) {
                    continue;
                }
                assign_capability($capability->name, -1000, $role->id, $context->id);
            }
        }
        mark_context_dirty($context->path);
    }
    // give everyone else access to the site level forum
    $required = array("mod/forum:addnews", "mod/forum:createattachment", "mod/forum:deleteownpost", "mod/forum:initialsubscriptions", "mod/forum:rate", "mod/forum:replynews", "mod/forum:replypost", "mod/forum:startdiscussion", "mod/forum:viewanyrating", "mod/forum:viewdiscussion", "mod/forum:viewrating");
    if ($roles = get_records_select('role', 'shortname NOT IN (\'guest\', \'user\')')) {
        foreach ($roles as $role) {
            foreach ($capabilities as $capability) {
                // check against the list of capabilities that we want to block
                if (!in_array($capability->name, $required)) {
                    continue;
                }
                assign_capability($capability->name, 1, $role->id, $context->id);
            }
        }
        mark_context_dirty($context->path);
    }
    // add TAO site wide FAQ
    $glossary = local_create_glossary(SITEID, get_string('defaultglossaryname', 'local'), get_string('defaultglossarydescription', 'local'));
    // set of capabilities that we want to orverride
    $required = array('mod/glossary:approve', 'mod/glossary:comment', 'mod/glossary:import', 'mod/glossary:managecategories', 'mod/glossary:managecomments', 'mod/glossary:manageentries', 'mod/glossary:rate', 'mod/glossary:write');
    if (!($cm = get_coursemodule_from_id("glossary", $glossary->coursemodule, SITEID))) {
        error("Could not determine which course module this belonged to!");
    }
    $context = get_context_instance(CONTEXT_MODULE, $cm->id);
    // find the exisiting list of capabilities
    $capabilities = fetch_context_capabilities($context);
    if ($roles = get_records_select('role', 'shortname NOT IN (\'admin\', \'superadmin\')')) {
        foreach ($roles as $role) {
            foreach ($capabilities as $capability) {
                // check against the list of capabilities that we want to block
                if (!in_array($capability->name, $required)) {
                    continue;
                }
                assign_capability($capability->name, -1000, $role->id, $context->id);
            }
        }
        mark_context_dirty($context->path);
    }
    //set up default Course Categories
    $course_cat = new stdclass();
    $course_cat->name = get_string('taocatlp', 'local');
    $course_cat->description = '';
    $course_cat->parent = 0;
    $course_cat->sortorder = 2;
    $course_cat->coursecount = 0;
    $course_cat->visible = 1;
    $course_cat->timemodified = time();
    $course_cat->depth = 1;
    $course_cat->path = "''";
    $course_cat->theme = '';
    $lpid = insert_record('course_categories', $course_cat);
    //insert learning path category and keep id for use later.
    $catcontext = get_context_instance(CONTEXT_COURSECAT, $lpid);
    mark_context_dirty($catcontext->path);
    $course_cat->name = get_string('taocatlptemplates', 'local');
    $course_cat->sortorder = 3;
    $course_cat->visible = 0;
    $lptempid = insert_record('course_categories', $course_cat);
    //insert my sections category keep id for use later.
    $catcontext = get_context_instance(CONTEXT_COURSECAT, $lptempid);
    mark_context_dirty($catcontext->path);
    $course_cat->name = get_string('taotrainingcourses', 'local');
    $course_cat->sortorder = 5;
    $course_cat->visible = 1;
    $taotrainingid = insert_record('course_categories', $course_cat);
    //insert my sections category keep id for use later.
    $catcontext = get_context_instance(CONTEXT_COURSECAT, $taotrainingid);
    mark_context_dirty($catcontext->path);
    $course_cat->name = get_string('taocatworkshop', 'local');
    $course_cat->parent = $lpid;
    $course_cat->sortorder = 2;
    $course_cat->visible = 0;
    $catworkid = insert_record('course_categories', $course_cat);
    //insert published category
    $catcontext = get_context_instance(CONTEXT_COURSECAT, $catworkid);
    mark_context_dirty($catcontext->path);
    $course_cat->name = get_string('taocatsuspended', 'local');
    $course_cat->parent = $lpid;
    $course_cat->sortorder = 3;
    $course_cat->visible = 0;
    $suscatid = insert_record('course_categories', $course_cat);
    //insert published category
    $catcontext = get_context_instance(CONTEXT_COURSECAT, $suscatid);
    mark_context_dirty($catcontext->path);
    fix_course_sortorder();
    //set paths correctly.
    //now set default categories for learning path stuff.
    set_config('lptemplatescategory', $lptempid);
    //set template category
    set_config('lpdefaultcategory', $catworkid);
    set_config('lppublishedcategory', $lpid);
    set_config('lpsuspendedcategory', $suscatid);
    //now prevent the admin user from having the switchrole cap in learning path category
    $catcontext = get_context_instance(CONTEXT_COURSECAT, $lpid);
    foreach (get_admin_roles() as $adminrole) {
        assign_capability('moodle/role:switchroles', CAP_PREVENT, $adminrole->id, $catcontext->id);
    }
    //now we need to do some silent restores for:
    // Learning Path Templates
    //silent restore of LP Template into $lptempid
    require_once $CFG->dirroot . '/course/lib.php';
    require_once $CFG->dirroot . '/backup/lib.php';
    require_once $CFG->dirroot . '/backup/restorelib.php';
    if (file_exists($CFG->dirroot . '/local/initialcoursetemplates/lpt.zip')) {
        $course = new StdClass();
        $course->category = $lptempid;
        $course->fullname = get_string('learningpathtemplate', 'local');
        $course->shortname = get_string('learningpathtemplateshortname', 'local');
        $course->format = 'learning';
        //hardcoded for this course format - for some reason silent restore doesn't like restoring this format if not already set
        if ($newcourse = create_course($course)) {
            import_backup_file_silently($CFG->dirroot . '/local/initialcoursetemplates/lpt.zip', $newcourse->id, true, false);
        }
        //now copy the backup file into place to use as template file.
        $fullpath = $CFG->dataroot . "/" . $newcourse->id . "/backupdata";
        if (!is_dir($fullpath)) {
            mkdir($fullpath, $CFG->directorypermissions, true);
        }
        copy($CFG->dirroot . '/local/initialcoursetemplates/lpt.zip', $fullpath . '/lpt.zip');
    }
    //now restore Training courses:
    if (file_exists($CFG->dirroot . '/local/initialcoursetemplates/taodocs1.zip')) {
        import_backup_file_silently($CFG->dirroot . '/local/initialcoursetemplates/taodocs1.zip', SITEID, true, false, array(), RESTORETO_NEW_COURSE);
    }
    if (file_exists($CFG->dirroot . '/local/initialcoursetemplates/taodocs2.1.zip')) {
        import_backup_file_silently($CFG->dirroot . '/local/initialcoursetemplates/taodocs2.1.zip', SITEID, true, false, array(), RESTORETO_NEW_COURSE);
    }
    if (file_exists($CFG->dirroot . '/local/initialcoursetemplates/taodocs2.2.zip')) {
        import_backup_file_silently($CFG->dirroot . '/local/initialcoursetemplates/taodocs2.2.zip', SITEID, true, false, array(), RESTORETO_NEW_COURSE);
    }
    //site frontpage stuff - default settings and some initial content.
    $sitecourse = get_record('course', 'id', SITEID);
    $sitecourse->numsections = 1;
    update_record('course', $sitecourse);
    $a = new stdclass();
    $a->myteachinglink = $CFG->wwwroot . '/local/mahara/taoviewtaoresources.php';
    $a->mytoolslink = $CFG->wwwroot . '/local/mahara/taoviewtaotools.php';
    $a->mylearninglink = $CFG->wwwroot . '/local/my/learning.php';
    $a->myworklink = $CFG->wwwroot . '/local/my/work.php';
    $a->mycollablink = $CFG->wwwroot . '/local/my/collaboration.php';
    $a->myteachingimg = $CFG->wwwroot . '/theme/intel/pix/path/teaching.jpg';
    $a->mylearningimg = $CFG->wwwroot . '/theme/intel/pix/path/learning.jpg';
    $a->myworkimg = $CFG->wwwroot . '/theme/intel/pix/path/work.jpg';
    $a->mytoolsimg = $CFG->wwwroot . '/theme/intel/pix/path/tools.jpg';
    $a->mycollabimg = $CFG->wwwroot . '/theme/intel/pix/path/collaboration.jpg';
    $sitesection = new stdclass();
    $sitesection->course = SITEID;
    $sitesection->section = 1;
    $sitesection->summary = addslashes(get_string('initialfrontpagecontent', 'local', $a));
    $sitesection->sequence = '';
    $sitesection->visible = 1;
    $sitesectionid = insert_record('course_sections', $sitesection);
    //add a link to the training courses on the frontpage: - there's probably a cleaner way to do this!!!
    $resource = new stdclass();
    $resource->course = SITEID;
    $resource->name = get_string('taotrainingcourses', 'local');
    $resource->type = 'file';
    $resource->reference = $CFG->wwwroot . '/course/category.php?id=' . $taotrainingid;
    $resource->summary = '';
    $resource->timemodified = time();
    $trainresid = insert_record("resource", $resource);
    //add record to course_modules for the resource
    $resm = new stdclass();
    $resm->course = SITEID;
    $resm->module = get_field('modules', 'id', 'name', 'resource');
    $resm->instance = $trainresid;
    $resm->section = $sitesectionid;
    $resm->added = time();
    $resm->score = 0;
    $resm->indent = 0;
    $resm->visible = 1;
    $resm->visibleold = 1;
    $resm->groupmode = 0;
    $resm->groupingid = 0;
    $resm->groupmembersonly = 0;
    $resm->trackprogress = 0;
    $resmid = insert_record('course_modules', $resm);
    //now update the sequence for the section just created.
    $sitesection->sequence = $resmid;
    $sitesection->id = $sitesectionid;
    update_record('course_sections', $sitesection);
    //set no other stuff to display in main content section of homepage
    set_config('frontpage', '');
    set_config('frontpageloggedin', '');
    set_config('allowvisiblecoursesinhiddencategories', '1');
    // ensure custom roles are set correctly
    tao_reset_custom_roles();
    rebuild_course_cache(SITEID);
    return true;
}
예제 #2
0
if (!($course = get_record("course", "id", $id))) {
    error("Course ID is incorrect");
}
require_login($course->id, false);
global $CFG;
$dir = $CFG->dataroot . '/incrementals_client/' . $id;
if (!check_dir_exists($dir, true, true)) {
    //now create folder for new incremental
    error('failed to create dir for new incremental' . $dir);
}
require_once $CFG->dirroot . '/lib/uploadlib.php';
$um = new upload_manager('newfile', false, true, $id, false, 0, true);
if ($file = $um->process_file_uploads($dir)) {
    $pref = new StdClass();
    $pref->updating = 1;
    $status = import_backup_file_silently($um->files['newfile']['fullpath'], $course->id, true, true, $pref);
    if ($status) {
        $navlinks = array();
        $navlinks[] = array('name' => get_string('updatecourse', 'local'), 'link' => '', 'type' => 'activity');
        $navigation = build_navigation($navlinks);
        print_header_simple(get_string('updatecourse', 'local'), get_string('updatecourse', 'local'), $navigation, "", "", true, '', '');
        //insert updated backup hash.
        $bkinstance = new object();
        $bkinstance->courseid = $course->id;
        $bkinstance->filename = $um->files['newfile']['name'];
        $bkinstance->hash = $um->files['newfile']['name'];
        $bkinstance->timecreated = time();
        if (!insert_record('incremental_instance', $bkinstance)) {
            error('failed inserting incremental_instance record');
        }
        print_box(get_string('updatecoursesuccess', 'local'), 'generalbox', 'intro');
예제 #3
0
파일: tao.php 프로젝트: nadavkav/MoodleTAO
function tao_create_lp($data, $author, $creatorroleid, $createtemplate = 0, $preferences = array())
{
    global $CFG;
    if (empty($data)) {
        error("invalid call to tao_create_lp");
    }
    // get course template
    if (!($course = get_record('course', 'id', $data->course_template))) {
        error('Invalid course id');
    }
    // get a handle on the most recent backup for the selected course
    $wdir = "/backupdata";
    $fullpath = $CFG->dataroot . "/" . $course->id . $wdir;
    $dirlist = array();
    $filelist = array();
    if (!is_dir($fullpath)) {
        error("No templates for selected course");
    }
    $directory = opendir($fullpath);
    // Find all files
    while (false !== ($file = readdir($directory))) {
        if ($file == "." || $file == "..") {
            continue;
        }
        if (strchr($file, ".") != ".zip") {
            continue;
        }
        if (is_dir($fullpath . "/" . $file)) {
            $dirlist[] = $file;
        } else {
            $filelist[] = $file;
        }
    }
    closedir($directory);
    asort($filelist);
    // get the last file
    $file = array_pop($filelist);
    $fullpathtofile = "{$fullpath}/{$file}";
    if (!$file) {
        error("No templates for selected course");
    }
    // attempt to create the new course
    if (!($newcourse = create_course($data))) {
        print_error('coursenotcreated');
    }
    $context = get_context_instance(CONTEXT_COURSE, $newcourse->id);
    $sitecontext = get_context_instance(CONTEXT_COURSE, SITEID);
    // assign our initial user - note this means automatic assigning by the backup should be skipped, which is based
    //   the on the manage:activities role being present
    role_assign($creatorroleid, $author->id, 0, $context->id);
    if ($data->learning_path_mode == LEARNING_PATH_MODE_RAFL) {
        //now set role override for PT users to prevent them from being able to add blocks and activities.
        $ptroleid = get_field('role', 'id', 'shortname', ROLE_PT);
        $ispt = user_has_role_assignment($author->id, $ptroleid, $sitecontext->id);
        if ($ispt) {
            //prevent from being able to change the structure of the pages.
            assign_capability('format/learning:manageactivities', CAP_PREVENT, $creatorroleid, $context->id);
        }
    }
    // create default the TAO Course (LP) Forum
    /// ** load this in template instead? ** local_create_forum($newcourse->id, SEPARATEGROUPS, get_string('defaultforumname', 'local'), get_string('defaultforumintro', 'local'));
    // create default the TAO Course (LP) Wiki
    /// ** load this in template instead? ** local_create_wiki($newcourse->id, SEPARATEGROUPS, get_string('defaultwikiname', 'local'), get_string('defaultwikisummary', 'local'));
    if (!$createtemplate) {
        // set course status
        if (!tao_update_course_status(COURSE_STATUS_NOTSUBMITTED, "Created new learning path from template", $newcourse)) {
            error('could not update status');
        }
    }
    //set up preferences for pasign to backup_file_silently
    $preferences['course_format'] = 1;
    if ($data->learning_path_mode == LEARNING_PATH_MODE_STANDARD) {
        // load the backup data into course //TODO some way of validating this
        import_backup_file_silently($fullpathtofile, $newcourse->id, false, false, $preferences, RESTORETO_CURRENT_DELETING);
        // if valid
        // set course status
        if (!tao_update_course_status(COURSE_STATUS_NOTSUBMITTED, "Created new learning path from template", $newcourse)) {
            error('could not update status');
        }
        // ensure we can use the course right after creating it
        // this means trigger a reload of accessinfo...
        mark_context_dirty($context->path);
        $author->raflmode = 0;
        // Redirect to course page
        return $newcourse->id;
    } elseif ($data->learning_path_mode == LEARNING_PATH_MODE_RAFL) {
        //set pref to not restore pages for all RAFL imports:
        $preferences['nopages'] = 1;
        // load the template, but leave out actual content pages - they are created by rafl structure.
        //     note: we must do this before adding the new pages otherwise this process will remove them
        import_backup_file_silently($fullpathtofile, $newcourse->id, false, false, $preferences);
        // todo do a non-fatal check for rafl module, and give a friendly message if not found
        require_once $CFG->dirroot . '/mod/rafl/lib.php';
        require_once $CFG->dirroot . '/mod/rafl/locallib.php';
        require_once $CFG->dirroot . '/course/format/learning/lib.php';
        require_once $CFG->dirroot . '/course/format/learning/pagelib.php';
        $rafl = new localLibRafl();
        $pageid = $newcourse->id;
        // pageid is actually courseid in the blockinstance context.  i know!
        $pagetype = 'course-view';
        // first create the summary page
        $page = new stdClass();
        $page->nameone = get_string('lpsummarypagetitle', 'local');
        $page->nametwo = get_string('lpsummarypagetitle', 'local');
        $page->courseid = $newcourse->id;
        $page->display = 1;
        $page->showbuttons = 3;
        $summarypageid = insert_record('format_page', $page);
        // add the standard blocks for a summary page
        $instanceid = tao_add_learningpath_block('tao_learning_path_summary', $pageid, $pagetype, "Learning Stations");
        if (!empty($instanceid)) {
            tao_add_learningpath_pageitem($summarypageid, $instanceid);
        }
        // now the station pages
        $items = $rafl->get_lp_item_structure(0);
        // todo don't hardcode this parameter
        foreach ($items as $item) {
            // check for existing station/pie, if not there insert as a format_page
            $sql = "SELECT id FROM {$CFG->prefix}format_page WHERE courseid = {$newcourse->id} AND rafl_item = {$item->question_item_id}";
            $exists = get_records_sql($sql);
            if (empty($exists)) {
                // add the format page
                $page = new stdClass();
                $page->nameone = $item->title;
                $page->nametwo = $item->title;
                $page->courseid = $newcourse->id;
                $page->display = 1;
                $page->showbuttons = 3;
                $page->parent = $summarypageid;
                $page->rafl_item = $item->question_item_id;
                $formatpageid = insert_record('format_page', $page);
                // add the title block
                $instanceid = tao_add_learningpath_block('html', $pageid, $pagetype, '', '<h1>' . $item->title . '</h1>');
                if (!empty($instanceid)) {
                    tao_add_learningpath_pageitem($formatpageid, $instanceid);
                }
            }
        }
        // now add the question blocks
        $country_item_id = $rafl->get_rafl_item_id_by_country('uk');
        $items = $rafl->get_lp_item_structure($country_item_id);
        // todo find a better way to pass this parameter
        foreach ($items as $item) {
            // db integrity - at least check for existing station/pie
            $sql = "SELECT id FROM {$CFG->prefix}format_page WHERE courseid = {$newcourse->id} AND rafl_item = {$item->pie_item_id}";
            $formatpage = get_record_sql($sql);
            if (!empty($formatpage)) {
                // insert question as a block and format_page item on this page
                $instanceid = tao_add_learningpath_block('tao_lp_qa', $pageid, $pagetype, $item->title);
                // create a new page item that links to the instance
                if (!empty($instanceid)) {
                    tao_add_learningpath_pageitem($formatpage->id, $instanceid, $item->question_item_id);
                }
            } else {
                debugging("pie {$item->pie_item_id} is not in the database");
            }
        }
        // add the rafl module to the course
        $mod = new object();
        $mod->course = $newcourse->id;
        $mod->name = 'RAFL Authoring Module';
        $mod->intro = 'RAFL Authoring Module';
        $instanceid = rafl_add_instance($mod);
        if (!($module = get_record("modules", "name", 'rafl'))) {
            error("This module type doesn't exist");
        }
        if (!($cs = get_record("course_sections", "section", 0, "course", $newcourse->id))) {
            error("This course section doesn't exist");
        }
        $cm->section = 0;
        //$cs->id;
        $cm->course = $newcourse->id;
        $cm->module = $module->id;
        $cm->modulename = $module->name;
        $cm->instance = $instanceid;
        // connect to course
        if (!($cm->coursemodule = add_course_module($cm))) {
            error("Could not add a new course module");
        }
        $sectionid = add_mod_to_section($cm);
        set_field("course_modules", "section", $sectionid, "id", $cm->coursemodule);
        // create rafl_share
        $rafl->create_share($newcourse->id, $author->id);
        // if valid
        // set course status
        if (!tao_update_course_status(COURSE_STATUS_NOTSUBMITTED, "Created new learning path from RAFL module", $newcourse)) {
            error('could not update status');
        }
        // ensure we can use the course right after creating it
        // this means trigger a reload of accessinfo...
        mark_context_dirty($context->path);
        $author->raflmode = 1;
        rebuild_course_cache($newcourse->id);
        // redirect to participants page
        return $newcourse->id;
    } else {
        error("invalid authoring mode");
    }
}
예제 #4
0
}
$restorefile = download_incremental($currenthash, $course->id);
if ($restorefile == 'autofailed') {
    $externalurl = get_field('config_plugins', 'value', 'name', 'backup_inc_server') . '?hash=' . $currenthash;
    print_box(get_string('autofailed', 'local') . '<br><a href="' . $externalurl . '&action=download" target="_blank">click here to download manually</a><br>', 'generalbox', 'intro');
    echo "TODO - must add upload form for incremental here!";
    //incremental_manual_download_form($id);
} elseif ($restorefile == 'uptodate') {
    print_box(get_string('uptodate', 'local'), 'generalbox', 'intro');
} else {
    $prefs['restore_course_files'] = 1;
    $prefs['restore_site_files'] = 1;
    $prefs['restore_user_files'] = 1;
    $pref = restore_generate_preferences_artificially($course, $prefs);
    $pref->updating = 1;
    $status = import_backup_file_silently($CFG->dataroot . '/incrementals_client/' . $id . '/' . $restorefile, $course->id, false, true, $pref);
    if ($status) {
        //insert updated backup hash.
        $bkinstance = new object();
        $bkinstance->courseid = $course->id;
        $bkinstance->filename = $restorefile;
        $bkinstance->hash = $restorefile;
        $bkinstance->timecreated = time();
        if (!insert_record('incremental_instance', $bkinstance)) {
            error('failed inserting incremental_instance record');
        }
        $client_keep = get_field('config_plugins', 'value', 'name', 'backup_inc_client_keep');
        if (!$client_keep) {
            if (!empty($currenthash)) {
                $currentfile = $currenthash . '.zip';
                if ($currentfile != $restorefile) {