<commit_before><?php
/**
 * Nooku Framework - http://www.nooku.org
 *
 * @copyright	Copyright (C) 2007 - 2013 <NAME> and Timble CVBA. (http://www.timble.net)
 * @license		GNU GPLv3 <http://www.gnu.org/licenses/gpl.html>
 * @link		git://git.assembla.com/nooku-framework.git for the canonical source repository
 */

namespace Nooku\Library;

/**
 * Database Model
 *
 * Provides interaction with a database
 *
 * @author  <NAME> <http://nooku.assembla.com/profile/johanjanssens>
 * @package Nooku\Library\Model
 */
class ModelDatabase extends ModelAbstract
{
    /**
     * Table object or identifier
     *
     * @var string|object
     */
    protected $_table;
    
    /**
     * Constructor
     *
     * @param ObjectConfig $config  An optional ObjectConfig object with configuration options
     */
    public function __construct(ObjectConfig $config)
    {
        parent::__construct($config);

        $this->_table = $config->table;

        $identifier = $alias = $this->getIdentifier()->toArray();

        //Create database.rowset alias
        $identifier['path'] = array('database', 'rowset');
        $alias['path']      = array('model', 'entity');

        $this->getObject('manager')->registerAlias($alias, $identifier);

        //Create database.row alias
        $identifier['path'] = array('database', 'row');
        $identifier['name'] = StringInflector::singularize($identifier['name']);

        $alias['path'] = array('model', 'entity');
        $alias['name'] = StringInflector::singularize($identifier['name']);

        $this->getObject('manager')->registerAlias($alias, $identifier);

        //Behavior depends on the database. Need to add if after database has been set.
        $this->addBehavior('indexable');
    }

    /**
     * Initializes the config for the object
     *
     * Called from {@link __construct()} as a first step of object instantiation.
     *
     * @param  ObjectConfig $config An optional ObjectConfig object with configuration options
     * @return  void
     */
    protected function _initialize(ObjectConfig $config)
    {
        $config->append(array(
            'table'     => $this->getIdentifier()->name,
            'behaviors' => array('paginatable', 'orderable'),
        ));

        parent::_initialize($config);
    }

    /**
     * Create a new entity for the data source
     *
     * @param ModelContext $context A model context object
     * @return  ModelEntityInterface The entity
     */
    protected function _actionCreate(ModelContext $context)
    {
        return $this->getTable()->createRowset();
    }

    /**
     * Fetch a new entity from the data source
     *
     * @param ModelContext $context A model context object
     * @return ModelEntityInterface The entity
     */
    protected function _actionFetch(ModelContext $context)
    {
        $state   = $context->state;
        $table   = $this->getTable();

        //Select the rows
        if (!$state->isEmpty())<commit_msg>re #378 : Reverted previous commit.<commit_after><?php
/**
 * Nooku Framework - http://www.nooku.org
 *
 * @copyright	Copyright (C) 2007 - 2013 <NAME> and Timble CVBA. (http://www.timble.net)
 * @license		GNU GPLv3 <http://www.gnu.org/licenses/gpl.html>
 * @link		git://git.assembla.com/nooku-framework.git for the canonical source repository
 */

namespace Nooku\Library;

/**
 * Database Model
 *
 * Provides interaction with a database
 *
 * @author  <NAME> <http://nooku.assembla.com/profile/johanjanssens>
 * @package Nooku\Library\Model
 */
class ModelDatabase extends ModelAbstract
{
    /**
     * Table object or identifier
     *
     * @var string|object
     */
    protected $_table;
    
    /**
     * Constructor
     *
     * @param ObjectConfig $config  An optional ObjectConfig object with configuration options
     */
    public function __construct(ObjectConfig $config)
    {
        parent::__construct($config);

        $this->_table = $config->table;

        $identifier = $alias = $this->getIdentifier()->toArray();

        //Create database.rowset alias
        $identifier['path'] = array('database', 'rowset');
        $alias['path']      = array('model', 'entity');

        $this->getObject('manager')->registerAlias($alias, $identifier);

        //Create database.row alias
        $identifier['path'] = array('database', 'row');
        $identifier['name'] = StringInflector::singularize($identifier['name']);

        $alias['path'] = array('model', 'entity');
        $alias['name'] = StringInflector::singularize($identifier['name']);

        $this->getObject('manager')->registerAlias($alias, $identifier);

        //Behavior depends on the database. Need to add if after database has been set.
        $this->addBehavior('indexable');
    }

    /**
     * Initializes the config for the object
     *
     * Called from {@link __construct()} as a first step of object instantiation.
     *
     * @param  ObjectConfig $config An optional ObjectConfig object with configuration options
     * @return  void
     */
    protected function _initialize(ObjectConfig $config)
    {
        $config->append(array(
            'table'     => $this->getIdentifier()->name,
            'behaviors' => array('paginatable', 'orderable'),
        ));

        parent::_initialize($config);
    }

    /**
     * Create a new entity for the data source
     *
     * @param ModelContext $context A model context object
     * @return  ModelEntityInterface The entity
     */
    protected function _actionCreate(ModelContext $context)
    {
        return $this->getTable()->createRow();
    }

    /**
     * Fetch a new entity from the data source
     *
     * @param ModelContext $context A model context object
     * @return ModelEntityInterface The entity
     */
    protected function _actionFetch(ModelContext $context)
    {
        $state   = $context->state;
        $table   = $this->getTable();

        //Select the rows
        if (!$state->isEmpty())
{'fraction_non_alphanumeric': 0.13588500752131039, 'fraction_numerical': 0.0035099448437238842, 'mean_word_length': 2.6779348494161033, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 49, 'https://': 0, 'lorem ipsum': 0, 'www.': 6, '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': '4409531', 'n_tokens_mistral': 1681, 'n_tokens_neox': 1635, 'n_words': 423}