示例#1
0
 public function setExpiresIn($expiresIn)
 {
     $until = \API\Util\Date::dateFromSeconds($expiresIn);
     $until = \API\Util\Date::dateStringToMongoDate($until);
     $this->setExpiresAt($until);
     return $this;
 }
示例#2
0
 /**
  * Fetches activity profiles according to the given parameters.
  *
  * @param array $request The incoming HTTP request
  *
  * @return array An array of activityProfile objects.
  */
 public function activityProfileGet($request)
 {
     $params = new Set($request->get());
     $collection = $this->getDocumentManager()->getCollection('activityProfiles');
     $cursor = $collection->find();
     // Single activity state
     if ($params->has('profileId')) {
         $cursor->where('profileId', $params->get('profileId'));
         $cursor->where('activityId', $params->get('activityId'));
         if ($cursor->count() === 0) {
             throw new Exception('Activity state does not exist.', Resource::STATUS_NOT_FOUND);
         }
         $this->cursor = $cursor;
         $this->single = true;
         return $this;
     }
     $cursor->where('activityId', $params->get('activityId'));
     if ($params->has('since')) {
         $since = Util\Date::dateStringToMongoDate($params->get('since'));
         $cursor->whereGreaterOrEqual('mongoTimestamp', $since);
     }
     $this->cursor = $cursor;
     return $this;
 }
示例#3
0
 /**
  * Fetches statements according to the given parameters.
  *
  * @param array $request The HTTP request object.
  *
  * @return array An array of statement objects.
  */
 public function statementGet($request)
 {
     $params = new Set($request->get());
     $collection = $this->getDocumentManager()->getCollection('statements');
     $cursor = $collection->find();
     // Single statement
     if ($params->has('statementId')) {
         $cursor->where('statement.id', $params->get('statementId'));
         $cursor->where('voided', false);
         if ($cursor->count() === 0) {
             throw new Exception('Statement does not exist.', Resource::STATUS_NOT_FOUND);
         }
         $this->cursor = $cursor;
         $this->single = true;
         return $this;
     }
     if ($params->has('voidedStatementId')) {
         $cursor->where('statement.id', $params->get('voidedStatementId'));
         $cursor->where('voided', true);
         if ($cursor->count() === 0) {
             throw new Exception('Statement does not exist.', Resource::STATUS_NOT_FOUND);
         }
         $this->cursor = $cursor;
         $this->single = true;
         return $this;
     }
     $cursor->where('voided', false);
     // Multiple statements
     if ($params->has('agent')) {
         $agent = $params->get('agent');
         $agent = json_decode($agent, true);
         //Fetch the identifier - otherwise we'd have to order the JSON
         if (isset($agent['mbox'])) {
             $uniqueIdentifier = 'mbox';
         } elseif (isset($agent['mbox_sha1sum'])) {
             $uniqueIdentifier = 'mbox_sha1sum';
         } elseif (isset($agent['openid'])) {
             $uniqueIdentifier = 'openid';
         } elseif (isset($agent['account'])) {
             $uniqueIdentifier = 'account';
         }
         if ($params->has('related_agents') && $params->get('related_agents') === 'true') {
             if ($uniqueIdentifier === 'account') {
                 $cursor->whereOr($collection->expression()->whereOr($collection->expression()->whereAnd($collection->expression()->where('statement.actor.' . $uniqueIdentifier . '.homePage', $agent[$uniqueIdentifier]['homePage']), $collection->expression()->where('statement.actor.' . $uniqueIdentifier . '.name', $agent[$uniqueIdentifier]['name'])), $collection->expression()->whereAnd($collection->expression()->where('statement.object.' . $uniqueIdentifier . '.homePage', $agent[$uniqueIdentifier]['homePage']), $collection->expression()->where('statement.object.' . $uniqueIdentifier . '.name', $agent[$uniqueIdentifier]['name'])), $collection->expression()->whereAnd($collection->expression()->where('statement.authority.' . $uniqueIdentifier . '.homePage', $agent[$uniqueIdentifier]['homePage']), $collection->expression()->where('statement.authority.' . $uniqueIdentifier . '.name', $agent[$uniqueIdentifier]['name'])), $collection->expression()->whereAnd($collection->expression()->where('statement.context.team.' . $uniqueIdentifier . '.homePage', $agent[$uniqueIdentifier]['homePage']), $collection->expression()->where('statement.context.team.' . $uniqueIdentifier . '.name', $agent[$uniqueIdentifier]['name'])), $collection->expression()->whereAnd($collection->expression()->where('statement.context.instructor.' . $uniqueIdentifier . '.homePage', $agent[$uniqueIdentifier]['homePage']), $collection->expression()->where('statement.context.instructor.' . $uniqueIdentifier . '.name', $agent[$uniqueIdentifier]['name'])), $collection->expression()->whereAnd($collection->expression()->where('statement.object.objectType', 'SubStatement'), $collection->expression()->where('statement.object.object.' . $uniqueIdentifier . '.homePage', $agent[$uniqueIdentifier]['homePage']), $collection->expression()->where('statement.object.object.' . $uniqueIdentifier . '.name', $agent[$uniqueIdentifier]['name']))), $collection->expression()->whereOr($collection->expression()->whereAnd($collection->expression()->where('references.actor.' . $uniqueIdentifier . '.homePage', $agent[$uniqueIdentifier]['homePage']), $collection->expression()->where('references.actor.' . $uniqueIdentifier . '.name', $agent[$uniqueIdentifier]['name'])), $collection->expression()->whereAnd($collection->expression()->where('references.object.' . $uniqueIdentifier . '.homePage', $agent[$uniqueIdentifier]['homePage']), $collection->expression()->where('references.object.' . $uniqueIdentifier . '.name', $agent[$uniqueIdentifier]['name'])), $collection->expression()->whereAnd($collection->expression()->where('references.authority.' . $uniqueIdentifier . '.homePage', $agent[$uniqueIdentifier]['homePage']), $collection->expression()->where('references.authority.' . $uniqueIdentifier . '.name', $agent[$uniqueIdentifier]['name'])), $collection->expression()->whereAnd($collection->expression()->where('references.context.team.' . $uniqueIdentifier . '.homePage', $agent[$uniqueIdentifier]['homePage']), $collection->expression()->where('references.context.team.' . $uniqueIdentifier . '.name', $agent[$uniqueIdentifier]['name'])), $collection->expression()->whereAnd($collection->expression()->where('references.context.instructor.' . $uniqueIdentifier . '.homePage', $agent[$uniqueIdentifier]['homePage']), $collection->expression()->where('references.context.instructor.' . $uniqueIdentifier . '.name', $agent[$uniqueIdentifier]['name'])), $collection->expression()->whereAnd($collection->expression()->where('references.object.objectType', 'SubStatement'), $collection->expression()->where('references.object.object.' . $uniqueIdentifier . '.homePage', $agent[$uniqueIdentifier]['homePage']), $collection->expression()->where('references.object.object.' . $uniqueIdentifier . '.name', $agent[$uniqueIdentifier]['name']))));
             } else {
                 $cursor->whereOr($collection->expression()->whereOr($collection->expression()->where('statement.actor.' . $uniqueIdentifier, $agent[$uniqueIdentifier]), $collection->expression()->where('statement.object.' . $uniqueIdentifier, $agent[$uniqueIdentifier]), $collection->expression()->where('statement.authority.' . $uniqueIdentifier, $agent[$uniqueIdentifier]), $collection->expression()->where('statement.context.team.' . $uniqueIdentifier, $agent[$uniqueIdentifier]), $collection->expression()->where('statement.context.instructor.' . $uniqueIdentifier, $agent[$uniqueIdentifier]), $collection->expression()->whereAnd($collection->expression()->where('statement.object.objectType', 'SubStatement'), $collection->expression()->where('statement.object.object.' . $uniqueIdentifier, $agent[$uniqueIdentifier]))), $collection->expression()->whereOr($collection->expression()->where('references.actor.' . $uniqueIdentifier, $agent[$uniqueIdentifier]), $collection->expression()->where('references.object.' . $uniqueIdentifier, $agent[$uniqueIdentifier]), $collection->expression()->where('references.authority.' . $uniqueIdentifier, $agent[$uniqueIdentifier]), $collection->expression()->where('references.context.team.' . $uniqueIdentifier, $agent[$uniqueIdentifier]), $collection->expression()->where('references.context.instructor.' . $uniqueIdentifier, $agent[$uniqueIdentifier]), $collection->expression()->whereAnd($collection->expression()->where('references.object.objectType', 'SubStatement'), $collection->expression()->where('references.object.object.' . $uniqueIdentifier, $agent[$uniqueIdentifier]))));
             }
         } else {
             if ($uniqueIdentifier === 'account') {
                 $cursor->whereOr($collection->expression()->whereOr($collection->expression()->whereAnd($collection->expression()->where('statement.actor.' . $uniqueIdentifier . '.homePage', $agent[$uniqueIdentifier]['homePage']), $collection->expression()->where('statement.actor.' . $uniqueIdentifier . '.name', $agent[$uniqueIdentifier]['name'])), $collection->expression()->whereAnd($collection->expression()->where('statement.object.' . $uniqueIdentifier . '.homePage', $agent[$uniqueIdentifier]['homePage']), $collection->expression()->where('statement.object.' . $uniqueIdentifier . '.name', $agent[$uniqueIdentifier]['name']))), $collection->expression()->whereOr($collection->expression()->whereAnd($collection->expression()->where('references.actor.' . $uniqueIdentifier . '.homePage', $agent[$uniqueIdentifier]['homePage']), $collection->expression()->where('references.actor.' . $uniqueIdentifier . '.name', $agent[$uniqueIdentifier]['name'])), $collection->expression()->whereAnd($collection->expression()->where('references.object.' . $uniqueIdentifier . '.homePage', $agent[$uniqueIdentifier]['homePage']), $collection->expression()->where('references.object.' . $uniqueIdentifier . '.name', $agent[$uniqueIdentifier]['name']))));
             } else {
                 $cursor->whereOr($collection->expression()->whereOr($collection->expression()->where('statement.actor.' . $uniqueIdentifier, $agent[$uniqueIdentifier]), $collection->expression()->where('statement.object.' . $uniqueIdentifier, $agent[$uniqueIdentifier])), $collection->expression()->whereOr($collection->expression()->where('references.actor.' . $uniqueIdentifier, $agent[$uniqueIdentifier]), $collection->expression()->where('references.object.' . $uniqueIdentifier, $agent[$uniqueIdentifier])));
             }
         }
     }
     if ($params->has('verb')) {
         $cursor->whereOr($collection->expression()->where('statement.verb.id', $params->get('verb')), $collection->expression()->where('references.verb.id', $params->get('verb')));
     }
     if ($params->has('activity')) {
         // Handle related
         if ($params->has('related_activities') && $params->get('related_activities') === 'true') {
             $cursor->whereOr($collection->expression()->whereOr($collection->expression()->where('statement.object.id', $params->get('activity')), $collection->expression()->where('statement.context.contextActivities.parent.id', $params->get('activity')), $collection->expression()->where('statement.context.contextActivities.category.id', $params->get('activity')), $collection->expression()->where('statement.context.contextActivities.grouping.id', $params->get('activity')), $collection->expression()->where('statement.context.contextActivities.other.id', $params->get('activity')), $collection->expression()->where('statement.context.contextActivities.parent.id', $params->get('activity')), $collection->expression()->where('statement.context.contextActivities.parent.id', $params->get('activity')), $collection->expression()->whereAnd($collection->expression()->where('statement.object.objectType', 'SubStatement'), $collection->expression()->where('statement.object.object', $params->get('activity')))), $collection->expression()->whereOr($collection->expression()->where('references.object.id', $params->get('activity')), $collection->expression()->where('references.context.contextActivities.parent.id', $params->get('activity')), $collection->expression()->where('references.context.contextActivities.category.id', $params->get('activity')), $collection->expression()->where('references.context.contextActivities.grouping.id', $params->get('activity')), $collection->expression()->where('references.context.contextActivities.other.id', $params->get('activity')), $collection->expression()->where('references.context.contextActivities.parent.id', $params->get('activity')), $collection->expression()->where('references.context.contextActivities.parent.id', $params->get('activity')), $collection->expression()->whereAnd($collection->expression()->where('references.object.objectType', 'SubStatement'), $collection->expression()->where('references.object.object', $params->get('activity')))));
         } else {
             $cursor->whereOr($collection->expression()->where('statement.object.id', $params->get('activity')), $collection->expression()->where('references.object.id', $params->get('activity')));
         }
     }
     if ($params->has('registration')) {
         $cursor->whereOr($collection->expression()->where('statement.context.registration', $params->get('registration')), $collection->expression()->where('references.context.registration', $params->get('registration')));
     }
     // Date based filters
     if ($params->has('since')) {
         $since = Util\Date::dateStringToMongoDate($params->get('since'));
         $cursor->whereGreaterOrEqual('mongo_timestamp', $since);
     }
     if ($params->has('until')) {
         $until = Util\Date::dateStringToMongoDate($params->get('until'));
         $cursor->whereLessOrEqual('mongo_timestamp', $until);
     }
     // Count before paginating
     $this->count = $cursor->count();
     // Handle pagination
     if ($params->has('since_id')) {
         $id = new \MongoId($params->get('since_id'));
         $cursor->whereGreaterOrEqual('_id', $id);
     }
     if ($params->has('until_id')) {
         $id = new \MongoId($params->get('until_id'));
         $cursor->whereLessOrEqual('_id', $id);
     }
     $this->format = $this->getSlim()->config('xAPI')['default_statement_get_format'];
     if ($params->has('format')) {
         $this->format = $params->get('format');
     }
     if ($params->has('ascending') && $params->get('ascending') === 'true') {
         $cursor->sort(['_id' => 1]);
         $this->descending = false;
     } else {
         $cursor->sort(['_id' => -1]);
         $this->descending = true;
     }
     if ($params->has('limit') && $params->get('limit') < $this->getSlim()->config('xAPI')['statement_get_limit'] && $params->get('limit') > 0) {
         $limit = $params->get('limit');
     } else {
         $limit = $this->getSlim()->config('xAPI')['statement_get_limit'];
     }
     // Hackish solution...think of a different way for handling this
     $limit = $limit + 1;
     $this->limit = $limit;
     $cursor->limit($limit);
     $this->cursor = $cursor;
     return $this;
 }
示例#4
0
 /**
  * Fetches agent profiles according to the given parameters.
  *
  * @param array $request The incoming HTTP request
  *
  * @return array An array of agentProfile objects.
  */
 public function agentProfileGet($request)
 {
     $params = new Set($request->get());
     $collection = $this->getDocumentManager()->getCollection('agentProfiles');
     $cursor = $collection->find();
     // Single activity profile
     if ($params->has('profileId')) {
         $cursor->where('profileId', $params->get('profileId'));
         $agent = $params->get('agent');
         $agent = json_decode($agent, true);
         //Fetch the identifier - otherwise we'd have to order the JSON
         if (isset($agent['mbox'])) {
             $uniqueIdentifier = 'mbox';
         } elseif (isset($agent['mbox_sha1sum'])) {
             $uniqueIdentifier = 'mbox_sha1sum';
         } elseif (isset($agent['openid'])) {
             $uniqueIdentifier = 'openid';
         } elseif (isset($agent['account'])) {
             $uniqueIdentifier = 'account';
         }
         $cursor->where('agent.' . $uniqueIdentifier, $agent[$uniqueIdentifier]);
         if ($cursor->count() === 0) {
             throw new Exception('Agent profile does not exist.', Resource::STATUS_NOT_FOUND);
         }
         $this->cursor = $cursor;
         $this->single = true;
         return $this;
     }
     $agent = $params->get('agent');
     $agent = json_decode($agent);
     $cursor->where('agent', $agent);
     if ($params->has('since')) {
         $since = Util\Date::dateStringToMongoDate($params->get('since'));
         $cursor->whereGreaterOrEqual('mongoTimestamp', $since);
     }
     $this->cursor = $cursor;
     return $this;
 }