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