\RedBeanPHPTagManager

RedBeanPHP Tag Manager.

The tag manager offers an easy way to quickly implement basic tagging functionality.

Provides methods to tag beans and perform tag-based searches in the bean database.

Summary

Methods
Properties
Constants
__construct()
hasTag()
untag()
tag()
addTags()
tagged()
taggedAll()
countTaggedAll()
countTagged()
No public properties found
No constants found
findTagByTitle()
$toolbox
$associationManager
$redbean
N/A
extractTagsIfNeeded()
No private properties found
N/A

Properties

Methods

__construct()

__construct(\RedBeanPHP\ToolBox  $toolbox) 

Constructor.

The tag manager offers an easy way to quickly implement basic tagging functionality.

Parameters

\RedBeanPHP\ToolBox $toolbox

toolbox object

hasTag()

hasTag(\RedBeanPHP\OODBBean  $bean, array|string  $tags, boolean  $all = FALSE) : boolean

Tests whether a bean has been associated with one ore more of the listed tags. If the third parameter is TRUE this method will return TRUE only if all tags that have been specified are indeed associated with the given bean, otherwise FALSE.

If the third parameter is FALSE this method will return TRUE if one of the tags matches, FALSE if none match.

Tag list can be either an array with tag names or a comma separated list of tag names.

Usage:

R::hasTag( $blog, 'horror,movie', TRUE );

The example above returns TRUE if the $blog bean has been tagged as BOTH horror and movie. If the post has only been tagged as 'movie' or 'horror' this operation will return FALSE because the third parameter has been set to TRUE.

Parameters

\RedBeanPHP\OODBBean $bean

bean to check for tags

array|string $tags

list of tags

boolean $all

whether they must all match or just some

Returns

boolean

untag()

untag(\RedBeanPHP\OODBBean  $bean, array  $tagList) : void

Removes all specified tags from the bean. The tags specified in the second parameter will no longer be associated with the bean.

Tag list can be either an array with tag names or a comma separated list of tag names.

Usage:

R::untag( $blog, 'smart,interesting' );

In the example above, the $blog bean will no longer be associated with the tags 'smart' and 'interesting'.

Parameters

\RedBeanPHP\OODBBean $bean

tagged bean

array $tagList

list of tags (names)

tag()

tag(\RedBeanPHP\OODBBean  $bean, mixed  $tagList = NULL) : string

Part of RedBeanPHP Tagging API.

Tags a bean or returns tags associated with a bean. If $tagList is NULL or omitted this method will return a comma separated list of tags associated with the bean provided. If $tagList is a comma separated list (string) of tags all tags will be associated with the bean. You may also pass an array instead of a string.

Usage:

R::tag( $meal, "TexMex,Mexican" ); $tags = R::tag( $meal );

The first line in the example above will tag the $meal as 'TexMex' and 'Mexican Cuisine'. The second line will retrieve all tags attached to the meal object.

Parameters

\RedBeanPHP\OODBBean $bean

bean to tag

mixed $tagList

tags to attach to the specified bean

Returns

string

addTags()

addTags(\RedBeanPHP\OODBBean  $bean, array  $tagList) : void

Part of RedBeanPHP Tagging API.

Adds tags to a bean. If $tagList is a comma separated list of tags all tags will be associated with the bean. You may also pass an array instead of a string.

Usage:

R::addTags( $blog, ["halloween"] );

The example adds the tag 'halloween' to the $blog bean.

Parameters

\RedBeanPHP\OODBBean $bean

bean to tag

array $tagList

list of tags to add to bean

tagged()

tagged(string  $beanType, array|string  $tagList, string  $sql = '', array  $bindings = array()) : array

Returns all beans that have been tagged with one or more of the specified tags.

Tag list can be either an array with tag names or a comma separated list of tag names.

Usage:

$watchList = R::tagged( 'movie', 'horror,gothic', ' ORDER BY movie.title DESC LIMIT ?', [ 10 ] );

The example uses R::tagged() to find all movies that have been tagged as 'horror' or 'gothic', order them by title and limit the number of movies to be returned to 10.

Parameters

string $beanType

type of bean you are looking for

array|string $tagList

list of tags to match

string $sql

additional SQL (use only for pagination)

array $bindings

bindings

Returns

array

taggedAll()

taggedAll(string  $beanType, array|string  $tagList, string  $sql = '', array  $bindings = array()) : array

Returns all beans that have been tagged with ALL of the tags given.

This method works the same as R::tagged() except that this method only returns beans that have been tagged with all the specified labels.

Tag list can be either an array with tag names or a comma separated list of tag names.

Usage:

$watchList = R::taggedAll( 'movie', [ 'gothic', 'short' ], ' ORDER BY movie.id DESC LIMIT ? ', [ 4 ] );

The example above returns at most 4 movies (due to the LIMIT clause in the SQL Query Snippet) that have been tagged as BOTH 'short' AND 'gothic'.

Parameters

string $beanType

type of bean you are looking for

array|string $tagList

list of tags to match

string $sql

additional sql snippet

array $bindings

bindings

Returns

array

countTaggedAll()

countTaggedAll(string  $beanType, array|string  $tagList, string  $sql = '', array  $bindings = array()) : integer

Like taggedAll() but only counts.

Parameters

string $beanType

type of bean you are looking for

array|string $tagList

list of tags to match

string $sql

additional sql snippet

array $bindings

bindings

Returns

integer

countTagged()

countTagged(string  $beanType, array|string  $tagList, string  $sql = '', array  $bindings = array()) : integer

Like tagged() but only counts.

Parameters

string $beanType

type of bean you are looking for

array|string $tagList

list of tags to match

string $sql

additional sql snippet

array $bindings

bindings

Returns

integer

findTagByTitle()

findTagByTitle(string  $title) : \RedBeanPHP\OODBBean

Finds a tag bean by it's title.

Internal method.

Parameters

string $title

title to search for

Returns

\RedBeanPHP\OODBBean

extractTagsIfNeeded()

extractTagsIfNeeded(array|string  $tagList) : array

Checks if the argument is a comma separated string, in this case it will split the string into words and return an array instead.

In case of an array the argument will be returned 'as is'.

Parameters

array|string $tagList

list of tags

Returns

array