mirror of
https://github.com/pierre42100/ComunicAPI
synced 2025-06-19 08:35:18 +00:00
Can update visibility level of an account image
This commit is contained in:
@ -105,7 +105,7 @@ class AccountImage {
|
||||
* @return int The visibility level of the account image
|
||||
*/
|
||||
public function getVisibilityLevel(int $userID) : int {
|
||||
$filePath = path_user_data(cs()->config->get(self::accountImageDirConfItem)."adresse_avatars/limit_view_".$userID.".txt", TRUE);
|
||||
$filePath = $this->getPathVisibilityFile($userID);
|
||||
|
||||
//Check restriction file
|
||||
if(!file_exists($filePath))
|
||||
@ -118,6 +118,31 @@ class AccountImage {
|
||||
return $fileContent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set (update) the visibility level of a an account image
|
||||
*
|
||||
* @param int $userID Target user ID
|
||||
* @param int $level New visibility level
|
||||
*/
|
||||
public function setVisibilityLevel(int $userID, int $level){
|
||||
|
||||
//Get the name of the file that contains visibility levels
|
||||
$file = $this->getPathVisibilityFile($userID);
|
||||
|
||||
//Check if the account image is publicy visible
|
||||
if($level == AccountImageSettings::VISIBILITY_OPEN){
|
||||
|
||||
//We do not need visibility file
|
||||
if(file_exists($file))
|
||||
unlink($file);
|
||||
|
||||
}
|
||||
|
||||
//Else append the new value to the file
|
||||
file_put_contents($file, $level);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get AccountImageSettings for an account
|
||||
*
|
||||
@ -207,6 +232,17 @@ class AccountImage {
|
||||
private function getPathMetadataFile(int $userID) : string {
|
||||
return path_user_data(cs()->config->get(self::accountImageDirConfItem)."adresse_avatars/".$userID.".txt", TRUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the system path of the file that contains visibility level restrictions
|
||||
*
|
||||
* @param int $userID The ID of the target user
|
||||
* @return string The sys path pointing on the file
|
||||
*/
|
||||
private function getPathVisibilityFile(int $userID) : string {
|
||||
return path_user_data(cs()->config->get(
|
||||
self::accountImageDirConfItem)."adresse_avatars/limit_view_".$userID.".txt", TRUE);
|
||||
}
|
||||
}
|
||||
|
||||
//Register class
|
||||
|
Reference in New Issue
Block a user