Skip to content
Snippets Groups Projects
Commit cca54422 authored by Kurund Jalmi's avatar Kurund Jalmi
Browse files

Merge pull request #798 from pradpnayak/CRM-12510

-- fixed for CRM-12510
parents 25d378a1 c6914066
Branches
Tags
No related merge requests found
......@@ -607,8 +607,9 @@ class CRM_Contribute_BAO_ContributionPage extends CRM_Contribute_DAO_Contributio
'contribution_page_id' => $copy->id,
));
//copy option group and values
$copy->default_amount_id = CRM_Core_BAO_OptionGroup::copyValue('contribution', $id, $copy->id, CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionPage', $id, 'default_amount_id'));
//copy price sets
CRM_Price_BAO_Set::copyPriceSet('civicrm_contribution_page', $id, $copy->id);
$copyTellFriend = &CRM_Core_DAO::copyGeneric('CRM_Friend_DAO_Friend', array(
'entity_id' => $id,
'entity_table' => 'civicrm_contribution_page',
......
......@@ -144,93 +144,5 @@ class CRM_Core_BAO_OptionGroup extends CRM_Core_DAO_OptionGroup {
$optionGroup->find(TRUE);
return $optionGroup->name;
}
/**
* Function to copy the option group and values
*
* @param String $component - component page for which custom
* option group and values need to be copied
* @param int $fromId - component page id on which
* basis copy is to be made
* @param int $toId - component page id to be copied onto
* @param int $defaultId - default custom value id on the
* component page
* @param String $discountSuffix - discount suffix for the discounted
* option group
*
* @return int $id - default custom value id for the
* copied component page
*
* @access public
* @static
*/
static function copyValue($component, $fromId, $toId, $defaultId = FALSE, $discountSuffix = NULL) {
$page = '_page';
if ($component == 'event') {
//fix for CRM-3391.
//as for event we remove 'page' from group name.
$page = NULL;
}
elseif ($component == 'price') {
$page = '_field';
}
$fromGroupName = 'civicrm_' . $component . $page . '.amount.' . $fromId . $discountSuffix;
$toGroupName = 'civicrm_' . $component . $page . '.amount.' . $toId . $discountSuffix;
$optionGroupId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup',
$fromGroupName,
'id',
'name'
);
if ($optionGroupId) {
$copyOptionGroup = &CRM_Core_DAO::copyGeneric('CRM_Core_DAO_OptionGroup',
array('name' => $fromGroupName),
array('name' => $toGroupName)
);
$copyOptionValue = &CRM_Core_DAO::copyGeneric('CRM_Core_DAO_OptionValue',
array('option_group_id' => $optionGroupId),
array('option_group_id' => $copyOptionGroup->id)
);
if ($discountSuffix) {
$copyDiscount =& CRM_Core_DAO::copyGeneric( 'CRM_Core_DAO_Discount',
array(
'entity_id' => $fromId,
'entity_table' => 'civicrm_' . $component,
'option_group_id' => $optionGroupId,
),
array(
'entity_id' => $toId,
'option_group_id' => $copyOptionGroup->id,
)
);
}
if ($defaultId) {
$query = "
SELECT second.id default_id
FROM civicrm_option_value first, civicrm_option_value second
WHERE second.option_group_id =%1
AND first.option_group_id =%2
AND first.weight = second.weight
AND first.id =%3
";
$params = array(1 => array($copyOptionGroup->id, 'Int'),
2 => array($optionGroupId, 'Int'),
3 => array($defaultId, 'Int'),
);
$dao = CRM_Core_DAO::executeQuery($query, $params);
while ($dao->fetch()) {
$id = $dao->default_id;
}
return $id;
}
return FALSE;
}
}
}
......@@ -866,23 +866,7 @@ WHERE civicrm_event.is_active = 1
$fieldsFix
);
}
$priceSetId = CRM_Price_BAO_Set::getFor('civicrm_event', $id);
if ($priceSetId) {
$isQuickConfig = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_Set', $priceSetId, 'is_quick_config');
if(!$isQuickConfig) {
$copyPriceSet = &CRM_Price_BAO_Set::copy($priceSetId);
CRM_Price_BAO_Set::addTo('civicrm_event', $copyEvent->id, $copyPriceSet->id);
} else {
$copyPriceSet = &CRM_Core_DAO::copyGeneric('CRM_Price_DAO_SetEntity',
array(
'entity_id' => $id,
'entity_table' => 'civicrm_event',
),
array('entity_id' => $copyEvent->id)
);
}
}
CRM_Price_BAO_Set::copyPriceSet('civicrm_event', $id, $copyEvent->id);
$copyUF = &CRM_Core_DAO::copyGeneric('CRM_Core_DAO_UFJoin',
array(
'entity_id' => $id,
......
......@@ -334,19 +334,6 @@ class CRM_Event_Form_ManageEvent_EventInfo extends CRM_Event_Form_ManageEvent {
// now that we have the event’s id, do some more template-based stuff
if (CRM_Utils_Array::value('template_id', $params)) {
CRM_Event_BAO_Event::copy($params['template_id'], $event, TRUE);
// copy price sets if any
$priceSetId = CRM_Price_BAO_Set::getFor('civicrm_event', $params['template_id']);
if ($priceSetId) {
$isQuickConfig = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_Set',
$priceSetId,
'is_quick_config'
);
if ($isQuickConfig) {
$copyPriceSet = &CRM_Price_BAO_Set::copy($priceSetId);
$priceSetId = $copyPriceSet->id;
}
CRM_Price_BAO_Set::addTo('civicrm_event', $event->id, $priceSetId);
}
}
$this->set('id', $event->id);
......
......@@ -1178,5 +1178,51 @@ WHERE ps.id = %1
return false;
}
/*
* Copy priceSet when event/contibution page is copied
*
* @params string $baoName BAO name
* @params int $id old event/contribution page id
* @params int $newId newly created event/contribution page id
*
*/
static function copyPriceSet($baoName, $id, $newId) {
$priceSetId = CRM_Price_BAO_Set::getFor($baoName, $id);
if ($priceSetId) {
$isQuickConfig = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_Set', $priceSetId, 'is_quick_config');
if($isQuickConfig) {
$copyPriceSet = &CRM_Price_BAO_Set::copy($priceSetId);
CRM_Price_BAO_Set::addTo($baoName, $newId, $copyPriceSet->id);
}
else {
$copyPriceSet = &CRM_Core_DAO::copyGeneric('CRM_Price_DAO_SetEntity',
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_Set::copy($setId);
$copyDiscount = &CRM_Core_DAO::copyGeneric(
'CRM_Core_DAO_Discount',
array(
'id' => $discountId,
),
array(
'entity_id' => $newId,
'price_set_id' => $copyPriceSet->id,
)
);
}
}
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment