/** * Delete a review * * @return void */ public function deletereview() { $database = App::get('db'); $publication =& $this->publication; // Incoming $reviewid = Request::getInt('comment', 0); // Do we have a review ID? if (!$reviewid) { $this->setError(Lang::txt('PLG_PUBLICATIONS_REVIEWS_NO_ID')); return; } // Do we have a publication ID? if (!$publication->exists()) { $this->setError(Lang::txt('PLG_PUBLICATIONS_REVIEWS_NO_RESOURCE_ID')); return; } $review = new \Components\Publications\Tables\Review($database); $review->load($reviewid); // Permissions check if ($review->created_by != User::get('id')) { return; } $review->state = 2; $review->store(); // Delete the review's comments $comments1 = \Hubzero\Item\Comment::all()->whereEquals('parent', $reviewid)->whereEquals('item_id', $publication->get('id'))->whereEquals('item_type', 'pubreview')->ordered()->rows(); foreach ($comments1 as $comment1) { $comment1->set('state', $comment1::STATE_DELETED); $comment1->save(); } // Recalculate the average rating for the parent publication $publication->table()->calculateRating(); $publication->table()->updateRating(); App::redirect(Route::url($publication->link('reviews')), Lang::txt('PLG_PUBLICATIONS_REVIEWS_REVIEW_DELETED')); return; }
/** * Delete a review * * @return void */ public function deletereview() { $database = App::get('db'); $publication =& $this->publication; // Incoming $reviewid = Request::getInt('comment', 0); // Do we have a review ID? if (!$reviewid) { $this->setError(Lang::txt('PLG_PUBLICATIONS_REVIEWS_NO_ID')); return; } // Do we have a publication ID? if (!$publication->exists()) { $this->setError(Lang::txt('PLG_PUBLICATIONS_REVIEWS_NO_RESOURCE_ID')); return; } $review = new \Components\Publications\Tables\Review($database); $review->load($reviewid); // Permissions check if ($review->created_by != User::get('id')) { return; } $review->state = 2; $review->store(); // Delete the review's comments $reply = new \Hubzero\Item\Comment($database); $comments1 = $reply->find(array('parent' => $reviewid, 'item_type' => 'pubreview', 'item_id' => $publication->get('id'))); if (count($comments1) > 0) { foreach ($comments1 as $comment1) { $reply->setState($comment1->id, 2); } } // Recalculate the average rating for the parent publication $publication->table()->calculateRating(); $publication->table()->updateRating(); App::redirect(Route::url($publication->link('reviews')), Lang::txt('PLG_PUBLICATIONS_REVIEWS_REVIEW_DELETED')); return; }