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


PHP tag_assign函数代码示例

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


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

示例1: tag_set

/**
 * Set the tags assigned to a record.  This overwrites the current tags.
 * 
 * This function is meant to be fed the string coming up from the user 
 * interface, which contains all tags assigned to a record.
 *
 * @param string $record_type the type of record to tag ('post' for blogs, 
 *     'user' for users, 'tag' for tags, etc.
 * @param int $record_id the id of the record to tag
 * @param array $tags the array of tags to set on the record. If 
 *     given an empty array, all tags will be removed.
 * @return void 
 */
function tag_set($record_type, $record_id, $tags)
{
    static $in_recursion_semaphore = false;
    // this is to prevent loops when tagging a tag
    if ($record_type == 'tag' && !$in_recursion_semaphore) {
        $current_tagged_tag_name = tag_get_name($record_id);
    }
    $tags_ids = tag_get_id($tags, TAG_RETURN_ARRAY);
    // force an array, even if we only have one tag.
    $cleaned_tags = tag_normalize($tags);
    //echo 'tags-in-tag_set'; var_dump($tags); var_dump($tags_ids); var_dump($cleaned_tags);
    $current_ids = tag_get_tags_ids($record_type, $record_id);
    //var_dump($current_ids);
    // for data coherence reasons, it's better to remove deleted tags
    // before adding new data: ordering could be duplicated.
    foreach ($current_ids as $current_id) {
        if (!in_array($current_id, $tags_ids)) {
            tag_delete_instance($record_type, $record_id, $current_id);
            if ($record_type == 'tag' && !$in_recursion_semaphore) {
                // if we are removing a tag-on-a-tag (manually related tag),
                // we need to remove the opposite relationship as well.
                tag_delete_instance('tag', $current_id, $record_id);
            }
        }
    }
    foreach ($tags as $ordering => $tag) {
        $tag = trim($tag);
        if (!$tag) {
            continue;
        }
        $clean_tag = $cleaned_tags[$tag];
        $tag_current_id = $tags_ids[$clean_tag];
        if (is_null($tag_current_id)) {
            // create new tags
            //echo "call to add tag $tag\n";
            $new_tag = tag_add($tag);
            $tag_current_id = $new_tag[$clean_tag];
        }
        tag_assign($record_type, $record_id, $tag_current_id, $ordering);
        // if we are tagging a tag (adding a manually-assigned related tag), we
        // need to create the opposite relationship as well.
        if ($record_type == 'tag' && !$in_recursion_semaphore) {
            $in_recursion_semaphore = true;
            tag_set_add('tag', $tag_current_id, $current_tagged_tag_name);
            $in_recursion_semaphore = false;
        }
    }
}
开发者ID:r007,项目名称:PMoodle,代码行数:61,代码来源:lib.php

示例2: coursetag_store_keywords

/**
 * Stores a tag for a course for a user
 *
 * @uses $CFG
 * @param array $tags simple array of keywords to be stored
 * @param integer $courseid
 * @param integer $userid
 * @param string $tagtype official or default only
 * @param string $myurl optional for logging creation of course tags
 */
function coursetag_store_keywords($tags, $courseid, $userid=0, $tagtype='official', $myurl='') {

    global $CFG;

    if (is_array($tags) and !empty($tags)) {
        foreach($tags as $tag) {
            $tag = trim($tag);
            if (strlen($tag) > 0) {
                //tag_set_add('course', $courseid, $tag, $userid); //deletes official tags

                //add tag if does not exist
                if (!$tagid = tag_get_id($tag)) {
                    $tag_id_array = tag_add(array($tag), $tagtype);
                    $tagid = $tag_id_array[moodle_strtolower($tag)];
                }
                //ordering
                $ordering = 0;
                if ($current_ids = tag_get_tags_ids('course', $courseid)) {
                    end($current_ids);
                    $ordering = key($current_ids) + 1;
                }
                //set type
                tag_type_set($tagid, $tagtype);

                //tag_instance entry
                tag_assign('course', $courseid, $tagid, $ordering, $userid);

                //logging - note only for user added tags
                if ($tagtype == 'default' and $myurl != '') {
                    $url = $myurl.'?query='.urlencode($tag);
                    add_to_log($courseid, 'coursetags', 'add', $url, 'Course tagged');
                }
            }
        }
    }

}
开发者ID:rolandovanegas,项目名称:moodle,代码行数:47,代码来源:coursetagslib.php

示例3: test_tag_deleted

 /**
  * Test the tag deleted event.
  */
 public function test_tag_deleted()
 {
     global $DB;
     $this->setAdminUser();
     // Create a course.
     $course = $this->getDataGenerator()->create_course();
     // Create tag we are going to delete.
     $tag = $this->getDataGenerator()->create_tag();
     // Trigger and capture the event for deleting a tag.
     $sink = $this->redirectEvents();
     tag_delete($tag->id);
     $events = $sink->get_events();
     $event = reset($events);
     // Check that the tag was deleted and the event data is valid.
     $this->assertEquals(0, $DB->count_records('tag'));
     $this->assertInstanceOf('\\core\\event\\tag_deleted', $event);
     $this->assertEquals(context_system::instance(), $event->get_context());
     // Create two tags we are going to delete to ensure passing multiple tags work.
     $tag = $this->getDataGenerator()->create_tag();
     $tag2 = $this->getDataGenerator()->create_tag();
     // Trigger and capture the events for deleting multiple tags.
     $sink = $this->redirectEvents();
     tag_delete(array($tag->id, $tag2->id));
     $events = $sink->get_events();
     // Check that the tags were deleted and the events data is valid.
     $this->assertEquals(0, $DB->count_records('tag'));
     foreach ($events as $event) {
         $this->assertInstanceOf('\\core\\event\\tag_deleted', $event);
         $this->assertEquals(context_system::instance(), $event->get_context());
     }
     // Create another tag to delete.
     $tag = $this->getDataGenerator()->create_tag();
     // Add a tag instance to a course.
     tag_assign('course', $course->id, $tag->id, 0, 2, 'course', context_course::instance($course->id)->id);
     // Trigger and capture the event for deleting a personal tag for a user for a course.
     $sink = $this->redirectEvents();
     coursetag_delete_keyword($tag->id, 2, $course->id);
     $events = $sink->get_events();
     $event = $events[1];
     // Check that the tag was deleted and the event data is valid.
     $this->assertEquals(0, $DB->count_records('tag'));
     $this->assertInstanceOf('\\core\\event\\tag_deleted', $event);
     $this->assertEquals(context_system::instance(), $event->get_context());
     // Create a new tag we are going to delete.
     $tag = $this->getDataGenerator()->create_tag();
     // Add the tag instance to the course again as it was deleted.
     tag_assign('course', $course->id, $tag->id, 0, 2, 'course', context_course::instance($course->id)->id);
     // Trigger and capture the event for deleting all tags in a course.
     $sink = $this->redirectEvents();
     coursetag_delete_course_tags($course->id);
     $events = $sink->get_events();
     $event = $events[1];
     // Check that the tag was deleted and the event data is valid.
     $this->assertEquals(0, $DB->count_records('tag'));
     $this->assertInstanceOf('\\core\\event\\tag_deleted', $event);
     $this->assertEquals(context_system::instance(), $event->get_context());
     // Create two tags we are going to delete to ensure passing multiple tags work.
     $tag = $this->getDataGenerator()->create_tag();
     $tag2 = $this->getDataGenerator()->create_tag();
     // Add multiple tag instances now and check that it still works.
     tag_assign('course', $course->id, $tag->id, 0, 2, 'course', context_course::instance($course->id)->id);
     tag_assign('course', $course->id, $tag2->id, 0, 2, 'course', context_course::instance($course->id)->id);
     // Trigger and capture the event for deleting all tags in a course.
     $sink = $this->redirectEvents();
     coursetag_delete_course_tags($course->id);
     $events = $sink->get_events();
     $events = array($events[2], $events[3]);
     // Check that the tags were deleted and the events data is valid.
     $this->assertEquals(0, $DB->count_records('tag'));
     foreach ($events as $event) {
         $this->assertInstanceOf('\\core\\event\\tag_deleted', $event);
         $this->assertEquals(context_system::instance(), $event->get_context());
     }
 }
开发者ID:janaece,项目名称:globalclassroom4_clean,代码行数:77,代码来源:events_test.php

示例4: test_tag_assign

 /**
  * Test the tag_assign function.
  * This function was deprecated in 3.1
  */
 public function test_tag_assign()
 {
     global $DB;
     // Create a course to tag.
     $course = $this->getDataGenerator()->create_course();
     // Create the tag.
     $tag = $this->getDataGenerator()->create_tag();
     $tag2 = $this->getDataGenerator()->create_tag();
     // Tag the course with the tag we created.
     tag_assign('course', $course->id, $tag->id, 0, 0, 'core', context_course::instance($course->id)->id);
     $this->assertDebuggingCalled();
     // Get the tag instance that should have been created.
     $taginstance = $DB->get_record('tag_instance', array('itemtype' => 'course', 'itemid' => $course->id), '*', MUST_EXIST);
     $this->assertEquals('core', $taginstance->component);
     $this->assertEquals(context_course::instance($course->id)->id, $taginstance->contextid);
     // Now call the tag_assign function without specifying the component or
     // contextid and ensure the function debugging is called twice.
     tag_assign('course', $course->id, $tag2->id, 0, 0);
     $this->assertDebuggingCalled();
 }
开发者ID:bewanyk,项目名称:moodle,代码行数:24,代码来源:taglib_test.php

示例5: coursetag_store_keywords

/**
 * Stores a tag for a course for a user
 *
 * @package  core_tag
 * @category tag
 * @param    array  $tags     simple array of keywords to be stored
 * @param    int    $courseid the id of the course we wish to store a tag for
 * @param    int    $userid   the id of the user we wish to store a tag for
 * @param    string $tagtype  official or default only
 * @param    string $myurl    (optional) for logging creation of course tags
 */
function coursetag_store_keywords($tags, $courseid, $userid = 0, $tagtype = 'official', $myurl = '')
{
    global $CFG;
    if (is_array($tags) and !empty($tags)) {
        foreach ($tags as $tag) {
            $tag = trim($tag);
            if (strlen($tag) > 0) {
                //tag_set_add('course', $courseid, $tag, $userid); //deletes official tags
                //add tag if does not exist
                if (!($tagid = tag_get_id($tag))) {
                    $tag_id_array = tag_add(array($tag), $tagtype);
                    $tagid = $tag_id_array[core_text::strtolower($tag)];
                }
                //ordering
                $ordering = 0;
                if ($current_ids = tag_get_tags_ids('course', $courseid)) {
                    end($current_ids);
                    $ordering = key($current_ids) + 1;
                }
                //set type
                tag_type_set($tagid, $tagtype);
                //tag_instance entry
                tag_assign('course', $courseid, $tagid, $ordering, $userid, 'core', context_course::instance($courseid)->id);
            }
        }
    }
}
开发者ID:janaece,项目名称:globalclassroom4_clean,代码行数:38,代码来源:coursetagslib.php

示例6: coursetag_store_keywords

/**
 * Stores a tag for a course for a user
 *
 * @deprecated since 3.0
 * @package  core_tag
 * @category tag
 * @param    array  $tags     simple array of keywords to be stored
 * @param    int    $courseid the id of the course we wish to store a tag for
 * @param    int    $userid   the id of the user we wish to store a tag for
 * @param    string $tagtype  official or default only
 * @param    string $myurl    (optional) for logging creation of course tags
 */
function coursetag_store_keywords($tags, $courseid, $userid = 0, $tagtype = 'official', $myurl = '')
{
    debugging('Function coursetag_store_keywords() is deprecated. Userid is no longer used for tagging courses.', DEBUG_DEVELOPER);
    global $CFG;
    require_once $CFG->dirroot . '/tag/lib.php';
    if (is_array($tags) and !empty($tags)) {
        foreach ($tags as $tag) {
            $tag = trim($tag);
            if (strlen($tag) > 0) {
                //tag_set_add('course', $courseid, $tag, $userid); //deletes official tags
                //add tag if does not exist
                if (!($tagid = tag_get_id($tag))) {
                    $tag_id_array = tag_add(array($tag), $tagtype);
                    $tagid = $tag_id_array[core_text::strtolower($tag)];
                }
                //ordering
                $ordering = 0;
                if ($current_ids = tag_get_tags_ids('course', $courseid)) {
                    end($current_ids);
                    $ordering = key($current_ids) + 1;
                }
                //set type
                tag_type_set($tagid, $tagtype);
                //tag_instance entry
                tag_assign('course', $courseid, $tagid, $ordering, $userid, 'core', context_course::instance($courseid)->id);
            }
        }
    }
}
开发者ID:nickbert77,项目名称:moodle,代码行数:41,代码来源:deprecatedlib.php

示例7: test_tag_bulk_delete_instances

 /**
  * Test deleting a group of tag instances.
  */
 public function test_tag_bulk_delete_instances()
 {
     global $DB;
     // Setup.
     $user = $this->getDataGenerator()->create_user();
     $course = $this->getDataGenerator()->create_course();
     $context = context_course::instance($course->id);
     // Create some tag instances.
     for ($i = 0; $i < 10; $i++) {
         $tag = $this->getDataGenerator()->create_tag(array('userid' => $user->id));
         tag_assign('course', $course->id, $tag->id, 0, 0, 'core', $context->id);
     }
     // Get tag instances. tag name and rawname are required for the event fired in this function.
     $sql = "SELECT ti.*, t.name, t.rawname\n                  FROM {tag_instance} ti\n                  JOIN {tag} t ON t.id = ti.tagid";
     $taginstances = $DB->get_records_sql($sql);
     $this->assertCount(10, $taginstances);
     // Run the function.
     tag_bulk_delete_instances($taginstances);
     // Make sure they are gone.
     $instancecount = $DB->count_records('tag_instance');
     $this->assertEquals(0, $instancecount);
 }
开发者ID:educakanchay,项目名称:campus,代码行数:25,代码来源:taglib_test.php


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