Skip to content

Commit a2a75a1

Browse files
author
Chris Gårdenberg
committed
v1.0.2 - Bugfix
- Fixes questions and attributes being rendered faulty
1 parent 1cf187d commit a2a75a1

3 files changed

Lines changed: 77 additions & 17 deletions

File tree

includes/_attributeFunctions.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,12 @@ function renderSelectField( $attribute, $multiple, $suffix, $data ) {
8181
echo $attribute->AttributeDescription;
8282
echo "</div><div class=\"inputHolder\">";
8383
echo "<select name=\"edu-attr_" . $attribute->AttributeID . ( $suffix != "" ? "-" . $suffix : "" ) . ( $multiple ? "[]" : "" ) . "\">\n";
84-
foreach ( $attribute->AttributeAlternative as $val ) {
84+
if ( is_array( $attribute->AttributeAlternative ) ) {
85+
foreach ( $attribute->AttributeAlternative as $val ) {
86+
echo "\t<option" . ( $data != null && $data == $val->AttributeAlternativeID ? " selected=\"selected\"" : "" ) . " value=\"" . $val->AttributeAlternativeID . "\">" . $val->AttributeAlternativeDescription . "</option>\n";
87+
}
88+
} else {
89+
$val = $attribute->AttributeAlternative;
8590
echo "\t<option" . ( $data != null && $data == $val->AttributeAlternativeID ? " selected=\"selected\"" : "" ) . " value=\"" . $val->AttributeAlternativeID . "\">" . $val->AttributeAlternativeDescription . "</option>\n";
8691
}
8792
echo "</select>";
@@ -92,7 +97,12 @@ function renderCheckboxListField( $attribute, $multiple, $suffix, $data ) {
9297
echo "<div class=\"inputLabel\">";
9398
echo $attribute->AttributeDescription;
9499
echo "</div><div class=\"inputHolder\">";
95-
foreach ( $attribute->AttributeAlternative as $val ) {
100+
if ( is_array( $attribute->AttributeAlternative ) ) {
101+
foreach ( $attribute->AttributeAlternative as $val ) {
102+
echo "\t<label><input" . ( $data != null && $data == $val->AttributeAlternativeID ? " checked=\"checked\"" : "" ) . " type=\"checkbox\" name=\"edu-attr_" . $attribute->AttributeID . ( $suffix != "" ? "-" . $suffix : "" ) . ( $multiple ? "[]" : "" ) . "\" value=\"" . $val->AttributeAlternativeID . "\">" . $val->AttributeAlternativeDescription . "</label>\n";
103+
}
104+
} else {
105+
$val = $attribute->AttributeAlternative;
96106
echo "\t<label><input" . ( $data != null && $data == $val->AttributeAlternativeID ? " checked=\"checked\"" : "" ) . " type=\"checkbox\" name=\"edu-attr_" . $attribute->AttributeID . ( $suffix != "" ? "-" . $suffix : "" ) . ( $multiple ? "[]" : "" ) . "\" value=\"" . $val->AttributeAlternativeID . "\">" . $val->AttributeAlternativeDescription . "</label>\n";
97107
}
98108
echo "</div>";

includes/_questionFunctions.php

Lines changed: 62 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,30 @@ function renderQuestion( $question ) {
4444
function renderNoteQuestion( $question ) {
4545
echo "<label><h3 class=\"inputLabel noteQuestion\">" . $question->QuestionText . ( $question->Answers->EventBookingAnswer->Price > 0 ? " <i class=\"priceLabel\">(" . convertToMoney( $question->Answers->EventBookingAnswer->Price ) . ")</i>" : "" ) . "</h3>";
4646
echo "<div class=\"inputHolder\">";
47-
echo "<textarea name=\"question_" . $question->Answers->EventBookingAnswer->AnswerID . "_note\" data-type=\"note\" onchange=\"eduBookingView.UpdatePrice();\" data-price=\"" . $question->Answers->EventBookingAnswer->Price . "\" resizable=\"resizable\" class=\"questionNoteField\" rows=\"3\">" . $question->Answers->EventBookingAnswer->DefaultAnswerText . "</textarea>";
47+
echo "<textarea name=\"question_" . $question->Answers->EventBookingAnswer->AnswerID . "_note\" data-type=\"note\" onchange=\"eduBookingView.UpdatePrice();\" data-price=\"" . $question->Answers->EventBookingAnswer->Price . "\"" . ( $question->Mandatory ? " required=\"required\"" : "" ) . " resizable=\"resizable\" class=\"questionNoteField\" rows=\"3\">" . $question->Answers->EventBookingAnswer->DefaultAnswerText . "</textarea>";
4848
echo "</div></label>";
4949
}
5050

5151
// QuestionTypeID 2
5252
function renderCheckBoxQuestion( $question ) {
5353
echo "<h3 class=\"inputLabel checkBoxQuestion\">" . $question->QuestionText . "</h3>";
54-
foreach ( $question->Answers->EventBookingAnswer as $q ) {
54+
if ( is_array( $question->Answers->EventBookingAnswer ) ) {
55+
foreach ( $question->Answers->EventBookingAnswer as $q ) {
56+
echo "<label>";
57+
echo "<div class=\"inputHolder\">";
58+
echo "<input type=\"checkbox\" class=\"questionCheck\" data-type=\"check\" data-price=\"" . $q->Price . "\" onchange=\"eduBookingView.UpdatePrice();\" name=\"question_" . $question->QuestionID . "_check\"" . ( $q->DefaultAlternative == 1 ? " checked=\"checked\"" : "" ) . "" . ( $question->Mandatory ? " required=\"required\"" : "" ) . " value=\"" . $q->AnswerID . "\" /> ";
59+
echo $q->AnswerText;
60+
if ( $q->Price > 0 ) {
61+
echo " <i class=\"priceLabel\">(" . convertToMoney( $q->Price ) . ")</i>";
62+
}
63+
echo "</div>";
64+
echo "</label>";
65+
}
66+
} else if ( is_object( $question->Answers->EventBookingAnswer ) ) {
67+
$q = $question->Answers->EventBookingAnswer;
5568
echo "<label>";
5669
echo "<div class=\"inputHolder\">";
57-
echo "<input type=\"checkbox\" class=\"questionCheck\" data-type=\"check\" data-price=\"" . $q->Price . "\" onchange=\"eduBookingView.UpdatePrice();\" name=\"question_" . $question->QuestionID . "_check\"" . ( $q->DefaultAlternative == 1 ? " checked=\"checked\"" : "" ) . " value=\"" . $q->AnswerID . "\" /> ";
70+
echo "<input type=\"checkbox\" class=\"questionCheck\" data-type=\"check\" data-price=\"" . $q->Price . "\" onchange=\"eduBookingView.UpdatePrice();\"" . ( $question->Mandatory ? " required=\"required\"" : "" ) . " name=\"question_" . $question->QuestionID . "_check\"" . ( $q->DefaultAlternative == 1 ? " checked=\"checked\"" : "" ) . " value=\"" . $q->AnswerID . "\" /> ";
5871
echo $q->AnswerText;
5972
if ( $q->Price > 0 ) {
6073
echo " <i class=\"priceLabel\">(" . convertToMoney( $q->Price ) . ")</i>";
@@ -71,9 +84,9 @@ function renderDateQuestion( $question ) {
7184
echo $question->QuestionText . ( $question->Answers->EventBookingAnswer->Price > 0 ? " <i class=\"priceLabel\">(" . convertToMoney( $question->Answers->EventBookingAnswer->Price ) . ")</i>" : "" );
7285
echo "</div>";
7386
echo "<div class=\"inputHolder\">";
74-
echo "<input type=\"date\" class=\"questionDate\" data-type=\"date\" onchange=\"eduBookingView.UpdatePrice();\" data-price=\"" . $question->Answers->EventBookingAnswer->Price . "\" name=\"question_" . $question->Answers->EventBookingAnswer->AnswerID . "_date\" />";
87+
echo "<input type=\"date\" class=\"questionDate\" data-type=\"date\" onchange=\"eduBookingView.UpdatePrice();\" data-price=\"" . $question->Answers->EventBookingAnswer->Price . "\"" . ( $question->Mandatory ? " required=\"required\"" : "" ) . " name=\"question_" . $question->Answers->EventBookingAnswer->AnswerID . "_date\" />";
7588
if ( $question->Time == 1 ) {
76-
echo "<input type=\"time\" onchange=\"eduBookingView.UpdatePrice();\" class=\"questionTime\" name=\"question_" . $question->Answers->EventBookingAnswer->AnswerID . "_time\" />";
89+
echo "<input type=\"time\" onchange=\"eduBookingView.UpdatePrice();\" class=\"questionTime\"" . ( $question->Mandatory ? " required=\"required\"" : "" ) . " name=\"question_" . $question->Answers->EventBookingAnswer->AnswerID . "_time\" />";
7790
}
7891
echo "</div>";
7992
echo "</label>";
@@ -86,8 +99,18 @@ function renderDropListQuestion( $question ) {
8699
echo $question->QuestionText;
87100
echo "</div>";
88101
echo "<div class=\"inputHolder\">";
89-
echo "<select class=\"questionDropdown\" onchange=\"eduBookingView.UpdatePrice();\" name=\"question_" . $question->QuestionID . "_dropdown\">";
90-
foreach ( $question->Answers->EventBookingAnswer as $q ) {
102+
echo "<select class=\"questionDropdown\" onchange=\"eduBookingView.UpdatePrice();\"" . ( $question->Mandatory ? " required=\"required\"" : "" ) . " name=\"question_" . $question->QuestionID . "_dropdown\">";
103+
if ( is_array( $question->Answers->EventBookingAnswer ) ) {
104+
foreach ( $question->Answers->EventBookingAnswer as $q ) {
105+
echo "<option value=\"" . $q->AnswerID . "\"" . ( $q->DefaultAlternative == 1 ? " selected=\"selected\"" : "" ) . " data-type=\"dropdown\" data-price=\"" . $q->Price . "\">";
106+
echo $q->AnswerText;
107+
if ( $q->Price > 0 ) {
108+
echo " (" . convertToMoney( $q->Price ) . ")";
109+
}
110+
echo "</option>";
111+
}
112+
} else if ( is_object( $question->Answers->EventBookingAnswer ) ) {
113+
$q = $question->Answers->EventBookingAnswer;
91114
echo "<option value=\"" . $q->AnswerID . "\"" . ( $q->DefaultAlternative == 1 ? " selected=\"selected\"" : "" ) . " data-type=\"dropdown\" data-price=\"" . $q->Price . "\">";
92115
echo $q->AnswerText;
93116
if ( $q->Price > 0 ) {
@@ -106,7 +129,7 @@ function renderNumberQuestion( $question ) {
106129
echo $question->QuestionText;
107130
echo "</div>";
108131
echo "<div class=\"inputHolder\">";
109-
echo "<input type=\"number\" class=\"questionText\" onchange=\"eduBookingView.UpdatePrice();\" data-price=\"" . $question->Answers->EventBookingAnswer->Price . "\" min=\"0\" data-type=\"number\" name=\"question_" . $question->Answers->EventBookingAnswer->AnswerID . "_number\" placeholder=\"" . edu__( "Quantity" ) . "\" />";
132+
echo "<input type=\"number\" class=\"questionText\" onchange=\"eduBookingView.UpdatePrice();\"" . ( $question->Mandatory ? " required=\"required\"" : "" ) . " data-price=\"" . $question->Answers->EventBookingAnswer->Price . "\" min=\"0\" data-type=\"number\" name=\"question_" . $question->Answers->EventBookingAnswer->AnswerID . "_number\" placeholder=\"" . edu__( "Quantity" ) . "\" />";
110133
if ( $question->Answers->EventBookingAnswer->Price > 0 ) {
111134
echo " <i class=\"priceLabel\">(" . sprintf( edu__( '%1$s / pcs' ), convertToMoney( $question->Answers->EventBookingAnswer->Price ) ) . ")</i>";
112135
}
@@ -127,10 +150,23 @@ function renderInfoText( $question ) {
127150
function renderRadioQuestion( $question, $display ) {
128151
echo "<h3 class=\"inputLabel radioQuestion\">" . $question->QuestionText . "</h3>";
129152
if ( $display == 'vertical' ) {
130-
foreach ( $question->Answers->EventBookingAnswer as $q ) {
153+
if ( is_array( $question->Answers->EventBookingAnswer ) ) {
154+
foreach ( $question->Answers->EventBookingAnswer as $q ) {
155+
echo "<label class=\"questionRadioVertical\">";
156+
echo "<div class=\"inputHolder\">";
157+
echo "<input type=\"radio\" class=\"questionRadio\" data-type=\"radio\"" . ( $question->Mandatory ? " required=\"required\"" : "" ) . " data-price=\"" . $q->Price . "\" name=\"question_" . $question->QuestionID . "_radio\" value=\"" . $q->AnswerID . "\" /> ";
158+
echo $q->AnswerText;
159+
if ( $q->Price > 0 ) {
160+
echo " <i class=\"priceLabel\">(" . convertToMoney( $q->Price ) . ")</i>";
161+
}
162+
echo "</div>";
163+
echo "</label>";
164+
}
165+
} else if ( is_object( $question->Answers->EventBookingAnswer ) ) {
166+
$q = $question->Answers->EventBookingAnswer;
131167
echo "<label class=\"questionRadioVertical\">";
132168
echo "<div class=\"inputHolder\">";
133-
echo "<input type=\"radio\" class=\"questionRadio\" data-type=\"radio\" data-price=\"" . $q->Price . "\" name=\"question_" . $question->QuestionID . "_radio\" value=\"" . $q->AnswerID . "\" /> ";
169+
echo "<input type=\"radio\" class=\"questionRadio\" data-type=\"radio\"" . ( $question->Mandatory ? " required=\"required\"" : "" ) . " data-price=\"" . $q->Price . "\" name=\"question_" . $question->QuestionID . "_radio\" value=\"" . $q->AnswerID . "\" /> ";
134170
echo $q->AnswerText;
135171
if ( $q->Price > 0 ) {
136172
echo " <i class=\"priceLabel\">(" . convertToMoney( $q->Price ) . ")</i>";
@@ -139,10 +175,23 @@ function renderRadioQuestion( $question, $display ) {
139175
echo "</label>";
140176
}
141177
} else if ( $display == 'horizontal' ) {
142-
foreach ( $question->Answers->EventBookingAnswer as $q ) {
178+
if ( is_array( $question->Answers->EventBookingAnswer ) ) {
179+
foreach ( $question->Answers->EventBookingAnswer as $q ) {
180+
echo "<label class=\"questionRadioHorizontal\">";
181+
echo "<div class=\"inputHolder\">";
182+
echo "<input type=\"radio\" class=\"questionRadio\" data-type=\"radio\"" . ( $question->Mandatory ? " required=\"required\"" : "" ) . " data-price=\"" . $q->Price . "\" name=\"question_" . $question->QuestionID . "_radio\" value=\"" . $q->AnswerID . "\" /> ";
183+
echo $q->AnswerText;
184+
if ( $q->Price > 0 ) {
185+
echo " <i class=\"priceLabel\">(" . convertToMoney( $q->Price ) . ")</i>";
186+
}
187+
echo "</div>";
188+
echo "</label>";
189+
}
190+
} else if ( is_object( $question->Answers->EventBookingAnswer ) ) {
191+
$q = $question->Answers->EventBookingAnswer;
143192
echo "<label class=\"questionRadioHorizontal\">";
144193
echo "<div class=\"inputHolder\">";
145-
echo "<input type=\"radio\" class=\"questionRadio\" data-type=\"radio\" data-price=\"" . $q->Price . "\" name=\"question_" . $question->QuestionID . "_radio\" value=\"" . $q->AnswerID . "\" /> ";
194+
echo "<input type=\"radio\" class=\"questionRadio\" data-type=\"radio\"" . ( $question->Mandatory ? " required=\"required\"" : "" ) . " data-price=\"" . $q->Price . "\" name=\"question_" . $question->QuestionID . "_radio\" value=\"" . $q->AnswerID . "\" /> ";
146195
echo $q->AnswerText;
147196
if ( $q->Price > 0 ) {
148197
echo " <i class=\"priceLabel\">(" . convertToMoney( $q->Price ) . ")</i>";
@@ -162,7 +211,7 @@ function renderTextQuestion( $question ) {
162211
echo $question->QuestionText . ( $question->Answers->EventBookingAnswer->Price > 0 ? " <i class=\"priceLabel\">(" . convertToMoney( $question->Answers->EventBookingAnswer->Price ) . ")</i>" : "" );
163212
echo "</div>";
164213
echo "<div class=\"inputHolder\">";
165-
echo "<input type=\"text\" data-price=\"" . $question->Answers->EventBookingAnswer->Price . "\" onchange=\"eduBookingView.UpdatePrice();\" data-type=\"text\" class=\"questionText\" name=\"question_" . $question->Answers->EventBookingAnswer->AnswerID . "_text\" />";
214+
echo "<input type=\"text\" data-price=\"" . $question->Answers->EventBookingAnswer->Price . "\"" . ( $question->Mandatory ? " required=\"required\"" : "" ) . " onchange=\"eduBookingView.UpdatePrice();\" data-type=\"text\" class=\"questionText\" name=\"question_" . $question->Answers->EventBookingAnswer->AnswerID . "_text\" />";
166215
echo "</div>";
167216
echo "</label>";
168217
}

readme.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Contributors: mnchga
33
Tags: booking, participants, courses, events, eduadmin, lega online
44
Requires at least: 3.0
55
Tested up to: 4.8.3
6-
Stable tag: 1.0.1
6+
Stable tag: 1.0.2
77
Requires PHP: 5.0.1 (with SoapClient)
88
License: GPL3
99
License-URI: https://www.gnu.org/licenses/gpl-3.0.en.html
@@ -34,9 +34,10 @@ Requires at least PHP 5.0.1 (with [SoapClient](http://php.net/manual/en/book.soa
3434

3535
== Changelog ==
3636

37-
### [Unreleased]
37+
### [1.0.2]
3838
- Removing internal language files
3939
- Removing `README.md` and `CHANGELOG.md`, these live inside `readme.txt` (this file)
40+
- Bugfix for questions and attributes with only one option (SOAP API gave us an object instead of an array)
4041

4142
### [1.0.1]
4243
- Modified when languages should load (`plugins_loaded` instead of `init`)

0 commit comments

Comments
 (0)