/**
  * Update default user preferences
  *
  */
 function update_default_user_preferences()
 {
     $category = UserWsConfigCategories::findById(get_id());
     if (!$category instanceof UserWsConfigCategory) {
         flash_error(lang('config category dnx'));
         $this->redirectToReferer(get_url('user', 'card'));
     }
     // if
     if ($category->isEmpty()) {
         flash_error(lang('config category is empty'));
         $this->redirectToReferer(get_url('user', 'card'));
     }
     // if
     $options = $category->getUserWsOptions(false);
     $categories = UserWsConfigCategories::getAll(false);
     tpl_assign('category', $category);
     tpl_assign('options', $options);
     tpl_assign('config_categories', $categories);
     $submited_values = array_var($_POST, 'options');
     if (is_array($submited_values)) {
         try {
             DB::beginWork();
             foreach ($options as $option) {
                 $new_value = array_var($submited_values, $option->getName());
                 if (is_null($new_value) || $new_value == $option->getValue()) {
                     continue;
                 }
                 $option->setValue($new_value);
                 $option->save();
                 if (!user_has_config_option($option->getName())) {
                     evt_add('user preference changed', array('name' => $option->getName(), 'value' => $new_value));
                     // update global cache if available
                     if (GlobalCache::isAvailable() && GlobalCache::key_exists('user_config_option_def_' . $option->getName())) {
                         GlobalCache::update('user_config_option_def_' . $option->getName(), $new_value);
                     }
                 }
             }
             // foreach
             DB::commit();
             flash_success(lang('success update config value', $category->getDisplayName()));
             ajx_current("back");
         } catch (Exception $ex) {
             DB::rollback();
             flash_success(lang('error update config value', $category->getDisplayName()));
         }
     }
     // if
 }
 /**
  * Return manager instance
  *
  * @access protected
  * @param void
  * @return UserWsConfigCategories 
  */
 function manager()
 {
     if (!$this->manager instanceof UserWsConfigCategories) {
         $this->manager = UserWsConfigCategories::instance();
     }
     return $this->manager;
 }
 /**
  * This function will return paginated result. Result is an array where first element is 
  * array of returned object and second populated pagination object that can be used for 
  * obtaining and rendering pagination data using various helpers.
  * 
  * Items and pagination array vars are indexed with 0 for items and 1 for pagination
  * because you can't use associative indexing with list() construct
  *
  * @access public
  * @param array $arguments Query argumens (@see find()) Limit and offset are ignored!
  * @param integer $items_per_page Number of items per page
  * @param integer $current_page Current page number
  * @return array
  */
 function paginate($arguments = null, $items_per_page = 10, $current_page = 1)
 {
     if (isset($this) && instance_of($this, 'UserWsConfigCategories')) {
         return parent::paginate($arguments, $items_per_page, $current_page);
     } else {
         return UserWsConfigCategories::instance()->paginate($arguments, $items_per_page, $current_page);
         //$instance =& ConfigCategories::instance();
         //return $instance->paginate($arguments, $items_per_page, $current_page);
     }
     // if
 }