This commit is contained in:
Joey Kimsey
2025-01-01 22:17:38 -05:00
parent ccc134d1b2
commit 1ef85c6c2c
65 changed files with 1200 additions and 215 deletions

View File

@ -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 ) ) {

View File

@ -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;
}
}