\ No newline at end of file
diff --git a/app/plugins/blog/views/sidebar2.html b/app/plugins/blog/views/sidebar2.html
index b135d93..8be0657 100644
--- a/app/plugins/blog/views/sidebar2.html
+++ b/app/plugins/blog/views/sidebar2.html
@@ -2,7 +2,7 @@
diff --git a/app/plugins/reviews/controllers/reviews.php b/app/plugins/reviews/controllers/reviews.php
index b28a4c6..dd14b16 100644
--- a/app/plugins/reviews/controllers/reviews.php
+++ b/app/plugins/reviews/controllers/reviews.php
@@ -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;
+ }
}
\ No newline at end of file
diff --git a/app/plugins/reviews/forms.php b/app/plugins/reviews/forms.php
index 03ccdcd..4f7ed41 100644
--- a/app/plugins/reviews/forms.php
+++ b/app/plugins/reviews/forms.php
@@ -25,6 +25,7 @@ class ReviewForms extends Forms {
self::addHandler( 'editReview', __CLASS__, 'editReview' );
self::addHandler( 'categoryCreate', __CLASS__, 'categoryCreate' );
self::addHandler( 'categoryEdit', __CLASS__, 'categoryEdit' );
+ self::addHandler( 'reviewEditPublic', __CLASS__, 'reviewEditPublic' );
}
/**
@@ -88,6 +89,21 @@ class ReviewForms extends Forms {
}
return true;
}
+ public static function reviewEditPublic() {
+ if ( ! Input::exists( 'review' ) ) {
+ Check::addUserError( 'You must provide a review.' );
+ return false;
+ }
+ if ( ! Input::exists( 'title' ) ) {
+ Check::addUserError( 'You must provide a title.' );
+ return false;
+ }
+ if ( ! Input::exists( 'rating' ) ) {
+ Check::addUserError( 'You must provide a rating.' );
+ return false;
+ }
+ return true;
+ }
}
new ReviewForms;
diff --git a/app/plugins/reviews/models/review.php b/app/plugins/reviews/models/review.php
index 3e96855..400fb0e 100644
--- a/app/plugins/reviews/models/review.php
+++ b/app/plugins/reviews/models/review.php
@@ -62,21 +62,19 @@ class Review extends DatabaseModel {
return self::$db->lastId();
}
- public function update( $id, $title, $rating, $review, $review_category_id = '0' ) {
+ public function update( $id, $title, $rating, $review, $review_category_id = null ) {
if ( ! $this->plugin->checkEnabled() ) {
Debug::info( 'Reviews are disabled in the config.' );
return false;
}
- if ( !Check::dataTitle( $slug ) ) {
- Debug::info( 'Review Categories: illegal title.' );
- return false;
- }
$fields = [
'title' => $title,
'rating' => $rating,
- 'review' => $review,
- 'review_category_id' => $review_category_id,
+ 'review' => $review
];
+ if ( ! empty( $review_category_id ) ) {
+ $fields['review_category_id'] = $review_category_id;
+ }
if ( !self::$db->update( $this->tableName, $id, $fields ) ) {
new CustomException( 'reviewUpdate' );
Debug::error( "Review: $id not updated: $fields" );
@@ -133,6 +131,23 @@ class Review extends DatabaseModel {
return $this->filter( $reviews->results() );
}
+ public function reviewedCategoriesByUser() {
+ $whereClause = ['createdBy', '=', App::$activeUser->ID];
+ $reviews = self::$db->action( 'SELECT ID,review_category_id', $this->tableName, $whereClause );
+
+ if ( !$reviews->count() ) {
+ Debug::info( 'No Reviews found.' );
+ return false;
+ }
+ $categoryIds = [];
+ foreach ($reviews->results() as $key => $result) {
+ if ( ! in_array( $result->review_category_id, $categoryIds ) ) {
+ $categoryIds[] = $result->review_category_id;
+ }
+ }
+ return $categoryIds;
+ }
+
public function byCategory( $id, $limit = null ) {
$whereClause = [ 'review_category_id', '=', $id ];
if ( empty( $limit ) ) {
diff --git a/app/plugins/reviews/models/review_category.php b/app/plugins/reviews/models/review_category.php
index 14848db..933b722 100644
--- a/app/plugins/reviews/models/review_category.php
+++ b/app/plugins/reviews/models/review_category.php
@@ -17,6 +17,7 @@ use TheTempusProject\Bedrock\Functions\Check;
use TheTempusProject\Canary\Bin\Canary as Debug;
use TheTempusProject\Classes\DatabaseModel;
use TheTempusProject\Plugins\Reviews as Plugin;
+use TheTempusProject\Models\Review;
use TheTempusProject\TheTempusProject as App;
use TheTempusProject\Canary\Classes\CustomException;
@@ -109,4 +110,29 @@ class ReviewCategory extends DatabaseModel {
}
return $out;
}
+
+ public function simpleUnreviewed() {
+ $categories = self::$db->get( $this->tableName, '*' );
+ if ( !$categories->count() ) {
+ Debug::warn( 'Could not find any categories' );
+ return false;
+ }
+
+ $categories = $categories->results();
+
+ $review = new Review;
+
+ $reviews = $review->reviewedCategoriesByUser();
+
+ $out = [];
+ foreach ( $categories as &$category ) {
+
+ if ( ! empty( $reviews) && in_array( $category->ID, $reviews ) ) {
+ continue;
+ }
+
+ $out[ $category->name ] = $category->ID;
+ }
+ return $out;
+ }
}
diff --git a/app/plugins/reviews/views/admin/category.html b/app/plugins/reviews/views/admin/category.html
index 32d1f0c..841f402 100644
--- a/app/plugins/reviews/views/admin/category.html
+++ b/app/plugins/reviews/views/admin/category.html
@@ -1,35 +1,42 @@
-
-
-
-
-
Review Category
-
-
-
-
-
+
+
+
+ {ADMIN_BREADCRUMBS}
+
+
+
+
Review Category: {name}
+
+
+
+
+
+
+
-
Name
-
{name}
+
Name:
+
{name}
-
Slug
-
{slug}
+
Slug:
+
{slug}
-
Created
-
{DTC}{createdAt}{/DTC}
+
Created:
+
{DTC}{createdAt}{/DTC}
-
-
-
+
\ No newline at end of file
diff --git a/app/plugins/reviews/views/admin/categoryCreate.html b/app/plugins/reviews/views/admin/categoryCreate.html
index ff77224..6cacb20 100644
--- a/app/plugins/reviews/views/admin/categoryCreate.html
+++ b/app/plugins/reviews/views/admin/categoryCreate.html
@@ -1,22 +1,35 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
+
+
+
+ {ADMIN_BREADCRUMBS}
+
+
+
+
\ No newline at end of file
diff --git a/app/plugins/reviews/views/admin/categoryEdit.html b/app/plugins/reviews/views/admin/categoryEdit.html
index 6be8a5d..f91060e 100644
--- a/app/plugins/reviews/views/admin/categoryEdit.html
+++ b/app/plugins/reviews/views/admin/categoryEdit.html
@@ -1,22 +1,35 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
+
+
+
+ {ADMIN_BREADCRUMBS}
+
+
+
+
\ No newline at end of file
diff --git a/app/plugins/reviews/views/admin/review.html b/app/plugins/reviews/views/admin/review.html
index 45260cd..4e1bb9c 100644
--- a/app/plugins/reviews/views/admin/review.html
+++ b/app/plugins/reviews/views/admin/review.html
@@ -1,28 +1,33 @@
-
-
-
-
-
Review
-
-
-
-
-
+
+
+
+ {ADMIN_BREADCRUMBS}
+
+
+
+
Review: {title}
+
+
+
+
+
+
+
-
Title
-
{title}
+
Title:
+
{title}
-
Rating
-
{rating}
+
Rating:
+
{rating}
-
Created
-
{DTC}{createdAt}{/DTC}
+
Created:
+
{DTC}{createdAt}{/DTC}
-
Review
+
Review:
{review}
@@ -31,12 +36,14 @@
-
-
-
+
\ No newline at end of file
diff --git a/app/plugins/reviews/views/admin/view.html b/app/plugins/reviews/views/admin/view.html
index e69de29..4e1bb9c 100644
--- a/app/plugins/reviews/views/admin/view.html
+++ b/app/plugins/reviews/views/admin/view.html
@@ -0,0 +1,49 @@
+
+
+
+ {ADMIN_BREADCRUMBS}
+
+
+
+
Review: {title}
+
+
+
+
+
+
+
+
+
+
Title:
+
{title}
+
+
+
Rating:
+
{rating}
+
+
+
Created:
+
{DTC}{createdAt}{/DTC}
+
+
+
Review:
+
+
+
{review}
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/plugins/reviews/views/create.html b/app/plugins/reviews/views/create.html
index 6852a83..51bd287 100644
--- a/app/plugins/reviews/views/create.html
+++ b/app/plugins/reviews/views/create.html
@@ -1,16 +1,18 @@
-
-
Write a Review
+
+
Share a Review
+
+
We thank you for for taking the time to review our products. We do not edit or modify reviews in any way. You, as the customer have the ability to modify your own reviews.
+
We read each and every review. You and the admin team both have the ability to comment on reviews privately. Neither your reviews or comments will be publicly shared without your permission.
-
-
+
+
+
{reviewCategorySelect}
-
-
-
-
-
-
+
+
+
+
@@ -20,10 +22,31 @@
-
-
-
+
+
+
+
+
+
+ No need to overthink it, something as simple as "My Review" is fine.
+
+
+
+
+
+
+
+
+ (max: 2000 characters)
+
+
+
+
+
+
+
+
+
-
\ No newline at end of file
diff --git a/app/plugins/reviews/views/edit.html b/app/plugins/reviews/views/edit.html
new file mode 100644
index 0000000..27b5830
--- /dev/null
+++ b/app/plugins/reviews/views/edit.html
@@ -0,0 +1,44 @@
+
+
Edit Your Review
+
+
+
+
+
+
+
+ No need to overthink it, something as simple as "My Review" is fine.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ (max: 2000 characters)
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/plugins/reviews/views/list.html b/app/plugins/reviews/views/list.html
index e1cd117..69c1653 100644
--- a/app/plugins/reviews/views/list.html
+++ b/app/plugins/reviews/views/list.html
@@ -1,4 +1,4 @@
-
+
@@ -7,12 +7,11 @@
On this page you can find your reviews to see any responses or make edits.
+ Add Review
\ No newline at end of file
diff --git a/app/plugins/reviews/views/view.html b/app/plugins/reviews/views/view.html
new file mode 100644
index 0000000..5a5d754
--- /dev/null
+++ b/app/plugins/reviews/views/view.html
@@ -0,0 +1,47 @@
+
+
+
+
+
+
+
Review: {title}
+
+
+
+
+
+
+
+
+
+
Title:
+
{title}
+
+
+
Rating:
+
{rating}
+
+
+
Created:
+
{DTC}{createdAt}{/DTC}
+
+
+
Review:
+
+
+
{review}
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/plugins/wip/views/admin/edit.html b/app/plugins/wip/views/admin/edit.html
index 0b86d90..e5a76ef 100644
--- a/app/plugins/wip/views/admin/edit.html
+++ b/app/plugins/wip/views/admin/edit.html
@@ -41,7 +41,7 @@