xref: /haiku/src/apps/haikudepot/packagemodel/UserRatingSummary.h (revision 344ded80d400028c8f561b4b876257b94c12db4a)
1 /*
2  * Copyright 2013-2014, Stephan Aßmus <superstippi@gmx.de>.
3  * Copyright 2016-2024, Andrew Lindesay <apl@lindesay.co.nz>.
4  * All rights reserved. Distributed under the terms of the MIT License.
5  */
6 #ifndef USER_RATING_SUMMARY_H
7 #define USER_RATING_SUMMARY_H
8 
9 #include <Referenceable.h>
10 
11 
12 /*!	This class contains data which provides an aggregate view of the user ratings
13 	for a package. Note that the data here is the result of an algorithm that only
14 	incorporates data from certain user ratings; for example we don't want to
15 	include users' ratings for every single version of a package but only the last
16 	one. Other rules also apply. For this reason, the calculation is performed on
17 	the server-side and presented here.
18 */
19 
20 class UserRatingSummary : public BReferenceable
21 {
22 public:
23 								UserRatingSummary();
24 								UserRatingSummary(const UserRatingSummary& other);
25 
26 			void				Clear();
27 
28 			float				AverageRating() const
29 									{ return fAverageRating; }
30 			int					RatingCount() const
31 									{ return fRatingCount; }
32 			int					RatingCountByStar(int star) const;
33 
34 			void				SetAverageRating(float value);
35 			void				SetRatingCount(int value);
36 			void				SetRatingByStar(int star, int ratingCount);
37 
38 			UserRatingSummary&	operator=(const UserRatingSummary& other);
39 			bool				operator==(const UserRatingSummary& other) const;
40 			bool				operator!=(const UserRatingSummary& other) const;
41 
42 private:
43 			float				fAverageRating;
44 			int					fRatingCount;
45 
46 			int					fRatingCountNoStar;
47 			int					fRatingCountByStar[6];
48 };
49 
50 typedef BReference<UserRatingSummary> UserRatingSummaryRef;
51 
52 
53 #endif // USER_RATING_SUMMARY_H
54