3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2019 |
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-2019
35 * This class provides the functionality to alter a privacy
36 * options for selected contacts
38 class CRM_Contact_Form_Task_AlterPreferences
extends CRM_Contact_Form_Task
{
41 * Build the form object.
43 public function buildQuickForm() {
44 // add select for preferences
46 $options = [ts('Add Selected Options'), ts('Remove selected options')];
48 $this->addRadio('actionTypeOption', ts('actionTypeOption'), $options);
50 $privacyOptions = CRM_Core_SelectValues
::privacy();
52 foreach ($privacyOptions as $prefID => $prefName) {
53 $this->_prefElement
= &$this->addElement('checkbox', "pref[$prefID]", NULL, $prefName);
56 $this->addDefaultButtons(ts('Set Privacy Options'));
59 public function addRules() {
60 $this->addFormRule(['CRM_Contact_Form_Task_AlterPreferences', 'formRule']);
64 * Set the default form values.
68 * the default array reference
70 public function setDefaultValues() {
73 $defaults['actionTypeOption'] = 0;
78 * @param CRM_Core_Form $form
83 public static function formRule($form, $rule) {
85 if (empty($form['pref']) && empty($form['contact_taglist'])) {
86 $errors['_qf_default'] = ts("Please select at least one privacy option.");
92 * Process the form after the input has been submitted and validated.
94 public function postProcess() {
95 //get the submitted values in an array
96 $params = $this->controller
->exportValues($this->_name
);
98 $actionTypeOption = CRM_Utils_Array
::value('actionTypeOption', $params, NULL);
99 // If remove option has been selected set new privacy value to "false"
100 $privacyValueNew = empty($actionTypeOption);
102 // check if any privay option has been checked
103 if (!empty($params['pref'])) {
104 $privacyValues = $params['pref'];
106 foreach ($this->_contactIds
as $contact_id) {
107 $contact = new CRM_Contact_BAO_Contact();
108 $contact->id
= $contact_id;
110 foreach ($privacyValues as $privacy_key => $privacy_value) {
111 $contact->$privacy_key = $privacyValueNew;
117 $privacyOptions = CRM_Core_SelectValues
::privacy();
119 foreach ($privacyValues as $privacy_key => $privacy_value) {
120 $label = $privacyOptions[$privacy_key];
121 $status[] = $privacyValueNew ?
ts("Added '%1'", [1 => $label]) : ts("Removed '%1'", [1 => $label]);
124 $status = '<ul><li>' . implode('</li><li>', $status) . '</li></ul>';
126 $title = ts('%1 Contacts Updated', [1 => $count]);
129 $name = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Contact', $contact_id, 'display_name');
130 $title = ts('%1 Updated', [1 => $name]);
133 CRM_Core_Session
::setStatus($status, $title, 'success');