CIVICRM-1391 Update Smart Group form unsets the existing Group Types for the Group
[civicrm-core.git] / CRM / Contact / Form / Task / SaveSearch / Update.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
bc77d7c0 4 | Copyright CiviCRM LLC. All rights reserved. |
6a488035 5 | |
bc77d7c0
TO
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
6a488035 9 +--------------------------------------------------------------------+
d25dd0ee 10 */
6a488035
TO
11
12/**
13 *
14 * @package CRM
ca5cec67 15 * @copyright CiviCRM LLC https://civicrm.org/licensing
6a488035
TO
16 */
17
18/**
f12c6f7d 19 * This class provides the functionality to update a saved search.
6a488035
TO
20 */
21class CRM_Contact_Form_Task_SaveSearch_Update extends CRM_Contact_Form_Task_SaveSearch {
22
23 /**
fe482240 24 * Build all the data structures needed to build the form.
6a488035 25 */
00be9182 26 public function preProcess() {
6a488035
TO
27 parent::preProcess();
28
29 $this->_id = $this->get('ssID');
30 if (!$this->_id) {
31 // fetch the value from the group id gid
32 $gid = $this->get('gid');
33 if ($gid) {
34 $this->_id = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Group', $gid, 'saved_search_id');
35 }
36 }
37 }
38
39 /**
c490a46a 40 * Set default values for the form.
6a488035 41 */
00be9182 42 public function setDefaultValues() {
6a488035 43
be2fb01f
CW
44 $defaults = [];
45 $params = [];
6a488035 46
be2fb01f 47 $params = ['saved_search_id' => $this->_id];
6a488035
TO
48 CRM_Contact_BAO_Group::retrieve($params, $defaults);
49
6734751a
JF
50 if (!empty($defaults['group_type'])) {
51 $types = explode(CRM_Core_DAO::VALUE_SEPARATOR,
52 substr($defaults['group_type'], 1, -1)
53 );
54 $defaults['group_type'] = array();
55 foreach ($types as $type) {
56 $defaults['group_type'][$type] = 1;
57 }
58 }
6a488035
TO
59 return $defaults;
60 }
96025800 61
6a488035 62}