*/
static $entityShortname = NULL;
- /**
- * Must be set to queryMode
- *
- * @var int
- */
- static $queryMode = CRM_Contact_BAO_Query::MODE_CONTACTS;
-
/**
* Build all the data structures needed to build the form.
*
/**
* Common pre-processing function.
*
- * @param CRM_Core_Form $form
+ * @param CRM_Core_Form_Task $form
*
* @throws \CRM_Core_Exception
*/
$sortOrder = $form->get(CRM_Utils_Sort::SORT_ORDER);
}
- $query = new CRM_Contact_BAO_Query($queryParams, NULL, NULL, FALSE, FALSE, $form::$queryMode);
+ $query = new CRM_Contact_BAO_Query($queryParams, NULL, NULL, FALSE, FALSE, $form->getQueryMode());
$query->_distinctComponentClause = " ( " . $form::$tableName . ".id )";
$query->_groupByComponentClause = " GROUP BY " . $form::$tableName . ".id ";
$result = $query->searchQuery(0, 0, $sortOrder);
);
}
+ /**
+ * Get the query mode (eg. CRM_Core_BAO_Query::MODE_CASE)
+ * Should be overridden by child classes in most cases
+ *
+ * @return int
+ */
+ public function getQueryMode() {
+ return CRM_Contact_BAO_Query::MODE_CONTACTS;
+ }
+
}
$this->_componentIds = array();
$this->_componentClause = NULL;
- $stateMachine = $this->controller->getStateMachine();
- $formName = CRM_Utils_System::getClassName($stateMachine);
- $isStandalone = $formName == 'CRM_Export_StateMachine_Standalone';
-
// we need to determine component export
- $componentName = explode('_', $formName);
$components = array('Contact', 'Contribute', 'Member', 'Event', 'Pledge', 'Case', 'Grant', 'Activity');
- if ($isStandalone) {
- $componentName = array('CRM', $this->controller->get('entity'));
- }
-
- $componentMode = $this->controller->get('component_mode');
// FIXME: This should use a modified version of CRM_Contact_Form_Search::getModeValue but it doesn't have all the contexts
- switch ($componentMode) {
+ switch ($this->getQueryMode()) {
case CRM_Contact_BAO_Query::MODE_CONTRIBUTE:
$entityShortname = 'Contribute';
+ $entityDAOName = $entityShortname;
break;
case CRM_Contact_BAO_Query::MODE_MEMBER:
case CRM_Contact_BAO_Query::MODE_EVENT:
$entityShortname = 'Event';
+ $entityDAOName = $entityShortname;
break;
case CRM_Contact_BAO_Query::MODE_PLEDGE:
$entityShortname = 'Pledge';
+ $entityDAOName = $entityShortname;
break;
case CRM_Contact_BAO_Query::MODE_CASE:
$entityShortname = 'Case';
+ $entityDAOName = $entityShortname;
break;
case CRM_Contact_BAO_Query::MODE_GRANT:
$entityShortname = 'Grant';
+ $entityDAOName = $entityShortname;
break;
case CRM_Contact_BAO_Query::MODE_ACTIVITY:
$entityShortname = 'Activity';
+ $entityDAOName = $entityShortname;
break;
default:
+ // FIXME: Code cleanup, we may not need to do this $componentName code here.
+ $formName = CRM_Utils_System::getClassName($this->controller->getStateMachine());
+ $componentName = explode('_', $formName);
+ if ($formName == 'CRM_Export_StateMachine_Standalone') {
+ $componentName = array('CRM', $this->controller->get('entity'));
+ }
$entityShortname = $componentName[1]; // Contact
+ $entityDAOName = $entityShortname;
break;
}
- if (empty($entityDAOName)) {
- $entityDAOName = $entityShortname;
- }
-
if (in_array($entityShortname, $components)) {
$this->_exportMode = constant('CRM_Export_Form_Select::' . strtoupper($entityShortname) . '_EXPORT');
$formTaskClassName = "CRM_{$entityShortname}_Form_Task";
}
}
- $formTaskClassName::preProcessCommon($this, !$isStandalone);
+ $formTaskClassName::preProcessCommon($this);
// $component is used on CRM/Export/Form/Select.tpl to display extra information for contact export
($this->_exportMode == self::CONTACT_EXPORT) ? $component = FALSE : $component = TRUE;
* @return bool|array
* mixed true or array of errors
*/
- static public function formRule($params, $files, $self) {
+ public static function formRule($params, $files, $self) {
$errors = array();
if (CRM_Utils_Array::value('mergeOption', $params) == self::EXPORT_MERGE_SAME_ADDRESS &&
/**
* Process the uploaded file.
*
- * @return void
+ * @throws \CRM_Core_Exception
*/
public function postProcess() {
$params = $this->controller->exportValues($this->_name);
return $options;
}
+ /**
+ * Get the query mode (eg. CRM_Core_BAO_Query::MODE_CASE)
+ *
+ * @return int
+ */
+ public function getQueryMode() {
+ return (int) $this->controller->get('component_mode');
+ }
+
}