Ajax::run('getRelations', 'both', function () { $current_user = wp_get_current_user(); $ret = []; // need to get the evaluations a user is associated with // in order to get the corresponding unique relations $unique_relation_ids = []; if (0 !== $current_user->ID) { $evaluations = null; if ('administrator' === $current_user->roles[0]) { $evaluations = get_posts(['post_type' => 'evaluation', 'posts_per_page' => -1]); } else { $evaluations = UserModel::getRelations($current_user->ID); } foreach ($evaluations as $key => $evaluation) { $evaluation_pod = pods('evaluation', (int) $evaluation->ID); $relation = $evaluation_pod->field('relation'); if (!$relation) { continue; } if (!in_array($relation['ID'], $unique_relation_ids)) { $relation_pod = pods('relation', $relation['ID']); if (!$relation_pod) { continue; } $ret[] = ['company' => $relation_pod->field('company'), 'agency' => $relation_pod->field('agency'), 'brand' => $relation_pod->field('brand'), 'country' => $relation_pod->field('country'), 'period_year' => $relation_pod->field('period_year'), 'period_quarter' => $relation_pod->field('period_quarter'), '180_360' => $evaluation_pod->field('180_360'), 'post' => $relation]; $unique_relation_ids[] = $relation['ID']; } } } // response output header("Content-Type: application/json"); echo json_encode($ret); exit; });
$filename = $type . '_' . $limesurvey_id . '_questions.json'; $questions = json_decode(file_get_contents(CABSPATH . 'cache/' . $filename), true); $user_role = $_POST['userRole']; // response output header("Content-Type: application/json"); echo json_encode($questions[$user_role]); exit; }); /** * */ Ajax::run('genRelationSurveys', 'both', function () { $evaluation_id = $_REQUEST['evaluation_id']; $evaluation_pod = pods('evaluation', $evaluation_id); $relation = $evaluation_pod->field('relation'); $relation_pod = pods('relation', $relation['ID']); $relation_type = $evaluation_pod->field('180_360'); $relation_steps = EvaluationModel::getSteps($relation_type); $survey_ids = []; foreach ($relation_steps as $key => $curr_step) { $questions_type = $curr_step === '360' ? 'company' : 'agency'; $limesurvey_id = EvaluationModel::surveyID($evaluation_id, $curr_step); $survey_ids[] = $limesurvey_id; $groups = LimesurveyModel::generateGroupsJsonCache($limesurvey_id, $questions_type); LimesurveyModel::generateQuestionsJsonCache($limesurvey_id, $questions_type, $groups); } // response output header("Content-Type: application/json"); echo json_encode($survey_ids); exit; });