function __construct($state = NULL,
$action = CRM_Core_Action::NONE,
$method = 'post',
- $name = NULL
+ $name = NULL
) {
$this->_config = CRM_Core_Config::singleton();
/* '2.2.alpha3', '2.2.0', '2.2.2', '2.1.alpha1', '2.1.3'); */
-
usort($revList, 'version_compare');
return $revList;
}
*/
public function getUpgradeVersions() {
$latestVer = CRM_Utils_System::version();
- $currentVer = CRM_Core_BAO_Domain::version(true);
+ $currentVer = CRM_Core_BAO_Domain::version(TRUE);
if (!$currentVer) {
CRM_Core_Error::fatal(ts('Version information missing in civicrm database.'));
}
array(1 => $latestVer));
}
- if (CRM_Core_DAO::getGlobalSetting('thread_stack', 0) < (1024*self::MINIMUM_THREAD_STACK)) {
+ if (CRM_Core_DAO::getGlobalSetting('thread_stack', 0) < (1024 * self::MINIMUM_THREAD_STACK)) {
$error = ts('CiviCRM %1 requires MySQL thread stack >= %2k', array(
1 => $latestVer,
2 => self::MINIMUM_THREAD_STACK
*
* @return bool
*/
- public static function doIncrementalUpgradeStep(CRM_Queue_TaskContext$ctx, $rev, $originalVer, $latestVer, $postUpgradeMessageFile) {
+ public static function doIncrementalUpgradeStep(CRM_Queue_TaskContext $ctx, $rev, $originalVer, $latestVer, $postUpgradeMessageFile) {
$upgrade = new CRM_Upgrade_Form();
$phpFunctionName = 'upgrade_' . str_replace('.', '_', $rev);
version_compare($rev, '3.2.alpha1') > 0
) {
$versionObject = $this->incrementalPhpObject($rev);
- if (is_callable(array(
+ if (is_callable(array(
$versionObject, 'setPreUpgradeMessage'))) {
- $versionObject->setPreUpgradeMessage($preUpgradeMessage, $rev, $currentVer);
- }
+ $versionObject->setPreUpgradeMessage($preUpgradeMessage, $rev, $currentVer);
+ }
}
}
}
$errorMessage = CRM_Core_Error::formatTextException($queueResult['exception']);
CRM_Core_Error::debug_log_message($errorMessage);
if ($enablePrint) {
- print($errorMessage);
- }
+ print ($errorMessage);
+ }
throw $queueResult['exception']; // FIXME test
}
public static function migrateHonoreeInfo(CRM_Queue_TaskContext $ctx) {
$query = "ALTER TABLE `civicrm_uf_join`
ADD COLUMN `module_data` longtext COMMENT 'Json serialized array of data used by the ufjoin.module'";
- CRM_Core_DAO::executeQuery($query);
+ CRM_Core_DAO::executeQuery($query);
$honorTypes = array_keys(CRM_Core_OptionGroup::values('honor_type'));
$ufGroupDAO = new CRM_Core_DAO_UFGroup();
if ($domain->locales) {
$locales = explode(CRM_Core_DAO::VALUE_SEPARATOR, $domain->locales);
foreach ($locales as $locale) {
- $honor_block_title = "honor_block_title_{$locale}";
- $honor_block_text = "honor_block_text_{$locale}";
+ $honor_block_title = "honor_block_title_{$locale}";
+ $honor_block_text = "honor_block_text_{$locale}";
$honorParams['soft_credit'] += array(
$locale => array(
'honor_block_title' => $dao->$honor_block_title,
}
}
if ($rev == '4.4.6'){
- $postUpgradeMessage .= '<br /><br /><strong>'. ts('Your contact image urls have been upgraded. If your contact image urls did not follow the standard format for image Urls they have not been upgraded. Please check the log to see image urls that were not upgraded.');
+ $postUpgradeMessage .= '<br /><br /><strong>'. ts('Your contact image urls have been upgraded. If your contact image urls did not follow the standard format for image Urls they have not been upgraded. Please check the log to see image urls that were not upgraded.');
}
}
$p[1] = array($acOptionGroupID, 'Integer');
if ($avinc) {
- $p[2] = array($avinc+$maxVal, 'Integer');
- $p[3] = array($avinc+$maxWeight, 'Integer');
+ $p[2] = array($avinc + $maxVal, 'Integer');
+ $p[3] = array($avinc + $maxWeight, 'Integer');
}
if ($nsinc) {
- $p[4] = array($nsinc+$maxVal, 'Integer');
- $p[5] = array($nsinc+$maxWeight, 'Integer');
+ $p[4] = array($nsinc + $maxVal, 'Integer');
+ $p[5] = array($nsinc + $maxWeight, 'Integer');
}
$insertStatus = implode(',', $insertStatus);
{$fkConstraint}
";
// CRM-14036 : delete entries of un-mapped contacts
- CRM_Core_DAO::executeQuery("DELETE ac FROM civicrm_activity_contact ac
+ CRM_Core_DAO::executeQuery("DELETE ac FROM civicrm_activity_contact ac
LEFT JOIN civicrm_contact c
ON c.id = ac.contact_id
WHERE c.id IS NULL;
");
- // delete entries of un-mapped activities
- CRM_Core_DAO::executeQuery("DELETE ac FROM civicrm_activity_contact ac
+ // delete entries of un-mapped activities
+ CRM_Core_DAO::executeQuery("DELETE ac FROM civicrm_activity_contact ac
LEFT JOIN civicrm_activity a
ON a.id = ac.activity_id
WHERE a.id IS NULL;
// CRM-13998 : missing alter statements for civicrm_report_instance
$this->addTask(ts('Confirm civicrm_report_instance sql table for upgrades'), 'updateReportInstanceTable');
-
return TRUE;
}
$imageURL = $dao->image_url;
$baseurl = CIVICRM_UF_BASEURL;
$baselen = strlen($baseurl);
- if (substr($imageURL, 0, $baselen)==$baseurl){
+ if (substr($imageURL, 0, $baselen) == $baseurl){
$photo = basename($dao->image_url);
$config = CRM_Core_Config::singleton();
$fullpath = $config->customFileUploadDir.$photo;
- if (file_exists($fullpath)){
- // For anyone who upgraded 4.4.6 release (eg 4.4.0=>4.4.6), the $newImageUrl incorrectly used backend URLs.
- // For anyone who skipped 4.4.6 (eg 4.4.0=>4.4.7), the $newImageUrl correctly uses frontend URLs
- self::setContactImageUrl($dao->id,
+ if (file_exists($fullpath)){
+ // For anyone who upgraded 4.4.6 release (eg 4.4.0=>4.4.6), the $newImageUrl incorrectly used backend URLs.
+ // For anyone who skipped 4.4.6 (eg 4.4.0=>4.4.7), the $newImageUrl correctly uses frontend URLs
+ self::setContactImageUrl($dao->id,
CRM_Utils_System::url('civicrm/contact/imagefile', 'photo='.$photo, TRUE, NULL, TRUE, TRUE));
- }
- else{
- $failures[$dao->id] = $dao->image_url;
- }
}
else{
- $failures[$dao->id] = $dao->image_url;
+ $failures[$dao->id] = $dao->image_url;
}
}
+ else{
+ $failures[$dao->id] = $dao->image_url;
+ }
+ }
CRM_Core_Error::debug_var('imageUrlsNotUpgraded', $failures);
return TRUE;
}
}
if (!$assigneeID || !$sourceID || !$targetID ) {
- $insert = "
+ $insert = "
INSERT INTO civicrm_option_value
(option_group_id, label, value, name, weight, is_reserved, is_active)
VALUES
$dao = CRM_Core_DAO::executeQuery($query);
-
$query = "
INSERT INTO civicrm_activity_contact (activity_id, contact_id, record_type_id)
SELECT activity_id, target_contact_id, {$targetID} as record_type_id
$dao = CRM_Core_DAO::executeQuery($query);
- $query = "DROP TABLE civicrm_activity_target";
- $dao = CRM_Core_DAO::executeQuery($query);
+ $query = "DROP TABLE civicrm_activity_target";
+ $dao = CRM_Core_DAO::executeQuery($query);
- $query = "DROP TABLE civicrm_activity_assignment";
- $dao = CRM_Core_DAO::executeQuery($query);
+ $query = "DROP TABLE civicrm_activity_assignment";
+ $dao = CRM_Core_DAO::executeQuery($query);
- $query = "ALTER TABLE civicrm_activity
+ $query = "ALTER TABLE civicrm_activity
DROP FOREIGN KEY FK_civicrm_activity_source_contact_id";
- $dao = CRM_Core_DAO::executeQuery($query);
+ $dao = CRM_Core_DAO::executeQuery($query);
- $query = "ALTER TABLE civicrm_activity DROP COLUMN source_contact_id";
- $dao = CRM_Core_DAO::executeQuery($query);
+ $query = "ALTER TABLE civicrm_activity DROP COLUMN source_contact_id";
+ $dao = CRM_Core_DAO::executeQuery($query);
- return TRUE;
+ return TRUE;
}
/**
foreach ($localeCustomArray as $localCustomData) {
// Traverse status array "enabled" "disabled"
foreach ($localCustomData as $status => $matchTypes) {
- $params["is_active"] = ($status == "enabled")?TRUE:FALSE;
+ $params["is_active"] = ($status == "enabled") ? TRUE : FALSE;
// Traverse Match Type array "wildcardMatch" "exactMatch"
foreach ($matchTypes as $matchType => $words) {
$params["match_type"] = $matchType;
$upgrade = new CRM_Upgrade_Form();
$upgrade->processSQL($rev);
-
$this->transferPreferencesToSettings();
$this->createNewSettings();
),
);
-
$userColumnNames = array(
self::NAVIGATION_NAME => array(
'navigation',
* @return void
*/
public function setPostUpgradeMessage(&$postUpgradeMessage, $rev) {
- if ($rev == '4.6.alpha1') {
+ if ($rev == '4.6.alpha1') {
$postUpgradeMessage .= '<br /><br />' . ts('Default versions of the following System Workflow Message Templates have been modified to handle new functionality: <ul><li>Events - Registration Confirmation and Receipt (on-line)</li><li>Events - Registration Confirmation and Receipt (off-line)</li><li>Contributions - Receipt (on-line)</li><li>Contributions - Receipt (off-line)</li><li>Memberships - Receipt (on-line)</li><li>Memberships - Signup and Renewal Receipts (off-line)</li></ul> If you have modified these templates, please review the new default versions and implement updates as needed to your copies (Administer > Communications > Message Templates > System Workflow Messages).');
- }
+ }
}
*/
public function setPreUpgradeMessage(&$preUpgradeMessage, $rev, $currentVer = NULL) {
if ($rev == '4.2.alpha1') {
- $tables = array('civicrm_contribution_page','civicrm_event','civicrm_group','civicrm_contact');
+ $tables = array('civicrm_contribution_page', 'civicrm_event', 'civicrm_group', 'civicrm_contact');
if (!CRM_Core_DAO::schemaRequiresRebuilding($tables)){
$errors = ts("The upgrade has identified some schema integrity issues in the database. It seems some of your constraints are missing. You will have to rebuild your schema before re-trying the upgrade. Please refer to %1.", array(1 => CRM_Utils_System::docURL2("Ensuring Schema Integrity on Upgrades", FALSE, "Ensuring Schema Integrity on Upgrades", NULL, NULL, "wiki")));
CRM_Core_Error::fatal($errors);
$invalidDataMessage .= "<td>{$invalidData->end_date}</td>";
$invalidDataMessage .= "<td>" . CRM_Utils_Array::value($invalidData->status_id, $membershipStatus) . "</td>";
$invalidDataMessage .= "</tr>";
- }
+ }
$invalidDataMessage .= "</table><p>" . ts('If you have reviewed the cleanup script documentation on the wiki and you are ready to run the cleanup now - <a href="%1">click here</a>.', array(1 => CRM_Utils_System::url('civicrm/upgrade/cleanup425', 'reset=1'))) . "</p>";
CRM_Core_Error::fatal($invalidDataMessage);
return FALSE;
- }
}
+ }
if ($rev == '4.2.beta2') {
// note: error conditions are also checked in upgrade_4_2_beta2()
$errors = ts("We found unexpected data values from an older version of CiviCRM in your database. The upgrade can not be run until this condition is corrected.<br /><br />Details: One or more rows are present in the civicrm_option_group with name like 'civicrm_price_field.amount.%'. <a href='%1'>Check here for information on diagnosing and correcting this problem.</a>", array(1 => 'http://forum.civicrm.org/index.php/topic,27744.msg118748.html#msg118748'));
CRM_Core_Error::fatal($errors);
return FALSE;
- }
+ }
}
}
$postUpgradeMessage .= '<br />' . ts('Please <a href="%1" target="_blank">configure the Extension Resource URL</a>.', array(
1 => CRM_Utils_System::url('civicrm/admin/setting/url', 'reset=1')
));
- }
+ }
}
if ($rev == '4.2.7') {
$postUpgradeMessage .= '<br />' . ts('If you have configured a report instance to allow anonymous access, you will need to reset the permission to Everyone for that instance (under the Report Settings pane).');
- }
+ }
}
/**
//checking whether the foreign key exists before dropping it
//drop foreign key queries of CRM-9850
$params = array();
- $tables = array('civicrm_contribution_page' =>'FK_civicrm_contribution_page_payment_processor_id',
+ $tables = array(
+ 'civicrm_contribution_page' => 'FK_civicrm_contribution_page_payment_processor_id',
'civicrm_event' => 'FK_civicrm_event_payment_processor_id',
'civicrm_group' => 'FK_civicrm_group_saved_search_id',
);
foreach($tables as $tableName => $fKey){
- $foreignKeyExists = CRM_Core_DAO::checkConstraintExists($tableName,$fKey);
+ $foreignKeyExists = CRM_Core_DAO::checkConstraintExists($tableName, $fKey);
if ($foreignKeyExists){
CRM_Core_DAO::executeQuery("ALTER TABLE {$tableName} DROP FOREIGN KEY {$fKey}", $params, TRUE, NULL, FALSE, FALSE);
CRM_Core_DAO::executeQuery("ALTER TABLE {$tableName} DROP INDEX {$fKey}", $params, TRUE, NULL, FALSE, FALSE);
while ($dao->fetch()) {
$addTo = explode('.', $dao->name);
if (!empty($addTo[2])) {
- $options = array ('optionGroup' => $dao->name);
+ $options = array('optionGroup' => $dao->name);
self::createPriceSet($daoName, $addTo, $options);
}
CRM_Core_OptionGroup::deleteAssoc($dao->name);
$addTo = array('civicrm_contribution_page');
while ($dao->fetch()) {
$addTo[2] = $dao->contribution_page_id;
- $options = array ('otherAmount' =>$dao->is_allow_other_amount,
+ $options = array(
+ 'otherAmount' => $dao->is_allow_other_amount,
'membership' => $dao->membership_block_id );
self::createPriceSet($daoName, $addTo, $options);
}
* (Queue Task Callback)
*/
public static function task_4_2_x_runSql(CRM_Queue_TaskContext $ctx, $rev) {
- $upgrade = new CRM_Upgrade_Form();
- $upgrade->processSQL($rev);
+ $upgrade = new CRM_Upgrade_Form();
+ $upgrade->processSQL($rev);
- // now rebuild all the triggers
- // CRM-9716
- // FIXME // CRM_Core_DAO::triggerRebuild();
+ // now rebuild all the triggers
+ // CRM-9716
+ // FIXME // CRM_Core_DAO::triggerRebuild();
- return TRUE;
+ return TRUE;
}
/**
*
* create price sets
*/
- public static function createPriceSet($daoName, $addTo, $options = array()) {
+ public static function createPriceSet($daoName, $addTo, $options = array()) {
$query = "SELECT title FROM {$addTo[0]} where id =%1";
$setParams['title'] = CRM_Core_DAO::singleValueQuery($query,
array(1 => array($addTo[2], 'Integer'))
$optionValue = array();
if (!empty($options['optionGroup'])) {
CRM_Core_OptionGroup::getAssoc($options['optionGroup'], $optionValue);
- if (empty($optionValue))
+ if (empty($optionValue)) {
return;
+ }
}
elseif (empty($options['otherAmount']) && empty($options['membership'])) {
//CRM-12273
return;
}
- if (! CRM_Core_DAO::getFieldValue('CRM_Upgrade_Snapshot_V4p2_Price_BAO_Set', $pageTitle, 'id', 'name', true)) {
+ if (! CRM_Core_DAO::getFieldValue('CRM_Upgrade_Snapshot_V4p2_Price_BAO_Set', $pageTitle, 'id', 'name', TRUE)) {
$setParams['name'] = $pageTitle;
}
else {
- $timeSec = explode(".", microtime(true));
+ $timeSec = explode(".", microtime(TRUE));
$setParams['name'] = $pageTitle . '_' . date('is', $timeSec[0]) . $timeSec[1];
}
$setParams['extends'] = $daoName[$addTo[0]][1];
$contribStatus = CRM_Utils_Array::value($dao->contribution_status_id, $contributionStatus);
$processedRecords[] = array($dao->contact_id, $dao->contribution_id, $contribStatus, $dao->membership_id,
$memType, $dao->start_date, $dao->end_date, $memStatus, $status);
-}
+ }
}
if ( !empty($processedRecords) ) {
WHERE v.option_group_id = g.id
AND g.name = %1
AND g.is_active = 1
- AND v.name = %2", array(1 => array('activity_type', 'String'),
+ AND v.name = %2", array(
+ 1 => array('activity_type', 'String'),
2 => array('Bulk Email', 'String'),
));
VALUES
(1, 'OnBehalf', 'civicrm_contribution_page', %1, 1, %2)";
- $params = array(1 => array($pages->id, 'Integer'),
+ $params = array(
+ 1 => array($pages->id, 'Integer'),
2 => array($onBehalfProfileId, 'Integer'),
);
CRM_Core_DAO::executeQuery($query, $params);
while ($customField->fetch()) {
$name = CRM_Utils_String::munge($customField->label, '_', 64);
$fldCnt = CRM_Core_DAO::singleValueQuery($customFldCntQuery,
- array(1 => array($name, 'String'),
+ array(
+ 1 => array($name, 'String'),
2 => array($customField->id, 'Integer'),
), TRUE, FALSE
);
SET `name` = %1
WHERE id = %2
";
- $customFieldParams = array(1 => array($name, 'String'),
+ $customFieldParams = array(
+ 1 => array($name, 'String'),
2 => array($customField->id, 'Integer'),
);
CRM_Core_DAO::executeQuery($customFieldQuery, $customFieldParams, TRUE, NULL, FALSE, FALSE);
while ($customGroup->fetch()) {
$name = CRM_Utils_String::munge($customGroup->title, '_', 64);
$grpCnt = CRM_Core_DAO::singleValueQuery($customGrpCntQuery,
- array(1 => array($name, 'String'),
+ array(
+ 1 => array($name, 'String'),
2 => array($customGroup->id, 'Integer'),
)
);
while ($ufGroup->fetch()) {
$name = CRM_Utils_String::munge($ufGroup->title, '_', 64);
$ufGrpCnt = CRM_Core_DAO::singleValueQuery($ufGrpCntQuery,
- array(1 => array($name, 'String'),
+ array(
+ 1 => array($name, 'String'),
2 => array($ufGroup->id, 'Integer'),
)
);
$updateLineItem1 = "ALTER TABLE civicrm_line_item ADD COLUMN price_field_value_id int(10) unsigned default NULL;";
CRM_Core_DAO::executeQuery($updateLineItem1);
-
$priceFieldDAO = new CRM_Price_DAO_PriceField();
$priceFieldDAO->find();
$ids = array();
// update civicrm_line_item for price_field_value_id.
// Used query to avoid line by line update.
if ($labelFound || $priceFound) {
- $lineItemParams = array(1 => array($fieldValueDAO->id, 'Integer'),
+ $lineItemParams = array(
+ 1 => array($fieldValueDAO->id, 'Integer'),
2 => array($opValueDAO->label, 'String'),
);
$updateLineItems = "UPDATE civicrm_line_item SET price_field_value_id = %1 WHERE label = %2";
$mainLineItem->find(TRUE);
while ($mainLineItem->fetch()) {
$dupeLineItem = new CRM_Price_BAO_LineItem();
- foreach ($fields as $fld) $dupeLineItem->$fld = $mainLineItem->$fld;
+ foreach ($fields as $fld) { $dupeLineItem->$fld = $mainLineItem->$fld;
+ }
$dupeLineItem->find(TRUE);
$dupeLineItem->addWhere("id != $mainLineItem->id");
while ($dupeLineItem->fetch()) {
$preMessage = !empty($rows) ? ts('The following records have been processed. Membership records with action = Un-linked have been disconnected from the listed contribution record:') : ts('Could not find any records to process.');
$template->assign('preMessage', $preMessage);
- $postMessage = ts('You can <a href="%1">click here</a> to try running the 4.2 upgrade script again. <a href="%2" target="_blank">(Review upgrade documentation)</a>',
- array(1 => CRM_Utils_System::url('civicrm/upgrade', 'reset=1'),
+ $postMessage = ts('You can <a href="%1">click here</a> to try running the 4.2 upgrade script again. <a href="%2" target="_blank">(Review upgrade documentation)</a>',
+ array(
+ 1 => CRM_Utils_System::url('civicrm/upgrade', 'reset=1'),
2 => 'http://wiki.civicrm.org/confluence/display/CRMDOC/Installation+and+Upgrades'));
$template->assign('postMessage', $postMessage);
if ($opId = CRM_Utils_Array::value($index, $opIds)) {
$optionsIds['id'] = $opId;
}
- else $optionsIds['id'] = NULL;
+ else { $optionsIds['id'] = NULL;
+ }
}
CRM_Upgrade_Snapshot_V4p2_Price_BAO_FieldValue::create($options, $optionsIds);
}
$elementName,
$fieldId,
$inactiveNeeded,
- $useRequired = TRUE,
- $label = NULL,
+ $useRequired = TRUE,
+ $label = NULL,
$fieldOptions = NULL,
$freezeOptions = array()
) {
$currencyName = $config->defaultCurrency;
if (!isset($label)) {
- $label = (property_exists($qf,'_membershipBlock') && !empty($qf->_membershipBlock['is_separate_payment']) && $field->name == 'contribution_amount' && empty($otherAmount['is_allow_other_amount'])) ? ts('Additional Contribution') : $field->label;
+ $label = (property_exists($qf, '_membershipBlock') && !empty($qf->_membershipBlock['is_separate_payment']) && $field->name == 'contribution_amount' && empty($otherAmount['is_allow_other_amount'])) ? ts('Additional Contribution') : $field->label;
}
if ($field->name == 'contribution_amount') {
- $qf->_contributionAmount = 1;
+ $qf->_contributionAmount = 1;
}
if (isset($qf->_online) && $qf->_online) {
$priceVal = implode($seperator, array($customOption[$optionKey][$valueFieldName], $count, $max_value));
$extra = array();
- if (property_exists($qf,'_quickConfig') && $qf->_quickConfig && property_exists($qf,'_contributionAmount') && $qf->_contributionAmount) {
+ if (property_exists($qf, '_quickConfig') && $qf->_quickConfig && property_exists($qf, '_contributionAmount') && $qf->_contributionAmount) {
$qf->assign('priceset', $elementName);
$extra = array('onclick' => 'useAmountOther();');
}
// if seperate membership payment is used with quick config priceset then change the other amount label
- if (property_exists($qf,'_membershipBlock') && !empty($qf->_membershipBlock['is_separate_payment']) && $qf->_quickConfig && $field->name == 'other_amount' && !property_exists($qf,'_contributionAmount')) {
- $label = ts('Additional Contribution');
- $useRequired = 0;
+ if (property_exists($qf, '_membershipBlock') && !empty($qf->_membershipBlock['is_separate_payment']) && $qf->_quickConfig && $field->name == 'other_amount' && !property_exists($qf, '_contributionAmount')) {
+ $label = ts('Additional Contribution');
+ $useRequired = 0;
} elseif (!empty($fieldOptions[$optionKey]['label'])) { //check for label.
- $label = $fieldOptions[$optionKey]['label'];
+ $label = $fieldOptions[$optionKey]['label'];
}
if ($field->is_display_amounts) {
$element = &$qf->add('text', $elementName, $label,
array_merge($extra,
- array('price' => json_encode(array($optionKey, $priceVal)),
+ array(
+ 'price' => json_encode(array($optionKey, $priceVal)),
'size' => '4',
)
),
case 'Radio':
$choice = array();
- if (property_exists($qf, '_quickConfig') && $qf->_quickConfig && property_exists($qf,'_contributionAmount') && $qf->_contributionAmount) {
+ if (property_exists($qf, '_quickConfig') && $qf->_quickConfig && property_exists($qf, '_contributionAmount') && $qf->_contributionAmount) {
$qf->assign('contriPriceset', $elementName);
}
$count = CRM_Utils_Array::value('count', $opt, '');
$max_value = CRM_Utils_Array::value('max_value', $opt, '');
$priceVal = implode($seperator, array($opt[$valueFieldName], $count, $max_value));
- $extra = array('price' => json_encode(array($elementName, $priceVal)),
+ $extra = array(
+ 'price' => json_encode(array($elementName, $priceVal)),
'data-amount' => $opt[$valueFieldName],
'data-currency' => $currencyName,
);
if (property_exists($qf, '_quickConfig') && $qf->_quickConfig && $field->name == 'contribution_amount') {
$extra += array('onclick' => 'clearAmountOther();');
} elseif (property_exists($qf, '_quickConfig') && $qf->_quickConfig && $field->name == 'membership_amount') {
- $extra += array('onclick' => "return showHideAutoRenew({$opt['membership_type_id']});",
+ $extra += array(
+ 'onclick' => "return showHideAutoRenew({$opt['membership_type_id']});",
'membership-type' => $opt['membership_type_id'],
);
- $qf->assign('membershipFieldID',$field->id);
+ $qf->assign('membershipFieldID', $field->id);
}
$choice[$opId] = $qf->createElement('radio', NULL, '', $opt['label'], $opt['id'], $extra);
$opt['label'] .= CRM_Utils_Money::format($opt[$valueFieldName]);
}
$check[$opId] = &$qf->createElement('checkbox', $opt['id'], NULL, $opt['label'],
- array('price' => json_encode(array($opt['id'], $priceVal)),
+ array(
+ 'price' => json_encode(array($opt['id'], $priceVal)),
'data-amount' => $opt[$valueFieldName],
'data-currency' => $currencyName,
)
}
if ($id = CRM_Utils_Array::value('id', $ids)) {
- if (isset($params['name']))unset($params['name']);
+ if (isset($params['name'])) { unset($params['name']);
+ }
$oldWeight = NULL;
if ($id) {
* to the price set used for particular event
* @param array $values
* Reference to the values array(.
- this is
+ this is
* lineItem array)
*
* @return void
* @param array $otherParams
*/
public static function syncLineItems($entityId, $entityTable = 'civicrm_contribution', $amount, $otherParams = NULL) {
- if (!$entityId || CRM_Utils_System::isNull($amount))
+ if (!$entityId || CRM_Utils_System::isNull($amount)) {
return;
+ }
$from = " civicrm_line_item li
LEFT JOIN civicrm_price_field pf ON pf.id = li.price_field_id
$set .= " ,li.label = %4,
li.price_field_value_id = cpfv.id ";
$where .= " AND cpse.entity_table = 'civicrm_event' AND cpse.entity_id = %5 ";
- $amount = empty($amount) ? 0: $amount;
+ $amount = empty($amount) ? 0 : $amount;
$params += array(
4 => array($otherParams['fee_label'], 'String'),
5 => array($otherParams['event_id'], 'String'),
$dao = CRM_Core_DAO::executeQuery($sql);
$defaultPriceSet = array();
while ($dao->fetch()) {
- $defaultPriceSet[$dao->priceFieldValueID]['setID'] = $dao->setID;
- $defaultPriceSet[$dao->priceFieldValueID]['priceFieldID'] = $dao->priceFieldID;
- $defaultPriceSet[$dao->priceFieldValueID]['name'] = $dao->name;
- $defaultPriceSet[$dao->priceFieldValueID]['label'] = $dao->label;
+ $defaultPriceSet[$dao->priceFieldValueID]['setID'] = $dao->setID;
+ $defaultPriceSet[$dao->priceFieldValueID]['priceFieldID'] = $dao->priceFieldID;
+ $defaultPriceSet[$dao->priceFieldValueID]['name'] = $dao->name;
+ $defaultPriceSet[$dao->priceFieldValueID]['label'] = $dao->label;
}
-
return $defaultPriceSet;
}
return $tables;
}
if (empty($forms)) {
- $queryString = "
+ $queryString = "
SELECT cli.entity_table, cli.entity_id
FROM civicrm_line_item cli
LEFT JOIN civicrm_price_field cpf ON cli.price_field_id = cpf.id
if ($isQuickConfig) {
$sql .= " AND ps.is_quick_config = 0 ";
}
- $params = array(1 => array($entityTable, 'String'),
+ $params = array(
+ 1 => array($entityTable, 'String'),
2 => array($entityId, 'Integer'),
);
if ($usedFor) {
if ($params["price_{$id}"] <= 0) {
continue;
}
- $params["price_{$id}"] = array($params["price_{$id}"] => 1);
- $optionValueId = CRM_Utils_Array::key(1, $params["price_{$id}"]);
- $optionLabel = CRM_Utils_Array::value('label', $field['options'][$optionValueId]);
- $params['amount_priceset_level_radio'] = array();
- $params['amount_priceset_level_radio'][$optionValueId] = $optionLabel;
- if (isset($radioLevel)) {
- $radioLevel = array_merge($radioLevel,
+ $params["price_{$id}"] = array($params["price_{$id}"] => 1);
+ $optionValueId = CRM_Utils_Array::key(1, $params["price_{$id}"]);
+ $optionLabel = CRM_Utils_Array::value('label', $field['options'][$optionValueId]);
+ $params['amount_priceset_level_radio'] = array();
+ $params['amount_priceset_level_radio'][$optionValueId] = $optionLabel;
+ if (isset($radioLevel)) {
+ $radioLevel = array_merge($radioLevel,
array_keys($params['amount_priceset_level_radio'])
- );
- }
- else {
- $radioLevel = array_keys($params['amount_priceset_level_radio']);
- }
- CRM_Upgrade_Snapshot_V4p2_Price_BAO_LineItem::format($id, $params, $field, $lineItem);
- $totalPrice += $lineItem[$optionValueId]['line_total'];
- break;
+ );
+ }
+ else {
+ $radioLevel = array_keys($params['amount_priceset_level_radio']);
+ }
+ CRM_Upgrade_Snapshot_V4p2_Price_BAO_LineItem::format($id, $params, $field, $lineItem);
+ $totalPrice += $lineItem[$optionValueId]['line_total'];
+ break;
case 'Select':
$params["price_{$id}"] = array($params["price_{$id}"] => 1);
$params['amount_priceset_level_select'] = array();
$params['amount_priceset_level_select'][CRM_Utils_Array::key(1, $params["price_{$id}"])] = $optionLabel;
if (isset($selectLevel)) {
- $selectLevel = array_merge($selectLevel, array_keys($params['amount_priceset_level_select']));
- }
- else {
- $selectLevel = array_keys($params['amount_priceset_level_select']);
- }
- CRM_Upgrade_Snapshot_V4p2_Price_BAO_LineItem::format($id, $params, $field, $lineItem);
- $totalPrice += $lineItem[$optionValueId]['line_total'];
- break;
- case 'CheckBox':
- $params['amount_priceset_level_checkbox'] = $optionIds = array();
- foreach ($params["price_{$id}"] as $optionId => $option) {
- $optionIds[] = $optionId;
- $optionLabel = $field['options'][$optionId]['label'];
- $params['amount_priceset_level_checkbox']["{$field['options'][$optionId]['id']}"] = $optionLabel;
- if (isset($checkboxLevel)) {
- $checkboxLevel = array_unique(array_merge(
- $checkboxLevel,
- array_keys($params['amount_priceset_level_checkbox'])
- )
- );
- }
- else {
- $checkboxLevel = array_keys($params['amount_priceset_level_checkbox']);
- }
- }
- CRM_Upgrade_Snapshot_V4p2_Price_BAO_LineItem::format($id, $params, $field, $lineItem);
- foreach ($optionIds as $optionId) {
- $totalPrice += $lineItem[$optionId]['line_total'];
- }
- break;
+ $selectLevel = array_merge($selectLevel, array_keys($params['amount_priceset_level_select']));
+ }
+ else {
+ $selectLevel = array_keys($params['amount_priceset_level_select']);
+ }
+ CRM_Upgrade_Snapshot_V4p2_Price_BAO_LineItem::format($id, $params, $field, $lineItem);
+ $totalPrice += $lineItem[$optionValueId]['line_total'];
+ break;
+
+ case 'CheckBox':
+ $params['amount_priceset_level_checkbox'] = $optionIds = array();
+ foreach ($params["price_{$id}"] as $optionId => $option) {
+ $optionIds[] = $optionId;
+ $optionLabel = $field['options'][$optionId]['label'];
+ $params['amount_priceset_level_checkbox']["{$field['options'][$optionId]['id']}"] = $optionLabel;
+ if (isset($checkboxLevel)) {
+ $checkboxLevel = array_unique(array_merge(
+ $checkboxLevel,
+ array_keys($params['amount_priceset_level_checkbox'])
+ )
+ );
+ }
+ else {
+ $checkboxLevel = array_keys($params['amount_priceset_level_checkbox']);
+ }
+ }
+ CRM_Upgrade_Snapshot_V4p2_Price_BAO_LineItem::format($id, $params, $field, $lineItem);
+ foreach ($optionIds as $optionId) {
+ $totalPrice += $lineItem[$optionId]['line_total'];
+ }
+ break;
}
}
*
* @return void
*/
-static function buildPriceSet(&$form) {
-$priceSetId = $form->get('priceSetId');
-$userid = $form->getVar('_userID');
-if (!$priceSetId) {
- return;
-}
+ static function buildPriceSet(&$form) {
+ $priceSetId = $form->get('priceSetId');
+ $userid = $form->getVar('_userID');
+ if (!$priceSetId) {
+ return;
+ }
-$validFieldsOnly = TRUE;
-$className = CRM_Utils_System::getClassName($form);
-if (in_array($className, array(
+ $validFieldsOnly = TRUE;
+ $className = CRM_Utils_System::getClassName($form);
+ if (in_array($className, array(
'CRM_Contribute_Form_Contribution', 'CRM_Member_Form_Membership'))) {
-$validFieldsOnly = FALSE;
-}
+ $validFieldsOnly = FALSE;
+ }
-$priceSet = self::getSetDetail($priceSetId, TRUE, $validFieldsOnly);
-$form->_priceSet = CRM_Utils_Array::value($priceSetId, $priceSet);
-$form->_quickConfig = $quickConfig = 0;
-if (CRM_Core_DAO::getFieldValue('CRM_Upgrade_Snapshot_V4p2_Price_DAO_Set', $priceSetId, 'is_quick_config')) {
- $quickConfig = 1;
-}
+ $priceSet = self::getSetDetail($priceSetId, TRUE, $validFieldsOnly);
+ $form->_priceSet = CRM_Utils_Array::value($priceSetId, $priceSet);
+ $form->_quickConfig = $quickConfig = 0;
+ if (CRM_Core_DAO::getFieldValue('CRM_Upgrade_Snapshot_V4p2_Price_DAO_Set', $priceSetId, 'is_quick_config')) {
+ $quickConfig = 1;
+ }
-$form->assign('quickConfig', $quickConfig);
-if ($className == "CRM_Contribute_Form_Contribution_Main") {
-$form->_quickConfig = $quickConfig;
-}
-$form->assign('priceSet', $form->_priceSet);
+ $form->assign('quickConfig', $quickConfig);
+ if ($className == "CRM_Contribute_Form_Contribution_Main") {
+ $form->_quickConfig = $quickConfig;
+ }
+ $form->assign('priceSet', $form->_priceSet);
-$component = 'contribution';
-if ($className == 'CRM_Member_Form_Membership') {
-$component = 'membership';
-}
+ $component = 'contribution';
+ if ($className == 'CRM_Member_Form_Membership') {
+ $component = 'membership';
+ }
-if ($className == 'CRM_Contribute_Form_Contribution_Main') {
-$feeBlock = &$form->_values['fee'];
-if (!empty($form->_useForMember)) {
-$component = 'membership';
-}
-}
-else {
-$feeBlock = &$form->_priceSet['fields'];
-}
+ if ($className == 'CRM_Contribute_Form_Contribution_Main') {
+ $feeBlock = &$form->_values['fee'];
+ if (!empty($form->_useForMember)) {
+ $component = 'membership';
+ }
+ }
+ else {
+ $feeBlock = &$form->_priceSet['fields'];
+ }
-// call the hook.
-CRM_Utils_Hook::buildAmount($component, $form, $feeBlock);
+ // call the hook.
+ CRM_Utils_Hook::buildAmount($component, $form, $feeBlock);
-foreach ($feeBlock as $field) {
-if (CRM_Utils_Array::value('visibility', $field) == 'public' ||
+ foreach ($feeBlock as $field) {
+ if (CRM_Utils_Array::value('visibility', $field) == 'public' ||
!$validFieldsOnly
) {
-$options = CRM_Utils_Array::value('options', $field);
-if ($className == 'CRM_Contribute_Form_Contribution_Main' && $component = 'membership') {
-$checklifetime = self::checkCurrentMembership($options, $userid);
-if ($checklifetime) {
-$form->assign('ispricelifetime', TRUE);
-}
-}
-if (!is_array($options)) {
- continue;
-}
-CRM_Upgrade_Snapshot_V4p2_Price_BAO_Field::addQuickFormElement($form,
-'price_' . $field['id'],
-$field['id'],
-FALSE,
-CRM_Utils_Array::value('is_required', $field, FALSE),
-NULL,
-$options
-);
-}
-}
-}
+ $options = CRM_Utils_Array::value('options', $field);
+ if ($className == 'CRM_Contribute_Form_Contribution_Main' && $component = 'membership') {
+ $checklifetime = self::checkCurrentMembership($options, $userid);
+ if ($checklifetime) {
+ $form->assign('ispricelifetime', TRUE);
+ }
+ }
+ if (!is_array($options)) {
+ continue;
+ }
+ CRM_Upgrade_Snapshot_V4p2_Price_BAO_Field::addQuickFormElement($form,
+ 'price_' . $field['id'],
+ $field['id'],
+ FALSE,
+ CRM_Utils_Array::value('is_required', $field, FALSE),
+ NULL,
+ $options
+ );
+ }
+ }
+ }
-/**
- * check the current Membership
- * having end date null.
- */
-static function checkCurrentMembership(&$options, $userid) {
-if (!$userid || empty($options)) {
-return;
-}
-static $_contact_memberships = array();
-$checklifetime = FALSE;
-foreach ($options as $key => $value) {
-if (!empty($value['membership_type_id'])) {
-if (!isset($_contact_memberships[$userid][$value['membership_type_id']])) {
-$_contact_memberships[$userid][$value['membership_type_id']] = CRM_Member_BAO_Membership::getContactMembership($userid, $value['membership_type_id'], FALSE);
-}
-$currentMembership = $_contact_memberships[$userid][$value['membership_type_id']];
-if (!empty($currentMembership) && empty($currentMembership['end_date'])) {
-unset($options[$key]);
-$checklifetime = TRUE;
-}
-}
-}
-if ($checklifetime) {
-return TRUE;
-}
-else {
-return FALSE;
-}
-}
+ /**
+ * check the current Membership
+ * having end date null.
+ */
+ static function checkCurrentMembership(&$options, $userid) {
+ if (!$userid || empty($options)) {
+ return;
+ }
+ static $_contact_memberships = array();
+ $checklifetime = FALSE;
+ foreach ($options as $key => $value) {
+ if (!empty($value['membership_type_id'])) {
+ if (!isset($_contact_memberships[$userid][$value['membership_type_id']])) {
+ $_contact_memberships[$userid][$value['membership_type_id']] = CRM_Member_BAO_Membership::getContactMembership($userid, $value['membership_type_id'], FALSE);
+ }
+ $currentMembership = $_contact_memberships[$userid][$value['membership_type_id']];
+ if (!empty($currentMembership) && empty($currentMembership['end_date'])) {
+ unset($options[$key]);
+ $checklifetime = TRUE;
+ }
+ }
+ }
+ if ($checklifetime) {
+ return TRUE;
+ }
+ else {
+ return FALSE;
+ }
+ }
/**
* Set daefult the price set fields.
*
* @return array $defaults
*/
-static function setDefaultPriceSet(&$form, &$defaults) {
-if (!isset($form->_priceSet) || empty($form->_priceSet['fields'])) {
-return $defaults;
-}
+ static function setDefaultPriceSet(&$form, &$defaults) {
+ if (!isset($form->_priceSet) || empty($form->_priceSet['fields'])) {
+ return $defaults;
+ }
-foreach ($form->_priceSet['fields'] as $key => $val) {
-foreach ($val['options'] as $keys => $values) {
-if ($values['is_default']) {
-if ($val['html_type'] == 'CheckBox') {
-$defaults["price_{$key}"][$keys] = 1;
-}
-else {
-$defaults["price_{$key}"] = $keys;
-}
-}
-}
-}
-return $defaults;
-}
+ foreach ($form->_priceSet['fields'] as $key => $val) {
+ foreach ($val['options'] as $keys => $values) {
+ if ($values['is_default']) {
+ if ($val['html_type'] == 'CheckBox') {
+ $defaults["price_{$key}"][$keys] = 1;
+ }
+ else {
+ $defaults["price_{$key}"] = $keys;
+ }
+ }
+ }
+ }
+ return $defaults;
+ }
-/**
- * Get field ids of a price set
- *
- * @param int id Price Set id
- *
- * @return array of the field ids
- *
- * @static
- */
-public static function getFieldIds($id) {
-$priceField = new CRM_Upgrade_Snapshot_V4p2_Price_DAO_Field();
-$priceField->price_set_id = $id;
-$priceField->find();
-while ($priceField->fetch()) {
-$var[] = $priceField->id;
-}
-return $var;
-}
+ /**
+ * Get field ids of a price set
+ *
+ * @param int id Price Set id
+ *
+ * @return array of the field ids
+ *
+ * @static
+ */
+ public static function getFieldIds($id) {
+ $priceField = new CRM_Upgrade_Snapshot_V4p2_Price_DAO_Field();
+ $priceField->price_set_id = $id;
+ $priceField->find();
+ while ($priceField->fetch()) {
+ $var[] = $priceField->id;
+ }
+ return $var;
+ }
-/**
- * This function is to make a copy of a price set, including
- * all the fields
- *
- * @param int $id
- * The price set id to copy.
- *
- * @return the copy object
- * @static
- */
-static function copy($id) {
-$maxId = CRM_Core_DAO::singleValueQuery("SELECT max(id) FROM civicrm_price_set");
-
-$title = ts('[Copy id %1]', array(1 => $maxId + 1));
-$fieldsFix = array(
- 'suffix' => array('title' => ' ' . $title,
-'name' => '__Copy_id_' . ($maxId + 1) . '_',
-),
-);
-
-$copy = &CRM_Core_DAO::copyGeneric('CRM_Upgrade_Snapshot_V4p2_Price_DAO_Set',
-array('id' => $id),
-NULL,
-$fieldsFix
-);
-
-//copying all the blocks pertaining to the price set
-$copyPriceField = &CRM_Core_DAO::copyGeneric('CRM_Upgrade_Snapshot_V4p2_Price_DAO_Field',
-array('price_set_id' => $id),
-array('price_set_id' => $copy->id)
-);
-if (!empty($copyPriceField)) {
-$price = array_combine(self::getFieldIds($id), self::getFieldIds($copy->id));
-
-//copy option group and values
-foreach ($price as $originalId => $copyId) {
-CRM_Core_DAO::copyGeneric('CRM_Upgrade_Snapshot_V4p2_Price_DAO_FieldValue',
-array('price_field_id' => $originalId),
-array('price_field_id' => $copyId)
-);
-}
-}
-$copy->save();
+ /**
+ * This function is to make a copy of a price set, including
+ * all the fields
+ *
+ * @param int $id
+ * The price set id to copy.
+ *
+ * @return the copy object
+ * @static
+ */
+ static function copy($id) {
+ $maxId = CRM_Core_DAO::singleValueQuery("SELECT max(id) FROM civicrm_price_set");
+
+ $title = ts('[Copy id %1]', array(1 => $maxId + 1));
+ $fieldsFix = array(
+ 'suffix' => array(
+ 'title' => ' ' . $title,
+ 'name' => '__Copy_id_' . ($maxId + 1) . '_',
+ ),
+ );
-CRM_Utils_Hook::copy('Set', $copy);
-return $copy;
-}
+ $copy = &CRM_Core_DAO::copyGeneric('CRM_Upgrade_Snapshot_V4p2_Price_DAO_Set',
+ array('id' => $id),
+ NULL,
+ $fieldsFix
+ );
+
+ //copying all the blocks pertaining to the price set
+ $copyPriceField = &CRM_Core_DAO::copyGeneric('CRM_Upgrade_Snapshot_V4p2_Price_DAO_Field',
+ array('price_set_id' => $id),
+ array('price_set_id' => $copy->id)
+ );
+ if (!empty($copyPriceField)) {
+ $price = array_combine(self::getFieldIds($id), self::getFieldIds($copy->id));
+
+ //copy option group and values
+ foreach ($price as $originalId => $copyId) {
+ CRM_Core_DAO::copyGeneric('CRM_Upgrade_Snapshot_V4p2_Price_DAO_FieldValue',
+ array('price_field_id' => $originalId),
+ array('price_field_id' => $copyId)
+ );
+ }
+ }
+ $copy->save();
+
+ CRM_Utils_Hook::copy('Set', $copy);
+ return $copy;
+ }
/**
* This function is to check price set permission
*
* @return bool
*/
-function checkPermission($sid) {
-if ($sid &&
+ function checkPermission($sid) {
+ if ($sid &&
self::eventPriceSetDomainID()
) {
-$domain_id = CRM_Core_DAO::getFieldValue('CRM_Upgrade_Snapshot_V4p2_Price_DAO_Set', $sid, 'domain_id', 'id');
-if (CRM_Core_Config::domainID() != $domain_id) {
-CRM_Core_Error::fatal(ts('You do not have permission to access this page.'));
-}
-}
-return TRUE;
-}
+ $domain_id = CRM_Core_DAO::getFieldValue('CRM_Upgrade_Snapshot_V4p2_Price_DAO_Set', $sid, 'domain_id', 'id');
+ if (CRM_Core_Config::domainID() != $domain_id) {
+ CRM_Core_Error::fatal(ts('You do not have permission to access this page.'));
+ }
+ }
+ return TRUE;
+ }
/**
* Get the sum of participant count
* @return int|null|string
* @static
*/
-public static function getPricesetCount($sid, $onlyActive = TRUE) {
-$count = 0;
-if (!$sid) {
- return $count;
-}
+ public static function getPricesetCount($sid, $onlyActive = TRUE) {
+ $count = 0;
+ if (!$sid) {
+ return $count;
+ }
-$where = NULL;
-if ($onlyActive) {
- $where = 'AND value.is_active = 1 AND field.is_active = 1';
-}
+ $where = NULL;
+ if ($onlyActive) {
+ $where = 'AND value.is_active = 1 AND field.is_active = 1';
+ }
-static $pricesetFieldCount;
-if (!isset($pricesetFieldCount[$sid])) {
-$sql = "
+ static $pricesetFieldCount;
+ if (!isset($pricesetFieldCount[$sid])) {
+ $sql = "
SELECT sum(value.count) as totalCount
FROM civicrm_price_field_value value
INNER JOIN civicrm_price_field field ON ( field.id = value.price_field_id )
WHERE pset.id = %1
$where";
-$count = CRM_Core_DAO::singleValueQuery($sql, array(1 => array($sid, 'Positive')));
-$pricesetFieldCount[$sid] = ($count) ? $count : 0;
-}
+ $count = CRM_Core_DAO::singleValueQuery($sql, array(1 => array($sid, 'Positive')));
+ $pricesetFieldCount[$sid] = ($count) ? $count : 0;
+ }
-return $pricesetFieldCount[$sid];
-}
+ return $pricesetFieldCount[$sid];
+ }
/**
* @param $ids
* @return array
*/
public static function getMembershipCount($ids) {
-$queryString = "
+ $queryString = "
SELECT count( pfv.id ) AS count, pfv.id AS id
FROM civicrm_price_field_value pfv
INNER JOIN civicrm_membership_type mt ON mt.id = pfv.membership_type_id
WHERE pfv.id IN ( $ids )
GROUP BY mt.member_of_contact_id";
-$crmDAO = CRM_Core_DAO::executeQuery($queryString);
-$count = array();
+ $crmDAO = CRM_Core_DAO::executeQuery($queryString);
+ $count = array();
-while ($crmDAO->fetch()) {
-$count[$crmDAO->id] = $crmDAO->count;
-}
+ while ($crmDAO->fetch()) {
+ $count[$crmDAO->id] = $crmDAO->count;
+ }
-return $count;
-}
+ return $count;
+ }
-/**
- * Function to check if auto renew option should be shown
- *
- * @param int $priceSetId
- * Price set id.
- *
- * @return int $autoRenewOption ( 0:hide, 1:optional 2:required )
- */
-public static function checkAutoRenewForPriceSet($priceSetId) {
-// auto-renew option should be visible if membership types associated with all the fields has
-// been set for auto-renew option
-// Auto renew checkbox should be frozen if for all the membership type auto renew is required
+ /**
+ * Function to check if auto renew option should be shown
+ *
+ * @param int $priceSetId
+ * Price set id.
+ *
+ * @return int $autoRenewOption ( 0:hide, 1:optional 2:required )
+ */
+ public static function checkAutoRenewForPriceSet($priceSetId) {
+ // auto-renew option should be visible if membership types associated with all the fields has
+ // been set for auto-renew option
+ // Auto renew checkbox should be frozen if for all the membership type auto renew is required
-// get the membership type auto renew option and check if required or optional
-$query = 'SELECT mt.auto_renew, mt.duration_interval, mt.duration_unit
+ // get the membership type auto renew option and check if required or optional
+ $query = 'SELECT mt.auto_renew, mt.duration_interval, mt.duration_unit
FROM civicrm_price_field_value pfv
INNER JOIN civicrm_membership_type mt ON pfv.membership_type_id = mt.id
INNER JOIN civicrm_price_field pf ON pfv.price_field_id = pf.id
AND pf.is_active = 1
AND pfv.is_active = 1';
-$params = array(1 => array($priceSetId, 'Integer'));
+ $params = array(1 => array($priceSetId, 'Integer'));
-$dao = CRM_Core_DAO::executeQuery($query, $params);
-$autoRenewOption = 2;
-$interval = $unit = array();
-while ($dao->fetch()) {
-if (!$dao->auto_renew) {
-$autoRenewOption = 0;
-break;
-}
-if ($dao->auto_renew == 1) {
-$autoRenewOption = 1;
-}
+ $dao = CRM_Core_DAO::executeQuery($query, $params);
+ $autoRenewOption = 2;
+ $interval = $unit = array();
+ while ($dao->fetch()) {
+ if (!$dao->auto_renew) {
+ $autoRenewOption = 0;
+ break;
+ }
+ if ($dao->auto_renew == 1) {
+ $autoRenewOption = 1;
+ }
-$interval[$dao->duration_interval] = $dao->duration_interval;
-$unit[$dao->duration_unit] = $dao->duration_unit;
-}
+ $interval[$dao->duration_interval] = $dao->duration_interval;
+ $unit[$dao->duration_unit] = $dao->duration_unit;
+ }
-if (count($interval) == 1 && count($unit) == 1 && $autoRenewOption > 0) {
-return $autoRenewOption;
-}
-else {
-return 0;
-}
-}
+ if (count($interval) == 1 && count($unit) == 1 && $autoRenewOption > 0) {
+ return $autoRenewOption;
+ }
+ else {
+ return 0;
+ }
+ }
/**
* Retrieve auto renew frequency and interval
* @return array associate array of frequency interval and unit
* @static
*/
- public static function getRecurDetails($priceSetId) {
- $query = 'SELECT mt.duration_interval, mt.duration_unit
+ public static function getRecurDetails($priceSetId) {
+ $query = 'SELECT mt.duration_interval, mt.duration_unit
FROM civicrm_price_field_value pfv
INNER JOIN civicrm_membership_type mt ON pfv.membership_type_id = mt.id
INNER JOIN civicrm_price_field pf ON pfv.price_field_id = pf.id
WHERE pf.price_set_id = %1 LIMIT 1';
- $params = array(1 => array($priceSetId, 'Integer'));
- $dao = CRM_Core_DAO::executeQuery($query, $params);
- $dao->fetch();
- return array($dao->duration_interval, $dao->duration_unit);
- }
+ $params = array(1 => array($priceSetId, 'Integer'));
+ $dao = CRM_Core_DAO::executeQuery($query, $params);
+ $dao->fetch();
+ return array($dao->duration_interval, $dao->duration_unit);
+ }
/**
* @return object
*
* @param int $id
* Id of the database record.
- * @param boolean $isQuickConfig
+ * @param bool $isQuickConfigValue we want to set the is_quick_config field.
* Value we want to set the is_quick_config field.
*
* @return Object DAO object on sucess, null otherwise