mirror of
				https://github.com/pierre42100/ComunicAPI
				synced 2025-11-04 04:04:20 +00:00 
			
		
		
		
	Can update group logo
This commit is contained in:
		@@ -136,6 +136,41 @@ class GroupsController {
 | 
				
			|||||||
		return array("success" => "Group settings have been successfully updated!");
 | 
							return array("success" => "Group settings have been successfully updated!");
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/**
 | 
				
			||||||
 | 
						 * Change (update) the logo of the group
 | 
				
			||||||
 | 
						 * 
 | 
				
			||||||
 | 
						 * @url POST /groups/upload_logo
 | 
				
			||||||
 | 
						 */
 | 
				
			||||||
 | 
						public function uploadLogo(){
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							//Get the ID of the group (with admin access)
 | 
				
			||||||
 | 
							$groupID = $this->getPostGroupIDWithAdmin("id");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							//Check if it is a valid file
 | 
				
			||||||
 | 
							if(!check_post_file("logo"))
 | 
				
			||||||
 | 
								Rest_fatal_error(400, "An error occurred while receiving logo !");
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							//Delete any previous logo
 | 
				
			||||||
 | 
							if(!components()->groups->deleteLogo($groupID))
 | 
				
			||||||
 | 
								Rest_fatal_error(500, "An error occurred while trying to delete previous group logo!");
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							//Save the new group logo
 | 
				
			||||||
 | 
							$file_path = save_post_image("logo", 0, GroupInfo::PATH_GROUPS_LOGO, 500, 500);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							//Update the settings of the group
 | 
				
			||||||
 | 
							$settings = components()->groups->get_settings($groupID);
 | 
				
			||||||
 | 
							$settings->set_logo($file_path);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if(!components()->groups->set_settings($settings))
 | 
				
			||||||
 | 
								Rest_fatal_error(500, "Could not save information about new group logo!");
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							//Success
 | 
				
			||||||
 | 
							return array(
 | 
				
			||||||
 | 
								"success" => "The new group logo has been successfully saved !",
 | 
				
			||||||
 | 
								"url" => $settings->get_logo_url()
 | 
				
			||||||
 | 
							);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
	 * Get and return a group ID specified in the POST request
 | 
						 * Get and return a group ID specified in the POST request
 | 
				
			||||||
	 * in which the current user has admin rigths
 | 
						 * in which the current user has admin rigths
 | 
				
			||||||
@@ -169,7 +204,7 @@ class GroupsController {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
		$data["id"] = $info->get_id();
 | 
							$data["id"] = $info->get_id();
 | 
				
			||||||
		$data["name"] = $info->get_name();
 | 
							$data["name"] = $info->get_name();
 | 
				
			||||||
		$data["icon_url"] = $info->get_icon_url();
 | 
							$data["icon_url"] = $info->get_logo_url();
 | 
				
			||||||
		$data["number_members"] = $info->get_number_members();
 | 
							$data["number_members"] = $info->get_number_members();
 | 
				
			||||||
		$data["membership"] = self::GROUPS_MEMBERSHIP_LEVELS[$info->get_membership_level()];
 | 
							$data["membership"] = self::GROUPS_MEMBERSHIP_LEVELS[$info->get_membership_level()];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -229,6 +229,34 @@ class GroupsComponent {
 | 
				
			|||||||
            array($id));
 | 
					            array($id));
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * Delete current group logo (if any)
 | 
				
			||||||
 | 
					     * 
 | 
				
			||||||
 | 
					     * @param int $id The ID of the target group
 | 
				
			||||||
 | 
					     * @return bool TRUE if the logo was deleted / FALSE else
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    public function deleteLogo(int $id) : bool {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        //Get the current settings of the group
 | 
				
			||||||
 | 
							$settings = $this->get_settings($id);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							//Check if the group has currently an group logo or not
 | 
				
			||||||
 | 
							if($settings->has_logo()){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								//Delete the previous logo
 | 
				
			||||||
 | 
								if(file_exists($settings->get_logo_sys_path()))
 | 
				
			||||||
 | 
									if(!unlink($settings->get_logo_sys_path()))
 | 
				
			||||||
 | 
					                    return FALSE;
 | 
				
			||||||
 | 
					            
 | 
				
			||||||
 | 
					            //Save new information
 | 
				
			||||||
 | 
					            $settings->set_logo("");
 | 
				
			||||||
 | 
					            return $this->set_settings($settings);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        //Success (nothing to be done)
 | 
				
			||||||
 | 
					        return TRUE;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * Turn a database entry into a GroupInfo object
 | 
					     * Turn a database entry into a GroupInfo object
 | 
				
			||||||
     * 
 | 
					     * 
 | 
				
			||||||
@@ -246,6 +274,9 @@ class GroupsComponent {
 | 
				
			|||||||
        $info->set_number_members($this->countMembers($info->get_id()));
 | 
					        $info->set_number_members($this->countMembers($info->get_id()));
 | 
				
			||||||
        $info->set_membership_level($this->getMembershipLevel(userID, $info->get_id()));
 | 
					        $info->set_membership_level($this->getMembershipLevel(userID, $info->get_id()));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if($data["path_logo"] != null && $data["path_logo"] != "")
 | 
				
			||||||
 | 
					            $info->set_logo($data["path_logo"]);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        return $info;
 | 
					        return $info;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
@@ -298,7 +329,11 @@ class GroupsComponent {
 | 
				
			|||||||
    private function GroupSettingsToDB(GroupSettings $settings) : array {
 | 
					    private function GroupSettingsToDB(GroupSettings $settings) : array {
 | 
				
			||||||
        $data = array();
 | 
					        $data = array();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        $data["name"] = $settings->get_name();
 | 
					        if($settings->has_name())
 | 
				
			||||||
 | 
					            $data["name"] = $settings->get_name();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if($settings->has_logo())
 | 
				
			||||||
 | 
					            $data["path_logo"] = $settings->get_logo();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        return $data;
 | 
					        return $data;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -7,13 +7,13 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
class GroupInfo extends BaseUniqueObject {
 | 
					class GroupInfo extends BaseUniqueObject {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	//Path to group icons in user data
 | 
						//Path to group logo in user data
 | 
				
			||||||
	const PATH_GROUPS_ICON = "groups_icon/";
 | 
						const PATH_GROUPS_LOGO = "groups_logo";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    //Private fields
 | 
					    //Private fields
 | 
				
			||||||
    private $name;
 | 
					    private $name;
 | 
				
			||||||
    private $number_members = -1;
 | 
					    private $number_members = -1;
 | 
				
			||||||
	private $icon;
 | 
						private $logo;
 | 
				
			||||||
	private $membership_level = -1;
 | 
						private $membership_level = -1;
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
@@ -43,21 +43,32 @@ class GroupInfo extends BaseUniqueObject {
 | 
				
			|||||||
		return $this->number_members;
 | 
							return $this->number_members;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	//Get and set the URL of the icon of group
 | 
						//Get and set the URL of the logo of group
 | 
				
			||||||
    public function set_icon(string $icon){
 | 
					    public function set_logo(string $logo){
 | 
				
			||||||
		$this->icon = $icon == "" ? null : $icon;
 | 
							$this->logo = $logo == "" ? null : $logo;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	public function has_icon() : bool {
 | 
						public function has_logo() : bool {
 | 
				
			||||||
		return $this->icon != null;
 | 
							return $this->logo != null;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	public function get_icon() : string {
 | 
						public function get_logo() : string {
 | 
				
			||||||
		return $this->icon != null ? $this->icon : self::PATH_GROUPS_ICON."default.png";
 | 
							return $this->logo != null ? $this->logo : self::PATH_GROUPS_LOGO."/default.png";
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	public function get_icon_url() : string {
 | 
						public function get_logo_url() : string {
 | 
				
			||||||
		return path_user_data($this->get_icon());
 | 
							return path_user_data($this->get_logo());
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						public function get_logo_sys_path() : string {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							//For security reasons, this method is available 
 | 
				
			||||||
 | 
							//only if the user has really a logo (avoid unattended
 | 
				
			||||||
 | 
							//operation on default logo)
 | 
				
			||||||
 | 
							if(!$this->has_logo())
 | 
				
			||||||
 | 
								throw new Exception("This GroupInfo object has not any logo set!");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							return path_user_data($this->get_logo(), true);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	//Get and set the membership level of the current user
 | 
						//Get and set the membership level of the current user
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user