APY / APYDataGridBundle

Symfony Datagrid Bundle
MIT License
493 stars 343 forks source link

Date Equal Filter Bug #224

Closed clubdesarrolladores closed 12 years ago

clubdesarrolladores commented 12 years ago

There is a bug in DateColumn.php (line 40)

Is missing: $this->setDataJunction(self::DATA_CONJUNCTION);

I think the code must be update to this:

switch ($filter->getOperator()) { case self::OPERATOR_EQ: $filters[] = new Filter(self::OPERATOR_GTE, $dateFrom); $filters[] = new Filter(self::OPERATOR_LTE, $dateTo); $this->setDataJunction(self::DATA_CONJUNCTION); //<------- break; case self::OPERATOR_NEQ:

Otherway performs a DISJUNCTION operation (OR).

Abhoryo commented 12 years ago

The data junction is a conjonction operation by default. Do you have a case where you have a problem?

clubdesarrolladores commented 12 years ago

Yes.

/**
 * @ORM\Column(name="date_start", type="date")
 * @Assert\NotBlank()
 * @Grid\Column(title="Start Date", inputType="date")
 */
protected $date_start;

/**
 * @ORM\Column(name="date_finish", type="date")
 * @Assert\NotBlank()
 * @Grid\Column(title="Finish Date", inputType="date")
 */
protected $date_finish;

this is the sql generated on filter:

SELECT w0_.subtype AS subtype0, w1_.description AS description1, w1_.payment_agreement AS payment_agreement2, w1_.number_of_installments AS number_of_installments3, w0_.id AS id4, w0_.name AS name5, w0_.note AS note6, w0_.lft AS lft7, w0_.rgt AS rgt8, w0_.root AS root9, w0_.lvl AS lvl10, w0_.created AS created11, w0_.updated AS updated12, w0_.last_expiration_notice AS last_expiration_notice13, w2_.name AS name14, w0_.status AS status15, w0_.date_start AS date_start16, w0_.date_finish AS date_finish17, w0_.price AS price18, w0_.currency AS currency19, w0_.conversion AS conversion20 FROM webfactory_service_projects w1_ INNER JOIN webfactory_service_services w0_ ON w1_.id = w0_.id LEFT JOIN webfactory_company_customers w2_ ON w0_.customer_id = w2_.id WHERE w0_.date_finish >= ? OR w0_.date_finish <= ? LIMIT 20

Parameters: [Object(DateTime), Object(DateTime)]

In the WHERE, this: WHERE w0_.datefinish >= ? OR w0.date_finish <= ?

must be: WHERE w0_.datefinish >= ? AND w0.date_finish <= ?

parameters: 05/08/1997 00:00:00 and 05/08/1997 23:59:59

Performing the change i post early, all works to me.

PS: Sorry my ENGLISH, i only speak PHP :P

Abhoryo commented 12 years ago

I can't reproduice it. Did you change the data conjunction yourself ?

clubdesarrolladores commented 12 years ago

I only change DateColumn.php (line 40) (first post).

Here is a action controller:

/**
 * Lists all Project entities.
 *
 */
public function indexAction()
{
    /* @var $source \APY\DataGridBundle\Grid\Source\Entity */
    $source = new Entity('WebFactoryServiceBundle:Project');
    /* @var $grid \APY\DataGridBundle\Grid\Grid */
    $grid = $this->get('grid');
    $grid->setHiddenColumns('id');
    $grid->setVisibleColumns(array('name', 'customer.name' , 'status', 'date_start', 'date_finish', 'price'));
    $grid->setSource($source);
    $deleteRowAction = new RowAction('Delete', 'project_delete', true, '_self', array('class' => 'grid_delete_action'));
    $grid->addRowAction($deleteRowAction);
    $editRowAction = new RowAction('Edit', 'project_edit');
    $grid->addRowAction($editRowAction);
    $showRowAction = new RowAction('Show', 'project_show');
    $grid->addRowAction($showRowAction);
    $grid->setActionsColumnSeparator("&nbsp;&nbsp;");
    return $grid->getGridResponse('WebFactoryServiceBundle:Project:index.html.twig', array('expireds' => 'project_expireds'));
}

May be entity inheritance + tree behavior is the problem?

<?php

namespace WebFactory\ServiceBundle\Entity;

use Doctrine\Common\Collections\ArrayCollection;
use Gedmo\Mapping\Annotation as Gedmo;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Bridge\Doctrine\Validator\Constraints as DoctrineAssert;
use APY\DataGridBundle\Grid\Mapping as Grid;
use WebFactory\CommonBundle\Validator\Constraints as CommonAssert;

/**
 * WebFactory\ServiceBundle\Entity\Service
 *
 * @ORM\Entity(repositoryClass="WebFactory\ServiceBundle\Entity\Repository\ServiceRepository")
 * @ORM\Table(name="webfactory_service_services")
 * @ORM\InheritanceType("JOINED")
 * @ORM\DiscriminatorColumn(name="service_type", type="string")
 * @ORM\DiscriminatorMap({"project" = "Project", "web_domain" = "WebDomain", "web_hosting" = "WebHosting"})
 * @Gedmo\Tree(type="nested")
 * @CommonAssert\Conversion();
 */
class Service

After commit "Add grid data conjunction setting" 2142e00f4d0a07c4f1e3575ce1d89aca8955ba56 error persists.

Abhoryo commented 12 years ago

Yeah my last commit is not about your problem

Abhoryo commented 12 years ago

Luckily, I found the bug by accident.