CRM-19213 fix payment_instrument_id on event & add first test (shell really)
[civicrm-core.git] / CRM / Event / Form / ManageEvent / Delete.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
7e9e8871 4 | CiviCRM version 4.7 |
6a488035 5 +--------------------------------------------------------------------+
fa938177 6 | Copyright CiviCRM LLC (c) 2004-2016 |
6a488035
TO
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
13 | |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
18 | |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
d25dd0ee 26 */
6a488035
TO
27
28/**
29 *
30 * @package CRM
fa938177 31 * @copyright CiviCRM LLC (c) 2004-2016
6a488035
TO
32 */
33
34/**
3bdf1f3a 35 * This class is to build the form for Deleting Group.
6a488035
TO
36 */
37class CRM_Event_Form_ManageEvent_Delete extends CRM_Event_Form_ManageEvent {
38
39 /**
66f9e52b 40 * Page title.
6a488035
TO
41 *
42 * @var string
6a488035
TO
43 */
44 protected $_title;
45
46 /**
66f9e52b 47 * Set variables up before form is built.
6a488035
TO
48 */
49 public function preProcess() {
50 parent::preProcess();
51
52 if ($this->_isTemplate) {
53 $this->_title = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $this->_id, 'template_title');
54 }
55 else {
56 $this->_title = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $this->_id, 'title');
57 }
58
59 if (!CRM_Event_BAO_Event::checkPermission($this->_id, CRM_Core_Permission::DELETE)) {
0499b0ad 60 CRM_Core_Error::fatal(ts('You do not have permission to access this page.'));
6a488035
TO
61 }
62 }
63
64 /**
66f9e52b 65 * Build the form object.
6a488035
TO
66 */
67 public function buildQuickForm() {
68 $this->assign('title', $this->_title);
69
70 $buttons = array(
71 array(
72 'type' => 'next',
73 'name' => $this->_isTemplate ? ts('Delete Event Template') : ts('Delete Event'),
74 'isDefault' => TRUE,
75 ),
76 array(
77 'type' => 'cancel',
78 'name' => ts('Cancel'),
79 ),
80 );
81 $this->addButtons($buttons);
82 }
83
84 /**
66f9e52b 85 * Process the form when submitted.
6a488035
TO
86 */
87 public function postProcess() {
88 $participant = new CRM_Event_DAO_Participant();
89 $participant->event_id = $this->_id;
90
91 if ($participant->find()) {
92 $searchURL = CRM_Utils_System::url('civicrm/event/search', 'reset=1');
93 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>.',
353ffa53
TO
94 array(1 => $searchURL)
95 ), ts('Deletion Error'), 'error');
6a488035
TO
96 return;
97 }
98 CRM_Event_BAO_Event::del($this->_id);
99 if ($this->_isTemplate) {
c7692a87 100 CRM_Core_Session::setStatus(ts("'%1' has been deleted.", array(1 => $this->_title)), ts('Template Deleted'), 'success');
6a488035
TO
101 CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/admin/eventTemplate', 'reset=1'));
102 }
103 else {
c7692a87 104 CRM_Core_Session::setStatus(ts("'%1' has been deleted.", array(1 => $this->_title)), ts('Event Deleted'), 'success');
6a488035
TO
105 }
106 }
96025800 107
6a488035 108}