further comment fixes
[civicrm-core.git] / CRM / Admin / Form / PaymentProcessorType.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
7e9e8871 4 | CiviCRM version 4.7 |
6a488035 5 +--------------------------------------------------------------------+
e7112fa7 6 | Copyright CiviCRM LLC (c) 2004-2015 |
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
e7112fa7 31 * @copyright CiviCRM LLC (c) 2004-2015
6a488035
TO
32 */
33
34/**
ce064e4f 35 * This class generates form components for Location Type.
6a488035
TO
36 */
37class CRM_Admin_Form_PaymentProcessorType extends CRM_Admin_Form {
38 protected $_id = NULL;
39
40 protected $_fields = NULL;
41
00be9182 42 public function preProcess() {
6a488035
TO
43 parent::preProcess();
44
45 $this->_fields = array(
46 array(
47 'name' => 'name',
48 'label' => ts('Name'),
49 'required' => TRUE,
50 ),
51 array(
52 'name' => 'title',
53 'label' => ts('Title'),
54 'required' => TRUE,
55 ),
56 array(
57 'name' => 'billing_mode',
58 'label' => ts('Billing Mode'),
59 'required' => TRUE,
60 'rule' => 'positiveInteger',
61 'msg' => ts('Enter a positive integer'),
62 ),
63 array(
64 'name' => 'description',
65 'label' => ts('Description'),
66 ),
67 array(
68 'name' => 'user_name_label',
69 'label' => ts('User Name Label'),
70 ),
71 array(
72 'name' => 'password_label',
73 'label' => ts('Password Label'),
74 ),
75 array(
76 'name' => 'signature_label',
77 'label' => ts('Signature Label'),
78 ),
79 array(
80 'name' => 'subject_label',
81 'label' => ts('Subject Label'),
82 ),
83 array(
84 'name' => 'class_name',
85 'label' => ts('PHP class name'),
86 'required' => TRUE,
87 ),
88 array(
89 'name' => 'url_site_default',
90 'label' => ts('Live Site URL'),
91 'required' => TRUE,
92 'rule' => 'url',
93 'msg' => ts('Enter a valid URL'),
94 ),
95 array(
96 'name' => 'url_api_default',
97 'label' => ts('Live API URL'),
98 'required' => FALSE,
99 'rule' => 'url',
100 'msg' => ts('Enter a valid URL'),
101 ),
102 array(
103 'name' => 'url_recur_default',
104 'label' => ts('Live Recurring Payments URL'),
105 'required' => TRUE,
106 'rule' => 'url',
107 'msg' => ts('Enter a valid URL'),
108 ),
109 array(
110 'name' => 'url_button_default',
111 'label' => ts('Live Button URL'),
112 'rule' => 'url',
113 'msg' => ts('Enter a valid URL'),
114 ),
115 array(
116 'name' => 'url_site_test_default',
117 'label' => ts('Test Site URL'),
118 'required' => TRUE,
119 'rule' => 'url',
120 'msg' => ts('Enter a valid URL'),
121 ),
122 array(
123 'name' => 'url_api_test_default',
124 'label' => ts('Test API URL'),
125 'required' => FALSE,
126 'rule' => 'url',
127 'msg' => ts('Enter a valid URL'),
128 ),
129 array(
130 'name' => 'url_recur_test_default',
131 'label' => ts('Test Recurring Payments URL'),
132 'required' => TRUE,
133 'rule' => 'url',
134 'msg' => ts('Enter a valid URL'),
135 ),
136 array(
137 'name' => 'url_button_test_default',
138 'label' => ts('Test Button URL'),
139 'rule' => 'url',
140 'msg' => ts('Enter a valid URL'),
141 ),
142 );
143 }
144
145 /**
eceb18cc 146 * Build the form object.
6a488035 147 *
dd244018 148 * @param bool $check
6a488035
TO
149 */
150 public function buildQuickForm($check = FALSE) {
151 parent::buildQuickForm();
152
153 if ($this->_action & CRM_Core_Action::DELETE) {
154 return;
155 }
156
481a74f4 157 $attributes = CRM_Core_DAO::getAttribute('CRM_Financial_DAO_PaymentProcessorType');
6a488035
TO
158
159 foreach ($this->_fields as $field) {
160 $required = CRM_Utils_Array::value('required', $field, FALSE);
161 $this->add('text', $field['name'],
162 $field['label'], $attributes['name'], $required
163 );
a7488080 164 if (!empty($field['rule'])) {
6a488035
TO
165 $this->addRule($field['name'], $field['msg'], $field['rule']);
166 }
167 }
168
169 // is this processor active ?
170 $this->add('checkbox', 'is_active', ts('Is this Payment Processor Type active?'));
171 $this->add('checkbox', 'is_default', ts('Is this Payment Processor Type the default?'));
172 $this->add('checkbox', 'is_recur', ts('Does this Payment Processor Type support recurring donations?'));
173 }
174
e0ef6999
EM
175 /**
176 * @return array
177 */
00be9182 178 public function setDefaultValues() {
6a488035
TO
179 $defaults = array();
180
181 if (!$this->_id) {
182 $defaults['is_active'] = $defaults['is_default'] = 1;
183 $defaults['user_name_label'] = ts('User Name');
184 $defaults['password_label'] = ts('Password');
185 $defaults['signature_label'] = ts('Signature');
186 $defaults['subject_label'] = ts('Subject');
187 return $defaults;
188 }
189
481a74f4 190 $dao = new CRM_Financial_DAO_PaymentProcessorType();
6a488035
TO
191 $dao->id = $this->_id;
192
193 if (!$dao->find(TRUE)) {
194 return $defaults;
195 }
196
197 CRM_Core_DAO::storeValues($dao, $defaults);
198
199 return $defaults;
200 }
201
202 /**
eceb18cc 203 * Process the form submission.
6a488035
TO
204 */
205 public function postProcess() {
481a74f4 206 CRM_Utils_System::flushCache('CRM_Financial_DAO_PaymentProcessorType');
6a488035
TO
207
208 if ($this->_action & CRM_Core_Action::DELETE) {
209 CRM_Financial_BAO_PaymentProcessorType::del($this->_id);
210 return;
211 }
212
213 $values = $this->controller->exportValues($this->_name);
214
a7488080 215 if (!empty($values['is_default'])) {
6a488035
TO
216 $query = "
217UPDATE civicrm_payment_processor SET is_default = 0";
218 CRM_Core_DAO::executeQuery($query, CRM_Core_DAO::$_nullArray);
219 }
220
481a74f4 221 $dao = new CRM_Financial_DAO_PaymentProcessorType();
6a488035 222
353ffa53 223 $dao->id = $this->_id;
6a488035 224 $dao->is_default = CRM_Utils_Array::value('is_default', $values, 0);
353ffa53
TO
225 $dao->is_active = CRM_Utils_Array::value('is_active', $values, 0);
226 $dao->is_recur = CRM_Utils_Array::value('is_recur', $values, 0);
6a488035
TO
227
228 $dao->name = $values['name'];
229 $dao->description = $values['description'];
230
231 foreach ($this->_fields as $field) {
232 $dao->{$field['name']} = trim($values[$field['name']]);
233 if (empty($dao->{$field['name']})) {
234 $dao->{$field['name']} = 'null';
235 }
236 }
237 $dao->save();
238 }
96025800 239
6a488035 240}