Updated helpers

This commit is contained in:
Pierre 2017-05-26 09:50:20 +02:00
parent 7a393b1644
commit 78e72542d8
4 changed files with 54 additions and 20 deletions

View File

@ -12,8 +12,14 @@ class accountImage{
//Nothing now //Nothing now
} }
public function test(){ /**
return "test"; * Returns the path of an account image
*
* @param Integer $userID The ID of the user on which we perform research
* @return String The URL pointing on the avatar
*/
public function getPath($userID){
return path_account_image("0Reverse.png");
} }
} }

View File

@ -161,26 +161,38 @@ class User{
if(count($userInfos) == 0) if(count($userInfos) == 0)
return array(); //No result return array(); //No result
//Return result
return $this->generateUserInfosArray($userInfos[0]);
}
/**
* Generate and return an array containing informations about a user
* given the database entry
*
* @param Array $userInfos The user entry in the database
* @return Array The informations ready to be returned
*/
private function generateUserInfosArray(array $userInfos) : array{
//Prepare return //Prepare return
$return = array(); $return = array();
$return['userID'] = $userInfos[0]['ID']; $return['userID'] = $userInfos['ID'];
$return['firstName'] = $userInfos[0]['prenom']; $return['firstName'] = $userInfos['prenom'];
$return['lastName'] = $userInfos[0]['nom']; $return['lastName'] = $userInfos['nom'];
$return['accountCreationDate'] = $userInfos[0]['date_creation']; $return['accountCreationDate'] = $userInfos['date_creation'];
$return['publicPage'] = $userInfos[0]['public']; $return['publicPage'] = $userInfos['public'];
$return['openPage'] = $userInfos[0]['pageouverte']; $return['openPage'] = $userInfos['pageouverte'];
$return['allowPostFromFriendOnHisPage'] = $userInfos[0]['autoriser_post_amis']; $return['allowPostFromFriendOnHisPage'] = $userInfos['autoriser_post_amis'];
$return['noCommentOnHisPage'] = $userInfos[0]['bloquecommentaire']; $return['noCommentOnHisPage'] = $userInfos['bloquecommentaire'];
$return['virtualDirectory'] = $userInfos[0]['sous_repertoire']; $return['virtualDirectory'] = $userInfos['sous_repertoire'];
$return['personnalWebsite'] = $userInfos[0]['site_web']; $return['personnalWebsite'] = $userInfos['site_web'];
$return['isPublicFriendList'] = $userInfos[0]['liste_amis_publique']; $return['isPublicFriendList'] = $userInfos['liste_amis_publique'];
//Add account image url //Add account image url
$return['accountImage'] = path_account_image("0Reverse.png"); $return['accountImage'] = CS::get()->components->accountImage->getPath($return['userID']);
//Only the user may get its mail address //Only the user may get its mail address
if(userID === $userID) if(userID === $return['userID'])
$return['mailAdress'] = $userInfos[0]['mail']; $return['mailAdress'] = $userInfos['mail'];
//Return result //Return result
return $return; return $return;

11
config/userdata.php Normal file
View File

@ -0,0 +1,11 @@
<?php
/**
* User data configuration file
*
* @author Pierre HUBERT
*/
/**
* The subdirectory (of user_data folder) containing image accounts
*/
$config->set("imageAccountPath", "avatars/");

View File

@ -9,18 +9,23 @@
* Get and returns the URL path to an userdata file * Get and returns the URL path to an userdata file
* *
* @param String $fileURI Optionnal, defines the URI pointing on the file * @param String $fileURI Optionnal, defines the URI pointing on the file
* @param Boolean $systemPath Optionnal, defines if system path is required instead of URL
* @return String The full URL to the userdata file * @return String The full URL to the userdata file
*/ */
function path_user_data($fileURI = ""){ function path_user_data($fileURI = "", $systemPath = false){
if(!$systemPath)
return CS::get()->config->get("storage_url").$fileURI; return CS::get()->config->get("storage_url").$fileURI;
else
return CS::get()->config->get("storage_path").$fileURI;
} }
/** /**
* Get and return the URL path to a specified account image * Get and return the URL path to a specified account image
* *
* @param String $imageURI Optionnal, defines URI of the image * @param String $imageURI Optionnal, defines URI of the image
* @param Boolean $systemPath Optionnal, defines if system path is required instead of URL
* @return String The full URL to the image account file * @return String The full URL to the image account file
*/ */
function path_account_image($imageURI=""){ function path_account_image($imageURI="", $systemPath = false){
return path_user_data("avatars/".$imageURI); return path_user_data(CS::get()->config->get("imageAccountPath").$imageURI, $systemPath);
} }