CRM-16761 -- Self service view, update and cancel for CiviEvent
authorjitendrapurohit <jitendra.purohit@webaccessglobal.com>
Wed, 25 Nov 2015 06:44:51 +0000 (12:14 +0530)
committerjitendrapurohit <jitendra.purohit@webaccessglobal.com>
Wed, 25 Nov 2015 06:44:51 +0000 (12:14 +0530)
CRM/Event/Form/ManageEvent/Registration.php
CRM/Event/Form/Registration/Confirm.php
CRM/Event/Form/SelfSvcTransfer.php
CRM/Event/Form/SelfSvcUpdate.php
CRM/Event/xml/Menu/Event.xml
CRM/Upgrade/4.7.beta1.msg_template/civicrm_msg_template.tpl
templates/CRM/Event/Form/SelfSvcUpdate.tpl

index c322214cfb8cd693a65a2fcde9b4c6a680fea3ae..ef10c0b50c3f40dc54bf862ebd0ef55c8dc46dd5 100644 (file)
@@ -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'],
index 161296c2bc6baf101c60291fcc95dc58ebba050d..7cea482f6738fda87d55c2ce4cbb6c8d363440c9 100644 (file)
@@ -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
index 6b2a7294a700707d3a69dffd86c9941522d1f7ca..65d5368c1a887563b714fe5a921cfb950dd7e0ea 100644 (file)
@@ -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");
         }
       }
     }
index bd2486e47e246a48963130c2136bfb719a8925f8..1e99855f1a1629c700f4c0da124906e096a47213 100644 (file)
@@ -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);
   }
 
 }
index 1e17e85dd08e31d90f27ba5b9a79ce3579bcd651..277f48894c6e36a3c85a8c810803786830c0860c 100644 (file)
      <title>Self Service Update</title>
      <page_callback>CRM_Event_Form_SelfSvcUpdate</page_callback>
      <access_callback>1</access_callback>
-     <is_public>true</is_public>
      <page_type>1</page_type>
      <weight>880</weight>
   </item>
      <page_callback>CRM_Event_Form_SelfSvcTransfer</page_callback>
      <page_type>1</page_type>
      <access_callback>1</access_callback>
-     <is_public>true</is_public>
      <weight>890</weight>
   </item>
   <item>
index 51f6d364fc6a059700eb7ab21a49afdae02a11ec..9189f0b3846a0afd41a6dc8a56ad322d91201120 100644 (file)
@@ -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}
index 322fccf121b49c99c5f8d4d579a9f846846059d0..463fde90fa0db2428dda7f91d7071a25e8e7ae1d 100644 (file)
 <div class="crm-submit-buttons">{include file="CRM/common/formButtons.tpl" location="top"}</div>
 <div>
     <table class="form-layout">
-         <tr class="crm-selfsvcupdate-form-block-email">
+        <tr class="crm-selfsvcupdate-form-block-email">
           <td class="label">{$form.email.label}</td>
-            <td>{$form.email.html}</td>
+          <td>{$form.email.html}</td>
         </tr>
-       <tr class="crm-selfsvcupdate-form-block-participant">
+        <tr class="crm-selfsvcupdate-form-block-participant">
           <td class="label">{$form.participant.label}</td>
-            <td>{$form.participant.html}</td>
+          <td>{$form.participant.html}</td>
         </tr>
           <tr class="crm-selfsvcupdate-form-block-participant">
             <td class="label">{$form.action.label}</td>
-             <td>{$form.action.html}</td>
+            <td>{$form.action.html}</td>
         </tr>
       <table class="crm-selfsvcupdate-form-details"><col width="30"><col width="50"><col width="20"><col width="10"><col width="10"><col width="12"><col width="10">
          <tr><th>Participant</th><th>Event</th><th>Fee Level</th><th>Fee Amt</th><th>Reg Date</th><th>Status</th><th>Role</th>
    </table>
  <div class="crm-submit-buttons">{include file="CRM/common/formButtons.tpl" location="bottom"}</div>
 </div>
+{literal}
+<script type="text/javascript">
+  var contributionID = {/literal}'{$contributionId}'{literal};
+  CRM.$(function($) {
+    $('#action').on('change', function() {
+      selected = $(this).find("option:selected").text();
+      if (selected == 'Cancel' && contributionID) {
+        CRM.alert(ts('Cancellations are not refundable.'), 'Warning', 'alert');
+      }
+    });
+  });
+</script>
+{/literal}