Skip to content

Commit

Permalink
GHPR403: New Slider type question (PoetOS#403)
Browse files Browse the repository at this point in the history
Co-authored-by: toanlam <[email protected]>
  • Loading branch information
toanlamt and toanlam authored Dec 22, 2022
1 parent a6b0039 commit 5d08554
Show file tree
Hide file tree
Showing 28 changed files with 985 additions and 21 deletions.
30 changes: 30 additions & 0 deletions classes/edit_question_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,36 @@ public function validation($data, $files) {
}
}

// If this is a slider question.
if ($data['type_id'] == QUESSLIDER) {
if (isset($data['minrange']) && isset($data['maxrange']) && isset($data['startingvalue']) &&
isset($data['stepvalue'])) {
if ($data['minrange'] >= $data['maxrange']) {
$errors['maxrange'] = get_string('invalidrange', 'questionnaire');
}

if (($data['startingvalue'] > $data['maxrange']) || ($data['startingvalue'] < $data['minrange'])) {
$errors['startingvalue'] = get_string('invalidstartingvalue', 'questionnaire');
}

if ($data['startingvalue'] > 100 || $data['startingvalue'] < -100) {
$errors['startingvalue'] = get_string('invalidstartingvalue', 'questionnaire');
}

if (($data['stepvalue'] > $data['maxrange']) || $data['stepvalue'] < 1) {
$errors['stepvalue'] = get_string('invalidincrement', 'questionnaire');
}

if ($data['minrange'] < -100) {
$errors['minrange'] = get_string('invalidminmaxrange', 'questionnaire');
}

if ($data['maxrange'] > 100) {
$errors['maxrange'] = get_string('invalidminmaxrange', 'questionnaire');
}
}
}

return $errors;
}

Expand Down
4 changes: 4 additions & 0 deletions classes/output/mobile.php
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,10 @@ protected static function add_pagequestion_data($questionnaire, $pagenum, $respo
$question = $questionnaire->questions[$questionid];
if ($question->supports_mobile()) {
$pagequestions[] = $question->mobile_question_display($qnum, $questionnaire->autonum);
$mobileotherdata = $question->mobile_otherdata();
if (!empty($mobileotherdata)) {
$responses = array_merge($responses, $mobileotherdata);
}
if (($response !== null) && isset($response->answers[$questionid])) {
$responses = array_merge($responses, $question->get_mobile_response_data($response));
}
Expand Down
25 changes: 24 additions & 1 deletion classes/question/question.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
define('QUESRATE', 8);
define('QUESDATE', 9);
define('QUESNUMERIC', 10);
define('QUESSLIDER', 11);
define('QUESPAGEBREAK', 99);
define('QUESSECTIONTEXT', 100);

Expand Down Expand Up @@ -117,7 +118,8 @@ abstract class question {
QUESDATE => 'date',
QUESNUMERIC => 'numerical',
QUESPAGEBREAK => 'pagebreak',
QUESSECTIONTEXT => 'sectiontext'
QUESSECTIONTEXT => 'sectiontext',
QUESSLIDER => 'slider',
];

/** @var array $notifications Array of extra messages for display purposes. */
Expand Down Expand Up @@ -1563,6 +1565,9 @@ public function mobile_question_display($qnum, $autonum = false) {
];
$mobiledata->choices = $this->mobile_question_choices_display();

if ($this->mobile_question_extradata_display()) {
$mobiledata->extradata = json_decode($this->extradata);
}
if ($autonum) {
$mobiledata->content = $qnum . '. ' . $mobiledata->content;
$mobiledata->content_stripped = $qnum . '. ' . $mobiledata->content_stripped;
Expand Down Expand Up @@ -1617,4 +1622,22 @@ public function get_mobile_response_data($response) {

return $resultdata;
}

/**
* True if question need extradata for mobile app.
*
* @return bool
*/
public function mobile_question_extradata_display() {
return false;
}

/**
* Return the otherdata to be used by the mobile app.
*
* @return array
*/
public function mobile_otherdata() {
return [];
}
}
Loading

0 comments on commit 5d08554

Please sign in to comment.