<commit_before><?php

namespace Maxtoan\ToolsBundle\Service\ObjectManager\HistoryManager\Adapter;

use Maxtoan\ToolsBundle\Service\ObjectManager\HistoryManager\HistoryInterface;
use Doctrine\ORM\EntityManager;
use Pagerfanta\Pagerfanta as Paginator;
use Pagerfanta\Adapter\DoctrineORMAdapter as Adapter;

/**
 * Adaptador de doctrine2
 *
 * @author <NAME> <<EMAIL>>
 */
class DoctrineORMAdapter implements HistoryAdapterInterface
{
    use \Maxtoan\ToolsBundle\Service\ObjectManager\TraitConfigure;
    
    /**
     * @var string
     */
    private $className;
    /**
     * @var EntityManager
     */
    private $em;
    
    public function __construct($className,EntityManager $em)
    {
        $this->className = $className;
        $this->em = $em;
    }
    
    public function create(array $options = [])
    {
        $entity = new $this->className;
        $entity->setEventName($options["eventName"]);
        $entity->setType($options["type"]);
        $entity->setExtra($options["extra"]);
        $entity->setDescription($options["description"]);
        $entity->setObjectId($options["objectId"]);
        $entity->setObjectType($options["objectType"]);
        $entity->setUserAgent($this->getUserAgent());
        $entity->setBrowser("Chrome");
        $entity->setOs("Android");
        $entity->setMobile(true);
        $entity->setBrowserVersion(88);
        $entity->setCreatedAt(new \DateTime());
        $this->em->persist($entity);
        return $this->em->flush();
    }
    
    public function delete(HistoryInterface $entity)
    {
        $this->em->remove($entity);
        return $this->em->flush();
    }
    
    public function find($id)
    {
        return $this->em->find($id);
    }
    
    /**
     * @param array $criteria
     * @param array $sortBy
     * @return Paginator
     */
    public function getPaginator(array $criteria = [],array $sortBy = [])
    {
        $repository = $this->em->getRepository($this->className);
        $qb = $repository->createQueryBuilder("e");
        $qb
            ->andWhere("e.objectId = :objectId")
            ->andWhere("e.objectType = :objectType")
            ->setParameter("objectId",$this->objectId)
            ->setParameter("objectType",$this->objectType)
            ->orderBy("e.createdAt","DESC")
            ;
        $pagerfanta = new Paginator(new Adapter($qb));
        return $pagerfanta;
    }<commit_msg>refactor(History): Se agrega paginador de historial.<commit_after><?php

namespace Maxtoan\ToolsBundle\Service\ObjectManager\HistoryManager\Adapter;

use Maxtoan\ToolsBundle\Service\ObjectManager\HistoryManager\HistoryInterface;
use Doctrine\ORM\EntityManager;
use Pagerfanta\Adapter\DoctrineORMAdapter as Adapter;
use Maxtoan\ToolsBundle\Model\Paginator\Paginator;

/**
 * Adaptador de doctrine2
 *
 * @author <NAME> <<EMAIL>>
 */
class DoctrineORMAdapter implements HistoryAdapterInterface
{
    use \Maxtoan\ToolsBundle\Service\ObjectManager\TraitConfigure;
    
    /**
     * @var string
     */
    private $className;
    /**
     * @var EntityManager
     */
    private $em;
    
    public function __construct($className,EntityManager $em)
    {
        $this->className = $className;
        $this->em = $em;
    }
    
    public function create(array $options = [])
    {
        $entity = new $this->className;
        $entity->setEventName($options["eventName"]);
        $entity->setType($options["type"]);
        $entity->setExtra($options["extra"]);
        $entity->setDescription($options["description"]);
        $entity->setObjectId($options["objectId"]);
        $entity->setObjectType($options["objectType"]);
        $entity->setUserAgent($this->getUserAgent());
        $entity->setBrowser("Chrome");
        $entity->setOs("Android");
        $entity->setMobile(true);
        $entity->setBrowserVersion(88);
        $entity->setCreatedAt(new \DateTime());
        $this->em->persist($entity);
        return $this->em->flush();
    }
    
    public function delete(HistoryInterface $entity)
    {
        $this->em->remove($entity);
        return $this->em->flush();
    }
    
    public function find($id)
    {
        return $this->em->find($id);
    }
    
    /**
     * @param array $criteria
     * @param array $sortBy
     * @return Paginator
     */
    public function getPaginator(array $criteria = [],array $sortBy = [])
    {
        $repository = $this->em->getRepository($this->className);
        $qb = $repository->createQueryBuilder("e");
        $qb
            ->andWhere("e.objectId = :objectId")
            ->andWhere("e.objectType = :objectType")
            ->setParameter("objectId",$this->objectId)
            ->setParameter("objectType",$this->objectType)
            ->orderBy("e.createdAt","DESC")
            ;
        $pagerfanta = new Paginator(new Adapter($qb));
        $pagerfanta->setDefaultFormat(Paginator::FORMAT_ARRAY_STANDARD);
        return $pagerfanta;
    }
{'fraction_non_alphanumeric': 0.15404805168584695, 'fraction_numerical': 0.0012113870381586917, 'mean_word_length': 2.747352496217852, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 84, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4670268', 'n_tokens_mistral': 1478, 'n_tokens_neox': 1473, 'n_words': 224}