diff --git a/classes/components/accountImage.php b/classes/components/accountImage.php index 333fefc..ae7b008 100644 --- a/classes/components/accountImage.php +++ b/classes/components/accountImage.php @@ -12,8 +12,14 @@ class accountImage{ //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"); } } diff --git a/classes/user.php b/classes/user.php index 6175eb4..3462bc1 100644 --- a/classes/user.php +++ b/classes/user.php @@ -161,26 +161,38 @@ class User{ if(count($userInfos) == 0) 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 $return = array(); - $return['userID'] = $userInfos[0]['ID']; - $return['firstName'] = $userInfos[0]['prenom']; - $return['lastName'] = $userInfos[0]['nom']; - $return['accountCreationDate'] = $userInfos[0]['date_creation']; - $return['publicPage'] = $userInfos[0]['public']; - $return['openPage'] = $userInfos[0]['pageouverte']; - $return['allowPostFromFriendOnHisPage'] = $userInfos[0]['autoriser_post_amis']; - $return['noCommentOnHisPage'] = $userInfos[0]['bloquecommentaire']; - $return['virtualDirectory'] = $userInfos[0]['sous_repertoire']; - $return['personnalWebsite'] = $userInfos[0]['site_web']; - $return['isPublicFriendList'] = $userInfos[0]['liste_amis_publique']; + $return['userID'] = $userInfos['ID']; + $return['firstName'] = $userInfos['prenom']; + $return['lastName'] = $userInfos['nom']; + $return['accountCreationDate'] = $userInfos['date_creation']; + $return['publicPage'] = $userInfos['public']; + $return['openPage'] = $userInfos['pageouverte']; + $return['allowPostFromFriendOnHisPage'] = $userInfos['autoriser_post_amis']; + $return['noCommentOnHisPage'] = $userInfos['bloquecommentaire']; + $return['virtualDirectory'] = $userInfos['sous_repertoire']; + $return['personnalWebsite'] = $userInfos['site_web']; + $return['isPublicFriendList'] = $userInfos['liste_amis_publique']; //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 - if(userID === $userID) - $return['mailAdress'] = $userInfos[0]['mail']; + if(userID === $return['userID']) + $return['mailAdress'] = $userInfos['mail']; //Return result return $return; diff --git a/config/userdata.php b/config/userdata.php new file mode 100644 index 0000000..cd05f69 --- /dev/null +++ b/config/userdata.php @@ -0,0 +1,11 @@ +set("imageAccountPath", "avatars/"); \ No newline at end of file diff --git a/helpers/userData.php b/helpers/userData.php index fe3e234..e23051a 100644 --- a/helpers/userData.php +++ b/helpers/userData.php @@ -9,18 +9,23 @@ * Get and returns the URL path to an userdata 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 */ -function path_user_data($fileURI = ""){ - return CS::get()->config->get("storage_url").$fileURI; +function path_user_data($fileURI = "", $systemPath = false){ + if(!$systemPath) + 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 * * @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 */ -function path_account_image($imageURI=""){ - return path_user_data("avatars/".$imageURI); +function path_account_image($imageURI="", $systemPath = false){ + return path_user_data(CS::get()->config->get("imageAccountPath").$imageURI, $systemPath); } \ No newline at end of file