Created
June 24, 2014 19:11
-
-
Save iansltx/6d0181c835e5afbf2965 to your computer and use it in GitHub Desktop.
Query Building
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 | |
class MyQuery { | |
protected function buildCollectionQuery($is_count_query = false) { | |
$qs = $is_count_query ? $this->baseCountQS : $this->baseCollectionQS; | |
$qsParams = ['']; | |
if ($this->showInactive === false) { | |
$qs .= " && u.userStatus = 'active'"; | |
} | |
if ($this->nameFilter !== null) { | |
$qs .= " && a.companyName LIKE ?"; | |
$qsParams[] = '%'.$this->nameFilter.'%'; | |
} | |
if (!$this->user->isAdmin()) { | |
$qs .= " && u.userManager = ?"; | |
$qsParams[] = $this->user->getId(); | |
} | |
if (count($this->sorts)) { | |
$qs .= ' ORDER BY ' . implode(', ', $this->sorts); | |
} | |
if (!$is_count_query) { | |
$qs .= ' LIMIT ' . $this->pageSize . ' OFFSET ' . $this->pageSize * ($this->page - 1); | |
} | |
return ['query' => $qs, 'params' => $qsParams]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment