Exemple #1
0
            if ( isset($xmlglossary['USEDYNALINK'][0]['#']) ) {
                $glossary->usedynalink = ($xmlglossary['USEDYNALINK'][0]['#']);
            } else {
                $glossary->usedynalink = $CFG->glossary_linkentries;
            }
            if ( isset($xmlglossary['DEFAULTAPPROVAL'][0]['#']) ) {
                $glossary->defaultapproval = ($xmlglossary['DEFAULTAPPROVAL'][0]['#']);
            } else {
                $glossary->defaultapproval = $CFG->glossary_defaultapproval;
            }

            // This field was not included in export, assume zero.
            $glossary->assessed = 0;

            // Include new glossary and return the new ID
            if ( !$glossary->id = glossary_add_instance($glossary) ) {
                echo $OUTPUT->notification("Error while trying to create the new glossary.");
                glossary_print_tabbed_table_end();
                echo $OUTPUT->footer();
                exit;
            } else {
                //The instance has been created, so lets do course_modules
                //and course_sections
                $mod = new stdClass();
                $mod->groupmode = $course->groupmode;  /// Default groupmode the same as course

                $mod->instance = $glossary->id;
                // course_modules and course_sections each contain a reference
                // to each other, so we have to update one of them twice.

                if (! $currmodule = $DB->get_record("modules", array("name"=>'glossary'))) {
Exemple #2
0
/**
* basic encapsulation of creating a glossary instance - as would be done in modedit.php
* with glossary_add_instance();
*
* @param int $courseid the id of the course to add forum to
* @param string $glossary_name  name of the glossary
* @param string $description descrition of the glossary
* @return $glossary object
* */
function local_create_glossary($courseid, $glossary_name, $description)
{
    global $CFG;
    require_once $CFG->dirroot . "/mod/glossary/lib.php";
    require_once $CFG->dirroot . "/lib/grouplib.php";
    if (!($course = get_record("course", "id", $courseid))) {
        error("This course doesn't exist");
    }
    $glossary = new object();
    $glossary->course = $courseid;
    $glossary->cmidnumber = 1;
    $glossary->name = $glossary_name;
    $glossary->intro = $description;
    $glossary->entbypage = 10;
    $glossary->mainglossary = 1;
    $glossary->globalglossary = false;
    $glossary->userrating = false;
    $glossary->ratingtime = false;
    if ($CFG->enablerssfeeds && isset($CFG->glossary_enablerssfeeds) && $CFG->glossary_enablerssfeeds) {
        $glossary->rsstype = 2;
        $glossary->rssarticles = 10;
    }
    $glossary->allowduplicatedentries = 0;
    $glossary->allowcomments = 1;
    $glossary->allowprintview = 1;
    $glossary->usedynalink = 1;
    $glossary->defaultapproval = 1;
    $glossary->displayformat = 'faq';
    $glossary->showspecial = 1;
    $glossary->showalphabet = 1;
    $glossary->showall = 1;
    $glossary->editalways = 0;
    $glossary->assesstimestart = time();
    $glossary->assesstimefinish = time();
    $glossary->showall = 1;
    $glossary->showall = 1;
    $glossary->showall = 1;
    $glossary->showall = 1;
    $glossary->groupingid = $course->defaultgroupingid;
    $glossary->groupmembersonly = 0;
    //    gradecat    8   - uncategorised
    $glossary->groupmode = 0;
    $glossary->visible = '1';
    $glossary->module = get_field('modules', 'id', 'name', 'glossary');
    $glossary->id = glossary_add_instance($glossary);
    $glossary->modulename = 'glossary';
    $glossary->instance = $glossary->id;
    $glossary->section = 0;
    // default to first level section
    $glossary->coursemodule = add_course_module($glossary);
    $sectionid = add_mod_to_section($glossary);
    set_field("course_modules", "section", $sectionid, "id", $glossary->coursemodule);
    set_coursemodule_visible($glossary->coursemodule, $glossary->visible);
    set_coursemodule_idnumber($glossary->coursemodule, $glossary->cmidnumber);
    rebuild_course_cache($glossary->course);
    return $glossary;
}