// add activity fields
$fields = CRM_Activity_BAO_Activity::exportableFields();
$this->_fields = array_merge($this->_fields, $fields);
+
+ // add any fields supported by extensions
+ $extFields = CRM_Extension_System::singleton()->getManager()->getSearchQueryFields();
+ $this->_fields = array_merge($this->_fields, $extFields);
}
// basically do all the work once, and then reuse it
//fix for CRM-951
CRM_Core_Component::alterQuery($this, 'select');
+ CRM_Extension_System::singleton()->getManager()->alterSearchQuery($this, 'select');
+
if (!empty($this->_cfIDs)) {
$this->_customQuery = new CRM_Core_BAO_CustomQuery($this->_cfIDs, TRUE);
$this->_customQuery->query();
}
CRM_Core_Component::alterQuery($this, 'where');
+
+ CRM_Extension_System::singleton()->getManager()->alterSearchQuery($this, 'where');
}
if ($this->_customQuery) {
default:
$from .= CRM_Core_Component::from($name, $mode, $side);
+ $from .= CRM_Extension_System::singleton()->getManager()->buildSearchfrom($name, $mode, $side);
continue;
}
}
$this->mapper->refresh();
}
+ public function &getSearchQueryFields() {
+ $extFields = array();
+ foreach (self::getActiveSearchQueryObjects() as $obj) {
+ $flds = $obj->getFields();
+ $extFields = array_merge($extFields, $flds);
+ }
+ return $extFields;
+ }
+
+ public function alterSearchQuery(&$query, $fnName) {
+ foreach (self::getActiveSearchQueryObjects() as $obj) {
+ $obj->$fnName($query);
+ }
+ }
+
+ public function buildSearchfrom($fieldName, $mode, $side) {
+ foreach (self::getActiveSearchQueryObjects() as $obj) {
+ $obj->from($fieldName, $mode, $side);
+ }
+ }
+
+ public function getActiveSearchQueryObjects() {
+ $queryObjects = array();
+ $extStatus = $this->getStatuses();
+ foreach ($extStatus as $key => $status) {
+ if ($status == CRM_Extension_Manager::STATUS_INSTALLED) {
+ $path = $this->mapper->keyToBasePath($key);
+ $info = $this->mapper->keyToInfo($key);
+ $classFile = $info->civix['namespace'] . DIRECTORY_SEPARATOR . 'BAO' . DIRECTORY_SEPARATOR . 'Query';
+ $queryFile = $path . DIRECTORY_SEPARATOR . "{$classFile}.php";
+ if (file_exists($queryFile)) {
+ require_once $queryFile;
+ $className = str_replace(DIRECTORY_SEPARATOR, '_', $classFile);
+ $obj = new $className();
+ $queryObjects[] = $obj;
+ }
+ }
+ }
+ return $queryObjects;
+ }
+
// ----------------------
/**