示例#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 doExecute(APIRequest $request)
 {
     $action = $request->getAction();
     if (!is_callable(array($this, $action))) {
         throw new RESTCommandException('Resource "' . $request->getResource() . '" does not support action "' . $action . '"');
     }
     return call_user_func(array($this, $action), $request);
 }
 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;
 }
示例#4
0
 /**
  * APIResponse constructor.
  *
  * @param string $body
  * @param object $jsonBody
  * @param string $signature
  */
 public function __construct($body, $jsonBody, $signature)
 {
     $this->protocol = $_SERVER['SERVER_PROTOCOL'];
     $this->method = $_SERVER['REQUEST_METHOD'];
     $this->path = $_SERVER['REQUEST_URI'] . $_SERVER['QUERY_STRING'];
     // TODO checkme
     $this->remoteAddress = $_SERVER['REMOTE_ADDR'];
     $this->headers = APIRequest::getAllHeaders();
     $this->body = $body;
     $this->jsonBody = $jsonBody;
     $this->signature = $signature;
 }
 /**
  * Make search over registrar notifications collection
  * 
  * @param SearchCriteria $criteria  Prepared search filters
  * @param int $limit results limit	
  * @param int $offset start rowset from
  * @param array $sort rowset sort rule array('field' => 'asc|desc')
  * 
  * @return str json response
  */
 public function search(SearchCriteria $criteria, $limit = 100, $offset = 0, array $sort = array(), $cltrid = false)
 {
     $get = $criteria->getCriteria();
     $get['do'] = 'search';
     $get['limit'] = $limit;
     $get['offset'] = $offset;
     foreach ($sort as $field => $direction) {
         $get['sort_field'] = $field;
         $get['sort_direction'] = $direction;
         // sorry. just one field
         break;
     }
     $json = APIRequest::GET('/notifications/', $cltrid ?: APIRequest::defaultClientTransactionID(), STRegistry::Session()->getAuthToken(), $get);
     return $json;
 }
示例#6
0
 /**
  * Populates the properties that store cached dimensions and metrics,
  * either from the database or from the API directly, depending on when
  * the data that we have was last fetched.
  */
 private function _refreshColumnMetadata()
 {
     /* If we're not using a database, the best we can do is to cache the
        column metadata for the duration of this process' existence. */
     if (self::$_dbConn) {
         try {
             $lastFetchData = self::_getLastFetchData('google_analytics_api_columns');
             if ($lastFetchData) {
                 $fetchDate = (int) $lastFetchData['fetch_date'];
                 $etag = $lastFetchData['etag'];
             } else {
                 $fetchDate = null;
                 $etag = null;
             }
             $columns = null;
             $newETag = null;
             if ($this->_bypassColumnCache || !$fetchDate || $fetchDate <= time() - GOOGLE_ANALYTICS_API_METADATA_CACHE_DURATION) {
                 $this->_bypassColumnCache = false;
                 $request = new APIRequest('metadata/ga/columns');
                 if ($etag) {
                     $request->setHeader('If-None-Match: ' . $etag);
                 }
                 $columns = $this->_makeRequest($request);
                 if ($columns) {
                     $stmt = self::$_DB_STATEMENTS['google_analytics_api_columns']['insert'];
                     foreach ($columns as $column) {
                         $stmt->bindValue(':name', $column->getName(), \PDO::PARAM_STR);
                         $stmt->bindValue(':type', $column->getType(), \PDO::PARAM_STR);
                         $stmt->bindValue(':data_type', $column->getDataType(), \PDO::PARAM_STR);
                         $stmt->bindValue(':replaced_by', $column->getReplacementColumn(), \PDO::PARAM_STR);
                         $stmt->bindValue(':group', $column->getGroup(), \PDO::PARAM_STR);
                         $stmt->bindValue(':ui_name', $column->getUIName(), \PDO::PARAM_STR);
                         $stmt->bindValue(':description', $column->getDescription(), \PDO::PARAM_STR);
                         $stmt->bindValue(':calculation', $column->getCalculation(), \PDO::PARAM_STR);
                         $stmt->bindValue(':min_template_index', $column->getMinTemplateIndex(), \PDO::PARAM_INT);
                         $stmt->bindValue(':max_template_index', $column->getMaxTemplateIndex(), \PDO::PARAM_INT);
                         $stmt->bindValue(':min_template_index_premium', $column->getPremiumMinTemplateIndex(), \PDO::PARAM_INT);
                         $stmt->bindValue(':max_template_index_premium', $column->getPremiumMaxTemplateIndex(), \PDO::PARAM_INT);
                         $stmt->bindValue(':allowed_in_segments', $column->isAllowedInSegments(), \PDO::PARAM_INT);
                         $stmt->bindValue(':deprecated', $column->isDeprecated(), \PDO::PARAM_INT);
                         $stmt->execute();
                     }
                     $stmt = null;
                 }
                 if (array_key_exists('etag', $this->_responseParsed) && $this->_responseParsed['etag']) {
                     $newETag = $this->_responseParsed['etag'];
                 } else {
                     $responseHeader = $this->getResponseHeaderAsAssociativeArray();
                     if (array_key_exists('ETag', $responseHeader) && $responseHeader['ETag']) {
                         $newETag = $responseHeader['ETag'];
                     }
                 }
                 if ($newETag) {
                     self::_storeFetchData('google_analytics_api_columns', count($columns), $newETag);
                 }
             }
             if (!$columns) {
                 $columns = array();
                 $stmt = self::$_dbConn->query('SELECT * FROM google_analytics_api_columns');
                 $stmt->bindColumn('name', $name, \PDO::PARAM_STR);
                 $stmt->bindColumn('type', $type, \PDO::PARAM_STR);
                 $stmt->bindColumn('data_type', $dataType, \PDO::PARAM_STR);
                 $stmt->bindColumn('replaced_by', $replacement, \PDO::PARAM_STR);
                 $stmt->bindColumn('group', $group, \PDO::PARAM_STR);
                 $stmt->bindColumn('ui_name', $uiName, \PDO::PARAM_STR);
                 $stmt->bindColumn('description', $description, \PDO::PARAM_STR);
                 $stmt->bindColumn('calculation', $calculation, \PDO::PARAM_STR);
                 /* Null values get cast to zeros if I bind them as
                    integers, so we'll rely on the object's setter to take care
                    of the type casting. */
                 $stmt->bindColumn('min_template_index', $minTemplateIndex, \PDO::PARAM_STR);
                 $stmt->bindColumn('max_template_index', $maxTemplateIndex, \PDO::PARAM_STR);
                 $stmt->bindColumn('min_template_index_premium', $minTemplateIndexPremium, \PDO::PARAM_STR);
                 $stmt->bindColumn('max_template_index_premium', $maxTemplateIndexPremium, \PDO::PARAM_STR);
                 $stmt->bindColumn('allowed_in_segments', $allowedInSegments, \PDO::PARAM_BOOL);
                 $stmt->bindColumn('deprecated', $deprecated, \PDO::PARAM_BOOL);
                 while ($stmt->fetch(\PDO::FETCH_BOUND)) {
                     $column = new Column();
                     $column->setID('ga:' . $name);
                     $column->setReplacementColumn($replacement);
                     $column->setType($type);
                     $column->setDataType($dataType);
                     $column->setGroup($group);
                     $column->setUIName($uiName);
                     $column->setDescription($description);
                     $column->setCalculation($calculation);
                     if ($minTemplateIndex !== null) {
                         $column->setMinTemplateIndex($minTemplateIndex);
                     }
                     if ($maxTemplateIndex !== null) {
                         $column->setMaxTemplateIndex($maxTemplateIndex);
                     }
                     if ($minTemplateIndexPremium !== null) {
                         $column->setPremiumMinTemplateIndex($minTemplateIndexPremium);
                     }
                     if ($maxTemplateIndexPremium !== null) {
                         $column->setPremiumMaxTemplateIndex($maxTemplateIndexPremium);
                     }
                     $column->isAllowedInSegments($allowedInSegments);
                     $column->isDeprecated($deprecated);
                     $columns[] = $column;
                 }
             }
         } catch (\PDOException $e) {
             throw new RuntimeException('Caught database error while refreshing column metadata.', null, $e);
         }
     } else {
         $columns = $this->_makeRequest(new APIRequest('metadata/ga/columns'));
     }
     foreach ($columns as $column) {
         if ($column->getType() == 'DIMENSION') {
             $table =& self::$_dimensions;
             $list =& self::$_dimensionNames;
         } else {
             $table =& self::$_metrics;
             $list =& self::$_metricNames;
         }
         $name = $column->getName();
         $table[$name] = $column;
         if (!$column->isDeprecated()) {
             $list[] = $name;
         }
     }
     usort(self::$_dimensionNames, 'strcasecmp');
     usort(self::$_metricNames, 'strcasecmp');
 }
示例#7
0
 /**
  * @internal
  * 
  * @return array
  */
 public function buildApiRequestArray()
 {
     $requestArray = $this->request->getRequestArray();
     $request = APIRequest::getRequestArrayFromString($requestArray);
     if (false === $this->config->enable_sort) {
         $request['filter_sort_column'] = '';
         $request['filter_sort_order'] = '';
     }
     if (!array_key_exists('format_metrics', $request) || $request['format_metrics'] === 'bc') {
         $request['format_metrics'] = '1';
     }
     if (!$this->requestConfig->disable_queued_filters && array_key_exists('disable_queued_filters', $request)) {
         unset($request['disable_queued_filters']);
     }
     return $request;
 }
 public static function Init(array $options)
 {
     self::$_options = $options;
 }
示例#9
0
if (!empty($settings['handler'])) {
    require sprintf("%s/src/server/php/handlers/%s/handler.php", ROOTDIR, $settings['handler']);
}
if (!empty($settings['extensions'])) {
    foreach ($settings['extensions'] as $l) {
        if (preg_match("/\\.php\$/", $l) === false) {
            require sprintf("%s/%s", ROOTDIR, preg_replace("/\\/\$/", "", $l));
        }
    }
}
date_default_timezone_set(TIMEZONE);
register_shutdown_function(array('APIResponse', 'ErrorHandler'));
session_start();
APIUser::restore();
if (defined("NOSERVER") && NOSERVER === true) {
    return;
}
if ($response = APIRequest::call()) {
    $response->output();
    return true;
} else {
    if (php_sapi_name() === "cli-server") {
        return false;
    }
    header("HTTP/1.0 404 Not Found");
    print "404 Not Found";
    if (!empty($_SERVER["REQUEST_URI"])) {
        print " - {$_SERVER["REQUEST_URI"]}";
    }
}
return false;
 /**
  * @param array $tParams Get request parameters as array
  * @return array
  */
 public function PullContents($tParams)
 {
     return json_decode(parent::PullContents($tParams));
 }
示例#11
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();
    }
}
 /**
  * Return registrar billing details
  * 
  * @return str json response
  */
 public function billingRecords($cltrid = false)
 {
     $json = APIRequest::GET(sprintf('/billing/%s', STRegistry::Session()->getLogin()), $cltrid ?: APIRequest::defaultClientTransactionID(), STRegistry::Session()->getAuthToken());
     return $json;
 }
示例#13
0
 /**
  * Creates a location and returns the new location as returned from the
  * API.
  *
  * @param Google\MyBusiness\Location $location
  * @param Google\MyBusiness\Account $account = null
  * @param boolean $dryRun = false
  */
 public function createLocation(Location $location, Account $account = null, $dryRun = false)
 {
     $ownerAccountID = $location->getOwnerAccountID();
     if (strlen($ownerAccountID)) {
         $account = new Account();
         $account->setID($ownerAccountID);
     } elseif ($account) {
         self::_validateID($account);
     } else {
         $account = $this->_getCachedAccount();
     }
     if ($location->getID() !== null) {
         throw new InvalidArgumentException('A new location may not already contain an ID.');
     }
     /* Even if the creation of new locations is disabled, we'll still allow
        dry runs. */
     if (!GOOGLE_MYBUSINESS_API_ALLOW_NEW_LOCATIONS && !$dryRun) {
         throw new RuntimeException('Cannot create new locations unless the ' . 'GOOGLE_MYBUSINESS_API_ALLOW_NEW_LOCATIONS setting is ' . 'defined as true.');
     }
     $requestBody = array('location' => $location->toREST(), 'languageCode' => $location->getLanguageCode(), 'validateOnly' => $dryRun, 'requestId' => $location->getHash());
     $request = new APIRequest($account->getName() . '/locations');
     $request->setPayload(json_encode($requestBody));
     $this->_parseCallback = '_parseLocationResponse';
     return $this->_makeRequest($request);
 }