<commit_before><?php

namespace Dal\Mapper;

use Dal\Db\Sql\Select;
use Dal\Db\TableGateway\TableGateway;
use Zend\Paginator\Adapter\DbSelect;
use Zend\ServiceManager\ServiceLocatorAwareInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
use Dal\Model\AbstractModel;
use Dal\Db\ResultSet\ResultSet;
use Dal\Paginator\Paginator;

abstract class AbstractMapper implements ServiceLocatorAwareInterface
{
    /**
     * @var \Dal\Db\TableGateway\TableGateway
     */
    protected $tableGateway;
    protected $paginator;
    protected $paginatorOptions = array();
    protected $usePaginator = false;
    protected $serviceLocator;

    /**
     *
     * @var \Dal\Db\ResultSet\ResultSet
     */
    protected $result;

    /**
     *
     * @var array
     */
    protected $primary_key;

    /**
     * Construct the model with the tablegateway
     *
     * @param TableGateway $tableGateway
     */
    public function __construct(TableGateway $tableGateway)
    {
        $this->tableGateway = $tableGateway;
    }

    /**
     * Update a modele
     *
     * @param \Dal\Model\AbstractModel $model
     * @param array                    $order
     *
     * @return \Dal\Db\ResultSet\ResultSet
     */
    public function select(AbstractModel $model, $order = null)
    {
        if ($this->usePaginator === true) {
            $sl = $this->tableGateway->getSql()->select();

            $sl->where($model->toArrayCurrent());
            if ($order) {
                $sl->order($order);
            }
            return  $this->initPaginator($sl);
        }

        $this->result = $this->tableGateway->select($model->toArrayCurrent());

        return $this->result;
    }

    /**
     * Excecute request directly by PDO
     *
     * @param string $request
     * @param array  $param
     *
     * @return \Dal\Db\ResultSet\ResultSet
     */
    public function requestPdo($request, $param = null)
    {
        $this->result = $this->tableGateway->requestPdo($request, $param);

        return $this->result;
    }

    /**
     * Excecute select directly by PDO
     *
     * @param string $select
     * @param array  $param
     *
     * @return \Dal\Db\ResultSet\ResultSet
     */
    public function selectBridge(Select $select)
    {
    	if ($this->usePaginator === true) {
    		return $this->initPaginator(array($select, $param));
    	}
    	
    	$this->result = $this->tableGateway->selectBridge($select);
    
    	return $this->result;
    }
    
    /**
     * Excecute select directly by PDO
     *
     * @param string $select
     * @param array  $param
     *
     * @return \Dal\Db\ResultSet\ResultSet
     */
    public function selectPdo($select, $param = null)
    {
        if ($this->usePaginator === true) {
            return $this->initPaginator(array($select, $param));
        }
        $this->result = $this->tableGateway->selectPdo($select, $param);

        return $this->result;
    }

    /**
     * Excecute select directly by PDO wihtout Mappage Model
     *
     * @param string $select
     * @param array  $param<commit_msg>add pagination<commit_after><?php

namespace Dal\Mapper;

use Dal\Db\Sql\Select;
use Dal\Db\TableGateway\TableGateway;
use Zend\Paginator\Adapter\DbSelect;
use Zend\ServiceManager\ServiceLocatorAwareInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
use Dal\Model\AbstractModel;
use Dal\Db\ResultSet\ResultSet;
use Dal\Paginator\Paginator;

abstract class AbstractMapper implements ServiceLocatorAwareInterface
{
    /**
     * @var \Dal\Db\TableGateway\TableGateway
     */
    protected $tableGateway;
    protected $paginator;
    protected $paginatorOptions = array();
    protected $usePaginator = false;
    protected $serviceLocator;

    /**
     *
     * @var \Dal\Db\ResultSet\ResultSet
     */
    protected $result;

    /**
     *
     * @var array
     */
    protected $primary_key;

    /**
     * Construct the model with the tablegateway
     *
     * @param TableGateway $tableGateway
     */
    public function __construct(TableGateway $tableGateway)
    {
        $this->tableGateway = $tableGateway;
    }

    /**
     * Update a modele
     *
     * @param \Dal\Model\AbstractModel $model
     * @param array                    $order
     *
     * @return \Dal\Db\ResultSet\ResultSet
     */
    public function select(AbstractModel $model, $order = null)
    {
        if ($this->usePaginator === true) {
            $sl = $this->tableGateway->getSql()->select();

            $sl->where($model->toArrayCurrent());
            if ($order) {
                $sl->order($order);
            }
            return  $this->initPaginator($sl);
        }

        $this->result = $this->tableGateway->select($model->toArrayCurrent());

        return $this->result;
    }

    /**
     * Excecute request directly by PDO
     *
     * @param string $request
     * @param array  $param
     *
     * @return \Dal\Db\ResultSet\ResultSet
     */
    public function requestPdo($request, $param = null)
    {
        $this->result = $this->tableGateway->requestPdo($request, $param);

        return $this->result;
    }

    /**
     * Excecute select directly by PDO
     *
     * @param string $select
     * @param array  $param
     *
     * @return \Dal\Db\ResultSet\ResultSet
     */
    public function selectBridge(Select $select)
    {
    	if ($this->usePaginator === true) {
    		return $this->initPaginator($select);
    	}
    	
    	$this->result = $this->tableGateway->selectBridge($select);
    
    	return $this->result;
    }
    
    /**
     * Excecute select directly by PDO
     *
     * @param string $select
     * @param array  $param
     *
     * @return \Dal\Db\ResultSet\ResultSet
     */
    public function selectPdo($select, $param = null)
    {
        if ($this->usePaginator === true) {
            return $this->initPaginator(array($select, $param));
        }
        $this->result = $this->tableGateway->selectPdo($select, $param);

        return $this->result;
    }

    /**
     * Excecute select directly by PDO wihtout Mappage Model
     *
     * @param string $select
     * @param array  $param
{'fraction_non_alphanumeric': 0.12971391417425226, 'fraction_numerical': 0.0, 'mean_word_length': 2.17984496124031, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 63, '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': '6939538', 'n_tokens_mistral': 1890, 'n_tokens_neox': 1903, 'n_words': 371}