financial#46 - clean money format at form layer
[civicrm-core.git] / CRM / Contribute / Form / ContributionPage / TabHeader.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
fee14197 4 | CiviCRM version 5 |
6a488035 5 +--------------------------------------------------------------------+
6b83d5bd 6 | Copyright CiviCRM LLC (c) 2004-2019 |
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
6b83d5bd 31 * @copyright CiviCRM LLC (c) 2004-2019
6a488035
TO
32 */
33
34/**
07f8d162 35 * Helper class to build navigation links.
6a488035
TO
36 */
37class CRM_Contribute_Form_ContributionPage_TabHeader {
186c9c17 38 /**
c490a46a 39 * @param CRM_Core_Form $form
186c9c17
EM
40 *
41 * @return array
42 */
00be9182 43 public static function build(&$form) {
6a488035 44 $tabs = $form->get('tabHeader');
8cc574cf 45 if (!$tabs || empty($_GET['reset'])) {
6a488035
TO
46 $tabs = self::process($form);
47 $form->set('tabHeader', $tabs);
48 }
49 $form->assign_by_ref('tabHeader', $tabs);
4165b7e5 50 CRM_Core_Resources::singleton()
96ed17aa 51 ->addScriptFile('civicrm', 'templates/CRM/common/TabHeader.js', 1, 'html-header')
874c9be7 52 ->addSetting(array(
353ffa53
TO
53 'tabSettings' => array(
54 'active' => self::getCurrentTab($tabs),
389bcebf 55 ),
353ffa53 56 ));
6a488035
TO
57 return $tabs;
58 }
59
186c9c17 60 /**
c490a46a 61 * @param CRM_Core_Form $form
186c9c17
EM
62 *
63 * @return array
64 */
00be9182 65 public static function process(&$form) {
6a488035
TO
66 if ($form->getVar('_id') <= 0) {
67 return NULL;
68 }
69
70 $tabs = array(
874c9be7 71 'settings' => array(
353ffa53 72 'title' => ts('Title'),
6a488035
TO
73 'link' => NULL,
74 'valid' => FALSE,
75 'active' => FALSE,
76 'current' => FALSE,
77 ),
874c9be7 78 'amount' => array(
353ffa53 79 'title' => ts('Amounts'),
6a488035
TO
80 'link' => NULL,
81 'valid' => FALSE,
82 'active' => FALSE,
83 'current' => FALSE,
84 ),
874c9be7 85 'membership' => array(
353ffa53 86 'title' => ts('Memberships'),
6a488035
TO
87 'link' => NULL,
88 'valid' => FALSE,
89 'active' => FALSE,
90 'current' => FALSE,
91 ),
874c9be7 92 'thankyou' => array(
353ffa53 93 'title' => ts('Receipt'),
6a488035
TO
94 'link' => NULL,
95 'valid' => FALSE,
96 'active' => FALSE,
97 'current' => FALSE,
98 ),
874c9be7 99 'friend' => array(
353ffa53 100 'title' => ts('Tell a Friend'),
6a488035
TO
101 'link' => NULL,
102 'valid' => FALSE,
103 'active' => FALSE,
104 'current' => FALSE,
105 ),
874c9be7 106 'custom' => array(
353ffa53 107 'title' => ts('Profiles'),
6a488035
TO
108 'link' => NULL,
109 'valid' => FALSE,
110 'active' => FALSE,
111 'current' => FALSE,
112 ),
874c9be7 113 'premium' => array(
353ffa53 114 'title' => ts('Premiums'),
6a488035
TO
115 'link' => NULL,
116 'valid' => FALSE,
117 'active' => FALSE,
118 'current' => FALSE,
119 ),
874c9be7 120 'widget' => array(
353ffa53 121 'title' => ts('Widgets'),
6a488035
TO
122 'link' => NULL,
123 'valid' => FALSE,
124 'active' => FALSE,
125 'current' => FALSE,
126 ),
874c9be7 127 'pcp' => array(
353ffa53 128 'title' => ts('Personal Campaigns'),
6a488035
TO
129 'link' => NULL,
130 'valid' => FALSE,
131 'active' => FALSE,
132 'current' => FALSE,
133 ),
134 );
135
136 $contribPageId = $form->getVar('_id');
48fe48a6 137 CRM_Utils_Hook::tabset('civicrm/admin/contribute', $tabs, array('contribution_page_id' => $contribPageId));
353ffa53
TO
138 $fullName = $form->getVar('_name');
139 $className = CRM_Utils_String::getClassName($fullName);
6a488035
TO
140
141 // Hack for special cases.
142 switch ($className) {
143 case 'Contribute':
144 $attributes = $form->getVar('_attributes');
b90552b7 145 $class = CRM_Utils_Request::retrieveComponent($attributes);
6a488035
TO
146 break;
147
148 case 'MembershipBlock':
149 $class = 'membership';
150 break;
151
152 default:
153 $class = strtolower($className);
154 break;
155 }
156
157 if (array_key_exists($class, $tabs)) {
158 $tabs[$class]['current'] = TRUE;
159 $qfKey = $form->get('qfKey');
160 if ($qfKey) {
161 $tabs[$class]['qfKey'] = "&qfKey={$qfKey}";
162 }
163 }
164
165 if ($contribPageId) {
0d8afee2 166 $reset = !empty($_GET['reset']) ? 'reset=1&' : '';
6a488035
TO
167
168 foreach ($tabs as $key => $value) {
169 if (!isset($tabs[$key]['qfKey'])) {
170 $tabs[$key]['qfKey'] = NULL;
171 }
172
389bcebf 173 $tabs[$key]['link'] = CRM_Utils_System::url(
6a488035 174 "civicrm/admin/contribute/{$key}",
353ffa53
TO
175 "{$reset}action=update&id={$contribPageId}{$tabs[$key]['qfKey']}"
176 );
6a488035
TO
177 $tabs[$key]['active'] = $tabs[$key]['valid'] = TRUE;
178 }
179 //get all section info.
180 $contriPageInfo = CRM_Contribute_BAO_ContributionPage::getSectionInfo(array($contribPageId));
181
182 foreach ($contriPageInfo[$contribPageId] as $section => $info) {
183 if (!$info) {
184 $tabs[$section]['valid'] = FALSE;
185 }
186 }
187 }
188 return $tabs;
189 }
190
186c9c17
EM
191 /**
192 * @param $form
193 */
00be9182 194 public static function reset(&$form) {
6a488035
TO
195 $tabs = self::process($form);
196 $form->set('tabHeader', $tabs);
197 }
198
186c9c17
EM
199 /**
200 * @param $tabs
201 *
202 * @return int|string
203 */
00be9182 204 public static function getCurrentTab($tabs) {
6a488035
TO
205 static $current = FALSE;
206
207 if ($current) {
208 return $current;
209 }
210
211 if (is_array($tabs)) {
212 foreach ($tabs as $subPage => $pageVal) {
213 if ($pageVal['current'] === TRUE) {
214 $current = $subPage;
215 break;
216 }
217 }
218 }
219
220 $current = $current ? $current : 'settings';
221 return $current;
222 }
96025800 223
6a488035 224}