3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.3 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2013
37 * This class generates form components for custom data
39 * It delegates the work to lower level subclasses and integrates the changes
40 * back in. It also uses a lot of functionality with the CRM API's, so any change
41 * made here could potentially affect the API etc. Be careful, be aware, use unit tests.
44 class CRM_Contact_Form_CustomData
extends CRM_Core_Form
{
47 * The table id, used when editing/creating custom data
54 * entity type of the table id
58 protected $_entityType;
61 * entity sub type of the table id
66 protected $_entitySubType;
73 //protected $_groupTree;
76 * Which blocks should we show and hide.
78 * @var CRM_Core_ShowHideBlocks
87 protected $_groupTitle;
90 * Array group display status.
94 protected $_groupCollapseDisplay;
105 * pre processing work done here.
107 * gets session variables for table name, id of entity in table, type of entity and stores them.
116 function preProcess() {
117 $this->_cdType
= CRM_Utils_Array
::value('type', $_GET);
119 $this->assign('cdType', FALSE);
120 if ($this->_cdType
) {
121 $this->assign('cdType', TRUE);
122 return CRM_Custom_Form_CustomData
::preProcess($this);
125 $this->_groupID
= CRM_Utils_Request
::retrieve('groupID', 'Positive', $this, TRUE);
126 $this->_tableID
= CRM_Utils_Request
::retrieve('tableId', 'Positive', $this, TRUE);
128 $this->_contactType
= CRM_Contact_BAO_Contact
::getContactType($this->_tableID
);
129 $this->_contactSubType
= CRM_Contact_BAO_Contact
::getContactSubType($this->_tableID
, ',');
130 $this->assign('contact_type', $this->_contactType
);
131 $this->assign('contact_subtype', $this->_contactSubType
);
132 list($displayName, $contactImage) = CRM_Contact_BAO_Contact
::getDisplayAndImage($this->_tableID
);
133 CRM_Utils_System
::setTitle($displayName, $contactImage . ' ' . $displayName);
135 // when custom data is included in this page
136 if (CRM_Utils_Array
::value('hidden_custom', $_POST)) {
137 for ($i = 0; $i <= $_POST['hidden_custom_group_count'][$this->_groupID
]; $i++
) {
138 CRM_Custom_Form_CustomData
::preProcess($this, NULL, NULL, $i);
139 CRM_Custom_Form_CustomData
::buildQuickForm($this);
140 CRM_Custom_Form_CustomData
::setDefaultValues($this);
146 * Function to actually build the form
151 public function buildQuickForm() {
152 if ($this->_cdType
) {
153 return CRM_Custom_Form_CustomData
::buildQuickForm($this);
156 //need to assign custom data type and subtype to the template
157 $this->assign('entityID', $this->_tableID
);
158 $this->assign('groupID', $this->_groupID
);
160 // make this form an upload since we dont know if the custom data injected dynamically
161 // is of type file etc
162 $this->addButtons(array(
165 'name' => ts('Save'),
170 'name' => ts('Cancel'),
177 * Set the default form values
181 * @return array the default array reference
183 function setDefaultValues() {
184 if ($this->_cdType
) {
185 $customDefaultValue = CRM_Custom_Form_CustomData
::setDefaultValues($this);
186 return $customDefaultValue;
189 $groupTree = &CRM_Core_BAO_CustomGroup
::getTree($this->_contactType
,
193 $this->_contactSubType
196 if (!CRM_Utils_Array
::value('hidden_custom_group_count', $_POST)) {
197 // custom data building in edit mode (required to handle multi-value)
198 $groupTree = &CRM_Core_BAO_CustomGroup
::getTree($this->_contactType
, $this, $this->_tableID
,
199 $this->_groupID
, $this->_contactSubType
201 $customValueCount = CRM_Core_BAO_CustomGroup
::buildCustomDataView($this, $groupTree, TRUE, $this->_groupID
);
204 $customValueCount = $_POST['hidden_custom_group_count'][$this->_groupID
];
207 $this->assign('customValueCount', $customValueCount);
214 * Process the user submitted custom data values.
220 public function postProcess() {
221 // Get the form values and groupTree
222 $params = $this->controller
->exportValues($this->_name
);
223 CRM_Core_BAO_CustomValueTable
::postProcess($params,
224 $this->_groupTree
[$this->_groupID
]['fields'],
230 // reset the group contact cache for this group
231 CRM_Contact_BAO_GroupContactCache
::remove();