/**
  * Build price options.
  *
  * @param CRM_Event_BAO_Event $event
  *
  * @return array
  */
 public function build_price_options($event)
 {
     $price_fields_for_event = array();
     $base_field_name = "event_{$event->id}_amount";
     $price_set_id = CRM_Price_BAO_PriceSet::getFor('civicrm_event', $event->id);
     //CRM-14492 display admin fields only if user is admin
     $adminFieldVisible = FALSE;
     if (CRM_Core_Permission::check('administer CiviCRM')) {
         $adminFieldVisible = TRUE;
     }
     if ($price_set_id) {
         $price_sets = CRM_Price_BAO_PriceSet::getSetDetail($price_set_id, TRUE, TRUE);
         $price_set = $price_sets[$price_set_id];
         $index = -1;
         foreach ($price_set['fields'] as $field) {
             $index++;
             if (CRM_Utils_Array::value('visibility', $field) == 'public' || CRM_Utils_Array::value('visibility', $field) == 'admin' && $adminFieldVisible == TRUE) {
                 $field_name = "event_{$event->id}_price_{$field['id']}";
                 CRM_Price_BAO_PriceField::addQuickFormElement($this, $field_name, $field['id'], FALSE);
                 $price_fields_for_event[] = $field_name;
             }
         }
     }
     return $price_fields_for_event;
 }
 /**
  * takes an associative array and creates a contribution page object
  *
  * @param array $params (reference ) an assoc array of name/value pairs
  *
  * @return object CRM_Contribute_DAO_ContributionPage object
  * @access public
  * @static
  */
 public static function &create(&$params)
 {
     $financialTypeId = NULL;
     if (!empty($params['id']) && !CRM_Price_BAO_PriceSet::getFor('civicrm_contribution_page', $params['id'], NULL, 1)) {
         $financialTypeId = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionPage', $params['id'], 'financial_type_id');
     }
     $dao = new CRM_Contribute_DAO_ContributionPage();
     $dao->copyValues($params);
     $dao->save();
     if ($financialTypeId && !empty($params['financial_type_id']) && $financialTypeId != $params['financial_type_id']) {
         CRM_Price_BAO_PriceFieldValue::updateFinancialType($params['id'], 'civicrm_contribution_page', $params['financial_type_id']);
     }
     return $dao;
 }
 /**
  * Takes an associative array and creates a contribution page object.
  *
  * @param array $params
  *   (reference ) an assoc array of name/value pairs.
  *
  * @return CRM_Contribute_DAO_ContributionPage
  */
 public static function &create(&$params)
 {
     $financialTypeId = NULL;
     if (!empty($params['id']) && !CRM_Price_BAO_PriceSet::getFor('civicrm_contribution_page', $params['id'], NULL, 1)) {
         $financialTypeId = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionPage', $params['id'], 'financial_type_id');
     }
     $hook = empty($params['id']) ? 'create' : 'edit';
     CRM_Utils_Hook::pre($hook, 'ContributionPage', CRM_Utils_Array::value('id', $params), $params);
     $dao = new CRM_Contribute_DAO_ContributionPage();
     $dao->copyValues($params);
     $dao->save();
     if ($financialTypeId && !empty($params['financial_type_id']) && $financialTypeId != $params['financial_type_id']) {
         CRM_Price_BAO_PriceFieldValue::updateFinancialType($params['id'], 'civicrm_contribution_page', $params['financial_type_id']);
     }
     CRM_Utils_Hook::post($hook, 'ContributionPage', $dao->id, $dao);
     return $dao;
 }
Esempio n. 4
0
 function build_price_options($event)
 {
     $price_fields_for_event = array();
     $base_field_name = "event_{$event->id}_amount";
     $price_set_id = CRM_Price_BAO_PriceSet::getFor('civicrm_event', $event->id);
     if ($price_set_id) {
         $price_sets = CRM_Price_BAO_PriceSet::getSetDetail($price_set_id, TRUE, TRUE);
         $price_set = $price_sets[$price_set_id];
         $index = -1;
         foreach ($price_set['fields'] as $field) {
             $index++;
             $field_name = "event_{$event->id}_price_{$field['id']}";
             CRM_Price_BAO_PriceField::addQuickFormElement($this, $field_name, $field['id'], FALSE);
             $price_fields_for_event[] = $field_name;
         }
     }
     return $price_fields_for_event;
 }
Esempio n. 5
0
 /**
  * Delete the indirect records associated with this contribution first.
  *
  * @param int $id
  *
  * @return mixed|null
  *   $results no of deleted Contribution on success, false otherwise
  */
 public static function deleteContribution($id)
 {
     CRM_Utils_Hook::pre('delete', 'Contribution', $id, CRM_Core_DAO::$_nullArray);
     $transaction = new CRM_Core_Transaction();
     $results = NULL;
     //delete activity record
     $params = array('source_record_id' => $id, 'activity_type_id' => 6);
     CRM_Activity_BAO_Activity::deleteActivity($params);
     //delete billing address if exists for this contribution.
     self::deleteAddress($id);
     //update pledge and pledge payment, CRM-3961
     CRM_Pledge_BAO_PledgePayment::resetPledgePayment($id);
     // remove entry from civicrm_price_set_entity, CRM-5095
     if (CRM_Price_BAO_PriceSet::getFor('civicrm_contribution', $id)) {
         CRM_Price_BAO_PriceSet::removeFrom('civicrm_contribution', $id);
     }
     // cleanup line items.
     $participantId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_ParticipantPayment', $id, 'participant_id', 'contribution_id');
     // delete any related entity_financial_trxn, financial_trxn and financial_item records.
     CRM_Core_BAO_FinancialTrxn::deleteFinancialTrxn($id);
     if ($participantId) {
         CRM_Price_BAO_LineItem::deleteLineItems($participantId, 'civicrm_participant');
     } else {
         CRM_Price_BAO_LineItem::deleteLineItems($id, 'civicrm_contribution');
     }
     //delete note.
     $note = CRM_Core_BAO_Note::getNote($id, 'civicrm_contribution');
     $noteId = key($note);
     if ($noteId) {
         CRM_Core_BAO_Note::del($noteId, FALSE);
     }
     $dao = new CRM_Contribute_DAO_Contribution();
     $dao->id = $id;
     $results = $dao->delete();
     $transaction->commit();
     CRM_Utils_Hook::post('delete', 'Contribution', $dao->id, $dao);
     // delete the recently created Contribution
     $contributionRecent = array('id' => $id, 'type' => 'Contribution');
     CRM_Utils_Recent::del($contributionRecent);
     return $results;
 }
 /**
  * Process the form.
  *
  * @return void
  */
 public function postProcess()
 {
     // get the submitted form values.
     $params = $this->controller->exportValues($this->_name);
     $deletePriceSet = 0;
     if ($params['membership_type']) {
         // we do this in case the user has hit the forward/back button
         $dao = new CRM_Member_DAO_MembershipBlock();
         $dao->entity_table = 'civicrm_contribution_page';
         $dao->entity_id = $this->_id;
         $dao->find(TRUE);
         $membershipID = $dao->id;
         if ($membershipID) {
             $params['id'] = $membershipID;
         }
         $membershipTypes = array();
         if (is_array($params['membership_type'])) {
             foreach ($params['membership_type'] as $k => $v) {
                 if ($v) {
                     $membershipTypes[$k] = CRM_Utils_Array::value("auto_renew_{$k}", $params);
                 }
             }
         }
         if ($this->_id && !empty($params['member_price_set_id'])) {
             CRM_Core_DAO::setFieldValue('CRM_Contribute_DAO_ContributionPage', $this->_id, 'amount_block_is_active', 0);
         }
         // check for price set.
         $priceSetID = CRM_Utils_Array::value('member_price_set_id', $params);
         if (!empty($params['member_is_active']) && is_array($membershipTypes) && !$priceSetID) {
             $usedPriceSetId = CRM_Price_BAO_PriceSet::getFor('civicrm_contribution_page', $this->_id, 2);
             if (empty($params['mem_price_field_id']) && !$usedPriceSetId) {
                 $pageTitle = strtolower(CRM_Utils_String::munge($this->_values['title'], '_', 245));
                 $setParams['title'] = $this->_values['title'];
                 if (!CRM_Core_DAO::getFieldValue('CRM_Price_BAO_PriceSet', $pageTitle, 'id', 'name')) {
                     $setParams['name'] = $pageTitle;
                 } elseif (!CRM_Core_DAO::getFieldValue('CRM_Price_BAO_PriceSet', $pageTitle . '_' . $this->_id, 'id', 'name')) {
                     $setParams['name'] = $pageTitle . '_' . $this->_id;
                 } else {
                     $timeSec = explode(".", microtime(TRUE));
                     $setParams['name'] = $pageTitle . '_' . date('is', $timeSec[0]) . $timeSec[1];
                 }
                 $setParams['is_quick_config'] = 1;
                 $setParams['extends'] = CRM_Core_Component::getComponentID('CiviMember');
                 $setParams['financial_type_id'] = CRM_Utils_Array::value('financial_type_id', $this->_values);
                 $priceSet = CRM_Price_BAO_PriceSet::create($setParams);
                 $priceSetID = $priceSet->id;
                 $fieldParams['price_set_id'] = $priceSet->id;
             } elseif ($usedPriceSetId) {
                 $setParams['extends'] = CRM_Core_Component::getComponentID('CiviMember');
                 $setParams['financial_type_id'] = CRM_Utils_Array::value('financial_type_id', $this->_values);
                 $setParams['id'] = $usedPriceSetId;
                 $priceSet = CRM_Price_BAO_PriceSet::create($setParams);
                 $priceSetID = $priceSet->id;
                 $fieldParams['price_set_id'] = $priceSet->id;
             } else {
                 $fieldParams['id'] = CRM_Utils_Array::value('mem_price_field_id', $params);
                 $priceSetID = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceField', CRM_Utils_Array::value('mem_price_field_id', $params), 'price_set_id');
             }
             $editedFieldParams = array('price_set_id' => $priceSetID, 'name' => 'membership_amount');
             $editedResults = array();
             CRM_Price_BAO_PriceField::retrieve($editedFieldParams, $editedResults);
             if (empty($editedResults['id'])) {
                 $fieldParams['name'] = strtolower(CRM_Utils_String::munge('Membership Amount', '_', 245));
                 if (empty($params['mem_price_field_id'])) {
                     CRM_Utils_Weight::updateOtherWeights('CRM_Price_DAO_PriceField', 0, 1, array('price_set_id' => $priceSetID));
                 }
                 $fieldParams['weight'] = 1;
             } else {
                 $fieldParams['id'] = CRM_Utils_Array::value('id', $editedResults);
             }
             $fieldParams['label'] = !empty($params['membership_type_label']) ? $params['membership_type_label'] : ts('Membership');
             $fieldParams['is_active'] = 1;
             $fieldParams['html_type'] = 'Radio';
             $fieldParams['is_required'] = !empty($params['is_required']) ? 1 : 0;
             $fieldParams['is_display_amounts'] = !empty($params['display_min_fee']) ? 1 : 0;
             $rowCount = 1;
             $options = array();
             if (!empty($fieldParams['id'])) {
                 CRM_Core_PseudoConstant::populate($options, 'CRM_Price_DAO_PriceFieldValue', TRUE, 'membership_type_id', NULL, " price_field_id = {$fieldParams['id']} ");
             }
             foreach ($membershipTypes as $memType => $memAutoRenew) {
                 if ($priceFieldID = CRM_Utils_Array::key($memType, $options)) {
                     $fieldParams['option_id'][$rowCount] = $priceFieldID;
                     unset($options[$priceFieldID]);
                 }
                 $membetype = CRM_Member_BAO_MembershipType::getMembershipTypeDetails($memType);
                 $fieldParams['option_label'][$rowCount] = CRM_Utils_Array::value('name', $membetype);
                 $fieldParams['option_amount'][$rowCount] = CRM_Utils_Array::value('minimum_fee', $membetype, 0);
                 $fieldParams['option_weight'][$rowCount] = CRM_Utils_Array::value('weight', $membetype);
                 $fieldParams['option_description'][$rowCount] = CRM_Utils_Array::value('description', $membetype);
                 $fieldParams['default_option'] = CRM_Utils_Array::value('membership_type_default', $params);
                 $fieldParams['option_financial_type_id'][$rowCount] = CRM_Utils_Array::value('financial_type_id', $membetype);
                 $fieldParams['membership_type_id'][$rowCount] = $memType;
                 // [$rowCount] = $membetype[''];
                 $rowCount++;
             }
             foreach ($options as $priceFieldID => $memType) {
                 CRM_Price_BAO_PriceFieldValue::setIsActive($priceFieldID, '0');
             }
             $priceField = CRM_Price_BAO_PriceField::create($fieldParams);
         } elseif (!$priceSetID) {
             $deletePriceSet = 1;
         }
         $params['is_required'] = CRM_Utils_Array::value('is_required', $params, FALSE);
         $params['is_active'] = CRM_Utils_Array::value('member_is_active', $params, FALSE);
         if ($priceSetID) {
             $params['membership_types'] = 'null';
             $params['membership_type_default'] = CRM_Utils_Array::value('membership_type_default', $params, 'null');
             $params['membership_types'] = serialize($membershipTypes);
             $params['display_min_fee'] = CRM_Utils_Array::value('display_min_fee', $params, FALSE);
             $params['is_separate_payment'] = CRM_Utils_Array::value('is_separate_payment', $params, FALSE);
         }
         $params['entity_table'] = 'civicrm_contribution_page';
         $params['entity_id'] = $this->_id;
         $dao = new CRM_Member_DAO_MembershipBlock();
         $dao->copyValues($params);
         $dao->save();
         if ($priceSetID && $params['is_active']) {
             CRM_Price_BAO_PriceSet::addTo('civicrm_contribution_page', $this->_id, $priceSetID);
         }
         if ($deletePriceSet || !CRM_Utils_Array::value('member_is_active', $params, FALSE)) {
             if ($this->_memPriceSetId) {
                 $pFIDs = array();
                 $conditionParams = array('price_set_id' => $this->_memPriceSetId, 'html_type' => 'radio', 'name' => 'contribution_amount');
                 CRM_Core_DAO::commonRetrieve('CRM_Price_DAO_PriceField', $conditionParams, $pFIDs);
                 if (empty($pFIDs['id'])) {
                     CRM_Price_BAO_PriceSet::removeFrom('civicrm_contribution_page', $this->_id);
                     CRM_Price_BAO_PriceSet::setIsQuickConfig($this->_memPriceSetId, '0');
                 } else {
                     CRM_Price_BAO_PriceField::setIsActive($params['mem_price_field_id'], '0');
                 }
             }
         }
     }
     parent::endPostProcess();
 }
Esempio n. 7
0
 /**
  * Helper function for static submit function.
  *
  * Set relevant params - help us to build up an array that we can pass in.
  *
  * @param int $id
  * @param array $params
  *
  * @return array
  * @throws CiviCRM_API3_Exception
  */
 public static function getFormParams($id, array $params)
 {
     if (!isset($params['is_pay_later'])) {
         if (!empty($params['payment_processor_id'])) {
             $params['is_pay_later'] = 0;
         } else {
             $params['is_pay_later'] = civicrm_api3('contribution_page', 'getvalue', array('id' => $id, 'return' => 'is_pay_later'));
         }
     }
     if (empty($params['price_set_id'])) {
         $params['price_set_id'] = CRM_Price_BAO_PriceSet::getFor('civicrm_contribution_page', $params['id']);
     }
     return $params;
 }
Esempio n. 8
0
 /**
  * Set default values for the form. Note that in edit/view mode
  * the default values are retrieved from the database
  *
  *
  * @return array
  *   defaults
  */
 public function setDefaultValues()
 {
     //some child classes calling setdefaults directly w/o preprocess.
     $this->_values = $this->get('values');
     if (!is_array($this->_values)) {
         $this->_values = array();
         if (isset($this->_id) && $this->_id) {
             $params = array('id' => $this->_id);
             CRM_Core_DAO::commonRetrieve('CRM_Contribute_DAO_ContributionPage', $params, $this->_values);
         }
         $this->set('values', $this->_values);
     }
     $defaults = $this->_values;
     $config = CRM_Core_Config::singleton();
     if (isset($this->_id)) {
         //set defaults for pledgeBlock values.
         $pledgeBlockParams = array('entity_id' => $this->_id, 'entity_table' => ts('civicrm_contribution_page'));
         $pledgeBlockDefaults = array();
         CRM_Pledge_BAO_PledgeBlock::retrieve($pledgeBlockParams, $pledgeBlockDefaults);
         if ($this->_pledgeBlockID = CRM_Utils_Array::value('id', $pledgeBlockDefaults)) {
             $defaults['is_pledge_active'] = TRUE;
         }
         $pledgeBlock = array('is_pledge_interval', 'max_reminders', 'initial_reminder_day', 'additional_reminder_day');
         foreach ($pledgeBlock as $key) {
             $defaults[$key] = CRM_Utils_Array::value($key, $pledgeBlockDefaults);
         }
         if (!empty($pledgeBlockDefaults['pledge_frequency_unit'])) {
             $defaults['pledge_frequency_unit'] = array_fill_keys(explode(CRM_Core_DAO::VALUE_SEPARATOR, $pledgeBlockDefaults['pledge_frequency_unit']), '1');
         }
         // fix the display of the monetary value, CRM-4038
         if (isset($defaults['goal_amount'])) {
             $defaults['goal_amount'] = CRM_Utils_Money::format($defaults['goal_amount'], NULL, '%a');
         }
         // get price set of type contributions
         //this is the value for stored in db if price set extends contribution
         $usedFor = 2;
         $this->_priceSetID = CRM_Price_BAO_PriceSet::getFor('civicrm_contribution_page', $this->_id, $usedFor, 1);
         if ($this->_priceSetID) {
             $defaults['price_set_id'] = $this->_priceSetID;
         }
         if (!empty($defaults['end_date'])) {
             list($defaults['end_date'], $defaults['end_date_time']) = CRM_Utils_Date::setDateDefaults($defaults['end_date']);
         }
         if (!empty($defaults['start_date'])) {
             list($defaults['start_date'], $defaults['start_date_time']) = CRM_Utils_Date::setDateDefaults($defaults['start_date']);
         }
     } else {
         $defaults['is_active'] = 1;
         // set current date as start date
         list($defaults['start_date'], $defaults['start_date_time']) = CRM_Utils_Date::setDateDefaults();
     }
     if (!isset($defaults['for_organization'])) {
         $defaults['for_organization'] = ts('I am contributing on behalf of an organization.');
     }
     if (!empty($defaults['recur_frequency_unit'])) {
         $defaults['recur_frequency_unit'] = array_fill_keys(explode(CRM_Core_DAO::VALUE_SEPARATOR, $defaults['recur_frequency_unit']), '1');
     } else {
         # CRM 10860
         $defaults['recur_frequency_unit'] = array('month' => 1);
     }
     if (!empty($defaults['is_for_organization'])) {
         $defaults['is_organization'] = 1;
     } else {
         $defaults['is_for_organization'] = 1;
     }
     // confirm page starts out enabled
     if (!isset($defaults['is_confirm_enabled'])) {
         $defaults['is_confirm_enabled'] = 1;
     }
     return $defaults;
 }
Esempio n. 9
0
 /**
  * This is sometimes called in a loop (during event search)
  * hence we cache the values to prevent repeated calls to the db
  */
 static function usesPriceSet($id)
 {
     static $usesPriceSet = array();
     if (!array_key_exists($id, $usesPriceSet)) {
         $usesPriceSet[$id] = CRM_Price_BAO_PriceSet::getFor('civicrm_event', $id);
     }
     return $usesPriceSet[$id];
 }
Esempio n. 10
0
 /**
  * Change is_quick_config priceSet to complex.
  *
  */
 public static function setIsQuickConfig()
 {
     $id = $context = NULL;
     if (!empty($_REQUEST['id'])) {
         $id = CRM_Utils_Type::escape($_REQUEST['id'], 'Integer');
     }
     if (!empty($_REQUEST['context'])) {
         $context = CRM_Utils_Type::escape($_REQUEST['context'], 'String');
     }
     // return false if $id is null and
     // $context is not civicrm_event or civicrm_contribution_page
     if (!$id || !in_array($context, array('civicrm_event', 'civicrm_contribution_page'))) {
         return FALSE;
     }
     $priceSetId = CRM_Price_BAO_PriceSet::getFor($context, $id, NULL);
     if ($priceSetId) {
         $result = CRM_Price_BAO_PriceSet::setIsQuickConfig($priceSetId, 0);
         if ($context == 'civicrm_event') {
             $sql = "UPDATE\n          civicrm_price_set cps\n          INNER JOIN civicrm_discount cd ON cd.price_set_id = cps.id\n          SET cps.is_quick_config = 0\n          WHERE cd.entity_id = (%1) AND cd.entity_table = 'civicrm_event' ";
             $params = array(1 => array($id, 'Integer'));
             CRM_Core_DAO::executeQuery($sql, $params);
             CRM_Core_BAO_Discount::del($id, $context);
         }
     }
     if (!$result) {
         $priceSetId = NULL;
     }
     CRM_Utils_JSON::output($priceSetId);
 }
Esempio n. 11
0
 /**
  * Process the form.
  */
 public function postProcess()
 {
     // get the submitted form values.
     $params = $this->controller->exportValues($this->_name);
     //update 'is_billing_required'
     if (empty($params['is_pay_later'])) {
         $params['is_billing_required'] = 0;
     }
     if (array_key_exists('payment_processor', $params)) {
         if (array_key_exists(CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_PaymentProcessor', 'AuthNet', 'id', 'payment_processor_type_id'), CRM_Utils_Array::value('payment_processor', $params))) {
             CRM_Core_Session::setStatus(ts(' Please note that the Authorize.net payment processor only allows recurring contributions and auto-renew memberships with payment intervals from 7-365 days or 1-12 months (i.e. not greater than 1 year).'), '', 'alert');
         }
     }
     // check for price set.
     $priceSetID = CRM_Utils_Array::value('price_set_id', $params);
     // get required fields.
     $fields = array('id' => $this->_id, 'is_recur' => FALSE, 'min_amount' => "null", 'max_amount' => "null", 'is_monetary' => FALSE, 'is_pay_later' => FALSE, 'is_billing_required' => FALSE, 'is_recur_interval' => FALSE, 'is_recur_installments' => FALSE, 'recur_frequency_unit' => "null", 'default_amount_id' => "null", 'is_allow_other_amount' => FALSE, 'amount_block_is_active' => FALSE);
     $resetFields = array();
     if ($priceSetID) {
         $resetFields = array('min_amount', 'max_amount', 'is_allow_other_amount');
     }
     if (empty($params['is_recur'])) {
         $resetFields = array_merge($resetFields, array('is_recur_interval', 'recur_frequency_unit'));
     }
     foreach ($fields as $field => $defaultVal) {
         $val = CRM_Utils_Array::value($field, $params, $defaultVal);
         if (in_array($field, $resetFields)) {
             $val = $defaultVal;
         }
         if (in_array($field, array('min_amount', 'max_amount'))) {
             $val = CRM_Utils_Rule::cleanMoney($val);
         }
         $params[$field] = $val;
     }
     if ($params['is_recur']) {
         $params['recur_frequency_unit'] = implode(CRM_Core_DAO::VALUE_SEPARATOR, array_keys($params['recur_frequency_unit']));
         $params['is_recur_interval'] = CRM_Utils_Array::value('is_recur_interval', $params, FALSE);
         $params['is_recur_installments'] = CRM_Utils_Array::value('is_recur_installments', $params, FALSE);
     }
     if (array_key_exists('payment_processor', $params) && !CRM_Utils_System::isNull($params['payment_processor'])) {
         $params['payment_processor'] = implode(CRM_Core_DAO::VALUE_SEPARATOR, array_keys($params['payment_processor']));
     } else {
         $params['payment_processor'] = 'null';
     }
     $contributionPage = CRM_Contribute_BAO_ContributionPage::create($params);
     $contributionPageID = $contributionPage->id;
     // prepare for data cleanup.
     $deleteAmountBlk = $deletePledgeBlk = $deletePriceSet = FALSE;
     if ($this->_priceSetID) {
         $deletePriceSet = TRUE;
     }
     if ($this->_pledgeBlockID) {
         $deletePledgeBlk = TRUE;
     }
     if (!empty($this->_amountBlock)) {
         $deleteAmountBlk = TRUE;
     }
     if ($contributionPageID) {
         if (!empty($params['amount_block_is_active'])) {
             // handle price set.
             if ($priceSetID) {
                 // add/update price set.
                 $deletePriceSet = FALSE;
                 if (!empty($params['price_field_id']) || !empty($params['price_field_other'])) {
                     $deleteAmountBlk = TRUE;
                 }
                 CRM_Price_BAO_PriceSet::addTo('civicrm_contribution_page', $contributionPageID, $priceSetID);
             } else {
                 $deletePriceSet = FALSE;
                 // process contribution amount block
                 $deleteAmountBlk = FALSE;
                 $labels = CRM_Utils_Array::value('label', $params);
                 $values = CRM_Utils_Array::value('value', $params);
                 $default = CRM_Utils_Array::value('default', $params);
                 $options = array();
                 for ($i = 1; $i < self::NUM_OPTION; $i++) {
                     if (isset($values[$i]) && strlen(trim($values[$i])) > 0) {
                         $options[] = array('label' => trim($labels[$i]), 'value' => CRM_Utils_Rule::cleanMoney(trim($values[$i])), 'weight' => $i, 'is_active' => 1, 'is_default' => $default == $i);
                     }
                 }
                 /* || !empty($params['price_field_value']) || CRM_Utils_Array::value( 'price_field_other', $params )*/
                 if (!empty($options) || !empty($params['is_allow_other_amount'])) {
                     $fieldParams['is_quick_config'] = 1;
                     $noContriAmount = NULL;
                     $usedPriceSetId = CRM_Price_BAO_PriceSet::getFor('civicrm_contribution_page', $this->_id, 3);
                     if (!(!empty($params['price_field_id']) || !empty($params['price_field_other'])) && !$usedPriceSetId) {
                         $pageTitle = strtolower(CRM_Utils_String::munge($this->_values['title'], '_', 245));
                         $setParams['title'] = $this->_values['title'];
                         if (!CRM_Core_DAO::getFieldValue('CRM_Price_BAO_PriceSet', $pageTitle, 'id', 'name')) {
                             $setParams['name'] = $pageTitle;
                         } elseif (!CRM_Core_DAO::getFieldValue('CRM_Price_BAO_PriceSet', $pageTitle . '_' . $this->_id, 'id', 'name')) {
                             $setParams['name'] = $pageTitle . '_' . $this->_id;
                         } else {
                             $timeSec = explode(".", microtime(TRUE));
                             $setParams['name'] = $pageTitle . '_' . date('is', $timeSec[0]) . $timeSec[1];
                         }
                         $setParams['is_quick_config'] = 1;
                         $setParams['financial_type_id'] = CRM_Utils_Array::value('financial_type_id', $this->_values);
                         $setParams['extends'] = CRM_Core_Component::getComponentID('CiviContribute');
                         $priceSet = CRM_Price_BAO_PriceSet::create($setParams);
                         $priceSetId = $priceSet->id;
                     } elseif ($usedPriceSetId && empty($params['price_field_id'])) {
                         $priceSetId = $usedPriceSetId;
                     } else {
                         if ($priceFieldId = CRM_Utils_Array::value('price_field_id', $params)) {
                             foreach ($params['price_field_value'] as $arrayID => $fieldValueID) {
                                 if (empty($params['label'][$arrayID]) && empty($params['value'][$arrayID]) && !empty($fieldValueID)) {
                                     CRM_Price_BAO_PriceFieldValue::setIsActive($fieldValueID, '0');
                                     unset($params['price_field_value'][$arrayID]);
                                 }
                             }
                             if (implode('', $params['price_field_value'])) {
                                 $fieldParams['id'] = CRM_Utils_Array::value('price_field_id', $params);
                                 $fieldParams['option_id'] = $params['price_field_value'];
                             } else {
                                 $noContriAmount = 0;
                                 CRM_Price_BAO_PriceField::setIsActive($priceFieldId, '0');
                             }
                         } else {
                             $priceFieldId = CRM_Utils_Array::value('price_field_other', $params);
                         }
                         $priceSetId = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceField', $priceFieldId, 'price_set_id');
                     }
                     CRM_Price_BAO_PriceSet::addTo('civicrm_contribution_page', $this->_id, $priceSetId);
                     if (!empty($options)) {
                         $editedFieldParams = array('price_set_id' => $priceSetId, 'name' => 'contribution_amount');
                         $editedResults = array();
                         $noContriAmount = 1;
                         CRM_Price_BAO_PriceField::retrieve($editedFieldParams, $editedResults);
                         if (empty($editedResults['id'])) {
                             $fieldParams['name'] = strtolower(CRM_Utils_String::munge("Contribution Amount", '_', 245));
                         } else {
                             $fieldParams['id'] = CRM_Utils_Array::value('id', $editedResults);
                         }
                         $fieldParams['price_set_id'] = $priceSetId;
                         $fieldParams['is_active'] = 1;
                         $fieldParams['weight'] = 2;
                         if (!empty($params['is_allow_other_amount'])) {
                             $fieldParams['is_required'] = 0;
                         } else {
                             $fieldParams['is_required'] = 1;
                         }
                         $fieldParams['label'] = $params['amount_label'];
                         $fieldParams['html_type'] = 'Radio';
                         $fieldParams['option_label'] = $params['label'];
                         $fieldParams['option_amount'] = $params['value'];
                         $fieldParams['financial_type_id'] = CRM_Utils_Array::value('financial_type_id', $this->_values);
                         foreach ($options as $value) {
                             $fieldParams['option_weight'][$value['weight']] = $value['weight'];
                         }
                         $fieldParams['default_option'] = $params['default'];
                         $priceField = CRM_Price_BAO_PriceField::create($fieldParams);
                     }
                     if (!empty($params['is_allow_other_amount']) && empty($params['price_field_other'])) {
                         $editedFieldParams = array('price_set_id' => $priceSetId, 'name' => 'other_amount');
                         $editedResults = array();
                         CRM_Price_BAO_PriceField::retrieve($editedFieldParams, $editedResults);
                         if (!($priceFieldID = CRM_Utils_Array::value('id', $editedResults))) {
                             $fieldParams = array('name' => 'other_amount', 'label' => ts('Other Amount'), 'price_set_id' => $priceSetId, 'html_type' => 'Text', 'financial_type_id' => CRM_Utils_Array::value('financial_type_id', $this->_values), 'is_display_amounts' => 0, 'weight' => 3);
                             $fieldParams['option_weight'][1] = 1;
                             $fieldParams['option_amount'][1] = 1;
                             if (!$noContriAmount) {
                                 $fieldParams['is_required'] = 1;
                                 $fieldParams['option_label'][1] = $fieldParams['label'] = $params['amount_label'];
                             } else {
                                 $fieldParams['is_required'] = 0;
                                 $fieldParams['option_label'][1] = $fieldParams['label'] = ts('Other Amount');
                             }
                             $priceField = CRM_Price_BAO_PriceField::create($fieldParams);
                         } else {
                             if (empty($editedResults['is_active'])) {
                                 $fieldParams = $editedResults;
                                 if (!$noContriAmount) {
                                     $priceFieldValueID = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceFieldValue', $priceFieldID, 'id', 'price_field_id');
                                     CRM_Core_DAO::setFieldValue('CRM_Price_DAO_PriceFieldValue', $priceFieldValueID, 'label', $params['amount_label']);
                                     $fieldParams = array('is_required' => 1, 'label' => $params['amount_label'], 'id' => $priceFieldID);
                                 }
                                 $fieldParams['is_active'] = 1;
                                 $priceField = CRM_Price_BAO_PriceField::add($fieldParams);
                             }
                         }
                     } elseif (empty($params['is_allow_other_amount']) && !empty($params['price_field_other'])) {
                         CRM_Price_BAO_PriceField::setIsActive($params['price_field_other'], '0');
                     } elseif ($priceFieldID = CRM_Utils_Array::value('price_field_other', $params)) {
                         $priceFieldValueID = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceFieldValue', $priceFieldID, 'id', 'price_field_id');
                         if (!$noContriAmount) {
                             $fieldParams = array('is_required' => 1, 'label' => $params['amount_label'], 'id' => $priceFieldID);
                             CRM_Price_BAO_PriceField::add($fieldParams);
                             CRM_Core_DAO::setFieldValue('CRM_Price_DAO_PriceFieldValue', $priceFieldValueID, 'label', $params['amount_label']);
                         } else {
                             CRM_Core_DAO::setFieldValue('CRM_Price_DAO_PriceField', $priceFieldID, 'is_required', 0);
                             CRM_Core_DAO::setFieldValue('CRM_Price_DAO_PriceFieldValue', $priceFieldValueID, 'label', ts('Other Amount'));
                         }
                     }
                 }
                 if (!empty($params['is_pledge_active'])) {
                     $deletePledgeBlk = FALSE;
                     $pledgeBlockParams = array('entity_id' => $contributionPageID, 'entity_table' => ts('civicrm_contribution_page'));
                     if ($this->_pledgeBlockID) {
                         $pledgeBlockParams['id'] = $this->_pledgeBlockID;
                     }
                     $pledgeBlock = array('pledge_frequency_unit', 'max_reminders', 'initial_reminder_day', 'additional_reminder_day');
                     foreach ($pledgeBlock as $key) {
                         $pledgeBlockParams[$key] = CRM_Utils_Array::value($key, $params);
                     }
                     $pledgeBlockParams['is_pledge_interval'] = CRM_Utils_Array::value('is_pledge_interval', $params, FALSE);
                     // create pledge block.
                     CRM_Pledge_BAO_PledgeBlock::create($pledgeBlockParams);
                 }
             }
         } else {
             if (!empty($params['price_field_id']) || !empty($params['price_field_other'])) {
                 $usedPriceSetId = CRM_Price_BAO_PriceSet::getFor('civicrm_contribution_page', $this->_id, 3);
                 if ($usedPriceSetId) {
                     if (!empty($params['price_field_id'])) {
                         CRM_Price_BAO_PriceField::setIsActive($params['price_field_id'], '0');
                     }
                     if (!empty($params['price_field_other'])) {
                         CRM_Price_BAO_PriceField::setIsActive($params['price_field_other'], '0');
                     }
                 } else {
                     $deleteAmountBlk = TRUE;
                     $deletePriceSet = TRUE;
                 }
             }
         }
         // delete pledge block.
         if ($deletePledgeBlk) {
             CRM_Pledge_BAO_PledgeBlock::deletePledgeBlock($this->_pledgeBlockID);
         }
         // delete previous price set.
         if ($deletePriceSet) {
             CRM_Price_BAO_PriceSet::removeFrom('civicrm_contribution_page', $contributionPageID);
         }
         if ($deleteAmountBlk) {
             $priceField = !empty($params['price_field_id']) ? $params['price_field_id'] : CRM_Utils_Array::value('price_field_other', $params);
             if ($priceField) {
                 $priceSetID = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceField', $priceField, 'price_set_id');
                 CRM_Price_BAO_PriceSet::setIsQuickConfig($priceSetID, 0);
             }
         }
     }
     parent::endPostProcess();
 }
Esempio n. 12
0
 /**
  * Get the amount for the undiscounted version of the field.
  *
  * Note this function is part of the refactoring process rather than the best approach.
  *
  * @param int $eventID
  * @param int $discountedPriceFieldOptionID
  * @param string $feeLevel (deprecated)
  *
  * @return null|string
  */
 public static function getUnDiscountedAmountForEventPriceSetFieldValue($eventID, $discountedPriceFieldOptionID, $feeLevel)
 {
     $priceSetId = CRM_Price_BAO_PriceSet::getFor('civicrm_event', $eventID, NULL);
     $params = array(1 => array($priceSetId, 'Integer'));
     if ($discountedPriceFieldOptionID) {
         $query = "SELECT cpfv.amount FROM `civicrm_price_field_value` cpfv\nLEFT JOIN civicrm_price_field cpf ON cpfv.price_field_id = cpf.id\nWHERE cpf.price_set_id = %1 AND cpfv.label = (SELECT label from civicrm_price_field_value WHERE id = %2)";
         $params[2] = array($discountedPriceFieldOptionID, 'Integer');
     } else {
         $feeLevel = current($feeLevel);
         $query = "SELECT cpfv.amount FROM `civicrm_price_field_value` cpfv\nLEFT JOIN civicrm_price_field cpf ON cpfv.price_field_id = cpf.id\nWHERE cpf.price_set_id = %1 AND cpfv.label LIKE %2";
         $params[2] = array($feeLevel, 'String');
     }
     return CRM_Core_DAO::singleValueQuery($query, $params);
 }
Esempio n. 13
0
/**
 * Get Event record.
 *
 * @param array $params
 *
 * @return array
 *   Array of all found event property values.
 */
function civicrm_api3_event_get($params)
{
    //legacy support for $params['return.sort']
    if (!empty($params['return.sort'])) {
        $params['options']['sort'] = $params['return.sort'];
        unset($params['return.sort']);
    }
    //legacy support for $params['return.offset']
    if (!empty($params['return.offset'])) {
        $params['options']['offset'] = $params['return.offset'];
        unset($params['return.offset']);
    }
    //legacy support for $params['return.max_results']
    if (!empty($params['return.max_results'])) {
        $params['options']['limit'] = $params['return.max_results'];
        unset($params['return.max_results']);
    }
    $sql = CRM_Utils_SQL_Select::fragment();
    if (!empty($params['isCurrent'])) {
        $sql->where('(start_date >= CURDATE() || end_date >= CURDATE())');
    }
    $events = _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params, FALSE, 'Event', $sql, TRUE);
    $options = _civicrm_api3_get_options_from_params($params);
    if ($options['is_count']) {
        return civicrm_api3_create_success($events, $params, 'Event', 'get');
    }
    foreach ($events as $id => $event) {
        if (!empty($params['return.is_full'])) {
            _civicrm_api3_event_getisfull($events, $id);
        }
        _civicrm_api3_event_get_legacy_support_42($events, $id);
        if (!empty($options['return'])) {
            $events[$id]['price_set_id'] = CRM_Price_BAO_PriceSet::getFor('civicrm_event', $id);
        }
    }
    return civicrm_api3_create_success($events, $params, 'Event', 'get');
}
Esempio n. 14
0
 /**
  * Copy priceSet when event/contibution page is copied
  *
  * @param string $baoName
  *   BAO name.
  * @param int $id
  *   Old event/contribution page id.
  * @param int $newId
  *   Newly created event/contribution page id.
  */
 public static function copyPriceSet($baoName, $id, $newId)
 {
     $priceSetId = CRM_Price_BAO_PriceSet::getFor($baoName, $id);
     if ($priceSetId) {
         $isQuickConfig = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $priceSetId, 'is_quick_config');
         if ($isQuickConfig) {
             $copyPriceSet = CRM_Price_BAO_PriceSet::copy($priceSetId);
             CRM_Price_BAO_PriceSet::addTo($baoName, $newId, $copyPriceSet->id);
         } else {
             $copyPriceSet =& CRM_Core_DAO::copyGeneric('CRM_Price_DAO_PriceSetEntity', array('entity_id' => $id, 'entity_table' => $baoName), array('entity_id' => $newId));
         }
         // copy event discount
         if ($baoName == 'civicrm_event') {
             $discount = CRM_Core_BAO_Discount::getOptionGroup($id, 'civicrm_event');
             foreach ($discount as $discountId => $setId) {
                 $copyPriceSet =& CRM_Price_BAO_PriceSet::copy($setId);
                 CRM_Core_DAO::copyGeneric('CRM_Core_DAO_Discount', array('id' => $discountId), array('entity_id' => $newId, 'price_set_id' => $copyPriceSet->id));
             }
         }
     }
 }
Esempio n. 15
0
 /**
  * Process line item for event.
  *
  * @param bool $event_in_cart
  * @param string $class
  */
 public function process_event_line_item(&$event_in_cart, $class = NULL)
 {
     $cost = 0;
     $price_set_id = CRM_Price_BAO_PriceSet::getFor("civicrm_event", $event_in_cart->event_id);
     $amount_level = NULL;
     if ($price_set_id) {
         $event_price_values = array();
         foreach ($this->_price_values as $key => $value) {
             if (preg_match("/event_{$event_in_cart->event_id}_(price.*)/", $key, $matches)) {
                 $event_price_values[$matches[1]] = $value;
             }
         }
         $price_sets = CRM_Price_BAO_PriceSet::getSetDetail($price_set_id, TRUE);
         $price_set = $price_sets[$price_set_id];
         $price_set_amount = array();
         CRM_Price_BAO_PriceSet::processAmount($price_set['fields'], $event_price_values, $price_set_amount);
         $discountCode = $this->_price_values['discountcode'];
         if (!empty($discountCode)) {
             $ret = $this->apply_discount($discountCode, $price_set_amount, $cost, $event_in_cart->event_id);
             if ($ret == FALSE) {
                 $cost = $event_price_values['amount'];
             }
         } else {
             $cost = $event_price_values['amount'];
         }
         // @todo - stop setting amount level in this function & call the CRM_Price_BAO_PriceSet::getAmountLevel
         // function to get correct amount level consistently. Remove setting of the amount level in
         // CRM_Price_BAO_PriceSet::processAmount. Extend the unit tests in CRM_Price_BAO_PriceSetTest
         // to cover all variants.
         $amount_level = $event_price_values['amount_level'];
         $price_details[$price_set_id] = $price_set_amount;
     }
     // iterate over each participant in event
     foreach ($event_in_cart->participants as &$participant) {
         $participant->cost = $cost;
         $participant->fee_level = $amount_level;
         $participant->price_details = $price_details;
     }
     $this->add_line_item($event_in_cart, $class);
 }
Esempio n. 16
0
 /**
  * Run the page.
  *
  * This method is called after the page is created. It checks for the
  * type of action and executes that action.
  * Finally it calls the parent's run method.
  *
  * @return void
  */
 public function run()
 {
     //get the event id.
     $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this, TRUE);
     $config = CRM_Core_Config::singleton();
     // ensure that the user has permission to see this page
     if (!CRM_Core_Permission::event(CRM_Core_Permission::VIEW, $this->_id, 'view event info')) {
         CRM_Utils_System::setUFMessage(ts('You do not have permission to view this event'));
         return CRM_Utils_System::permissionDenied();
     }
     $action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE);
     $context = CRM_Utils_Request::retrieve('context', 'String', $this, FALSE, 'register');
     $this->assign('context', $context);
     // Sometimes we want to suppress the Event Full msg
     $noFullMsg = CRM_Utils_Request::retrieve('noFullMsg', 'String', $this, FALSE, 'false');
     // set breadcrumb to append to 2nd layer pages
     $breadCrumbPath = CRM_Utils_System::url('civicrm/event/info', "id={$this->_id}&reset=1");
     //retrieve event information
     $params = array('id' => $this->_id);
     CRM_Event_BAO_Event::retrieve($params, $values['event']);
     if (!$values['event']['is_active']) {
         // form is inactive, die a fatal death
         CRM_Utils_System::setUFMessage(ts('The event you requested is currently unavailable (contact the site administrator for assistance).'));
         return CRM_Utils_System::permissionDenied();
     }
     if (!empty($values['event']['is_template'])) {
         // form is an Event Template
         CRM_Core_Error::fatal(ts('The page you requested is currently unavailable.'));
     }
     // Add Event Type to $values in case folks want to display it
     $values['event']['event_type'] = CRM_Utils_Array::value($values['event']['event_type_id'], CRM_Event_PseudoConstant::eventType());
     $this->assign('isShowLocation', CRM_Utils_Array::value('is_show_location', $values['event']));
     // show event fees.
     if ($this->_id && !empty($values['event']['is_monetary'])) {
         //CRM-6907
         $config = CRM_Core_Config::singleton();
         $config->defaultCurrency = CRM_Utils_Array::value('currency', $values['event'], $config->defaultCurrency);
         //CRM-10434
         $discountId = CRM_Core_BAO_Discount::findSet($this->_id, 'civicrm_event');
         if ($discountId) {
             $priceSetId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Discount', $discountId, 'price_set_id');
         } else {
             $priceSetId = CRM_Price_BAO_PriceSet::getFor('civicrm_event', $this->_id);
         }
         // get price set options, - CRM-5209
         if ($priceSetId) {
             $setDetails = CRM_Price_BAO_PriceSet::getSetDetail($priceSetId, TRUE, TRUE);
             $priceSetFields = $setDetails[$priceSetId]['fields'];
             if (is_array($priceSetFields)) {
                 $fieldCnt = 1;
                 $visibility = CRM_Core_PseudoConstant::visibility('name');
                 // CRM-14492 Admin price fields should show up on event registration if user has 'administer CiviCRM' permissions
                 $adminFieldVisible = FALSE;
                 if (CRM_Core_Permission::check('administer CiviCRM')) {
                     $adminFieldVisible = TRUE;
                 }
                 foreach ($priceSetFields as $fid => $fieldValues) {
                     if (!is_array($fieldValues['options']) || empty($fieldValues['options']) || CRM_Utils_Array::value('visibility_id', $fieldValues) != array_search('public', $visibility) && $adminFieldVisible == FALSE) {
                         continue;
                     }
                     if (count($fieldValues['options']) > 1) {
                         $values['feeBlock']['value'][$fieldCnt] = '';
                         $values['feeBlock']['label'][$fieldCnt] = $fieldValues['label'];
                         $values['feeBlock']['lClass'][$fieldCnt] = 'price_set_option_group-label';
                         $values['feeBlock']['isDisplayAmount'][$fieldCnt] = CRM_Utils_Array::value('is_display_amounts', $fieldValues);
                         $fieldCnt++;
                         $labelClass = 'price_set_option-label';
                     } else {
                         $labelClass = 'price_set_field-label';
                     }
                     // show tax rate with amount
                     $invoiceSettings = Civi::settings()->get('contribution_invoice_settings');
                     $taxTerm = CRM_Utils_Array::value('tax_term', $invoiceSettings);
                     $displayOpt = CRM_Utils_Array::value('tax_display_settings', $invoiceSettings);
                     $invoicing = CRM_Utils_Array::value('invoicing', $invoiceSettings);
                     foreach ($fieldValues['options'] as $optionId => $optionVal) {
                         $values['feeBlock']['isDisplayAmount'][$fieldCnt] = CRM_Utils_Array::value('is_display_amounts', $fieldValues);
                         if ($invoicing && isset($optionVal['tax_amount'])) {
                             $values['feeBlock']['value'][$fieldCnt] = CRM_Price_BAO_PriceField::getTaxLabel($optionVal, 'amount', $displayOpt, $taxTerm);
                             $values['feeBlock']['tax_amount'][$fieldCnt] = $optionVal['tax_amount'];
                         } else {
                             $values['feeBlock']['value'][$fieldCnt] = $optionVal['amount'];
                         }
                         $values['feeBlock']['label'][$fieldCnt] = $optionVal['label'];
                         $values['feeBlock']['lClass'][$fieldCnt] = $labelClass;
                         $fieldCnt++;
                     }
                 }
             }
             // Tell tpl we have price set fee data and whether it's a quick_config price set
             $this->assign('isPriceSet', 1);
             $this->assign('isQuickConfig', $setDetails[$priceSetId]['is_quick_config']);
         }
     }
     $params = array('entity_id' => $this->_id, 'entity_table' => 'civicrm_event');
     $values['location'] = CRM_Core_BAO_Location::getValues($params, TRUE);
     // fix phone type labels
     if (!empty($values['location']['phone'])) {
         $phoneTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Phone', 'phone_type_id');
         foreach ($values['location']['phone'] as &$val) {
             if (!empty($val['phone_type_id'])) {
                 $val['phone_type_display'] = $phoneTypes[$val['phone_type_id']];
             }
         }
     }
     //retrieve custom field information
     $groupTree = CRM_Core_BAO_CustomGroup::getTree('Event', $this, $this->_id, 0, $values['event']['event_type_id']);
     CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree, FALSE, NULL, NULL, NULL, $this->_id);
     $this->assign('action', CRM_Core_Action::VIEW);
     //To show the event location on maps directly on event info page
     $locations = CRM_Event_BAO_Event::getMapInfo($this->_id);
     if (!empty($locations) && !empty($values['event']['is_map'])) {
         $this->assign('locations', $locations);
         $this->assign('mapProvider', $config->mapProvider);
         $this->assign('mapKey', $config->mapAPIKey);
         $sumLat = $sumLng = 0;
         $maxLat = $maxLng = -400;
         $minLat = $minLng = 400;
         foreach ($locations as $location) {
             $sumLat += $location['lat'];
             $sumLng += $location['lng'];
             if ($location['lat'] > $maxLat) {
                 $maxLat = $location['lat'];
             }
             if ($location['lat'] < $minLat) {
                 $minLat = $location['lat'];
             }
             if ($location['lng'] > $maxLng) {
                 $maxLng = $location['lng'];
             }
             if ($location['lng'] < $minLng) {
                 $minLng = $location['lng'];
             }
         }
         $center = array('lat' => (double) $sumLat / count($locations), 'lng' => (double) $sumLng / count($locations));
         $span = array('lat' => (double) ($maxLat - $minLat), 'lng' => (double) ($maxLng - $minLng));
         $this->assign_by_ref('center', $center);
         $this->assign_by_ref('span', $span);
         if ($action == CRM_Core_Action::PREVIEW) {
             $mapURL = CRM_Utils_System::url('civicrm/contact/map/event', "eid={$this->_id}&reset=1&action=preview", TRUE, NULL, TRUE, TRUE);
         } else {
             $mapURL = CRM_Utils_System::url('civicrm/contact/map/event', "eid={$this->_id}&reset=1", TRUE, NULL, TRUE, TRUE);
         }
         $this->assign('skipLocationType', TRUE);
         $this->assign('mapURL', $mapURL);
     }
     if (CRM_Core_Permission::check('view event participants') && CRM_Core_Permission::check('view all contacts')) {
         $statusTypes = CRM_Event_PseudoConstant::participantStatus(NULL, 'is_counted = 1', 'label');
         $statusTypesPending = CRM_Event_PseudoConstant::participantStatus(NULL, 'is_counted = 0', 'label');
         $findParticipants['statusCounted'] = implode(', ', array_values($statusTypes));
         $findParticipants['statusNotCounted'] = implode(', ', array_values($statusTypesPending));
         $this->assign('findParticipants', $findParticipants);
     }
     $participantListingID = CRM_Utils_Array::value('participant_listing_id', $values['event']);
     if ($participantListingID) {
         $participantListingURL = CRM_Utils_System::url('civicrm/event/participant', "reset=1&id={$this->_id}", TRUE, NULL, TRUE, TRUE);
         $this->assign('participantListingURL', $participantListingURL);
     }
     $hasWaitingList = CRM_Utils_Array::value('has_waitlist', $values['event']);
     $eventFullMessage = CRM_Event_BAO_Participant::eventFull($this->_id, FALSE, $hasWaitingList);
     $allowRegistration = FALSE;
     if (!empty($values['event']['is_online_registration'])) {
         if (CRM_Event_BAO_Event::validRegistrationRequest($values['event'], $this->_id)) {
             // we always generate urls for the front end in joomla
             $action_query = $action === CRM_Core_Action::PREVIEW ? "&action={$action}" : '';
             $url = CRM_Utils_System::url('civicrm/event/register', "id={$this->_id}&reset=1{$action_query}", TRUE, NULL, TRUE, TRUE);
             if (!$eventFullMessage || $hasWaitingList) {
                 $registerText = ts('Register Now');
                 if (!empty($values['event']['registration_link_text'])) {
                     $registerText = $values['event']['registration_link_text'];
                 }
                 // check if we're in shopping cart mode for events
                 $enable_cart = Civi::settings()->get('enable_cart');
                 if ($enable_cart) {
                     $link = CRM_Event_Cart_BAO_EventInCart::get_registration_link($this->_id);
                     $registerText = $link['label'];
                     $url = CRM_Utils_System::url($link['path'], $link['query'] . $action_query, TRUE, NULL, TRUE, TRUE);
                 }
                 //Fixed for CRM-4855
                 $allowRegistration = CRM_Event_BAO_Event::showHideRegistrationLink($values);
                 $this->assign('registerText', $registerText);
                 $this->assign('registerURL', $url);
                 $this->assign('eventCartEnabled', $enable_cart);
             }
         } elseif (CRM_Core_Permission::check('register for events')) {
             $this->assign('registerClosed', TRUE);
         }
     }
     $this->assign('allowRegistration', $allowRegistration);
     $session = CRM_Core_Session::singleton();
     $params = array('contact_id' => $session->get('userID'), 'event_id' => CRM_Utils_Array::value('id', $values['event']), 'role_id' => CRM_Utils_Array::value('default_role_id', $values['event']));
     if ($eventFullMessage && $noFullMsg == 'false' || CRM_Event_BAO_Event::checkRegistration($params)) {
         $statusMessage = $eventFullMessage;
         if (CRM_Event_BAO_Event::checkRegistration($params)) {
             if ($noFullMsg == 'false') {
                 if ($values['event']['allow_same_participant_emails']) {
                     $statusMessage = ts('It looks like you are already registered for this event.  You may proceed if you want to create an additional registration.');
                 } else {
                     $registerUrl = CRM_Utils_System::url('civicrm/event/register', "reset=1&id={$values['event']['id']}&cid=0");
                     $statusMessage = ts("It looks like you are already registered for this event. If you want to change your registration, or you feel that you've gotten this message in error, please contact the site administrator.") . ' ' . ts('You can also <a href="%1">register another participant</a>.', array(1 => $registerUrl));
                 }
             }
         } elseif ($hasWaitingList) {
             $statusMessage = CRM_Utils_Array::value('waitlist_text', $values['event']);
             if (!$statusMessage) {
                 $statusMessage = ts('Event is currently full, but you can register and be a part of waiting list.');
             }
         }
         CRM_Core_Session::setStatus($statusMessage);
     }
     // we do not want to display recently viewed items, so turn off
     $this->assign('displayRecent', FALSE);
     // set page title = event title
     CRM_Utils_System::setTitle($values['event']['title']);
     $this->assign('event', $values['event']);
     if (isset($values['feeBlock'])) {
         $this->assign('feeBlock', $values['feeBlock']);
     }
     $this->assign('location', $values['location']);
     if (CRM_Core_Permission::check('access CiviEvent')) {
         $enableCart = Civi::settings()->get('enable_cart');
         $this->assign('manageEventLinks', CRM_Event_Page_ManageEvent::tabs($enableCart));
     }
     return parent::run();
 }
Esempio n. 17
0
 /**
  * @param $event_in_cart
  * @param null $class
  */
 public function process_event_line_item(&$event_in_cart, $class = NULL)
 {
     $cost = 0;
     $price_set_id = CRM_Price_BAO_PriceSet::getFor("civicrm_event", $event_in_cart->event_id);
     $amount_level = NULL;
     if ($price_set_id) {
         $event_price_values = array();
         foreach ($this->_price_values as $key => $value) {
             if (preg_match("/event_{$event_in_cart->event_id}_(price.*)/", $key, $matches)) {
                 $event_price_values[$matches[1]] = $value;
             }
         }
         $price_sets = CRM_Price_BAO_PriceSet::getSetDetail($price_set_id, TRUE);
         $price_set = $price_sets[$price_set_id];
         $price_set_amount = array();
         CRM_Price_BAO_PriceSet::processAmount($price_set['fields'], $event_price_values, $price_set_amount);
         $cost = $event_price_values['amount'];
         $amount_level = $event_price_values['amount_level'];
         $price_details[$price_set_id] = $price_set_amount;
     }
     // iterate over each participant in event
     foreach ($event_in_cart->participants as &$participant) {
         $participant->cost = $cost;
         $participant->fee_level = $amount_level;
         $participant->price_details = $price_details;
     }
     $this->add_line_item($event_in_cart, $class);
 }
 public function setDefaultValues()
 {
     $params = array('id' => $this->_participantId);
     CRM_Event_BAO_Participant::getValues($params, $defaults, $ids);
     $priceSetId = CRM_Price_BAO_PriceSet::getFor('civicrm_event', $this->_eventId);
     $priceSetValues = CRM_Event_Form_EventFees::setDefaultPriceSet($this->_participantId, $this->_eventId, FALSE);
     if (!empty($priceSetValues)) {
         $defaults[$this->_participantId] = array_merge($defaults[$this->_participantId], $priceSetValues);
     }
     $this->assign('totalAmount', CRM_Utils_Array::value('fee_amount', $defaults[$this->_participantId]));
     if ($this->_action == CRM_Core_Action::UPDATE) {
         $fee_level = $defaults[$this->_participantId]['fee_level'];
         CRM_Event_BAO_Participant::fixEventLevel($fee_level);
         $this->assign('fee_level', $fee_level);
         $this->assign('fee_amount', CRM_Utils_Array::value('fee_amount', $defaults[$this->_participantId]));
     }
     $defaults = $defaults[$this->_participantId];
     return $defaults;
 }
 /**
  * create trxn entry if an event has discount.
  *
  * @param int $eventID
  *   Event id.
  * @param array $contributionParams
  *   Contribution params.
  *
  * @param $feeLevel
  *
  */
 public static function createDiscountTrxn($eventID, $contributionParams, $feeLevel)
 {
     // CRM-11124
     $checkDiscount = CRM_Core_BAO_Discount::findSet($eventID, 'civicrm_event');
     if (!empty($checkDiscount)) {
         $feeLevel = current($feeLevel);
         $priceSetId = CRM_Price_BAO_PriceSet::getFor('civicrm_event', $eventID, NULL);
         $query = "SELECT cpfv.amount FROM `civicrm_price_field_value` cpfv\nLEFT JOIN civicrm_price_field cpf ON cpfv.price_field_id = cpf.id\nWHERE cpf.price_set_id = %1 AND cpfv.label LIKE %2";
         $params = array(1 => array($priceSetId, 'Integer'), 2 => array($feeLevel, 'String'));
         $mainAmount = CRM_Core_DAO::singleValueQuery($query, $params);
         $relationTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Discounts Account is' "));
         $contributionParams['trxnParams']['from_financial_account_id'] = CRM_Contribute_PseudoConstant::financialAccountType($contributionParams['contribution']->financial_type_id, $relationTypeId);
         if (!empty($contributionParams['trxnParams']['from_financial_account_id'])) {
             $contributionParams['trxnParams']['total_amount'] = $mainAmount - $contributionParams['total_amount'];
             $contributionParams['trxnParams']['payment_processor_id'] = NULL;
             $contributionParams['trxnParams']['payment_instrument_id'] = NULL;
             $contributionParams['trxnParams']['check_number'] = NULL;
             $contributionParams['trxnParams']['trxn_id'] = NULL;
             $contributionParams['trxnParams']['net_amount'] = NULL;
             $contributionParams['trxnParams']['fee_amount'] = NULL;
             CRM_Core_BAO_FinancialTrxn::create($contributionParams['trxnParams']);
         }
     }
 }
function simpledonate_civicrm_pageRun(&$page)
{
    $pageName = $page->getVar('_name');
    if ($pageName == 'Civi\\Angular\\Page\\Main' && $page->urlPath[1] == 'simple') {
        //Get all contribution page detils and session details to be used in js
        $settingVal = simpledonate_getSimpleDonateSetting();
        $session = CRM_Core_Session::singleton();
        $contactID = $session->get('userID');
        if ($settingVal['donatePageID']) {
            $extends = CRM_Core_Component::getComponentID('CiviContribute');
            $priceSetID = CRM_Price_BAO_PriceSet::getFor('civicrm_contribution_page', $settingVal['donatePageID'], $extends);
            $priceField = civicrm_api3('PriceField', 'get', array("price_set_id" => $priceSetID));
            //Check for is_quick_config
            $isQuickConfig = civicrm_api3('PriceSet', 'getvalue', array('id' => $priceSetID, 'return' => "is_quick_config"));
            //Check for Other amount
            $otherAmount = FALSE;
            foreach ($priceField['values'] as $key => $value) {
                if ($value['name'] == 'other_amount') {
                    $otherAmount = TRUE;
                } else {
                    $priceFieldVal = civicrm_api3('PriceFieldValue', 'get', array('return' => "amount, title, name, is_default", "price_field_id" => $value['id']));
                    $priceList = $priceFieldVal['values'];
                    $htmlPriceList[$value['html_type']] = $priceFieldVal['values'];
                }
            }
            //Get donation page details
            $donateConfig = $donatePage = civicrm_api3('ContributionPage', 'getsingle', array('id' => $settingVal['donatePageID']));
            CRM_Utils_System::setTitle($donateConfig['title']);
            // Set the page title
            $currencySymbol = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_Currency', $donatePage['currency'], 'symbol', 'name');
            $test = !empty($_GET['test']) ? 'test' : 'live';
            // Check for test or live donation
            //Get payment processor details
            if (is_array($donatePage['payment_processor'])) {
                $paymentProcessors = CRM_Financial_BAO_PaymentProcessor::getPayments($donatePage['payment_processor'], $test);
            } else {
                $paymentProcessor = CRM_Financial_BAO_PaymentProcessor::getPayment($donatePage['payment_processor'], $test);
                $paymentProcessors[$paymentProcessor['id']] = $paymentProcessor;
                $paymentProcessors[$paymentProcessor['id']]['hide'] = $donateConfig['is_pay_later'] ? FALSE : TRUE;
            }
            //set Country and State value
            $config = CRM_Core_Config::singleton();
            $defaultContactCountry = $config->defaultContactCountry;
            $stateProvince = array_flip(CRM_Core_PseudoConstant::stateProvinceForCountry($defaultContactCountry));
            $countryList = CRM_Core_PseudoConstant::country();
            $stateList = array();
            foreach ($countryList as $key => $val) {
                $stateList[$key] = CRM_Core_PseudoConstant::stateProvinceForCountry($key);
            }
            CRM_Core_Resources::singleton()->addSetting(array('simpledonate' => array('sessionContact' => $contactID, 'priceSetID' => $priceSetID, 'ziptasticEnable' => $settingVal['ziptasticEnable'], 'countryList' => CRM_Core_PseudoConstant::country(), 'stateList' => $stateList, 'country' => $defaultContactCountry, 'allStates' => $stateProvince, 'currency' => $currencySymbol, 'config' => $donateConfig, 'paymentProcessor' => $paymentProcessors, 'priceList' => $priceList, 'otherAmount' => $otherAmount, 'isTest' => $test == 'test' ? 1 : 0, 'htmlPriceList' => $htmlPriceList, 'isQuickConfig' => $isQuickConfig)));
            //Include bootstrap and custom css files to affect this angular page only
            CRM_Core_Resources::singleton()->addStyleFile('com.webaccessglobal.simpledonate', 'css/bootstrap.min.css', 103, 'page-header');
            CRM_Core_Resources::singleton()->addStyleFile('com.webaccessglobal.simpledonate', 'css/simpledonate.css', 100, 'page-body');
        }
        if ($contactID) {
            $id = array('id' => $contactID);
            $result = civicrm_api3('Contact', 'getSingle', $id);
            CRM_Core_Resources::singleton()->addSetting(array('simpledonateVal' => $result));
        }
    }
}
Esempio n. 21
0
    /**
     * This function sets the default values for price set.
     *
     *
     * @param int $participantID
     * @param int $eventID
     * @param bool $includeQtyZero
     *
     * @return void
     */
    public static function setDefaultPriceSet($participantID, $eventID = NULL, $includeQtyZero = TRUE)
    {
        $defaults = array();
        if (!$eventID && $participantID) {
            $eventID = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Participant', $participantID, 'event_id');
        }
        if (!$participantID || !$eventID) {
            return $defaults;
        }
        // get price set ID.
        $priceSetID = CRM_Price_BAO_PriceSet::getFor('civicrm_event', $eventID);
        if (!$priceSetID) {
            return $defaults;
        }
        // use line items for setdefault price set fields, CRM-4090
        $lineItems[$participantID] = CRM_Price_BAO_LineItem::getLineItems($participantID, 'participant', NULL, $includeQtyZero);
        if (is_array($lineItems[$participantID]) && !CRM_Utils_System::isNull($lineItems[$participantID])) {
            $priceFields = $htmlTypes = $optionValues = array();
            foreach ($lineItems[$participantID] as $lineId => $items) {
                $priceFieldId = CRM_Utils_Array::value('price_field_id', $items);
                $priceOptionId = CRM_Utils_Array::value('price_field_value_id', $items);
                if ($priceFieldId && $priceOptionId) {
                    $priceFields[$priceFieldId][] = $priceOptionId;
                }
            }
            if (empty($priceFields)) {
                return $defaults;
            }
            // get all price set field html types.
            $sql = '
SELECT  id, html_type
  FROM  civicrm_price_field
 WHERE  id IN (' . implode(',', array_keys($priceFields)) . ')';
            $fieldDAO = CRM_Core_DAO::executeQuery($sql);
            while ($fieldDAO->fetch()) {
                $htmlTypes[$fieldDAO->id] = $fieldDAO->html_type;
            }
            foreach ($lineItems[$participantID] as $lineId => $items) {
                $fieldId = $items['price_field_id'];
                $htmlType = CRM_Utils_Array::value($fieldId, $htmlTypes);
                if (!$htmlType) {
                    continue;
                }
                if ($htmlType == 'Text') {
                    $defaults["price_{$fieldId}"] = $items['qty'];
                } else {
                    $fieldOptValues = CRM_Utils_Array::value($fieldId, $priceFields);
                    if (!is_array($fieldOptValues)) {
                        continue;
                    }
                    foreach ($fieldOptValues as $optionId) {
                        if ($htmlType == 'CheckBox') {
                            $defaults["price_{$fieldId}"][$optionId] = TRUE;
                        } else {
                            $defaults["price_{$fieldId}"] = $optionId;
                            break;
                        }
                    }
                }
            }
        }
        return $defaults;
    }
 public function setDefaultValues()
 {
     $params = array('id' => $this->_participantId);
     CRM_Event_BAO_Participant::getValues($params, $defaults, $ids);
     $priceSetId = CRM_Price_BAO_PriceSet::getFor('civicrm_event', $this->_eventId);
     $priceSetValues = CRM_Event_Form_EventFees::setDefaultPriceSet($this->_participantId, $this->_eventId, FALSE);
     $priceFieldId = array_keys($this->_values['fee']);
     if (!empty($priceSetValues)) {
         $defaults[$this->_participantId] = array_merge($defaults[$this->_participantId], $priceSetValues);
     } else {
         foreach ($priceFieldId as $key => $value) {
             if (!empty($value) && ($this->_values['fee'][$value]['html_type'] == 'Radio' || $this->_values['fee'][$value]['html_type'] == 'Select') && !$this->_values['fee'][$value]['is_required']) {
                 $fee_keys = array_keys($this->_values['fee']);
                 $defaults[$this->_participantId]['price_' . $fee_keys[$key]] = 0;
             }
         }
     }
     $this->assign('totalAmount', CRM_Utils_Array::value('fee_amount', $defaults[$this->_participantId]));
     if ($this->_action == CRM_Core_Action::UPDATE) {
         $fee_level = $defaults[$this->_participantId]['fee_level'];
         CRM_Event_BAO_Participant::fixEventLevel($fee_level);
         $this->assign('fee_level', $fee_level);
         $this->assign('fee_amount', CRM_Utils_Array::value('fee_amount', $defaults[$this->_participantId]));
     }
     $defaults = $defaults[$this->_participantId];
     return $defaults;
 }
Esempio n. 23
0
 /**
  * Set default values for the form.
  *
  * For edit/view mode the default values are retrieved from the database.
  */
 public function setDefaultValues()
 {
     $parentDefaults = parent::setDefaultValues();
     $eventId = $this->_id;
     $params = array();
     $defaults = array();
     if (isset($eventId)) {
         $params = array('id' => $eventId);
     }
     CRM_Event_BAO_Event::retrieve($params, $defaults);
     if (isset($eventId)) {
         $price_set_id = CRM_Price_BAO_PriceSet::getFor('civicrm_event', $eventId, NULL, 1);
         if ($price_set_id) {
             $defaults['price_set_id'] = $price_set_id;
         } else {
             $priceSetId = CRM_Price_BAO_PriceSet::getFor('civicrm_event', $eventId, NULL);
             if ($priceSetId) {
                 if ($isQuick = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $priceSetId, 'is_quick_config')) {
                     $this->assign('isQuick', $isQuick);
                     $priceField = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceField', $priceSetId, 'id', 'price_set_id');
                     $options = array();
                     $priceFieldOptions = CRM_Price_BAO_PriceFieldValue::getValues($priceField, $options, 'weight', TRUE);
                     $defaults['price_field_id'] = $priceField;
                     $countRow = 0;
                     foreach ($options as $optionId => $optionValue) {
                         $countRow++;
                         $defaults['value'][$countRow] = CRM_Utils_Money::format($optionValue['amount'], NULL, '%a');
                         $defaults['label'][$countRow] = $optionValue['label'];
                         $defaults['name'][$countRow] = $optionValue['name'];
                         $defaults['weight'][$countRow] = $optionValue['weight'];
                         $defaults['price_field_value'][$countRow] = $optionValue['id'];
                         if ($optionValue['is_default']) {
                             $defaults['default'] = $countRow;
                         }
                     }
                 }
             }
         }
     }
     //check if discounted
     $discountedEvent = CRM_Core_BAO_Discount::getOptionGroup($this->_id, 'civicrm_event');
     if (!empty($discountedEvent)) {
         $defaults['is_discount'] = $i = 1;
         $totalLables = $maxSize = $defaultDiscounts = array();
         foreach ($discountedEvent as $optionGroupId) {
             $defaults['discount_price_set'][] = $optionGroupId;
             $name = $defaults["discount_name[{$i}]"] = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $optionGroupId, 'title');
             list($defaults["discount_start_date[{$i}]"]) = CRM_Utils_Date::setDateDefaults(CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Discount', $optionGroupId, 'start_date', 'price_set_id'));
             list($defaults["discount_end_date[{$i}]"]) = CRM_Utils_Date::setDateDefaults(CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Discount', $optionGroupId, 'end_date', 'price_set_id'));
             $defaultDiscounts[] = CRM_Price_BAO_PriceSet::getSetDetail($optionGroupId);
             $i++;
         }
         //avoid moving up value of lable when some labels don't
         //have a value ,fixed for CRM-3088
         $rowCount = 1;
         foreach ($defaultDiscounts as $val) {
             $discountFields = current($val);
             $discountFields = current($discountFields['fields']);
             foreach ($discountFields['options'] as $discountFieldsval) {
                 $defaults['discounted_label'][$discountFieldsval['weight']] = $discountFieldsval['label'];
                 $defaults['discounted_value'][$discountFieldsval['weight']][$rowCount] = CRM_Utils_Money::format($discountFieldsval['amount'], NULL, '%a');
                 $defaults['discount_option_id'][$rowCount][$discountFieldsval['weight']] = $discountFieldsval['id'];
                 if (!empty($discountFieldsval['is_default'])) {
                     $defaults['discounted_default'] = $discountFieldsval['weight'];
                 }
             }
             $rowCount++;
         }
         //CRM-12970
         ksort($defaults['discounted_value']);
         ksort($defaults['discounted_label']);
         $rowCount = 1;
         foreach ($defaults['discounted_label'] as $key => $value) {
             if ($key != $rowCount) {
                 $defaults['discounted_label'][$rowCount] = $value;
                 $defaults['discounted_value'][$rowCount] = $defaults['discounted_value'][$key];
                 unset($defaults['discounted_value'][$key]);
                 unset($defaults['discounted_label'][$key]);
                 foreach ($defaults['discount_option_id'] as &$optionIds) {
                     if (array_key_exists($key, $optionIds)) {
                         $optionIds[$rowCount] = $optionIds[$key];
                         unset($optionIds[$key]);
                     }
                 }
             }
             $rowCount++;
         }
         $this->set('discountSection', 1);
         $this->buildQuickForm();
     } elseif (!empty($defaults['label'])) {
         //if Regular Fees are present in DB and event fee page is in update mode
         $defaults['discounted_label'] = $defaults['label'];
     } elseif (!empty($this->_submitValues['label'])) {
         //if event is newly created, use submitted values for
         //discount labels
         if (is_array($this->_submitValues['label'])) {
             $k = 1;
             foreach ($this->_submitValues['label'] as $value) {
                 if ($value) {
                     $defaults['discounted_label'][$k] = $value;
                     $k++;
                 }
             }
         }
     }
     $defaults['id'] = $eventId;
     if (!empty($totalLables)) {
         $maxKey = count($totalLables) - 1;
         if (isset($maxKey) && !empty($totalLables[$maxKey]['value'])) {
             foreach ($totalLables[$maxKey]['value'] as $i => $v) {
                 if ($totalLables[$maxKey]['amount_id'][$i] == CRM_Utils_Array::value('default_discount_fee_id', $defaults)) {
                     $defaults['discounted_default'] = $i;
                     break;
                 }
             }
         }
     }
     if (!isset($defaults['discounted_default'])) {
         $defaults['discounted_default'] = 1;
     }
     if (!isset($defaults['is_monetary'])) {
         $defaults['is_monetary'] = 1;
     }
     if (!isset($defaults['fee_label'])) {
         $defaults['fee_label'] = ts('Event Fee(s)');
     }
     if (!isset($defaults['pay_later_text']) || empty($defaults['pay_later_text'])) {
         $defaults['pay_later_text'] = ts('I will send payment by check');
     }
     $this->_showHide = new CRM_Core_ShowHideBlocks();
     if (!$defaults['is_monetary']) {
         $this->_showHide->addHide('event-fees');
     }
     if (isset($defaults['price_set_id'])) {
         $this->_showHide->addHide('map-field');
     }
     $this->_showHide->addToTemplate();
     $this->assign('inDate', $this->_inDate);
     if (!empty($defaults['payment_processor'])) {
         $defaults['payment_processor'] = str_replace(CRM_Core_DAO::VALUE_SEPARATOR, ',', $defaults['payment_processor']);
     }
     return $defaults;
 }
Esempio n. 24
0
/**
 * Get Event record.
 *
 *
 * @param  array  $params     an associative array of name/value property values of civicrm_event
 * {@getfields event_get}
 *
 * @return  Array of all found event property values.
 * @access public
 *
 */
function civicrm_api3_event_get($params)
{
    //legacy support for $params['return.sort']
    if (!empty($params['return.sort'])) {
        $params['options']['sort'] = $params['return.sort'];
        unset($params['return.sort']);
    }
    //legacy support for $params['return.offset']
    if (!empty($params['return.offset'])) {
        $params['options']['offset'] = $params['return.offset'];
        unset($params['return.offset']);
    }
    //legacy support for $params['return.max_results']
    if (!empty($params['return.max_results'])) {
        $params['options']['limit'] = $params['return.max_results'];
        unset($params['return.max_results']);
    }
    $eventDAO = new CRM_Event_BAO_Event();
    _civicrm_api3_dao_set_filter($eventDAO, $params, TRUE, 'Event');
    if (!empty($params['is_template'])) {
        $eventDAO->whereAdd('( is_template = 1 )');
    } elseif (empty($eventDAO->id)) {
        $eventDAO->whereAdd('( is_template IS NULL ) OR ( is_template = 0 )');
    }
    if (!empty($params['isCurrent'])) {
        $eventDAO->whereAdd('(start_date >= CURDATE() || end_date >= CURDATE())');
    }
    // @todo should replace all this with _civicrm_api3_dao_to_array($bao, $params, FALSE, $entity) - but we still have
    // the return.is_full to deal with.
    // NB the std dao_to_array function should only return custom if required.
    $event = array();
    $options = _civicrm_api3_get_options_from_params($params);
    $eventDAO->find();
    while ($eventDAO->fetch()) {
        $event[$eventDAO->id] = array();
        CRM_Core_DAO::storeValues($eventDAO, $event[$eventDAO->id]);
        if (!empty($params['return.is_full'])) {
            _civicrm_api3_event_getisfull($event, $eventDAO->id);
        }
        _civicrm_api3_event_get_legacy_support_42($event, $eventDAO->id);
        _civicrm_api3_custom_data_get($event[$eventDAO->id], 'Event', $eventDAO->id, NULL, $eventDAO->event_type_id);
        if (!empty($options['return'])) {
            $event[$eventDAO->id]['price_set_id'] = CRM_Price_BAO_PriceSet::getFor('civicrm_event', $eventDAO->id);
        }
    }
    //end of the loop
    return civicrm_api3_create_success($event, $params, 'event', 'get', $eventDAO);
}