Skip to content

Instantly share code, notes, and snippets.

@arnolanglade
Last active April 9, 2018 10:20
Show Gist options
  • Save arnolanglade/ee97a245af22aa6f70c5c94ab9a58672 to your computer and use it in GitHub Desktop.
Save arnolanglade/ee97a245af22aa6f70c5c94ab9a58672 to your computer and use it in GitHub Desktop.
<?php
namespace Akeneo\Bundle\ClassificationBundle\Doctrine\ORM\Repository;
use Akeneo\Bundle\StorageUtilsBundle\Doctrine\ORM\Repository\SearchableRepository;
use Akeneo\Component\Classification\Repository\TagRepositoryInterface;
/**
* Tag repository
*
* @author Willy Mesnage <[email protected]>
* @copyright 2015 Akeneo SAS (http://www.akeneo.com)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/
class TagRepository extends SearchableRepository implements TagRepositoryInterface
{
/**
* {@inheritdoc}
*/
public function getIdentifierProperties()
{
return ['code'];
}
/**
* {@inheritdoc}
*/
public function findOneByIdentifier($identifier)
{
return $this->findOneBy(['code' => $identifier]);
}
/**
* Get all tags id and code
*
* @return string[]
*/
public function findAllCodes()
{
$queryBuilder = $this->createQueryBuilder('t');
$queryBuilder->select('t.id, t.code');
$queryBuilder->orderBy('t.code');
$codes = [];
foreach ($queryBuilder->getQuery()->getArrayResult() as $result) {
$codes[$result['code']] = $result['id'];
}
return $codes;
}
/**
* @return string
*/
protected function getAlias()
{
return 'tag';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment