Beispiel #1
0
require_login($course, true, $cm);
add_to_log($course->id, "rafl", "view", "view.php?id={$cm->id}", "{$rafl->id}");
/// Print the page header
$strrafls = get_string('modulenameplural', 'rafl');
$strrafl = get_string('modulename', 'rafl');
$navlinks = array();
$navlinks[] = array('name' => $strrafls, 'link' => "index.php?id={$course->id}", 'type' => 'activity');
$navlinks[] = array('name' => format_string($rafl->name), 'link' => '', 'type' => 'activityinstance');
$navigation = build_navigation($navlinks);
print_header_simple(format_string($rafl->name), '', $navigation, '', '', true, update_module_button($cm->id, $course->id, $strrafl), navmenu($course, $cm));
/**
 ********************************************** DAN HAS BEEN HERE START *************************************************
 */
// Better move to the top of this file
require_once dirname(__FILE__) . '/locallib.php';
$rafl = new localLibRafl();
// Debugging
//var_dump($rafl->get_lp_item_structure($rafl->get_rafl_item_id_by_country('uk')));
//$rafl->update_moodle_item($cm->course, $raflitemid, $text);
//$rafl->create_share(3456, 123456);
//$rafl->update_share_contributors(3456, array(7655, 7644));
//die('done!');
// In case we should ever do countries: Gimme the right rafl item in the right language for this country
$country_item_id = $rafl->get_rafl_item_id_by_country('uk');
// Print the rafl page
$rafl->display_rafl_component($cm->course, $country_item_id, $CFG->prefix);
/**
 ********************************************** DAN HAS BEEN HERE END *************************************************
 */
// Finish the page
print_footer($course);
Beispiel #2
0
function local_role_processing($course, $roleid)
{
    global $CFG;
    $shortname = get_field('role', 'shortname', 'id', $roleid);
    // if we are in rafl mode and updating contributors, update the rafl module
    if ($course->learning_path_mode == LEARNING_PATH_MODE_RAFL && $shortname == ROLE_LPCONTRIBUTOR) {
        require_once $CFG->dirroot . '/mod/rafl/locallib.php';
        $rafl = new localLibRafl();
        // get a list of the contributors
        $users = tao_get_lpcontributors(get_context_instance(CONTEXT_COURSE, $course->id));
        $idarray = array();
        if (!empty($users)) {
            foreach ($users as $user) {
                array_push($idarray, $user->id);
            }
            $rafl->update_share_contributors($course->id, $idarray);
        }
    }
}
Beispiel #3
0
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");
    }
}
Beispiel #4
0
    error_log("No share_id provided");
    return;
}
if (empty($success_item_id)) {
    error_log("No success_item_id provided");
    return;
}
if (empty($unit_item_id)) {
    error_log("No unit_item_id provided");
    return;
}
if (empty($webcelltext)) {
    error_log("No webcelltext provided");
    return;
}
// call the store_evidence routine
$rafl = new localLibRafl();
error_log($webcelltext);
$rating = $rafl->store_evidence($share_id, $success_item_id, $unit_item_id, $webcelltext);
if (empty($rating)) {
    error_log('Could not store RAFL evidence');
    return;
}
if (!$rafl->update_moodle_item($share_id, $success_item_id, $webcelltext)) {
    error_log('Could not store evidence in Moodle tables');
    return;
}
// Success
error_log("SUCCESS: updated share {$share_id}, webcell {$success_item_id} with '{$webcelltext}'");
// return rating to AJAX call
echo $rating;
Beispiel #5
0
     $canviewrafl = true;
 } else {
     if (has_capability('moodle/local:canassignselftorafl', get_context_instance(CONTEXT_COURSE, SITEID))) {
         $roleid = get_field('role', 'id', 'shortname', ROLE_LPCONTRIBUTOR);
         if (!user_has_role_assignment($USER->id, $roleid, $context->id)) {
             //if isn't already a contributor, assign as one
             role_assign($roleid, $USER->id, 0, $context->id);
             local_role_processing($course, $roleid);
             $notifymessage = get_string('raflautoaddcontrib', 'rafl');
         }
         $canviewrafl = true;
     }
 }
 if ($canviewrafl) {
     require_once $CFG->dirroot . '/mod/rafl/locallib.php';
     $rafl = new localLibRafl();
     // get the right module id
     $moduleid = $rafl->get_course_module_id($course->id);
     $country_item_id = $rafl->get_rafl_item_id_by_country('uk');
     page_print_position($pageblocks, BLOCK_POS_LEFT, null);
     echo '<td id="middle-column">';
     if (!empty($notifymessage)) {
         notify($notifymessage);
     }
     $rafl->display_rafl_component($course->id, $country_item_id, $CFG);
     echo '</td>';
     page_print_position($pageblocks, BLOCK_POS_RIGHT, null);
 } else {
     echo '<tr>';
     page_print_position($pageblocks, BLOCK_POS_LEFT, null);
     echo '<td id="middle-column">';
Beispiel #6
0
 function instance_config_save($data, $pinned = false, $updaterafl = true)
 {
     global $CFG;
     // if in rafl mode then attempt to update the rafl tables
     if ($CFG->raflmodeenabled && $updaterafl) {
         $course = get_record('course', 'id', $this->instance->pageid);
         if ($course->learning_path_mode == LEARNING_PATH_MODE_RAFL) {
             // look up raflitem id
             if ($pageitem = get_record('format_page_items', 'blockinstance', $this->instance->id)) {
                 require_once $CFG->dirroot . '/mod/rafl/locallib.php';
                 $rafl = new localLibRafl();
                 $rafl->update_share_item($course->id, $pageitem->rafl_item, $data->text);
             } else {
                 error_log('no matching rafl item could be found');
             }
         }
     }
     // And now forward to the default implementation defined in the parent class
     return parent::instance_config_save($data);
 }