From ed0c10767959134051f8b5e23a132f53bafb83dc Mon Sep 17 00:00:00 2001 From: Josantonius Date: Fri, 11 Aug 2017 15:08:23 +0200 Subject: [PATCH] Updated to 1.0.1 version --- CHANGELOG.md | 1 + src/Controller/Admin/Rating/Rating.php | 55 ++++++++++++++++---------- 2 files changed, 36 insertions(+), 20 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 626385c..0955d2c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ * Added `ExtensionsForGrifus\Modules\CustomRatingGrifus\Controller\Admin\Rating\Rating->setRatingAndVotes()` method. * Added `ExtensionsForGrifus\Modules\CustomRatingGrifus\Controller\Admin\Rating\Rating->addMetaBoxes()` method. * Added `ExtensionsForGrifus\Modules\CustomRatingGrifus\Controller\Admin\Rating\Rating->renderMetaBoxes()` method. +* Added `ExtensionsForGrifus\Modules\CustomRatingGrifus\Controller\Admin\Rating\Rating->getDefaultVotes()` method. * Deleted `ExtensionsForGrifus\Modules\CustomRatingGrifus\Controller\Admin\Rating\Rating->setMovieRating()` method. diff --git a/src/Controller/Admin/Rating/Rating.php b/src/Controller/Admin/Rating/Rating.php index 006ef4f..0a983e2 100644 --- a/src/Controller/Admin/Rating/Rating.php +++ b/src/Controller/Admin/Rating/Rating.php @@ -201,22 +201,9 @@ public function restartRating($postID, $post, $update) { if (App::main()->isAfterInsertPost($post, $update)) { - $votes = $this->model->getMovieVotes($postID); - - if (!$votes) { - - $votes = [ - '1' => 0, - '2' => 0, - '3' => 0, - '4' => 0, - '5' => 0, - '6' => 0, - '7' => 0, - '8' => 0, - '9' => 0, - '10' => 0, - ]; + if (!$this->model->getMovieVotes($postID)) { + + $votes = $this->getDefaultVotes($postID); $this->setRatingAndVotes($postID, $votes); @@ -250,12 +237,15 @@ public function restartAllRatings() { foreach ($posts as $post) { - if (isset($post->ID)) { + if (isset($post->ID) && !$this->model->getMovieVotes($post->ID)){ - if ($this->restartRating($post->ID)) { + $this->setRatingAndVotes( - $response['ratings_restarted']++; - } + $post->ID, + $this->getDefaultVotes($post->ID) + ); + + $response['ratings_restarted']++; } } @@ -332,6 +322,31 @@ public function restartWhenAdd() { die(); } + /** + * Get default votes. + * + * @since 1.0.1 + * + * @param int $postID → post ID + * + * @return array → default votes + */ + public function getDefaultVotes($postID) { + + return [ + '1' => 0, + '2' => 0, + '3' => 0, + '4' => 0, + '5' => 0, + '6' => 0, + '7' => 0, + '8' => 0, + '9' => 0, + '10' => 0, + ]; + } + /** * Add movie rating. *