PHP code example of carrooi / labels

1. Go to this page and download the library: Download carrooi/labels library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

carrooi / labels example snippets


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;
	}

}

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

}

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

}

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

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

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

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

$namespaces->removeNamespace($namespace);

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

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

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

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

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

$labels->removeLabel($label);

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

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

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

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

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

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