mirror of
https://github.com/pierre42100/ComunicAPI
synced 2024-12-24 12:38:58 +00:00
Can get advanced informations about a user.
This commit is contained in:
parent
1a0a812519
commit
9beca55ad1
@ -127,7 +127,15 @@ class userController
|
||||
if(!CS::get()->components->user->userAllowed(userID, $userID))
|
||||
Rest_fatal_error(401, "You are not allowed to access these information !");
|
||||
|
||||
echo "ok";
|
||||
//Get user informations
|
||||
$userInfos = CS::get()->components->user->getUserInfos($userID, true);
|
||||
|
||||
//Check if we got a response
|
||||
if(count($userInfos) == 0)
|
||||
Rest_fatal_error(500, "Couldn't get informations about the user !");
|
||||
|
||||
//Return user informations
|
||||
return $userInfos;
|
||||
|
||||
}
|
||||
|
||||
|
57
classes/components/backgroundImage.php
Normal file
57
classes/components/backgroundImage.php
Normal file
@ -0,0 +1,57 @@
|
||||
<?php
|
||||
/**
|
||||
* User background image class
|
||||
*
|
||||
* @author Pierre HUBERT
|
||||
*/
|
||||
class BackgroundImage {
|
||||
|
||||
/**
|
||||
* @var String Base folder path for account image
|
||||
*/
|
||||
private $files_path;
|
||||
|
||||
/**
|
||||
* @var String Base URL for account images
|
||||
*/
|
||||
private $files_url;
|
||||
|
||||
/**
|
||||
* @var String Default background image
|
||||
*/
|
||||
private $defaultFile = "0.jpg";
|
||||
|
||||
/**
|
||||
* Constructor of the class
|
||||
*/
|
||||
public function __construct(){
|
||||
//Set values
|
||||
$this->files_path = path_user_data(CS::get()->config->get("backgroundImagePath"), true);
|
||||
$this->files_url = path_user_data(CS::get()->config->get("backgroundImagePath"), false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the path of a background image
|
||||
*
|
||||
* @param Integer $userID The ID of the user on which we perform research
|
||||
* @return String The URL pointing on the background image
|
||||
*/
|
||||
public function getPath(int $userID) : string {
|
||||
//First, check if the background image exists
|
||||
$backgroundImageRefFile = $this->files_path."adresse_imgfond/".$userID.".txt";
|
||||
if(file_exists($backgroundImageRefFile)){
|
||||
|
||||
//Get background image path and return it
|
||||
return $this->files_url.file_get_contents($backgroundImageRefFile);
|
||||
|
||||
}
|
||||
else {
|
||||
//Return default background image
|
||||
return $this->files_url.$this->defaultFile;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//Register class
|
||||
Components::register("backgroundImage", new BackgroundImage());
|
@ -162,9 +162,10 @@ class User{
|
||||
* Get Single User Infos
|
||||
*
|
||||
* @param Integer $userID The user ID
|
||||
* @param $advanced Get advanced informations about user, for its page for example
|
||||
* @return Array The result of the function (user informations) (empty one if it fails)
|
||||
*/
|
||||
public function getUserInfos($userID) : array {
|
||||
public function getUserInfos($userID, bool $advanced = false) : array {
|
||||
//Prepare database request
|
||||
$tablesName = $this->userTable;
|
||||
$conditions = "WHERE utilisateurs.ID = ?";
|
||||
@ -180,7 +181,7 @@ class User{
|
||||
return array(); //No result
|
||||
|
||||
//Return result
|
||||
return $this->generateUserInfosArray($userInfos[0]);
|
||||
return $this->generateUserInfosArray($userInfos[0], $advanced);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -222,9 +223,10 @@ class User{
|
||||
* given the database entry
|
||||
*
|
||||
* @param Array $userInfos The user entry in the database
|
||||
* @param $advanced Get advanced informations about user or not (to display its profile for example)
|
||||
* @return Array The informations ready to be returned
|
||||
*/
|
||||
private function generateUserInfosArray(array $userInfos) : array{
|
||||
private function generateUserInfosArray(array $userInfos, bool $advanced) : array{
|
||||
//Prepare return
|
||||
$return = array();
|
||||
$return['userID'] = $userInfos['ID'];
|
||||
@ -242,9 +244,13 @@ class User{
|
||||
//Add account image url
|
||||
$return['accountImage'] = CS::get()->components->accountImage->getPath($return['userID']);
|
||||
|
||||
//Only the user may get its mail address
|
||||
if(userID === $return['userID'])
|
||||
$return['mailAdress'] = $userInfos['mail'];
|
||||
//Check if we have to fetch advanced informations
|
||||
if($advanced){
|
||||
|
||||
//Add background image url
|
||||
$return['backgroundImage'] = CS::get()->components->backgroundImage->getPath($return['userID']);
|
||||
|
||||
}
|
||||
|
||||
//Return result
|
||||
return $return;
|
||||
|
@ -8,4 +8,9 @@
|
||||
/**
|
||||
* The subdirectory (of user_data folder) containing image accounts
|
||||
*/
|
||||
$config->set("imageAccountPath", "avatars/");
|
||||
$config->set("imageAccountPath", "avatars/");
|
||||
|
||||
/**
|
||||
* The subdirectory (of user_data folder) containing background images
|
||||
*/
|
||||
$config->set("backgroundImagePath", "imgfond/");
|
Loading…
Reference in New Issue
Block a user