本文整理汇总了PHP中jsonRPCClient::set_participant_properties方法的典型用法代码示例。如果您正苦于以下问题:PHP jsonRPCClient::set_participant_properties方法的具体用法?PHP jsonRPCClient::set_participant_properties怎么用?PHP jsonRPCClient::set_participant_properties使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类jsonRPCClient
的用法示例。
在下文中一共展示了jsonRPCClient::set_participant_properties方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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);
}
}
}
示例2: time
if ((int) $evaluation_type === 180 && (int) $relation_step === 180) {
error_log('survey completed sanity check pass');
$survey_completed = true;
} else {
$response_180 = $survey_pod->field('response_180');
$response_360 = $survey_pod->field('response_360');
if ((int) $evaluation_type === 360 && (int) $relation_step === 180 && !empty($response_360)) {
$survey_completed === true;
}
if ((int) $evaluation_type === 360 && (int) $relation_step === 360 && !empty($response_180)) {
$survey_completed === true;
}
}
if ($survey_completed === true) {
error_log('>>> setting survey completed to true');
$myJSONRPCClient->set_participant_properties($sessionKey, $limesurvey_id, $user_token->tid, ['completed' => 'Y', 'usesleft' => 0]);
$survey_args['completed'] = 1;
$survey_args['completed_date'] = date_i18n('d-M-Y G:i', time());
}
// response
$survey_args['response_' . $relation_step] = json_encode($_POST);
// save
$survey_pod->save($survey_args);
$posted_answers = $_POST;
// release the session key
$myJSONRPCClient->release_session_key($sessionKey);
$durations = ['TM' => 5, 'OM' => 10, 'OP' => 20];
$details = ['role' => $current_user->roles[0], 'company_or_agency' => get_user_meta($current_user->ID, 'company_or_agency', true), 'company' => $relation_pod->display('company'), 'agency' => $relation_pod->display('agency'), 'brand' => $relation_pod->display('brand'), 'country' => $relation_pod->display('country'), 'duration' => isset($durations[$current_user->roles[0]]) ? $durations[$current_user->roles[0]] : 20, 'expiration' => "11th September"];
$details['source_company'] = $details['company_or_agency'] == 'company' ? $details['company'] : $details['agency'];
$details['target_company'] = $details['company_or_agency'] == 'company' ? $details['agency'] : $details['company'];
// send notification Email