PHPackages                             carrooi/favorites - 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/favorites

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

carrooi/favorites
=================

Favorites bundle for Nette

1.0.2(10y ago)03931MITPHPPHP &gt;=5.4

Since Jan 30Pushed 10y ago1 watchersCompare

[ Source](https://github.com/Carrooi/Nette-Favorites)[ Packagist](https://packagist.org/packages/carrooi/favorites)[ RSS](/packages/carrooi-favorites/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependencies (10)Versions (4)Used By (0)

Carrooi/Favorites
=================

[](#carrooifavorites)

[![Build Status](https://camo.githubusercontent.com/50c7d69783141cdb15e5995faa214133a1f040c8547af9bc67d3cfa6253b9ce5/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f436172726f6f692f4e657474652d4661766f72697465732e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/Carrooi/Nette-Favorites)[![Donate](https://camo.githubusercontent.com/7f8b0c0980ad316210d1ec0c7d3298ace87d2f7c0eb6911977c0644951af5bd2/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f646f6e6174652d50617950616c2d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=BQN5R3E85DJRS)

Favorites module in Doctrine for Nette framework.

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

[](#installation)

```
$ composer require carrooi/favorites
$ composer update

```

Then just enable nette extension in your config.neon:

```
extensions:
	favorites: Carrooi\Favorites\DI\FavoritesExtension
```

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

[](#configuration)

```
extensions:
	favorites: Carrooi\Favorites\DI\FavoritesExtension

favorites:

	userClass: App\Model\Entities\User
```

As you can see, the only thing you need to do is set your `user` class which implements `Carrooi\Favorites\Model\Entities\IUserEntity` interface.

Usage
-----

[](#usage)

Lets create our `User` implementation.

```
namespace App\Model\Entities;

use Carrooi\Favorites\Model\Entities\IUserEntity;
use Doctrine\ORM\Mapping as ORM;

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

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

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

}
```

Now imagine that you want to be able to add entity `Article` to favorites.

```
namespace App\Model\Entities;

use Carrooi\Favorites\Model\Entities\IFavoritableEntity;
use Carrooi\Favorites\Model\Entities\TFavorites;
use Doctrine\ORM\Mapping as ORM;

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

	use TFavorites;

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

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

}
```

Please notice that you can use `TFavorites` trait, which implements all methods from `IFavoritableEntity` interface.

**Do not forget to update your database schema after every change.**

### Manipulation

[](#manipulation)

You can use prepared `Carrooi\Favorites\Model\Facades\FavoritesFacade` service for manipulations with favorites.

#### Add to favorites

[](#add-to-favorites)

```
$article = $this->articles->createSomehow();
$user = $this->users->getCurrentSomehow();

$favoritesFacade->addItemToFavorites($user, $article);
```

#### Remove from favorites

[](#remove-from-favorites)

```
$article = $this->articles->getCurrentSomehow();
$user = $this->users->getCurrentSomehow();

$favoritesFacade->removeItemFromFavorites($user, $article);
```

#### Is item in favorites

[](#is-item-in-favorites)

```
$article = $this->articles->getCurrentSomehow();
$user = $this->users->getCurrentSomehow();

$favoritesFacade->hasItemInFavorites($user, $article);
```

#### Find all items by user and type

[](#find-all-items-by-user-and-type)

```
$user = $this->user->getCurrentSomehow();

$favoritesFacade->findAllItemsByUserAndType($user, Article::getClassName());
```

#### Find all by user and type

[](#find-all-by-user-and-type)

Similar to previous method, but will return `FavoriteItem` entities, not `IFavoritableEntity`.

```
$user = $this->user->getCurrentSomehow();

$favoritesFacade->findAllByUserAndType($user, Article::getClassName());
```

**That method can be used only in combination with custom associations. See bellow**

#### Find all favorites by user

[](#find-all-favorites-by-user)

```
$user = $this->user->getCurrentSomehow();

$favoritesFacade->findAllByUser($user);
```

**That method can be used only in combination with custom associations. See bellow**

#### Count by user

[](#count-by-user)

```
$user = $this->user->getCurrentSomehow();

$favoritesFacade->getCountByUser($user);
```

Custom FavoriteItem entity
--------------------------

[](#custom-favoriteitem-entity)

```
favorites:

	userClass: App\Model\Entities\User
	favoriteItemClass: App\Model\Entities\FavoriteItem
```

```
namespace App\Model\Entities;

use Carrooi\Favorites\Model\Entities\FavoriteItem;
use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity
 * @author David Kudera
 */
class FavoriteItem extends FavoriteItem
{

	// ...

}
```

This will come in handy when you'll want to use `FavoriteItem` entity in your queries with `JOIN`.

Just imagine that you want to have eg. `getArticle()` method in `FavoriteItem` entity.

```
namespace App\Model\Entities;

use Carrooi\Favorites\Model\Entities\FavoriteItem;
use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity
 * @author David Kudera
 */
class FavoriteItem extends FavoriteItem
{

	/** @var \App\Model\Entities\Article */
	private $article;

	/**
	 * @return \App\Model\Entities\Article
	 */
	public function getArticle()
	{
		return $this->article;
	}

	/**
	 * @param \App\Model\Entities\Article $article
	 * @return $this
	 */
	public function setArticle(Article $article)
	{
		$this->article = $article;
		return $this;
	}

}
```

And add configuration:

```
favorites:

	userClass: App\Model\Entities\User
	favoriteItemClass: App\Model\Entities\FavoriteItem

	associations:
		App\Model\Entities\Article:
			field: article
			setter: setArticle
```

Now you have your own implementation of `FavoriteItem` entity.

**Please also notice that if you'll use this custom association mapping, this module will work with one-to-many relations. Otherwise it will be many-to-many.**

Changelog
---------

[](#changelog)

- 1.0.2

    - Add missing cascade removing for user [\#1](https://github.com/Carrooi/Nette-Favorites/pull/1)
- 1.0.1

    - Fixed tests running under nette 2.3
    - Fix relations mapping
- 1.0.0

    - First version

###  Health Score

28

—

LowBetter than 52% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity60

Established project with proven stability

 Bus Factor1

Top contributor holds 95.5% 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

Every ~227 days

Total

3

Last Release

3717d 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 (21 commits)")[![rutrader](https://avatars.githubusercontent.com/u/1757341?v=4)](https://github.com/rutrader "rutrader (1 commits)")

---

Tags

nettecarrooiFavorites

### Embed Badge

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

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

###  Alternatives

[nette/component-model

⚛ Nette Component Model

28817.0M106](/packages/nette-component-model)[nette/code-checker

✅ Nette CodeChecker: A simple tool to check source code against a set of Nette coding standards.

911.7M6](/packages/nette-code-checker)

PHPackages © 2026

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