mirror of
				https://github.com/pierre42100/ComunicAPI
				synced 2025-11-03 19:54:14 +00:00 
			
		
		
		
	Can get account image settings through the API
This commit is contained in:
		@@ -7,6 +7,15 @@
 | 
			
		||||
 | 
			
		||||
class SettingsController {
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Account image visibility levels for the API
 | 
			
		||||
	 */
 | 
			
		||||
	const AccountImageVisibilityLevels = array(
 | 
			
		||||
		AccountImageSettings::VISIBILITY_OPEN => "open",
 | 
			
		||||
		AccountImageSettings::VISIBILITY_PUBLIC => "public",
 | 
			
		||||
		AccountImageSettings::VISIBILITY_FRIENDS => "friends"
 | 
			
		||||
	);
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Get general account settings
 | 
			
		||||
	 * 
 | 
			
		||||
@@ -187,6 +196,23 @@ class SettingsController {
 | 
			
		||||
		return array("success" => "The password has been updated !");
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Get account image information
 | 
			
		||||
	 * 
 | 
			
		||||
	 * @url POST /settings/get_account_image
 | 
			
		||||
	 */
 | 
			
		||||
	public function getAccountImageSettings(){
 | 
			
		||||
 | 
			
		||||
		//User login required
 | 
			
		||||
		user_login_required();
 | 
			
		||||
 | 
			
		||||
		//Get the settings of the user
 | 
			
		||||
		$settings = components()->accountImage->getSettings(userID);
 | 
			
		||||
 | 
			
		||||
		//Return parsed settings object
 | 
			
		||||
		return $this->AccountImageSettingsToAPI($settings);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Turn a GeneralSettings object into a valid API object
 | 
			
		||||
	 * 
 | 
			
		||||
@@ -232,4 +258,22 @@ class SettingsController {
 | 
			
		||||
		return $data;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Turn a AccountImageSettings object into API object
 | 
			
		||||
	 * 
 | 
			
		||||
	 * @param AccountImageSettings $settings The settings object to convert
 | 
			
		||||
	 * @return array Generated API object
 | 
			
		||||
	 */
 | 
			
		||||
	private function AccountImageSettingsToAPI(AccountImageSettings $settings) : array {
 | 
			
		||||
 | 
			
		||||
		$data = array();
 | 
			
		||||
 | 
			
		||||
		$data["has_image"] = $settings->has_image_path();
 | 
			
		||||
		$data["image_url"] = $settings->has_image_path() ? path_user_data($settings->get_image_path()) : null;
 | 
			
		||||
		$data["visibility"] = self::AccountImageVisibilityLevels[$settings->get_visibility_level()];
 | 
			
		||||
 | 
			
		||||
		return $data;
 | 
			
		||||
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user