Skip to content

Commit

Permalink
Merge pull request #12316 from mattwire/core_task_code_cleanup
Browse files Browse the repository at this point in the history
NFC Code cleanup to core task class
  • Loading branch information
eileenmcnaughton authored Jun 20, 2018
2 parents 4df22c8 + fe841bd commit 500b95a
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 18 deletions.
7 changes: 7 additions & 0 deletions CRM/Case/Form/Task.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ 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 Down
49 changes: 31 additions & 18 deletions CRM/Core/Form/Task.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,27 @@ abstract class CRM_Core_Form_Task extends CRM_Core_Form {
*/
public $_contactIds;

// Must be set to entity table name (eg. civicrm_participant) by child class
/**
* Must be set to entity table name (eg. civicrm_participant) by child class
*
* @var string
*/
static $tableName = NULL;
// Must be set to entity shortname (eg. event)

/**
* Must be set to entity shortname (eg. event)
*
* @var string
*/
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 @@ -88,25 +104,24 @@ public function preProcess() {
* Common pre-processing function.
*
* @param CRM_Core_Form $form
* @param bool $useTable FIXME This parameter could probably be deprecated as it's not used here
*
* @throws \CRM_Core_Exception
*/
public static function preProcessCommon(&$form, $useTable = FALSE) {
public static function preProcessCommon(&$form) {
$form->_entityIds = array();

$values = $form->controller->exportValues($form->get('searchFormName'));
$searchFormValues = $form->controller->exportValues($form->get('searchFormName'));

$form->_task = $values['task'];
$form->_task = $searchFormValues['task'];
$className = 'CRM_' . ucfirst($form::$entityShortname) . '_Task';
$entityTasks = $className::tasks();
$form->assign('taskName', $entityTasks[$form->_task]);

$ids = array();
if ($values['radio_ts'] == 'ts_sel') {
foreach ($values as $name => $value) {
$entityIds = array();
if ($searchFormValues['radio_ts'] == 'ts_sel') {
foreach ($searchFormValues as $name => $value) {
if (substr($name, 0, CRM_Core_Form::CB_PREFIX_LEN) == CRM_Core_Form::CB_PREFIX) {
$ids[] = substr($name, CRM_Core_Form::CB_PREFIX_LEN);
$entityIds[] = substr($name, CRM_Core_Form::CB_PREFIX_LEN);
}
}
}
Expand All @@ -117,24 +132,22 @@ public static function preProcessCommon(&$form, $useTable = FALSE) {
$sortOrder = $form->get(CRM_Utils_Sort::SORT_ORDER);
}

$query = new CRM_Contact_BAO_Query($queryParams, NULL, NULL, FALSE, FALSE,
CRM_Contact_BAO_Query::MODE_CASE
);
$query = new CRM_Contact_BAO_Query($queryParams, NULL, NULL, FALSE, FALSE, $form::$queryMode);
$query->_distinctComponentClause = " ( " . $form::$tableName . ".id )";
$query->_groupByComponentClause = " GROUP BY " . $form::$tableName . ".id ";
$result = $query->searchQuery(0, 0, $sortOrder);
$selector = $form::$entityShortname . '_id';
while ($result->fetch()) {
$ids[] = $result->$selector;
$entityIds[] = $result->$selector;
}
}

if (!empty($ids)) {
$form->_componentClause = ' ' . $form::$tableName . '.id IN ( ' . implode(',', $ids) . ' ) ';
$form->assign('totalSelected' . ucfirst($form::$entityShortname) . 's', count($ids));
if (!empty($entityIds)) {
$form->_componentClause = ' ' . $form::$tableName . '.id IN ( ' . implode(',', $entityIds) . ' ) ';
$form->assign('totalSelected' . ucfirst($form::$entityShortname) . 's', count($entityIds));
}

$form->_entityIds = $form->_componentIds = $ids;
$form->_entityIds = $form->_componentIds = $entityIds;

// Some functions (eg. PDF letter tokens) rely on Ids being in specific fields rather than the generic $form->_entityIds
// So we set that specific field here (eg. for cases $form->_caseIds = $form->_entityIds).
Expand Down

0 comments on commit 500b95a

Please sign in to comment.