本文整理汇总了PHP中Ajax::run方法的典型用法代码示例。如果您正苦于以下问题:PHP Ajax::run方法的具体用法?PHP Ajax::run怎么用?PHP Ajax::run使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Ajax
的用法示例。
在下文中一共展示了Ajax::run方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: function
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;
});
示例2: json_decode
$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;
});