mirror of
				https://github.com/pierre42100/ComunicAPI
				synced 2025-11-03 19:54:14 +00:00 
			
		
		
		
	Can delete movies
This commit is contained in:
		@@ -26,11 +26,8 @@ class Movies {
 | 
				
			|||||||
		
 | 
							
 | 
				
			||||||
		$results = CS::get()->db->select($this::MOVIES_TABLE, $conditions, $values);
 | 
							$results = CS::get()->db->select($this::MOVIES_TABLE, $conditions, $values);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		$movies = array();
 | 
							//Process the list of movies
 | 
				
			||||||
		foreach($results as $row)
 | 
							return $this->processMultipleDBentry($results);
 | 
				
			||||||
			$movies[] = $this->dbToMovie($row);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		return $movies;
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
@@ -83,6 +80,70 @@ class Movies {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/**
 | 
				
			||||||
 | 
						 * Delete a movie
 | 
				
			||||||
 | 
						 * 
 | 
				
			||||||
 | 
						 * @param Movie $movie The movie to delete
 | 
				
			||||||
 | 
						 * @return bool TRUE for a success / FALSE else
 | 
				
			||||||
 | 
						 */
 | 
				
			||||||
 | 
						private function delete(Movie $movie) : bool {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							//Delete related posts
 | 
				
			||||||
 | 
							if(!components()->posts->deleteAllWithMovie($movie->get_id()))
 | 
				
			||||||
 | 
								return FALSE;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							//Delete file (if possible)
 | 
				
			||||||
 | 
							if(!$movie->has_uri())
 | 
				
			||||||
 | 
								return FAlSE;
 | 
				
			||||||
 | 
							$file_path = path_user_data($movie->get_uri(), TRUE);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if(file_exists($file_path)){
 | 
				
			||||||
 | 
								if(!unlink($file_path))
 | 
				
			||||||
 | 
									return FALSE;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							//Remove database entry
 | 
				
			||||||
 | 
							return CS::get()->db->deleteEntry(
 | 
				
			||||||
 | 
								$this::MOVIES_TABLE, 
 | 
				
			||||||
 | 
								"ID = ?", 
 | 
				
			||||||
 | 
								array($movie->get_id()));
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/**
 | 
				
			||||||
 | 
						 * Delete (remove) all the movies of a user
 | 
				
			||||||
 | 
						 * 
 | 
				
			||||||
 | 
						 * @param int $userID The ID of the target user
 | 
				
			||||||
 | 
						 * @return bool TRUE for success / FALSE else
 | 
				
			||||||
 | 
						 */
 | 
				
			||||||
 | 
						public function deleteAllUser(int $userID) : bool {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							//Get the list of movies of the user
 | 
				
			||||||
 | 
							$list = $this->get_list($userID);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							//Process the list of movies
 | 
				
			||||||
 | 
							foreach($list as $movie){
 | 
				
			||||||
 | 
								if(!$this->delete($movie))
 | 
				
			||||||
 | 
									return FALSE;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							//Success
 | 
				
			||||||
 | 
							return TRUE;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/**
 | 
				
			||||||
 | 
						 * Process a list of database entries into Movie entries
 | 
				
			||||||
 | 
						 * 
 | 
				
			||||||
 | 
						 * @param array $entries The entries to parse
 | 
				
			||||||
 | 
						 * @return array Generated list of entries
 | 
				
			||||||
 | 
						 */
 | 
				
			||||||
 | 
						private function processMultipleDBentry(array $entries) : array {
 | 
				
			||||||
 | 
							$movies = array();
 | 
				
			||||||
 | 
							foreach($entries as $row)
 | 
				
			||||||
 | 
								$movies[] = $this->dbToMovie($row);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							return $movies;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
	 * Convert database entry into movie object
 | 
						 * Convert database entry into movie object
 | 
				
			||||||
	 * 
 | 
						 * 
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user