本文整理汇总了PHP中core_tag_tag类的典型用法代码示例。如果您正苦于以下问题:PHP core_tag_tag类的具体用法?PHP core_tag_tag怎么用?PHP core_tag_tag使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了core_tag_tag类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: test_create_content
public function test_create_content()
{
global $DB;
$this->resetAfterTest();
$this->setAdminUser();
$course = $this->getDataGenerator()->create_course();
$wiki = $this->getDataGenerator()->create_module('wiki', array('course' => $course));
$wikigenerator = $this->getDataGenerator()->get_plugin_generator('mod_wiki');
$page1 = $wikigenerator->create_first_page($wiki);
$page2 = $wikigenerator->create_content($wiki);
$page3 = $wikigenerator->create_content($wiki, array('title' => 'Custom title', 'tags' => array('Cats', 'mice')));
unset($wiki->cmid);
$page4 = $wikigenerator->create_content($wiki, array('tags' => 'Cats, dogs'));
$subwikis = $DB->get_records('wiki_subwikis', array('wikiid' => $wiki->id), 'id');
$this->assertEquals(1, count($subwikis));
$subwikiid = key($subwikis);
$records = $DB->get_records('wiki_pages', array('subwikiid' => $subwikiid), 'id');
$this->assertEquals(4, count($records));
$this->assertEquals($page1->id, $records[$page1->id]->id);
$this->assertEquals($page2->id, $records[$page2->id]->id);
$this->assertEquals($page3->id, $records[$page3->id]->id);
$this->assertEquals('Custom title', $records[$page3->id]->title);
$this->assertEquals(array('Cats', 'mice'), array_values(core_tag_tag::get_item_tags_array('mod_wiki', 'wiki_pages', $page3->id)));
$this->assertEquals(array('Cats', 'dogs'), array_values(core_tag_tag::get_item_tags_array('mod_wiki', 'wiki_pages', $page4->id)));
}
开发者ID:evltuma,项目名称:moodle,代码行数:25,代码来源:generator_test.php
示例2: export_for_template
/**
* Export this data so it can be used as the context for a mustache template.
*
* @param renderer_base $output
* @return stdClass
*/
public function export_for_template(renderer_base $output)
{
global $CFG;
require_once $CFG->libdir . '/externallib.php';
$r = new stdClass();
$r->id = (int) $this->record->id;
$r->tagcollid = clean_param($this->record->tagcollid, PARAM_INT);
$r->rawname = clean_param($this->record->rawname, PARAM_TAG);
$r->name = clean_param($this->record->name, PARAM_TAG);
$format = clean_param($this->record->descriptionformat, PARAM_INT);
list($r->description, $r->descriptionformat) = external_format_text($this->record->description, $format, \context_system::instance()->id, 'core', 'tag', $r->id);
$r->flag = clean_param($this->record->flag, PARAM_INT);
if (isset($this->record->official)) {
$r->official = clean_param($this->record->official, PARAM_INT);
} else {
$r->official = $this->record->tagtype === 'official' ? 1 : 0;
}
$url = \core_tag_tag::make_url($r->tagcollid, $r->rawname);
$r->viewurl = $url->out(false);
$manageurl = new moodle_url('/tag/manage.php', array('sesskey' => sesskey(), 'tagid' => $this->record->id));
$url = new moodle_url($manageurl);
$url->param('action', 'changetype');
$url->param('tagtype', $r->official ? 'default' : 'official');
$r->changetypeurl = $url->out(false);
$url = new moodle_url($manageurl);
$url->param('action', $this->record->flag ? 'resetflag' : 'setflag');
$r->changeflagurl = $url->out(false);
return $r;
}
开发者ID:bewanyk,项目名称:moodle,代码行数:35,代码来源:tag.php
示例3: core_tag_inplace_editable
/**
* Implements callback inplace_editable() allowing to edit values in-place
*
* @param string $itemtype
* @param int $itemid
* @param mixed $newvalue
* @return \core\output\inplace_editable
*/
function core_tag_inplace_editable($itemtype, $itemid, $newvalue)
{
if ($itemtype === 'tagname') {
require_capability('moodle/tag:manage', context_system::instance());
$tag = core_tag_tag::get($itemid, '*', MUST_EXIST);
$tag->update(array('rawname' => $newvalue));
return new \core_tag\output\tagname($tag);
}
}
开发者ID:rushi963,项目名称:moodle,代码行数:17,代码来源:lib.php
示例4: validation
/**
* Custom form validation
*
* @param array $data
* @param array $files
* @return array
*/
public function validation($data, $files)
{
$errors = parent::validation($data, $files);
if (isset($data['rawname'])) {
$newname = core_text::strtolower($data['rawname']);
$tag = $this->_customdata['tag'];
if ($tag->name != $newname) {
// The name has changed, let's make sure it's not another existing tag.
if (core_tag_tag::get_by_name($tag->tagcollid, $newname)) {
// Something exists already, so flag an error.
$errors['rawname'] = get_string('namesalreadybeeingused', 'tag');
}
}
}
return $errors;
}
开发者ID:bewanyk,项目名称:moodle,代码行数:23,代码来源:edit_form.php
示例5: __construct
/**
* Constructor
*
* @param core_tag_tag|stdClass $tag
* @param string $component
* @param string $itemtype
* @param string $content
* @param bool $exclusivemode
* @param int $fromctx context id where the link was displayed, may be used by callbacks
* to display items in the same context first
* @param int $ctx context id where we need to search for items
* @param int $rec search items in sub contexts as well
* @param int $page
* @param bool $totalpages
*/
public function __construct($tag, $component, $itemtype, $content, $exclusivemode = false, $fromctx = 0, $ctx = 0, $rec = 1, $page = 0, $totalpages = 1)
{
$this->record = new stdClass();
$this->tag = $tag;
$tagareas = \core_tag_area::get_areas();
if (!isset($tagareas[$itemtype][$component])) {
throw new \coding_exception('Tag area for component ' . $component . ' and itemtype ' . $itemtype . ' is not defined');
}
$this->tagarea = $tagareas[$itemtype][$component];
$this->record->tagid = $tag->id;
$this->record->ta = $this->tagarea->id;
$this->record->itemtype = $itemtype;
$this->record->component = $component;
$a = (object) array('tagarea' => \core_tag_area::display_name($component, $itemtype), 'tag' => \core_tag_tag::make_display_name($tag));
if ($exclusivemode) {
$this->record->title = get_string('itemstaggedwith', 'tag', $a);
} else {
$this->record->title = (string) $a->tagarea;
}
$this->record->content = $content;
$this->record->nextpageurl = null;
$this->record->prevpageurl = null;
$this->record->exclusiveurl = null;
$url = core_tag_tag::make_url($tag->tagcollid, $tag->rawname, $exclusivemode, $fromctx, $ctx, $rec);
$urlparams = array('ta' => $this->tagarea->id);
if ($totalpages > $page + 1) {
$this->record->nextpageurl = new moodle_url($url, $urlparams + array('page' => $page + 1));
}
if ($page > 0) {
$this->record->prevpageurl = new moodle_url($url, $urlparams + array('page' => $page - 1));
}
if (!$exclusivemode && ($totalpages > 1 || $page)) {
$this->record->exclusiveurl = new moodle_url($url, $urlparams + array('excl' => 1));
}
$this->record->exclusivetext = get_string('exclusivemode', 'tag', $a);
$this->record->hascontent = $totalpages > 1 || $page || $content;
$this->record->anchor = $component . '_' . $itemtype;
}
开发者ID:evltuma,项目名称:moodle,代码行数:53,代码来源:tagindex.php
示例6: wiki_reset_userdata
/**
* Implements callback to reset course
*
* @param stdClass $data
* @return boolean|array
*/
function wiki_reset_userdata($data)
{
global $CFG, $DB;
require_once $CFG->dirroot . '/mod/wiki/pagelib.php';
require_once $CFG->dirroot . "/mod/wiki/locallib.php";
$componentstr = get_string('modulenameplural', 'wiki');
$status = array();
//get the wiki(s) in this course.
if (!($wikis = $DB->get_records('wiki', array('course' => $data->courseid)))) {
return false;
}
if (empty($data->reset_wiki_comments) && empty($data->reset_wiki_tags) && empty($data->reset_wiki_pages)) {
return $status;
}
foreach ($wikis as $wiki) {
if (!($cm = get_coursemodule_from_instance('wiki', $wiki->id, $data->courseid))) {
continue;
}
$context = context_module::instance($cm->id);
// Remove tags or all pages.
if (!empty($data->reset_wiki_pages) || !empty($data->reset_wiki_tags)) {
// Get subwiki information.
$subwikis = wiki_get_subwikis($wiki->id);
foreach ($subwikis as $subwiki) {
// Get existing pages.
if ($pages = wiki_get_page_list($subwiki->id)) {
// If the wiki page isn't selected then we are only removing tags.
if (empty($data->reset_wiki_pages)) {
// Go through each page and delete the tags.
foreach ($pages as $page) {
core_tag_tag::remove_all_item_tags('mod_wiki', 'wiki_pages', $page->id);
}
} else {
// Otherwise we are removing pages and tags.
wiki_delete_pages($context, $pages, $subwiki->id);
}
}
if (!empty($data->reset_wiki_pages)) {
// Delete any subwikis.
$DB->delete_records('wiki_subwikis', array('id' => $subwiki->id), IGNORE_MISSING);
// Delete any attached files.
$fs = get_file_storage();
$fs->delete_area_files($context->id, 'mod_wiki', 'attachments');
}
}
if (!empty($data->reset_wiki_pages)) {
$status[] = array('component' => $componentstr, 'item' => get_string('deleteallpages', 'wiki'), 'error' => false);
}
if (!empty($data->reset_wiki_tags)) {
$status[] = array('component' => $componentstr, 'item' => get_string('tagsdeleted', 'wiki'), 'error' => false);
}
}
// Remove all comments.
if (!empty($data->reset_wiki_comments) || !empty($data->reset_wiki_pages)) {
$DB->delete_records_select('comments', "contextid = ? AND commentarea='wiki_page'", array($context->id));
if (!empty($data->reset_wiki_comments)) {
$status[] = array('component' => $componentstr, 'item' => get_string('deleteallcomments'), 'error' => false);
}
}
}
return $status;
}
开发者ID:dg711,项目名称:moodle,代码行数:68,代码来源:lib.php
示例7: test_data_saved
public function test_data_saved()
{
global $DB;
$this->resetAfterTest(true);
// Create.
$mode = tool_uploadcourse_processor::MODE_CREATE_NEW;
$updatemode = tool_uploadcourse_processor::UPDATE_NOTHING;
$data = array('shortname' => 'c1', 'fullname' => 'Fullname', 'category' => '1', 'visible' => '0', 'startdate' => '8 June 1990', 'idnumber' => '123abc', 'summary' => 'Summary', 'format' => 'weeks', 'theme' => 'afterburner', 'lang' => 'en', 'newsitems' => '7', 'showgrades' => '0', 'showreports' => '1', 'legacyfiles' => '1', 'maxbytes' => '1234', 'groupmode' => '2', 'groupmodeforce' => '1', 'enablecompletion' => '1', 'tags' => 'Cat, Dog', 'role_teacher' => 'Knight', 'role_manager' => 'Jedi', 'enrolment_1' => 'guest', 'enrolment_2' => 'self', 'enrolment_2_roleid' => '1', 'enrolment_3' => 'manual', 'enrolment_3_disable' => '1');
$this->assertFalse($DB->record_exists('course', array('shortname' => 'c1')));
$co = new tool_uploadcourse_course($mode, $updatemode, $data);
$this->assertTrue($co->prepare());
$co->proceed();
$this->assertTrue($DB->record_exists('course', array('shortname' => 'c1')));
$course = $DB->get_record('course', array('shortname' => 'c1'));
$ctx = context_course::instance($course->id);
$this->assertEquals($data['fullname'], $course->fullname);
$this->assertEquals($data['category'], $course->category);
$this->assertEquals($data['visible'], $course->visible);
$this->assertEquals(mktime(0, 0, 0, 6, 8, 1990), $course->startdate);
$this->assertEquals($data['idnumber'], $course->idnumber);
$this->assertEquals($data['summary'], $course->summary);
$this->assertEquals($data['format'], $course->format);
$this->assertEquals($data['theme'], $course->theme);
$this->assertEquals($data['lang'], $course->lang);
$this->assertEquals($data['newsitems'], $course->newsitems);
$this->assertEquals($data['showgrades'], $course->showgrades);
$this->assertEquals($data['showreports'], $course->showreports);
$this->assertEquals($data['legacyfiles'], $course->legacyfiles);
$this->assertEquals($data['maxbytes'], $course->maxbytes);
$this->assertEquals($data['groupmode'], $course->groupmode);
$this->assertEquals($data['groupmodeforce'], $course->groupmodeforce);
$this->assertEquals($data['enablecompletion'], $course->enablecompletion);
$this->assertEquals($data['tags'], join(', ', core_tag_tag::get_item_tags_array('core', 'course', $course->id)));
// Roles.
$roleids = array();
$roles = get_all_roles();
foreach ($roles as $role) {
$roleids[$role->shortname] = $role->id;
}
$this->assertEquals('Knight', $DB->get_field_select('role_names', 'name', 'roleid = :roleid AND contextid = :ctxid', array('ctxid' => $ctx->id, 'roleid' => $roleids['teacher'])));
$this->assertEquals('Jedi', $DB->get_field_select('role_names', 'name', 'roleid = :roleid AND contextid = :ctxid', array('ctxid' => $ctx->id, 'roleid' => $roleids['manager'])));
// Enrolment methods.
$enroldata = array();
$instances = enrol_get_instances($course->id, false);
$this->assertCount(3, $instances);
foreach ($instances as $instance) {
$enroldata[$instance->enrol] = $instance;
}
$this->assertNotEmpty($enroldata['guest']);
$this->assertEquals(ENROL_INSTANCE_ENABLED, $enroldata['guest']->status);
$this->assertNotEmpty($enroldata['self']);
$this->assertEquals($data['enrolment_2_roleid'], $enroldata['self']->roleid);
$this->assertEquals(ENROL_INSTANCE_ENABLED, $enroldata['self']->status);
$this->assertNotEmpty($enroldata['manual']);
$this->assertEquals(ENROL_INSTANCE_DISABLED, $enroldata['manual']->status);
// Update existing course.
$cat = $this->getDataGenerator()->create_category();
$mode = tool_uploadcourse_processor::MODE_UPDATE_ONLY;
$updatemode = tool_uploadcourse_processor::UPDATE_ALL_WITH_DATA_ONLY;
$data = array('shortname' => 'c1', 'fullname' => 'Fullname 2', 'category' => $cat->id, 'visible' => '1', 'startdate' => '11 June 1984', 'idnumber' => 'changeidn', 'summary' => 'Summary 2', 'format' => 'topics', 'theme' => 'clean', 'lang' => '', 'newsitems' => '2', 'showgrades' => '1', 'showreports' => '0', 'legacyfiles' => '0', 'maxbytes' => '4321', 'groupmode' => '1', 'groupmodeforce' => '0', 'enablecompletion' => '0', 'role_teacher' => 'Teacher', 'role_manager' => 'Manager', 'enrolment_1' => 'guest', 'enrolment_1_disable' => '1', 'enrolment_2' => 'self', 'enrolment_2_roleid' => '2', 'enrolment_3' => 'manual', 'enrolment_3_delete' => '1');
$this->assertTrue($DB->record_exists('course', array('shortname' => 'c1')));
$co = new tool_uploadcourse_course($mode, $updatemode, $data);
$this->assertTrue($co->prepare());
$co->proceed();
$course = $DB->get_record('course', array('shortname' => 'c1'));
$ctx = context_course::instance($course->id);
$this->assertEquals($data['fullname'], $course->fullname);
$this->assertEquals($data['category'], $course->category);
$this->assertEquals($data['visible'], $course->visible);
$this->assertEquals(mktime(0, 0, 0, 6, 11, 1984), $course->startdate);
$this->assertEquals($data['idnumber'], $course->idnumber);
$this->assertEquals($data['summary'], $course->summary);
$this->assertEquals($data['format'], $course->format);
$this->assertEquals($data['theme'], $course->theme);
$this->assertEquals($data['lang'], $course->lang);
$this->assertEquals($data['newsitems'], $course->newsitems);
$this->assertEquals($data['showgrades'], $course->showgrades);
$this->assertEquals($data['showreports'], $course->showreports);
$this->assertEquals($data['legacyfiles'], $course->legacyfiles);
$this->assertEquals($data['maxbytes'], $course->maxbytes);
$this->assertEquals($data['groupmode'], $course->groupmode);
$this->assertEquals($data['groupmodeforce'], $course->groupmodeforce);
$this->assertEquals($data['enablecompletion'], $course->enablecompletion);
// Roles.
$roleids = array();
$roles = get_all_roles();
foreach ($roles as $role) {
$roleids[$role->shortname] = $role->id;
}
$this->assertEquals('Teacher', $DB->get_field_select('role_names', 'name', 'roleid = :roleid AND contextid = :ctxid', array('ctxid' => $ctx->id, 'roleid' => $roleids['teacher'])));
$this->assertEquals('Manager', $DB->get_field_select('role_names', 'name', 'roleid = :roleid AND contextid = :ctxid', array('ctxid' => $ctx->id, 'roleid' => $roleids['manager'])));
// Enrolment methods.
$enroldata = array();
$instances = enrol_get_instances($course->id, false);
$this->assertCount(2, $instances);
foreach ($instances as $instance) {
$enroldata[$instance->enrol] = $instance;
}
$this->assertNotEmpty($enroldata['guest']);
$this->assertEquals(ENROL_INSTANCE_DISABLED, $enroldata['guest']->status);
//.........这里部分代码省略.........
开发者ID:evltuma,项目名称:moodle,代码行数:101,代码来源:course_test.php
示例8: remove_course_contents
//.........这里部分代码省略.........
foreach ($cleanuplugintypes as $type) {
if (!empty($callbacks[$type])) {
foreach ($callbacks[$type] as $pluginfunction) {
debugging("Callback delete_course is deprecated. Function {$pluginfunction} should be converted " . 'to observer of event \\core\\event\\course_content_deleted', DEBUG_DEVELOPER);
$pluginfunction($course->id, $showfeedback);
}
if ($showfeedback) {
echo $OUTPUT->notification($strdeleted . get_string('type_' . $type . '_plural', 'plugin'), 'notifysuccess');
}
}
}
// Delete questions and question categories.
question_delete_course($course, $showfeedback);
if ($showfeedback) {
echo $OUTPUT->notification($strdeleted . get_string('questions', 'question'), 'notifysuccess');
}
// Make sure there are no subcontexts left - all valid blocks and modules should be already gone.
$childcontexts = $coursecontext->get_child_contexts();
// Returns all subcontexts since 2.2.
foreach ($childcontexts as $childcontext) {
$childcontext->delete();
}
unset($childcontexts);
// Remove all roles and enrolments by default.
if (empty($options['keep_roles_and_enrolments'])) {
// This hack is used in restore when deleting contents of existing course.
role_unassign_all(array('contextid' => $coursecontext->id, 'component' => ''), true);
enrol_course_delete($course);
if ($showfeedback) {
echo $OUTPUT->notification($strdeleted . get_string('type_enrol_plural', 'plugin'), 'notifysuccess');
}
}
// Delete any groups, removing members and grouping/course links first.
if (empty($options['keep_groups_and_groupings'])) {
groups_delete_groupings($course->id, $showfeedback);
groups_delete_groups($course->id, $showfeedback);
}
// Filters be gone!
filter_delete_all_for_context($coursecontext->id);
// Notes, you shall not pass!
note_delete_all($course->id);
// Die comments!
comment::delete_comments($coursecontext->id);
// Ratings are history too.
$delopt = new stdclass();
$delopt->contextid = $coursecontext->id;
$rm = new rating_manager();
$rm->delete_ratings($delopt);
// Delete course tags.
core_tag_tag::remove_all_item_tags('core', 'course', $course->id);
// Notify the competency subsystem.
\core_competency\api::hook_course_deleted($course);
// Delete calendar events.
$DB->delete_records('event', array('courseid' => $course->id));
$fs->delete_area_files($coursecontext->id, 'calendar');
// Delete all related records in other core tables that may have a courseid
// This array stores the tables that need to be cleared, as
// table_name => column_name that contains the course id.
$tablestoclear = array('backup_courses' => 'courseid', 'user_lastaccess' => 'courseid');
foreach ($tablestoclear as $table => $col) {
$DB->delete_records($table, array($col => $course->id));
}
// Delete all course backup files.
$fs->delete_area_files($coursecontext->id, 'backup');
// Cleanup course record - remove links to deleted stuff.
$oldcourse = new stdClass();
$oldcourse->id = $course->id;
$oldcourse->summary = '';
$oldcourse->cacherev = 0;
$oldcourse->legacyfiles = 0;
if (!empty($options['keep_groups_and_groupings'])) {
$oldcourse->defaultgroupingid = 0;
}
$DB->update_record('course', $oldcourse);
// Delete course sections.
$DB->delete_records('course_sections', array('course' => $course->id));
// Delete legacy, section and any other course files.
$fs->delete_area_files($coursecontext->id, 'course');
// Files from summary and section.
// Delete all remaining stuff linked to context such as files, comments, ratings, etc.
if (empty($options['keep_roles_and_enrolments']) and empty($options['keep_groups_and_groupings'])) {
// Easy, do not delete the context itself...
$coursecontext->delete_content();
} else {
// Hack alert!!!!
// We can not drop all context stuff because it would bork enrolments and roles,
// there might be also files used by enrol plugins...
}
// Delete legacy files - just in case some files are still left there after conversion to new file api,
// also some non-standard unsupported plugins may try to store something there.
fulldelete($CFG->dataroot . '/' . $course->id);
// Delete from cache to reduce the cache size especially makes sense in case of bulk course deletion.
$cachemodinfo = cache::make('core', 'coursemodinfo');
$cachemodinfo->delete($courseid);
// Trigger a course content deleted event.
$event = \core\event\course_content_deleted::create(array('objectid' => $course->id, 'context' => $coursecontext, 'other' => array('shortname' => $course->shortname, 'fullname' => $course->fullname, 'options' => $options)));
$event->add_record_snapshot('course', $course);
$event->trigger();
return true;
}
开发者ID:lucaboesch,项目名称:moodle,代码行数:101,代码来源:moodlelib.php
示例9: delete
/**
* Deletes this entry from the database. Access control checks must be done by calling code.
*
* @return void
*/
public function delete()
{
global $DB;
$this->delete_attachments();
$this->remove_associations();
// Get record to pass onto the event.
$record = $DB->get_record('post', array('id' => $this->id));
$DB->delete_records('post', array('id' => $this->id));
core_tag_tag::remove_all_item_tags('core', 'post', $this->id);
$event = \core\event\blog_entry_deleted::create(array('objectid' => $this->id, 'relateduserid' => $this->userid));
$event->add_record_snapshot("post", $record);
$event->set_blog_entry($this);
$event->trigger();
}
开发者ID:gabrielrosset,项目名称:moodle,代码行数:19,代码来源:locallib.php
示例10: update_course
/**
* Update a course.
*
* Please note this functions does not verify any access control,
* the calling code is responsible for all validation (usually it is the form definition).
*
* @param object $data - all the data needed for an entry in the 'course' table
* @param array $editoroptions course description editor options
* @return void
*/
function update_course($data, $editoroptions = NULL)
{
global $DB, $CFG;
$data->timemodified = time();
$oldcourse = course_get_format($data->id)->get_course();
$context = context_course::instance($oldcourse->id);
if ($editoroptions) {
$data = file_postupdate_standard_editor($data, 'summary', $editoroptions, $context, 'course', 'summary', 0);
}
if ($overviewfilesoptions = course_overviewfiles_options($data->id)) {
$data = file_postupdate_standard_filemanager($data, 'overviewfiles', $overviewfilesoptions, $context, 'course', 'overviewfiles', 0);
}
// Check we don't have a duplicate shortname.
if (!empty($data->shortname) && $oldcourse->shortname != $data->shortname) {
if ($DB->record_exists_sql('SELECT id from {course} WHERE shortname = ? AND id <> ?', array($data->shortname, $data->id))) {
throw new moodle_exception('shortnametaken', '', '', $data->shortname);
}
}
// Check we don't have a duplicate idnumber.
if (!empty($data->idnumber) && $oldcourse->idnumber != $data->idnumber) {
if ($DB->record_exists_sql('SELECT id from {course} WHERE idnumber = ? AND id <> ?', array($data->idnumber, $data->id))) {
throw new moodle_exception('courseidnumbertaken', '', '', $data->idnumber);
}
}
if (!isset($data->category) or empty($data->category)) {
// prevent nulls and 0 in category field
unset($data->category);
}
$changesincoursecat = $movecat = (isset($data->category) and $oldcourse->category != $data->category);
if (!isset($data->visible)) {
// data not from form, add missing visibility info
$data->visible = $oldcourse->visible;
}
if ($data->visible != $oldcourse->visible) {
// reset the visibleold flag when manually hiding/unhiding course
$data->visibleold = $data->visible;
$changesincoursecat = true;
} else {
if ($movecat) {
$newcategory = $DB->get_record('course_categories', array('id' => $data->category));
if (empty($newcategory->visible)) {
// make sure when moving into hidden category the course is hidden automatically
$data->visible = 0;
}
}
}
// Update with the new data
$DB->update_record('course', $data);
// make sure the modinfo cache is reset
rebuild_course_cache($data->id);
// update course format options with full course data
course_get_format($data->id)->update_course_format_options($data, $oldcourse);
$course = $DB->get_record('course', array('id' => $data->id));
if ($movecat) {
$newparent = context_coursecat::instance($course->category);
$context->update_moved($newparent);
}
$fixcoursesortorder = $movecat || isset($data->sortorder) && $oldcourse->sortorder != $data->sortorder;
if ($fixcoursesortorder) {
fix_course_sortorder();
}
// purge appropriate caches in case fix_course_sortorder() did not change anything
cache_helper::purge_by_event('changesincourse');
if ($changesincoursecat) {
cache_helper::purge_by_event('changesincoursecat');
}
// Test for and remove blocks which aren't appropriate anymore
blocks_remove_inappropriate($course);
// Save any custom role names.
save_local_role_names($course->id, $data);
// update enrol settings
enrol_course_updated(false, $course, $data);
// Update course tags.
if (isset($data->tags)) {
core_tag_tag::set_item_tags('core', 'course', $course->id, context_course::instance($course->id), $data->tags);
}
// Trigger a course updated event.
$event = \core\event\course_updated::create(array('objectid' => $course->id, 'context' => context_course::instance($course->id), 'other' => array('shortname' => $course->shortname, 'fullname' => $course->fullname)));
$event->set_legacy_logdata(array($course->id, 'course', 'update', 'edit.php?id=' . $course->id, $course->id));
$event->trigger();
if ($oldcourse->format !== $course->format) {
// Remove all options stored for the previous format
// We assume that new course format migrated everything it needed watching trigger
// 'course_updated' and in method format_XXX::update_course_format_options()
$DB->delete_records('course_format_options', array('courseid' => $course->id, 'format' => $oldcourse->format));
}
}
开发者ID:rushi963,项目名称:moodle,代码行数:97,代码来源:lib.php
示例11: test_search_courses
/**
* Test search_courses
*/
public function test_search_courses()
{
global $DB;
$this->resetAfterTest(true);
$this->setAdminUser();
$generatedcourses = array();
$coursedata1['fullname'] = 'FIRST COURSE';
$course1 = self::getDataGenerator()->create_course($coursedata1);
$coursedata2['fullname'] = 'SECOND COURSE';
$course2 = self::getDataGenerator()->create_course($coursedata2);
// Search by name.
$results = core_course_external::search_courses('search', 'FIRST');
$results = external_api::clean_returnvalue(core_course_external::search_courses_returns(), $results);
$this->assertEquals($coursedata1['fullname'], $results['courses'][0]['fullname']);
$this->assertCount(1, $results['courses']);
// Create the forum.
$record = new stdClass();
$record->introformat = FORMAT_HTML;
$record->course = $course2->id;
// Set Aggregate type = Average of ratings.
$forum = self::getDataGenerator()->create_module('forum', $record);
// Search by module.
$results = core_course_external::search_courses('modulelist', 'forum');
$results = external_api::clean_returnvalue(core_course_external::search_courses_returns(), $results);
$this->assertEquals(1, $results['total']);
// Enable coursetag option.
set_config('block_tags_showcoursetags', true);
// Add tag 'TAG-LABEL ON SECOND COURSE' to Course2.
core_tag_tag::set_item_tags('core', 'course', $course2->id, context_course::instance($course2->id), array('TAG-LABEL ON SECOND COURSE'));
$taginstance = $DB->get_record('tag_instance', array('itemtype' => 'course', 'itemid' => $course2->id), '*', MUST_EXIST);
// Search by tagid.
$results = core_course_external::search_courses('tagid', $taginstance->tagid);
$results = external_api::clean_returnvalue(core_course_external::search_courses_returns(), $results);
$this->assertEquals($coursedata2['fullname'], $results['courses'][0]['fullname']);
// Search by block (use news_items default block).
$blockid = $DB->get_field('block', 'id', array('name' => 'news_items'));
$results = core_course_external::search_courses('blocklist', $blockid);
$results = external_api::clean_returnvalue(core_course_external::search_courses_returns(), $results);
$this->assertEquals(2, $results['total']);
// Now as a normal user.
$user = self::getDataGenerator()->create_user();
// Add a 3rd, hidden, course we shouldn't see, even when enrolled as student.
$coursedata3['fullname'] = 'HIDDEN COURSE';
$coursedata3['visible'] = 0;
$course3 = self::getDataGenerator()->create_course($coursedata3);
$this->getDataGenerator()->enrol_user($user->id, $course3->id, 'student');
$this->getDataGenerator()->enrol_user($user->id, $course2->id, 'student');
$this->setUser($user);
$results = core_course_external::search_courses('search', 'FIRST');
$results = external_api::clean_returnvalue(core_course_external::search_courses_returns(), $results);
$this->assertCount(1, $results['courses']);
$this->assertEquals(1, $results['total']);
$this->assertEquals($coursedata1['fullname'], $results['courses'][0]['fullname']);
// Check that we can see both without the limit to enrolled setting.
$results = core_course_external::search_courses('search', 'COURSE', 0, 0, array(), 0);
$results = external_api::clean_returnvalue(core_course_external::search_courses_returns(), $results);
$this->assertCount(2, $results['courses']);
$this->assertEquals(2, $results['total']);
// Check that we only see our enrolled course when limiting.
$results = core_course_external::search_courses('search', 'COURSE', 0, 0, array(), 1);
$results = external_api::clean_returnvalue(core_course_external::search_courses_returns(), $results);
$this->assertCount(1, $results['courses']);
$this->assertEquals(1, $results['total']);
$this->assertEquals($coursedata2['fullname'], $results['courses'][0]['fullname']);
// Search by block (use news_items default block). Should fail (only admins allowed).
$this->setExpectedException('required_capability_exception');
$results = core_course_external::search_courses('blocklist', $blockid);
}
开发者ID:sirromas,项目名称:lms,代码行数:71,代码来源:externallib_test.php
示例12: test_combine_tags_with_correlated
/**
* Testing function core_tag_tag::combine_tags() when correlated tags are present.
*/
public function test_combine_tags_with_correlated()
{
$task = new \core\task\tag_cron_task();
$tags = $this->prepare_correlated();
$task->compute_correlations();
// Now 'cat' is correlated with 'cats'.
// Also 'dog', 'dogs' and 'puppy' are correlated.
// There is a manual relation between 'cat' and 'kitten'.
// See function test_correlations() for assertions.
// Combine tags 'dog' and 'kitten' into 'cat' and make sure that cat is now correlated with dogs and puppy.
$tags['cat']->combine_tags(array($tags['dog'], $tags['kitten']));
$correlatedtags = $this->get_correlated_tags_names($tags['cat']);
$this->assertEquals(['cats', 'dogs', 'puppy'], $correlatedtags);
$correlatedtags = $this->get_correlated_tags_names($tags['dogs']);
$this->assertEquals(['cat', 'puppy'], $correlatedtags);
$correlatedtags = $this->get_correlated_tags_names($tags['puppy']);
$this->assertEquals(['cat', 'dogs'], $correlatedtags);
// Add tag that does not have any correlations.
$user7 = $this->getDataGenerator()->create_user();
core_tag_tag::set_item_tags('core', 'user', $user7->id, context_user::instance($user7->id), array('hippo'));
$tags['hippo'] = core_tag_tag::get_by_name(core_tag_collection::get_default(), 'hippo', '*');
// Combine tag 'cat' into 'hippo'. Now 'hippo' should have the same correlations 'cat' used to have and also
// tags 'dogs' and 'puppy' should have 'hippo' in correlations.
$tags['hippo']->combine_tags(array($tags['cat']));
$correlatedtags = $this->get_correlated_tags_names($tags['hippo']);
$this->assertEquals(['cats', 'dogs', 'puppy'], $correlatedtags);
$correlatedtags = $this->get_correlated_tags_names($tags['dogs']);
$this->assertEquals(['hippo', 'puppy'], $correlatedtags);
$correlatedtags = $this->get_correlated_tags_names($tags['puppy']);
$this->assertEquals(['dogs', 'hippo'], $correlatedtags);
}
开发者ID:evltuma,项目名称:moodle,代码行数:34,代码来源:taglib_test.php
示例13: switch
$usercontext = context_user::instance($USER->id);
switch ($action) {
case 'addinterest':
if (!core_tag_tag::is_enabled('core', 'user')) {
print_error('tagdisabled');
}
$tag = required_param('tag', PARAM_TAG);
core_tag_tag::add_item_tag('core', 'user', $USER->id, $usercontext, $tag);
$tc = core_tag_area::get_collection('core', 'user');
redirect(core_tag_tag::make_url($tc, $tag));
break;
case 'removeinterest':
if (!core_tag_tag::is_enabled('core', 'user')) {
print_error('tagdisabled');
}
$tag = required_param('tag', PARAM_TAG);
core_tag_tag::remove_item_tag('core', 'user', $USER->id, $tag);
$tc = core_tag_area::get_collection('core', 'user');
redirect(core_tag_tag::make_url($tc, $tag));
break;
case 'flaginappropriate':
require_capability('moodle/tag:flag', context_system::instance());
$id = required_param('id', PARAM_INT);
$tagobject = core_tag_tag::get($id, '*', MUST_EXIST);
$tagobject->flag();
redirect($tagobject->get_view_url(), get_string('responsiblewillbenotified', 'tag'));
break;
default:
print_error('unknowaction');
break;
}
开发者ID:evltuma,项目名称:moodle,代码行数:31,代码来源:user.php
示例14: _tidy_question
/**
* Private function to factor common code out of get_question_options().
*
* @param object $question the question to tidy.
* @param boolean $loadtags load the question tags from the tags table. Optional, default false.
*/
function _tidy_question($question, $loadtags = false)
{
global $CFG;
// Load question-type specific fields.
if (!question_bank::is_qtype_installed($question->qtype)) {
$question->questiontext = html_writer::tag('p', get_string('warningmissingtype', 'qtype_missingtype')) . $question->questiontext;
}
question_bank::get_qtype($question->qtype)->get_question_options($question);
// Convert numeric fields to float. (Prevents these being displayed as 1.0000000.)
$question->defaultmark += 0;
$question->penalty += 0;
if (isset($question->_partiallyloaded)) {
unset($question->_partiallyloaded);
}
if ($loadtags && core_tag_tag::is_enabled('core_question', 'question')) {
$question->tags = core_tag_tag::get_item_tags_array('core_question', 'question', $question->id);
}
}
开发者ID:rushi963,项目名称:moodle,代码行数:24,代码来源:questionlib.php
示例15: move_tags
/**
* Moves existing tags associated with an item type to another tag collection
*
* @param string $component
* @param string $itemtype
* @param int $tagcollid
*/
public static function move_tags($component, $itemtype, $tagcollid)
{
global $DB;
$params = array('itemtype1' => $itemtype, 'component1' => $component, 'itemtype2' => $itemtype, 'component2' => $component, 'tagcollid1' => $tagcollid, 'tagcollid2' => $tagcollid);
// Find all collections that need to be cleaned later.
$sql = "SELECT DISTINCT t.tagcollid " . "FROM {tag_instance} ti " . "JOIN {tag} t ON t.id = ti.tagid AND t.tagcollid <> :tagcollid1 " . "WHERE ti.itemtype = :itemtype2 AND ti.component = :component2 ";
$cleanupcollections = $DB->get_fieldset_sql($sql, $params);
// Find all tags that are related to the tags being moved and make sure they are present in the target tagcoll.
// This query is a little complicated because Oracle does not allow to run SELECT DISTINCT on CLOB fields.
$sql = "SELECT name, rawname, description, descriptionformat, userid, tagtype, flag " . "FROM {tag} WHERE id IN " . "(SELECT r.id " . "FROM {tag_instance} ti " . "JOIN {tag} t ON t.id = ti.tagid AND t.tagcollid <> :tagcollid1 " . "JOIN {tag_instance} tr ON tr.itemtype = 'tag' and tr.component = 'core' AND tr.itemid = t.id " . "JOIN {tag} r ON r.id = tr.tagid " . "LEFT JOIN {tag} re ON re.name = r.name AND re.tagcollid = :tagcollid2 " . "WHERE ti.itemtype = :itemtype2 AND ti.component = :component2 " . " AND re.id IS NULL)";
// We need related tags that ARE NOT present in the target tagcoll.
$result = $DB->get_records_sql($sql, $params);
foreach ($result as $tag) {
$tag->tagcollid = $tagcollid;
$tag->id = $DB->insert_record('tag', $tag);
\core\event\tag_created::create_from_tag($tag);
}
// Find all tags that need moving and have related tags, remember their related tags.
$sql = "SELECT t.name AS tagname, r.rawname AS relatedtag " . "FROM {tag_instance} ti " . "JOIN {tag} t ON t.id = ti.tagid AND t.tagcollid <> :tagcollid1 " . "JOIN {tag_instance} tr ON t.id = tr.tagid AND tr.itemtype = 'tag' and tr.component = 'core' " . "JOIN {tag} r ON r.id = tr.itemid " . "WHERE ti.itemtype = :itemtype2 AND ti.component = :component2 " . "ORDER BY t.id, tr.ordering ";
$relatedtags = array();
$result = $DB->get_recordset_sql($sql, $params);
foreach ($result as $record) {
$relatedtags[$record->tagname][] = $record->relatedtag;
}
$result->close();
// Find all tags that are used for this itemtype/component and are not present in the target tag collection.
// This query is a little complicated because Oracle does not allow to run SELECT DISTINCT on CLOB fields.
$sql = "SELECT id, name, rawname, description, descriptionformat, userid, tagtype, flag\n FROM {tag} WHERE id IN\n (SELECT t.id\n FROM {tag_instance} ti\n JOIN {tag} t ON t.id = ti.tagid AND t.tagcollid <> :tagcollid1\n LEFT JOIN {tag} tt ON tt.name = t.name AND tt.tagcollid = :tagcollid2\n WHERE ti.itemtype = :itemtype2 AND ti.component = :component2\n AND tt.id IS NULL)";
$movedtags = array();
// Keep track of moved tags so we don't hit DB index violation.
$result = $DB->get_records_sql($sql, $params);
foreach ($result as $tag) {
$originaltagid = $tag->id;
if (array_key_exists($tag->name, $movedtags)) {
// Case of corrupted data when the same tag was in several collections.
$tag->id = $movedtags[$tag->name];
} else {
// Copy the tag into the new collection.
unset($tag->id);
$tag->tagcollid = $tagcollid;
$tag->id = $DB->insert_record('tag', $tag);
\core\event\tag_created::create_from_tag($tag);
$movedtags[$tag->name] = $tag->id;
}
$DB->execute("UPDATE {tag_instance} SET tagid = ? WHERE tagid = ? AND itemtype = ? AND component = ?", array($tag->id, $originaltagid, $itemtype, $component));
}
// Find all tags that are used for this itemtype/component and are already present in the target tag collection.
$sql = "SELECT DISTINCT t.id, tt.id AS targettagid\n FROM {tag_instance} ti\n JOIN {tag} t ON t.id = ti.tagid AND t.tagcollid <> :tagcollid1\n JOIN {tag} tt ON tt.name = t.name AND tt.tagcollid = :tagcollid2\n WHERE ti.itemtype = :itemtype2 AND ti.component = :component2";
$result = $DB->get_records_sql($sql, $params);
foreach ($result as $tag) {
$DB->execute("UPDATE {tag_instance} SET tagid = ? WHERE t
|
请发表评论