Created
July 10, 2020 12:00
-
-
Save cgi-caesar/fa6367ab8726ab6aea4ae5d7f3d08202 to your computer and use it in GitHub Desktop.
aMember (site.php): Affiliate autocomplete without full access to affiliate module
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()->router->addRoute('aff-autocomplete', new Am_Mvc_Router_Route('aff/admin/autocomplete', [ | |
'module' => 'default', | |
'controller' => 'admin-aff-autocomplete', | |
'action' => 'index', | |
])); | |
class AdminAffAutocompleteController extends Am_Mvc_Controller | |
{ | |
function checkAdminPermissions(Admin $admin) | |
{ | |
return true; | |
} | |
function indexAction() | |
{ | |
if (!$term = $this->getParam('term')) { | |
return null; | |
} | |
$term = "%{$term}%"; | |
$exclude = $this->getInt('exclude'); | |
$q = new Am_Query($this->getDi()->userTable); | |
$q->addWhere( | |
'((t.login LIKE ?) OR (t.email LIKE ?) OR (t.name_f LIKE ?) OR (t.name_l LIKE ?))', | |
$term, $term, $term, $term); | |
if ($exclude) { | |
$q->addWhere('user_id<>?', $exclude); | |
} | |
$q->addWhere('is_affiliate>?', 0); | |
$qq = $q->query(0, 10); | |
$ret = []; | |
while ($r = $this->getDi()->db->fetchRow($qq)) { | |
$ret[] = [ | |
'label' => sprintf('%s / "%s" <%s>', $r['login'], $r['name_f'] . ' ' . $r['name_l'], $r['email']), | |
'value' => $r['login'] | |
]; | |
} | |
if ($q->getFoundRows() > 10) | |
$ret[] = [ | |
'label' => sprintf("... %d more rows found ...", $q->getFoundRows() - 10), | |
'value' => null, | |
]; | |
$this->ajaxResponse($ret); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment