I took the time to audit and remove the code blocks which had been previously commented as "silly but difficult to audit"
CRM_Contact_Form_Task_PDFLetterCommon::preProcess($this);
// store case id if present
- $this->_caseId = CRM_Utils_Request::retrieve('caseid', 'Positive', $this, FALSE);
+ $this->_caseId = CRM_Utils_Request::retrieve('caseid', 'CommaSeparatedIntegers', $this, FALSE);
+ if (!empty($this->_caseId) && strpos($this->_caseId, ',')) {
+ $this->_caseIds = explode(',', $this->_caseId);
+ unset($this->_caseId);
+ }
// retrieve contact ID if this is 'single' mode
- $cid = CRM_Utils_Request::retrieve('cid', 'Positive', $this, FALSE);
+ $cid = CRM_Utils_Request::retrieve('cid', 'CommaSeparatedIntegers', $this, FALSE);
if ($cid) {
// this is true in non-search context / single mode
if ($cid) {
CRM_Contact_Form_Task_PDFLetterCommon::preProcessSingle($this, $cid);
$this->_single = TRUE;
- $this->_cid = $cid;
}
else {
parent::preProcess();
*/
public function listTokens() {
$tokens = CRM_Core_SelectValues::contactTokens();
- if (isset($this->_caseId)) {
- $caseTypeId = CRM_Core_DAO::getFieldValue('CRM_Case_DAO_Case', $this->_caseId, 'case_type_id');
+ if (isset($this->_caseId) || isset($this->_caseIds)) {
+ // For a single case, list tokens relevant for only that case type
+ $caseTypeId = isset($this->_caseId) ? CRM_Core_DAO::getFieldValue('CRM_Case_DAO_Case', $this->_caseId, 'case_type_id') : NULL;
$tokens += CRM_Core_SelectValues::caseTokens($caseTypeId);
}
return $tokens;
* @param int $cid
*/
public static function preProcessSingle(&$form, $cid) {
- $form->_contactIds = array($cid);
+ $form->_contactIds = explode(',', $cid);
// put contact display name in title for single contact mode
- CRM_Utils_System::setTitle(ts('Print/Merge Document for %1', array(1 => CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $cid, 'display_name'))));
+ if (count($form->_contactIds) === 1) {
+ CRM_Utils_System::setTitle(ts('Print/Merge Document for %1', array(1 => CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $cid, 'display_name'))));
+ }
}
/**
// CRM-16725 Skip creation of activities if user is previewing their PDF letter(s)
if ($isLiveMode) {
-
- // This seems silly, but the old behavior was to first check `_cid`
- // and then use the provided `$contactIds`. Probably not even necessary,
- // but difficult to audit.
- $contactIds = $form->_cid ? array($form->_cid) : $form->_contactIds;
- $activityIds = self::createActivities($form, $html_message, $contactIds, $formValues['subject'], CRM_Utils_Array::value('campaign_id', $formValues));
+ $activityIds = self::createActivities($form, $html_message, $form->_contactIds, $formValues['subject'], CRM_Utils_Array::value('campaign_id', $formValues));
}
if (!empty($formValues['document_file_path'])) {
case 'multiple':
// One activity per contact.
- foreach ($contactIds as $contactId) {
+ foreach ($contactIds as $i => $contactId) {
$fullParams = array(
'target_contact_id' => $contactId,
) + $activityParams;
+ if (!empty($form->_caseId)) {
+ $fullParams['case_id'] = $form->_caseId;
+ }
+ elseif (!empty($form->_caseIds[$i])) {
+ $fullParams['case_id'] = $form->_caseIds[$i];
+ }
+
if (isset($perContactHtml[$contactId])) {
$fullParams['details'] = implode('<hr>', $perContactHtml[$contactId]);
}
$fullParams = array(
'target_contact_id' => $contactIds,
) + $activityParams;
- $activity = CRM_Activity_BAO_Activity::create($fullParams);
- $activityIds[] = $activity->id;
+ if (!empty($form->_caseId)) {
+ $fullParams['case_id'] = $form->_caseId;
+ }
+ elseif (!empty($form->_caseIds)) {
+ $fullParams['case_id'] = $form->_caseIds;
+ }
+ $activity = civicrm_api3('Activity', 'create', $fullParams);
+ $activityIds[] = $activity['id'];
break;
default:
throw new CRM_Core_Exception("Unrecognized option in recordGeneratedLetters: " . Civi::settings()->get('recordGeneratedLetters'));
}
- if (!empty($form->_caseId)) {
- foreach ($activityIds as $activityId) {
- $caseActivityParams = array('activity_id' => $activityId, 'case_id' => $form->_caseId);
- CRM_Case_BAO_Case::processCaseActivity($caseActivityParams);
- }
- }
-
return $activityIds;
}
$this->skipOnHold = $this->skipDeceased = FALSE;
CRM_Contact_Form_Task_PDFLetterCommon::preProcess($this);
// store case id if present
- $this->_caseId = CRM_Utils_Request::retrieve('caseid', 'Positive', $this, FALSE);
+ $this->_caseId = CRM_Utils_Request::retrieve('caseid', 'CommaSeparatedIntegers', $this, FALSE);
+ if (!empty($this->_caseId) && strpos($this->_caseId, ',')) {
+ $this->_caseIds = explode(',', $this->_caseId);
+ unset($this->_caseId);
+ }
// retrieve contact ID if this is 'single' mode
- $cid = CRM_Utils_Request::retrieve('cid', 'Positive', $this, FALSE);
+ $cid = CRM_Utils_Request::retrieve('cid', 'CommaSeparatedIntegers', $this, FALSE);
$this->_activityId = CRM_Utils_Request::retrieve('id', 'Positive', $this, FALSE);
if ($cid) {
CRM_Contact_Form_Task_PDFLetterCommon::preProcessSingle($this, $cid);
$this->_single = TRUE;
- $this->_cid = $cid;
}
else {
parent::preProcess();
}
}
- // This seems silly, but the old behavior was to first check `_cid`
- // and then use the provided `$contactIds`. Probably not even necessary,
- // but difficult to audit.
- $contactIds = $form->_cid ? array($form->_cid) : array_keys($contacts);
+ $contactIds = array_keys($contacts);
self::createActivities($form, $html_message, $contactIds, CRM_Utils_Array::value('subject', $formValues, ts('Thank you letter')), CRM_Utils_Array::value('campaign_id', $formValues), $contactHtml);
$html = array_diff_key($html, $emailedHtml);
$html_message,
$categories
);
- // This seems silly, but the old behavior was to first check `_cid`
- // and then use the provided `$contactIds`. Probably not even necessary,
- // but difficult to audit.
- $contactIDs = $form->_cid ? array($form->_cid) : $contactIDs;
self::createActivities($form, $html_message, $contactIDs, $formValues['subject'], CRM_Utils_Array::value('campaign_id', $formValues));
CRM_Utils_PDF_Utils::html2pdf($html, "CiviLetter.pdf", FALSE, $formValues);
return FALSE;
}
+ /**
+ * @param $value
+ *
+ * @return bool
+ */
+ public static function commaSeparatedIntegers($value) {
+ foreach (explode(',', $value) as $val) {
+ if (!self::positiveInteger($val)) {
+ return FALSE;
+ }
+ }
+ return TRUE;
+ }
+
/**
* @param $value
*
}
break;
+ case 'CommaSeparatedIntegers':
+ if (CRM_Utils_Rule::commaSeparatedIntegers($data)) {
+ return $data;
+ }
+ break;
+
case 'Boolean':
if (CRM_Utils_Rule::boolean($data)) {
return $data;