Commit 63f5bf82 authored by okhin's avatar okhin 🚴

Adding a filter by date

parent 8ee23dea
Pipeline #2249 passed with stages
in 12 seconds
...@@ -70,7 +70,7 @@ class DonationSeeder extends AbstractSeed ...@@ -70,7 +70,7 @@ class DonationSeeder extends AbstractSeed
array( array(
'id' => 3, 'id' => 3,
'status' => 100, 'status' => 100,
'datec' => '2016-06-10 12:34', 'datec' => '2016-06-11 12:34',
'somme' => 100, 'somme' => 100,
'lang' => 'fr_FR', 'lang' => 'fr_FR',
'cadeau' => 1, 'cadeau' => 1,
......
...@@ -43,7 +43,7 @@ class DonationFinder ...@@ -43,7 +43,7 @@ class DonationFinder
* *
* @return array * @return array
*/ */
public function adminSearch($text, $sum, $public, $status, $limit = 50, $page = 1) public function adminSearch($text, $sum, $public, $status, $date1, $date2 = "2999-12-31 23:59:59", $limit = 50, $page = 1)
{ {
$query = <<<EOQ $query = <<<EOQ
SELECT d.id as id, SELECT d.id as id,
...@@ -87,6 +87,11 @@ EOQ; ...@@ -87,6 +87,11 @@ EOQ;
$params['status'] = $status; $params['status'] = $status;
} }
if ('' !== $date1) {
$query .= ' AND d.datec BETWEEN (:date1) AND (:date2) ';
$params['date1'] = $date1;
$params['date2'] = $date2;
}
$first = ($page - 1) * $limit; $first = ($page - 1) * $limit;
$last = ($page) * $limit; $last = ($page) * $limit;
$query .= " ORDER BY datec DESC LIMIT $first, $last"; $query .= " ORDER BY datec DESC LIMIT $first, $last";
......
...@@ -43,10 +43,12 @@ class DonationFinderTest extends FunctionalTest ...@@ -43,10 +43,12 @@ class DonationFinderTest extends FunctionalTest
public function testAdminSearchDonations() public function testAdminSearchDonations()
{ {
$this->assertCount(1, $this->container['donation_finder']->adminSearch($text='alice@example.org', $sum='', $public='', $status='')); $this->assertCount(1, $this->container['donation_finder']->adminSearch($text='alice@example.org', $sum='', $public='', $status='', $date1=''));
$this->assertCount(2, $this->container['donation_finder']->adminSearch($text='', $sum='1000', $public='', $status='')); $this->assertCount(2, $this->container['donation_finder']->adminSearch($text='', $sum='1000', $public='', $status='', $date1=''));
$this->assertCount(2, $this->container['donation_finder']->adminSearch($text='', $sum='', $public='0', $status='')); $this->assertCount(2, $this->container['donation_finder']->adminSearch($text='', $sum='', $public='0', $status='', $date1=''));
$this->assertCount(2, $this->container['donation_finder']->adminSearch($text='', $sum='', $public='', $status='1')); $this->assertCount(2, $this->container['donation_finder']->adminSearch($text='', $sum='', $public='', $status='1', $date1=''));
$this->assertCount(2, $this->container['donation_finder']->adminSearch($text='', $sum='', $public='', $status='1', $date1=''));
$this->assertCount(1, $this->container['donation_finder']->adminSearch($text='', $sum='', $public='', $status='', $date1='2016-06-11 00:00:00'));
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment