class CRM_Core_Page_AJAX_RecurringEntity {
public static function updateMode() {
- if(CRM_Utils_Array::value('mode', $_REQUEST) && CRM_Utils_Array::value('entityId', $_REQUEST)){
+ if(CRM_Utils_Array::value('mode', $_REQUEST) && CRM_Utils_Array::value('entityId', $_REQUEST) && CRM_Utils_Array::value('entityTable', $_REQUEST)){
+
$finalResult = array();
$mode = CRM_Utils_Type::escape($_REQUEST['mode'], 'Integer');
$entityId = CRM_Utils_Type::escape($_REQUEST['entityId'], 'Integer');
+ $entityTable = CRM_Utils_Type::escape($_REQUEST['entityTable'], 'String');
- $sql = "UPDATE
- civicrm_recurring_entity
- SET mode = %1
- WHERE entity_id = %2 AND entity_table = 'civicrm_event'";
- $params = array(
- 1 => array($mode, 'Integer'),
- 2 => array($entityId, 'Integer')
- );
- CRM_Core_DAO::executeQuery($sql, $params);
+ if(CRM_Utils_Array::value('linkedEntityTable', $_REQUEST)){
+ $result = array();
+ $result = CRM_Event_BAO_Event::updateModeRecurringEntityForEvent($entityId, $_REQUEST['linkedEntityTable']);
+ }
+
+ $dao = new CRM_Core_DAO_RecurringEntity();
+ if(!empty($result)){
+ $dao->entity_id = $result['entityId'];
+ $dao->entityTable = $result['entityTable'];
+ }else{
+ $dao->entity_id = $entityId;
+ $dao->entityTable = $entityTable;
+ }
+ $dao->find(TRUE);
+ $dao->mode = $mode;
+ $dao->save();
$finalResult['status'] = 'Done';
}
echo json_encode($finalResult);
}
return CRM_Core_PseudoConstant::get(__CLASS__, $fieldName, $params, $context);
}
+
+ /**
+ * Update mode column in civicrm_recurring_entity table for event related tabs
+ *
+ * @params int $entityId event id
+ * @params string $linkedEntityTable Linked entity table name for this event
+ * @return array
+ */
+ public static function updateModeRecurringEntityForEvent($entityId, $linkedEntityTable){
+ $result = array();
+ if( $entityId && $linkedEntityTable ){
+ switch ($linkedEntityTable) {
+ case 'civicrm_tell_friend':
+ $params = array(
+ 'entity_id' => $entityId,
+ 'entity_table' => 'civicrm_event'
+ );
+ $defaults = array();
+ CRM_Core_DAO::commonRetrieve('CRM_Friend_DAO_Friend', $params, $defaults);
+ if(CRM_Utils_Array::value('id', $defaults)){
+ $result['entityId'] = $defaults['id'];
+ $result['entityTable'] = 'civicrm_tell_friend';
+ }
+ break;
+
+ case 'civicrm_pcp_block':
+ $params = array(
+ 'entity_id' => $entityId,
+ 'entity_table' => 'civicrm_event'
+ );
+ $defaults = array();
+ CRM_Core_DAO::commonRetrieve('CRM_PCP_DAO_PCPBlock', $params, $defaults);
+ if(CRM_Utils_Array::value('id', $defaults)){
+ $result['entityId'] = $defaults['id'];
+ $result['entityTable'] = 'civicrm_pcp_block';
+ }
+ break;
+
+ default:
+ break;
+ }
+ }
+ return $result;
+ }
}
{literal}
<script>
CRM.$(function($) {
+ //Tab and table mapper
+ var mapper = {'CRM_Event_Form_ManageEvent_EventInfo': 'civicrm_event',
+ 'CRM_Event_Form_ManageEvent_Location': 'civicrm_location',
+ 'CRM_Event_Form_ManageEvent_Fee': 'civicrm_fee',
+ 'CRM_Event_Form_ManageEvent_Registration': 'civicrm_registration',
+ 'CRM_Friend_Form_Event': 'civicrm_tell_friend',
+ 'CRM_PCP_Form_Event': 'civicrm_pcp_block'
+ };
+ //var findTellAFriend = false;
+ var form = '';
$('#crm-main-content-wrapper').on('click', 'div.crm-submit-buttons span.crm-button input[value="Save"], div.crm-submit-buttons span.crm-button input[value="Save and Done"]', function() {
- $("#repeat-mode-dailog").dialog({
- title: 'How does this change affect other repeating events in the set?',
- modal: true,
- width: '650',
- buttons: {
- Cancel: function() { //cancel
- $( this ).dialog( "close" );
- }
+ form = $(this).parents('form:first').attr('class');
+ if( form != "" && mapper.hasOwnProperty(form)){
+/* var re = new RegExp("^CRM_Friend_", "i");
+ var match = re.test(form);
+ if (match == true){
+ findTellAFriend = true;
+ }else{
+ findTellAFriend = false;
+ }
+*/
+ $("#repeat-mode-dailog").dialog({
+ title: 'How does this change affect other repeating events in the set?',
+ modal: true,
+ width: '650',
+ buttons: {
+ Cancel: function() { //cancel
+ $( this ).dialog( "close" );
+ }
+ }
+ }).dialog('open');
+ return false;
}
- }).dialog('open');
- return false;
});
$(".only-this-event").click(function(){
cj(".all-events").click(function(){
updateMode(3);
});
-
+
function updateMode(mode) {
var eventID = {/literal}{$id}{literal};
- if (eventID != "" && mode) {
+ if (eventID != "" && mode && form != "") {
var ajaxurl = CRM.url("civicrm/ajax/recurringentity/update-mode");
- var data = {mode: mode, entityId: eventID};
+ var data = {mode: mode, entityId: eventID, entityTable:'civicrm_event', linkedEntityTable:mapper[form]};
$.ajax({
dataType: "json",
data: data,