Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NFC Code cleanup to core task class #12316

Merged
merged 1 commit into from
Jun 20, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is this used?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn't find any instances?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://github.com/civicrm/civicrm-core/pull/12316/files#diff-8e58e0ef24ffee40975a92a797f7acecR135

It's a baby step towards making that preProcessCommon function generic enough to handle more than just the case task.


/**
* @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