<commit_before><?php

namespace Wanjee\Shuwee\AdminBundle\Datagrid;

use Symfony\Component\HttpFoundation\Request;
use Wanjee\Shuwee\AdminBundle\Admin\AdminInterface;
use Wanjee\Shuwee\AdminBundle\Datagrid\Field\DatagridField;
use Wanjee\Shuwee\AdminBundle\Datagrid\Datasource\DatasourceInterface;

/**
 * Class Datagrid
 * @package Wanjee\Shuwee\AdminBundle\Datagrid
 */
class Datagrid implements DatagridInterface
{
    /**
     * @var \Wanjee\Shuwee\AdminBundle\Admin\Admin $admin
     */
    protected $admin;

    /**
     * @var array List of available fields for this datagrid
     */
    protected $fields = array();

    /**
     * @var \Wanjee\Shuwee\AdminBundle\Datagrid\Datasource\DatasourceInterface
     */
    protected $dataSource;

    /**
     *
     */
    function __construct(AdminInterface $admin)
    {
        $this->admin = $admin;

        return $this;
    }

    /**
     * @return \Wanjee\Shuwee\AdminBundle\Admin\Admin
     */
    public function getAdmin()
    {
        return $this->admin;
    }

    /**
     * @param \Wanjee\Shuwee\AdminBundle\Admin\Admin $admin
     */
    public function setAdmin($admin)
    {
        $this->admin = $admin;

        return $this;
    }

    /**
     * @param \Wanjee\Shuwee\AdminBundle\Datagrid\Datasource\DatasourceInterface $datasource
     */
    public function setDatasource(DatasourceInterface $datasource)
    {
        $this->dataSource = $datasource;

        return $this;
    }

    /**
     * @return \Wanjee\Shuwee\AdminBundle\Datagrid\Datasource\DatasourceInterface
     */
    public function getDataSource()
    {
        return $this->dataSource;
    }

    /**
     * @return int
     */
    public function getPaginator()
    {
        return $this->dataSource->getPaginator();
    }


    /**
     * @param string $name
     * @param string $type A valid DatagridType implementation name
     * @param array $options List of options for the given DatagridType
     */
    public function addField($name, $type, $options = array())
    {
        // instanciate new field object of given type
        $type = $this->getDatagridManager()->getType($type);

        $field = new DatagridField($name, $type, $options);

        $this->fields[] = $field;

        return $this;
    }

    /**
     * Return list of all fields configured for this datagrid
     */
    public function getFields()
    {
        return $this->fields;
    }

    /**
     * @param \Symfony\Component\HttpFoundation\Request $request
     */
    public function bind(Request $request)
    {
        $query = $request->query->all();

        if (isset($query['page'])) {
            $this->dataSource->setPage($query['page']);
        }
    }

    /**
     * @return \Wanjee\Shuwee\AdminBundle\Datagrid\DatagridManager
     */
    public function getDatagridManager() {
        return $this->admin->getDatagridManager();
    }
}<commit_msg>Revert "Relies on Datasource & Request to build content of a datagrid"<commit_after><?php

namespace Wanjee\Shuwee\AdminBundle\Datagrid;

use Symfony\Component\HttpFoundation\Request;
use Wanjee\Shuwee\AdminBundle\Admin\AdminInterface;
use Wanjee\Shuwee\AdminBundle\Datagrid\Field\DatagridField;

/**
 * Class Datagrid
 * @package Wanjee\Shuwee\AdminBundle\Datagrid
 */
class Datagrid implements DatagridInterface
{
    /**
     * @var \Wanjee\Shuwee\AdminBundle\Admin\Admin $admin
     */
    protected $admin;

    /**
     * @var array List of available fields for this datagrid
     */
    protected $fields = array();

    /**
     * @var array List of entities for this datagrid
     */
    protected $entities = array();

    /**
     *
     */
    function __construct(AdminInterface $admin)
    {
        $this->admin = $admin;

        return $this;
    }

    /**
     * @return \Wanjee\Shuwee\AdminBundle\Admin\Admin
     */
    public function getAdmin()
    {
        return $this->admin;
    }

    /**
     * @param \Wanjee\Shuwee\AdminBundle\Admin\Admin $admin
     */
    public function setAdmin($admin)
    {
        $this->admin = $admin;
    }

    /**
     * @param string $name
     * @param string $type A valid DatagridType implementation name
     * @param array $options List of options for the given DatagridType
     */
    public function addField($name, $type, $options = array())
    {
        // instanciate new field object of given type
        $type = $this->getDatagridManager()->getType($type);

        $field = new DatagridField($name, $type, $options);

        $this->fields[] = $field;

        return $this;
    }

    /**
     * Return list of all fields configured for this datagrid
     */
    public function getFields()
    {
        return $this->fields;
    }

    /**
     * Set all entities
     * FIXME datagrid should be responsible for the entities retrieval as it will be for paging, sortering, filtering
     */
    public function setEntities($entities = array())
    {
        $this->entities = $entities;
    }

    /**
     * Return entities
     *
     * @return array
     */
    public function getEntities()
    {
        return $this->entities;
    }

    /**
     * @param \Symfony\Component\HttpFoundation\Request $request
     */
    public function setRequest(Request $request)
    {

    }

    /**
     * @return \Wanjee\Shuwee\AdminBundle\Datagrid\DatagridManager
     */
    public function getDatagridManager() {
        return $this->admin->getDatagridManager();
    }
}
{'fraction_non_alphanumeric': 0.12201834862385322, 'fraction_numerical': 0.0, 'mean_word_length': 2.313677811550152, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 31, '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': '4791542', 'n_tokens_mistral': 1720, 'n_tokens_neox': 1682, 'n_words': 352}