Merge pull request #12264 from civicrm/5.2
[civicrm-core.git] / CRM / Member / Form / MembershipConfig.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2018 |
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 +--------------------------------------------------------------------+
26 */
27
28 /**
29 *
30 * @package CRM
31 * @copyright CiviCRM LLC (c) 2004-2018
32 * $Id$
33 *
34 */
35
36 /**
37 * Base class for offline membership / membership type / membership renewal and membership status forms
38 *
39 */
40 class CRM_Member_Form_MembershipConfig extends CRM_Core_Form {
41
42 /**
43 * The id of the object being edited / created
44 *
45 * @var int
46 */
47 public $_id;
48
49 /**
50 * The name of the BAO object for this form.
51 *
52 * @var string
53 */
54 protected $_BAOName;
55
56 /**
57 * Set default values for the form. MobileProvider that in edit/view mode
58 * the default values are retrieved from the database
59 *
60 * @return array
61 * defaults
62 */
63 public function setDefaultValues() {
64 $defaults = array();
65
66 if (isset($this->_id)) {
67 $params = array('id' => $this->_id);
68 $baoName = $this->_BAOName;
69 $baoName::retrieve($params, $defaults);
70 }
71
72 if (isset($defaults['minimum_fee'])) {
73 $defaults['minimum_fee'] = CRM_Utils_Money::format($defaults['minimum_fee'], NULL, '%a');
74 }
75
76 if (isset($defaults['status'])) {
77 $this->assign('membershipStatus', $defaults['status']);
78 }
79
80 if ($this->_action & CRM_Core_Action::ADD) {
81 $defaults['is_active'] = 1;
82 }
83
84 if (isset($defaults['member_of_contact_id']) &&
85 $defaults['member_of_contact_id']
86 ) {
87 $defaults['member_org'] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact',
88 $defaults['member_of_contact_id'], 'display_name'
89 );
90 }
91 return $defaults;
92 }
93
94 /**
95 * Build the form object.
96 *
97 * @return void
98 */
99 public function buildQuickForm() {
100 if ($this->_action & CRM_Core_Action::RENEW) {
101 $this->addButtons(array(
102 array(
103 'type' => 'upload',
104 'name' => ts('Renew'),
105 'isDefault' => TRUE,
106 ),
107 array(
108 'type' => 'cancel',
109 'name' => ts('Cancel'),
110 ),
111 ));
112 }
113 elseif ($this->_action & CRM_Core_Action::DELETE) {
114 $this->addButtons(array(
115 array(
116 'type' => 'next',
117 'name' => ts('Delete'),
118 'isDefault' => TRUE,
119 ),
120 array(
121 'type' => 'cancel',
122 'name' => ts('Cancel'),
123 ),
124 ));
125 }
126 else {
127 $this->addButtons(array(
128 array(
129 'type' => 'upload',
130 'name' => ts('Save'),
131 'isDefault' => TRUE,
132 ),
133 array(
134 'type' => 'upload',
135 'name' => ts('Save and New'),
136 'subName' => 'new',
137 ),
138 array(
139 'type' => 'cancel',
140 'name' => ts('Cancel'),
141 ),
142 ));
143 }
144 }
145
146 }