<commit_before><?php
class Vps_Model_Mongo extends Vps_Model_Abstract
{
    protected $_rowClass = 'Vps_Model_Mongo_Row';
    protected $_data = array();
    protected $_collection;

    public function __construct(array $config = array())
    {
        if (is_string($this->_collection)) {
            $this->_collection = Vps_Registry::get('dao')->getMongoDb()->{$this->_collection};
        }
    }

    protected function _init()
    {
    }

    public function update(Vps_Model_Row_Interface $row, $rowData)
    {
        throw new Vps_Exception_NotYetImplemented();
    }

    public function insert(Vps_Model_Row_Interface $row, $rowData)
    {
        throw new Vps_Exception_NotYetImplemented();
    }

    public function delete(Vps_Model_Row_Interface $row)
    {
        throw new Vps_Exception_NotYetImplemented();
    }

    public function getRowByDataKey($key)
    {
        if (!isset($this->_rows[$key])) {
            $this->_rows[$key] = new $this->_rowClass(array(
                'data' => $this->_data[$key],
                'model' => $this
            ));
        }
        return $this->_rows[$key];
    }

    public function getData()
    {
        return $this->_data;
    }

    public function countRows($where = array())
    {
        if (!is_object($where)) {
            if (is_string($where)) $where = array($where);
            $select = $this->select($where);
        } else {
            $select = $where;
        }
        $p = Vps_Registry::get('db')->getProfiler()->queryStart(print_r($this->_getQuery($select), true));
        $ret = $this->_collection->find($this->_getQuery($select))->count();
        $p = Vps_Registry::get('db')->getProfiler()->queryEnd($p);
        return $ret;
    }

    private function _getQuery(Vps_Model_Select $select)
    {
        $where = array();
        if ($equals = $select->getPart(Vps_Model_Select::WHERE_EQUALS)) {
            foreach ($equals as $k=>$v) {
                $where[$k] = $v;
            }
        }
        if ($exprs = $select->getPart(Vps_Model_Select::WHERE_EXPRESSION)) {
            foreach ($exprs as $e) {
                if ($e instanceof Vps_Model_Select_Expr_Equals) {
                    $where[$e->getField()] = $e->getValue();
                } else if ($e instanceof Vps_Model_Select_Expr_HigherDate) {
                    $where[$e->getField()]['$gt'] = new MongoDate(strtotime($e->getValue()));
                } else if ($e instanceof Vps_Model_Select_Expr_SmallerDate) {
                    $where[$e->getField()]['$lt'] = new MongoDate(strtotime($e->getValue()));
                } else if ($e instanceof Vps_Model_Select_Expr_HigherEqualDate) {
                    $where[$e->getField()]['$gte'] = new MongoDate(strtotime($e->getValue()));
                } else if ($e instanceof Vps_Model_Select_Expr_SmallerEqualDate) {
                    $where[$e->getField()]['$lte'] = new MongoDate(strtotime($e->getValue()));
                }
            }
        }
        if ($id = $select->getPart(Vps_Model_Select::WHERE_ID)) {
            $where['id'] = $id; //TODO dynam.
        }
        return $where;
    }

    public function getIds($where=null, $order=null, $limit=null, $start=null)
    {
        if (!is_object($where)) {
            if (is_string($where)) $where = array($where);
            $select = $this->select($where, $order, $limit, $start);<commit_msg>NotEquals epxression unterstuetzen<commit_after><?php
class Vps_Model_Mongo extends Vps_Model_Abstract
{
    protected $_rowClass = 'Vps_Model_Mongo_Row';
    protected $_data = array();
    protected $_collection;

    public function __construct(array $config = array())
    {
        if (is_string($this->_collection)) {
            $this->_collection = Vps_Registry::get('dao')->getMongoDb()->{$this->_collection};
        }
    }

    protected function _init()
    {
    }

    public function update(Vps_Model_Row_Interface $row, $rowData)
    {
        throw new Vps_Exception_NotYetImplemented();
    }

    public function insert(Vps_Model_Row_Interface $row, $rowData)
    {
        throw new Vps_Exception_NotYetImplemented();
    }

    public function delete(Vps_Model_Row_Interface $row)
    {
        throw new Vps_Exception_NotYetImplemented();
    }

    public function getRowByDataKey($key)
    {
        if (!isset($this->_rows[$key])) {
            $this->_rows[$key] = new $this->_rowClass(array(
                'data' => $this->_data[$key],
                'model' => $this
            ));
        }
        return $this->_rows[$key];
    }

    public function getData()
    {
        return $this->_data;
    }

    public function countRows($where = array())
    {
        if (!is_object($where)) {
            if (is_string($where)) $where = array($where);
            $select = $this->select($where);
        } else {
            $select = $where;
        }
        $p = Vps_Registry::get('db')->getProfiler()->queryStart(print_r($this->_getQuery($select), true));
        $ret = $this->_collection->find($this->_getQuery($select))->count();
        $p = Vps_Registry::get('db')->getProfiler()->queryEnd($p);
        return $ret;
    }

    private function _getQuery(Vps_Model_Select $select)
    {
        $where = array();
        if ($equals = $select->getPart(Vps_Model_Select::WHERE_EQUALS)) {
            foreach ($equals as $k=>$v) {
                $where[$k] = $v;
            }
        }
        if ($exprs = $select->getPart(Vps_Model_Select::WHERE_EXPRESSION)) {
            foreach ($exprs as $e) {
                if ($e instanceof Vps_Model_Select_Expr_Equals) {
                    $where[$e->getField()] = $e->getValue();
                } else if ($e instanceof Vps_Model_Select_Expr_NotEquals) {
                    $where[$e->getField()]['$ne'] = $e->getValue();
                } else if ($e instanceof Vps_Model_Select_Expr_HigherDate) {
                    $where[$e->getField()]['$gt'] = new MongoDate(strtotime($e->getValue()));
                } else if ($e instanceof Vps_Model_Select_Expr_SmallerDate) {
                    $where[$e->getField()]['$lt'] = new MongoDate(strtotime($e->getValue()));
                } else if ($e instanceof Vps_Model_Select_Expr_HigherEqualDate) {
                    $where[$e->getField()]['$gte'] = new MongoDate(strtotime($e->getValue()));
                } else if ($e instanceof Vps_Model_Select_Expr_SmallerEqualDate) {
                    $where[$e->getField()]['$lte'] = new MongoDate(strtotime($e->getValue()));
                }
            }
        }
        if ($id = $select->getPart(Vps_Model_Select::WHERE_ID)) {
            $where['id'] = $id; //TODO dynam.
        }
        return $where;
    }

    public function getIds($where=null, $order=null, $limit=null, $start=null)
    {
        if (!is_object($where)) {
            if (is_string($where)) $where = array($where);
            $select = $this->select($where, $order, $limit, $start);
{'fraction_non_alphanumeric': 0.15578613633088342, 'fraction_numerical': 0.0, 'mean_word_length': 2.290659080132764, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 81, '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': '5281860', 'n_tokens_mistral': 2145, 'n_tokens_neox': 2083, 'n_words': 362}