Merge pull request #23226 from MegaphoneJon/individual-employers
[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.
beb414cc 32 *
33 * @throws \CiviCRM_API3_Exception
34 * @throws \CRM_Core_Exception
6a488035
TO
35 */
36 public function preProcess() {
37 parent::preProcess();
38
39 if ($this->_isTemplate) {
40 $this->_title = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $this->_id, 'template_title');
41 }
42 else {
43 $this->_title = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $this->_id, 'title');
44 }
45
f6807038 46 if (!CRM_Event_BAO_Event::checkPermission((int) $this->_id, CRM_Core_Permission::DELETE)) {
beb414cc 47 CRM_Core_Error::statusBounce(ts('You do not have permission to access this page.'));
6a488035
TO
48 }
49 }
50
51 /**
66f9e52b 52 * Build the form object.
6a488035
TO
53 */
54 public function buildQuickForm() {
55 $this->assign('title', $this->_title);
56
be2fb01f
CW
57 $buttons = [
58 [
6a488035
TO
59 'type' => 'next',
60 'name' => $this->_isTemplate ? ts('Delete Event Template') : ts('Delete Event'),
61 'isDefault' => TRUE,
be2fb01f
CW
62 ],
63 [
6a488035
TO
64 'type' => 'cancel',
65 'name' => ts('Cancel'),
be2fb01f
CW
66 ],
67 ];
6a488035
TO
68 $this->addButtons($buttons);
69 }
70
71 /**
66f9e52b 72 * Process the form when submitted.
6a488035
TO
73 */
74 public function postProcess() {
75 $participant = new CRM_Event_DAO_Participant();
76 $participant->event_id = $this->_id;
77
78 if ($participant->find()) {
79 $searchURL = CRM_Utils_System::url('civicrm/event/search', 'reset=1');
80 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 81 [1 => $searchURL]
353ffa53 82 ), ts('Deletion Error'), 'error');
6a488035
TO
83 return;
84 }
85 CRM_Event_BAO_Event::del($this->_id);
86 if ($this->_isTemplate) {
be2fb01f 87 CRM_Core_Session::setStatus(ts("'%1' has been deleted.", [1 => $this->_title]), ts('Template Deleted'), 'success');
6a488035
TO
88 CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/admin/eventTemplate', 'reset=1'));
89 }
90 else {
be2fb01f 91 CRM_Core_Session::setStatus(ts("'%1' has been deleted.", [1 => $this->_title]), ts('Event Deleted'), 'success');
6a488035
TO
92 }
93 }
96025800 94
6a488035 95}