コード例 #1
0
	/**
	 * List user preferences
	 *
	 */
	function update_user_preferences(){
		$category = ContactConfigCategories::findById(get_id());
		if(!($category instanceof ContactConfigCategory)) {
			flash_error(lang('config category dnx'));
			$this->redirectToReferer(get_url('contact','card'));
		} // if

		if($category->isEmpty()) {
			flash_error(lang('config category is empty'));
			$this->redirectToReferer(get_url('contact','card'));
		} // if

		$options = $category->getContactOptions(false);
		$categories = ContactConfigCategories::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) {
					// update cache if available
					if (GlobalCache::isAvailable()) {
						GlobalCache::delete('user_config_option_'.logged_user()->getId().'_'.$option->getName());
					}
					if($option->getName() == "reminders_events" || $option->getName() == "reminders_tasks"){
						$array_value = array_var($submited_values, $option->getName());
						$new_value = array_var($array_value,"reminder_type") . "," . array_var($array_value,"reminder_duration") . "," . array_var($array_value,"reminder_duration_type");
					}else{
						$new_value = array_var($submited_values, $option->getName());
					}
					
					if(is_null($new_value) || ($new_value == $option->getContactValue(logged_user()->getId()))) continue;
	
					$option->setContactValue($new_value, logged_user()->getId());
					$option->save();
					evt_add("user preference changed", array('name' => $option->getName(), 'value' => $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
	} //list_preferences
コード例 #2
0
 /**
  * Update default user preferences
  *
  */
 function update_default_user_preferences()
 {
     $category = ContactConfigCategories::findById(get_id());
     if (!$category instanceof ContactConfigCategory) {
         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->getContactOptions(false);
     $categories = ContactConfigCategories::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) {
                 // update global cache if available
                 if (GlobalCache::isAvailable()) {
                     GlobalCache::delete('user_config_option_def_' . $option->getName());
                 }
                 $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));
                 }
             }
             // 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
 }
コード例 #3
0
 /**
  * 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, 'ContactConfigCategories')) {
         return parent::paginate($arguments, $items_per_page, $current_page);
     } else {
         return ContactConfigCategories::instance()->paginate($arguments, $items_per_page, $current_page);
     }
     // if
 }
コード例 #4
0
 /**
 * Return manager instance
 *
 * @access protected
 * @param void
 * @return ContactConfigCategories 
 */
 function manager() {
   if(!($this->manager instanceof ContactConfigCategories)) $this->manager = ContactConfigCategories::instance();
   return $this->manager;
 } // manager