wip
This commit is contained in:
@ -33,7 +33,7 @@ class Reviews extends Controller {
|
||||
|
||||
public function __construct() {
|
||||
self::$title = 'Reviews - {SITENAME}';
|
||||
self::$pageDescription = 'On this page you can submit a reviews for a product.';
|
||||
self::$pageDescription = 'This page allows you to add a new product review or update your existing reviews.';
|
||||
|
||||
if ( ! App::$isLoggedIn ) {
|
||||
Session::flash( 'notice', 'You must be logged in to review products.' );
|
||||
@ -48,18 +48,21 @@ class Reviews extends Controller {
|
||||
}
|
||||
|
||||
public function index() {
|
||||
$reviews = Views::simpleView( 'reviews.list', self::$reviews->byUser() );
|
||||
Components::set( 'reviews', $reviews );
|
||||
Views::view( 'reviews.list' );
|
||||
Views::view( 'reviews.list', self::$reviews->byUser() );
|
||||
}
|
||||
|
||||
public function review( $slug = null ) {
|
||||
$category = self::$categories->findBySlug( $slug );
|
||||
if ( ! $category ) {
|
||||
$categories = self::$categories->simpleUnreviewed();
|
||||
if ( empty( $categories ) ) {
|
||||
Session::flash( 'notice', 'There are no additional products to review at this time.' );
|
||||
Redirect::to( 'reviews/index' );
|
||||
}
|
||||
$selectedCategory = '0';
|
||||
$reviewCategorySelect = HoudiniForms::getSelectHtml(
|
||||
'review_category_id',
|
||||
self::$categories->simple(),
|
||||
$categories,
|
||||
$selectedCategory,
|
||||
);
|
||||
Components::set( 'reviewCategorySelect', $reviewCategorySelect );
|
||||
@ -78,12 +81,76 @@ class Reviews extends Controller {
|
||||
return Views::view( 'reviews.create' );
|
||||
}
|
||||
$result = self::$reviews->create( Input::post('title'), Input::post('rating'), Input::post('review'), Input::post('review_category_id') );
|
||||
if ( true === $result ) {
|
||||
if ( ! empty( $result ) ) {
|
||||
Session::flash( 'success', 'Your review has been received.' );
|
||||
Redirect::to( 'home/index' );
|
||||
Redirect::to( 'reviews/index' );
|
||||
} else {
|
||||
Issues::add( 'error', 'There was an unresolved error while submitting your review.' );
|
||||
return Views::view( 'reviews.create' );
|
||||
}
|
||||
}
|
||||
|
||||
public function view( $id = null ) {
|
||||
$review = $this->confirmOwner( $id );
|
||||
Views::view( 'reviews.view', $review );
|
||||
}
|
||||
|
||||
public function edit( $id = null ) {
|
||||
$review = $this->confirmOwner( $id );
|
||||
|
||||
if ( ! Input::exists( 'submit' ) ) {
|
||||
return Views::view( 'reviews.edit', $review );
|
||||
}
|
||||
|
||||
if ( ! Forms::check( 'reviewEditPublic' ) ) {
|
||||
Issues::add( 'error', [ 'There was an error with your request.' => Check::userErrors() ] );
|
||||
return Views::view( 'reviews.edit', $review );
|
||||
}
|
||||
|
||||
$result = self::$reviews->update(
|
||||
$id,
|
||||
Input::post('title'),
|
||||
Input::post('rating'),
|
||||
Input::post('review')
|
||||
);
|
||||
|
||||
if ( $result ) {
|
||||
Session::flash( 'success', 'Your review has been updated.' );
|
||||
return Redirect::to( 'reviews/index' );
|
||||
}
|
||||
|
||||
Issues::add( 'error', [ 'There was an error with your request.' => Check::userErrors() ] );
|
||||
Views::view( 'reviews.edit', $review );
|
||||
}
|
||||
|
||||
public function delete( $id = null ) {
|
||||
$this->confirmOwner( $id );
|
||||
if ( self::$reviews->delete( $id ) ) {
|
||||
Session::flash( 'success', 'Review deleted' );
|
||||
} else {
|
||||
Session::flash( 'error', 'There was an error with your request.' );
|
||||
}
|
||||
return Redirect::to( 'reviews/index' );
|
||||
}
|
||||
|
||||
private function confirmOwner( $id ) {
|
||||
if ( ! App::$isLoggedIn ) {
|
||||
Session::flash( 'error', 'You must be logged in to review products.' );
|
||||
return Redirect::home();
|
||||
}
|
||||
if ( !Check::id( $id ) ) {
|
||||
Session::flash( 'error', 'Unknown Review' );
|
||||
return Redirect::to( 'reviews/index' );
|
||||
}
|
||||
$review = self::$reviews->findById( $id );
|
||||
if ( empty( $review ) ) {
|
||||
Session::flash( 'error', 'Unknown Review' );
|
||||
return Redirect::to( 'reviews/index' );
|
||||
}
|
||||
if ( App::$activeUser->ID != $review->createdBy ) {
|
||||
Session::flash( 'error', 'Unknown Review' );
|
||||
return Redirect::to( 'reviews/index' );
|
||||
}
|
||||
return $review;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user