<?php

namespace Market\ZodacoBundle\Entity;

use Doctrine\ORM\EntityRepository;

/**
 * HistoriesSellRepository
 *
 * This class was generated by the Doctrine ORM. Add your own custom
 * repository methods below.
 */
class HistoriesSellRepository extends EntityRepository
{

    public function _getCountListByUser($user_id) {
        $q = 'SELECT c FROM MarketZodacoBundle:HistoriesSell c';
        $q .= ' WHERE c.user_id =' . $user_id;
        $total = $this->getEntityManager()->createQuery($q)->getResult();
        return count($total);
    }

    public function _getProListByUser($user_id, $page = 1, $limit = 12) {
        $q = 'SELECT c FROM MarketZodacoBundle:HistoriesSell c ';
        $q .= ' WHERE c.user_id =' . $user_id;
        $q .= ' ORDER BY c.id DESC';
        return $this->getEntityManager()
                        ->createQuery($q)
                        ->setMaxResults($limit)
                        ->setFirstResult(($page - 1) * $limit)
                        ->getResult();
    }
}
