mirror of
https://github.com/pierre42100/ComunicAPI
synced 2024-11-27 15:59:29 +00:00
Can get account image settings through the API
This commit is contained in:
parent
e71372de60
commit
7400989afe
@ -7,6 +7,15 @@
|
|||||||
|
|
||||||
class SettingsController {
|
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
|
* Get general account settings
|
||||||
*
|
*
|
||||||
@ -187,6 +196,23 @@ class SettingsController {
|
|||||||
return array("success" => "The password has been updated !");
|
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
|
* Turn a GeneralSettings object into a valid API object
|
||||||
*
|
*
|
||||||
@ -232,4 +258,22 @@ class SettingsController {
|
|||||||
return $data;
|
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;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -29,13 +29,13 @@ class AccountImage {
|
|||||||
* @return string The URL pointing on the account image
|
* @return string The URL pointing on the account image
|
||||||
*/
|
*/
|
||||||
public function getFile(int $userID) : string {
|
public function getFile(int $userID) : string {
|
||||||
|
|
||||||
//First, check if the account image exists
|
//First, check if the account image exists
|
||||||
$accountImageFileName = $this->getFileAccountImage($userID);
|
$accountImageFileName = $this->getFileAccountImage($userID);
|
||||||
if($accountImageFileName != ""){
|
if($accountImageFileName != ""){
|
||||||
|
|
||||||
//Get account image visibility level
|
//Get account image visibility level
|
||||||
$visibilityLevel = $this->visibilityLevel($userID);
|
$visibilityLevel = $this->getVisibilityLevel($userID);
|
||||||
|
|
||||||
//If account image is open or if the user signed in is the user making the request
|
//If account image is open or if the user signed in is the user making the request
|
||||||
if($visibilityLevel == AccountImageSettings::VISIBILITY_OPEN || userID == $userID)
|
if($visibilityLevel == AccountImageSettings::VISIBILITY_OPEN || userID == $userID)
|
||||||
@ -64,6 +64,16 @@ class AccountImage {
|
|||||||
return self::defaultAccountImage;
|
return self::defaultAccountImage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the path to an account image
|
||||||
|
*
|
||||||
|
* @param int $userID Target user ID
|
||||||
|
* @return string $url The URL of the account image
|
||||||
|
*/
|
||||||
|
public function getPath(int $userID) : string {
|
||||||
|
return cs()->config->get(self::accountImageDirConfItem).$this->getFile($userID);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the URL to an account image
|
* Returns the URL to an account image
|
||||||
*
|
*
|
||||||
@ -71,7 +81,17 @@ class AccountImage {
|
|||||||
* @return string $url The URL of the account image
|
* @return string $url The URL of the account image
|
||||||
*/
|
*/
|
||||||
public function getURL(int $userID) : string {
|
public function getURL(int $userID) : string {
|
||||||
return path_user_data(cs()->config->get(self::accountImageDirConfItem).$this->getFile($userID));
|
return path_user_data($this->getPath($userID));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check whether a user has an account image or not
|
||||||
|
*
|
||||||
|
* @param int $userID Target user ID
|
||||||
|
* @return bool TRUE if the user has an account image / FALSE else
|
||||||
|
*/
|
||||||
|
public function has(int $userID) : bool {
|
||||||
|
return $this->getFileAccountImage($userID) != "";
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -84,7 +104,7 @@ class AccountImage {
|
|||||||
* @param int $userID The ID of the user on which we perform researchs
|
* @param int $userID The ID of the user on which we perform researchs
|
||||||
* @return int The visibility level of the account image
|
* @return int The visibility level of the account image
|
||||||
*/
|
*/
|
||||||
private function visibilityLevel(int $userID) : int {
|
public function getVisibilityLevel(int $userID) : int {
|
||||||
$filePath = path_user_data(cs()->config->get(self::accountImageDirConfItem)."adresse_avatars/limit_view_".$userID.".txt", TRUE);
|
$filePath = path_user_data(cs()->config->get(self::accountImageDirConfItem)."adresse_avatars/limit_view_".$userID.".txt", TRUE);
|
||||||
|
|
||||||
//Check restriction file
|
//Check restriction file
|
||||||
@ -98,6 +118,26 @@ class AccountImage {
|
|||||||
return $fileContent;
|
return $fileContent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get AccountImageSettings for an account
|
||||||
|
*
|
||||||
|
* @param int $userID ID of the target user
|
||||||
|
* @return AccountImageSettings Generated account settings object
|
||||||
|
*/
|
||||||
|
public function getSettings(int $userID) : AccountImageSettings {
|
||||||
|
|
||||||
|
//Create and fill UserAccountImage object
|
||||||
|
$settings = new AccountImageSettings();
|
||||||
|
|
||||||
|
//Add user account image (if any)
|
||||||
|
if($this->has(userID)){
|
||||||
|
$settings->set_image_path($this->getPath(userID));
|
||||||
|
}
|
||||||
|
$settings->set_visibility_level($this->getVisibilityLevel(userID));
|
||||||
|
|
||||||
|
return $settings;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the file to the user account image, if the user has any
|
* Get the file to the user account image, if the user has any
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user