Пример #1
0
 public function getAll()
 {
     $viewers = Viewer::all();
     foreach ($viewers as $viewer) {
         unset($viewer->update_user);
         unset($viewer->create_user);
         unset($viewer->viewer_owner_uuid);
     }
     return $viewers;
 }
 public function getResults($assessmentResultsUuid, $viewerUuid, $projectUuid)
 {
     // get latest version of viewer
     //
     $viewer = Viewer::where('viewer_uuid', '=', $viewerUuid)->first();
     $viewerVersion = $viewer->getLatestVersion();
     $viewerVersionUuid = $viewerVersion->viewer_version_uuid;
     if ($assessmentResultsUuid != "none") {
         foreach (explode(',', $assessmentResultsUuid) as $resultUuid) {
             $assessmentResult = AssessmentResult::where('assessment_result_uuid', '=', $resultUuid)->first();
             $execution = ExecutionRecord::where('execution_record_uuid', '=', $assessmentResult->execution_record_uuid)->first();
             $assessmentRun = AssessmentRun::where('assessment_run_uuid', '=', $execution->assessment_run_uuid)->first();
             if ($assessmentRun) {
                 $result = $this->checkPermissions($assessmentRun);
                 if ($result !== true) {
                     return $result;
                 }
             }
         }
     }
     // create stored procedure call
     //
     $connection = DB::connection('assessment');
     $pdo = $connection->getPdo();
     $stmt = $pdo->prepare("CALL launch_viewer(:assessmentResultsUuid, :userUuidIn, :viewerVersionUuid, :projectUuid, @returnUrl, @returnString, @viewerInstanceUuid);");
     // bind params
     //
     $stmt->bindParam(":assessmentResultsUuid", $assessmentResultsUuid, PDO::PARAM_STR, 5000);
     $stmt->bindParam(":userUuidIn", $userUuidIn, PDO::PARAM_STR, 45);
     $stmt->bindParam(":viewerVersionUuid", $viewerVersionUuid, PDO::PARAM_STR, 45);
     $stmt->bindParam(":projectUuid", $projectUuid, PDO::PARAM_STR, 45);
     // set param values
     //
     if ($assessmentResultsUuid == 'none') {
         $assessmentResultsUuid = '';
     }
     $userUuidIn = Session::get('user_uid');
     $returnUrl = null;
     $returnString = null;
     $viewerInstanceUuid = null;
     // call stored procedure
     //
     $results = $stmt->execute();
     // fetch return parameters
     //
     $select = $pdo->query('SELECT @returnUrl, @returnString, @viewerInstanceUuid');
     $results = $select->fetchAll();
     $returnUrl = $results[0]["@returnUrl"];
     $returnString = $results[0]["@returnString"];
     $viewerInstanceUuid = $results[0]["@viewerInstanceUuid"];
     if (substr($returnUrl, -4) == 'html') {
         // return results
         //
         return array("assessment_results_uuid" => $assessmentResultsUuid, "results" => file_get_contents($returnUrl), "results_status" => $returnString);
     } else {
         // get url/status from viewer instance if present
         // otherwise just use what database gave us.
         // FIXME viewer is always present when url has no .html?
         if ($viewerInstanceUuid) {
             $instance = ViewerInstance::where('viewer_instance_uuid', '=', $viewerInstanceUuid)->first();
             // TODO what is return value of status when returns immediately
             // if proxy url, return it
             //
             if ($instance->proxy_url) {
                 $pdo->query("CALL select_system_setting ('CODEDX_BASE_URL',@rtn);");
                 $base_url = $pdo->query("SELECT @rtn")->fetchAll()[0]["@rtn"];
                 if ($base_url) {
                     $returnUrl = $base_url . $instance->proxy_url;
                     return array("assessment_results_uuid" => $assessmentResultsUuid, "results_url" => $returnUrl, "results_status" => $returnString);
                 }
             } else {
                 return array("results_viewer_status" => $instance->status, "results_status" => "LOADING", "viewer_instance" => $viewerInstanceUuid);
             }
         }
         // return results url
         //
         return array("assessment_results_uuid" => $assessmentResultsUuid, "results_url" => $returnUrl, "results_status" => $returnString);
     }
 }