Skip to content
This repository has been archived by the owner on Feb 27, 2021. It is now read-only.

Commit

Permalink
Redo data structure and clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
developerace committed Aug 22, 2017
1 parent a69faf0 commit 013e4a5
Show file tree
Hide file tree
Showing 3 changed files with 221 additions and 121 deletions.
78 changes: 36 additions & 42 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,63 +17,57 @@

} else {

//manual override because only short answer has been implemented
$questionTypeID = mt_rand(0, count($questions)-1);
//gets a random question from the sub array of question types
$questionID = mt_rand(0, count($questions[$questionTypeID])-1);
$questionID = mt_rand(0, count($questions)-1);

$questionObject = $questions[$questionTypeID][$questionID];
$questionObject = $questions[$questionID];

$smarty->assign("questionTypeID", $questionTypeID);
//$smarty->assign("questionID", $questionID);
$smarty->assign("questionText", $questions[$questionTypeID][$questionID]["question"]);
$smarty->assign("questionText", $questions[$questionID]["question"]);
//$smarty->assign("questionObject", $questionObject);

if($questionTypeID == 1) {
$choices = array();

$type = $questionObject["type"];
$smarty->assign("multiplechoicetype", $type);
switch ($type) {
case "randomFromAPI":
for ($questionNumber=0; $questionNumber <= 3; $questionNumber++) {
$choices[] = getFirstValueFromAPI($questionObject["API"]);
}
break;

case "text":
foreach ($questionObject as $key => $value) {
if (gettype($key) == "integer") {
$choices[] = $value; //add value to choices
}
}
break;

case "random":
for ($questionNumber=0; $questionNumber <= 3; $questionNumber++) {
$options = $questionObject["options"];
$choices[] = $options[mt_rand(0, count($options)-1)];
}
break;
$type = $questionObject["type"];
$smarty->assign("questiontype", $type);

default:
# code...
break;
if (in_array($type, array("multiplechoice", "rating"))) {
$source = $questionObject["source"];
$smarty->assign("datasource", $source);
}
$smarty->assign("choices", $choices);
$choices = array();

if ($type == "shortanswer") {
//do nothing
} elseif ($type == "multiplechoice" && $source == "randomFromAPI") {
for ($questionNumber=0; $questionNumber <= 3; $questionNumber++) {
$choices[] = getFirstValueFromAPI($questionObject["API"]);
}

} elseif ($type == "multiplechoice" && $source == "random") {
for ($questionNumber=0; $questionNumber <= 3; $questionNumber++) {
$options = $questionObject["options"];
$choices[] = $options[mt_rand(0, count($options)-1)];
}

} elseif ($type == "multiplechoice" && $source == "text") {
foreach ($questionObject as $key => $value) {
if (gettype($key) == "integer") {
$choices[] = $value; //add value to choices
}
}

} elseif($questionTypeID == 2) {
} elseif ($type == "rating" && $source == "randomFromAPI") {
$smarty->assign("ratingPhoto", getFirstValueFromAPI($questionObject["API"]));

if (isset($questionObject["randomFromAPI"])){
$smarty->assign("photoPath", getFirstValueFromAPI($questionObject["randomFromAPI"]));
} else {

} elseif ($type == "rating" && $source == "none") {
//do nothing
}
}


}
$smarty->assign("choices", $choices);


}


function getFirstValueFromAPI($URL) {
Expand Down
20 changes: 9 additions & 11 deletions index.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -19,30 +19,28 @@

{else}
<h2>{$questionText}</h2>
{if $questionTypeID eq 0}

<textarea form="continue" required></textarea>
{if $questiontype eq "shortanswer"}
<textarea form="continue" required></textarea>

{elseif $questionTypeID eq 1}

{if $multiplechoicetype eq "randomFromAPI"}
{elseif $questiontype eq "multiplechoice" and $datasource eq "randomFromAPI"}
<form class="multiplechoiceIMG">
{foreach from=$choices key=$key item=$value}
<label class="multiplechoiceIMG"><input type="radio" form="continue" name="multiplechoice" required><img class="multiplechoiceimage" src="{$value}"></label><br>
{/foreach}
</form>
{elseif $multiplechoicetype eq "text" or "random"}

{elseif $questiontype eq "multiplechoice" and $datasource eq "random" or $datasource eq "text"}
<form class="multiplechoice">
{foreach from=$choices key=$key item=$value}
<label class="multiplechoice"><input type="radio" form="continue" name="multiplechoice" required>{$value}</label><br>
{/foreach}
{/if}
</form>
</form>

{elseif $questionTypeID eq 2}
{elseif $questiontype eq "rating"}
<small>Click the red circles to rate</small>
{if isset($photoPath)}
<img class="rating" src="{$photoPath}" />
{if $datasource eq "randomFromAPI"}
<img class="rating" src="{$ratingPhoto}" />
{/if}
<form class="rating">
<span class="starRating">
Expand Down

0 comments on commit 013e4a5

Please sign in to comment.