Merge pull request #18400 from aydun/class_api_tweak_2
[civicrm-core.git] / CRM / Event / Form / ManageEvent / Delete.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
5 | |
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 |
9 +--------------------------------------------------------------------+
10 */
11
12 /**
13 *
14 * @package CRM
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
16 */
17
18 /**
19 * This class is to build the form for Deleting Group.
20 */
21 class CRM_Event_Form_ManageEvent_Delete extends CRM_Event_Form_ManageEvent {
22
23 /**
24 * Page title.
25 *
26 * @var string
27 */
28 protected $_title;
29
30 /**
31 * Set variables up before form is built.
32 *
33 * @throws \CiviCRM_API3_Exception
34 * @throws \CRM_Core_Exception
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
46 if (!CRM_Event_BAO_Event::checkPermission($this->_id, CRM_Core_Permission::DELETE)) {
47 CRM_Core_Error::statusBounce(ts('You do not have permission to access this page.'));
48 }
49 }
50
51 /**
52 * Build the form object.
53 */
54 public function buildQuickForm() {
55 $this->assign('title', $this->_title);
56
57 $buttons = [
58 [
59 'type' => 'next',
60 'name' => $this->_isTemplate ? ts('Delete Event Template') : ts('Delete Event'),
61 'isDefault' => TRUE,
62 ],
63 [
64 'type' => 'cancel',
65 'name' => ts('Cancel'),
66 ],
67 ];
68 $this->addButtons($buttons);
69 }
70
71 /**
72 * Process the form when submitted.
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>.',
81 [1 => $searchURL]
82 ), ts('Deletion Error'), 'error');
83 return;
84 }
85 CRM_Event_BAO_Event::del($this->_id);
86 if ($this->_isTemplate) {
87 CRM_Core_Session::setStatus(ts("'%1' has been deleted.", [1 => $this->_title]), ts('Template Deleted'), 'success');
88 CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/admin/eventTemplate', 'reset=1'));
89 }
90 else {
91 CRM_Core_Session::setStatus(ts("'%1' has been deleted.", [1 => $this->_title]), ts('Event Deleted'), 'success');
92 }
93 }
94
95 }