Example #1
0
 /**
  * Build Premium Block im Contribution Pages.
  *
  * @param CRM_Core_Form $form
  * @param int $pageID
  * @param bool $formItems
  * @param int $selectedProductID
  * @param string $selectedOption
  */
 public static function buildPremiumBlock(&$form, $pageID, $formItems = FALSE, $selectedProductID = NULL, $selectedOption = NULL)
 {
     $form->add('hidden', "selectProduct", $selectedProductID, array('id' => 'selectProduct'));
     $dao = new CRM_Contribute_DAO_Premium();
     $dao->entity_table = 'civicrm_contribution_page';
     $dao->entity_id = $pageID;
     $dao->premiums_active = 1;
     CRM_Financial_BAO_FinancialType::getAvailableFinancialTypes($financialTypes, CRM_Core_Action::ADD);
     $addWhere = "financial_type_id IN (0)";
     if (!empty($financialTypes)) {
         $addWhere = "financial_type_id IN (" . implode(',', array_keys($financialTypes)) . ")";
     }
     if ($dao->find(TRUE)) {
         $premiumID = $dao->id;
         $premiumBlock = array();
         CRM_Core_DAO::storeValues($dao, $premiumBlock);
         $dao = new CRM_Contribute_DAO_PremiumsProduct();
         $dao->premiums_id = $premiumID;
         $dao->whereAdd($addWhere);
         $dao->orderBy('weight');
         $dao->find();
         $products = array();
         $radio = array();
         while ($dao->fetch()) {
             $productDAO = new CRM_Contribute_DAO_Product();
             $productDAO->id = $dao->product_id;
             $productDAO->is_active = 1;
             if ($productDAO->find(TRUE)) {
                 if ($selectedProductID != NULL) {
                     if ($selectedProductID == $productDAO->id) {
                         if ($selectedOption) {
                             $productDAO->options = ts('Selected Option') . ': ' . $selectedOption;
                         } else {
                             $productDAO->options = NULL;
                         }
                         CRM_Core_DAO::storeValues($productDAO, $products[$productDAO->id]);
                     }
                 } else {
                     CRM_Core_DAO::storeValues($productDAO, $products[$productDAO->id]);
                 }
             }
             $options = $temp = array();
             $temp = explode(',', $productDAO->options);
             foreach ($temp as $value) {
                 $options[trim($value)] = trim($value);
             }
             if ($temp[0] != '') {
                 $form->addElement('select', 'options_' . $productDAO->id, NULL, $options);
             }
         }
         if (count($products)) {
             $form->assign('showPremium', $formItems);
             $form->assign('showSelectOptions', $formItems);
             $form->assign('products', $products);
             $form->assign('premiumBlock', $premiumBlock);
         }
     }
 }