public function testSavePreferencesToDBAndResetPreferences()
 {
     $user = new User();
     $user->retrieve('1');
     $userPreference = new UserPreference($user);
     //create a Preference record, save it to DB
     $userPreference->setPreference('test', 'test val', 'test_category');
     $userPreference->savePreferencesToDB();
     //retrieve it back and verify
     $result = $userPreference->retrieve_by_string_fields(array('assigned_user_id' => $user->id, 'category' => 'test_category'));
     $this->assertTrue(isset($result->id));
     //reset the preferences and verify that it is deleted
     $userPreference->resetPreferences();
     $result = $userPreference->retrieve_by_string_fields(array('assigned_user_id' => $user->id, 'category' => 'test_category'));
     $this->assertEquals(null, $result);
 }
 /**
  * Delete a filter from previously used
  * @param RestService $api 
  * @param array $args 
  * @return array of formatted Beans
  */
 public function deleteUsed($api, $args)
 {
     $data = array();
     $user_preference = new UserPreference($GLOBALS['current_user']);
     $used_filters = $user_preference->getPreference($args['module_name'], 'filters');
     if (isset($args['record']) && !empty($args['record'])) {
         // if the record exists unset it
         $key = array_search($args['record'], $used_filters);
         if ($key !== false) {
             unset($used_filters[$key]);
         }
     } else {
         // delete them all
         $used_filters = array();
     }
     $user_preference->setPreference($args['module_name'], $used_filters, 'filters');
     $user_preference->savePreferencesToDB(true);
     if (!empty($used_filters)) {
         $beans = $this->loadFilters($used_filters);
         $data = $this->formatBeans($api, $args, $beans);
     }
     return $data;
 }
 /**
  * Alias for setPreference in modules/UserPreferences/UserPreference.php
  *    
  */
 function setPreference($name, $value, $nosession = 0, $category = 'global', $user = null)
 {
     if (isset($user)) {
         UserPreference::setPreference($name, $value, $nosession, $category, $user);
     } else {
         UserPreference::setPreference($name, $value, $nosession, $category, $this);
     }
 }