* @return string
*/
public function whereGroupClause($field, $value, $op) {
- if (empty($this->contactTempTable)) {
+ if ($op == 'notin') {
+ // We do not have an optimisation for this scenario at this stage. Use
+ // parent.
+ return parent::whereGroupClause($field, $value, $op);
+ }
+
+ if (empty($this->groupTempTable)) {
$group = new CRM_Contact_DAO_Group();
$group->is_active = 1;
$group->find();
* @return string
*/
public function buildQuery($applyLimit = TRUE) {
+
+ // Calling where & select before FROM allows us to build temp tables to use in from.
+ $this->where();
$this->select();
$this->from();
$this->customDataFrom(empty($this->contactTempTable));
- $this->where();
+
$this->groupBy();
$this->orderBy();
$this->getPermissionedFTQuery($this);