3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2018 |
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-2018
35 * Main page for viewing all Saved searches.
37 class CRM_Contact_Page_SavedSearch
extends CRM_Core_Page
{
40 * The action links that we need to display for the browse screen.
44 static $_links = NULL;
47 * Delete a saved search.
52 public function delete($id) {
53 // first delete the group associated with this saved search
54 $group = new CRM_Contact_DAO_Group();
55 $group->saved_search_id
= $id;
56 if ($group->find(TRUE)) {
57 CRM_Contact_BAO_Group
::discard($group->id
);
60 $savedSearch = new CRM_Contact_DAO_SavedSearch();
61 $savedSearch->id
= $id;
62 $savedSearch->is_active
= 0;
67 * Browse all saved searches.
70 * content of the parents run method
72 public function browse() {
75 $savedSearch = new CRM_Contact_DAO_SavedSearch();
76 $savedSearch->is_active
= 1;
77 $savedSearch->selectAdd();
78 $savedSearch->selectAdd('id, form_values');
80 $properties = array('id', 'name', 'description');
81 while ($savedSearch->fetch()) {
82 // get name and description from group object
83 $group = new CRM_Contact_DAO_Group();
84 $group->saved_search_id
= $savedSearch->id
;
85 if ($group->find(TRUE)) {
86 $permissions = CRM_Contact_BAO_Group
::checkPermission($group->id
, TRUE);
87 if (!CRM_Utils_System
::isNull($permissions)) {
90 $row['name'] = $group->title
;
91 $row['description'] = $group->description
;
93 $row['id'] = $savedSearch->id
;
94 $formValues = unserialize($savedSearch->form_values
);
95 $query = new CRM_Contact_BAO_Query($formValues);
96 $row['query_detail'] = $query->qill();
98 $action = array_sum(array_keys(self
::links()));
99 $action = $action & CRM_Core_Action
::mask($permissions);
100 $row['action'] = CRM_Core_Action
::formLink(
103 array('id' => $row['id']),
106 'savedSearch.manage.action',
116 $this->assign('rows', $rows);
117 return parent
::run();
121 * Run this page (figure out the action needed and perform it).
123 public function run() {
124 $action = CRM_Utils_Request
::retrieve('action', 'String',
125 $this, FALSE, 'browse'
128 $this->assign('action', $action);
130 if ($action & CRM_Core_Action
::DELETE
) {
131 $id = CRM_Utils_Request
::retrieve('id', 'Positive',
143 * (reference) of action links
145 public static function &links() {
147 if (!(self
::$_links)) {
149 $deleteExtra = ts('Do you really want to remove this Smart Group?');
151 self
::$_links = array(
152 CRM_Core_Action
::VIEW
=> array(
153 'name' => ts('Search'),
154 'url' => 'civicrm/contact/search/advanced',
155 'qs' => 'reset=1&force=1&ssID=%%id%%',
156 'title' => ts('Search'),
158 CRM_Core_Action
::DELETE
=> array(
159 'name' => ts('Delete'),
160 'url' => 'civicrm/contact/search/saved',
161 'qs' => 'action=delete&id=%%id%%',
162 'extra' => 'onclick="return confirm(\'' . $deleteExtra . '\');"',
166 return self
::$_links;