X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=CRM%2FContribute%2FForm%2FSoftCredit.php;h=bb1686d410d347519054efe5f363f036ca2bcb35;hb=c156d4d6f1d69cfb9e578901f485b67e39f70cf3;hp=22d653083be687c1514fd80bdcf500436fadffa6;hpb=fceab3b6c4cd8383c4e91346a177f44558db36f1;p=civicrm-core.git diff --git a/CRM/Contribute/Form/SoftCredit.php b/CRM/Contribute/Form/SoftCredit.php index 22d653083b..bb1686d410 100644 --- a/CRM/Contribute/Form/SoftCredit.php +++ b/CRM/Contribute/Form/SoftCredit.php @@ -1,7 +1,7 @@ addMoney("{$prefix}amount[{$rowNumber}]", ts('Amount')); + $form->addMoney("{$prefix}amount[{$rowNumber}]", ts('Amount'), FALSE, NULL, FALSE); if (!empty($form->_softCreditInfo['soft_credit'][$rowNumber]['soft_credit_id'])) { $form->add('hidden', "{$prefix}id[{$rowNumber}]", $form->_softCreditInfo['soft_credit'][$rowNumber]['soft_credit_id']); } } + // CRM-7368 allow user to set or edit PCP link for contributions + $siteHasPCPs = CRM_Contribute_PseudoConstant::pcPage(); + if (!CRM_Utils_Array::crmIsEmptyArray($siteHasPCPs)) { + $form->assign('siteHasPCPs', 1); + $pcpDataUrl = CRM_Utils_System::url('civicrm/ajax/rest', + 'className=CRM_Contact_Page_AJAX&fnName=getPCPList&json=1&context=contact&reset=1', + FALSE, NULL, FALSE + ); + $form->assign('pcpDataUrl', $pcpDataUrl); + $form->addElement('text', 'pcp_made_through', ts('Credit to a Personal Campaign Page')); + $form->addElement('hidden', 'pcp_made_through_id', '', array('id' => 'pcp_made_through_id')); + $form->addElement('checkbox', 'pcp_display_in_roll', ts('Display in Honor Roll?'), NULL); + $form->addElement('text', 'pcp_roll_nickname', ts('Name (for Honor Roll)')); + $form->addElement('textarea', 'pcp_personal_note', ts('Personal Note (for Honor Roll)')); + } $form->assign('showSoftCreditRow', $showSoftCreditRow); $form->assign('rowCount', $item_count); $form->assign('showCreateNew', $showCreateNew); @@ -88,13 +103,13 @@ class CRM_Contribute_Form_SoftCredit { static function setDefaultValues(&$defaults, &$form) { if (!empty($form->_softCreditInfo['soft_credit'])) { foreach ($form->_softCreditInfo['soft_credit'] as $key => $value) { - $defaults["soft_credit_amount[$key]"] = $value['amount']; + $defaults["soft_credit_amount[$key]"] = CRM_Utils_Money::format($value['amount'], NULL, '%a'); $defaults["soft_credit_contact_select_id[$key]"] = $value['contact_id']; } } - if (CRM_Utils_Array::value('pcp_id', $form->_softCreditInfo['pcp'])) { - $pcpInfo = $form->_softCreditInfo['pcp']; + elseif (CRM_Utils_Array::value('pcp_id', $form->_softCreditInfo)) { + $pcpInfo = $form->_softCreditInfo; $pcpId = CRM_Utils_Array::value('pcp_id', $pcpInfo); $pcpTitle = CRM_Core_DAO::getFieldValue('CRM_PCP_DAO_PCP', $pcpId, 'title'); $contributionPageTitle = CRM_PCP_BAO_PCP::getPcpPageTitle($pcpId, 'contribute'); @@ -105,5 +120,47 @@ class CRM_Contribute_Form_SoftCredit { $defaults['pcp_personal_note'] = CRM_Utils_Array::value('pcp_personal_note', $pcpInfo); } } + + /** + * global form rule + * + * @param array $fields the input form values + * + * @return true if no errors, else array of errors + * @access public + * @static + */ + static function formRule($fields) { + $errors = array(); + + // if honor roll fields are populated but no PCP is selected + if (!CRM_Utils_Array::value('pcp_made_through_id', $fields)) { + if (CRM_Utils_Array::value('pcp_display_in_roll', $fields) || + CRM_Utils_Array::value('pcp_roll_nickname', $fields) || + CRM_Utils_Array::value('pcp_personal_note', $fields) + ) { + $errors['pcp_made_through'] = ts('Please select a Personal Campaign Page, OR uncheck Display in Honor Roll and clear both the Honor Roll Name and the Personal Note field.'); + } + } + + if (!empty($fields['soft_credit_amount'])) { + $repeat = array_count_values($fields['soft_credit_contact_select_id']); + foreach ($fields['soft_credit_amount'] as $key => $val) { + if (!empty($fields['soft_credit_contact_select_id'][$key])) { + if ($repeat[$fields['soft_credit_contact_select_id'][$key]] > 1) { + $errors["soft_credit_contact_select_id[$key]"] = ts('You cannot enter multiple soft credits for the same contact.'); + } + if ($fields['soft_credit_amount'][$key] + && (CRM_Utils_Rule::cleanMoney($fields['soft_credit_amount'][$key]) > CRM_Utils_Rule::cleanMoney($fields['total_amount']))) { + $errors["soft_credit_amount[$key]"] = ts('Soft credit amount cannot be more than the total amount.'); + } + if (empty($fields['soft_credit_amount'][$key])) { + $errors["soft_credit_amount[$key]"] = ts('Please enter the soft credit amount.'); + } + } + } + } + return $errors; + } }