Download the PHP package carrooi/labels without Composer
On this page you can find all versions of the php package carrooi/labels. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package labels
Carrooi/Labels
Labels module for Nette framework.
Now any doctrine entity can be turned to "labelable" entity (imagine your gmail mails with labels).
Installation
Configuration
- ownerClass: Most probably your
User
entity - labelItemClass: Entity with associations between your labels and labelable entities
- entities: List of labelable entities with name of column in your
LabelItem
entity
Owner entity
Owner entity must implement Carrooi\Labels\Model\Entities\ILabelOwner
interface with only one method:
getId()
: returns identifier
LabelItem entity
Entity which must implement Carrooi\Labels\Model\Entities\ILabelItem
interface with these methods:
getId()
: returns identifiergetLabel()
: returnsCarrooi\Labels\Model\Entities\Label
entitysetLabel()
: setsCarrooi\Labels\Model\Entities\Label
entity
Instead of implementing last two methods on your own, you can use prepared Carrooi\Labels\Model\Entities\TLabelItem
trait.
Labelable entity
Last thing is to update your labelable entities, eg. our Mail
entity.
Each labelable entity must implement Carrooi\Labels\Model\Entities\ILabelableEntity
interface with these methods:
getId()
: returns identifiergetLabelItems()
: returns array ofCarrooi\Labels\Model\Entities\ILabelItem
entitiesaddLabelItem()
: adds nowCarrooi\Labels\Model\Entities\ILabelItem
entity to label items collectionremoveLabelItem()
: removesCarrooi\Labels\Model\Entities\ILabelItem
entity from label items collection
Again you don't need to implement these methods (except for getId()
) on your own, but simply use Carrooi\Labels\Model\Entities\TLabelable
trait.
Usage
The main idea is that you have more label namespaces in which you (or your users) can create new labels. Of course if you want, you can have just one main namespace and all labels in that namespace. Example of this aproach is eg. GitHub where your labels are shared between issues and pull requests.
These namespaces will be probably "hard-defined" in your project and database.
Label namespaces facade
For working with namespaces you can use registered service Carrooi\Labels\Model\Facades\LabelNamespacesFacade
.
Create new namespace:
Find namespace:
Get all namespaces:
Rename namespace:
Remove namespace:
Labels facade
Now you can let your users create own labels. There is Carrooi\Labels\Model\Facades\LabelsFacade
service for that.
Creating label:
Last argument is for "system name" of label and is not required. This can come in handy if you have some default labels and you want to work with them later.
Get all labels:
Find label by system name:
Find label by id:
Rename label:
You can replace 2nd and 3rd arguments with nulls.
Remove label:
Label items facade
Last facade class is Carrooi\Labels\Model\Facades\LabelItemsFacade
which is again registered as service in DI container.
With this service you can manage actual labelable entities in created labels.
Add labelable item to label:
Find label item entity by labelable item:
Is labelable item in label?:
Get all label items in label:
Get labelable items by type:
Remove labelable item from label:
Changelog
- 1.0.0
- Initial version
All versions of labels with dependencies
nette/di Version ~2.2
nette/application Version ~2.2
kdyby/doctrine Version ~2.2
kdyby/events Version ~2.3