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 provides the functionality for batch profile update for contributions
39 class CRM_Contribute_Form_Task_Batch
extends CRM_Contribute_Form_Task
{
42 * the title of the group
49 * maximum profile fields that will be displayed
52 protected $_maxFields = 9;
55 * variable to store redirect path
58 protected $_userContext;
61 * build all the data structures needed to build the form
66 function preProcess() {
68 * initialize the task and row fields
72 //get the contact read only fields to display.
73 $readOnlyFields = array_merge(array('sort_name' => ts('Name')),
74 CRM_Core_BAO_Setting
::valueOptions(CRM_Core_BAO_Setting
::SYSTEM_PREFERENCES_NAME
,
75 'contact_autocomplete_options',
76 TRUE, NULL, FALSE, 'name', TRUE
79 //get the read only field data.
80 $returnProperties = array_fill_keys(array_keys($readOnlyFields), 1);
81 $contactDetails = CRM_Contact_BAO_Contact_Utils
::contactDetails($this->_contributionIds
,
82 'CiviContribute', $returnProperties
84 $this->assign('contactDetails', $contactDetails);
85 $this->assign('readOnlyFields', $readOnlyFields);
95 function buildQuickForm() {
96 $ufGroupId = $this->get('ufGroupId');
99 CRM_Core_Error
::fatal('ufGroupId is missing');
101 $this->_title
= ts('Batch Update for Contributions') . ' - ' . CRM_Core_BAO_UFGroup
::getTitle($ufGroupId);
102 CRM_Utils_System
::setTitle($this->_title
);
104 $this->addDefaultButtons(ts('Save'));
105 $this->_fields
= array();
106 $this->_fields
= CRM_Core_BAO_UFGroup
::getFields($ufGroupId, FALSE, CRM_Core_Action
::VIEW
);
108 // remove file type field and then limit fields
109 $suppressFields = FALSE;
110 $removehtmlTypes = array('File', 'Autocomplete-Select');
111 foreach ($this->_fields
as $name => $field) {
112 if ($cfID = CRM_Core_BAO_CustomField
::getKeyID($name) &&
113 in_array($this->_fields
[$name]['html_type'], $removehtmlTypes)
115 $suppressFields = TRUE;
116 unset($this->_fields
[$name]);
119 //fix to reduce size as we are using this field in grid
120 if (is_array($field['attributes']) && $this->_fields
[$name]['attributes']['size'] > 19) {
121 //shrink class to "form-text-medium"
122 $this->_fields
[$name]['attributes']['size'] = 19;
126 $this->_fields
= array_slice($this->_fields
, 0, $this->_maxFields
);
128 $this->addButtons(array(
131 'name' => ts('Update Contribution(s)'),
136 'name' => ts('Cancel'),
142 $this->assign('profileTitle', $this->_title
);
143 $this->assign('componentIds', $this->_contributionIds
);
144 $fileFieldExists = FALSE;
146 //load all campaigns.
147 if (array_key_exists('contribution_campaign_id', $this->_fields
)) {
148 $this->_componentCampaigns
= array();
149 CRM_Core_PseudoConstant
::populate($this->_componentCampaigns
,
150 'CRM_Contribute_DAO_Contribution',
151 TRUE, 'campaign_id', 'id',
152 ' id IN (' . implode(' , ', array_values($this->_contributionIds
)) . ' ) '
157 $customFields = CRM_Core_BAO_CustomField
::getFields('Contribution');
158 foreach ($this->_contributionIds
as $contributionId) {
159 $typeId = CRM_Core_DAO
::getFieldValue( "CRM_Contribute_DAO_Contribution", $contributionId, 'financial_type_id' );
160 foreach ($this->_fields
as $name => $field) {
161 if ($customFieldID = CRM_Core_BAO_CustomField
::getKeyID($name)) {
162 $customValue = CRM_Utils_Array
::value($customFieldID, $customFields);
163 if (CRM_Utils_Array
::value('extends_entity_column_value', $customValue)) {
164 $entityColumnValue = explode(CRM_Core_DAO
::VALUE_SEPARATOR
,
165 $customValue['extends_entity_column_value']
169 if (CRM_Utils_Array
::value($typeId, $entityColumnValue) ||
170 CRM_Utils_System
::isNull($entityColumnValue[$typeId])
172 CRM_Core_BAO_UFGroup
::buildProfile($this, $field, NULL, $contributionId);
176 // handle non custom fields
177 CRM_Core_BAO_UFGroup
::buildProfile($this, $field, NULL, $contributionId);
182 $this->assign('fields', $this->_fields
);
184 // don't set the status message when form is submitted.
185 $buttonName = $this->controller
->getButtonName('submit');
187 if ($suppressFields && $buttonName != '_qf_Batch_next') {
188 CRM_Core_Session
::setStatus(ts("FILE or Autocomplete Select type field(s) in the selected profile are not supported for Batch Update and have been excluded."), ts('Unsupported Field Type'), 'error');
191 $this->addDefaultButtons(ts('Update Contributions'));
195 * This function sets the default values for the form.
201 function setDefaultValues() {
202 if (empty($this->_fields
)) {
207 foreach ($this->_contributionIds
as $contributionId) {
208 $details[$contributionId] = array();
209 CRM_Core_BAO_UFGroup
::setProfileDefaults(NULL, $this->_fields
, $defaults, FALSE, $contributionId, 'Contribute');
216 * process the form after the input has been submitted and validated
222 public function postProcess() {
223 $params = $this->exportValues();
230 if (isset($params['field'])) {
231 foreach ($params['field'] as $key => $value) {
233 $value['custom'] = CRM_Core_BAO_CustomField
::postProcess($value,
234 CRM_Core_DAO
::$_nullObject,
239 $ids['contribution'] = $key;
240 foreach ($dates as $val) {
241 if (isset($value[$val])) {
242 $value[$val] = CRM_Utils_Date
::processDate($value[$val]);
245 if (CRM_Utils_Array
::value('financial_type', $value)) {
246 $value['financial_type_id'] = $value['financial_type'];
249 if (CRM_Utils_Array
::value('payment_instrument', $value)) {
250 $value['payment_instrument_id'] = $value['payment_instrument'];
253 if (CRM_Utils_Array
::value('contribution_source', $value)) {
254 $value['source'] = $value['contribution_source'];
257 unset($value['financial_type']);
258 unset($value['contribution_source']);
259 $contribution = CRM_Contribute_BAO_Contribution
::add($value, $ids);
261 // add custom field values
262 if (CRM_Utils_Array
::value('custom', $value) &&
263 is_array($value['custom'])
265 CRM_Core_BAO_CustomValueTable
::store($value['custom'], 'civicrm_contribution', $contribution->id
);
268 CRM_Core_Session
::setStatus(ts("Your updates have been saved."), ts('Saved'), 'success');
271 CRM_Core_Session
::setStatus(ts("No updates have been saved."), ts('Not Saved'), 'alert');