aboutsummaryrefslogtreecommitdiff
path: root/lib/models/Vote.php
diff options
context:
space:
mode:
authorRasmus Fuhse <fuhse@data-quest.de>2022-12-16 13:13:32 +0000
committerRasmus Fuhse <fuhse@data-quest.de>2022-12-16 13:13:32 +0000
commit653fcaba5a06b8098f9bdb98c051c35a567a4513 (patch)
tree4c0cb47566019bbab09401b7287ef188322239b5 /lib/models/Vote.php
parentf127f0fb49c0f687f80588e0e1008e95be37d6ce (diff)
Resolve "Evaluationen mit Fragebögen"
Closes #703 Merge request studip/studip!363
Diffstat (limited to 'lib/models/Vote.php')
-rw-r--r--lib/models/Vote.php103
1 files changed, 36 insertions, 67 deletions
diff --git a/lib/models/Vote.php b/lib/models/Vote.php
index 6060f0b..12c8fee 100644
--- a/lib/models/Vote.php
+++ b/lib/models/Vote.php
@@ -1,13 +1,20 @@
<?php
require_once 'lib/classes/QuestionType.interface.php';
-use eTask\Task;
-
class Vote extends QuestionnaireQuestion implements QuestionType
{
- public static function getIcon($active = false, $add = false)
+ public static function getIcon(bool $active = false) : Icon
+ {
+ return Icon::create(static::getIconShape(), $active ? 'clickable' : 'info');
+ }
+
+ /**
+ * Returns the shape of the icon of this QuestionType
+ * @return string
+ */
+ public static function getIconShape()
{
- return Icon::create('vote', $active ? 'clickable' : 'info');
+ return 'vote';
}
public static function getName()
@@ -15,69 +22,18 @@ class Vote extends QuestionnaireQuestion implements QuestionType
return _('Auswahlfrage');
}
- public function getEditingTemplate()
+ static public function getEditingComponent()
{
- $tf = new Flexi_TemplateFactory(realpath(__DIR__.'/../../app/views'));
- $template = $tf->open('questionnaire/question_types/vote/vote_edit');
- $template->set_attribute('vote', $this);
- return $template;
+ return ['vote-edit', ''];
}
- public function createDataFromRequest()
+ public function beforeStoringQuestiondata($questiondata)
{
- $questions = Request::getArray('questions');
- $data = $questions[$this->getId()];
-
- // create a new eTask if this is a new question
- if (!$this->etask) {
- $this->etask = Task::create(
- [
- 'type' => 'multiple-choice',
- 'user_id' => $GLOBALS['user']->id,
- ]
- );
- }
-
- // update description
- $this->etask->description = Studip\Markup::purifyHtml($data['description']);
-
- // update task's type (single|multiple)
- $task = [
- 'type' => $data['task']['type'] === 'multiple' ? 'multiple' : 'single',
- 'answers' => []
- ];
-
- // update task's answers
- foreach ($data['task']['answers'] as $index => $text) {
- $trimmedText = trim($text);
- if ($trimmedText === '') {
- continue;
- }
-
- $task['answers'][] = [
- 'text' => $trimmedText,
- 'score' => 0,
- 'feedback' => ''
- ];
- }
-
- $this->etask->task = $task;
-
- // update randomize option
- if (isset($data['options']['randomize'])) {
- $options = $this->etask->options;
- $options['randomize'] = (bool) $data['options']['randomize'];
- $this->etask->options = $options;
- }
- // update mandatory option
- if (isset($data['options']['mandatory'])) {
- $options = $this->etask->options;
- $options['mandatory'] = (bool) $data['options']['mandatory'];
- $this->etask->options = $options;
- }
-
- // store the eTask instance
- $this->etask->store();
+ $questiondata['description'] = \Studip\Markup::markAsHtml(
+ \Studip\Markup::purifyHtml($questiondata['description'])
+ );
+ $questiondata['options'] = array_filter($questiondata['options']);
+ return $questiondata;
}
public function getDisplayTemplate()
@@ -106,7 +62,19 @@ class Vote extends QuestionnaireQuestion implements QuestionType
return $answer;
}
- public function getResultTemplate($only_user_ids = null)
+ public function getUserIdsOfFilteredAnswer($answer_option)
+ {
+ $user_ids = [];
+ foreach ($this->answers as $answer) {
+ $answerData = $answer['answerdata']->getArrayCopy();
+ if (in_array($answer_option, (array) $answerData['answers'])) {
+ $user_ids[] = $answer['user_id'];
+ }
+ }
+ return $user_ids;
+ }
+
+ public function getResultTemplate($only_user_ids = null, $filtered = null)
{
$answers = $this->answers;
if ($only_user_ids !== null) {
@@ -120,6 +88,7 @@ class Vote extends QuestionnaireQuestion implements QuestionType
$template = $factory->open('questionnaire/question_types/vote/vote_evaluation');
$template->set_attribute('vote', $this);
$template->set_attribute('answers', $answers);
+ $template->set_attribute('filtered', $filtered);
return $template;
}
@@ -127,9 +96,9 @@ class Vote extends QuestionnaireQuestion implements QuestionType
{
$output = [];
- $taskAnswers = $this->etask->task['answers'];
+ $options = $this['questiondata']['options'] ? $this['questiondata']['options']->getArrayCopy() : [];
- foreach ($taskAnswers as $key => $option) {
+ foreach ($options as $key => $option) {
$answerOption = [];
$countNobodys = 0;
@@ -149,7 +118,7 @@ class Vote extends QuestionnaireQuestion implements QuestionType
$answerOption[$userId] = 0;
}
}
- $output[$option['text']] = $answerOption;
+ $output[$option] = $answerOption;
}
return $output;
}