Merge pull request #16008 from civicrm/5.20
[civicrm-core.git] / CRM / Event / Form / ManageEvent / Delete.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
bc77d7c0 4 | Copyright CiviCRM LLC. All rights reserved. |
6a488035 5 | |
bc77d7c0
TO
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
6a488035 9 +--------------------------------------------------------------------+
d25dd0ee 10 */
6a488035
TO
11
12/**
13 *
14 * @package CRM
ca5cec67 15 * @copyright CiviCRM LLC https://civicrm.org/licensing
6a488035
TO
16 */
17
18/**
3bdf1f3a 19 * This class is to build the form for Deleting Group.
6a488035
TO
20 */
21class CRM_Event_Form_ManageEvent_Delete extends CRM_Event_Form_ManageEvent {
22
23 /**
66f9e52b 24 * Page title.
6a488035
TO
25 *
26 * @var string
6a488035
TO
27 */
28 protected $_title;
29
30 /**
66f9e52b 31 * Set variables up before form is built.
6a488035
TO
32 */
33 public function preProcess() {
34 parent::preProcess();
35
36 if ($this->_isTemplate) {
37 $this->_title = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $this->_id, 'template_title');
38 }
39 else {
40 $this->_title = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $this->_id, 'title');
41 }
42
43 if (!CRM_Event_BAO_Event::checkPermission($this->_id, CRM_Core_Permission::DELETE)) {
0499b0ad 44 CRM_Core_Error::fatal(ts('You do not have permission to access this page.'));
6a488035
TO
45 }
46 }
47
48 /**
66f9e52b 49 * Build the form object.
6a488035
TO
50 */
51 public function buildQuickForm() {
52 $this->assign('title', $this->_title);
53
be2fb01f
CW
54 $buttons = [
55 [
6a488035
TO
56 'type' => 'next',
57 'name' => $this->_isTemplate ? ts('Delete Event Template') : ts('Delete Event'),
58 'isDefault' => TRUE,
be2fb01f
CW
59 ],
60 [
6a488035
TO
61 'type' => 'cancel',
62 'name' => ts('Cancel'),
be2fb01f
CW
63 ],
64 ];
6a488035
TO
65 $this->addButtons($buttons);
66 }
67
68 /**
66f9e52b 69 * Process the form when submitted.
6a488035
TO
70 */
71 public function postProcess() {
72 $participant = new CRM_Event_DAO_Participant();
73 $participant->event_id = $this->_id;
74
75 if ($participant->find()) {
76 $searchURL = CRM_Utils_System::url('civicrm/event/search', 'reset=1');
77 CRM_Core_Session::setStatus(ts('This event cannot be deleted because there are participant records linked to it. If you want to delete this event, you must first find the participants linked to this event and delete them. You can use use <a href=\'%1\'> CiviEvent >> Find Participants page </a>.',
be2fb01f 78 [1 => $searchURL]
353ffa53 79 ), ts('Deletion Error'), 'error');
6a488035
TO
80 return;
81 }
82 CRM_Event_BAO_Event::del($this->_id);
83 if ($this->_isTemplate) {
be2fb01f 84 CRM_Core_Session::setStatus(ts("'%1' has been deleted.", [1 => $this->_title]), ts('Template Deleted'), 'success');
6a488035
TO
85 CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/admin/eventTemplate', 'reset=1'));
86 }
87 else {
be2fb01f 88 CRM_Core_Session::setStatus(ts("'%1' has been deleted.", [1 => $this->_title]), ts('Event Deleted'), 'success');
6a488035
TO
89 }
90 }
96025800 91
6a488035 92}