mirror of
				https://github.com/pierre42100/ComunicAPI
				synced 2025-11-04 12:14:12 +00:00 
			
		
		
		
	Update following status
This commit is contained in:
		@@ -201,4 +201,36 @@ class friendsController{
 | 
				
			|||||||
		//Return the response
 | 
							//Return the response
 | 
				
			||||||
		return $response;
 | 
							return $response;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/**
 | 
				
			||||||
 | 
						 * Update the following status of a friendship
 | 
				
			||||||
 | 
						 * 
 | 
				
			||||||
 | 
						 * @url POST /friends/setFollowing
 | 
				
			||||||
 | 
						 */
 | 
				
			||||||
 | 
						public function update_following(){
 | 
				
			||||||
 | 
							user_login_required(); //Login required
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							//Check if the a friendID has been specified
 | 
				
			||||||
 | 
							if(!isset($_POST['friendID']))
 | 
				
			||||||
 | 
								Rest_fatal_error(400, "Please specify a friend ID !");
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$friendID = toInt($_POST['friendID']);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							//Check if a follow status has been specified
 | 
				
			||||||
 | 
							if(!isset($_POST['follow']))
 | 
				
			||||||
 | 
								Rest_fatal_error(400, "Please specify a follow status!");
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$following = $_POST['follow'] === "true";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							//Check if the two personns are friend
 | 
				
			||||||
 | 
							if(!CS::get()->components->friends->are_friend(userID, $friendID))
 | 
				
			||||||
 | 
								Rest_fatal_error(401, "You are not friend with this personn!");
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							//Update following status
 | 
				
			||||||
 | 
							if(!CS::get()->components->friends->set_following(userID, $friendID, $following))
 | 
				
			||||||
 | 
								Rest_fatal_error(500, "Couldn't update friendship status!");
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							//Success
 | 
				
			||||||
 | 
							return array("success" => "Friendship status has been updated!");
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -299,7 +299,28 @@ class friends {
 | 
				
			|||||||
		
 | 
							
 | 
				
			||||||
		return $response[0]['autoriser_post_page'] == 1;
 | 
							return $response[0]['autoriser_post_page'] == 1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/**
 | 
				
			||||||
 | 
						 * Update the following status for a friendship
 | 
				
			||||||
 | 
						 * 
 | 
				
			||||||
 | 
						 * @param int $userID The ID of the user updating the status
 | 
				
			||||||
 | 
						 * @param int $friendID The ID of the target friend
 | 
				
			||||||
 | 
						 * @param boolean $following The new status
 | 
				
			||||||
 | 
						 * @return bool True in case of succcess / false else
 | 
				
			||||||
 | 
						 */
 | 
				
			||||||
 | 
						public function set_following(int $userID, int $friendID, bool $following) : bool {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							//Update the table
 | 
				
			||||||
 | 
							$tableName = $this->friendsTable;
 | 
				
			||||||
 | 
							$conditions = "ID_personne = ? AND ID_amis = ?";
 | 
				
			||||||
 | 
							$conditionsValues = array($userID, $friendID);
 | 
				
			||||||
 | 
							$newValues = array(
 | 
				
			||||||
 | 
								"abonnement" => $following ? 1 : 0
 | 
				
			||||||
 | 
							);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							//Perform the request
 | 
				
			||||||
 | 
							return CS::get()->db->updateDB($tableName, $conditions, $newValues, $conditionsValues);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user