Esempio n. 1
0
 public function testMain()
 {
     $savedSearch = new SavedSearch();
     $savedSearch->name = 'test';
     $savedSearch->search_module = 'Leads';
     $savedSearch->save();
     //test for record ID to verify that record is saved
     $this->assertTrue(isset($savedSearch->id));
     $this->assertEquals(36, strlen($savedSearch->id));
     //test handleSave method
     $this->handleSaveAndRetrieveSavedSearch($savedSearch->id);
     //test returnSavedSearch method
     $this->returnSavedSearch($savedSearch->id);
     //test returnSavedSearchContents method
     $this->returnSavedSearchContents($savedSearch->id);
     //test handleDelete method
     $this->handleDelete($savedSearch->id);
 }
Esempio n. 2
0
 public function testGetByOwnerAndViewClassName()
 {
     $user = User::getByUsername('super');
     $steven = User::getByUsername('steven');
     $savedSearches = SavedSearch::getByOwnerAndViewClassName($user, 'someView');
     $this->assertEquals(0, count($savedSearches));
     $savedSearches = SavedSearch::getByOwnerAndViewClassName($steven, 'someView');
     $this->assertEquals(0, count($savedSearches));
     //create saved search for steven
     $savedSearch = new SavedSearch();
     $savedSearch->owner = $steven;
     $savedSearch->name = 'Test Saved Search';
     $savedSearch->serializedData = serialize(array('x', 'y'));
     $savedSearch->viewClassName = 'someView';
     $this->assertTrue($savedSearch->save());
     $savedSearches = SavedSearch::getByOwnerAndViewClassName($user, 'someView');
     $this->assertEquals(0, count($savedSearches));
     $savedSearches = SavedSearch::getByOwnerAndViewClassName($steven, 'someView');
     $this->assertEquals(1, count($savedSearches));
     $savedSearches = SavedSearch::getByOwnerAndViewClassName($steven, 'someView2');
     $this->assertEquals(0, count($savedSearches));
 }
Esempio n. 3
0
 function handleSave($prefix, $redirect = true, $useRequired = false, $id = null, $searchModuleBean)
 {
     global $current_user, $timedate;
     $focus = new SavedSearch();
     if ($id) {
         $focus->retrieve($id);
     }
     if ($useRequired && !checkRequired($prefix, array_keys($focus->required_fields))) {
         return null;
     }
     $ignored_inputs = array('PHPSESSID', 'module', 'action', 'saved_search_name', 'saved_search_select', 'advanced', 'Calls_divs', 'ACLRoles_divs');
     $contents = $_REQUEST;
     if ($id == null) {
         $focus->name = $contents['saved_search_name'];
     }
     $focus->search_module = $contents['search_module'];
     foreach ($contents as $input => $value) {
         if (in_array($input, $ignored_inputs)) {
             unset($contents[$input]);
             continue;
         }
         //Filter date fields to ensure it is saved to DB format, but also avoid empty values
         if (!empty($value) && preg_match('/^(start_range_|end_range_|range_)?(.*?)(_advanced|_basic)$/', $input, $match)) {
             $field = $match[2];
             if (isset($searchModuleBean->field_defs[$field]['type'])) {
                 $type = $searchModuleBean->field_defs[$field]['type'];
                 //Avoid macro values for the date types
                 if (($type == 'date' || $type == 'datetime' || $type == 'datetimecombo') && !preg_match('/^\\[.*?\\]$/', $value)) {
                     $db_format = $timedate->to_db_date($value, false);
                     $contents[$input] = $db_format;
                 } else {
                     if ($type == 'int' || $type == 'currency' || $type == 'decimal' || $type == 'float') {
                         if (preg_match('/[^\\d]/', $value)) {
                             require_once 'modules/Currencies/Currency.php';
                             $contents[$input] = unformat_number($value);
                             //Flag this value as having been unformatted
                             $contents[$input . '_unformatted_number'] = true;
                             //If the type is of currency and there was a currency symbol (non-digit), save the symbol
                             if ($type == 'currency' && preg_match('/^([^\\d])/', $value, $match)) {
                                 $contents[$input . '_currency_symbol'] = $match[1];
                             }
                         } else {
                             //unset any flags
                             if (isset($contents[$input . '_unformatted_number'])) {
                                 unset($contents[$input . '_unformatted_number']);
                             }
                             if (isset($contents[$input . '_currency_symbol'])) {
                                 unset($contents[$input . '_currency_symbol']);
                             }
                         }
                     }
                 }
             }
         }
     }
     $contents['advanced'] = true;
     $focus->contents = base64_encode(serialize($contents));
     $focus->assigned_user_id = $current_user->id;
     $focus->new_schema = true;
     $saved_search_id = $focus->save();
     $GLOBALS['log']->debug("Saved record with id of " . $focus->id);
     $orderBy = empty($contents['orderBy']) ? 'name' : $contents['orderBy'];
     $search_query = "&orderBy=" . $orderBy . "&sortOrder=" . $contents['sortOrder'] . "&query=" . $_REQUEST['query'] . "&searchFormTab=" . $_REQUEST['searchFormTab'] . '&showSSDIV=' . $contents['showSSDIV'];
     if ($redirect) {
         $this->handleRedirect($focus->search_module, $search_query, $saved_search_id, 'true');
     }
 }
 private function getSearchDataForSort()
 {
     $savedSearch = new SavedSearch();
     $savedSearch->name = 'something';
     $savedSearch->viewClassName = 'view';
     $savedSearch->serializedData = 'someString';
     $saved = $savedSearch->save();
     $searchModel = new AAASavedDynamicSearchFormTestModel(new AAA(false));
     $listAttributesSelector = new ListAttributesSelector('AListView', 'TestModule');
     $searchModel->setListAttributesSelector($listAttributesSelector);
     $searchModel->dynamicStructure = '1 and 5';
     $searchModel->dynamicClauses = array('a', 'b');
     $searchModel->anyMixedAttributes = 'abcdef';
     $searchModel->savedSearchId = $savedSearch->id;
     $searchModel->setAnyMixedAttributesScope('xyz');
     $searchModel->getListAttributesSelector()->setSelected(array('aaaMember', 'aaaMember2'));
     $dataCollection = new SavedSearchAttributesDataCollection($searchModel);
     return array('dataCollection' => $dataCollection, 'savedSearch' => $savedSearch);
 }
Esempio n. 5
0
 function handleSave($prefix, $redirect = true, $useRequired = false, $id = null)
 {
     global $current_user;
     $focus = new SavedSearch();
     if ($id) {
         $focus->retrieve($id);
     }
     if ($useRequired && !checkRequired($prefix, array_keys($focus->required_fields))) {
         return null;
     }
     $ignored_inputs = array('PHPSESSID', 'module', 'action', 'saved_search_name', 'saved_search_select', 'advanced', 'Calls_divs', 'ACLRoles_divs');
     $contents = $_REQUEST;
     if ($id == null) {
         $focus->name = $contents['saved_search_name'];
     }
     $focus->search_module = $contents['search_module'];
     foreach ($contents as $input => $value) {
         if (in_array($input, $ignored_inputs)) {
             unset($contents[$input]);
         }
     }
     $contents['advanced'] = true;
     $focus->contents = base64_encode(serialize($contents));
     $focus->assigned_user_id = $current_user->id;
     $focus->new_schema = true;
     $saved_search_id = $focus->save();
     $GLOBALS['log']->debug("Saved record with id of " . $focus->id);
     $orderBy = empty($contents['orderBy']) ? 'name' : $contents['orderBy'];
     $search_query = "&orderBy=" . $orderBy . "&sortOrder=" . $contents['sortOrder'] . "&query=" . $_REQUEST['query'] . "&searchFormTab=" . $_REQUEST['searchFormTab'] . '&showSSDIV=' . $contents['showSSDIV'];
     $this->handleRedirect($focus->search_module, $search_query, $saved_search_id, 'true');
 }
 public function saveSearch()
 {
     $this->layout->body_class = 'user';
     $title = Input::get('title', '');
     $filter = Input::get('filter', '');
     $location = Input::get('location', '');
     $query = Input::get('query', '');
     if (Auth::check()) {
         $search = new SavedSearch();
         $search->title = $title;
         $search->filter = $filter;
         $search->location = $location;
         $search->query = $query;
         $search->user = Auth::user()->id;
         $search->datetime = date("Y-m-d H:i:s");
         $search->save();
     }
 }
 function handleSave($prefix, $redirect = true, $useRequired = false, $id = null)
 {
     require_once 'log4php/LoggerManager.php';
     global $current_user;
     $focus = new SavedSearch();
     if ($id) {
         $focus->retrieve($id);
     }
     if ($useRequired && !checkRequired($prefix, array_keys($focus->required_fields))) {
         return null;
     }
     $ignored_inputs = array('PHPSESSID', 'module', 'action', 'saved_search_name', 'saved_search_select', 'advanced');
     $contents = array_merge($_POST, $_GET);
     if ($id == null) {
         $focus->name = $contents['saved_search_name'];
     }
     $focus->search_module = $contents['search_module'];
     foreach ($contents as $input => $value) {
         if (in_array($input, $ignored_inputs)) {
             unset($contents[$input]);
         }
     }
     $contents['advanced'] = true;
     $focus->contents = base64_encode(serialize($contents));
     $focus->assigned_user_id = $current_user->id;
     $focus->new_schema = true;
     $focus->search_module = $focus->search_module;
     $saved_search_id = $focus->save();
     $GLOBALS['log']->debug("Saved record with id of " . $focus->id);
     $search_query = '';
     foreach ($contents as $input => $value) {
         if (is_array($value)) {
             // handle multiselects
             foreach ($value as $v) {
                 $search_query .= $input . '[]=' . $v . '&';
             }
         } else {
             $search_query .= $input . '=' . $value . '&';
         }
     }
     $this->handleRedirect($focus->search_module, $search_query, $saved_search_id, 'true');
 }