Пример #1
0
 });
 $has_branches = array_filter($actual_questions, function ($item) {
     return !empty($item["branching_logic"]);
 });
 $no_branches = array_filter($actual_questions, function ($item) {
     return empty($item["branching_logic"]);
 });
 $branched_fields = array_flip(array_column($has_branches, "field_name"));
 $unbranched_total = count($no_branches);
 //GET # OF COMPLETED FIELDS OF SURVEY
 $just_formnames = array_map(function ($item) {
     return $item["field_name"];
 }, $actual_questions);
 $instrument_complete = $instrument_id . "_complete";
 array_push($just_formnames, $instrument_complete);
 $user_answers = getUserAnswers($loggedInUser->id, $just_formnames);
 if (isset($user_answers[0])) {
     $user_actually_completed = !isset($user_answers[$current_arm]) ? $user_answers[0][$instrument_id . "_timestamp"] : $user_answers[$current_arm][$instrument_id . "_timestamp"];
     //= "[not completed]"
     //IF THERE ARE USER ANSWERS THEN MATCH THEM
     $surveys[$index]["survey_complete"] = ($user_actually_completed == "[not completed]" || $user_actually_completed == "") && empty($user_answers[0][$instrument_complete]) ? 0 : 1;
     if (!$surveys[$index]["survey_complete"]) {
         $core_surveys_complete = false;
     }
     $user_answers = array_filter($user_answers[0]);
     foreach ($metadata as $idx => $item) {
         $fn = $item["field_name"];
         $metadata[$idx]["user_answer"] = "";
         if (array_key_exists($fn, $user_answers)) {
             $metadata[$idx]["user_answer"] = $user_answers[$fn];
         }
Пример #2
0
    foreach ($surveys as $index => $instrument_event) {
        if ($instrument_event["instrument_name"] != $surveyid) {
            continue;
        }
        addSessionMessage("Come back later to complete the '" . $instrument_event["instrument_label"] . "' Survey.<br> And collect your reward : <span class='fruit " . $fruits[$index] . "'></span>  Get the whole fruit basket!", "notice");
    }
}
//FOR THE PIE CHART
$health_behaviors_complete = false;
$all_answers = array();
$graph_fields = array("core_walking_hr", "core_walking_min", "core_sitting_hr", "core_sitting_min");
foreach ($surveys as $index => $instrument_event) {
    if ($instrument_event["instrument_name"] !== "your_health_behaviors") {
        continue;
    }
    $all_answers = getUserAnswers(null, $graph_fields);
    $user_answers = array();
    foreach ($graph_fields as $key) {
        if ($instrument_event["survey_complete"]) {
            $health_behaviors_complete = true;
            if (array_key_exists($key, $instrument_event["completed_fields"])) {
                $user_answers[$key] = $instrument_event["completed_fields"][$key];
            }
        }
    }
}
// AGGREGATE OF ALL PARTICIPANTS
$ALL_TIME_WALKING_IN_MINUTES = 0;
$ALL_TIME_SITTING_IN_MINUTES = 0;
foreach ($all_answers as $answers) {
    foreach ($answers as $fieldname => $answer) {