aboutsummaryrefslogtreecommitdiff
path: root/lib/models/FeedbackElement.php
diff options
context:
space:
mode:
authorRon Lucke <lucke@elan-ev.de>2024-01-10 14:20:49 +0000
committerRon Lucke <lucke@elan-ev.de>2024-01-10 14:20:49 +0000
commit7293abbad9c1a149cfffd99c9ab5060fe945b773 (patch)
tree6e80b665c4cda71829570e6f0925f4d876e25fde /lib/models/FeedbackElement.php
parent874bd358f5ecc2e148a6ad36bcf155fe738c107a (diff)
StEP #2472
Merge request studip/studip!2296
Diffstat (limited to 'lib/models/FeedbackElement.php')
-rw-r--r--lib/models/FeedbackElement.php18
1 files changed, 18 insertions, 0 deletions
diff --git a/lib/models/FeedbackElement.php b/lib/models/FeedbackElement.php
index 63a2186..468f146 100644
--- a/lib/models/FeedbackElement.php
+++ b/lib/models/FeedbackElement.php
@@ -3,6 +3,7 @@
/**
*
* @author Nils Gehrke <nils.gehrke@uni-goettingen.de>
+ * @author Ron Lucke <lucke@elan-ev.de>
*
* The column "range_type" represents the name of a class that implements
* FeedbackRange.
@@ -17,6 +18,7 @@
* @property int $mode database column
* @property int $results_visible database column
* @property int $commentable database column
+ * @property int $anonymous_entries database column
* @property int $mkdate database column
* @property int $chdate database column
* @property SimpleORMapCollection|FeedbackEntry[] $entries has_many FeedbackEntry
@@ -156,6 +158,22 @@ class FeedbackElement extends SimpleORMap
}
}
+ public function getAverageRating(): float
+ {
+ $ratings = $this->getRatings();
+
+ if (empty($ratings)) {
+ return 0;
+ }
+
+ return array_sum($ratings) / count($ratings);
+ }
+
+ public function hasEntries(): bool
+ {
+ return count($this->getRatings()) > 0;
+ }
+
public function getRange()
{
return $this->range_type::find($this->range_id);