<?php

namespace OfficeBrain\Bundle\SubShopBundle\Entity;

use Doctrine\ORM\EntityRepository;

/**
 * SubShopThemeColorRepository.
 *
 * This class was generated by the Doctrine ORM. Add your own custom
 * repository methods below.
 */
class SubShopThemeColorRepository extends EntityRepository
{
    public function set($sub_shop_theme_color)
    {
        return $this->commit($sub_shop_theme_color);
    }

    public function findAll()
    {
        return $this->createQueryBuilder('stc')
        ->select('stc')
        ->orderBy('stc.name', 'DESC')
        ->getQuery()
        ->getResult();
    }

    public function find($id, $lockMode = NULL, $lockVersion = NULL)
    {
        return $this->createQueryBuilder('s')
        ->select('s')
        ->where('s.id = :id')
        ->setParameter(':id', $id)
        ->getQuery()
        ->getSingleResult();
    }

    public function findByIds($ids)
    {
        return $this->createQueryBuilder('stc')
                ->select('stc')
                ->where('stc.id IN( :ids )')
                ->setParameter(':ids', $ids)
                ->getQuery()
                ->getResult();
    }

    public function findBySlugs($slugs)
    {
        return $this->createQueryBuilder('stc')
        ->select('stc')
        ->where('stc.slug IN( :slugs )')
        ->setParameter(':slugs', $slugs)
        ->getQuery()
        ->getResult();
    }

    /**
     * Commit entity.
     */
    private function commit($entity)
    {
        $this->_em->persist($entity);
        $this->_em->flush();

        return $entity->getId();
    }
}
