/** * retrieve() and getPledgeBlock() method of pledge block */ function testRetrieveAndGetPledgeBlock() { $pledgeFrequencyUnit = array('week' => 1, 'month' => 1, 'year' => 1); $params = array('entity_id' => $this->_contributionPageId, 'entity_table' => 'civicrm_contribution_page', 'pledge_frequency_unit' => $pledgeFrequencyUnit, 'max_reminders' => 2, 'initial_reminder_day' => 2, 'additional_reminder_day' => 1); $pledgeBlock = CRM_Pledge_BAO_PledgeBlock::create($params); // use retrieve() method $retrieveParams = array('entity_id' => $this->_contributionPageId, 'entity_table' => 'civicrm_contribution_page'); $default = array(); $retrievePledgeBlock = CRM_Pledge_BAO_PledgeBlock::retrieve($retrieveParams, $default); // use getPledgeBlock() method $getPledgeBlock = CRM_Pledge_BAO_PledgeBlock::getPledgeBlock($this->_contributionPageId); // check on both retrieve and getPledgeBlock values foreach ($params as $param => $value) { $this->assertEquals($value, $retrievePledgeBlock->{$param}); $this->assertEquals($value, $getPledgeBlock[$param]); } // Also check for pledgeBlock id. $this->assertEquals($pledgeBlock->id, $retrievePledgeBlock->id); $this->assertEquals($pledgeBlock->id, $getPledgeBlock['id']); }
/** * 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; }