Last active
March 12, 2021 15:46
-
-
Save cgi-caesar/cf4a69a903a950907e2e40ae81592dad to your computer and use it in GitHub Desktop.
aMember (site.php): extend standard filter for payments grid
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
Am_Di::getInstance()->hook->add('gridPaymentInitGrid', function(Am_Event_Grid $e) { | |
$e->getGrid()->setFilter(new Am_Grid_Filter_PaymentsAdv); | |
}); | |
class Am_Grid_Filter_PaymentsAdv extends Am_Grid_Filter_Payments | |
{ | |
public function renderInputs() | |
{ | |
return parent::renderInputs() | |
. $this->renderCheckbox('only_recurring', ___('display only recurring')) | |
. $this->renderCheckbox('only_not_recurring', ___('display only not recurring')); | |
} | |
public function renderCheckbox($name, $title) | |
{ | |
return sprintf(<<<CUT | |
<label> | |
<input type="hidden" name="%s_filter[$name]" value="0" /> | |
<input type="checkbox" name="%s_filter[$name]" value="1" %s /> %s</label> | |
CUT | |
, $this->grid->getId() | |
, $this->grid->getId() | |
, (!empty($this->vars['filter'][$name]) ? 'checked' : '') | |
, Am_Html::escape($title) | |
); | |
} | |
protected function applyFilter() | |
{ | |
parent::applyFilter(); | |
$filter = (array)$this->vars['filter']; | |
if (!empty($filter['only_recurring'])) { | |
$q = $this->grid->getDataSource()->getDataSourceQuery(); | |
if (!$this->isInvoiceJoin) { | |
$q->leftJoin('?_invoice', 'i', 't.invoice_id=i.invoice_id'); | |
$this->isInvoiceJoin = true; | |
} | |
$q->addWhere('rebill_times>0'); | |
} | |
if (!empty($filter['only_not_recurring'])) { | |
$q = $this->grid->getDataSource()->getDataSourceQuery(); | |
if (!$this->isInvoiceJoin) { | |
$q->leftJoin('?_invoice', 'i', 't.invoice_id=i.invoice_id'); | |
$this->isInvoiceJoin = true; | |
} | |
$q->addWhere('IFNULL(rebill_times,0) = 0'); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment