Exemplo n.º 1
0
 public static function deletePost($post_id)
 {
     //delete img
     //first get the post
     $post = self::getPost($post_id);
     //post->getImg
     $img = $post->getImagesPost();
     //foreach img delete img in the DB
     if ($img != NULL) {
         foreach ($img as $image) {
             DAL::deleteImg($image->getImg_id());
         }
         //then in the files (somthing like rmdir /images/posts/$postid -R) !!!this section might rise errors...
         $dir = 'images/posts/' . $post->getPost_id();
         $files = array_diff(scandir($dir), array('.', '..'));
         foreach ($files as $file) {
             is_dir("{$dir}/{$file}") ? delTree("{$dir}/{$file}") : unlink("{$dir}/{$file}");
         }
         rmdir($dir);
     }
     //then get votes
     $votes = $post->getVote_post();
     //foreach vote, unset it
     if ($votes != NULL) {
         foreach ($votes as $vote) {
             DAL::unsetVote_post($vote->getPost_id(), $vote->getUser()->getUsername());
         }
     }
     DAL::deletePost($post_id);
 }
 static function unsetVote_post($post_id, $username)
 {
     DAL::unsetVote_post($post_id, $username);
 }