saved_search_id = $id; if ($group->find(TRUE)) { CRM_Contact_BAO_Group::discard($group->id); } $savedSearch = new CRM_Contact_DAO_SavedSearch(); $savedSearch->id = $id; $savedSearch->is_active = 0; $savedSearch->save(); return; } /** * Browse all saved searches. * * @return content of the parents run method * */ function browse() { $rows = array(); $savedSearch = new CRM_Contact_DAO_SavedSearch(); $savedSearch->is_active = 1; $savedSearch->selectAdd(); $savedSearch->selectAdd('id, form_values'); $savedSearch->find(); $properties = array('id', 'name', 'description'); while ($savedSearch->fetch()) { // get name and description from group object $group = new CRM_Contact_DAO_Group(); $group->saved_search_id = $savedSearch->id; if ($group->find(TRUE)) { $permissions = CRM_Group_Page_Group::checkPermission($group->id, $group->title); if (!CRM_Utils_System::isNull($permissions)) { $row = array(); $row['name'] = $group->title; $row['description'] = $group->description; $row['id'] = $savedSearch->id; $formValues = unserialize($savedSearch->form_values); $query = new CRM_Contact_BAO_Query($formValues); $row['query_detail'] = $query->qill(); $action = array_sum(array_keys(self::links())); $action = $action & CRM_Core_Action::mask($permissions); $row['action'] = CRM_Core_Action::formLink( self::links(), $action, array('id' => $row['id']), ts('more'), FALSE, 'savedSearch.manage.action', 'SavedSearch', $row['id'] ); $rows[] = $row; } } } $this->assign('rows', $rows); return parent::run(); } /** * run this page (figure out the action needed and perform it). * * @return void */ function run() { $action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'browse' ); $this->assign('action', $action); if ($action & CRM_Core_Action::DELETE) { $id = CRM_Utils_Request::retrieve('id', 'Positive', $this, TRUE ); $this->delete($id); } $this->browse(); } /** * Get action Links * * @return array (reference) of action links * @static */ static function &links() { if (!(self::$_links)) { $deleteExtra = ts('Do you really want to remove this Smart Group?'); self::$_links = array( CRM_Core_Action::VIEW => array( 'name' => ts('Search'), 'url' => 'civicrm/contact/search/advanced', 'qs' => 'reset=1&force=1&ssID=%%id%%', 'title' => ts('Search'), ), CRM_Core_Action::DELETE => array( 'name' => ts('Delete'), 'url' => 'civicrm/contact/search/saved', 'qs' => 'action=delete&id=%%id%%', 'extra' => 'onclick="return confirm(\'' . $deleteExtra . '\');"', ), ); } return self::$_links; } }