* @param boolean $count
* @param boolean $sortByChar
* @param boolean $groupContacts
+ * @param boolean $onlyDeleted
*
* @return array sql query parts as an array
* @access public
*/
- function query($count = FALSE, $sortByChar = FALSE, $groupContacts = FALSE) {
+ function query($count = FALSE, $sortByChar = FALSE, $groupContacts = FALSE, $onlyDeleted = FALSE) {
+ // build permission clause
+ $this->generatePermissionClause($onlyDeleted, $count);
+
if ($count) {
if (isset($this->_rowCountClause)) {
$select = "SELECT {$this->_rowCountClause}";
$where = "WHERE {$this->_whereClause}";
}
+ if (!empty($this->_permissionWhereClause)) {
+ if (empty($where)) {
+ $where = "WHERE $this->_permissionWhereClause";
+ }
+ else {
+ $where = "$where AND $this->_permissionWhereClause";
+ }
+ }
+
$having = '';
if (!empty($this->_having)) {
foreach ($this->_having as $havingSets) {
break;
}
}
- $this->generatePermissionClause($onlyDeleted, $count);
// building the query string
$groupBy = NULL;
// note : this modifies _fromClause and _simpleFromClause
$this->includePseudoFieldsJoin($sort);
- list($select, $from, $where, $having) = $this->query($count, $sortByChar, $groupContacts);
-
- if(!empty($this->_permissionWhereClause)){
- if (empty($where)) {
- $where = "WHERE $this->_permissionWhereClause";
- }
- else {
- $where = "$where AND $this->_permissionWhereClause";
- }
- }
+ list($select, $from, $where, $having) = $this->query($count, $sortByChar, $groupContacts, $onlyDeleted);
if ($additionalWhereClause) {
$where = $where . ' AND ' . $additionalWhereClause;