Exemplo n.º 1
0
Arquivo: lib.php Projeto: r007/PMoodle
/**
 * 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);
}
Exemplo n.º 2
0
/**
 * 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 $limitnum return a subset comprising this many records (optional, default is 10)
 * @return array an array of tag objects
 */
function related_tags($tag_name_or_id, $limitnum = 10)
{
    $tag_id = tag_id_from_string($tag_name_or_id);
    //gets the manually added related tags
    if (!($manual_related_tags = get_item_tags('tag', $tag_id, 'ti.ordering ASC', DEFAULT_TAG_TABLE_FIELDS))) {
        $manual_related_tags = array();
    }
    //gets the correlated tags
    $automatic_related_tags = correlated_tags($tag_id);
    $related_tags = array_merge($manual_related_tags, $automatic_related_tags);
    return array_slice(object_array_unique($related_tags), 0, $limitnum);
}