Skip to content

Commit

Permalink
Merge pull request #7297 from jitendrapurohit/selfservice
Browse files Browse the repository at this point in the history
CRM-16761 -- Self service view, update and cancel for CiviEvent
  • Loading branch information
davecivicrm committed Nov 27, 2015
2 parents 8b60bc7 + 9dddcd7 commit 0eb9c23
Show file tree
Hide file tree
Showing 10 changed files with 310 additions and 19 deletions.
3 changes: 3 additions & 0 deletions CRM/Event/Form/ManageEvent/Registration.php
Expand Up @@ -808,6 +808,9 @@ public function postProcess() {
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'],
Expand Down
6 changes: 6 additions & 0 deletions CRM/Event/Form/Registration/Confirm.php
Expand Up @@ -907,6 +907,12 @@ public function postProcess() {
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
Expand Down
11 changes: 5 additions & 6 deletions CRM/Event/Form/SelfSvcTransfer.php
Expand Up @@ -166,11 +166,12 @@ public function preProcess() {
$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()) {
Expand Down Expand Up @@ -227,7 +228,7 @@ public static function formRule($fields, $files, $self) {
//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;
}
Expand Down Expand Up @@ -269,9 +270,8 @@ public static function checkProfileComplete($fields, &$errors, $self) {
*
* 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;
Expand All @@ -282,8 +282,7 @@ public static function checkRegistration($fields, $self, $contact_id) {
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");
}
}
}
Expand Down
23 changes: 18 additions & 5 deletions CRM/Event/Form/SelfSvcUpdate.php
Expand Up @@ -125,6 +125,7 @@ public function preProcess() {
$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) {
Expand All @@ -140,11 +141,14 @@ public function preProcess() {
$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()) {
Expand All @@ -157,23 +161,30 @@ public function preProcess() {
//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);
while ($dao->fetch()) {
$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);
Expand Down Expand Up @@ -328,6 +339,8 @@ public function cancelParticipant($params) {
$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);
}

}
2 changes: 0 additions & 2 deletions CRM/Event/xml/Menu/Event.xml
Expand Up @@ -260,7 +260,6 @@
<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>
Expand All @@ -270,7 +269,6 @@
<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>
Expand Down
57 changes: 56 additions & 1 deletion 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. *}
{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}
@@ -0,0 +1,146 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title></title>
</head>
<body>

{capture assign=headerStyle}colspan="2" style="text-align: left; padding: 4px; border-bottom: 1px solid #999; background-color: #eee;"{/capture}
{capture assign=labelStyle }style="padding: 4px; border-bottom: 1px solid #999; background-color: #f7f7f7;"{/capture}
{capture assign=valueStyle }style="padding: 4px; border-bottom: 1px solid #999;"{/capture}

<center>
<table width="620" border="0" cellpadding="0" cellspacing="0" id="crm-event_receipt" style="font-family: Arial, Verdana, sans-serif; text-align: left;">

<!-- BEGIN HEADER -->
<!-- You can add table row(s) here with logo or other header elements -->
<!-- END HEADER -->

<!-- BEGIN CONTENT -->

<tr>
<td>
<p>{ts 1=$contact.display_name}Dear %1{/ts},</p>
<p>{ts 1=$to_participant}Your Event Registration has been Transferred to %1.{/ts}</p>
</td>
</tr>
<tr>
<td>
<table style="border: 1px solid #999; margin: 1em 0em 1em; border-collapse: collapse; width:100%;">
<tr>
<th {$headerStyle}>
{ts}Event Information and Location{/ts}
</th>
</tr>
<tr>
<td colspan="2" {$valueStyle}>
{$event.event_title}<br />
{$event.event_start_date|crmDate}{if $event.event_end_date}-{if $event.event_end_date|date_format:"%Y%m%d" == $event.event_start_date|date_format:"%Y%m%d"}{$event.event_end_date|crmDate:0:1}{else}{$event.event_end_date|crmDate}{/if}{/if}
</td>
</tr>
<tr>
<td {$labelStyle}>
{ts}Participant Role{/ts}:
</td>
<td {$valueStyle}>
{$participant.role}
</td>
</tr>

{if $isShowLocation}
<tr>
<td colspan="2" {$valueStyle}>
{if $event.location.address.1.name}
{$event.location.address.1.name}<br />
{/if}
{if $event.location.address.1.street_address}
{$event.location.address.1.street_address}<br />
{/if}
{if $event.location.address.1.supplemental_address_1}
{$event.location.address.1.supplemental_address_1}<br />
{/if}
{if $event.location.address.1.supplemental_address_2}
{$event.location.address.1.supplemental_address_2}<br />
{/if}
{if $event.location.address.1.city}
{$event.location.address.1.city} {$event.location.address.1.postal_code}
{if $event.location.address.1.postal_code_suffix}
- {$event.location.address.1.postal_code_suffix}
{/if}
{/if}
</td>
</tr>
{/if}

{if $event.location.phone.1.phone || $event.location.email.1.email}
<tr>
<td colspan="2" {$labelStyle}>
{ts}Event Contacts:{/ts}
</td>
</tr>
{foreach from=$event.location.phone item=phone}
{if $phone.phone}
<tr>
<td {$labelStyle}>
{if $phone.phone_type}{$phone.phone_type_display}{else}{ts}Phone{/ts}{/if}
</td>
<td {$valueStyle}>
{$phone.phone}
</td>
</tr>
{/if}
{/foreach}
{foreach from=$event.location.email item=eventEmail}
{if $eventEmail.email}
<tr>
<td {$labelStyle}>
{ts}Email{/ts}
</td>
<td {$valueStyle}>
{$eventEmail.email}
</td>
</tr>
{/if}
{/foreach}
{/if}

{if $contact.email}
<tr>
<th {$headerStyle}>
{ts}Registered Email{/ts}
</th>
</tr>
<tr>
<td colspan="2" {$valueStyle}>
{$contact.email}
</td>
</tr>
{/if}

{if $register_date}
<tr>
<td {$labelStyle}>
{ts}Registration Date{/ts}
</td>
<td {$valueStyle}>
{$participant.register_date|crmDate}
</td>
</tr>
{/if}

</table>
</td>
</tr>

<tr>
<td>
<p>{ts 1=$domain.phone 2=$domain.email}Please contact us at %1 or send email to %2 if you have questions.{/ts}</p>
</td>
</tr>

</table>
</center>

</body>
</html>
@@ -0,0 +1 @@
{ts 1=$event.event_title}Event Registration Transferred for %1{/ts}

0 comments on commit 0eb9c23

Please sign in to comment.