Beispiel #1
0
 /**
  * Function used to build form element for soft credit block.
  *
  * @param CRM_Core_Form $form
  *
  * @return \CRM_Core_Form
  */
 public static function buildQuickForm(&$form)
 {
     if (!empty($form->_honor_block_is_active)) {
         $ufJoinDAO = new CRM_Core_DAO_UFJoin();
         $ufJoinDAO->module = 'soft_credit';
         $ufJoinDAO->entity_id = $form->_id;
         if ($ufJoinDAO->find(TRUE)) {
             $jsonData = CRM_Contribute_BAO_ContributionPage::formatModuleData($ufJoinDAO->module_data, TRUE, 'soft_credit');
             if ($jsonData) {
                 foreach (array('honor_block_title', 'honor_block_text') as $name) {
                     $form->assign($name, $jsonData[$name]);
                 }
                 $softCreditTypes = CRM_Core_OptionGroup::values("soft_credit_type", FALSE);
                 // radio button for Honor Type
                 foreach ($jsonData['soft_credit_types'] as $value) {
                     $honorTypes[$value] = $form->createElement('radio', NULL, NULL, $softCreditTypes[$value], $value);
                 }
                 $form->addGroup($honorTypes, 'soft_credit_type_id', NULL)->setAttribute('allowClear', TRUE);
             }
         }
         return $form;
     }
     // by default generate 10 blocks
     $item_count = 11;
     $showSoftCreditRow = 2;
     if ($form->getAction() & CRM_Core_Action::UPDATE) {
         $form->_softCreditInfo = CRM_Contribute_BAO_ContributionSoft::getSoftContribution($form->_id, TRUE);
     } elseif (!empty($form->_pledgeID)) {
         //Check and select most recent completed contrubtion and use it to retrieve
         //soft-credit information to use as default for current pledge payment, CRM-13981
         $pledgePayments = CRM_Pledge_BAO_PledgePayment::getPledgePayments($form->_pledgeID);
         foreach ($pledgePayments as $id => $record) {
             if ($record['contribution_id']) {
                 $softCredits = CRM_Contribute_BAO_ContributionSoft::getSoftContribution($record['contribution_id'], TRUE);
                 if ($record['status'] == 'Completed' && count($softCredits) > 0) {
                     $form->_softCreditInfo = $softCredits;
                 }
             }
         }
     }
     if (property_exists($form, "_softCreditInfo")) {
         if (!empty($form->_softCreditInfo['soft_credit'])) {
             $showSoftCreditRow = count($form->_softCreditInfo['soft_credit']);
             $showSoftCreditRow++;
         }
     }
     for ($rowNumber = 1; $rowNumber <= $item_count; $rowNumber++) {
         $form->addEntityRef("soft_credit_contact_id[{$rowNumber}]", ts('Contact'), array('create' => TRUE));
         $form->addMoney("soft_credit_amount[{$rowNumber}]", ts('Amount'), FALSE, NULL, FALSE);
         $form->addSelect("soft_credit_type[{$rowNumber}]", array('entity' => 'contribution_soft', 'field' => 'soft_credit_type_id', 'label' => ts('Type')));
         if (!empty($form->_softCreditInfo['soft_credit'][$rowNumber]['soft_credit_id'])) {
             $form->add('hidden', "soft_credit_id[{$rowNumber}]", $form->_softCreditInfo['soft_credit'][$rowNumber]['soft_credit_id']);
         }
     }
     self::addPCPFields($form);
     $form->assign('showSoftCreditRow', $showSoftCreditRow);
     $form->assign('rowCount', $item_count);
     $form->addElement('hidden', 'sct_default_id', CRM_Core_OptionGroup::getDefaultValue("soft_credit_type"), array('id' => 'sct_default_id'));
 }
Beispiel #2
0
 /**
  * Process the form.
  */
 public function postProcess()
 {
     // get the submitted form values.
     $params = $this->controller->exportValues($this->_name);
     // we do this in case the user has hit the forward/back button
     if ($this->_id) {
         $params['id'] = $this->_id;
     } else {
         $session = CRM_Core_Session::singleton();
         $params['created_id'] = $session->get('userID');
         $params['created_date'] = date('YmdHis');
         $config = CRM_Core_Config::singleton();
         $params['currency'] = $config->defaultCurrency;
     }
     $params['is_confirm_enabled'] = CRM_Utils_Array::value('is_confirm_enabled', $params, FALSE);
     $params['is_share'] = CRM_Utils_Array::value('is_share', $params, FALSE);
     $params['is_active'] = CRM_Utils_Array::value('is_active', $params, FALSE);
     $params['is_credit_card_only'] = CRM_Utils_Array::value('is_credit_card_only', $params, FALSE);
     $params['honor_block_is_active'] = CRM_Utils_Array::value('honor_block_is_active', $params, FALSE);
     $params['is_for_organization'] = !empty($params['is_organization']) ? CRM_Utils_Array::value('is_for_organization', $params, FALSE) : 0;
     $params['start_date'] = CRM_Utils_Date::processDate($params['start_date'], $params['start_date_time'], TRUE);
     $params['end_date'] = CRM_Utils_Date::processDate($params['end_date'], $params['end_date_time'], TRUE);
     $params['goal_amount'] = CRM_Utils_Rule::cleanMoney($params['goal_amount']);
     if (!$params['honor_block_is_active']) {
         $params['honor_block_title'] = NULL;
         $params['honor_block_text'] = NULL;
     }
     $dao = CRM_Contribute_BAO_ContributionPage::create($params);
     $ufJoinParams = array('is_organization' => array('module' => 'on_behalf', 'entity_table' => 'civicrm_contribution_page', 'entity_id' => $dao->id), 'honor_block_is_active' => array('module' => 'soft_credit', 'entity_table' => 'civicrm_contribution_page', 'entity_id' => $dao->id));
     foreach ($ufJoinParams as $index => $ufJoinParam) {
         if (!empty($params[$index])) {
             // first delete all past entries
             CRM_Core_BAO_UFJoin::deleteAll($ufJoinParam);
             $ufJoinParam['uf_group_id'] = $params[$index];
             $ufJoinParam['weight'] = 1;
             $ufJoinParam['is_active'] = 1;
             if ($index == 'honor_block_is_active') {
                 $ufJoinParam['uf_group_id'] = $params['honoree_profile'];
                 $ufJoinParam['module_data'] = CRM_Contribute_BAO_ContributionPage::formatModuleData($params, FALSE, 'soft_credit');
             } else {
                 $ufJoinParam['uf_group_id'] = $params['onbehalf_profile_id'];
                 $ufJoinParam['module_data'] = CRM_Contribute_BAO_ContributionPage::formatModuleData($params, FALSE, 'on_behalf');
             }
             CRM_Core_BAO_UFJoin::create($ufJoinParam);
         } else {
             if ($index == 'honor_block_is_active') {
                 $params['honor_block_title'] = NULL;
                 $params['honor_block_text'] = NULL;
             } else {
                 $params['for_organization'] = NULL;
             }
             //On subsequent honor_block_is_active uncheck, disable(don't delete)
             //that particular honoree profile entry in UFjoin table, CRM-13981
             $ufId = CRM_Core_BAO_UFJoin::findJoinEntryId($ufJoinParam);
             if ($ufId) {
                 $ufJoinParam['uf_group_id'] = CRM_Core_BAO_UFJoin::findUFGroupId($ufJoinParam);
                 $ufJoinParam['is_active'] = 0;
                 CRM_Core_BAO_UFJoin::create($ufJoinParam);
             }
         }
     }
     $this->set('id', $dao->id);
     if ($this->_action & CRM_Core_Action::ADD) {
         $url = 'civicrm/admin/contribute/amount';
         $urlParams = "action=update&reset=1&id={$dao->id}";
         // special case for 'Save and Done' consistency.
         if ($this->controller->getButtonName('submit') == '_qf_Amount_upload_done') {
             $url = 'civicrm/admin/contribute';
             $urlParams = 'reset=1';
             CRM_Core_Session::setStatus(ts("'%1' information has been saved.", array(1 => $this->getTitle())), ts('Saved'), 'success');
         }
         CRM_Utils_System::redirect(CRM_Utils_System::url($url, $urlParams));
     }
     parent::endPostProcess();
 }
 /**
  * Load values for a contribution page.
  *
  * @param int $id
  * @param array $values
  */
 public static function setValues($id, &$values)
 {
     $modules = array('CiviContribute', 'soft_credit', 'on_behalf');
     $values['custom_pre_id'] = $values['custom_post_id'] = NULL;
     $params = array('id' => $id);
     CRM_Core_DAO::commonRetrieve('CRM_Contribute_DAO_ContributionPage', $params, $values);
     // get the profile ids
     $ufJoinParams = array('entity_table' => 'civicrm_contribution_page', 'entity_id' => $id);
     // retrieve profile id as also unserialize module_data corresponding to each $module
     foreach ($modules as $module) {
         $ufJoinParams['module'] = $module;
         $ufJoin = new CRM_Core_DAO_UFJoin();
         $ufJoin->copyValues($ufJoinParams);
         if ($module == 'CiviContribute') {
             $ufJoin->orderBy('weight asc');
             $ufJoin->find();
             while ($ufJoin->fetch()) {
                 if ($ufJoin->weight == 1) {
                     $values['custom_pre_id'] = $ufJoin->uf_group_id;
                 } else {
                     $values['custom_post_id'] = $ufJoin->uf_group_id;
                 }
             }
         } else {
             $ufJoin->find(TRUE);
             if (!$ufJoin->is_active) {
                 continue;
             }
             $params = CRM_Contribute_BAO_ContributionPage::formatModuleData($ufJoin->module_data, TRUE, $module);
             $values = array_merge($params, $values);
             if ($module == 'soft_credit') {
                 $values['honoree_profile_id'] = $ufJoin->uf_group_id;
                 $values['honor_block_is_active'] = $ufJoin->is_active;
             } else {
                 $values['onbehalf_profile_id'] = $ufJoin->uf_group_id;
             }
         }
     }
 }
Beispiel #4
0
 /**
  * Function used to build form element for soft credit block.
  *
  * @param CRM_Core_Form $form
  *
  * @return \CRM_Core_Form
  */
 public static function buildQuickForm(&$form)
 {
     if (!empty($form->_honor_block_is_active)) {
         $ufJoinDAO = new CRM_Core_DAO_UFJoin();
         $ufJoinDAO->module = 'soft_credit';
         $ufJoinDAO->entity_id = $form->_id;
         if ($ufJoinDAO->find(TRUE)) {
             $jsonData = CRM_Contribute_BAO_ContributionPage::formatModuleData($ufJoinDAO->module_data, TRUE, 'soft_credit');
             if ($jsonData) {
                 foreach (array('honor_block_title', 'honor_block_text') as $name) {
                     $form->assign($name, $jsonData[$name]);
                 }
                 $softCreditTypes = CRM_Core_OptionGroup::values("soft_credit_type", FALSE);
                 // radio button for Honor Type
                 foreach ($jsonData['soft_credit_types'] as $value) {
                     $honorTypes[$value] = $form->createElement('radio', NULL, NULL, $softCreditTypes[$value], $value);
                 }
                 $form->addGroup($honorTypes, 'soft_credit_type_id', NULL)->setAttribute('allowClear', TRUE);
             }
         }
         return $form;
     }
     // by default generate 10 blocks
     $item_count = 11;
     $showSoftCreditRow = 2;
     if ($form->getAction() & CRM_Core_Action::UPDATE) {
         $form->_softCreditInfo = CRM_Contribute_BAO_ContributionSoft::getSoftContribution($form->_id, TRUE);
     } elseif (!empty($form->_pledgeID)) {
         //Check and select most recent completed contrubtion and use it to retrieve
         //soft-credit information to use as default for current pledge payment, CRM-13981
         $pledgePayments = CRM_Pledge_BAO_PledgePayment::getPledgePayments($form->_pledgeID);
         foreach ($pledgePayments as $id => $record) {
             if ($record['contribution_id']) {
                 $softCredits = CRM_Contribute_BAO_ContributionSoft::getSoftContribution($record['contribution_id'], TRUE);
                 if ($record['status'] == 'Completed' && count($softCredits) > 0) {
                     $form->_softCreditInfo = $softCredits;
                 }
             }
         }
     }
     if (property_exists($form, "_softCreditInfo")) {
         if (!empty($form->_softCreditInfo['soft_credit'])) {
             $showSoftCreditRow = count($form->_softCreditInfo['soft_credit']);
             $showSoftCreditRow++;
         }
     }
     for ($rowNumber = 1; $rowNumber <= $item_count; $rowNumber++) {
         $form->addEntityRef("soft_credit_contact_id[{$rowNumber}]", ts('Contact'), array('create' => TRUE));
         $form->addMoney("soft_credit_amount[{$rowNumber}]", ts('Amount'), FALSE, NULL, FALSE);
         $form->addSelect("soft_credit_type[{$rowNumber}]", array('entity' => 'contribution_soft', 'field' => 'soft_credit_type_id', 'label' => ts('Type')));
         if (!empty($form->_softCreditInfo['soft_credit'][$rowNumber]['soft_credit_id'])) {
             $form->add('hidden', "soft_credit_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);
         // Fixme: Not a true entityRef field. Relies on PCP.js.tpl
         $form->add('text', 'pcp_made_through_id', ts('Credit to a Personal Campaign Page'), array('class' => 'twenty', 'placeholder' => ts('- select -')));
         // stores the label
         $form->add('hidden', 'pcp_made_through');
         $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->addElement('hidden', 'sct_default_id', CRM_Core_OptionGroup::getDefaultValue("soft_credit_type"), array('id' => 'sct_default_id'));
 }