mirror of
				https://github.com/pierre42100/ComunicAPI
				synced 2025-11-04 12:14:12 +00:00 
			
		
		
		
	Delete deprecated generateUserInfosArray method
This commit is contained in:
		@@ -41,25 +41,30 @@ class userController
 | 
				
			|||||||
		//Check if it is a wide request or not
 | 
							//Check if it is a wide request or not
 | 
				
			||||||
		if(count($usersID) <= 10)
 | 
							if(count($usersID) <= 10)
 | 
				
			||||||
			//Try to get user infos
 | 
								//Try to get user infos
 | 
				
			||||||
			$userInfos = CS::get()->components->user->getMultipleUserInfos($usersID);
 | 
								$usersInfo = CS::get()->components->user->getMultipleUserInfos($usersID);
 | 
				
			||||||
		else {
 | 
							else {
 | 
				
			||||||
			//Divide request in multiples ones
 | 
								//Divide request in multiples ones
 | 
				
			||||||
			$userInfos = array();
 | 
								$usersInfo = array();
 | 
				
			||||||
			foreach(array_chunk($usersID, 10) as $process_users_ID){
 | 
								foreach(array_chunk($usersID, 10) as $process_users_ID){
 | 
				
			||||||
				
 | 
									
 | 
				
			||||||
				//Get informations about the IDS
 | 
									//Get informations about the IDS
 | 
				
			||||||
				foreach(CS::get()->components->user->getMultipleUserInfos($process_users_ID) as $key=>$val){
 | 
									foreach(CS::get()->components->user->getMultipleUserInfos($process_users_ID) as $key=>$val){
 | 
				
			||||||
					$userInfos[$key] = $val;
 | 
										$usersInfo[$key] = $val;
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
		//Check if response is empty
 | 
							//Check if response is empty
 | 
				
			||||||
		if(count($userInfos) == 0)
 | 
							if(count($usersInfo) == 0)
 | 
				
			||||||
			throw new RestException(401, "Couldn't get user data !");
 | 
								throw new RestException(401, "Couldn't get user data !");
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
 | 
							//Parse User objects into API-readable objects
 | 
				
			||||||
 | 
							foreach($usersInfo as $num=>$info){
 | 
				
			||||||
 | 
								$usersInfo[$num] = $this->userToAPI($info);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		//Return result
 | 
							//Return result
 | 
				
			||||||
		return $userInfos;
 | 
							return $usersInfo;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -310,11 +310,11 @@ class Posts {
 | 
				
			|||||||
			$visibilityLevel = CS::get()->components->user->getVisibility($post_infos['user_page_id']);
 | 
								$visibilityLevel = CS::get()->components->user->getVisibility($post_infos['user_page_id']);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			//If the page is open, access is free
 | 
								//If the page is open, access is free
 | 
				
			||||||
			if($visibilityLevel == User::USER_PAGE_OPEN)
 | 
								if($visibilityLevel == UserComponent::USER_PAGE_OPEN)
 | 
				
			||||||
				return $this::BASIC_ACCESS;
 | 
									return $this::BASIC_ACCESS;
 | 
				
			||||||
			
 | 
								
 | 
				
			||||||
			//Else check if the user is signed in and the page is public 
 | 
								//Else check if the user is signed in and the page is public 
 | 
				
			||||||
			else if($userID != 0 AND $visibilityLevel == User::USER_PAGE_PUBLIC)
 | 
								else if($userID != 0 AND $visibilityLevel == UserComponent::USER_PAGE_PUBLIC)
 | 
				
			||||||
				return $this::BASIC_ACCESS;
 | 
									return $this::BASIC_ACCESS;
 | 
				
			||||||
			
 | 
								
 | 
				
			||||||
			else
 | 
								else
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -13,7 +13,7 @@ class UserComponent {
 | 
				
			|||||||
	const USER_TABLE = "utilisateurs";
 | 
						const USER_TABLE = "utilisateurs";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
	 * Pages visiblity levels
 | 
						 * User pages visiblity levels
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	const USER_PAGE_PRIVATE = 0;
 | 
						const USER_PAGE_PRIVATE = 0;
 | 
				
			||||||
	const USER_PAGE_PUBLIC = 1;
 | 
						const USER_PAGE_PUBLIC = 1;
 | 
				
			||||||
@@ -72,8 +72,8 @@ class UserComponent {
 | 
				
			|||||||
	/**
 | 
						/**
 | 
				
			||||||
	 * Get Multiple Users Infos
 | 
						 * Get Multiple Users Infos
 | 
				
			||||||
	 *
 | 
						 *
 | 
				
			||||||
	 * @param Array $usersID The users ID
 | 
						 * @param array $usersID The users ID
 | 
				
			||||||
	 * @return Array The result of the function (user informations) (empty one if it fails)
 | 
						 * @return array The result of the function (user informations as User objects) (empty one if it fails)
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	public function getMultipleUserInfos(array $usersID) : array {
 | 
						public function getMultipleUserInfos(array $usersID) : array {
 | 
				
			||||||
		//Prepare database request
 | 
							//Prepare database request
 | 
				
			||||||
@@ -96,7 +96,7 @@ class UserComponent {
 | 
				
			|||||||
		
 | 
							
 | 
				
			||||||
		//Process result
 | 
							//Process result
 | 
				
			||||||
		foreach($usersInfos as $processUser){
 | 
							foreach($usersInfos as $processUser){
 | 
				
			||||||
			$result[$processUser['ID']] = $this->generateUserInfosArray($processUser);
 | 
								$result[$processUser['ID']] = $this->parseDbToUser($processUser);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		//Return result
 | 
							//Return result
 | 
				
			||||||
@@ -247,13 +247,13 @@ class UserComponent {
 | 
				
			|||||||
			return FALSE; //An error occured
 | 
								return FALSE; //An error occured
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		//Check if the page is open
 | 
							//Check if the page is open
 | 
				
			||||||
		if($visibility == User::USER_PAGE_OPEN)
 | 
							if($visibility == UserComponent::USER_PAGE_OPEN)
 | 
				
			||||||
			return true;
 | 
								return true;
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
		if($userID == 0)
 | 
							if($userID == 0)
 | 
				
			||||||
			return false;
 | 
								return false;
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
		if($visibility == User::USER_PAGE_PUBLIC)
 | 
							if($visibility == UserComponent::USER_PAGE_PUBLIC)
 | 
				
			||||||
			return true;
 | 
								return true;
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
		if(CS::get()->components->friends->are_friend($userID, $targetUser))
 | 
							if(CS::get()->components->friends->are_friend($userID, $targetUser))
 | 
				
			||||||
@@ -351,57 +351,6 @@ class UserComponent {
 | 
				
			|||||||
		return $result[0]["liste_amis_publique"] == 1;
 | 
							return $result[0]["liste_amis_publique"] == 1;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/**
 | 
					 | 
				
			||||||
	 * Generate and return an array containing informations about a user
 | 
					 | 
				
			||||||
	 * given the database entry
 | 
					 | 
				
			||||||
	 *
 | 
					 | 
				
			||||||
	 * @param array $userInfos The user entry in the database
 | 
					 | 
				
			||||||
	 * @param bool $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, bool $advanced = false) : array{
 | 
					 | 
				
			||||||
		//Prepare return
 | 
					 | 
				
			||||||
		$return = array();
 | 
					 | 
				
			||||||
		$return['userID'] = $userInfos['ID'];
 | 
					 | 
				
			||||||
		$return['firstName'] = $userInfos['prenom'];
 | 
					 | 
				
			||||||
		$return['lastName'] = $userInfos['nom'];
 | 
					 | 
				
			||||||
		$return['publicPage'] = $userInfos['public'] == 1;
 | 
					 | 
				
			||||||
		$return['openPage'] = $userInfos['pageouverte'] == 1;
 | 
					 | 
				
			||||||
		$return['virtualDirectory'] = $userInfos['sous_repertoire'];
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		//Add account image url
 | 
					 | 
				
			||||||
		$return['accountImage'] = CS::get()->components->accountImage->getPath($return['userID']);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		//Check if we have to fetch advanced informations
 | 
					 | 
				
			||||||
		if($advanced){
 | 
					 | 
				
			||||||
			
 | 
					 | 
				
			||||||
			//Public friend list
 | 
					 | 
				
			||||||
			$return['friend_list_public'] = $userInfos['liste_amis_publique'] == 1;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
			//Personnal website
 | 
					 | 
				
			||||||
			$return['personnalWebsite'] = $userInfos['site_web'];
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
			//Block comment his his page ?
 | 
					 | 
				
			||||||
			$return['noCommentOnHisPage'] = $userInfos['bloquecommentaire'] == 1;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
			//Allow user to post informations on his page
 | 
					 | 
				
			||||||
			$return['allowPostFromFriendOnHisPage'] = $userInfos['autoriser_post_amis'] == 1;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
			//Account creation date
 | 
					 | 
				
			||||||
			$return['account_creation_time'] = strtotime($userInfos['date_creation']);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
			//Add background image url
 | 
					 | 
				
			||||||
			$return['backgroundImage'] = CS::get()->components->backgroundImage->getPath($return['userID']);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
			//Get the number of likes of the page
 | 
					 | 
				
			||||||
			$return['pageLikes'] = CS::get()->components->likes->count($return['userID'], Likes::LIKE_USER);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		//Return result
 | 
					 | 
				
			||||||
		return $return;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
	 * Parse user database entry into user object
 | 
						 * Parse user database entry into user object
 | 
				
			||||||
	 * 
 | 
						 * 
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user