<commit_before><?php

/*
 * This file is part of the CSBill package.
 *
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace CSBill\ClientBundle\Controller;

use CSBill\CoreBundle\Controller\BaseController;
use CSBill\ClientBundle\Entity\Client;
use CSBill\DataGridBundle\Grid\Filters;
use APY\DataGridBundle\Grid\Source\Entity;
use APY\DataGridBundle\Grid\Column\ActionsColumn;
use APY\DataGridBundle\Grid\Action\RowAction;
use Doctrine\ORM\QueryBuilder;
use CSBill\ClientBundle\Form\Client as ClientForm;
use Symfony\Component\HttpFoundation\Request;

class DefaultController extends BaseController
{
    /**
     * List all the clients
     *
     * @param  Request                                    $request
     * @return \Symfony\Component\HttpFoundation\Response
     */
    public function indexAction(Request $request)
    {
        $source = new Entity('CSBillClientBundle:Client');

        // Get a Grid instance
        $grid = $this->get('grid');

        // TODO : get better way of adding filters & search instead of defining it in the controller like this
        $filters = new Filters($request);

        $filters->add(
            'all_clients',
            null,
            true,
            array(
                'active_class' => 'label label-info',
                'default_class' => 'label label-default'
            )
        );

        $statusList = $this->getRepository('CSBillClientBundle:Status')->findAll();

        foreach ($statusList as $status) {
            $filters->add($status->getName().'_clients', function (QueryBuilder $queryBuilder) use ($status) {
                $aliases = $queryBuilder->getRootAliases();
                $alias = $aliases[0];

                $queryBuilder->join($alias.'.status', 's')
                   ->andWhere('s.name = :status_name')
                   ->setParameter('status_name', $status->getName());
            },
                false,
                array(
                    'active_class' => 'label label-' . $status->getLabel(),
                    'default_class' => 'label label-default'
                )
            );
        }

        $search = $request->get('search');

        $source->manipulateQuery(function (QueryBuilder $queryBuilder) use ($search, $filters) {

            if ($filters->isFilterActive()) {
                $filter = $filters->getActiveFilter();
                $filter($queryBuilder);
            }

            if ($search) {
                $aliases = $queryBuilder->getRootAliases();

                $queryBuilder->andWhere($aliases[0].'.name LIKE :search')
                    ->setParameter('search', "%{$search}%");
            }
        });

        // Attach the source to the grid
        $grid->setSource($source);

        $viewAction = new RowAction($this->get('translator')->trans('view'), '_clients_view');
        //$viewAction->setAttributes(array('class' => 'btn'));

        $editAction = new RowAction($this->get('translator')->trans('edit'), '_clients_edit');
        //$editAction->setAttributes(array('class' => 'btn'));

        $actionsRow = new ActionsColumn('actions', 'Action', array($editAction, $viewAction));
        $grid->addColumn($actionsRow, 100);

        $grid->hideColumns(array('updated', 'deleted'));

        // Return the response of the grid to the template
        return $grid->getGridResponse('CSBillClientBundle:Default:index.html.twig', array('filters' => $filters));
    }
<commit_msg>[ClientBundle] Link client website in datagrid<commit_after><?php

/*
 * This file is part of the CSBill package.
 *
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace CSBill\ClientBundle\Controller;

use CSBill\CoreBundle\Controller\BaseController;
use CSBill\ClientBundle\Entity\Client;
use CSBill\DataGridBundle\Grid\Filters;
use APY\DataGridBundle\Grid\Source\Entity;
use APY\DataGridBundle\Grid\Column\ActionsColumn;
use APY\DataGridBundle\Grid\Action\RowAction;
use Doctrine\ORM\QueryBuilder;
use CSBill\ClientBundle\Form\Client as ClientForm;
use Symfony\Component\HttpFoundation\Request;

class DefaultController extends BaseController
{
    /**
     * List all the clients
     *
     * @param  Request                                    $request
     * @return \Symfony\Component\HttpFoundation\Response
     */
    public function indexAction(Request $request)
    {
        $source = new Entity('CSBillClientBundle:Client');

        // Get a Grid instance
        $grid = $this->get('grid');

        // TODO : get better way of adding filters & search instead of defining it in the controller like this
        $filters = new Filters($request);

        $filters->add(
            'all_clients',
            null,
            true,
            array(
                'active_class' => 'label label-info',
                'default_class' => 'label label-default'
            )
        );

        $statusList = $this->getRepository('CSBillClientBundle:Status')->findAll();

        foreach ($statusList as $status) {
            $filters->add($status->getName().'_clients', function (QueryBuilder $queryBuilder) use ($status) {
                $aliases = $queryBuilder->getRootAliases();
                $alias = $aliases[0];

                $queryBuilder->join($alias.'.status', 's')
                   ->andWhere('s.name = :status_name')
                   ->setParameter('status_name', $status->getName());
            },
                false,
                array(
                    'active_class' => 'label label-' . $status->getLabel(),
                    'default_class' => 'label label-default'
                )
            );
        }

        $search = $request->get('search');

        $source->manipulateQuery(function (QueryBuilder $queryBuilder) use ($search, $filters) {

            if ($filters->isFilterActive()) {
                $filter = $filters->getActiveFilter();
                $filter($queryBuilder);
            }

            if ($search) {
                $aliases = $queryBuilder->getRootAliases();

                $queryBuilder->andWhere($aliases[0].'.name LIKE :search')
                    ->setParameter('search', "%{$search}%");
            }
        });

        // Attach the source to the grid
        $grid->setSource($source);

        $viewAction = new RowAction($this->get('translator')->trans('view'), '_clients_view');
        //$viewAction->setAttributes(array('class' => 'btn'));

        $editAction = new RowAction($this->get('translator')->trans('edit'), '_clients_edit');
        //$editAction->setAttributes(array('class' => 'btn'));

        $actionsRow = new ActionsColumn('actions', 'Action', array($editAction, $viewAction));
        $grid->addColumn($actionsRow, 100);

        $grid->hideColumns(array('updated', 'deleted'));

        $grid->getColumn('website')->manipulateRenderCell(function($value) {
            if (!empty($value)) {
                return '<a href="'. $value . '" target="_blank">' . $value . '<a>';
            }

            return $value;
        })->setSafe(false);

        // Return the response of the grid to the template
        return $grid->getGridResponse('CSBillClientBundle:Default:index.html.twig', array('filters' => $filters));
    }

{'fraction_non_alphanumeric': 0.14080343947333065, 'fraction_numerical': 0.0013435442697836894, 'mean_word_length': 2.2634809294169225, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 86, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1459117', 'n_tokens_mistral': 2019, 'n_tokens_neox': 1939, 'n_words': 428}