<commit_before><?php

/**
 * LICENSE
 *
 * This source file is subject to the new BSD license
 * It is  available through the world-wide-web at this URL:
 * http://www.petala-azul.com/bsd.txt
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to <EMAIL> so we can send you a copy immediately.
 *
 * @package   Bvb_Grid
 * @author    <NAME> <<EMAIL>>
 * @copyright 2010 ZFDatagrid
 * @license   http://www.petala-azul.com/bsd.txt   New BSD License
 * @version   $Id$
 * @link      http://zfdatagrid.com
 */
class Bvb_Grid_Source_Array implements Bvb_Grid_Source_SourceInterface {

    /**
     * Fields list
     *
     * @var array
     */
    protected $_fields = array();
    /**
     * Raw result
     *
     * @var array
     */
    protected $_rawResult = array();
    /**
     * Current Offset
     *
     * @var int
     */
    protected $_offset;
    /**
     * Current Result start
     *
     * @var int
     */
    protected $_start;
    /**
     * Total Records Foun
     *
     * @var int
     */
    protected $_totalRecords = 0;
    /**
     * Source nama
     *
     * @var string
     */
    protected $_sourceName;
    /**
     * Cache Instance
     *
     * @var mixed
     */
    protected $_cache;
    /**
     * Primary Key
     *
     * @var string|null
     */
    protected $_primaryKey = null;

    public function __construct(array $array, $titles = null)
    {
        if (count($array) > 0) {
            $min = min(array_keys($array));
            if ($titles === null || count($titles) != count($array[$min])) {
                $this->_fields = array_keys($array[$min]);
            } else {
                $this->_fields = $titles;
                foreach ($array as $key => $value) {
                    $array[$key] = array_combine($titles, $value);
                }
            }
        } elseif ($titles !== null) {
            $this->_fields = $titles;
        }

        if (count($this->_fields) == 0) {
            $this->_fields = array('Default');
        }

        $this->_rawResult = $array;
        $this->_sourceName = 'array';
    }

    public function quoteValue($value)
    {
        return $value;
    }

    /**
     * Resets query order
     *
     * @return bool
     */
    public function resetOrder()
    {
        return true;
    }

    /**
     * Resets result limit
     *
     * @return bool
     */
    public function resetLimit()
    {
        return true;
    }

    /**
     * Returns source name
     *
     * @return string
     */
    public function getSourceName()
    {
        return $this->_sourceName;
    }

    /**
     * Builds fields information.
     *
     * @return array
     */
    public function buildFields()
    {
        $fields = $this->_fields;

        $final = array();

        foreach ($fields as $value) {
            if ($value == '_zfgId') {
                $final[$value] = array('title' => ucfirst(str_replace('_', ' ', $value)),
                    'field' => $value, 'remove' => 1);
            } else {
                $final[$value] = array('title' => ucfirst(str_replace('_', ' ', $value)),
                    'field' => $value);
            }
        }

        return $final;
    }

    /**
     * Builds query limit
     *
     * @param int $offset
     * @param int $start
     *
     * @return bool
     */
    public function buildQueryLimit($offset, $start)
    {
        $this->_offset = $offset;
        $this->_start = ($this->_totalRecords != 0) ? 0 : $start;
        return true;
    }

    /**
     * Adds a condition to filter
     *
     * @param string $filter
     * @param string $op
     * @param array  $completeField
     *
     * @return bool
     */
    public function addCondition($filter, $op, $completeField)
    {

        $explode = explode('.', $completeField['field']);
        $field = end($explode);

        foreach ($this->_rawResult as $key => $result) {
            foreach ($result as $fieldKey => $fieldValue) {
                if (strlen($filter) > 0 && $fieldKey == $field) {
                    if (!$this->_applySearchType($fieldValue, $filter, $op)) {
                        unset($this->_rawResult[$key]);
                    }
                }
            }
        }
<commit_msg>fixes issue #763<commit_after><?php

/**
 * LICENSE
 *
 * This source file is subject to the new BSD license
 * It is  available through the world-wide-web at this URL:
 * http://www.petala-azul.com/bsd.txt
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to <EMAIL> so we can send you a copy immediately.
 *
 * @package   Bvb_Grid
 * @author    <NAME> <<EMAIL>>
 * @copyright 2010 ZFDatagrid
 * @license   http://www.petala-azul.com/bsd.txt   New BSD License
 * @version   $Id$
 * @link      http://zfdatagrid.com
 */
class Bvb_Grid_Source_Array implements Bvb_Grid_Source_SourceInterface {

    /**
     * Fields list
     *
     * @var array
     */
    protected $_fields = array();
    /**
     * Raw result
     *
     * @var array
     */
    protected $_rawResult = array();
    /**
     * Current Offset
     *
     * @var int
     */
    protected $_offset;
    /**
     * Current Result start
     *
     * @var int
     */
    protected $_start;
    /**
     * Total Records Foun
     *
     * @var int
     */
    protected $_totalRecords = 0;
    /**
     * Source nama
     *
     * @var string
     */
    protected $_sourceName;
    /**
     * Cache Instance
     *
     * @var mixed
     */
    protected $_cache;
    /**
     * Primary Key
     *
     * @var string|null
     */
    protected $_primaryKey = null;

    public function __construct(array $array, $titles = null)
    {
        if (count($array) > 0) {
            $min = min(array_keys($array));
            if ($titles === null || count($titles) != count($array[$min])) {
                $this->_fields = array_keys($array[$min]);
            } else {
                $this->_fields = $titles;
                foreach ($array as $key => $value) {
                    $array[$key] = array_combine($titles, $value);
                }
            }
        } elseif ($titles !== null) {
            $this->_fields = $titles;
        }

        if (count($this->_fields) == 0) {
            $this->_fields = array('Default');
        }

        $this->_rawResult = $array;
        $this->_sourceName = 'array';
    }

    public function quoteValue($value)
    {
        return $value;
    }

    /**
     * Resets query order
     *
     * @return bool
     */
    public function resetOrder()
    {
        return true;
    }

    /**
     * Resets result limit
     *
     * @return bool
     */
    public function resetLimit()
    {
        return true;
    }

    /**
     * Returns source name
     *
     * @return string
     */
    public function getSourceName()
    {
        return $this->_sourceName;
    }

    /**
     * Builds fields information.
     *
     * @return array
     */
    public function buildFields()
    {
        $fields = $this->_fields;

        $final = array();

        foreach ($fields as $value) {
            if ($value == '_zfgId') {
                $final[$value] = array('title' => ucfirst(str_replace('_', ' ', $value)),
                    'field' => $value, 'remove' => 1);
            } else {
                $final[$value] = array('title' => ucfirst(str_replace('_', ' ', $value)),
                    'field' => $value);
            }
        }

        return $final;
    }

    /**
     * Builds query limit
     *
     * @param int $offset
     * @param int $start
     *
     * @return bool
     */
    public function buildQueryLimit($offset, $start)
    {
        $this->_offset = $offset;
        $this->_start = ($this->_totalRecords != 0) ? $start : 0;
        return true;
    }

    /**
     * Adds a condition to filter
     *
     * @param string $filter
     * @param string $op
     * @param array  $completeField
     *
     * @return bool
     */
    public function addCondition($filter, $op, $completeField)
    {

        $explode = explode('.', $completeField['field']);
        $field = end($explode);

        foreach ($this->_rawResult as $key => $result) {
            foreach ($result as $fieldKey => $fieldValue) {
                if (strlen($filter) > 0 && $fieldKey == $field) {
                    if (!$this->_applySearchType($fieldValue, $filter, $op)) {
                        unset($this->_rawResult[$key]);
                    }
                }
            }
        }

{'fraction_non_alphanumeric': 0.14037727114917256, 'fraction_numerical': 0.002893183659298692, 'mean_word_length': 1.5712585540017852, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 61, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, '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': '3810126', 'n_tokens_mistral': 2611, 'n_tokens_neox': 2526, 'n_words': 630}