Esempio n. 1
0
 private function getParam($param)
 {
     $param_value = \LockerRequest::getParam($param);
     $value = json_decode($param_value, true);
     if ($value === null && $param_value === null) {
         throw new Exceptions\Exception("Expected `{$param}` to be defined as a URL parameter.");
     } else {
         if ($value === null) {
             throw new Exceptions\Exception("Expected the value of `{$param}` to be valid JSON in the URL parameter.");
         }
     }
     return $value;
 }
 /**
  * Updates (PUTs) Statement with the given id.
  * @param [String => mixed] $options
  * @return Response
  */
 public function update($options)
 {
     $this->createStatements($options, function ($statements) {
         $statement_id = \LockerRequest::getParam(StatementController::STATEMENT_ID);
         // Returns a error if identifier is not present.
         if (!$statement_id) {
             throw new Exceptions\Exception('A statement ID is required to PUT.');
         }
         // Adds the ID to the statement.
         $statements[0]->id = $statement_id;
         return $statements;
     });
     return IlluminateResponse::make('', 204, $this->getCORSHeaders());
 }
Esempio n. 3
0
 protected function validatedParam($type, $param, $default = null)
 {
     $paramValue = \LockerRequest::getParam($param, $default);
     $value = $this->decodeValue($paramValue);
     if (isset($value)) {
         $this->validateValue($param, $value, $type);
     }
     return $value;
 }
 /**
  * Grab site stats
  * @return Response
  **/
 public function getGraphData()
 {
     $startDate = \LockerRequest::getParam('graphStartDate');
     $endDate = \LockerRequest::getParam('graphEndDate');
     $startDate = !$startDate ? null : new \Carbon\Carbon($startDate);
     $endDate = !$endDate ? null : new \Carbon\Carbon($endDate);
     $admin_dashboard = new \app\locker\data\dashboards\AdminDashboard();
     $graph_data = $admin_dashboard->getGraphData($startDate, $endDate);
     return Response::json($graph_data);
 }
 /**
  * Checks params to comply with requirements.
  * https://github.com/adlnet/xAPI-Spec/blob/master/xAPI.md#723-getstatements
  **/
 private function validateIds()
 {
     // Attempts to get IDs from the params.
     $statementId = \LockerRequest::getParam(self::STATEMENT_ID);
     $voidedId = \LockerRequest::getParam(self::VOIDED_ID);
     // Returns an error if both `statementId` and `voidedId` are set.
     if ($statementId && $voidedId) {
         throw new Exceptions\Exception('You can\'t request based on both`' . self::STATEMENT_ID . '` and `' . self::VOIDED_ID . '`');
     } else {
         if ($statementId || $voidedId) {
             $allowedParams = ['content', self::STATEMENT_ID, self::VOIDED_ID, 'attachments', 'format'];
             // Returns an error if a $key is not an allowed param.
             foreach ($this->params as $key => $value) {
                 if (!in_array($key, $allowedParams)) {
                     throw new Exceptions\Exception('When using `' . self::STATEMENT_ID . '` or `' . self::VOIDED_ID . '`, the only other parameters allowed are `attachments` and/or `format`.');
                 }
             }
         }
     }
 }