Skip to content

Commit 5164a91

Browse files
committed
Wip
1 parent 4ef0e33 commit 5164a91

File tree

7 files changed

+210
-625
lines changed

7 files changed

+210
-625
lines changed

config/review-ratable.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
return [
4+
// Default rating types for reviews
5+
'default_rating_types' => [
6+
'overall',
7+
'customer_service',
8+
'quality',
9+
'friendly',
10+
'price',
11+
],
12+
13+
// Default departments if needed
14+
'default_departments' => [
15+
'Sales',
16+
'Service',
17+
'Parts',
18+
],
19+
20+
// Other configuration settings can be added here
21+
'default_approved' => false,
22+
'max_rating_value' => 10,
23+
'min_rating_value' => 1,
24+
];

database/migrations/create_reviews_table.php.stub

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,9 @@ class CreateReviewsTable extends Migration
1010
Schema::create('reviews', function (Blueprint $table) {
1111
$table->bigIncrements('id');
1212
$table->integer('rating');
13-
$table->integer('customer_service_rating')->nullable();
14-
$table->integer('quality_rating')->nullable();
15-
$table->integer('friendly_rating')->nullable();
16-
$table->integer('pricing_rating')->nullable();
13+
$table->json('ratings')->nullable();
14+
$table->json('departments')->nullable();
1715
$table->enum('recommend', ['Yes', 'No']);
18-
$table->enum('department', ['Sales', 'Service', 'Parts']);
1916
$table->string('title');
2017
$table->string('body');
2118
$table->boolean('approved')->default(0);

src/Contracts/ReviewRateable.php

Lines changed: 65 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -7,177 +7,155 @@
77
interface ReviewRateable
88
{
99
/**
10+
* Get all reviews for the model.
11+
*
1012
* @return \Illuminate\Database\Eloquent\Relations\MorphMany
1113
*/
12-
public function ratings();
14+
public function reviews();
1315

1416
/**
17+
* Get the rating types for the model.
1518
*
16-
* @param $round
17-
* @return double
19+
* @return array
1820
*/
19-
public function averageRating($round = null);
21+
public function ratingTypes();
2022

2123
/**
24+
* Add a review to the model.
2225
*
23-
* @param $round
24-
* @return double
26+
* @param array $data
27+
* @return \Illuminate\Database\Eloquent\Model
2528
*/
26-
public function averageCustomerServiceRating($round = null);
29+
public function addReview(array $data);
2730

2831
/**
32+
* Add a rating to a specific review.
2933
*
30-
* @param $round
31-
* @return double
34+
* @param int $reviewId
35+
* @param string $type
36+
* @param int $rating
37+
* @return void
3238
*/
33-
public function averageQualityRating($round = null);
39+
public function addRatingToReview($reviewId, $type, $rating);
3440

3541
/**
42+
* Get a specific rating from a review.
3643
*
37-
* @param $round
38-
* @return double
44+
* @param int $reviewId
45+
* @param string $type
46+
* @return int|null
3947
*/
40-
public function averageFriendlyRating($round = null);
48+
public function getReviewRating($reviewId, $type);
4149

4250
/**
51+
* Calculate the average rating for a specific type.
4352
*
44-
* @param $round
53+
* @param string|null $type
54+
* @param int|null $round
4555
* @return double
4656
*/
47-
public function averagePricingRating($round = null);
48-
49-
/**
50-
*
51-
* @return int
52-
*/
53-
public function countRating();
54-
55-
/**
56-
*
57-
* @return int
58-
*/
59-
public function countCustomerServiceRating();
60-
61-
/**
62-
*
63-
* @return int
64-
*/
65-
public function countQualityRating();
66-
67-
/**
68-
*
69-
* @return int
70-
*/
71-
public function countFriendlyRating();
57+
public function averageRating($type = 'rating', $round = null);
7258

7359
/**
60+
* Count the number of ratings for a specific type.
7461
*
62+
* @param string|null $type
7563
* @return int
7664
*/
77-
public function countPriceRating();
65+
public function countRating($type = 'rating');
7866

7967
/**
68+
* Sum the ratings for a specific type.
8069
*
70+
* @param string|null $type
8171
* @return double
8272
*/
83-
public function sumRating();
73+
public function sumRating($type = 'rating');
8474

8575
/**
76+
* Calculate the rating percentage for a specific type.
8677
*
87-
* @param $max
88-
*
78+
* @param string|null $type
79+
* @param int $max
8980
* @return double
9081
*/
91-
public function ratingPercent($max = 5);
82+
public function ratingPercent($type = 'rating', $max = 5);
9283

9384
/**
85+
* Retrieve all ratings for the given ID.
9486
*
95-
* @param $data
96-
* @param $author
97-
* @param $parent
98-
*
99-
* @return static
100-
*/
101-
public function rating($data, Model $author, Model $parent = null);
102-
103-
/**
104-
*
105-
* @param $id
106-
* @param $data
107-
* @param $parent
108-
*
109-
* @return mixed
110-
*/
111-
public function updateRating($id, $data, Model $parent = null);
112-
113-
/**
114-
*
115-
* @param $id
116-
* @param $sort
117-
*
87+
* @param int $id
88+
* @param string $sort
11889
* @return mixed
11990
*/
12091
public function getAllRatings($id, $sort = 'desc');
12192

12293
/**
94+
* Retrieve all approved ratings for the given ID.
12395
*
124-
* @param $id
125-
* @param $sort
126-
*
96+
* @param int $id
97+
* @param string $sort
12798
* @return mixed
12899
*/
129100
public function getApprovedRatings($id, $sort = 'desc');
130101

131102
/**
103+
* Retrieve all non-approved ratings for the given ID.
132104
*
133-
* @param $id
134-
* @param $sort
135-
*
105+
* @param int $id
106+
* @param string $sort
136107
* @return mixed
137108
*/
138109
public function getNotApprovedRatings($id, $sort = 'desc');
139110

140111
/**
141-
* @param $id
142-
* @param $limit
143-
* @param $sort
112+
* Retrieve recent ratings for the given ID.
144113
*
114+
* @param int $id
115+
* @param int $limit
116+
* @param string $sort
145117
* @return mixed
146118
*/
147119
public function getRecentRatings($id, $limit = 5, $sort = 'desc');
148120

149121
/**
150-
* @param $id
151-
* @param $limit
152-
* @param $approved
153-
* @param $sort
122+
* Retrieve recent user ratings.
154123
*
124+
* @param int $id
125+
* @param int $limit
126+
* @param bool $approved
127+
* @param string $sort
155128
* @return mixed
156129
*/
157130
public function getRecentUserRatings($id, $limit = 5, $approved = true, $sort = 'desc');
158131

159132
/**
160-
* @param $rating
161-
* @para $type
162-
* @param $approved
163-
* @param $sort
133+
* Get a collection of reviews by average rating.
164134
*
135+
* @param double $rating
136+
* @param string $type
137+
* @param bool $approved
138+
* @param string $sort
165139
* @return mixed
166140
*/
167141
public function getCollectionByAverageRating($rating, $type = 'rating', $approved = true, $sort = 'desc');
168142

169143
/**
144+
* Delete a rating by its ID.
170145
*
171-
* @param $id
172-
*
146+
* @param int $id
173147
* @return mixed
174148
*/
175149
public function deleteRating($id);
176150

177151
/**
152+
* Retrieve user ratings.
178153
*
179-
* @param $id
154+
* @param int $id
155+
* @param string $author
156+
* @param string $sort
180157
* @return mixed
181158
*/
182159
public function getUserRatings($id, $author, $sort = 'desc');
183160
}
161+

0 commit comments

Comments
 (0)