All Projects → ThingEngineer → PHP-TagEngine-Class

ThingEngineer / PHP-TagEngine-Class

Licence: other
Simplifies and automates the handeling of tags and tag maps.

Programming Languages

PHP
23972 projects - #3 most used programming language

TagEngine simplifies and automates the handeling of tags and tag maps in a system that requires one or more types of entities to be tagged.

Use tabels.sql to create the tag engine tabels and insert test data (tag types).

To utilize this class, first import TagEngine.php into your project, and require it.
This class also utilizes a MySQLi wrapper that can be found here: http://github.com/ajillion/PHP-MySQLi-Database-Class
It can easily be modified to support the ORM of your choice, or none at all if you enjoy using the crappy mysql_connect procedural method of database access.


require_once('Mysqlidb.php');
require_once('TagEngine.php');

After that, create a new instance of the MySQLi wrapper and the TagEngine.
Be sure to pass the newly created database object to the TagEnigne when you instantiate it.


$db = new Mysqlidb('host', 'username', 'password', 'databaseName');
$tagEngine = new TagEngine($db);

Setup Methods

Allows changing of the default TagEngine settings.


setTables('myTagsTable', 'myTagTypesTable', 'myTagMapsTable');   // Set up the tag engine tabels
$tagEngine->setTagLen(4);   // Set the minimum number of characters a tag must have.

mapTags Method

Creates tag maps to existing tags, and adds tags that do not exist yet.


$tagEngine->mapTags(100, 'img', 'tag1,tag2,tag3');		// Create's 3 new tags and maps them to the relative id 
                                                      //  of 100 with a type of img (Image).

getTagId Method

Retrives the tag id for the given tag name.


$tagEngine->getTagId('tag3');   // Retreive the tag id for 'tag3'.

getTagName Method

Retrives the tag name of the given tag id


$tagEngine->getTagName(1);   //  Gets the tag name for tag id 1

tagExists Method

Checks to see if the given tag exists.


if ($tagEngine->tagExists('tag5'))   // If the tag exists the method returns true, if it does not it returns false.
{
	echo 'true';
}else{
	echo 'false';
}

getTagTypeId Method

Retrives the id of the given type.


$tagEngine->getTagTypeId('img');   // Gets the id for type 'img' (Image)

getTags Method

Retrives tags mapped to an entity of a particular type and returns them in a zero indexed array.


$tagEngine->getTags(100, 'img');   // Gets all tags that are mapped to relative id 100 and type img (Image).

cleanTags Method

Removes all tag maps for the given relative id and type. Also removes the tag if it is no longer mapped to any other entity.


$tagEngine->cleanTags(100, 'img');   // Removes all tag maps to relative id 100 of type 'img' (Image) and deletes the tags
                                     // that weremapped to it (tag1,tag2,tag3) since they are no longer in use.

removeTagMap Method

Manualy remove one tag map with the given parameters.


$tagEngine->removeTagMap(100, 'img', 1); // Remove the tag map to relative id 100 of type 'img' (Image) where the tag id is 1

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].