Skip to content

Commit

Permalink
Non functional changes towards shared functions in Core_Form_Task
Browse files Browse the repository at this point in the history
  • Loading branch information
mattwire committed Jul 9, 2018
1 parent 5a95845 commit a017474
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 34 deletions.
16 changes: 9 additions & 7 deletions CRM/Case/Form/Task.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,6 @@ class CRM_Case_Form_Task extends CRM_Core_Form_Task {
// Must be set to entity shortname (eg. event)
static $entityShortname = 'case';

/**
* Must be set to queryMode
*
* @var int
*/
static $queryMode = CRM_Contact_BAO_Query::MODE_CASE;

/**
* @inheritDoc
*/
Expand All @@ -56,4 +49,13 @@ public function setContactIDs() {
);
}

/**
* Get the query mode (eg. CRM_Core_BAO_Query::MODE_CASE)
*
* @return int
*/
public function getQueryMode() {
return CRM_Contact_BAO_Query::MODE_CASE;
}

}
2 changes: 2 additions & 0 deletions CRM/Contact/Form/Task.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ public function preProcess() {
* Common pre-processing function.
*
* @param CRM_Core_Form $form
*
* @throws \CRM_Core_Exception
*/
public static function preProcessCommon(&$form) {
$form->_contactIds = array();
Expand Down
21 changes: 12 additions & 9 deletions CRM/Core/Form/Task.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,6 @@ abstract class CRM_Core_Form_Task extends CRM_Core_Form {
*/
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.
*
Expand All @@ -103,7 +96,7 @@ public function preProcess() {
/**
* Common pre-processing function.
*
* @param CRM_Core_Form $form
* @param CRM_Core_Form_Task $form
*
* @throws \CRM_Core_Exception
*/
Expand Down Expand Up @@ -132,7 +125,7 @@ public static function preProcessCommon(&$form) {
$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);
Expand Down Expand Up @@ -210,4 +203,14 @@ public function addDefaultButtons($title, $nextType = 'next', $backType = 'back'
);
}

/**
* 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;
}

}
44 changes: 26 additions & 18 deletions CRM/Export/Form/Select.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,23 +94,14 @@ public function preProcess() {
$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:
Expand All @@ -120,33 +111,41 @@ public function preProcess() {

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";
Expand Down Expand Up @@ -196,7 +195,7 @@ public function preProcess() {
}
}

$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;
Expand Down Expand Up @@ -344,7 +343,7 @@ public function buildQuickForm() {
* @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 &&
Expand Down Expand Up @@ -372,7 +371,7 @@ static public function formRule($params, $files, $self) {
/**
* Process the uploaded file.
*
* @return void
* @throws \CRM_Core_Exception
*/
public function postProcess() {
$params = $this->controller->exportValues($this->_name);
Expand Down Expand Up @@ -521,4 +520,13 @@ public static function getGreetingOptions() {
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');
}

}

0 comments on commit a017474

Please sign in to comment.