3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
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 +--------------------------------------------------------------------+
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
19 * Main page for viewing all Saved searches.
21 class CRM_Contact_Page_SavedSearch
extends CRM_Core_Page
{
24 * The action links that we need to display for the browse screen.
28 public static $_links = NULL;
31 * Delete a saved search.
36 public function delete($id) {
37 // first delete the group associated with this saved search
38 $group = new CRM_Contact_DAO_Group();
39 $group->saved_search_id
= $id;
40 if ($group->find(TRUE)) {
41 CRM_Contact_BAO_Group
::discard($group->id
);
44 $savedSearch = new CRM_Contact_DAO_SavedSearch();
45 $savedSearch->id
= $id;
46 $savedSearch->is_active
= 0;
51 * Browse all saved searches.
54 * content of the parents run method
56 public function browse() {
59 $savedSearch = new CRM_Contact_DAO_SavedSearch();
60 $savedSearch->is_active
= 1;
61 $savedSearch->selectAdd();
62 $savedSearch->selectAdd('id, form_values');
64 $properties = ['id', 'name', 'description'];
65 while ($savedSearch->fetch()) {
66 // get name and description from group object
67 $group = new CRM_Contact_DAO_Group();
68 $group->saved_search_id
= $savedSearch->id
;
69 if ($group->find(TRUE)) {
70 $permissions = CRM_Contact_BAO_Group
::checkPermission($group->id
, TRUE);
71 if (!CRM_Utils_System
::isNull($permissions)) {
74 $row['name'] = $group->title
;
75 $row['description'] = $group->description
;
77 $row['id'] = $savedSearch->id
;
78 $formValues = CRM_Utils_String
::unserialize($savedSearch->form_values
);
79 $query = new CRM_Contact_BAO_Query($formValues);
80 $row['query_detail'] = $query->qill();
82 $action = array_sum(array_keys(self
::links()));
83 $action = $action & CRM_Core_Action
::mask($permissions);
84 $row['action'] = CRM_Core_Action
::formLink(
90 'savedSearch.manage.action',
100 $this->assign('rows', $rows);
101 return parent
::run();
105 * Run this page (figure out the action needed and perform it).
107 public function run() {
108 $action = CRM_Utils_Request
::retrieve('action', 'String',
109 $this, FALSE, 'browse'
112 $this->assign('action', $action);
114 if ($action & CRM_Core_Action
::DELETE
) {
115 $id = CRM_Utils_Request
::retrieve('id', 'Positive',
127 * (reference) of action links
129 public static function &links() {
131 if (!(self
::$_links)) {
133 $deleteExtra = ts('Do you really want to remove this Smart Group?');
136 CRM_Core_Action
::VIEW
=> [
137 'name' => ts('Search'),
138 'url' => 'civicrm/contact/search/advanced',
139 'qs' => 'reset=1&force=1&ssID=%%id%%',
140 'title' => ts('Search'),
142 CRM_Core_Action
::DELETE
=> [
143 'name' => ts('Delete'),
144 'url' => 'civicrm/contact/search/saved',
145 'qs' => 'action=delete&id=%%id%%',
146 'extra' => 'onclick="return confirm(\'' . $deleteExtra . '\');"',
150 return self
::$_links;