本文整理汇总了PHP中update_course函数的典型用法代码示例。如果您正苦于以下问题:PHP update_course函数的具体用法?PHP update_course怎么用?PHP update_course使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了update_course函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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: test_update_course_numsections
public function test_update_course_numsections()
{
global $DB;
$this->resetAfterTest(true);
$generator = $this->getDataGenerator();
$course = $generator->create_course(array('numsections' => 10, 'format' => 'weeks'), array('createsections' => true));
$generator->create_module('assign', array('course' => $course, 'section' => 7));
$this->setAdminUser();
$this->assertEquals(11, $DB->count_records('course_sections', array('course' => $course->id)));
// Change the numsections to 8, last two sections did not have any activities, they should be deleted.
update_course((object) array('id' => $course->id, 'numsections' => 8));
$this->assertEquals(9, $DB->count_records('course_sections', array('course' => $course->id)));
$this->assertEquals(9, count(get_fast_modinfo($course)->get_section_info_all()));
// Change the numsections to 5, section 8 should be deleted but section 7 should remain as it has activities.
update_course((object) array('id' => $course->id, 'numsections' => 6));
$this->assertEquals(8, $DB->count_records('course_sections', array('course' => $course->id)));
$this->assertEquals(8, count(get_fast_modinfo($course)->get_section_info_all()));
$this->assertEquals(6, course_get_format($course)->get_course()->numsections);
}
开发者ID:evltuma,项目名称:moodle,代码行数:19,代码来源:format_weeks_test.php
示例3: uninstall_plugin
//.........这里部分代码省略.........
if (file_exists($CFG->dirroot . '/mod/' . $module->name . '/lib.php')) {
require_once $CFG->dirroot . '/mod/' . $module->name . '/lib.php';
$uninstallfunction = $module->name . '_uninstall';
if (function_exists($uninstallfunction)) {
debugging("{$uninstallfunction}() has been deprecated. Use the plugin's db/uninstall.php instead", DEBUG_DEVELOPER);
if (!$uninstallfunction()) {
echo $OUTPUT->notification('Encountered a problem running uninstall function for ' . $module->name . '!');
}
}
}
} else {
if ($type === 'enrol') {
// NOTE: this is a bit brute force way - it will not trigger events and hooks properly
// nuke all role assignments
role_unassign_all(array('component' => $component));
// purge participants
$DB->delete_records_select('user_enrolments', "enrolid IN (SELECT id FROM {enrol} WHERE enrol = ?)", array($name));
// purge enrol instances
$DB->delete_records('enrol', array('enrol' => $name));
// tweak enrol settings
if (!empty($CFG->enrol_plugins_enabled)) {
$enabledenrols = explode(',', $CFG->enrol_plugins_enabled);
$enabledenrols = array_unique($enabledenrols);
$enabledenrols = array_flip($enabledenrols);
unset($enabledenrols[$name]);
$enabledenrols = array_flip($enabledenrols);
if (is_array($enabledenrols)) {
set_config('enrol_plugins_enabled', implode(',', $enabledenrols));
}
}
} else {
if ($type === 'block') {
if ($block = $DB->get_record('block', array('name' => $name))) {
// Inform block it's about to be deleted
if (file_exists("{$CFG->dirroot}/blocks/{$block->name}/block_{$block->name}.php")) {
$blockobject = block_instance($block->name);
if ($blockobject) {
$blockobject->before_delete();
//only if we can create instance, block might have been already removed
}
}
// First delete instances and related contexts
$instances = $DB->get_records('block_instances', array('blockname' => $block->name));
foreach ($instances as $instance) {
blocks_delete_instance($instance);
}
// Delete block
$DB->delete_records('block', array('id' => $block->id));
}
} else {
if ($type === 'format') {
if (($defaultformat = get_config('moodlecourse', 'format')) && $defaultformat !== $name) {
$courses = $DB->get_records('course', array('format' => $name), 'id');
$data = (object) array('id' => null, 'format' => $defaultformat);
foreach ($courses as $record) {
$data->id = $record->id;
update_course($data);
}
}
$DB->delete_records('course_format_options', array('format' => $name));
}
}
}
}
// perform clean-up task common for all the plugin/subplugin types
//delete the web service functions and pre-built services
require_once $CFG->dirroot . '/lib/externallib.php';
external_delete_descriptions($component);
// delete calendar events
$DB->delete_records('event', array('modulename' => $pluginname));
// delete all the logs
$DB->delete_records('log', array('module' => $pluginname));
// delete log_display information
$DB->delete_records('log_display', array('component' => $component));
// delete the module configuration records
unset_all_config_for_plugin($pluginname);
// delete message provider
message_provider_uninstall($component);
// delete message processor
if ($type === 'message') {
message_processor_uninstall($name);
}
// delete the plugin tables
$xmldbfilepath = $plugindirectory . '/db/install.xml';
drop_plugin_tables($component, $xmldbfilepath, false);
if ($type === 'mod' or $type === 'block') {
// non-frankenstyle table prefixes
drop_plugin_tables($name, $xmldbfilepath, false);
}
// delete the capabilities that were defined by this module
capabilities_cleanup($component);
// remove event handlers and dequeue pending events
events_uninstall($component);
// Delete all remaining files in the filepool owned by the component.
$fs = get_file_storage();
$fs->delete_component_files($component);
// Finally purge all caches.
purge_all_caches();
echo $OUTPUT->notification(get_string('success'), 'notifysuccess');
}
开发者ID:masaterutakeno,项目名称:MoodleMobile,代码行数:101,代码来源:adminlib.php
示例4: update_course
<?php
require_once $_SERVER['DOCUMENT_ROOT'] . '/reou/controllers/courses_controller.php';
// We are going to update or edit course
update_course($db, $_POST);
# Or #
list($course_details, $course_schedules, $course_categories, $instructors) = course_edit($db);
$weekdays = array("Sunday", "Monday", "Tuesday", "Wedesday", "Thursday", "Friday", "Saturday");
require_once $_SERVER['DOCUMENT_ROOT'] . '/reou/views/layouts/header.php';
// Load course_schedule result to be used in javascript variable.
?>
<script>
var course_schedules = <?php
echo json_encode($course_schedules);
?>
;
console.log(course_schedules);
console.log("variable - course_schedules");
</script>
<!-- Courses. Thisgs we would liek to update -->
<!--
- The Goal today is to be able to create a course then create a schedule for that course.
开发者ID:ZeroG001,项目名称:reou,代码行数:31,代码来源:course_edit.php
示例5: course_change_visibility
/**
* Changes the visibility of a course.
*
* @param int $courseid The course to change.
* @param bool $show True to make it visible, false otherwise.
* @return bool
*/
function course_change_visibility($courseid, $show = true)
{
$course = new stdClass();
$course->id = $courseid;
$course->visible = $show ? '1' : '0';
$course->visibleold = $course->visible;
update_course($course);
return true;
}
开发者ID:EmmanuelYupit,项目名称:educursos,代码行数:16,代码来源:lib.php
示例6: test_course_updated_event
/**
* Test that triggering a course_updated event works as expected.
*/
public function test_course_updated_event()
{
global $DB;
$this->resetAfterTest();
// Create a course.
$course = $this->getDataGenerator()->create_course();
// Create a category we are going to move this course to.
$category = $this->getDataGenerator()->create_category();
// Create a hidden category we are going to move this course to.
$categoryhidden = $this->getDataGenerator()->create_category(array('visible' => 0));
// Update course and catch course_updated event.
$sink = $this->redirectEvents();
update_course($course);
$events = $sink->get_events();
$sink->close();
// Get updated course information from the DB.
$updatedcourse = $DB->get_record('course', array('id' => $course->id), '*', MUST_EXIST);
// Validate event.
$event = array_shift($events);
$this->assertInstanceOf('\\core\\event\\course_updated', $event);
$this->assertEquals('course', $event->objecttable);
$this->assertEquals($updatedcourse->id, $event->objectid);
$this->assertEquals(context_course::instance($course->id), $event->get_context());
$url = new moodle_url('/course/edit.php', array('id' => $event->objectid));
$this->assertEquals($url, $event->get_url());
$this->assertEquals($updatedcourse, $event->get_record_snapshot('course', $event->objectid));
$this->assertEquals('course_updated', $event->get_legacy_eventname());
$this->assertEventLegacyData($updatedcourse, $event);
$expectedlog = array($updatedcourse->id, 'course', 'update', 'edit.php?id=' . $course->id, $course->id);
$this->assertEventLegacyLogData($expectedlog, $event);
// Move course and catch course_updated event.
$sink = $this->redirectEvents();
move_courses(array($course->id), $category->id);
$events = $sink->get_events();
$sink->close();
// Return the moved course information from the DB.
$movedcourse = $DB->get_record('course', array('id' => $course->id), '*', MUST_EXIST);
// Validate event.
$event = array_shift($events);
$this->assertInstanceOf('\\core\\event\\course_updated', $event);
$this->assertEquals('course', $event->objecttable);
$this->assertEquals($movedcourse->id, $event->objectid);
$this->assertEquals(context_course::instance($course->id), $event->get_context());
$this->assertEquals($movedcourse, $event->get_record_snapshot('course', $movedcourse->id));
$this->assertEquals('course_updated', $event->get_legacy_eventname());
$this->assertEventLegacyData($movedcourse, $event);
$expectedlog = array($movedcourse->id, 'course', 'move', 'edit.php?id=' . $movedcourse->id, $movedcourse->id);
$this->assertEventLegacyLogData($expectedlog, $event);
// Move course to hidden category and catch course_updated event.
$sink = $this->redirectEvents();
move_courses(array($course->id), $categoryhidden->id);
$events = $sink->get_events();
$sink->close();
// Return the moved course information from the DB.
$movedcoursehidden = $DB->get_record('course', array('id' => $course->id), '*', MUST_EXIST);
// Validate event.
$event = array_shift($events);
$this->assertInstanceOf('\\core\\event\\course_updated', $event);
$this->assertEquals('course', $event->objecttable);
$this->assertEquals($movedcoursehidden->id, $event->objectid);
$this->assertEquals(context_course::instance($course->id), $event->get_context());
$this->assertEquals($movedcoursehidden, $event->get_record_snapshot('course', $movedcoursehidden->id));
$this->assertEquals('course_updated', $event->get_legacy_eventname());
$this->assertEventLegacyData($movedcoursehidden, $event);
$expectedlog = array($movedcoursehidden->id, 'course', 'move', 'edit.php?id=' . $movedcoursehidden->id, $movedcoursehidden->id);
$this->assertEventLegacyLogData($expectedlog, $event);
$this->assertEventContextNotUsed($event);
}
开发者ID:uniedpa,项目名称:moodle,代码行数:71,代码来源:courselib_test.php
示例7: role_assign
// assign default role to creator if not already having permission to manage course assignments
if (!has_capability('moodle/course:view', $context) or !has_capability('moodle/role:assign', $context)) {
role_assign($CFG->creatornewroleid, $USER->id, 0, $context->id);
}
// ensure we can use the course right after creating it
// this means trigger a reload of accessinfo...
mark_context_dirty($context->path);
if ($data->metacourse and has_capability('moodle/course:managemetacourse', $context)) {
// Redirect users with metacourse capability to student import
redirect($CFG->wwwroot . "/course/importstudents.php?id={$course->id}");
} else {
// Redirect to roles assignment
redirect($CFG->wwwroot . "/{$CFG->admin}/roles/assign.php?contextid={$context->id}");
}
} else {
if (!update_course($data)) {
print_error('coursenotupdated');
}
redirect($CFG->wwwroot . "/course/view.php?id={$course->id}");
}
}
}
/// Print the form
$site = get_site();
$streditcoursesettings = get_string("editcoursesettings");
$straddnewcourse = get_string("addnewcourse");
$stradministration = get_string("administration");
$strcategories = get_string("categories");
$navlinks = array();
if (!empty($course)) {
$navlinks[] = array('name' => $streditcoursesettings, 'link' => null, 'type' => 'misc');
开发者ID:nadavkav,项目名称:MoodleTAO,代码行数:31,代码来源:edit.php
示例8: enrol_get_instances
}
if (!is_enrolled($context)) {
// Redirect to manual enrolment page if possible
$instances = enrol_get_instances($course->id, true);
foreach($instances as $instance) {
if ($plugin = enrol_get_plugin($instance->enrol)) {
if ($plugin->get_manual_enrol_link($instance)) {
// we know that the ajax enrol UI will have an option to enrol
redirect(new moodle_url('/enrol/users.php', array('id'=>$course->id)));
}
}
}
}
} else {
// Save any changes to the files used in the editor
update_course($data, $editoroptions);
}
rebuild_course_cache($course->id);
// Redirect user to newly created/updated course.
redirect(new moodle_url('/course/view.php', array('id' => $course->id)));
}
// Print the form
$site = get_site();
$streditcoursesettings = get_string("editcoursesettings");
$straddnewcourse = get_string("addnewcourse");
$stradministration = get_string("administration");
开发者ID:ncsu-delta,项目名称:moodle,代码行数:31,代码来源:edit.php
示例9: 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
示例10: test_update_course
public function test_update_course()
{
global $DB;
$this->resetAfterTest();
$defaultcategory = $DB->get_field_select('course_categories', "MIN(id)", "parent=0");
$course = new stdClass();
$course->fullname = 'Apu loves Unit Təsts';
$course->shortname = 'test1';
$course->idnumber = '1';
$course->summary = 'Awesome!';
$course->summaryformat = FORMAT_PLAIN;
$course->format = 'topics';
$course->newsitems = 0;
$course->numsections = 5;
$course->category = $defaultcategory;
$created = create_course($course);
// Ensure the checks only work on idnumber/shortname that are not already ours.
update_course($created);
$course->shortname = 'test2';
$course->idnumber = '2';
$created2 = create_course($course);
// Test duplicate idnumber.
$created2->idnumber = '1';
try {
update_course($created2);
$this->fail('Expected exception when trying to update a course with duplicate idnumber');
} catch (moodle_exception $e) {
$this->assertEquals(get_string('idnumbertaken', 'error'), $e->getMessage());
}
// Test duplicate shortname.
$created2->idnumber = '2';
$created2->shortname = 'test1';
try {
update_course($created2);
$this->fail('Expected exception when trying to update a course with a duplicate shortname');
} catch (moodle_exception $e) {
$this->assertEquals(get_string('shortnametaken', 'error', $created2->shortname), $e->getMessage());
}
}
开发者ID:masaterutakeno,项目名称:MoodleMobile,代码行数:39,代码来源:courselib_test.php
示例11: array
if ($query->is_empty()) {
$rollback = true;
return array(SERVER_ERROR, "{\"success\":false}");
}
return array(OKAY, json_encode($query->get_row_assoc()));
});
http_response_code($code);
return $json;
}
header('Content-Type: application/json');
if (!abet_is_admin_authenticated()) {
page_fail(UNAUTHORIZED);
}
if ($_SERVER['REQUEST_METHOD'] == 'GET') {
$obj = new stdClass();
$obj->courses = get_courses();
$obj->profiles = get_profiles();
echo json_encode($obj);
} else {
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
if (!array_key_exists('id', $_POST)) {
// create new course
echo create_course(isset($_POST['title']) ? $_POST['title'] : null, isset($_POST['course_number']) ? $_POST['course_number'] : null, isset($_POST['coordinator']) ? $_POST['coordinator'] : null, isset($_POST['instructor']) ? $_POST['instructor'] : null, isset($_POST['description']) ? $_POST['description'] : null, isset($_POST['textbook']) ? $_POST['textbook'] : null, isset($_POST['credit_hours']) ? $_POST['credit_hours'] : null);
} else {
// edit existing course
echo update_course($_POST['id'], isset($_POST['title']) ? $_POST['title'] : null, isset($_POST['course_number']) ? $_POST['course_number'] : null, isset($_POST['coordinator']) ? $_POST['coordinator'] : null, isset($_POST['instructor']) ? $_POST['instructor'] : null, isset($_POST['description']) ? $_POST['description'] : null, isset($_POST['textbook']) ? $_POST['textbook'] : null, isset($_POST['credit_hours']) ? $_POST['credit_hours'] : null);
}
} else {
page_fail(BAD_REQUEST);
}
}
开发者ID:RogerGee,项目名称:abet1,代码行数:31,代码来源:course.php
示例12: update_courses
/**
* Update some courses information
* @global object $DB
* @param array|struct $params - need to be define as struct for XMLRPC
* @subparam integer $params:course->id
* @subparam string $params:course->idnumber
* @subparam string $params:course->shortname
* @subparam integer $params:course->category
* @subparam string $params:course->fullname
* @subparam string $params:course->summary
* @subparam string $params:course->format
* @subparam integer $params:course->startdate
* @subparam integer $params:course->sortorder
* @subparam integer $params:course->showgrades
* @subparam string $params:course->modinfo
* @subparam string $params:course->newsitems
* @subparam string $params:course->guest
* @subparam integer $params:course->metacourse
* @subparam string $params:course->password
* @subparam integer $params:course->enrolperiod
* @subparam integer $params:course->defaultrole
* @subparam integer $params:course->enrollable
* @subparam integer $params:course->numsections
* @subparam integer $params:course->expirynotify
* @subparam integer $params:course->notifystudents
* @subparam integer $params:course->expirythreshold
* @subparam integer $params:course->marker
* @subparam integer $params:course->maxbytes
* @subparam integer $params:course->showreports
* @subparam integer $params:course->visible
* @subparam integer $params:course->hiddensections
* @subparam integer $params:course->groupmode
* @subparam integer $params:course->groupmodeforce
* @subparam integer $params:course->defaultgroupingid
* @subparam string $params:course->lang
* @subparam string $params:course->theme
* @subparam string $params:course->cost
* @subparam string $params:course->currency
* @subparam integer $params:course->timecreated
* @subparam integer $params:course->timemodified
* @subparam integer $params:course->requested
* @subparam integer $params:course->restrictmodules
* @subparam integer $params:course->enrolstartdate
* @subparam integer $params:course->enrolenddate
* @subparam string $params:course->enrol
* @subparam integer $params:course->enablecompletion
* @return boolean result true if success
*/
static function update_courses($params)
{
global $DB, $USER;
if (has_capability('moodle/course:update', get_context_instance(CONTEXT_SYSTEM))) {
$courses = array();
$result = true;
foreach ($params as $courseparams) {
$course = new stdClass();
if (array_key_exists('idnumber', $courseparams)) {
$course->idnumber = clean_param($courseparams['idnumber'], PARAM_ALPHANUM);
}
if (array_key_exists('shortname', $courseparams)) {
$course->shortname = clean_param($courseparams['shortname'], PARAM_ALPHANUMEXT);
}
if (array_key_exists('category', $courseparams)) {
$course->category = clean_param($courseparams['category'], PARAM_INT);
}
if (array_key_exists('fullname', $courseparams)) {
$course->fullname = clean_param($courseparams['fullname'], PARAM_TEXT);
}
if (array_key_exists('summary', $courseparams)) {
$course->summary = clean_param($courseparams['summary'], PARAM_TEXT);
}
if (array_key_exists('format', $courseparams)) {
$course->format = clean_param($courseparams['format'], PARAM_ALPHANUMEXT);
}
if (array_key_exists('startdate', $courseparams)) {
$course->startdate = clean_param($courseparams['startdate'], PARAM_INT);
}
if (array_key_exists('sortorder', $courseparams)) {
$course->sortorder = clean_param($courseparams['sortorder'], PARAM_INT);
}
if (array_key_exists('showgrades', $courseparams)) {
$course->showgrades = clean_param($courseparams['showgrades'], PARAM_INT);
}
if (array_key_exists('modinfo', $courseparams)) {
$course->modinfo = clean_param($courseparams['modinfo'], PARAM_ALPHANUMEXT);
}
if (array_key_exists('newsitems', $courseparams)) {
$course->newsitems = clean_param($courseparams['newsitems'], PARAM_ALPHANUMEXT);
}
if (array_key_exists('guest', $courseparams)) {
$course->guest = clean_param($courseparams['guest'], PARAM_ALPHANUMEXT);
}
if (array_key_exists('metacourse', $courseparams)) {
$course->metacourse = clean_param($courseparams['metacourse'], PARAM_INT);
}
if (array_key_exists('password', $courseparams)) {
$course->password = clean_param($courseparams['password'], PARAM_ALPHANUMEXT);
}
if (array_key_exists('enrolperiod', $courseparams)) {
$course->enrolperiod = clean_param($courseparams['enrolperiod'], PARAM_INT);
//.........这里部分代码省略.........
开发者ID:nicolasconnault,项目名称:moodle2.0,代码行数:101,代码来源:external.php
示例13: update_course
public static function update_course($course)
{
global $CFG, $DB;
// Valida os parametros.
$params = self::validate_parameters(self::update_course_parameters(), array('course' => $course));
// Inlcui a biblioteca de cursos 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);
// Se nao existir curso mapeado para a turma dispara uma excessao.
if ($courseid) {
$course->id = $courseid;
} else {
throw new Exception("Nenhum curso mapeado com a turma com trm_id: " . $course->trm_id);
}
// Cria o curso usando a biblioteca do proprio moodle.
update_course($course);
// Persiste as operacoes em caso de sucesso.
$transaction->allow_commit();
// Prepara o array de retorno.
$returndata['id'] = $courseid;
$returndata['status'] = 'success';
$returndata['message'] = "Curso atualizado com sucesso";
return $returndata;
}
开发者ID:uemanet,项目名称:moodle-local_wsmiidle,代码行数:29,代码来源:course.php
示例14: time
$data->startdate = time();
$data->marker = 0;
$data->maxbytes = 0;
$data->legacyfiles = 0;
$data->showreports = 0;
$data->visible = 1;
$data->visibleold = 1;
$data->groupmode = 0;
$data->groupmodeforce = 0;
$data->defaultgroupingid = 0;
$data->lang = ' ';
$data->theme = ' ';
$data->timecreated = time();
$data->timemodified = time();
$data->requested = 0;
$data->enablecompletion = 1;
$data->completionnotify = 0;
$data->coursetype = 0;
$b = create_course($data);
update_course($b);
//$b=$DB->insert_record('course', $data);
$context = context_course::instance($b->id, MUST_EXIST);
rebuild_course_cache($b->id);
if ($b) {
$count = $DB->get_record('course_categories', array('id' => $data->category));
$count->coursecount = ($count->coursecount + 1);
$DB->update_record('course_categories', $count);
}
echo '<input type="hidden" value="' . $b->id . '" name="newonlinecourseid1">';
?>
开发者ID:anilch,项目名称:Personel,代码行数:30,代码来源:insertmoodlecourse.php
示例15: test_groups_allgroups_course_menu
/**
* Tests for groups_allgroups_course_menu() .
*/
public function test_groups_allgroups_course_menu()
{
global $SESSION;
$this->resetAfterTest();
// Generate data.
$course = $this->getDataGenerator()->create_course();
$record = new stdClass();
$record->courseid = $course->id;
$group1 = $this->getDataGenerator()->create_group($record);
$group2 = $this->getDataGenerator()->create_group($record);
$user = $this->getDataGenerator()->create_user();
$this->getDataGenerator()->enrol_user($user->id, $course->id);
$this->setUser($user);
$html = groups_allgroups_course_menu($course, 'someurl.php');
// Since user is not a part of this group and doesn't have accessallgroups permission,
// the html should be empty.
$this->assertEmpty($html);
groups_add_member($group1->id, $user);
// Now user can access one of the group. We can't assert an exact match here because of random ids generated by yui. So do
// partial match to see if all groups are listed or not.
$html = groups_allgroups_course_menu($course, 'someurl.php');
$this->assertContains(format_string($group1->name), $html);
$this->assertNotContains(format_string($group2->name), $html);
$this->setAdminUser();
// Now user can access everything.
$html = groups_allgroups_course_menu($course, 'someurl.php');
$this->assertContains(format_string($group1->name), $html);
$this->assertContains(format_string($group2->name), $html);
// Make sure separate groups mode, doesn't change anything.
$course->groupmode = SEPARATEGROUPS;
update_course($course);
$html = groups_allgroups_course_menu($course, 'someurl.php');
$this->assertContains(format_string($group1->name), $html);
$this->assertContains(format_string($group2->name), $html);
// Make sure Visible groups mode, doesn't change anything.
$course->groupmode = VISIBLEGROUPS;
update_course($course);
$html = groups_allgroups_course_menu($course, 'someurl.php');
$this->assertContains(format_string($group1->name), $html);
$this->assertContains(format_string($group2->name), $html);
// Let us test activegroup changes now.
$this->setUser($user);
$SESSION->activegroup[$course->id][VISIBLEGROUPS][$course->defaultgroupingid] = 5;
groups_allgroups_course_menu($course, 'someurl.php', false);
// Do not update session.
$this->assertSame(5, $SESSION->activegroup[$course->id][VISIBLEGROUPS][$course->defaultgroupingid]);
groups_allgroups_course_menu($course, 'someurl.php', true, $group1->id);
// Update session.
$this->assertSame($group1->id, $SESSION->activegroup[$course->id][VISIBLEGROUPS][$course->defaultgroupingid]);
// Try to update session with an invalid groupid. It should not accept the invalid id.
groups_allgroups_course_menu($course, 'someurl.php', true, 256);
$this->assertEquals($group1->id, $SESSION->activegroup[$course->id][VISIBLEGROUPS][$course->defaultgroupingid]);
}
开发者ID:janaece,项目名称:globalclassroom4_clean,代码行数:56,代码来源:grouplib_test.php
示例16: test_update_course_frontpage_category
/**
* Test test_update_course_frontpage_category.
*/
public function test_update_course_frontpage_category()
{
// Fetch front page course.
$course = get_course(SITEID);
// Test update information on front page course.
$course->category = 99;
$this->expectException('moodle_exception');
$this->expectExceptionMessage(get_string('invalidcourse', 'error'));
update_course($course);
}
开发者ID:EsdrasCaleb,项目名称:moodle,代码行数:13,代码来源:courselib_test.php
示例17: test_groups_user_groups_visible
/**
* Tests for groups_user_groups_visible.
*/
public function test_groups_user_groups_visible()
{
global $CFG, $DB;
$generator = $this->getDataGenerator();
$this->resetAfterTest();
$this->setAdminUser();
// Create a course category, course and groups.
$cat = $generator->create_category(array('parent' => 0));
$course = $generator->create_course(array('category' => $cat->id));
$coursecontext = context_course::instance($course->id);
$group1 = $generator->create_group(array('courseid' => $course->id, 'name' => 'Group 1'));
$group2 = $generator->create_group(array('courseid' => $course->id, 'name' => 'Group 2'));
$group3 = $generator->create_group(array('courseid' => $course->id, 'name' => 'Group 3'));
$group4 = $generator->create_group(array('courseid' => $course->id, 'name' => 'Group 4'));
// Create cm.
$assign = $generator->create_module("assign", array('course' => $course->id));
$cm = get_coursemodule_from_instance("assign", $assign->id);
// Create users.
$user1 = $generator->create_user();
// Normal user.
$user2 = $generator->create_user();
// Normal user.
$user3 = $generator->create_user();
// Teacher, access all groups.
$user4 = $generator->create_user();
// Normal user.
// Enrol users into the course.
$generator->enrol_user($user1->id, $course->id);
$generator->enrol_user($user2->id, $course->id);
$generator->enrol_user($user4->id, $course->id);
// Assign groups.
// User1 and User4 share groups.
groups_add_member($group1, $user1);
groups_add_member($group2, $user2);
groups_add_member($group1, $user4);
// Give capability at course level to the user to access all groups.
$role = $DB->get_field("role", "id", array("shortname" => "manager"));
$generator->enrol_user($user3->id, $course->id, $role);
// Make sure the user has the capability.
assign_capability('moodle/site:accessallgroups', CAP_ALLOW, $role, $coursecontext->id);
// Normal users in different groups.
$this->setUser($user1);
// No groups , not forced.
$result = groups_user_groups_visible($course, $user2->id);
$this->assertTrue($result);
$result = groups_user_groups_visible($course, $user2->id);
$this->assertTrue($result);
// Cm with no groups.
$cm->groupmode = SEPARATEGROUPS;
$result = groups_user_groups_visible($course, $user2->id, $cm);
$this->assertFalse($result);
// Cm with separate groups.
$cm->groupmode = VISIBLEGROUPS;
$result = groups_user_groups_visible($course, $user2->id, $cm);
$this->assertTrue($result);
// Cm with visible groups.
// No groups, forced.
$course->groupmode = NOGROUPS;
$course->groupmodeforce = true;
update_course($course);
$result = groups_user_groups_visible($course, $user2->id);
$this->assertTrue($result);
$result = groups_user_groups_visible($course, $user2->id);
$this->assertTrue($result);
// Cm with no groups.
$cm->groupmode = SEPARATEGROUPS;
$result = groups_user_groups_visible($course, $user2->id, $cm);
$this->assertTrue($result);
// Cm with separate groups.
$cm->groupmode = SEPARATEGROUPS;
$result = groups_user_groups_visible($course, $user2->id);
$this->assertTrue($result);
// Cm with visible groups.
// Visible groups, forced.
$course->groupmode = VISIBLEGROUPS;
$course->groupmodeforce = true;
update_course($course);
$result = groups_user_groups_visible($course, $user2->id);
$this->assertTrue($result);
$cm->groupmode = NOGROUPS;
$result = groups_user_groups_visible($course, $user2->id, $cm);
$this->assertTrue($result);
// Cm with no groups.
$cm->groupmode = SEPARATEGROUPS;
$result = groups_user_groups_visible($course, $user2->id, $cm);
$this->assertTrue($result);
// Cm with separate groups.
$cm->groupmode = VISIBLEGROUPS;
$result = groups_user_groups_visible($course, $user2->id, $cm);
$this->assertTrue($result);
// Cm with visible groups.
// Visible groups, not forced.
$course->groupmode = VISIBLEGROUPS;
$course->groupmodeforce = false;
update_course($course);
$result = groups_user_groups_visible($course, $user2->id);
$this->assertTrue($result);
//.........这里部分代码省略.........
开发者ID:evltuma,项目名称:moodle,代码行数:101,代码来源:grouplib_test.php
示例18: test_delete
/**
* Tests deleting discussion and permanent delete
* Checks completion
*/
public function test_delete()
{
global $DB, $USER, $SITE, $CFG;
require_once $CFG->dirroot . '/mod/forumng/mod_forumng_cron.php';
$CFG->enablecompletion = true;
$this->resetAfterTest(true);
$this->setAdminUser();
$course = $this->get_new_course();
$course->enablecompletion = 1;
update_course($course);
$forum = $this->get_new_forumng($course->id, array('removeafter' => 1, 'r
|
请发表评论