예제 #1
0
 public function updateReview(DB $db, APIRequest $request, APIResponse $response)
 {
     $this->vars->review = new PerformanceReview();
     $this->vars->review->loadById($db, $request->get('reviewId'));
     //validate?
     foreach ($request->post('questions') as $questionId => $answerPost) {
         $answer = new ReviewAnswer();
         if (!$answer->loadOneWhere($db, 'question_id = ? and review_id = ?', [$questionId, $this->vars->review->id])) {
             $answer->questionId = $questionId;
             $answer->reviewId = $this->vars->review->id;
         }
         $answer->text = $answerPost['text'];
         $answer->scale = $answerPost['scale'];
         $answer->store($db);
     }
     if ($_POST['action'] == 'submit') {
         $this->vars->review->submitted = 'yes';
         $this->vars->review->submittedYmdt = gmdate('Y-m-d H:i:s');
         $this->vars->review->submit($db);
         $updater = new WorkflowUpdater();
         $workflow = new Workflow();
         $workflow->loadOneWhere($db, 'table_row_id = ? and type = ?', [$this->vars->review->id, 'review']);
         $updater->complete($db, $workflow);
     }
     $response->success();
 }
 public function updateReview(APIRequest $request, APIResponse $response)
 {
     $reviewId = $request->get('id');
     try {
         //The API could use a different Request object, as long as it implements the right
         //interface.
         $reviewAnswers = new ReviewAnswersRequest($reviewId, $request->post('questions'));
     } catch (InvalidArgumentException $exception) {
         //invalid data posted.
         $response->errorCode(400);
         $response->errorMessage('You did it wrong!');
         return true;
     }
     $this->getPerformanceReviewService()->answerReviewQuestions($reviewAnswers);
     $response->successCode(200);
     return true;
 }
예제 #3
0
파일: api.php 프로젝트: osuisumi/OS.js
 public static function ErrorHandler()
 {
     $response = null;
     if (!is_null($e = error_get_last())) {
         $type = 'UNKNOWN';
         switch ((int) $e['type']) {
             case E_ERROR:
                 // 1
                 $type = 'E_ERROR';
                 break;
             case E_WARNING:
                 // 2
                 $type = 'E_WARNING';
                 break;
             case E_PARSE:
                 // 4
                 $type = 'E_PARSE';
                 break;
             case E_NOTICE:
                 // 8
                 $type = 'E_NOTICE';
                 break;
             case E_CORE_ERROR:
                 // 16
                 $type = 'E_CORE_ERROR';
                 break;
             case E_CORE_WARNING:
                 // 32
                 $type = 'E_CORE_WARNING';
                 break;
             case E_CORE_ERROR:
                 // 64
                 $type = 'E_COMPILE_ERROR';
                 break;
             case E_CORE_WARNING:
                 // 128
                 $type = 'E_COMPILE_WARNING';
                 break;
             case E_USER_ERROR:
                 // 256
                 $type = 'E_USER_ERROR';
                 break;
             case E_USER_WARNING:
                 // 512
                 $type = 'E_USER_WARNING';
                 break;
             case E_USER_NOTICE:
                 // 1024
                 $type = 'E_USER_NOTICE';
                 break;
             case E_STRICT:
                 // 2048
                 $type = 'E_STRICT';
                 break;
             case E_RECOVERABLE_ERROR:
                 // 4096
                 $type = 'E_RECOVERABLE_ERROR';
                 break;
             case E_DEPRECATED:
                 // 8192
                 $type = 'E_DEPRECATED';
                 break;
             case E_USER_DEPRECATED:
                 // 16384
                 $type = 'E_USER_DEPRECATED';
                 break;
         }
         if (!ERRHANDLER && !in_array($type, array('E_ERROR', 'E_PARSE', 'E_CORE_ERROR', 'E_RECOVERABLE_ERROR'))) {
             return;
         }
         if (ob_get_level()) {
             ob_end_clean();
         }
         $error = $e["message"];
         if (SHOWERRORS) {
             $error = implode("\n", array($e['message'], "Type: {$type}", "Line: {$e['line']}", "File: {$e['file']}"));
         }
         $response = new APIResponse(false, false, $error, 500);
     }
     if ($response) {
         $response->output();
     }
 }
예제 #4
0
function exceptionHandlerForAPI(Exception $exception)
{
    $bt = $exception->getTrace();
    array_unshift($bt, array('line' => $exception->getLine(), 'file' => $exception->getFile()));
    Kurogo::log(LOG_ALERT, "A " . get_class($exception) . " has occured: " . $exception->getMessage(), "exception", $bt);
    $error = KurogoError::errorFromException($exception);
    $response = new APIResponse();
    $response->setVersion(0);
    $response->setError($error);
    $response->display();
    exit;
}
예제 #5
0
function exceptionHandlerForAPI($exception) {
    $error = KurogoError::errorFromException($exception);
    $response = new APIResponse();
    $response->setVersion(0);
    $response->setError($error);
    $response->display();
}
예제 #6
0
<?php

include_once 'utils/xml-converter.php';
include_once 'utils/strings.php';
include_once 'classes/api-request.php';
include_once 'classes/api-response.php';
include_once 'classes/api-response-handler.php';
$timestampStart = time();
$requestURI = $_SERVER['REQUEST_URI'];
$request = new APIRequest($requestURI);
$handler = new APIResponseHandler($request);
$obj = $handler->getObject();
$response = new APIResponse();
$response->setData($obj);
$timestampEnd = time();
$response->setDelay($timestampEnd - $timestampStart);
// Prepares the result
$arr = array("request" => $request->toArray(), "response" => $response->toArray());
if ($request->getExtension() == "json") {
    $json = json_encode($arr);
    header('Content-Type: text/json');
    echo $json;
} else {
    if ($request->getExtension() == "xml") {
        $xml = new SimpleXMLElement('<root/>');
        array_to_xml($arr, $xml);
        header('Content-Type: text/xml');
        echo $xml->asXML();
    }
}