예제 #1
0
 public function deleteAction()
 {
     $this->fa->readOnly();
     $id = (int) $this->getParam('id');
     $record = Favorite::getRepository()->findOneBy(array('id' => $id, 'user_id' => $this->user->id));
     if ($record instanceof Favorite) {
         $record->delete();
     }
     $this->alert('<b>Favorite removed!</b>', 'green');
     return $this->redirectFromHere(array('action' => 'index', 'id' => NULL));
 }
예제 #2
0
 public function favoriteAction()
 {
     $csrf_key = $this->getParam('key');
     // Verify this isn't a cross-domain attack before proceeding
     if ($this->csrf->verify($csrf_key, '_upload_content')) {
         // TODO: Check comment hiding rate limit here!
         $upload_id = (int) $this->getParam('id');
         $upload = Upload::find($upload_id);
         // Verifying if the Upload exists
         if (!$upload instanceof Upload) {
             throw new \FA\Exception('Upload not found!');
         }
         $favorite = $this->em->createQuery('SELECT f FROM \\Entity\\Favorite f WHERE f.upload_id = :upload_id')->setParameter('upload_id', $upload->id)->getArrayResult();
         // Verify the user can even progress further
         //self::_userCheck($upload);
         // If the favorite exists, delete it. If not, create it!
         // TODO: Look into soft deleting
         if (count($favorite) > 0) {
             \FA\Utilities::print_r($favorite);
         } else {
             $favorite = new Favorite();
             $favorite->upload = $upload;
             $favorite->user = $this->user;
             $favorite->save();
         }
         // Redirect to the Upload page to our comment!
         // TODO: Add a way to auto-lock on to the comment. Maybe a perma-link style approach?
         return $this->redirectToName('upload_view', array('id' => $upload->id));
     }
 }