Commit a39e9915 authored by okhin's avatar okhin 🚴

Adding a filter by date

parent bb599f4f
......@@ -70,7 +70,7 @@ class DonationSeeder extends AbstractSeed
array(
'id' => 3,
'status' => 100,
'datec' => '2016-06-10 12:34',
'datec' => '2016-06-11 12:34',
'somme' => 100,
'lang' => 'fr_FR',
'cadeau' => 1,
......
......@@ -43,7 +43,7 @@ class DonationFinder
*
* @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
SELECT d.id as id,
......@@ -87,6 +87,11 @@ EOQ;
$params['status'] = $status;
}
if ('' !== $date1) {
$query .= ' AND d.datec BETWEEN (:date1) AND (:date2) ';
$params['date1'] = $date1;
$params['date2'] = $date2;
}
$first = ($page - 1) * $limit;
$last = ($page) * $limit;
$query .= " ORDER BY datec DESC LIMIT $first, $last";
......
......@@ -43,10 +43,12 @@ class DonationFinderTest extends FunctionalTest
public function testAdminSearchDonations()
{
$this->assertCount(1, $this->container['donation_finder']->adminSearch($text='alice@example.org', $sum='', $public='', $status=''));
$this->assertCount(2, $this->container['donation_finder']->adminSearch($text='', $sum='1000', $public='', $status=''));
$this->assertCount(2, $this->container['donation_finder']->adminSearch($text='', $sum='', $public='0', $status=''));
$this->assertCount(2, $this->container['donation_finder']->adminSearch($text='', $sum='', $public='', $status='1'));
$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='', $date1=''));
$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', $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