当前位置: 首页>>代码示例>>PHP>>正文


PHP AjaxResponse::stream方法代码示例

本文整理汇总了PHP中AjaxResponse::stream方法的典型用法代码示例。如果您正苦于以下问题:PHP AjaxResponse::stream方法的具体用法?PHP AjaxResponse::stream怎么用?PHP AjaxResponse::stream使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在AjaxResponse的用法示例。


在下文中一共展示了AjaxResponse::stream方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: add_action

}
// delete relation
add_action('pods_api_pre_delete_pod_item_relation', 'delete_relation', 99999, 3);
function delete_relation($params, $pod)
{
    error_log('delete relation ' . json_encode($params) . '-' . json_encode($pod));
    $evaluations = RelationModel::evaluations($params->id);
    error_log('rel evaluations ' . json_encode($evaluations));
    foreach ($evaluations as $key => $evaluation) {
        wp_delete_post($evaluation->ID, true);
    }
}
// delete user
add_action('delete_user', 'remove_user');
function remove_user($user_id)
{
    $survey = pods('survey', ['limit' => -1, 'where' => 'user.ID = ' . $user_id]);
    while ($survey->fetch()) {
        $candidate_user = $survey->field('user');
        error_log(json_encode($candidate_user));
        if ($candidate_user) {
            error_log(json_encode($candidate_user));
            //wp_delete_post($user_survey->ID, true);
        }
    }
}
add_action('wp_ajax_response_seeder', function () {
    ResponseSeeder::run();
    AjaxResponse::stream(['success' => 'success'], true);
    exit;
});
开发者ID:strikles,项目名称:php,代码行数:31,代码来源:admin.php

示例2: run

 /**
  * [run - do all the seedings]
  * @return [json] [AjaxResponse]
  */
 public static function run()
 {
     // this function should do:
     // get the relationship
     // get all related user
     // fill in all surveys
     // output summary with Reponse::output
     $evaluation_id = (int) $_POST['evaluation_id'];
     $relation_users = EvaluationModel::users($evaluation_id);
     AjaxResponse::stream(['message' => 'Initiating seeding', 'status' => 'OK', 'log' => true]);
     foreach ($relation_users as $key => $user_id) {
         if (!is_numeric($relation_users[$key])) {
             error_log('Invalid user - ' . json_encode($relation_users[$key]));
         }
         // company / agency
         $user_type = UserModel::userType($user_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);
         foreach ($relation_steps as $relation_step) {
             // get the user
             $user = UserModel::findByID($user_id);
             // get survey id
             $limesurvey_id = EvaluationModel::surveyID($evaluation_id, $relation_step);
             $questions_type = $relation_step === '360' ? 'company' : 'agency';
             $filename = $questions_type . '_' . $limesurvey_id . '_questions.json';
             $all_questions = json_decode(file_get_contents(CABSPATH . 'cache/' . $filename), true);
             $user_role = $user->roles[0];
             $questions = null;
             if (!array_key_exists($user_role, $all_questions)) {
                 // status response
                 AjaxResponse::stream(['message' => 'ERROR: invalid role (could not load questions for user): ' . $user_id . ' ' . $relation_step, 'status' => 'failure', 'error' => true, 'log' => true], false);
                 continue;
             }
             // pich the right user role
             $questions = $all_questions[$user_role];
             // get question ids
             $question_ids = self::getQuestionIDs($limesurvey_id, $questions);
             // generate some random values for each question
             $question_answers = self::generateAnswers($question_ids);
             if (!count($question_answers)) {
                 // status response
                 AjaxResponse::stream(['message' => 'ERROR: could not generate answers processing user: ' . $user_id . ' ' . $relation_step, 'status' => 'failure', 'error' => true, 'log' => true], false);
                 continue;
             }
             $user_token = LimesurveyModel::getTokenByRelation($limesurvey_id, $user->user_email, $evaluation_id);
             if (!$user_token) {
                 // status response
                 AjaxResponse::stream(['message' => 'ERROR: could not match token for : ' . $user_id, 'status' => 'failure', 'error' => true, 'log' => true], false);
                 continue;
             }
             $res = array_merge($question_answers, ['token' => $user_token->tid]);
             // instanciate a new client
             $myJSONRPCClient = new jsonRPCClient(LS_BASEURL);
             // receive session key
             $sessionKey = $myJSONRPCClient->get_session_key(LS_USER, LS_PASSWORD);
             // save values
             $success_status = $myJSONRPCClient->add_response($sessionKey, $limesurvey_id, $res);
             // set participant status
             $participant_status = $myJSONRPCClient->set_participant_properties($sessionKey, $limesurvey_id, $user_token->tid, ['completed' => 'Y', 'usesleft' => 0]);
             // release session key
             $myJSONRPCClient->release_session_key($sessionKey);
             // status response
             AjaxResponse::stream(['message' => 'processing user: ' . $user_id . ' ' . $relation_step, 'status' => 'OK', 'log' => true], false);
         }
     }
 }
开发者ID:strikles,项目名称:php,代码行数:73,代码来源:ResponseSeeder.class.php


注:本文中的AjaxResponse::stream方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。