PHPackages                             carrooi/labels - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. carrooi/labels

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

carrooi/labels
==============

Labels module for Nette

1.0.0(11y ago)017MITPHP

Since Feb 12Pushed 11y ago1 watchersCompare

[ Source](https://github.com/Carrooi/Nette-Labels)[ Packagist](https://packagist.org/packages/carrooi/labels)[ RSS](/packages/carrooi-labels/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (9)Versions (2)Used By (0)

Carrooi/Labels
==============

[](#carrooilabels)

[![Build Status](https://camo.githubusercontent.com/8cae940ccab72296aefa254ce07f954c10296c611538e924a49253f72e1b3928/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f436172726f6f692f4e657474652d4c6162656c732e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/Carrooi/Nette-Labels)[![Donate](https://camo.githubusercontent.com/7f8b0c0980ad316210d1ec0c7d3298ace87d2f7c0eb6911977c0644951af5bd2/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f646f6e6174652d50617950616c2d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=5LPZU9QNQAVTC)

Labels module for Nette framework.

Now any doctrine entity can be turned to "labelable" entity (imagine your gmail mails with labels).

Installation
------------

[](#installation)

```
$ composer require carrooi/labels
$ composer update

```

Configuration
-------------

[](#configuration)

```
extensions:
	labels: Carrooi\Labels\DI\LabelsExtension

labels:

	ownerClass: App\Model\Entities\User
	labelItemClass: App\Model\Entities\LabelItem

	entities:
		App\Model\Entities\Mail: mail
		App\Model\Entities\Article: article
```

- **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)

Owner entity must implement `Carrooi\Labels\Model\Entities\ILabelOwner` interface with only one method:

- `getId()`: returns identifier

```
namespace App\Model\Entities;

use Carrooi\Labels\Model\Entities\ILabelOwner;
use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity
 * @author David Kudera
 */
class User implements ILabelOwner
{

	// ...

	/**
	 * @return int
	 */
	public function getId()
	{
		return $this->id;
	}

}
```

LabelItem entity
----------------

[](#labelitem-entity)

Entity which must implement `Carrooi\Labels\Model\Entities\ILabelItem` interface with these methods:

- `getId()`: returns identifier
- `getLabel()`: returns `Carrooi\Labels\Model\Entities\Label` entity
- `setLabel()`: sets `Carrooi\Labels\Model\Entities\Label` entity

Instead of implementing last two methods on your own, you can use prepared `Carrooi\Labels\Model\Entities\TLabelItem` trait.

```
namespace App\Model\Entities;

use Carrooi\Labels\Model\Entities\ILabelItem;
use Carrooi\Labels\Model\Entities\TLabelItem;
use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity
 * @author David Kudera
 */
class LabelItem implements ILabelItem
{

	use TLabelItem;

	/**
	 * @ORM\Id
	 * @ORM\Column(type="integer")
	 * @var int
	 */
	private $id;

	/**
	 * @ORM\ManyToOne(targetEntity="\App\Model\Entities\Mail")
	 * @var \App\Model\Entities\Mail
	 */
	private $mail;

	/**
	 * @ORM\ManyToOne(targetEntity="\App\Model\Entities\Article")
	 * @var \App\Model\Entities\Article
	 */
	private $article;

	/**
	 * @return int
	 */
	public function getId()
	{
		return $this->id;
	}

	// ... other getters and setters for mail and article fields

}
```

Labelable entity
----------------

[](#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 identifier
- `getLabelItems()`: returns array of `Carrooi\Labels\Model\Entities\ILabelItem` entities
- `addLabelItem()`: adds now `Carrooi\Labels\Model\Entities\ILabelItem` entity to label items collection
- `removeLabelItem()`: removes `Carrooi\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.

```
namespace CarrooiTests\LabelsApp\Model\Entities;

use Carrooi\Labels\Model\Entities\ILabelableEntity;
use Carrooi\Labels\Model\Entities\TLabelable;
use Kdyby\Doctrine\Entities\Attributes\Identifier;
use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity
 * @author David Kudera
 */
class Article implements ILabelableEntity
{

	use TLabelable;

	// ... your own fields

	/**
	 * @return int
	 */
	public function getId()
	{
		return $this->id;
	}

	// ... some other getters and setters

}
```

Usage
-----

[](#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
-----------------------

[](#label-namespaces-facade)

For working with namespaces you can use registered service `Carrooi\Labels\Model\Facades\LabelNamespacesFacade`.

**Create new namespace**:

```
$namespace = $namespaces->addNamespace('articles');
```

**Find namespace**:

```
$namespace = $namespaces->findNamespace('articles');
```

**Get all namespaces**:

```
foreach ($namespaces->getNamespaces() as $namespace) {
	// ...
}
```

**Rename namespace**:

```
$namespaces->renameNamespace($namespace, 'mails');
```

**Remove namespace**:

```
$namespaces->removeNamespace($namespace);
```

Labels facade
-------------

[](#labels-facade)

Now you can let your users create own labels. There is `Carrooi\Labels\Model\Facades\LabelsFacade` service for that.

**Creating label**:

```
$label = $labels->addLabel($namespace, $owner, 'Best articles', 'best');
```

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**:

```
foreach ($labels->getLabels($namespace, $owner) as $label) {
	// ...
}
```

**Find label by system name**:

```
$label = $labels->findLabel($namespace, $owner, 'best');
```

**Find label by id**:

```
$label = $labels->findLabelById($id);
```

**Rename label**:

```
$labels->renameLabel($label, 'Super articles', 'super');
```

You can replace 2nd and 3rd arguments with nulls.

**Remove label**:

```
$labels->removeLabel($label);
```

Label items facade
------------------

[](#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**:

```
$labelItems->addItemToLabel($article, $label);
```

**Find label item entity by labelable item**:

```
$labelItem = $labelItems->findItem($article, $label);
```

**Is labelable item in label?**:

```
$labelItems->isItemInLabel($article, $label);
```

**Get all label items in label**:

```
foreach ($labelItems->getItems($label) as $labelItem) {
	// ...
}
```

**Get labelable items by type**:

```
foreach ($labelItems->getItemsByType($label, Article::class) as $article) {
	// ...
}
```

**Remove labelable item from label**:

```
$labelItems->removeItemFromLabel($label, $item);
```

Changelog
---------

[](#changelog)

- 1.0.0
    - Initial version

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity63

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

4112d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/838c6933d498fdb2a31f251ed45006a6ef97935ea2a27f38dab7738038939fc9?d=identicon)[david\_kudera](/maintainers/david_kudera)

---

Top Contributors

[![davidkudera](https://avatars.githubusercontent.com/u/1174072?v=4)](https://github.com/davidkudera "davidkudera (12 commits)")

---

Tags

nettecarrooilabels

### Embed Badge

![Health badge](/badges/carrooi-labels/health.svg)

```
[![Health](https://phpackages.com/badges/carrooi-labels/health.svg)](https://phpackages.com/packages/carrooi-labels)
```

###  Alternatives

[contributte/menu-control

Menu control for Nette framework

29108.6k1](/packages/contributte-menu-control)[carrooi/nette-menu

Menu control for Nette framework

2950.0k1](/packages/carrooi-nette-menu)[ipub/gravatar

Gravatar creator for Nette Framework

122.0k1](/packages/ipub-gravatar)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
