From: jitendrapurohit Date: Wed, 25 Nov 2015 06:44:51 +0000 (+0530) Subject: CRM-16761 -- Self service view, update and cancel for CiviEvent X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=4abc4ee141ef95713408dc2f6361e48a67ba2fe7;p=civicrm-core.git CRM-16761 -- Self service view, update and cancel for CiviEvent --- diff --git a/CRM/Event/Form/ManageEvent/Registration.php b/CRM/Event/Form/ManageEvent/Registration.php index c322214cfb..ef10c0b50c 100644 --- a/CRM/Event/Form/ManageEvent/Registration.php +++ b/CRM/Event/Form/ManageEvent/Registration.php @@ -808,6 +808,9 @@ class CRM_Event_Form_ManageEvent_Registration extends CRM_Event_Form_ManageEvent if (!$params['is_online_registration']) { $params['is_email_confirm'] = FALSE; } + if (!empty($params['allow_selfcancelxfer'])) { + $params['selfcancelxfer_time'] = !empty($params['selfcancelxfer_time']) ? $params['selfcancelxfer_time'] : 0; + } if (!$this->_isTemplate) { $params['registration_start_date'] = CRM_Utils_Date::processDate($params['registration_start_date'], diff --git a/CRM/Event/Form/Registration/Confirm.php b/CRM/Event/Form/Registration/Confirm.php index 161296c2bc..7cea482f67 100644 --- a/CRM/Event/Form/Registration/Confirm.php +++ b/CRM/Event/Form/Registration/Confirm.php @@ -907,6 +907,12 @@ class CRM_Event_Form_Registration_Confirm extends CRM_Event_Form_Registration { if ($participantNum = array_search('participant', $participantCount)) { unset($participantCount[$participantNum]); } + // Change $this->_values['participant'] to include additional participant values + $ids = $participantValues = array(); + $participantParams = array('id' => $participantID); + CRM_Event_BAO_Participant::getValues($participantParams, $participantValues, $ids); + $this->_values['participant'] = $participantValues[$participantID]; + $this->assign('isPrimary', 0); $this->assign('customProfile', NULL); //Additional Participant should get only it's payment information diff --git a/CRM/Event/Form/SelfSvcTransfer.php b/CRM/Event/Form/SelfSvcTransfer.php index 6b2a7294a7..65d5368c1a 100644 --- a/CRM/Event/Form/SelfSvcTransfer.php +++ b/CRM/Event/Form/SelfSvcTransfer.php @@ -166,11 +166,12 @@ class CRM_Event_Form_SelfSvcTransfer extends CRM_Core_Form { $this->_contact_email = $email; $details = array(); $details = CRM_Event_BAO_Participant::participantDetails($this->_from_participant_id); + $optionGroupId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', 'participant_role', 'id', 'name'); $query = " SELECT cpst.name as status, cov.name as role, cp.fee_level, cp.fee_amount, cp.register_date FROM civicrm_participant cp LEFT JOIN civicrm_participant_status_type cpst ON cpst.id = cp.status_id - LEFT JOIN civicrm_option_value cov ON cov.value = cp.role_id and cov.option_group_id = 13 + LEFT JOIN civicrm_option_value cov ON cov.value = cp.role_id and cov.option_group_id = {$optionGroupId} WHERE cp.id = {$this->_from_participant_id}"; $dao = CRM_Core_DAO::executeQuery($query, CRM_Core_DAO::$_nullArray); while ($dao->fetch()) { @@ -227,7 +228,7 @@ class CRM_Event_Form_SelfSvcTransfer extends CRM_Core_Form { //check that either an email or firstname+lastname is included in the form(CRM-9587) $to_contact_id = self::checkProfileComplete($fields, $errors, $self); //To check if the user is already registered for the event(CRM-2426) - self::checkRegistration($fields, $self, $to_contact_id); + self::checkRegistration($fields, $self, $to_contact_id, $errors); //return parent::formrule($fields, $files, $self); return empty($errors) ? TRUE : $errors; } @@ -269,9 +270,8 @@ class CRM_Event_Form_SelfSvcTransfer extends CRM_Core_Form { * * return @void */ - public static function checkRegistration($fields, $self, $contact_id) { + public static function checkRegistration($fields, $self, $contact_id, &$errors) { // verify whether this contact already registered for this event - $session = CRM_Core_Session::singleton(); $contact_details = CRM_Contact_BAO_Contact::getContactDetails($contact_id); $display_name = $contact_details[0]; $query = "select event_id from civicrm_participant where contact_id = " . $contact_id; @@ -282,8 +282,7 @@ class CRM_Event_Form_SelfSvcTransfer extends CRM_Core_Form { if (!empty($to_event_id)) { foreach ($to_event_id as $id) { if ($id == $self->_event_id) { - $status = $display_name . ts(" is already registered for this event"); - $session->setStatus($status, ts('Oops.'), 'alert'); + $errors['email'] = $display_name . ts(" is already registered for this event"); } } } diff --git a/CRM/Event/Form/SelfSvcUpdate.php b/CRM/Event/Form/SelfSvcUpdate.php index bd2486e47e..1e99855f1a 100644 --- a/CRM/Event/Form/SelfSvcUpdate.php +++ b/CRM/Event/Form/SelfSvcUpdate.php @@ -125,6 +125,7 @@ class CRM_Event_Form_SelfSvcUpdate extends CRM_Core_Form { $this->set('values', $this->_part_values); //fetch Event by event_id, verify that this event can still be xferred/cancelled $this->_event_id = $this->_part_values['event_id']; + $url = CRM_Utils_System::url('civicrm/event/info', "reset=1&id={$this->_event_id}&noFullMsg=true"); $this->_contact_id = $this->_part_values['participant_contact_id']; $this->assign('action', $this->_action); if ($this->_participant_id) { @@ -140,11 +141,14 @@ class CRM_Event_Form_SelfSvcUpdate extends CRM_Core_Form { $this->_contact_email = $email; $details = array(); $details = CRM_Event_BAO_Participant::participantDetails($this->_participant_id); + $optionGroupId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', 'participant_role', 'id', 'name'); + $contributionId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_ParticipantPayment', $this->_participant_id, 'contribution_id', 'participant_id'); + $this->assign('contributionId', $contributionId); $query = " SELECT cpst.name as status, cov.name as role, cp.fee_level, cp.fee_amount, cp.register_date, cp.status_id FROM civicrm_participant cp LEFT JOIN civicrm_participant_status_type cpst ON cpst.id = cp.status_id - LEFT JOIN civicrm_option_value cov ON cov.value = cp.role_id and cov.option_group_id = 13 + LEFT JOIN civicrm_option_value cov ON cov.value = cp.role_id and cov.option_group_id = {$optionGroupId} WHERE cp.id = {$this->_participant_id}"; $dao = CRM_Core_DAO::executeQuery($query, CRM_Core_DAO::$_nullArray); while ($dao->fetch()) { @@ -157,7 +161,8 @@ class CRM_Event_Form_SelfSvcUpdate extends CRM_Core_Form { //verify participant status is still Registered if ($details['status'] != "Registered") { $status = "You are no longer registered for " . $this->_event_title; - $session->setStatus($status, ts('Event status error.'), 'alert'); + CRM_Core_Session::setStatus($status, ts('Event status error.'), 'alert'); + CRM_Utils_System::redirect($url); } $query = "select start_date as start, selfcancelxfer_time as time from civicrm_event where id = " . $this->_event_id; $dao = CRM_Core_DAO::executeQuery($query, CRM_Core_DAO::$_nullArray); @@ -165,15 +170,21 @@ class CRM_Event_Form_SelfSvcUpdate extends CRM_Core_Form { $time_limit = $dao->time; $start_date = $dao->start; } + $start_time = new Datetime($start_date); + $timenow = new Datetime(); + if (!empty($start_time) && $start_time < $timenow) { + $status = ts("The event has been started, cannot transfer or cancel this event"); + $session->setStatus($status, ts('Oops.'), 'alert'); + CRM_Utils_System::redirect($url); + } if (!empty($time_limit) && $time_limit > 0) { - $timenow = new Datetime(""); - $start_time = new Datetime($start_date); $interval = $timenow->diff($start_time); $days = $interval->format('%d'); $hours = $interval->format('%h'); if ($hours <= $time_limit && $days < 1) { - $status = ts("Less than ") . $time_limit . ts(" hours to start time, cannot transfer or cancel this event"); + $status = ts("Less than %1 hours to start time, cannot transfer or cancel this event", array(1 => $time_limit)); $session->setStatus($status, ts('Oops.'), 'alert'); + CRM_Utils_System::redirect($url); } } $this->assign('details', $details); @@ -328,6 +339,8 @@ class CRM_Event_Form_SelfSvcUpdate extends CRM_Core_Form { $statusMsg = ts('Event registration information for %1 has been updated.', array(1 => $this->_contact_name)); $statusMsg .= ' ' . ts('A cancellation email has been sent to %1.', array(1 => $this->_contact_email)); CRM_Core_Session::setStatus($statusMsg, ts('Saved'), 'success'); + $url = CRM_Utils_System::url('civicrm/event/info', "reset=1&id={$this->_event_id}&noFullMsg=true"); + CRM_Utils_System::redirect($url); } } diff --git a/CRM/Event/xml/Menu/Event.xml b/CRM/Event/xml/Menu/Event.xml index 1e17e85dd0..277f48894c 100644 --- a/CRM/Event/xml/Menu/Event.xml +++ b/CRM/Event/xml/Menu/Event.xml @@ -260,7 +260,6 @@ Self Service Update CRM_Event_Form_SelfSvcUpdate 1 - true 1 880 @@ -270,7 +269,6 @@ CRM_Event_Form_SelfSvcTransfer 1 1 - true 890 diff --git a/CRM/Upgrade/4.7.beta1.msg_template/civicrm_msg_template.tpl b/CRM/Upgrade/4.7.beta1.msg_template/civicrm_msg_template.tpl index 51f6d364fc..9189f0b384 100644 --- a/CRM/Upgrade/4.7.beta1.msg_template/civicrm_msg_template.tpl +++ b/CRM/Upgrade/4.7.beta1.msg_template/civicrm_msg_template.tpl @@ -1 +1,56 @@ -{* TO DO: Add upgrade logic to update event_online msg templates and insert participant_transferred and cancelled msg templates. *} \ No newline at end of file +{php} + $dir = SMARTY_DIR . '/../../CRM/Upgrade/4.7.beta1.msg_template/message_templates'; + $templates = array(); + $ovNames = array( + 'event' => array( + 'participant_transferred' => ts('Events - Registration Transferred Notice', array('escape' => 'sql')), + ), + ); + + $this->assign('ovNames', $ovNames); + $this->assign('dir', $dir); + + foreach (preg_grep('/\.tpl$/', scandir($dir)) as $filename) { + $parts = explode('_', basename($filename, '.tpl')); + $templates[] = array('type' => array_pop($parts), 'name' => implode('_', $parts), 'filename' => "$dir/$filename"); + } + $this->assign('templates', $templates); +{/php} +{foreach from=$ovNames key=name item=ignore} + SELECT @tpl_ogid_{$name} := MAX(id) FROM civicrm_option_group WHERE name = 'msg_tpl_workflow_{$name}'; + SELECT @max_val := MAX(ROUND(op.value)) FROM civicrm_option_value op WHERE op.option_group_id = @tpl_ogid_{$name}; + SELECT @max_wt := max(weight) from civicrm_option_value where option_group_id=@tpl_ogid_{$name}; +{/foreach} + +INSERT INTO civicrm_option_value + (option_group_id, name, {localize field='label'}label{/localize}, value, weight) VALUES +{foreach from=$ovNames key=gName item=ovs name=for_groups} +{foreach from=$ovs key=vName item=label name=for_values} + (@tpl_ogid_{$gName}, '{$vName}', {localize}'{$label}'{/localize}, (SELECT @max_val := @max_val+1), (SELECT @max_wt := @max_wt+1)) {if $smarty.foreach.for_groups.last and $smarty.foreach.for_values.last};{else},{/if} +{/foreach} +{/foreach} + +{foreach from=$ovNames key=gName item=ovs} +{foreach from=$ovs key=vName item=label} + SELECT @tpl_ovid_{$vName} := MAX(id) FROM civicrm_option_value WHERE option_group_id = @tpl_ogid_{$gName} AND name = '{$vName}'; +{/foreach} +{/foreach} + +INSERT INTO civicrm_msg_template + (msg_title, msg_subject, msg_text, msg_html, workflow_id, is_default, is_reserved) VALUES +{foreach from=$ovNames key=gName item=ovs name=for_groups} +{foreach from=$ovs key=vName item=title name=for_values} + {fetch assign=subject file="`$smarty.const.SMARTY_DIR`/../../CRM/Upgrade/4.7.beta1.msg_template/message_templates/`$vName`_subject.tpl"} + {fetch assign=text file="`$smarty.const.SMARTY_DIR`/../../CRM/Upgrade/4.7.beta1.msg_template/message_templates/`$vName`_text.tpl"} + {fetch assign=html file="`$smarty.const.SMARTY_DIR`/../../CRM/Upgrade/4.7.beta1.msg_template/message_templates/`$vName`_html.tpl"} + ('{$title}', '{$subject|escape:"quotes"}', '{$text|escape:"quotes"}', '{$html|escape:"quotes"}', @tpl_ovid_{$vName}, 1, 0), + ('{$title}', '{$subject|escape:"quotes"}', '{$text|escape:"quotes"}', '{$html|escape:"quotes"}', @tpl_ovid_{$vName}, 0, 1) {if $smarty.foreach.for_groups.last and $smarty.foreach.for_values.last};{else},{/if} +{/foreach} +{/foreach} + +{foreach from=$templates item=tpl} + {fetch assign=content file=$tpl.filename} + SELECT @workflow_id := MAX(id) FROM civicrm_option_value WHERE name = '{$tpl.name}'; + SELECT @content := msg_{$tpl.type} FROM civicrm_msg_template WHERE workflow_id = @workflow_id AND is_reserved = 1 LIMIT 1; + UPDATE civicrm_msg_template SET msg_{$tpl.type} = '{$content|escape:"quotes"}' WHERE workflow_id = @workflow_id AND (is_reserved = 1 OR (is_default = 1 AND msg_{$tpl.type} = @content)); +{/foreach} diff --git a/templates/CRM/Event/Form/SelfSvcUpdate.tpl b/templates/CRM/Event/Form/SelfSvcUpdate.tpl index 322fccf121..463fde90fa 100644 --- a/templates/CRM/Event/Form/SelfSvcUpdate.tpl +++ b/templates/CRM/Event/Form/SelfSvcUpdate.tpl @@ -26,17 +26,17 @@
{include file="CRM/common/formButtons.tpl" location="top"}
- + - + - + - + - +
{$form.email.label}{$form.email.html}{$form.email.html}
{$form.participant.label}{$form.participant.html}{$form.participant.html}
{$form.action.label}{$form.action.html}{$form.action.html}
@@ -52,3 +52,16 @@
ParticipantEventFee LevelFee AmtReg DateStatusRole
{include file="CRM/common/formButtons.tpl" location="bottom"}
+{literal} + +{/literal}