| 1 | <?php |
| 2 | /* |
| 3 | +--------------------------------------------------------------------+ |
| 4 | | Copyright CiviCRM LLC. All rights reserved. | |
| 5 | | | |
| 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 | |
| 9 | +--------------------------------------------------------------------+ |
| 10 | */ |
| 11 | |
| 12 | /** |
| 13 | * |
| 14 | * @package CRM |
| 15 | * @copyright CiviCRM LLC https://civicrm.org/licensing |
| 16 | */ |
| 17 | |
| 18 | /** |
| 19 | * This class provides the functionality to update a saved search. |
| 20 | */ |
| 21 | class CRM_Contact_Form_Task_SaveSearch_Update extends CRM_Contact_Form_Task_SaveSearch { |
| 22 | |
| 23 | /** |
| 24 | * Build all the data structures needed to build the form. |
| 25 | */ |
| 26 | public function preProcess() { |
| 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 | /** |
| 40 | * Set default values for the form. |
| 41 | */ |
| 42 | public function setDefaultValues() { |
| 43 | |
| 44 | $defaults = []; |
| 45 | $params = []; |
| 46 | |
| 47 | $params = ['saved_search_id' => $this->_id]; |
| 48 | CRM_Contact_BAO_Group::retrieve($params, $defaults); |
| 49 | |
| 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 | } |
| 59 | return $defaults; |
| 60 | } |
| 61 | |
| 62 | } |