/** * Process the form. * * @param array $premiumParams * @param CRM_Contribute_BAO_Contribution $contribution */ protected function postProcessPremium($premiumParams, $contribution) { $hour = $minute = $second = 0; // assigning Premium information to receipt tpl $selectProduct = CRM_Utils_Array::value('selectProduct', $premiumParams); if ($selectProduct && $selectProduct != 'no_thanks') { $startDate = $endDate = ""; $this->assign('selectPremium', TRUE); $productDAO = new CRM_Contribute_DAO_Product(); $productDAO->id = $selectProduct; $productDAO->find(TRUE); $this->assign('product_name', $productDAO->name); $this->assign('price', $productDAO->price); $this->assign('sku', $productDAO->sku); $this->assign('option', CRM_Utils_Array::value('options_' . $premiumParams['selectProduct'], $premiumParams)); $periodType = $productDAO->period_type; if ($periodType) { $fixed_period_start_day = $productDAO->fixed_period_start_day; $duration_unit = $productDAO->duration_unit; $duration_interval = $productDAO->duration_interval; if ($periodType == 'rolling') { $startDate = date('Y-m-d'); } elseif ($periodType == 'fixed') { if ($fixed_period_start_day) { $date = explode('-', date('Y-m-d')); $month = substr($fixed_period_start_day, 0, strlen($fixed_period_start_day) - 2); $day = substr($fixed_period_start_day, -2) . "<br/>"; $year = $date[0]; $startDate = $year . '-' . $month . '-' . $day; } else { $startDate = date('Y-m-d'); } } $date = explode('-', $startDate); $year = $date[0]; $month = $date[1]; $day = $date[2]; switch ($duration_unit) { case 'year': $year = $year + $duration_interval; break; case 'month': $month = $month + $duration_interval; break; case 'day': $day = $day + $duration_interval; break; case 'week': $day = $day + $duration_interval * 7; } $endDate = date('Y-m-d H:i:s', mktime($hour, $minute, $second, $month, $day, $year)); $this->assign('start_date', $startDate); $this->assign('end_date', $endDate); } $dao = new CRM_Contribute_DAO_Premium(); $dao->entity_table = 'civicrm_contribution_page'; $dao->entity_id = $this->_id; $dao->find(TRUE); $this->assign('contact_phone', $dao->premiums_contact_phone); $this->assign('contact_email', $dao->premiums_contact_email); //create Premium record $params = array('product_id' => $premiumParams['selectProduct'], 'contribution_id' => $contribution->id, 'product_option' => CRM_Utils_Array::value('options_' . $premiumParams['selectProduct'], $premiumParams), 'quantity' => 1, 'start_date' => CRM_Utils_Date::customFormat($startDate, '%Y%m%d'), 'end_date' => CRM_Utils_Date::customFormat($endDate, '%Y%m%d')); if (!empty($premiumParams['selectProduct'])) { $daoPremiumsProduct = new CRM_Contribute_DAO_PremiumsProduct(); $daoPremiumsProduct->product_id = $premiumParams['selectProduct']; $daoPremiumsProduct->premiums_id = $dao->id; $daoPremiumsProduct->find(TRUE); $params['financial_type_id'] = $daoPremiumsProduct->financial_type_id; } //Fixed For CRM-3901 $daoContrProd = new CRM_Contribute_DAO_ContributionProduct(); $daoContrProd->contribution_id = $contribution->id; if ($daoContrProd->find(TRUE)) { $params['id'] = $daoContrProd->id; } CRM_Contribute_BAO_Contribution::addPremium($params); if ($productDAO->cost && !empty($params['financial_type_id'])) { $trxnParams = array('cost' => $productDAO->cost, 'currency' => $productDAO->currency, 'financial_type_id' => $params['financial_type_id'], 'contributionId' => $contribution->id); CRM_Core_BAO_FinancialTrxn::createPremiumTrxn($trxnParams); } } elseif ($selectProduct == 'no_thanks') { //Fixed For CRM-3901 $daoContrProd = new CRM_Contribute_DAO_ContributionProduct(); $daoContrProd->contribution_id = $contribution->id; if ($daoContrProd->find(TRUE)) { $daoContrProd->delete(); } } }
/** * Process the form. * * @return void */ public function postProcess() { // get the submitted form values. $params = $this->controller->exportValues($this->_name); $urlParams = 'civicrm/admin/contribute/premium'; if ($this->_action & CRM_Core_Action::PREVIEW) { $session = CRM_Core_Session::singleton(); $url = CRM_Utils_System::url($urlParams, 'reset=1&action=update&id=' . $this->_id); $single = $session->get('singleForm'); CRM_Utils_System::redirect($url); return; } if ($this->_action & CRM_Core_Action::DELETE) { $session = CRM_Core_Session::singleton(); $url = CRM_Utils_System::url($urlParams, 'reset=1&action=update&id=' . $this->_id); $dao = new CRM_Contribute_DAO_PremiumsProduct(); $dao->id = $this->_pid; $dao->delete(); CRM_Core_Session::setStatus(ts('Selected Premium Product has been removed from this Contribution Page.'), ts('Saved'), 'success'); CRM_Utils_System::redirect($url); } else { $session = CRM_Core_Session::singleton(); $url = CRM_Utils_System::url($urlParams, 'reset=1&action=update&id=' . $this->_id); if ($this->_pid) { $params['id'] = $this->_pid; } $dao = new CRM_Contribute_DAO_Premium(); $dao->entity_table = 'civicrm_contribution_page'; $dao->entity_id = $this->_id; $dao->find(TRUE); $premiumID = $dao->id; $params['premiums_id'] = $premiumID; $oldWeight = NULL; if ($this->_pid) { $oldWeight = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_PremiumsProduct', $this->_pid, 'weight', 'id'); } // updateOtherWeights needs to filter on premiums_id $filter = array('premiums_id' => $params['premiums_id']); $params['weight'] = CRM_Utils_Weight::updateOtherWeights('CRM_Contribute_DAO_PremiumsProduct', $oldWeight, $params['weight'], $filter); $dao = new CRM_Contribute_DAO_PremiumsProduct(); $dao->copyValues($params); $dao->save(); CRM_Utils_System::redirect($url); } }
/** * Browse function. */ public function browse() { // get all custom groups sorted by weight $premiums = array(); $pageID = CRM_Utils_Request::retrieve('id', 'Positive', $this, FALSE, 0); $dao = new CRM_Contribute_DAO_Premium(); $dao->entity_table = 'civicrm_contribution_page'; $dao->entity_id = $pageID; $dao->find(TRUE); $premiumID = $dao->id; $this->assign('products', FALSE); $this->assign('id', $pageID); if (!$premiumID) { return; } $dao = new CRM_Contribute_DAO_PremiumsProduct(); $dao->premiums_id = $premiumID; $dao->orderBy('weight'); $dao->find(); while ($dao->fetch()) { $productDAO = new CRM_Contribute_DAO_Product(); $productDAO->id = $dao->product_id; $productDAO->is_active = 1; if ($productDAO->find(TRUE)) { $premiums[$productDAO->id] = array(); $premiums[$productDAO->id]['weight'] = $dao->weight; CRM_Core_DAO::storeValues($productDAO, $premiums[$productDAO->id]); $action = array_sum(array_keys($this->links())); $premiums[$dao->product_id]['action'] = CRM_Core_Action::formLink(self::links(), $action, array('id' => $pageID, 'pid' => $dao->id), ts('more'), FALSE, 'premium.contributionpage.row', 'Premium', $dao->id); //Financial Type if (!empty($dao->financial_type_id)) { $premiums[$productDAO->id]['financial_type_id'] = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_FinancialType', $dao->financial_type_id, 'name'); } } } if (count(CRM_Contribute_PseudoConstant::products($pageID)) == 0) { $this->assign('products', FALSE); } else { $this->assign('products', TRUE); } // Add order changing widget to selector $returnURL = CRM_Utils_System::url('civicrm/admin/contribute/premium', "reset=1&action=update&id={$pageID}"); $filter = "premiums_id = {$premiumID}"; CRM_Utils_Weight::addOrder($premiums, 'CRM_Contribute_DAO_PremiumsProduct', 'id', $returnURL, $filter); $this->assign('rows', $premiums); }
/** * Process the form * * @return void * @access public */ public function postProcess() { // get the submitted form values. $params = $this->controller->exportValues($this->_name); $urlParams = 'civicrm/admin/contribute/premium'; if ($this->_action & CRM_Core_Action::PREVIEW) { $session = CRM_Core_Session::singleton(); $url = CRM_Utils_System::url($urlParams, 'reset=1&action=update&id=' . $this->_id); $single = $session->get('singleForm'); CRM_Utils_System::redirect($url); return; } if ($this->_action & CRM_Core_Action::DELETE) { $session = CRM_Core_Session::singleton(); $url = CRM_Utils_System::url($urlParams, 'reset=1&action=update&id=' . $this->_id); $dao = new CRM_Contribute_DAO_PremiumsProduct(); $dao->id = $this->_pid; $dao->delete(); CRM_Core_Session::setStatus(ts('Selected Premium Product has been removed from this Contribution Page.')); CRM_Utils_System::redirect($url); } else { $session = CRM_Core_Session::singleton(); $url = CRM_Utils_System::url($urlParams, 'reset=1&action=update&id=' . $this->_id); if ($this->_pid) { $params['id'] = $this->_pid; } $dao = new CRM_Contribute_DAO_Premium(); $dao->entity_table = 'civicrm_contribution_page'; $dao->entity_id = $this->_id; $dao->find(TRUE); $premiumID = $dao->id; $params['premiums_id'] = $premiumID; $dao = new CRM_Contribute_DAO_PremiumsProduct(); $dao->copyValues($params); $dao->save(); CRM_Utils_System::redirect($url); } }
/** * Delete premium associated w/ contribution page. * * @param int $contributionPageID */ public static function deletePremium($contributionPageID) { if (!$contributionPageID) { return; } //need to delete entries from civicrm_premiums //as well as from civicrm_premiums_product, CRM-4586 $params = array('entity_id' => $contributionPageID, 'entity_table' => 'civicrm_contribution_page'); $premium = new CRM_Contribute_DAO_Premium(); $premium->copyValues($params); $premium->find(); while ($premium->fetch()) { //lets delete from civicrm_premiums_product $premiumsProduct = new CRM_Contribute_DAO_PremiumsProduct(); $premiumsProduct->premiums_id = $premium->id; $premiumsProduct->delete(); //now delete premium $premium->delete(); } }
/** * Get all premiums. * * * @param int $pageID * @return array * array of all Premiums if any */ public static function products($pageID = NULL) { $products = array(); $dao = new CRM_Contribute_DAO_Product(); $dao->is_active = 1; $dao->orderBy('id'); $dao->find(); while ($dao->fetch()) { $products[$dao->id] = $dao->name; } if ($pageID) { $dao = new CRM_Contribute_DAO_Premium(); $dao->entity_table = 'civicrm_contribution_page'; $dao->entity_id = $pageID; $dao->find(TRUE); $premiumID = $dao->id; $productID = array(); $dao = new CRM_Contribute_DAO_PremiumsProduct(); $dao->premiums_id = $premiumID; $dao->find(); while ($dao->fetch()) { $productID[$dao->product_id] = $dao->product_id; } $tempProduct = array(); foreach ($products as $key => $value) { if (!array_key_exists($key, $productID)) { $tempProduct[$key] = $value; } } return $tempProduct; } return $products; }
/** * Process the form * * @return void * @access public */ 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 $dao = new CRM_Contribute_DAO_Premium(); $dao->entity_table = 'civicrm_contribution_page'; $dao->entity_id = $this->_id; $dao->find(true); $premiumID = $dao->id; if ($premiumID) { $params['id'] = $premiumID; } $params['premiums_active'] = CRM_Utils_Array::value('premiums_active', $params, false); $params['premiums_display_min_contribution'] = CRM_Utils_Array::value('premiums_display_min_contribution', $params, false); $params['entity_table'] = 'civicrm_contribution_page'; $params['entity_id'] = $this->_id; $dao = new CRM_Contribute_DAO_Premium(); $dao->copyValues($params); $dao->save(); }
/** * * @return void * @access public * @static */ function browse() { // get all custom groups sorted by weight $premiums = array(); require_once 'CRM/Contribute/DAO/Product.php'; $pageID = CRM_Utils_Request::retrieve('id', 'Positive', $this, false, 0); $dao = new CRM_Contribute_DAO_Premium(); $dao->entity_table = 'civicrm_contribution_page'; $dao->entity_id = $pageID; $dao->find(true); $premiumID = $dao->id; $this->assign('products', false); if (!$premiumID) { return; } require_once 'CRM/Contribute/DAO/PremiumsProduct.php'; $dao = new CRM_Contribute_DAO_PremiumsProduct(); $dao->premiums_id = $premiumID; $dao->orderBy('weight'); $dao->find(); while ($dao->fetch()) { $productDAO = new CRM_Contribute_DAO_Product(); $productDAO->id = $dao->product_id; $productDAO->is_active = 1; if ($productDAO->find(true)) { $premiums[$productDAO->id] = array(); $premiums[$productDAO->id]['weight'] = $dao->weight; CRM_Core_DAO::storeValues($productDAO, $premiums[$productDAO->id]); $action = array_sum(array_keys($this->links())); $premiums[$dao->product_id]['action'] = CRM_Core_Action::formLink(self::links(), $action, array('id' => $pageID, 'pid' => $dao->id)); } } require_once 'CRM/Contribute/PseudoConstant.php'; if (count(CRM_Contribute_PseudoConstant::products($pageID)) == 0) { $this->assign('products', false); } else { $this->assign('products', true); } // Add order changing widget to selector $returnURL = CRM_Utils_System::url('civicrm/admin/contribute/premium', "reset=1&action=update&id={$pageID}"); $filter = "premiums_id = {$premiumID}"; require_once 'CRM/Utils/Weight.php'; CRM_Utils_Weight::addOrder($premiums, 'CRM_Contribute_DAO_PremiumsProduct', 'id', $returnURL, $filter); $this->assign('rows', $premiums); }