From d3600e688a7a935a87200b05c05209f4cf4b3985 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Sat, 29 Aug 2015 08:16:18 -0700 Subject: [PATCH] CRM_Core_BAO_ActionSchedule::getSelection - Make it easier to trace dataflow --- CRM/Admin/Form/ScheduleReminders.php | 17 ++++++------- CRM/Core/BAO/ActionSchedule.php | 38 +++++++++------------------- 2 files changed, 20 insertions(+), 35 deletions(-) diff --git a/CRM/Admin/Form/ScheduleReminders.php b/CRM/Admin/Form/ScheduleReminders.php index cac7e5ae9a..013cb63e20 100644 --- a/CRM/Admin/Form/ScheduleReminders.php +++ b/CRM/Admin/Form/ScheduleReminders.php @@ -111,12 +111,11 @@ class CRM_Admin_Form_ScheduleReminders extends CRM_Admin_Form { ); $selectionOptions = CRM_Core_BAO_ActionSchedule::getSelection($mappingID); - extract($selectionOptions); - $this->assign('entityMapping', json_encode($entityMapping)); - $this->assign('recipientMapping', json_encode($recipientMapping)); + $this->assign('entityMapping', json_encode($selectionOptions['entityMapping'])); + $this->assign('recipientMapping', json_encode($selectionOptions['recipientMapping'])); if (empty($this->_context)) { - if (empty($sel1)) { + if (empty($selectionOptions['sel1'])) { CRM_Core_Error::fatal('Could not find mapping for scheduled reminders.'); } @@ -129,7 +128,7 @@ class CRM_Admin_Form_ScheduleReminders extends CRM_Admin_Form { 'style' => 'vertical-align: top;', ) ); - $sel->setOptions(array($sel1, $sel2, $sel3)); + $sel->setOptions(array($selectionOptions['sel1'], $selectionOptions['sel2'], $selectionOptions['sel3'])); if (is_a($sel->_elements[1], 'HTML_QuickForm_select')) { // make second selector a multi-select - @@ -144,7 +143,7 @@ class CRM_Admin_Form_ScheduleReminders extends CRM_Admin_Form { } } else { - $options = $sel3[$this->_mappingID][0]; + $options = $selectionOptions['sel3'][$this->_mappingID][0]; $attributes = array('multiple' => 'multiple', 'class' => 'crm-select2 huge', 'placeholder' => $options[0]); unset($options[0]); $this->add('select', 'entity', ts('Recipient(s)'), $options, TRUE, $attributes); @@ -192,7 +191,7 @@ class CRM_Admin_Form_ScheduleReminders extends CRM_Admin_Form { //reminder_action $this->add('select', 'start_action_condition', ts('Action Condition'), $condition); - $this->add('select', 'start_action_date', ts('Date Field'), $sel4, TRUE); + $this->add('select', 'start_action_date', ts('Date Field'), $selectionOptions['sel4'], TRUE); $this->addElement('checkbox', 'record_activity', $recordActivity); @@ -205,7 +204,7 @@ class CRM_Admin_Form_ScheduleReminders extends CRM_Admin_Form { $this->add('select', 'end_frequency_unit', ts('until'), $freqUnitsDisplay); $this->add('select', 'end_frequency_interval', ts('until'), $numericOptions); $this->add('select', 'end_action', ts('Repetition Condition'), $condition, TRUE); - $this->add('select', 'end_date', ts('Date Field'), $sel4, TRUE); + $this->add('select', 'end_date', ts('Date Field'), $selectionOptions['sel4'], TRUE); $this->add('text', 'from_name', ts('From Name')); $this->add('text', 'from_email', ts('From Email')); @@ -225,7 +224,7 @@ class CRM_Admin_Form_ScheduleReminders extends CRM_Admin_Form { $this->add('select', 'limit_to', ts('Limit Options'), $limitOptions, FALSE, array('onChange' => "showHideByValue('limit_to','','recipient', 'select','select',true);")); - $this->add('select', 'recipient', $recipientLabels['other'], $sel5, + $this->add('select', 'recipient', $recipientLabels['other'], $selectionOptions['sel5'], FALSE, array('onchange' => "showHideByValue('recipient','manual','recipientManual','table-row','select',false); showHideByValue('recipient','group','recipientGroup','table-row','select',false);") ); diff --git a/CRM/Core/BAO/ActionSchedule.php b/CRM/Core/BAO/ActionSchedule.php index 8085b5b366..14783381a6 100755 --- a/CRM/Core/BAO/ActionSchedule.php +++ b/CRM/Core/BAO/ActionSchedule.php @@ -78,31 +78,22 @@ class CRM_Core_BAO_ActionSchedule extends CRM_Core_DAO_ActionSchedule { */ public static function getSelection($id = NULL) { $mappings = CRM_Core_BAO_ActionSchedule::getMappings(); + $selectedMapping = $mappings[$id ? $id : 1]; - $entityValueLabels = $entityStatusLabels = $dateFieldLabels = array(); - $entityRecipientLabels = $entityRecipientNames = array(); - - if (!$id) { - $id = 1; - } - + $entityValueLabels = array(); foreach ($mappings as $mapping) { /** @var \Civi\ActionSchedule\Mapping $mapping */ - - $mappingId = $mapping->getId(); - $entityValueLabels[$mappingId] = $mapping->getValueLabels(); + $entityValueLabels[$mapping->getId()] = $mapping->getValueLabels(); // Not sure why: everything *except* contact-dates have a $valueLabel. if ($mapping->getId() !== CRM_Contact_ActionMapping::CONTACT_MAPPING_ID) { $valueLabel = array('- ' . strtolower($mapping->getValueHeader()) . ' -'); $entityValueLabels[$mapping->getId()] = $valueLabel + $entityValueLabels[$mapping->getId()]; } + } - if ($mapping->getId() == $id) { - $dateFieldLabels = $mapping->getDateFields(); - $entityRecipientLabels = $mapping->getRecipientTypes() + self::getAdditionalRecipients(); - $entityRecipientNames = array_combine(array_keys($entityRecipientLabels), array_keys($entityRecipientLabels)); - } - + $entityStatusLabels = array(); + foreach ($mappings as $mapping) { + /** @var \Civi\ActionSchedule\Mapping $mapping */ $statusLabel = array('- ' . strtolower($mapping->getStatusHeader()) . ' -'); $entityStatusLabels[$mapping->getId()] = $entityValueLabels[$mapping->getId()]; foreach ($entityStatusLabels[$mapping->getId()] as $kkey => & $vval) { @@ -110,21 +101,16 @@ class CRM_Core_BAO_ActionSchedule extends CRM_Core_DAO_ActionSchedule { } } - $entityLabels = array_map(function ($v) { - return $v->getLabel(); - }, $mappings); - $entityNames = array_map(function ($v) { - return $v->getEntity(); - }, $mappings); + $entityRecipientLabels = $selectedMapping->getRecipientTypes() + self::getAdditionalRecipients(); return array( - 'sel1' => $entityLabels, + 'sel1' => CRM_Utils_Array::collectMethod('getLabel', $mappings), 'sel2' => $entityValueLabels, 'sel3' => $entityStatusLabels, - 'sel4' => $dateFieldLabels, + 'sel4' => $selectedMapping->getDateFields(), 'sel5' => $entityRecipientLabels, - 'entityMapping' => $entityNames, - 'recipientMapping' => $entityRecipientNames, + 'entityMapping' => CRM_Utils_Array::collectMethod('getEntity', $mappings), + 'recipientMapping' => array_combine(array_keys($entityRecipientLabels), array_keys($entityRecipientLabels)), ); } -- 2.25.1