wip
This commit is contained in:
@ -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 ) ) {
|
||||
|
Reference in New Issue
Block a user