当前位置: 首页>>代码示例>>PHP>>正文


PHP create_course函数代码示例

本文整理汇总了PHP中create_course函数的典型用法代码示例。如果您正苦于以下问题:PHP create_course函数的具体用法?PHP create_course怎么用?PHP create_course使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了create_course函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: create_course_pditt

function create_course_pditt($category,$idnumber,$kodemk,$namamk,$summary,$startdate=0,$visible=0,$format='topics'){
    global $DB, $CFG;
    //$x = $DB->get_record('course', array('idnumber'=>$idnumber, 'shortname'=>$kodemk), '*');
    $x = $DB->get_record('course', array('idnumber'=>$idnumber), '*');
    if (!$x) {
        $data = new stdClass();
        $data->category=$category;
        $data->idnumber = $idnumber;
        $data->fullname=$namamk;
        $data->shortname = $kodemk;
        $data->summary = $summary;
        $data->summaryformat=0;
        $data->format=$format;
        $data->startdate = $startdate;
        $data->showgrades=1;
        $data->visible=$visible;
        $h=create_course($data);
        return $h->id; 
    } else {
        $data = new stdClass();
        $data->fullname=$namamk;
        $data->idnumber = $idnumber;
        $data->shortname = $kodemk;
        $data->summary = $summary;
        $data->id = $x->id;
        update_course($data);
        return $x->id;
    }

}
开发者ID:rm77,项目名称:pd1tt_module,代码行数:30,代码来源:fungsi_moodle.php

示例2: execute

 public function execute()
 {
     global $CFG;
     require_once $CFG->dirroot . '/course/lib.php';
     foreach ($this->arguments as $argument) {
         $this->expandOptionsManually(array($argument));
         $options = $this->expandedOptions;
         $course = new \stdClass();
         $course->fullname = $options['fullname'];
         $course->shortname = $argument;
         $course->description = $options['description'];
         $format = $options['format'];
         if (!$format) {
             $format = get_config('moodlecourse', 'format');
         }
         $course->format = $format;
         $course->idnumber = $options['idnumber'];
         $visible = strtolower($options['visible']);
         if ($visible == 'n' || $visible == 'no') {
             $visible = 0;
         } else {
             $visible = 1;
         }
         $course->visible = $visible;
         $course->category = $options['category'];
         $course->summary = '';
         $course->summaryformat = FORMAT_HTML;
         $course->startdate = time();
         //either use API create_course
         $newcourse = create_course($course);
         echo $newcourse->id . "\n";
     }
 }
开发者ID:tmuras,项目名称:moosh,代码行数:33,代码来源:CourseCreate.php

示例3: test_create_course

 public function test_create_course()
 {
     global $DB;
     $this->resetAfterTest(true);
     $defaultcategory = $DB->get_field_select('course_categories', "MIN(id)", "parent=0");
     $course = new stdClass();
     $course->fullname = 'Apu loves Unit Təsts';
     $course->shortname = 'Spread the lŭve';
     $course->idnumber = '123';
     $course->summary = 'Awesome!';
     $course->summaryformat = FORMAT_PLAIN;
     $course->format = 'topics';
     $course->newsitems = 0;
     $course->numsections = 5;
     $course->category = $defaultcategory;
     $created = create_course($course);
     $context = context_course::instance($created->id);
     // Compare original and created.
     $original = (array) $course;
     $this->assertEquals($original, array_intersect_key((array) $created, $original));
     // Ensure default section is created.
     $sectioncreated = $DB->record_exists('course_sections', array('course' => $created->id, 'section' => 0));
     $this->assertTrue($sectioncreated);
     // Ensure blocks have been associated to the course.
     $blockcount = $DB->count_records('block_instances', array('parentcontextid' => $context->id));
     $this->assertGreaterThan(0, $blockcount);
 }
开发者ID:JP-Git,项目名称:moodle,代码行数:27,代码来源:courselib_test.php

示例4: cace_create_newcourse

/**
 * Create a new course using existing Moodle functionality
 *
 * @author Andrew Zoltay
 * date    2010-05-03
 * @param associative array $newcourse used to create new course
 * @param string $pagecontent contents of page resource
 * @return int id of new course or failure of course creation
 */
function cace_create_newcourse($newcourse, $pagecontent)
{
    global $DB, $USER;
    // Need to force a user so the system can log who is doing the action.
    $USER = $DB->get_record('user', array('username' => 'mdladmin'));
    // Prep the course info.
    $course = cace_prep_newcourse($newcourse);
    // Verify $course was prepared correctly.
    if (!$course) {
        cace_write_to_log("ERROR - Moodle cace_prep_newcourse() failed for {$newcourse->idnumber}");
        return false;
    }
    // Create the new course shell.
    try {
        $createdcourse = create_course($course);
        // If course shell was created, add "Development Notes" resource to new shell
        // First prep the data - default section to the first one in the course (0).
        $data = cace_prep_page_data($createdcourse, 0, $pagecontent);
        if (!cace_add_page_resource($createdcourse, $data)) {
            // Just report the error - don't stop execution.
            cace_write_to_log("ERROR - Failed to add {$data->name} for course {$newcourse->idnumber}");
        }
        // Add default blocks to the right column.
        cace_update_default_course_blocks($createdcourse);
        // Add a record in the grade categories table and also in the grade items table to support letter grade and percentages
        // in the course totals column.
        cace_add_grade_records($createdcourse->id);
        return $createdcourse->id;
    } catch (moodle_exception $e) {
        cace_write_to_log("ERROR - Moodle create_course() failed for {$newcourse->idnumber} " . $e->getMessage());
        return false;
    }
}
开发者ID:royalroads,项目名称:cace,代码行数:42,代码来源:cacelib.php

示例5: test_user_sync_on_pm_user_create

 /**
  * Validate that appropriate fields are synched over to Moodle when PM user is enrolled in a class instance during an import.
  */
 public function test_user_sync_on_pm_user_create()
 {
     global $CFG, $DB;
     require_once $CFG->dirroot . '/course/lib.php';
     require_once $CFG->dirroot . '/local/elisprogram/lib/setup.php';
     require_once elispm::lib('data/classmoodlecourse.class.php');
     require_once elispm::lib('data/course.class.php');
     require_once elispm::lib('data/pmclass.class.php');
     require_once elispm::lib('data/user.class.php');
     // Configure the elis enrolment plugin.
     $roleid = $DB->get_field('role', 'id', array(), IGNORE_MULTIPLE);
     set_config('roleid', $roleid, 'enrol_elis');
     $user = new user(array('idnumber' => 'testuseridnumber', 'username' => 'testuserusername', 'firstname' => 'testuserfirstname', 'lastname' => 'testuserlastname', 'email' => 'test@useremail.com', 'country' => 'CA'));
     $user->save();
     $course = new course(array('name' => 'testcoursename', 'idnumber' => 'testcourseidnumber', 'syllabus' => ''));
     $course->save();
     $class = new pmclass(array('courseid' => $course->id, 'idnumber' => 'testclassidnumber'));
     $class->save();
     $category = new stdClass();
     $category->name = 'testcategoryname';
     $category->id = $DB->insert_record('course_categories', $category);
     // Create the associated context.
     context_coursecat::instance($category->id);
     $mdlcourse = new stdClass();
     $mdlcourse->category = $category->id;
     $mdlcourse->fullname = 'testcoursefullname';
     $mdlcourse = create_course($mdlcourse);
     // Associate class instance to Moodle course.
     $classmoodlecourse = new classmoodlecourse(array('classid' => $class->id, 'moodlecourseid' => $mdlcourse->id));
     $classmoodlecourse->save();
     // Run the enrolment create action.
     $record = new stdClass();
     $record->context = 'class_testclassidnumber';
     $record->user_username = 'testuserusername';
     $importplugin = rlip_dataplugin_factory::factory('dhimport_version1elis');
     $importplugin->fslogger = new silent_fslogger(null);
     $importplugin->class_enrolment_create($record, 'bogus', 'testclassidnumber');
     // Validate the enrolment.
     $enrolid = $DB->get_field('enrol', 'id', array('enrol' => 'elis', 'courseid' => $mdlcourse->id));
     $this->assertNotEquals(false, $enrolid);
     $mdluserid = $DB->get_field('user', 'id', array('username' => 'testuserusername'));
     $this->assertNotEquals(false, $mdluserid);
     $this->assertTrue($DB->record_exists('user_enrolments', array('enrolid' => $enrolid, 'userid' => $mdluserid)));
     // Validate the role assignment.
     $mdlcoursecontext = context_course::instance($mdlcourse->id);
     $this->assertTrue($DB->record_exists('role_assignments', array('roleid' => $roleid, 'contextid' => $mdlcoursecontext->id, 'userid' => $mdluserid)));
 }
开发者ID:jamesmcq,项目名称:elis,代码行数:50,代码来源:elis_enrolment_sync_test.php

示例6: create_course

 public static function create_course($course)
 {
     global $CFG, $DB;
     // Valida os parametros.
     $params = self::validate_parameters(self::create_course_parameters(), array('course' => $course));
     // Inlcui a biblioteca de curso do moodle
     require_once "{$CFG->dirroot}/course/lib.php";
     // Transforma o array em objeto.
     $course = (object) $course;
     // Inicia a transacao, qualquer erro que aconteca o rollback sera executado.
     $transaction = $DB->start_delegated_transaction();
     // Busca o id do curso apartir do trm_id da turma.
     $courseid = self::get_course_by_trm_id($course->trm_id);
     // Dispara uma excessao se essa turma ja estiver mapeado para um curso.
     if ($courseid) {
         throw new Exception("Essa turma ja esta mapeada com o curso de id: " . $courseid);
     }
     // Cria o curso usando a biblioteca do proprio moodle.
     $result = create_course($course);
     // Caso o curso tenha sido criado adiciona a tabela de controle os dados dos curso e da turma.
     if ($result->id) {
         $data['trm_id'] = $course->trm_id;
         $data['courseid'] = $result->id;
         $res = $DB->insert_record('itg_turma_course', $data);
     }
     // Persiste as operacoes em caso de sucesso.
     $transaction->allow_commit();
     // Prepara o array de retorno.
     if ($res) {
         $returndata['id'] = $result->id;
         $returndata['status'] = 'success';
         $returndata['message'] = 'Curso criado com sucesso';
     } else {
         $returndata['id'] = 0;
         $returndata['status'] = 'error';
         $returndata['message'] = 'Erro ao tentar criar o curso';
     }
     return $returndata;
 }
开发者ID:uemanet,项目名称:moodle-local_wsmiidle,代码行数:39,代码来源:course.php

示例7: build

 /**
  * Create the fixture
  *
  * This method must be safe to call multiple times.
  *
  * @return void
  * @throws moodle_exception
  */
 public function build()
 {
     global $CFG, $DB;
     require_once $CFG->libdir . '/coursecatlib.php';
     if (!$this->exists()) {
         $course = (object) $this->get_options();
         // Clean course table - can happen when unit tests fail...
         if (!empty($course->shortname) and $record = $DB->get_record('course', array('shortname' => $course->shortname))) {
             delete_course($record, false);
         }
         if (!empty($course->idnumber) and $record = $DB->get_record('course', array('idnumber' => $course->idnumber))) {
             delete_course($record, false);
         }
         // Try to help folks out...
         if (!property_exists($course, 'category')) {
             $course->category = coursecat::get_default()->id;
         }
         if (!property_exists($course, 'fullname')) {
             $course->fullname = '';
         }
         $course = create_course($course);
         $this->set_results($DB->get_record('course', array('id' => $course->id), '*', MUST_EXIST));
     }
 }
开发者ID:bgao-ca,项目名称:moodle-local_mr,代码行数:32,代码来源:course.php

示例8: create_courses

    /**
     * Create  courses
     *
     * @param array $courses
     * @return array courses (id and shortname only)
     * @since Moodle 2.2
     */
    public static function create_courses($courses) {
        global $CFG, $DB;
        require_once($CFG->dirroot . "/course/lib.php");
        require_once($CFG->libdir . '/completionlib.php');

        $params = self::validate_parameters(self::create_courses_parameters(),
                        array('courses' => $courses));

        $availablethemes = core_component::get_plugin_list('theme');
        $availablelangs = get_string_manager()->get_list_of_translations();

        $transaction = $DB->start_delegated_transaction();

        foreach ($params['courses'] as $course) {

            // Ensure the current user is allowed to run this function
            $context = context_coursecat::instance($course['categoryid'], IGNORE_MISSING);
            try {
                self::validate_context($context);
            } catch (Exception $e) {
                $exceptionparam = new stdClass();
                $exceptionparam->message = $e->getMessage();
                $exceptionparam->catid = $course['categoryid'];
                throw new moodle_exception('errorcatcontextnotvalid', 'webservice', '', $exceptionparam);
            }
            require_capability('moodle/course:create', $context);

            // Make sure lang is valid
            if (array_key_exists('lang', $course) and empty($availablelangs[$course['lang']])) {
                throw new moodle_exception('errorinvalidparam', 'webservice', '', 'lang');
            }

            // Make sure theme is valid
            if (array_key_exists('forcetheme', $course)) {
                if (!empty($CFG->allowcoursethemes)) {
                    if (empty($availablethemes[$course['forcetheme']])) {
                        throw new moodle_exception('errorinvalidparam', 'webservice', '', 'forcetheme');
                    } else {
                        $course['theme'] = $course['forcetheme'];
                    }
                }
            }

            //force visibility if ws user doesn't have the permission to set it
            $category = $DB->get_record('course_categories', array('id' => $course['categoryid']));
            if (!has_capability('moodle/course:visibility', $context)) {
                $course['visible'] = $category->visible;
            }

            //set default value for completion
            $courseconfig = get_config('moodlecourse');
            if (completion_info::is_enabled_for_site()) {
                if (!array_key_exists('enablecompletion', $course)) {
                    $course['enablecompletion'] = $courseconfig->enablecompletion;
                }
            } else {
                $course['enablecompletion'] = 0;
            }

            $course['category'] = $course['categoryid'];

            // Summary format.
            $course['summaryformat'] = external_validate_format($course['summaryformat']);

            if (!empty($course['courseformatoptions'])) {
                foreach ($course['courseformatoptions'] as $option) {
                    $course[$option['name']] = $option['value'];
                }
            }

            //Note: create_course() core function check shortname, idnumber, category
            $course['id'] = create_course((object) $course)->id;

            $resultcourses[] = array('id' => $course['id'], 'shortname' => $course['shortname']);
        }

        $transaction->allow_commit();

        return $resultcourses;
    }
开发者ID:rwijaya,项目名称:moodle,代码行数:87,代码来源:externallib.php

示例9: sync_courses


//.........这里部分代码省略.........
                 $course->shortname = $fields[$shortname_l];
                 $course->idnumber = $idnumber ? $fields[$idnumber_l] : '';
                 if ($category) {
                     if (empty($fields[$category_l])) {
                         // Empty category means use default.
                         $course->category = $defaultcategory;
                     } else {
                         if ($coursecategory = $DB->get_record('course_categories', array($localcategoryfield => $fields[$category_l]), 'id')) {
                             // Yay, correctly specified category!
                             $course->category = $coursecategory->id;
                             unset($coursecategory);
                         } else {
                             // Bad luck, better not continue because unwanted ppl might get access to course in different category.
                             if ($verbose) {
                                 mtrace('  error: invalid category ' . $localcategoryfield . ', can not create course: ' . $fields[$shortname_l]);
                             }
                             continue;
                         }
                     }
                 } else {
                     $course->category = $defaultcategory;
                 }
                 $createcourses[] = $course;
             }
         }
         $rs->Close();
     } else {
         mtrace('Error reading data from the external course table');
         $extdb->Close();
         return 4;
     }
     if ($createcourses) {
         require_once "{$CFG->dirroot}/course/lib.php";
         $templatecourse = $this->get_config('templatecourse');
         $template = false;
         if ($templatecourse) {
             if ($template = $DB->get_record('course', array('shortname' => $templatecourse))) {
                 $template = fullclone(course_get_format($template)->get_course());
                 unset($template->id);
                 unset($template->fullname);
                 unset($template->shortname);
                 unset($template->idnumber);
             } else {
                 if ($verbose) {
                     mtrace("  can not find template for new course!");
                 }
             }
         }
         if (!$template) {
             $courseconfig = get_config('moodlecourse');
             $template = new stdClass();
             $template->summary = '';
             $template->summaryformat = FORMAT_HTML;
             $template->format = $courseconfig->format;
             $template->newsitems = $courseconfig->newsitems;
             $template->showgrades = $courseconfig->showgrades;
             $template->showreports = $courseconfig->showreports;
             $template->maxbytes = $courseconfig->maxbytes;
             $template->groupmode = $courseconfig->groupmode;
             $template->groupmodeforce = $courseconfig->groupmodeforce;
             $template->visible = $courseconfig->visible;
             $template->lang = $courseconfig->lang;
             $template->groupmodeforce = $courseconfig->groupmodeforce;
         }
         foreach ($createcourses as $fields) {
             $newcourse = clone $template;
             $newcourse->fullname = $fields->fullname;
             $newcourse->shortname = $fields->shortname;
             $newcourse->idnumber = $fields->idnumber;
             $newcourse->category = $fields->category;
             // Detect duplicate data once again, above we can not find duplicates
             // in external data using DB collation rules...
             if ($DB->record_exists('course', array('shortname' => $newcourse->shortname))) {
                 if ($verbose) {
                     mtrace("  can not insert new course, duplicate shortname detected: " . $newcourse->shortname);
                 }
                 continue;
             } else {
                 if (!empty($newcourse->idnumber) and $DB->record_exists('course', array('idnumber' => $newcourse->idnumber))) {
                     if ($verbose) {
                         mtrace("  can not insert new course, duplicate idnumber detected: " . $newcourse->idnumber);
                     }
                     continue;
                 }
             }
             $c = create_course($newcourse);
             if ($verbose) {
                 mtrace("  creating course: {$c->id}, {$c->fullname}, {$c->shortname}, {$c->idnumber}, {$c->category}");
             }
         }
         unset($createcourses);
         unset($template);
     }
     // Close db connection.
     $extdb->Close();
     if ($verbose) {
         mtrace('...course synchronisation finished.');
     }
     return 0;
 }
开发者ID:vinoth4891,项目名称:clinique,代码行数:101,代码来源:lib.php

示例10: approve

 /**
  * This function approves the request turning it into a course
  *
  * This function converts the course request into a course, at the same time
  * transferring any files used in the summary to the new course and then removing
  * the course request and the files associated with it.
  *
  * @return int The id of the course that was created from this request
  */
 public function approve()
 {
     global $CFG, $DB, $USER;
     $user = $DB->get_record('user', array('id' => $this->properties->requester, 'deleted' => 0), '*', MUST_EXIST);
     $category = get_course_category($CFG->defaultrequestcategory);
     $courseconfig = get_config('moodlecourse');
     // Transfer appropriate settings
     $data = clone $this->properties;
     unset($data->id);
     unset($data->reason);
     unset($data->requester);
     // Set category
     $data->category = $category->id;
     $data->sortorder = $category->sortorder;
     // place as the first in category
     // Set misc settings
     $data->requested = 1;
     // Apply course default settings
     $data->format = $courseconfig->format;
     $data->numsections = $courseconfig->numsections;
     $data->hiddensections = $courseconfig->hiddensections;
     $data->newsitems = $courseconfig->newsitems;
     $data->showgrades = $courseconfig->showgrades;
     $data->showreports = $courseconfig->showreports;
     $data->maxbytes = $courseconfig->maxbytes;
     $data->groupmode = $courseconfig->groupmode;
     $data->groupmodeforce = $courseconfig->groupmodeforce;
     $data->visible = $courseconfig->visible;
     $data->visibleold = $data->visible;
     $data->lang = $courseconfig->lang;
     $course = create_course($data);
     $context = get_context_instance(CONTEXT_COURSE, $course->id, MUST_EXIST);
     // add enrol instances
     if (!$DB->record_exists('enrol', array('courseid' => $course->id, 'enrol' => 'manual'))) {
         if ($manual = enrol_get_plugin('manual')) {
             $manual->add_default_instance($course);
         }
     }
     // enrol the requester as teacher if necessary
     if (!empty($CFG->creatornewroleid) and !is_viewing($context, $user, 'moodle/role:assign') and !is_enrolled($context, $user, 'moodle/role:assign')) {
         enrol_try_internal_enrol($course->id, $user->id, $CFG->creatornewroleid);
     }
     $this->delete();
     $a = new stdClass();
     $a->name = format_string($course->fullname, true, array('context' => get_context_instance(CONTEXT_COURSE, $course->id)));
     $a->url = $CFG->wwwroot . '/course/view.php?id=' . $course->id;
     $this->notify($user, $USER, 'courserequestapproved', get_string('courseapprovedsubject'), get_string('courseapprovedemail2', 'moodle', $a));
     return $course->id;
 }
开发者ID:numbas,项目名称:moodle,代码行数:58,代码来源:lib.php

示例11: create_course

    /**
     * Create a test course
     * @param array|stdClass $record
     * @param array $options with keys:
     *      'createsections'=>bool precreate all sections
     * @return stdClass course record
     */
    public function create_course($record=null, array $options=null) {
        global $DB, $CFG;
        require_once("$CFG->dirroot/course/lib.php");

        $this->coursecount++;
        $i = $this->coursecount;

        $record = (array)$record;

        if (!isset($record['fullname'])) {
            $record['fullname'] = 'Test course '.$i;
        }

        if (!isset($record['shortname'])) {
            $record['shortname'] = 'tc_'.$i;
        }

        if (!isset($record['idnumber'])) {
            $record['idnumber'] = '';
        }

        if (!isset($record['format'])) {
            $record['format'] = 'topics';
        }

        if (!isset($record['newsitems'])) {
            $record['newsitems'] = 0;
        }

        if (!isset($record['numsections'])) {
            $record['numsections'] = 5;
        }

        if (!isset($record['summary'])) {
            $record['summary'] = "Test course $i\n$this->loremipsum";
        }

        if (!isset($record['summaryformat'])) {
            $record['summaryformat'] = FORMAT_MOODLE;
        }

        if (!isset($record['category'])) {
            $record['category'] = $DB->get_field_select('course_categories', "MIN(id)", "parent=0");
        }

        $course = create_course((object)$record);
        context_course::instance($course->id);
        if (!empty($options['createsections'])) {
            if (isset($course->numsections)) {
                course_create_sections_if_missing($course, range(0, $course->numsections));
            } else {
                course_create_sections_if_missing($course, 0);
            }
        }

        return $course;
    }
开发者ID:Burick,项目名称:moodle,代码行数:64,代码来源:data_generator.php

示例12: create_restored_course

function create_restored_course(&$tool_content, $restoreThis, $course_code, $course_lang, $course_title, $course_desc, $course_vis, $course_prof) {
    global $webDir, $urlServer, $urlAppend, $langEnter, $langBack, $currentCourseCode;
    require_once 'modules/create_course/functions.php';
    require_once 'modules/course_info/restorehelper.class.php';
    require_once 'include/lib/fileManageLib.inc.php';
    $new_course_code = null;
    $new_course_id = null;

    Database::get()->transaction(function() use (&$new_course_code, &$new_course_id, $restoreThis, $course_code, $course_lang, $course_title, $course_desc, $course_vis, $course_prof, $webDir, &$tool_content, $urlServer, $urlAppend) {
        $departments = array();
        if (isset($_POST['department'])) {
            foreach ($_POST['department'] as $did) {
                $departments[] = intval($did);
            }
        } else {
            $minDep = Database::get()->querySingle("SELECT MIN(id) AS min FROM hierarchy");
            if ($minDep) {
                $departments[0] = $minDep->min;
            }
        }

        $r = $restoreThis . '/html';
        list($new_course_code, $new_course_id) = create_course($course_code, $course_lang, $course_title, $course_desc, $departments, $course_vis, $course_prof);
        if (!$new_course_code) {
            $tool_content = "<div class='alert alert-warning'>" . $GLOBALS['langError'] . "</div>";
            draw($tool_content, 3);
            exit;
        }

        if (!file_exists($restoreThis)) {
            redirect_to_home_page('modules/course_info/restore_course.php');
        }
        $config_data = unserialize(file_get_contents($restoreThis . '/config_vars'));
        // If old $urlAppend didn't end in /, add it
        if (substr($config_data['urlAppend'], -1) !== '/') {
            $config_data['urlAppend'] .= '/';
        }
        $eclass_version = (isset($config_data['version'])) ? $config_data['version'] : null;
        $backupData = null;
        if (file_exists($restoreThis . '/backup.php')) {
            $backupData = parse_backup_php($restoreThis . '/backup.php');
            $eclass_version = $backupData['eclass_version'];
        }
        $restoreHelper = new RestoreHelper($eclass_version);

        $course_file = $restoreThis . '/' . $restoreHelper->getFile('course');
        if (file_exists($course_file)) {
            $course_dataArr = unserialize(file_get_contents($course_file));
            $course_data = $course_dataArr[0];
            // update course query
            $upd_course_sql = "UPDATE course SET keywords = ?s, doc_quota = ?f, video_quota = ?f, "
                            . " group_quota = ?f, dropbox_quota = ?f, glossary_expand = ?d ";
            $upd_course_args = array(
                $course_data[$restoreHelper->getField('course', 'keywords')],
                floatval($course_data['doc_quota']),
                floatval($course_data['video_quota']),
                floatval($course_data['group_quota']),
                floatval($course_data['dropbox_quota']),
                intval($course_data[$restoreHelper->getField('course', 'glossary_expand')])
            );
            if (isset($course_data['home_layout']) and isset($course_data['course_image'])) {
                $upd_course_sql .= ', home_layout = ?d, course_image = ?s ';
                $upd_course_args[] = $course_data['home_layout'];
                $upd_course_args[] = $course_data['course_image'];
            }
            // Set keywords to '' if NULL
            if (!isset($upd_course_args[0])) {
                $upd_course_args[0] = '';
            }
            // handle course weekly if exists
            if (isset($course_data['view_type']) && isset($course_data['start_date']) && isset($course_data['finish_date'])) {
                $upd_course_sql .= " , view_type = ?s, start_date = ?t, finish_date = ?t ";
                array_push($upd_course_args,
                    $course_data['view_type'],
                    $course_data['start_date'],
                    $course_data['finish_date']
                );
            }
            $upd_course_sql .= " WHERE id = ?d ";
            array_push($upd_course_args, intval($new_course_id));

            Database::get()->query($upd_course_sql, $upd_course_args);
        }

        $userid_map = array();
        $user_file = $restoreThis . '/user';
        if (file_exists($user_file)) {
            $cours_user = unserialize(file_get_contents($restoreThis . '/' . $restoreHelper->getFile('course_user')));
            $userid_map = restore_users(unserialize(file_get_contents($user_file)), $cours_user, $departments, $restoreHelper);
            register_users($new_course_id, $userid_map, $cours_user, $restoreHelper);
        }
        $userid_map[0] = 0;
        $userid_map[-1] = -1;

        $coursedir = "${webDir}/courses/$new_course_code";
        $videodir = "${webDir}/video/$new_course_code";
        move_dir($r, $coursedir);
        if (is_dir($restoreThis . '/video_files')) {
            move_dir($restoreThis . '/video_files', $videodir);
        }
//.........这里部分代码省略.........
开发者ID:nikosv,项目名称:openeclass,代码行数:101,代码来源:restore_functions.php

示例13: create_course

 /**
  * Will create the moodle course from the template
  * course_ext is an array as obtained from ldap -- flattened somewhat
  *
  * @param array $course_ext
  * @param progress_trace $trace
  * @return mixed false on error, id for the newly created course otherwise.
  */
 function create_course($course_ext, progress_trace $trace)
 {
     global $CFG, $DB;
     require_once "{$CFG->dirroot}/course/lib.php";
     // Override defaults with template course
     $template = false;
     if ($this->get_config('template')) {
         if ($template = $DB->get_record('course', array('shortname' => $this->get_config('template')))) {
             $template = fullclone(course_get_format($template)->get_course());
             unset($template->id);
             // So we are clear to reinsert the record
             unset($template->fullname);
             unset($template->shortname);
             unset($template->idnumber);
         }
     }
     if (!$template) {
         $courseconfig = get_config('moodlecourse');
         $template = new stdClass();
         $template->summary = '';
         $template->summaryformat = FORMAT_HTML;
         $template->format = $courseconfig->format;
         $template->newsitems = $courseconfig->newsitems;
         $template->showgrades = $courseconfig->showgrades;
         $template->showreports = $courseconfig->showreports;
         $template->maxbytes = $courseconfig->maxbytes;
         $template->groupmode = $courseconfig->groupmode;
         $template->groupmodeforce = $courseconfig->groupmodeforce;
         $template->visible = $courseconfig->visible;
         $template->lang = $courseconfig->lang;
         $template->enablecompletion = $courseconfig->enablecompletion;
     }
     $course = $template;
     $course->category = $this->get_config('category');
     if (!$DB->record_exists('course_categories', array('id' => $this->get_config('category')))) {
         $categories = $DB->get_records('course_categories', array(), 'sortorder', 'id', 0, 1);
         $first = reset($categories);
         $course->category = $first->id;
     }
     // Override with required ext data
     $course->idnumber = $course_ext[$this->get_config('course_idnumber')][0];
     $course->fullname = $course_ext[$this->get_config('course_fullname')][0];
     $course->shortname = $course_ext[$this->get_config('course_shortname')][0];
     if (empty($course->idnumber) || empty($course->fullname) || empty($course->shortname)) {
         // We are in trouble!
         $trace->output(get_string('cannotcreatecourse', 'enrol_ldap') . ' ' . var_export($course, true));
         return false;
     }
     $summary = $this->get_config('course_summary');
     if (!isset($summary) || empty($course_ext[$summary][0])) {
         $course->summary = '';
     } else {
         $course->summary = $course_ext[$this->get_config('course_summary')][0];
     }
     // Check if the shortname already exists if it does - skip course creation.
     if ($DB->record_exists('course', array('shortname' => $course->shortname))) {
         $trace->output(get_string('duplicateshortname', 'enrol_ldap', $course));
         return false;
     }
     $newcourse = create_course($course);
     return $newcourse->id;
 }
开发者ID:abhilash1994,项目名称:moodle,代码行数:70,代码来源:lib.php

示例14: proceed

 /**
  * Proceed with the import of the course.
  *
  * @return void
  */
 public function proceed()
 {
     global $CFG, $USER;
     if (!$this->prepared) {
         throw new coding_exception('The course has not been prepared.');
     } else {
         if ($this->has_errors()) {
             throw new moodle_exception('Cannot proceed, errors were detected.');
         } else {
             if ($this->processstarted) {
                 throw new coding_exception('The process has already been started.');
             }
         }
     }
     $this->processstarted = true;
     if ($this->do === self::DO_DELETE) {
         if ($this->delete()) {
             $this->status('coursedeleted', new lang_string('coursedeleted', 'tool_uploadcourse'));
         } else {
             $this->error('errorwhiledeletingcourse', new lang_string('errorwhiledeletingcourse', 'tool_uploadcourse'));
         }
         return true;
     } else {
         if ($this->do === self::DO_CREATE) {
             $course = create_course((object) $this->data);
             $this->id = $course->id;
             $this->status('coursecreated', new lang_string('coursecreated', 'tool_uploadcourse'));
         } else {
             if ($this->do === self::DO_UPDATE) {
                 $course = (object) $this->data;
                 update_course($course);
                 $this->id = $course->id;
                 $this->status('courseupdated', new lang_string('courseupdated', 'tool_uploadcourse'));
             } else {
                 // Strangely the outcome has not been defined, or is unknown!
                 throw new coding_exception('Unknown outcome!');
             }
         }
     }
     // Restore a course.
     if (!empty($this->restoredata)) {
         $rc = new restore_controller($this->restoredata, $course->id, backup::INTERACTIVE_NO, backup::MODE_IMPORT, $USER->id, backup::TARGET_CURRENT_ADDING);
         // Check if the format conversion must happen first.
         if ($rc->get_status() == backup::STATUS_REQUIRE_CONV) {
             $rc->convert();
         }
         if ($rc->execute_precheck()) {
             $rc->execute_plan();
             $this->status('courserestored', new lang_string('courserestored', 'tool_uploadcourse'));
         } else {
             $this->error('errorwhilerestoringcourse', new lang_string('errorwhilerestoringthecourse', 'tool_uploadcourse'));
         }
         $rc->destroy();
     }
     // Proceed with enrolment data.
     $this->process_enrolment_data($course);
     // Reset the course.
     if ($this->importoptions['reset'] || $this->options['reset']) {
         if ($this->do === self::DO_UPDATE && $this->can_reset()) {
             $this->reset($course);
             $this->status('coursereset', new lang_string('coursereset', 'tool_uploadcourse'));
         }
     }
     // Mark context as dirty.
     $context = context_course::instance($course->id);
     $context->mark_dirty();
 }
开发者ID:evltuma,项目名称:moodle,代码行数:72,代码来源:course.php

示例15: raise_memory_limit

 raise_memory_limit(MEMORY_EXTRA);
 // Are we creating a new context (that means a new course tool)?
 if ($service == 'create_context') {
     $custom_context_template = $context->info['custom_context_template'];
     if (!($tplcourse = $DB->get_record('course', array('idnumber' => $custom_context_template), '*', IGNORE_MULTIPLE))) {
         print_error('invalidtplcourse', 'local_ltiprovider');
     }
     require_once "{$CFG->dirroot}/course/lib.php";
     $newcourse = new stdClass();
     $newcourse->fullname = local_ltiprovider_get_new_course_info('fullname', $context);
     $newcourse->shortname = local_ltiprovider_get_new_course_info('shortname', $context);
     $newcourse->idnumber = local_ltiprovider_get_new_course_info('idnumber', $context);
     $categories = $DB->get_records('course_categories', null, '', 'id', 0, 1);
     $category = array_shift($categories);
     $newcourse->category = $category->id;
     $course = create_course($newcourse);
     $coursecontext = context_course::instance($course->id);
     // Create the tool that provide the full course.
     $tool = local_ltiprovider_create_tool($course->id, $coursecontext->id, $context);
     $username = local_ltiprovider_create_username($context->info['oauth_consumer_key'], $context->info['user_id']);
     $userrestoringid = $DB->get_field('user', 'id', array('username' => $username));
     // Duplicate course + users.
     $course = local_ltiprovider_duplicate_course($tplcourse->id, $course, 1, $options = array(array('name' => 'users', 'value' => 1)), $userrestoringid, $context);
     echo json_encode($course);
 } else {
     if ($service == 'duplicate_resource') {
         $idnumber = $context->info['custom_resource_link_copy_id'];
         $resource_link_id = $context->info['resource_link_id'];
         if (!$tool) {
             print_error('missingrequiredtool', 'local_ltiprovider');
         }
开发者ID:OctaveBabel,项目名称:moodle-itop,代码行数:31,代码来源:services.php


注:本文中的create_course函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。