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


PHP jsonRPCClient::get_session_key方法代码示例

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


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

示例1: test

 /**
  * Simple procedure to test most RPC functions
  *
  */
 public function test()
 {
     $sFileToImport = dirname(Yii::app()->basePath) . DIRECTORY_SEPARATOR . 'docs' . DIRECTORY_SEPARATOR . 'demosurveys' . DIRECTORY_SEPARATOR . 'limesurvey2_sample_survey_english.lss';
     //        $sFileToImport=dirname(Yii::app()->basePath).DIRECTORY_SEPARATOR.'docs'.DIRECTORY_SEPARATOR.'demosurveys'.DIRECTORY_SEPARATOR.'survey_archive_example_feedback_survey.zip';
     Yii::app()->loadLibrary('jsonRPCClient');
     $myJSONRPCClient = new jsonRPCClient(Yii::app()->getBaseUrl(true) . '/' . dirname(Yii::app()->request->getPathInfo()));
     $sSessionKey = $myJSONRPCClient->get_session_key('admin', 'password');
     if (is_array($sSessionKey)) {
         echo $sSessionKey['status'];
         die;
     } else {
         echo 'Retrieved session key' . '<br>';
     }
     $sLSSData = base64_encode(file_get_contents($sFileToImport));
     $iSurveyID = $myJSONRPCClient->import_survey($sSessionKey, $sLSSData, 'zip', 'Test import by JSON_RPC', 1000);
     echo 'Created new survey SID:' . $iSurveyID . '<br>';
     /*
             Very simple example to export responses as Excel file
             $aResult=$myJSONRPCClient->export_reponses($sSessionKey,$iSurveyID,'xls');
             file_put_contents('d:\test.xls',base64_decode(chunk_split($aResult)));
     */
     $aResult = $myJSONRPCClient->activate_survey($sSessionKey, $iSurveyID);
     if ($aResult['status'] == 'OK') {
         echo 'Survey ' . $iSurveyID . ' successfully activated.<br>';
     }
     $aResult = $myJSONRPCClient->activate_participant_tokens($sSessionKey, $iSurveyID, array(1, 2));
     if ($aResult['status'] == 'OK') {
         echo 'Tokens for Survey ID ' . $iSurveyID . ' successfully activated.<br>';
     }
     $aResult = $myJSONRPCClient->set_survey_properties($sSessionKey, $iSurveyID, array('faxto' => '0800-LIMESURVEY'));
     if ($aResult['status'] == 'OK') {
         echo 'Modified survey settings for survey ' . $iSurveyID . '<br>';
     }
     $aResult = $myJSONRPCClient->add_survey_language($sSessionKey, $iSurveyID, 'ar');
     if ($aResult['status'] == 'OK') {
         echo 'Added Arabian as additional language' . '<br>';
     }
     $aResult = $myJSONRPCClient->set_survey_language_properties($sSessionKey, $iSurveyID, array('surveyls_welcometext' => 'An Arabian welcome text!'), 'ar');
     if ($aResult['status'] == 'OK') {
         echo 'Modified survey locale setting welcometext for Arabian in survey ID ' . $iSurveyID . '<br>';
     }
     $aResult = $myJSONRPCClient->delete_survey_language($sSessionKey, $iSurveyID, 'ar');
     if ($aResult['status'] == 'OK') {
         echo 'Removed Arabian as additional language' . '<br>';
     }
     die;
     $aResult = $myJSONRPCClient->delete_survey($sSessionKey, $iSurveyID);
     echo 'Deleted survey SID:' . $iSurveyID . '-' . $aResult['status'] . '<br>';
     // Release the session key - close the session
     $Result = $myJSONRPCClient->release_session_key($sSessionKey);
     echo 'Closed the session' . '<br>';
 }
开发者ID:rawaludin,项目名称:LimeSurvey,代码行数:56,代码来源:remotecontrol.php

示例2: die

     die(print_r(LS_RPC_PATH, true));
 }
 // get all evaluations for a given relation
 $relation_id = array_key_exists('relation_id', $_REQUEST) ? (int) $_REQUEST['relation_id'] : null;
 $relation_step = array_key_exists('step', $_REQUEST) ? (int) $_REQUEST['step'] : null;
 $evaluation_id = array_key_exists('evaluation_id', $_REQUEST) ? (int) $_REQUEST['evaluation_id'] : null;
 $evaluations = [];
 if ($relation_id) {
     $evaluations = RelationModel::evaluations($relation_id);
 } elseif ($evaluation_id) {
     $evaluations[] = pods('evaluation', $evaluation_id);
 }
 // instanciate a new client
 $myJSONRPCClient = new jsonRPCClient(LS_BASEURL);
 // receive session key
 $sessionKey = $myJSONRPCClient->get_session_key(LS_USER, LS_PASSWORD);
 // calculate averages for current evaluation
 $response = [];
 foreach ($evaluations as $key => $evaluation) {
     $limesurvey_id = EvaluationModel::surveyID($evaluation->ID, $relation_step);
     $type = $relation_step === '360' ? 'company' : 'agency';
     // questions
     $questions_filename = $type . '_' . $limesurvey_id . '_questions.json';
     $survey_questions = json_decode(file_get_contents(CABSPATH . 'cache/' . $questions_filename), true);
     $group_q = ['OP' => [], 'OM' => [], 'TM' => []];
     foreach ($survey_questions as $rolekey => $rolevalue) {
         foreach ($rolevalue as $sqkey => $sqvalue) {
             if (!array_key_exists($sqvalue['g']['id']['gid'], $group_q[$rolekey])) {
                 $group_q[$rolekey][$sqvalue['g']['id']['gid']] = ['name' => $sqvalue['g']['group_name'], 'gid' => $sqvalue['g']['id']['gid'], 'questions' => [], 'question_benchmarks' => [], 'questions_txt' => []];
             }
             $group_q[$rolekey][$sqvalue['g']['id']['gid']]['questions'][] = $sqvalue['q']['title'];
开发者ID:strikles,项目名称:php,代码行数:31,代码来源:reporting.php

示例3: 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

示例4: create

 /**
  * creates a single new limesurvey
  * @param  [type] $post_id       [description]
  * @param  [type] $relation_args [description]
  * @param  [type] $relation_step [description]
  * @return [type]                [description]
  */
 public static function create($post_id, $relation_args, $relation_step)
 {
     // require jsonRPCClient.php
     if (file_exists(LS_RPC_PATH)) {
         require_once LS_RPC_PATH;
     } else {
         die(print_r(LS_RPC_PATH, true));
     }
     // create a new client
     $myJSONRPCClient = new jsonRPCClient(LS_BASEURL);
     // get session key
     $sessionKey = $myJSONRPCClient->get_session_key(LS_USER, LS_PASSWORD);
     // check survey metadata
     $limesurveyid_field_name = 'survey_id_' . $relation_step;
     $limesurvey_id = $relation_args->evaluation_pod->field($limesurveyid_field_name);
     // check there isn't another relation with the same core relation and periods(year/quarter) to do
     // check survey id
     $survey_exists = !empty($limesurvey_id) && is_numeric($limesurvey_id);
     // if not create one
     if ($survey_exists) {
         error_log('>>> activating existig survey');
         self::activate_survey($sessionKey, $limesurvey_id, $relation_args, $myJSONRPCClient);
         $myJSONRPCClient->release_session_key($sessionKey);
         return;
     }
     // generate base64 string from import file
     $import_file = $relation_step . '.lss';
     $import_data = base64_encode(file_get_contents(CABSPATH . 'cache/' . $import_file));
     $survey_name = self::getSurveyName($relation_args, $relation_step);
     // import data
     $import_success_status = $myJSONRPCClient->import_survey($sessionKey, $import_data, 'lss', $survey_name);
     if (is_array($import_success_status)) {
         throw new Exception('Failed to import the survey ' . json_encode($import_success_status));
     } else {
         // save the newly created  survey id to the relation pod
         $new_survey_id = $import_success_status;
         update_post_meta($post_id, $limesurveyid_field_name, $new_survey_id);
         // activate survey if required
         self::activate_survey($sessionKey, $new_survey_id, $relation_args, $myJSONRPCClient);
         // generate corresponding cache
         self::generateJsonCaches($new_survey_id, $relation_step === '180' ? 'agency' : 'company');
     }
     // release key
     $myJSONRPCClient->release_session_key($sessionKey);
 }
开发者ID:strikles,项目名称:php,代码行数:52,代码来源:LimesurveyModel.php


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