本文整理汇总了PHP中tag_get_tags函数的典型用法代码示例。如果您正苦于以下问题:PHP tag_get_tags函数的具体用法?PHP tag_get_tags怎么用?PHP tag_get_tags使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了tag_get_tags函数的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: process_tag
public function process_tag($data) {
global $CFG, $DB;
$data = (object)$data;
if (!empty($CFG->usetags)) { // if enabled in server
// TODO: This is highly inneficient. Each time we add one tag
// we fetch all the existing because tag_set() deletes them
// so everything must be reinserted on each call
$tags = array();
$existingtags = tag_get_tags('course', $this->get_courseid());
// Re-add all the existitng tags
foreach ($existingtags as $existingtag) {
$tags[] = $existingtag->rawname;
}
// Add the one being restored
$tags[] = $data->rawname;
// Send all the tags back to the course
tag_set('course', $this->get_courseid(), $tags);
}
}
开发者ID:nottmoo,项目名称:moodle,代码行数:21,代码来源:restore_stepslib.php
示例2: process_tag
protected function process_tag($data)
{
global $CFG, $DB;
$data = (object) $data;
$newquestion = $this->get_new_parentid('question');
if (!empty($CFG->usetags)) {
// if enabled in server
// TODO: This is highly inefficient. Each time we add one tag
// we fetch all the existing because tag_set() deletes them
// so everything must be reinserted on each call
$tags = array();
$existingtags = tag_get_tags('question', $newquestion);
// Re-add all the existitng tags
foreach ($existingtags as $existingtag) {
$tags[] = $existingtag->rawname;
}
// Add the one being restored
$tags[] = $data->rawname;
// Get the category, so we can then later get the context.
$categoryid = $this->get_new_parentid('question_category');
if (empty($this->cachedcategory) || $this->cachedcategory->id != $categoryid) {
$this->cachedcategory = $DB->get_record('question_categories', array('id' => $categoryid));
}
// Send all the tags back to the question
tag_set('question', $newquestion, $tags, 'core_question', $this->cachedcategory->contextid);
}
}
开发者ID:Jinelle,项目名称:moodle,代码行数:27,代码来源:restore_stepslib.php
示例3: backup_user_info
//.........这里部分代码省略.........
/// write assign/override code for context_userid
$user->isneeded = strpos($user->info, "needed");
fwrite($bf, start_tag("ROLES", 4, true));
if ($user->info != "needed" && $user->info != "") {
//PRINT ROLE INFO
$roles = explode(",", $user->info);
foreach ($roles as $role) {
if ($role != "" && $role != "needed") {
fwrite($bf, start_tag("ROLE", 5, true));
//Print Role info
fwrite($bf, full_tag("TYPE", 6, false, $role));
//Print ROLE end
fwrite($bf, end_tag("ROLE", 5, true));
}
}
}
//Needed
if ($user->isneeded !== false) {
//Print ROLE start
fwrite($bf, start_tag("ROLE", 5, true));
//Print Role info
fwrite($bf, full_tag("TYPE", 6, false, "needed"));
//Print ROLE end
fwrite($bf, end_tag("ROLE", 5, true));
}
//End ROLES tag
fwrite($bf, end_tag("ROLES", 4, true));
//Check if we have custom profile fields to backup
if ($cpfields = get_records_sql("SELECT uif.shortname, uif.datatype, uidata.data\n FROM {$CFG->prefix}user_info_field uif,\n {$CFG->prefix}user_info_data uidata\n WHERE uif.id = uidata.fieldid\n AND uidata.userid = {$user->id}")) {
//Start USER_CUSTOM_PROFILE_FIELDS tag
fwrite($bf, start_tag("USER_CUSTOM_PROFILE_FIELDS", 4, true));
//Write custom profile fields
foreach ($cpfields as $cpfield) {
fwrite($bf, start_tag("USER_CUSTOM_PROFILE_FIELD", 5, true));
fwrite($bf, full_tag("FIELD_NAME", 6, false, $cpfield->shortname));
fwrite($bf, full_tag("FIELD_TYPE", 6, false, $cpfield->datatype));
fwrite($bf, full_tag("FIELD_DATA", 6, false, $cpfield->data));
fwrite($bf, end_tag("USER_CUSTOM_PROFILE_FIELD", 5, true));
}
//End USER_CUSTOM_PROFILE_FIELDS tag
fwrite($bf, end_tag("USER_CUSTOM_PROFILE_FIELDS", 4, true));
}
//Check if we have user tags to backup
if (!empty($CFG->usetags)) {
if ($tags = tag_get_tags('user', $user->id)) {
//This return them ordered by default
//Start USER_TAGS tag
fwrite($bf, start_tag("USER_TAGS", 4, true));
//Write user tags fields
foreach ($tags as $tag) {
fwrite($bf, start_tag("USER_TAG", 5, true));
fwrite($bf, full_tag("NAME", 6, false, $tag->name));
fwrite($bf, full_tag("RAWNAME", 6, false, $tag->rawname));
fwrite($bf, end_tag("USER_TAG", 5, true));
}
//End USER_TAGS tag
fwrite($bf, end_tag("USER_TAGS", 4, true));
}
}
//Check if we have user_preferences to backup
if ($preferences_data = get_records("user_preferences", "userid", $user->old_id)) {
//Start USER_PREFERENCES tag
fwrite($bf, start_tag("USER_PREFERENCES", 4, true));
//Write each user_preference
foreach ($preferences_data as $user_preference) {
fwrite($bf, start_tag("USER_PREFERENCE", 5, true));
fwrite($bf, full_tag("NAME", 6, false, $user_preference->name));
fwrite($bf, full_tag("VALUE", 6, false, $user_preference->value));
fwrite($bf, end_tag("USER_PREFERENCE", 5, true));
}
//End USER_PREFERENCES tag
fwrite($bf, end_tag("USER_PREFERENCES", 4, true));
}
$context = get_context_instance(CONTEXT_USER, $user->old_id);
write_role_overrides_xml($bf, $context, 4);
/// write role_assign code here
write_role_assignments_xml($bf, $preferences, $context, 4);
//End User tag
fwrite($bf, end_tag("USER", 3, true));
//Do some output
$counter++;
if ($counter % 10 == 0) {
echo ".";
if ($counter % 200 == 0) {
echo "<br />";
}
backup_flush(300);
}
}
//End Users tag
fwrite($bf, end_tag("USERS", 2, true));
} else {
// There aren't any users.
$status = true;
}
if ($users) {
rs_close($users);
}
return $status;
}
开发者ID:nagyistoce,项目名称:moodle-Teach-Pilot,代码行数:101,代码来源:backuplib.php
示例4: tag_get_related_tags
/**
* Returns tags related to a tag
*
* Related tags of a tag come from two sources:
* - manually added related tags, which are tag_instance entries for that tag
* - correlated tags, which are a calculated
*
* @param string $tag_name_or_id is a single **normalized** tag name or the id
* of a tag
* @param int $type the function will return either manually
* (TAG_RELATED_MANUAL) related tags or correlated (TAG_RELATED_CORRELATED)
* tags. Default is TAG_RELATED_ALL, which returns everything.
* @param int $limitnum return a subset comprising this many records (optional,
* default is 10)
* @return array an array of tag objects
*/
function tag_get_related_tags($tagid, $type = TAG_RELATED_ALL, $limitnum = 10)
{
$related_tags = array();
if ($type == TAG_RELATED_ALL || $type == TAG_RELATED_MANUAL) {
//gets the manually added related tags
$related_tags = tag_get_tags('tag', $tagid);
}
if ($type == TAG_RELATED_ALL || $type == TAG_RELATED_CORRELATED) {
//gets the correlated tags
$automatic_related_tags = tag_get_correlated($tagid, $limitnum);
if (is_array($automatic_related_tags)) {
$related_tags = array_merge($related_tags, $automatic_related_tags);
}
}
return array_slice(object_array_unique($related_tags), 0, $limitnum);
}
开发者ID:r007,项目名称:PMoodle,代码行数:32,代码来源:lib.php
示例5: test_correlations
/**
* Test for function tag_compute_correlations() that is part of tag cron
*/
public function test_correlations()
{
global $DB;
$task = new \core\task\tag_cron_task();
$tags = array_map(function ($t) {
return $t->id;
}, $this->prepare_correlated());
$task->compute_correlations();
$this->assertEquals($tags['cats'], $DB->get_field_select('tag_correlation', 'correlatedtags', 'tagid = ?', array($tags['cat'])));
$this->assertEquals($tags['cat'], $DB->get_field_select('tag_correlation', 'correlatedtags', 'tagid = ?', array($tags['cats'])));
$this->assertEquals($tags['dogs'] . ',' . $tags['puppy'], $DB->get_field_select('tag_correlation', 'correlatedtags', 'tagid = ?', array($tags['dog'])));
$this->assertEquals($tags['dog'] . ',' . $tags['puppy'], $DB->get_field_select('tag_correlation', 'correlatedtags', 'tagid = ?', array($tags['dogs'])));
$this->assertEquals($tags['dog'] . ',' . $tags['dogs'], $DB->get_field_select('tag_correlation', 'correlatedtags', 'tagid = ?', array($tags['puppy'])));
// Make sure get_correlated_tags() returns 'cats' as the only correlated tag to the 'cat'.
$correlatedtags = array_values(core_tag_tag::get($tags['cat'])->get_correlated_tags(true));
$this->assertCount(3, $correlatedtags);
// This will return all existing instances but they all point to the same tag.
$this->assertEquals('cats', $correlatedtags[0]->rawname);
$this->assertEquals('cats', $correlatedtags[1]->rawname);
$this->assertEquals('cats', $correlatedtags[2]->rawname);
$correlatedtags = array_values(core_tag_tag::get($tags['cat'])->get_correlated_tags());
$this->assertCount(1, $correlatedtags);
// Duplicates are filtered out here.
$this->assertEquals('cats', $correlatedtags[0]->rawname);
// Make sure tag_get_correlated() returns 'dogs' and 'puppy' as the correlated tags to the 'dog'.
$correlatedtags = core_tag_tag::get($tags['dog'])->get_correlated_tags(true);
$this->assertCount(6, $correlatedtags);
// 2 tags times 3 instances.
$correlatedtags = array_values(core_tag_tag::get($tags['dog'])->get_correlated_tags());
$this->assertCount(2, $correlatedtags);
$this->assertEquals('dogs', $correlatedtags[0]->rawname);
$this->assertEquals('puppy', $correlatedtags[1]->rawname);
// Function get_related_tags() will return both related and correlated tags.
$relatedtags = array_values(core_tag_tag::get($tags['cat'])->get_related_tags());
$this->assertCount(2, $relatedtags);
$this->assertEquals('kitten', $relatedtags[0]->rawname);
$this->assertEquals('cats', $relatedtags[1]->rawname);
// Also test deprecated method tag_get_related_tags() and tag_get_correlated().
$correlatedtags = array_values(tag_get_correlated($tags['cat']));
$this->assertDebuggingCalled();
$this->assertCount(3, $correlatedtags);
// This will return all existing instances but they all point to the same tag.
$this->assertEquals('cats', $correlatedtags[0]->rawname);
$this->assertEquals('cats', $correlatedtags[1]->rawname);
$this->assertEquals('cats', $correlatedtags[2]->rawname);
$correlatedtags = array_values(tag_get_related_tags($tags['cat'], TAG_RELATED_CORRELATED));
$this->assertDebuggingCalled();
$this->assertCount(1, $correlatedtags);
// Duplicates are filtered out here.
$this->assertEquals('cats', $correlatedtags[0]->rawname);
$correlatedtags = array_values(tag_get_correlated($tags['dog']));
$this->assertDebuggingCalled();
$this->assertCount(6, $correlatedtags);
// 2 tags times 3 instances.
$correlatedtags = array_values(tag_get_related_tags($tags['dog'], TAG_RELATED_CORRELATED));
$this->assertDebuggingCalled();
$this->assertCount(2, $correlatedtags);
$this->assertEquals('dogs', $correlatedtags[0]->rawname);
$this->assertEquals('puppy', $correlatedtags[1]->rawname);
$relatedtags = array_values(tag_get_related_tags($tags['cat']));
$this->assertDebuggingCalled();
$this->assertCount(2, $relatedtags);
$this->assertEquals('kitten', $relatedtags[0]->rawname);
$this->assertEquals('cats', $relatedtags[1]->rawname);
// End of testing deprecated methods.
// If we then manually set 'cat' and 'cats' as related, get_related_tags() will filter out duplicates.
core_tag_tag::get($tags['cat'])->set_related_tags(array('kitten', 'cats'));
$relatedtags = array_values(core_tag_tag::get($tags['cat'])->get_related_tags());
$this->assertCount(2, $relatedtags);
$this->assertEquals('kitten', $relatedtags[0]->rawname);
$this->assertEquals('cats', $relatedtags[1]->rawname);
// Make sure core_tag_tag::get_item_tags(), core_tag_tag::get_correlated_tags() return the same set of fields.
$relatedtags = core_tag_tag::get_item_tags('core', 'tag', $tags['cat']);
$relatedtag = reset($relatedtags);
$correlatedtags = core_tag_tag::get($tags['cat'])->get_correlated_tags();
$correlatedtag = reset($correlatedtags);
$this->assertEquals(array_keys((array) $relatedtag->to_object()), array_keys((array) $correlatedtag->to_object()));
// Make sure tag_get_correlated() and tag_get_tags() return the same set of fields.
// Both functions were deprecated in 3.1.
$relatedtags = tag_get_tags('tag', $tags['cat']);
$this->assertDebuggingCalled();
$relatedtag = reset($relatedtags);
$correlatedtags = tag_get_correlated($tags['cat']);
$this->assertDebuggingCalled();
$correlatedtag = reset($correlatedtags);
$this->assertEquals(array_keys((array) $relatedtag), array_keys((array) $correlatedtag));
}
开发者ID:evltuma,项目名称:moodle,代码行数:90,代码来源:taglib_test.php
示例6: test_correlations
//.........这里部分代码省略.........
$user2 = $this->getDataGenerator()->create_user();
$user3 = $this->getDataGenerator()->create_user();
$user4 = $this->getDataGenerator()->create_user();
$user5 = $this->getDataGenerator()->create_user();
$user6 = $this->getDataGenerator()->create_user();
// Several records have both 'cat' and 'cats' tags attached to them.
// This will make those tags automatically correlated.
// Same with 'dog', 'dogs' and 'puppy.
core_tag_tag::set_item_tags('core', 'user', $user1->id, context_user::instance($user1->id), array('cat', 'cats'));
core_tag_tag::set_item_tags('core', 'user', $user2->id, context_user::instance($user2->id), array('cat', 'cats', 'kitten'));
core_tag_tag::set_item_tags('core', 'user', $user3->id, context_user::instance($user3->id), array('cat', 'cats'));
core_tag_tag::set_item_tags('core', 'user', $user4->id, context_user::instance($user4->id), array('dog', 'dogs', 'puppy'));
core_tag_tag::set_item_tags('core', 'user', $user5->id, context_user::instance($user5->id), array('dog', 'dogs', 'puppy'));
core_tag_tag::set_item_tags('core', 'user', $user6->id, context_user::instance($user6->id), array('dog', 'dogs', 'puppy'));
$tags = core_tag_tag::get_by_name_bulk(core_tag_collection::get_default(), array('cat', 'cats', 'dog', 'dogs', 'kitten', 'puppy'));
$tags = array_map(function ($t) {
return $t->id;
}, $tags);
// Add manual relation between tags 'cat' and 'kitten'.
core_tag_tag::get($tags['cat'])->set_related_tags(array('kitten'));
$task->compute_correlations();
$this->assertEquals($tags['cats'], $DB->get_field_select('tag_correlation', 'correlatedtags', 'tagid = ?', array($tags['cat'])));
$this->assertEquals($tags['cat'], $DB->get_field_select('tag_correlation', 'correlatedtags', 'tagid = ?', array($tags['cats'])));
$this->assertEquals($tags['dogs'] . ',' . $tags['puppy'], $DB->get_field_select('tag_correlation', 'correlatedtags', 'tagid = ?', array($tags['dog'])));
$this->assertEquals($tags['dog'] . ',' . $tags['puppy'], $DB->get_field_select('tag_correlation', 'correlatedtags', 'tagid = ?', array($tags['dogs'])));
$this->assertEquals($tags['dog'] . ',' . $tags['dogs'], $DB->get_field_select('tag_correlation', 'correlatedtags', 'tagid = ?', array($tags['puppy'])));
// Make sure get_correlated_tags() returns 'cats' as the only correlated tag to the 'cat'.
$correlatedtags = array_values(core_tag_tag::get($tags['cat'])->get_correlated_tags(true));
$this->assertCount(3, $correlatedtags);
// This will return all existing instances but they all point to the same tag.
$this->assertEquals('cats', $correlatedtags[0]->rawname);
$this->assertEquals('cats', $correlatedtags[1]->rawname);
$this->assertEquals('cats', $correlatedtags[2]->rawname);
$correlatedtags = array_values(core_tag_tag::get($tags['cat'])->get_correlated_tags());
$this->assertCount(1, $correlatedtags);
// Duplicates are filtered out here.
$this->assertEquals('cats', $correlatedtags[0]->rawname);
// Make sure tag_get_correlated() returns 'dogs' and 'puppy' as the correlated tags to the 'dog'.
$correlatedtags = core_tag_tag::get($tags['dog'])->get_correlated_tags(true);
$this->assertCount(6, $correlatedtags);
// 2 tags times 3 instances.
$correlatedtags = array_values(core_tag_tag::get($tags['dog'])->get_correlated_tags());
$this->assertCount(2, $correlatedtags);
$this->assertEquals('dogs', $correlatedtags[0]->rawname);
$this->assertEquals('puppy', $correlatedtags[1]->rawname);
// Function get_related_tags() will return both related and correlated tags.
$relatedtags = array_values(core_tag_tag::get($tags['cat'])->get_related_tags());
$this->assertCount(2, $relatedtags);
$this->assertEquals('kitten', $relatedtags[0]->rawname);
$this->assertEquals('cats', $relatedtags[1]->rawname);
// Also test deprecated method tag_get_related_tags() and tag_get_correlated().
$correlatedtags = array_values(tag_get_correlated($tags['cat']));
$this->assertDebuggingCalled();
$this->assertCount(3, $correlatedtags);
// This will return all existing instances but they all point to the same tag.
$this->assertEquals('cats', $correlatedtags[0]->rawname);
$this->assertEquals('cats', $correlatedtags[1]->rawname);
$this->assertEquals('cats', $correlatedtags[2]->rawname);
$correlatedtags = array_values(tag_get_related_tags($tags['cat'], TAG_RELATED_CORRELATED));
$this->assertDebuggingCalled();
$this->assertCount(1, $correlatedtags);
// Duplicates are filtered out here.
$this->assertEquals('cats', $correlatedtags[0]->rawname);
$correlatedtags = array_values(tag_get_correlated($tags['dog']));
$this->assertDebuggingCalled();
$this->assertCount(6, $correlatedtags);
// 2 tags times 3 instances.
$correlatedtags = array_values(tag_get_related_tags($tags['dog'], TAG_RELATED_CORRELATED));
$this->assertDebuggingCalled();
$this->assertCount(2, $correlatedtags);
$this->assertEquals('dogs', $correlatedtags[0]->rawname);
$this->assertEquals('puppy', $correlatedtags[1]->rawname);
$relatedtags = array_values(tag_get_related_tags($tags['cat']));
$this->assertDebuggingCalled();
$this->assertCount(2, $relatedtags);
$this->assertEquals('kitten', $relatedtags[0]->rawname);
$this->assertEquals('cats', $relatedtags[1]->rawname);
// End of testing deprecated methods.
// If we then manually set 'cat' and 'cats' as related, get_related_tags() will filter out duplicates.
core_tag_tag::get($tags['cat'])->set_related_tags(array('kitten', 'cats'));
$relatedtags = array_values(core_tag_tag::get($tags['cat'])->get_related_tags());
$this->assertCount(2, $relatedtags);
$this->assertEquals('kitten', $relatedtags[0]->rawname);
$this->assertEquals('cats', $relatedtags[1]->rawname);
// Make sure core_tag_tag::get_item_tags(), core_tag_tag::get_correlated_tags() return the same set of fields.
$relatedtags = core_tag_tag::get_item_tags('core', 'tag', $tags['cat']);
$relatedtag = reset($relatedtags);
$correlatedtags = core_tag_tag::get($tags['cat'])->get_correlated_tags();
$correlatedtag = reset($correlatedtags);
$this->assertEquals(array_keys((array) $relatedtag->to_object()), array_keys((array) $correlatedtag->to_object()));
// Make sure tag_get_correlated() and tag_get_tags() return the same set of fields.
// Both functions were deprecated in 3.1.
$relatedtags = tag_get_tags('tag', $tags['cat']);
$this->assertDebuggingCalled();
$relatedtag = reset($relatedtags);
$correlatedtags = tag_get_correlated($tags['cat']);
$this->assertDebuggingCalled();
$correlatedtag = reset($correlatedtags);
$this->assertEquals(array_keys((array) $relatedtag), array_keys((array) $correlatedtag));
}
开发者ID:bewanyk,项目名称:moodle,代码行数:101,代码来源:taglib_test.php
示例7: backup_blog
function backup_blog($bf, $blogid, $level)
{
global $DB;
$blog = $DB->get_record('post', array('module' => 'blog', 'id' => $blogid));
/// start blog
fwrite($bf, start_tag("BLOG", $level, true));
/// blog body
fwrite($bf, full_tag("ID", $level + 1, false, $blog->id));
fwrite($bf, full_tag("MODULE", $level + 1, false, $blog->module));
fwrite($bf, full_tag("USERID", $level + 1, false, $blog->userid));
fwrite($bf, full_tag("COURSEID", $level + 1, false, $blog->courseid));
fwrite($bf, full_tag("GROUPID", $level + 1, false, $blog->groupid));
fwrite($bf, full_tag("MODULEID", $level + 1, false, $blog->moduleid));
fwrite($bf, full_tag("COURSEMODULEID", $level + 1, false, $blog->coursemoduleid));
fwrite($bf, full_tag("SUBJECT", $level + 1, false, $blog->subject));
fwrite($bf, full_tag("SUMMARY", $level + 1, false, $blog->summary));
fwrite($bf, full_tag("CONTENT", $level + 1, false, $blog->content));
fwrite($bf, full_tag("UNIQUEHASH", $level + 1, false, $blog->uniquehash));
fwrite($bf, full_tag("RATING", $level + 1, false, $blog->rating));
fwrite($bf, full_tag("FORMAT", $level + 1, false, $blog->format));
fwrite($bf, full_tag("ATTACHMENT", $level + 1, false, $blog->attachment));
fwrite($bf, full_tag("PUBLISHSTATE", $level + 1, false, $blog->publishstate));
fwrite($bf, full_tag("LASTMODIFIED", $level + 1, false, $blog->lastmodified));
fwrite($bf, full_tag("CREATED", $level + 1, false, $blog->created));
fwrite($bf, full_tag("USERMODIFIED", $level + 1, false, $blog->usermodified));
/// Blog tags
/// Check if we have blog tags to backup
if (!empty($CFG->usetags)) {
if ($tags = tag_get_tags('post', $blog->id)) {
//This return them ordered by default
/// Start BLOG_TAGS tag
fwrite($bf, start_tag("BLOG_TAGS", $level + 1, true));
/// Write blog tags fields
foreach ($tags as $tag) {
fwrite($bf, start_tag("BLOG_TAG", $level + 2, true));
fwrite($bf, full_tag("NAME", $level + 3, false, $tag->name));
fwrite($bf, full_tag("RAWNAME", $level + 3, false, $tag->rawname));
fwrite($bf, end_tag("BLOG_TAG", $level + 2, true));
}
/// End BLOG_TAGS tag
fwrite($bf, end_tag("BLOG_TAGS", $level + 1, true));
}
}
/// end blog
fwrite($bf, end_tag("BLOG", $level, true));
}
开发者ID:JP-Git,项目名称:moodle,代码行数:46,代码来源:backuplib.php
示例8: bookmarks_get_item_tags
/**
*
*
*
*/
function bookmarks_get_item_tags($id)
{
return tag_get_tags('bookmark', $id);
}
开发者ID:laiello,项目名称:moodle-social-bookmarking,代码行数:9,代码来源:lib.php
示例9: tag_get_related_tags
/**
* Returns tags related to a tag
*
* Related tags of a tag come from two sources:
* - manually added related tags, which are tag_instance entries for that tag
* - correlated tags, which are calculated
*
* @package core_tag
* @category tag
* @access public
* @param string $tagid is a single **normalized** tag name or the id of a tag
* @param int $type the function will return either manually (TAG_RELATED_MANUAL) related tags or correlated
* (TAG_RELATED_CORRELATED) tags. Default is TAG_RELATED_ALL, which returns everything.
* @param int $limitnum (optional) return a subset comprising this many records, the default is 10
* @return array an array of tag objects
*/
function tag_get_related_tags($tagid, $type = TAG_RELATED_ALL, $limitnum = 10)
{
$related_tags = array();
if ($type == TAG_RELATED_ALL || $type == TAG_RELATED_MANUAL) {
//gets the manually added related tags
$related_tags = tag_get_tags('tag', $tagid);
}
if ($type == TAG_RELATED_ALL || $type == TAG_RELATED_CORRELATED) {
//gets the correlated tags
$automatic_related_tags = tag_get_correlated($tagid);
$related_tags = array_merge($related_tags, $automatic_related_tags);
}
// Remove duplicated tags (multiple instances of the same tag).
$seen = array();
foreach ($related_tags as $instance => $tag) {
if (isset($seen[$tag->id])) {
unset($related_tags[$instance]);
} else {
$seen[$tag->id] = 1;
}
}
return array_slice($related_tags, 0, $limitnum);
}
开发者ID:alanaipe2015,项目名称:moodle,代码行数:39,代码来源:lib.php
示例10: test_correlations
/**
* Test for function tag_compute_correlations() that is part of tag cron
*/
public function test_correlations()
{
global $DB;
$user = $this->getDataGenerator()->create_user();
$this->setUser($user);
$user1 = $this->getDataGenerator()->create_user();
$user2 = $this->getDataGenerator()->create_user();
$user3 = $this->getDataGenerator()->create_user();
$user4 = $this->getDataGenerator()->create_user();
$user5 = $this->getDataGenerator()->create_user();
$user6 = $this->getDataGenerator()->create_user();
// Several records have both 'cat' and 'cats' tags attached to them.
// This will make those tags automatically correlated.
// Same with 'dog', 'dogs' and 'puppy.
tag_set('user', $user1->id, array('cat', 'cats'), 'core', context_user::instance($user1->id)->id);
tag_set('user', $user2->id, array('cat', 'cats', 'kitten'), 'core', context_user::instance($user2->id)->id);
tag_set('user', $user3->id, array('cat', 'cats'), 'core', context_user::instance($user3->id)->id);
tag_set('user', $user4->id, array('dog', 'dogs', 'puppy'), 'core', context_user::instance($user4->id)->id);
tag_set('user', $user5->id, array('dog', 'dogs', 'puppy'), 'core', context_user::instance($user5->id)->id);
tag_set('user', $user6->id, array('dog', 'dogs', 'puppy'), 'core', context_user::instance($user6->id)->id);
$tags = tag_get_id(array('cat', 'cats', 'dog', 'dogs', 'kitten', 'puppy'));
// Add manual relation between tags 'cat' and 'kitten'.
tag_set('tag', $tags['cat'], array('kitten'), 'core', context_system::instance()->id);
tag_compute_correlations();
$this->assertEquals($tags['cats'], $DB->get_field_select('tag_correlation', 'correlatedtags', 'tagid = ?', array($tags['cat'])));
$this->assertEquals($tags['cat'], $DB->get_field_select('tag_correlation', 'correlatedtags', 'tagid = ?', array($tags['cats'])));
$this->assertEquals($tags['dogs'] . ',' . $tags['puppy'], $DB->get_field_select('tag_correlation', 'correlatedtags', 'tagid = ?', array($tags['dog'])));
$this->assertEquals($tags['dog'] . ',' . $tags['puppy'], $DB->get_field_select('tag_correlation', 'correlatedtags', 'tagid = ?', array($tags['dogs'])));
$this->assertEquals($tags['dog'] . ',' . $tags['dogs'], $DB->get_field_select('tag_correlation', 'correlatedtags', 'tagid = ?', array($tags['puppy'])));
// Make sure tag_get_correlated() returns 'cats' as the only correlated tag to the 'cat'.
$correlatedtags = array_values(tag_get_correlated($tags['cat']));
$this->assertCount(3, $correlatedtags);
// This will return all existing instances but they all point to the same tag.
$this->assertEquals('cats', $correlatedtags[0]->rawname);
$this->assertEquals('cats', $correlatedtags[1]->rawname);
$this->assertEquals('cats', $correlatedtags[2]->rawname);
$correlatedtags = array_values(tag_get_related_tags($tags['cat'], TAG_RELATED_CORRELATED));
$this->assertCount(1, $correlatedtags);
// Duplicates are filtered out here.
$this->assertEquals('cats', $correlatedtags[0]->rawname);
// Make sure tag_get_correlated() returns 'dogs' and 'puppy' as the correlated tags to the 'dog'.
$correlatedtags = array_values(tag_get_correlated($tags['dog']));
$this->assertCount(6, $correlatedtags);
// 2 tags times 3 instances.
$correlatedtags = array_values(tag_get_related_tags($tags['dog'], TAG_RELATED_CORRELATED));
$this->assertCount(2, $correlatedtags);
$this->assertEquals('dogs', $correlatedtags[0]->rawname);
$this->assertEquals('puppy', $correlatedtags[1]->rawname);
// Function tag_get_related_tags() with default argument will return both related and correlated tags.
$relatedtags = array_values(tag_get_related_tags($tags['cat']));
$this->assertCount(2, $relatedtags);
$this->assertEquals('kitten', $relatedtags[0]->rawname);
$this->assertEquals('cats', $relatedtags[1]->rawname);
// If we then manually set 'cat' and 'cats' as related, tag_get_related_tags() will filter out duplicates.
tag_set('tag', $tags['cat'], array('kitten', 'cats'), 'core', context_system::instance()->id);
$relatedtags = array_values(tag_get_related_tags($tags['cat']));
$this->assertCount(2, $relatedtags);
$this->assertEquals('kitten', $relatedtags[0]->rawname);
$this->assertEquals('cats', $relatedtags[1]->rawname);
// Make sure tag_get_correlated() and tag_get_tags() return the same set of fields.
$relatedtags = tag_get_tags('tag', $tags['cat']);
$relatedtag = reset($relatedtags);
$correlatedtags = tag_get_correlated($tags['cat']);
$correlatedtag = reset($correlatedtags);
$this->assertEquals(array_keys((array) $relatedtag), array_keys((array) $correlatedtag));
}
开发者ID:alanaipe2015,项目名称:moodle,代码行数:69,代码来源:taglib_test.php
示例11: wiki_tags_get_tag_links
/**
* Returns a XHTML string with comma-separated wikitags links
*
* @param Object $WS WikiStorage
*/
function wiki_tags_get_tag_links($WS)
{
global $CFG, $COURSE;
$page = wiki_page_last_version($WS->page, $WS);
if (!$page) {
return null;
}
$tags = tag_get_tags('wiki', $page->created);
if (!empty($tags)) {
$tags = array_values($tags);
$links = '';
$size = count($tags);
for ($i = 0; $i < $size; $i++) {
$tag = $tags[$i];
$links .= '<a href="' . $CFG->wwwroot . '/mod/wiki/tags/view.php?cid=' . $COURSE->id . '&cmid=' . $WS->cm->id . '&tagid=' . $tag->id . '">' . tag_display_name($tag) . '</a>';
/*
* // when moodle-core (2.0?) allow to add custom items to
* // taglist page we can enable this.
*$links .= '<a href="'.$CFG->wwwroot.'/tag/index.php?'.
* '&id='.$tag->id.'">'.$tag->name.'</a>';
*/
if ($i != $size - 1) {
$links .= ', ';
}
}
return $links;
}
return '';
}
开发者ID:hmatulis,项目名称:RTL-BIDI-Hebrew-Moodle-Plugins,代码行数:34,代码来源:tags.lib.php
注:本文中的tag_get_tags函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论