Welcompose
[ class tree: Welcompose ] [ index: Welcompose ] [ all elements ]

Class: Media_Tag

Source Location: /media_classes/tag.class.php

Class Overview




Variables

Methods



Class Details

[line 38]


[ Top ]


Class Variables

static $instance =  null

[line 45]

Singleton



Tags:

access:  public

Type:   object


[ Top ]

$base =  null

[line 52]

Reference to base class



Tags:

access:  public

Type:   object


[ Top ]

$_tag_separator =  ','

[line 60]

Tag separator used when converting tag strings to arrays and vice versa.



Tags:

access:  public

Type:   mixed


[ Top ]



Class Methods


constructor __construct [line 67]

Media_Tag __construct( )

Start instance of base class, load configuration and establish database connection. Please don't call the constructor direcly, use the singleton pattern instead.



Tags:

access:  public


[ Top ]

method addLink [line 658]

int addLink( int $object, int $tag)

Adds link between object and tag. Takes the object id as first

argument, the tag word id as second argument. First, the function will look up, if the link exists. If it doesn't exists, the function will add one. If it already exist, nothing happens. The function always returns boolean true.




Tags:

return:  Link id
throws:  Media_TagException
access:  protected


Parameters:

int   $object   Object id
int   $tag   Tag id

[ Top ]

method addTag [line 201]

int addTag( int $object, string $tag)

Inserts a tag into the tag table. Takes the object which the tag will be linked to as first argument and the tag word as third second.

The amount of occurrences will be set to 1. If the tag already exists in the database, updateTag() will be called.




Tags:

return:  Tag id
throws:  Media_TagException
access:  protected


Parameters:

int   $object   Object id
string   $tag   Tag word

[ Top ]

method addTags [line 94]

bool addTags( int $object, array $tags)

Adds tags of a object. Takes the object id as first argument, the tag list as second argument. Returns bool.



Tags:

throws:  Media_TagException
access:  public


Parameters:

int   $object   Object id
array   $tags   Tag array

[ Top ]

method deleteLink [line 695]

bool deleteLink( int $object, int $tag)

Removes link between object and tag. Takes the object id as first argument, the tag word id as second argument. First, the function will look up, if the link exists. If it exists, it will be deleted. If it doesn't exist, nothing happens. The function always returns boolean true.



Tags:

throws:  Media_TagException
access:  protected


Parameters:

int   $object   Object id
int   $tag   Tag id

[ Top ]

method deleteTag [line 349]

bool deleteTag( int $object, string $tag)

Removes tag. Takes the object id as first argument and the

tag word as second argument. First, the function will decrease the occurrences (-1) and then remove every tag where the amount of occurrences is 0 (null). Then it will remove the link between the tag and the object.




Tags:

throws:  Media_TagException
access:  protected


Parameters:

int   $object   Object id
string   $tag   Tag word

[ Top ]

method deleteTags [line 172]

bool deleteTags( int $object, array 1)

Deletes all tags of a object. Takes the object id as first argument.

Returns bool.




Tags:

throws:  tagException
access:  public


Parameters:

array   1   Tag array
int   $object   Object id

[ Top ]

method link_exists [line 599]

mixed link_exists( int $object, int $tag)

Check for link between object id and tag word. Takes object id as first argument, tag word id as second argument. Return bool on false and int (Link id) on true.



Tags:

throws:  Media_TagException
access:  public


Parameters:

int   $object   Object id
int   $tag   Tag id

[ Top ]

method selectTag [line 385]

array selectTag( int $id)

Selects tag. Takes tag word id as first argument. Returns tag information.



Tags:

throws:  Media_TagException
access:  public


Parameters:

int   $id   Tag word id

[ Top ]

method selectTags [line 447]

array selectTags( [array $params = array()])

Selects tags. Takes array with select params as first argument. Returns array with tags.

List of supported parameters

  • project: int, project id
  • object: int, object id
  • start: int, article offset
  • limit: int, amount of articles to return
  • order_marco, string, otpional: How to sort the result set. Supported macros:
    • FIRST_CHAR: sort by first char
    • WORD: sorty by tag word
    • OCCURRENCES: sorty by occurrences
</ul>




Tags:

throws:  Media_TagException
access:  public


Parameters:

array   $params   Select params

[ Top ]

method tag_exists [line 552]

mixed tag_exists( string $tag)

Function to look up if the tag is already in the database. Takes the tag word (some scalar value) as first argument. Returns the tag id in the database (int) or, if the tag wasn't found, boolean false.



Tags:

throws:  Media_TagException
access:  public


Parameters:

string   $tag   Tag word

[ Top ]

method updateTag [line 255]

int updateTag( int $object, string $tag, [string $modify_amount = 'increase'])

Function to increase/decrease occurrences of tag words and to add/remove links between tag words. Takes the object id as first argument, the tag word as second argument and the instruction how to modify the occurrences as third argument.

modify_amount can be either increase or decrease.




Tags:

return:  Tag id
throws:  Media_TagException
access:  protected


Parameters:

int   $object   Object id
string   $tag   Tag word
string   $modify_amount   Modify amount

[ Top ]

method updateTags [line 125]

bool updateTags( int $object, array $tags)

Update tags of an object. Takes the object id as first argument and the new tag list as second argument. Fetches the old tag list from the database and calculates the differences. Tags that are no longer required will be removed, new ones will be added.



Tags:

throws:  Media_TagException
access:  public


Parameters:

int   $object   Object id
array   $tags   Tag array

[ Top ]

method _prepareTagStringForQuery [line 780]

array _prepareTagStringForQuery( string $string)

Prepares tag string for tag query. Takes a string of tags, each separated by Tag::_tag_separator, as first argument. Returns array.



Tags:

return:  Tag array
throws:  Media_TagException
access:  public


Parameters:

string   $string   Tag string

[ Top ]

method _tagArrayToString [line 759]

array _tagArrayToString( string $array)

Helper function to convert a array of tags into a string of tags, each separated by a comma. Useful when it's required to prepare data for a user input field.



Tags:

return:  Tag array
throws:  Media_TagException
access:  public


Parameters:

string   $array   Tag string

[ Top ]

method _tagStringToArray [line 732]

array _tagStringToArray( string $string)

Helper function to convert a string of tags, each separated by a comma, into an array. Useful when receiving data from a an user input field.



Tags:

return:  Tag array
throws:  Media_TagException
access:  public


Parameters:

string   $string   Tag string

[ Top ]


Documentation generated on Sun, 08 Jan 2012 17:52:05 +0100 by phpDocumentor 1.4.3