atelierdisko/li3_taggable

This package is abandoned and no longer maintained. No replacement package was suggested.

Lithium behavior that let's you add tag support to models.

Installs: 2 134

Dependents: 9

Suggesters: 0

Security: 0

Stars: 1

Watchers: 3

Forks: 2

Type:lithium-library

v1.6.1 2018-07-11 14:34 UTC

README

The li3_taggable library aims to make it super simple to add tag functionality to your models.

Installation

The preferred installation method is via composer. You can add the library as a dependency via:

composer require atelierdisko/li3_taggable

li₃ plugins must be registered within your application bootstrap phase as they use a different (faster) autoloader.

Libraries::add('li3_taggable')

The official manual has more information on how to register the plugin with the app or use alternative installation methods (i.e. via GIT).

Features

  • Auto-Tagging
  • Namespaced Tags ('look:summer')
  • Tag filters to normalize tags
  • Augments finders to allow searching tags as a list even when data source do not support lists natively
  • Optional tag model, to store tags in a central place
  • Denormalized storage

Usage

To enable, add Taggable to the $_actsAs array in your model that uses li3_behaviors\data\model\Behaviors:

class Posts extends \lithium\data\Model {

    use li3_behaviors\data\model\Behaviors;

    protected static $_actsAs = [
        'Taggable' => [
            'field' => 'tags',
            'filters' => ['strtolower']
        ]
    ];
}

Advanced filtering of tagged records

The finder for data sources that do not support arrays, enables query operators on the serialized field, as if it was an array.

The default 'HAS ANY' operator is used when the value is an array of strings. It is implied when the value is an array and no operator is given. It selects the row when any of the given strings is in the tags:

Posts::find('all', ['conditions' => [
	'tags' => ['foo', 'bar']		
]]);

... which is equal to:

Posts::find('all', ['conditions' => [
	'tags' => ['HAS ANY' => ['foo', 'bar']]
]]);

The 'HAS ALL' operator selects records that have all of the given tags instead:

Posts::find('all', ['conditions' => [
	'tags' => ['HAS ALL' => ['foo', 'bar']]
]]);

The default 'HAS' operator is used when the value is a single string. It is implied when the value is a string and no operator is given. It selects the row when the given strings is found in the tags:

Posts::find('all', ['conditions' => [
	'tags' => 'foo'
]]);

... which is equal to:

Posts::find('all', ['conditions' => [
	'tags' => ['HAS' => 'foo']
]]);

Most operators can negated:

Posts::find('all', ['conditions' => [
	'tags' => ['NOT HAS' => 'foo']
]]);
Posts::find('all', ['conditions' => [
	'tags' => ['NOT HAS ANY' => ['foo', 'bar']]
]]);

Should the native 'REGEXP' operator be used, the re-formatting is skipped, and the query conditions are simply passed through:

Posts::find('all', ['conditions' => [
	'tags' => ['REGEXP' => '^foo']
]]);

More information

See the API documentation for li3_taggable\extensions\data\behavior\Taggable for more detailed information about exposed methods and configuration options.

Copyright & License

Copyright 2012 Affinitive LLC. All rights reserved. Copyright 2013 Marius Wilms. All rights reserved. Copyright 2016 Atelier Disko. All rights reserved.

This library is distributed under the terms of the BSD 3-Clause License. The full license text can be found in the LICENSE.txt file.