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"); } }
$page->parent = $summarypageid; $formatpageid = insert_record('format_page', $page); // add the title block $instanceid = tao_add_learningpath_block('html', $pageid, $pagetype, '', '<h1>' . $page->nameone . '</h1>'); if (!empty($instanceid)) { tao_add_learningpath_pageitem($formatpageid, $instanceid); } if (!empty($evds['questions'])) { foreach ($evds['questions'] as $question => $qdata) { // call the store_evidence routines //use Textlib to convert/clean data // $textlib = textlib_get_instance(); //$qdata['text'] = $textlib->convert($qdata['text'], strtolower(mb_detect_encoding($qdata['text']))); $text = clean_text($qdata['text'], FORMAT_MOODLE); // insert question as a block and format_page item on this page $instanceid = tao_add_learningpath_block('tao_lp_qa', $pageid, $pagetype, $question, $text); // create a new page item that links to the instance if (!empty($instanceid)) { tao_add_learningpath_pageitem($formatpageid, $instanceid); } } } } } //now do stuff with Teaching methods = presentation methods. $sql = "SELECT {$importlang} FROM language, presMethod WHERE " . "language.id=presMethod.title_id AND presMethod.id=" . $rec['method_id']; $rs2 = $dbh->Execute($sql); if (!empty($rs2)) { while ($rec2 = $rs2->FetchRow()) { $method = $rec2[$importlang]; $existingmethod = get_record('classification_value', 'value', $method);