1 | <?php |
||
14 | class Ratings |
||
15 | { |
||
16 | /** @var ApiClientInterface */ |
||
17 | private $client; |
||
18 | |||
19 | /** @var Video [] */ |
||
20 | private $videos = []; |
||
21 | |||
22 | /** @var int */ |
||
23 | private $vmId; |
||
24 | |||
25 | /** @var string */ |
||
26 | private $metadataFieldAverage; |
||
27 | |||
28 | /** @var string */ |
||
29 | private $metadataFieldCount; |
||
30 | |||
31 | public function __construct( |
||
42 | |||
43 | /** |
||
44 | * Increases the count of all ratings by one and calculates a new average rating value. |
||
45 | * |
||
46 | * @param string $videoId |
||
47 | * @param int $rating |
||
48 | */ |
||
49 | public function addRating($videoId, $rating) |
||
62 | |||
63 | /** |
||
64 | * Modifies the average rating value. Count of all ratings stays the same (will not be increased). |
||
65 | * The use case of this function is, when someone wants to change its rating (video was already rated by that person). |
||
66 | * |
||
67 | * @param string $videoId |
||
68 | * @param int $rating |
||
69 | * @param int $oldRating |
||
70 | */ |
||
71 | public function modifyRating($videoId, $rating, $oldRating) |
||
82 | |||
83 | /** |
||
84 | * Returns the average rating value from the custom meta data fields from a given video. |
||
85 | * |
||
86 | * @param string $videoId |
||
87 | * |
||
88 | * @return float|int |
||
89 | */ |
||
90 | public function getRatingAverage($videoId) |
||
94 | |||
95 | /** |
||
96 | * Returns the count of all ratings from the custom meta data fields from a given video. |
||
97 | * |
||
98 | * @param string $videoId |
||
99 | * |
||
100 | * @return float|int |
||
101 | */ |
||
102 | private function getRatingCount($videoId) |
||
106 | |||
107 | /** |
||
108 | * Returns a meta data field of a video always as a number. |
||
109 | * |
||
110 | * @param $videoId |
||
111 | * @param $customMetaDataField |
||
112 | * |
||
113 | * @return float|int |
||
114 | */ |
||
115 | private function getCustomMetaDataField($videoId, $customMetaDataField) |
||
123 | |||
124 | /** |
||
125 | * Stores the custom meta data fields with the api client. |
||
126 | * |
||
127 | * @param array $customMetaData |
||
128 | * @param string $videoId |
||
129 | */ |
||
130 | private function storeCustomMetaData($customMetaData, $videoId) |
||
142 | |||
143 | /** |
||
144 | * Fetches and returns video from api client and stores it locally. |
||
145 | * This way api client will be requested only once for every video. |
||
146 | * |
||
147 | * @param string $videoId |
||
148 | * |
||
149 | * @return Video |
||
150 | */ |
||
151 | private function getVideo($videoId) |
||
161 | |||
162 | /** |
||
163 | * Returns custom meta data fields which are related to rating. |
||
164 | * |
||
165 | * @param array $customMetaData |
||
166 | * |
||
167 | * @return array |
||
168 | */ |
||
169 | private function filterCustomMetaData($customMetaData) |
||
180 | } |
||
181 |