Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
232624b1 | 4 | | CiviCRM version 4.4 | |
6a488035 TO |
5 | +--------------------------------------------------------------------+ |
6 | | Copyright CiviCRM LLC (c) 2004-2013 | | |
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-2013 | |
32 | * $Id$ | |
33 | * | |
34 | */ | |
35 | ||
36 | /** | |
37 | * this class builds custom data | |
38 | */ | |
39 | class CRM_Custom_Form_CustomData { | |
40 | ||
41 | /** | |
42 | * @param CRM_Core_Form $form | |
43 | * @param null|string $subName | |
44 | * @param null|string $subType | |
45 | * @param null|int $groupCount | |
46 | * @param null|String $type | |
47 | * @param null|int $entityID | |
48 | * @return void | |
49 | */ | |
50 | static function preProcess(&$form, $subName = NULL, $subType = NULL, | |
63dbed83 | 51 | $groupCount = NULL, $type = NULL, $entityID = NULL, $onlySubType = NULL |
6a488035 TO |
52 | ) { |
53 | if ($type) { | |
54 | $form->_type = $type; | |
55 | } | |
56 | else { | |
57 | $form->_type = CRM_Utils_Request::retrieve('type', 'String', $form); | |
58 | } | |
59 | ||
60 | if (isset($subType)) { | |
61 | $form->_subType = $subType; | |
62 | } | |
63 | else { | |
64 | $form->_subType = CRM_Utils_Request::retrieve('subType', 'String', $form); | |
65 | } | |
66 | ||
67 | if ($form->_subType == 'null') { | |
68 | $form->_subType = NULL; | |
69 | } | |
70 | ||
71 | if (isset($subName)) { | |
72 | $form->_subName = $subName; | |
73 | } | |
74 | else { | |
75 | $form->_subName = CRM_Utils_Request::retrieve('subName', 'String', $form); | |
76 | } | |
77 | ||
78 | if ($form->_subName == 'null') { | |
79 | $form->_subName = NULL; | |
80 | } | |
81 | ||
82 | if ($groupCount) { | |
83 | $form->_groupCount = $groupCount; | |
84 | } | |
85 | else { | |
86 | $form->_groupCount = CRM_Utils_Request::retrieve('cgcount', 'Positive', $form); | |
87 | } | |
88 | ||
89 | $form->assign('cgCount', $form->_groupCount); | |
90 | ||
91 | //carry qf key, since this form is not inhereting core form. | |
92 | if ($qfKey = CRM_Utils_Request::retrieve('qfKey', 'String', CRM_Core_DAO::$_nullObject)) { | |
93 | $form->assign('qfKey', $qfKey); | |
94 | } | |
95 | ||
96 | if ($entityID) { | |
97 | $form->_entityId = $entityID; | |
98 | } | |
99 | else { | |
100 | $form->_entityId = CRM_Utils_Request::retrieve('entityID', 'Positive', $form); | |
101 | } | |
102 | ||
103 | $typeCheck = CRM_Utils_Request::retrieve( 'type', 'String', CRM_Core_DAO::$_nullObject ); | |
104 | $urlGroupId = CRM_Utils_Request::retrieve('groupID', 'Positive', CRM_Core_DAO::$_nullObject); | |
8ef12e64 | 105 | if ( isset($typeCheck) && $urlGroupId) { |
6a488035 TO |
106 | $form->_groupID = $urlGroupId; |
107 | } else { | |
108 | $form->_groupID = CRM_Utils_Request::retrieve('groupID', 'Positive', $form); | |
109 | } | |
110 | ||
111 | $gid = (isset($form->_groupID)) ? $form->_groupID : NULL; | |
112 | $getCachedTree = isset($form->_getCachedTree) ? $form->_getCachedTree : TRUE; | |
113 | ||
114 | $subType = $form->_subType; | |
115 | if (!is_array($subType) && strstr($subType, CRM_Core_DAO::VALUE_SEPARATOR)) { | |
116 | $subType = str_replace(CRM_Core_DAO::VALUE_SEPARATOR, ',', trim($subType, CRM_Core_DAO::VALUE_SEPARATOR)); | |
117 | } | |
8ef12e64 | 118 | |
6a488035 TO |
119 | $groupTree = &CRM_Core_BAO_CustomGroup::getTree($form->_type, |
120 | $form, | |
121 | $form->_entityId, | |
122 | $gid, | |
123 | $subType, | |
124 | $form->_subName, | |
63dbed83 | 125 | $getCachedTree, |
126 | $onlySubType | |
6a488035 TO |
127 | ); |
128 | ||
129 | if (property_exists($form, '_customValueCount') && !empty($groupTree)) { | |
130 | $form->_customValueCount = CRM_Core_BAO_CustomGroup::buildCustomDataView($form, $groupTree, TRUE, NULL, NULL); | |
131 | } | |
132 | // we should use simplified formatted groupTree | |
133 | $groupTree = CRM_Core_BAO_CustomGroup::formatGroupTree($groupTree, $form->_groupCount, $form); | |
134 | ||
135 | if (isset($form->_groupTree) && is_array($form->_groupTree)) { | |
136 | $keys = array_keys($groupTree); | |
137 | foreach ($keys as $key) { | |
138 | $form->_groupTree[$key] = $groupTree[$key]; | |
139 | } | |
140 | } | |
141 | else { | |
142 | $form->_groupTree = $groupTree; | |
143 | } | |
144 | } | |
145 | ||
146 | static function setDefaultValues(&$form) { | |
147 | $defaults = array(); | |
148 | CRM_Core_BAO_CustomGroup::setDefaults($form->_groupTree, $defaults, FALSE, FALSE, $form->get('action')); | |
149 | return $defaults; | |
150 | } | |
151 | ||
152 | /** | |
153 | * @param CRM_Core_Form $form | |
154 | * @return void | |
155 | */ | |
156 | static function buildQuickForm(&$form) { | |
157 | $form->addElement('hidden', 'hidden_custom', 1); | |
158 | $form->addElement('hidden', "hidden_custom_group_count[{$form->_groupID}]", $form->_groupCount); | |
7b226831 | 159 | CRM_Core_BAO_CustomGroup::buildQuickForm($form, $form->_groupTree); |
6a488035 TO |
160 | } |
161 | } | |
162 |