3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
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-2015
37 * Main page for viewing all Saved searches.
40 class CRM_Contact_Page_SavedSearch
extends CRM_Core_Page
{
43 * The action links that we need to display for the browse screen.
47 static $_links = NULL;
50 * Delete a saved search.
57 public function delete($id) {
58 // first delete the group associated with this saved search
59 $group = new CRM_Contact_DAO_Group();
60 $group->saved_search_id
= $id;
61 if ($group->find(TRUE)) {
62 CRM_Contact_BAO_Group
::discard($group->id
);
65 $savedSearch = new CRM_Contact_DAO_SavedSearch();
66 $savedSearch->id
= $id;
67 $savedSearch->is_active
= 0;
72 * Browse all saved searches.
75 * content of the parents run method
77 public function browse() {
80 $savedSearch = new CRM_Contact_DAO_SavedSearch();
81 $savedSearch->is_active
= 1;
82 $savedSearch->selectAdd();
83 $savedSearch->selectAdd('id, form_values');
85 $properties = array('id', 'name', 'description');
86 while ($savedSearch->fetch()) {
87 // get name and description from group object
88 $group = new CRM_Contact_DAO_Group();
89 $group->saved_search_id
= $savedSearch->id
;
90 if ($group->find(TRUE)) {
91 $permissions = CRM_Group_Page_Group
::checkPermission($group->id
, $group->title
);
92 if (!CRM_Utils_System
::isNull($permissions)) {
95 $row['name'] = $group->title
;
96 $row['description'] = $group->description
;
98 $row['id'] = $savedSearch->id
;
99 $formValues = unserialize($savedSearch->form_values
);
100 $query = new CRM_Contact_BAO_Query($formValues);
101 $row['query_detail'] = $query->qill();
103 $action = array_sum(array_keys(self
::links()));
104 $action = $action & CRM_Core_Action
::mask($permissions);
105 $row['action'] = CRM_Core_Action
::formLink(
108 array('id' => $row['id']),
111 'savedSearch.manage.action',
121 $this->assign('rows', $rows);
122 return parent
::run();
126 * Run this page (figure out the action needed and perform it).
130 public function run() {
131 $action = CRM_Utils_Request
::retrieve('action', 'String',
132 $this, FALSE, 'browse'
135 $this->assign('action', $action);
137 if ($action & CRM_Core_Action
::DELETE
) {
138 $id = CRM_Utils_Request
::retrieve('id', 'Positive',
150 * (reference) of action links
152 public static function &links() {
154 if (!(self
::$_links)) {
156 $deleteExtra = ts('Do you really want to remove this Smart Group?');
158 self
::$_links = array(
159 CRM_Core_Action
::VIEW
=> array(
160 'name' => ts('Search'),
161 'url' => 'civicrm/contact/search/advanced',
162 'qs' => 'reset=1&force=1&ssID=%%id%%',
163 'title' => ts('Search'),
165 CRM_Core_Action
::DELETE
=> array(
166 'name' => ts('Delete'),
167 'url' => 'civicrm/contact/search/saved',
168 'qs' => 'action=delete&id=%%id%%',
169 'extra' => 'onclick="return confirm(\'' . $deleteExtra . '\');"',
173 return self
::$_links;