public function putStatement(StatementId $id, Statement $statement)
 {
     if (null !== $statement->getId() && !$id->equals($statement->getId())) {
         throw new ConflictException(sprintf('Id parameter ("%s") and statement id ("%s") do not match.', $id->getValue(), $statement->getId()->getValue()));
     }
     try {
         $existingStatement = $this->repository->findStatementById($id->getValue());
     } catch (NotFoundException $e) {
         $this->repository->storeStatement($statement, true);
     }
     return new Response('', 204);
 }
 /**
  * Loads a statement result.
  *
  * @param IRL $urlPath An optional URL path refering to more results
  *
  * @return StatementResult
  */
 public static function getStatementResult(IRL $urlPath = null)
 {
     $statement1 = StatementFixtures::getMinimalStatement();
     $verb = new Verb(IRI::fromString('http://adlnet.gov/expapi/verbs/deleted'), LanguageMap::create(array('en-US' => 'deleted')));
     $statement2 = new Statement(StatementId::fromString('12345678-1234-5678-8234-567812345679'), new Agent(InverseFunctionalIdentifier::withMbox(IRI::fromString('mailto:bob@example.com'))), $verb, $statement1->getObject());
     $statementResult = new StatementResult(array($statement1, $statement2), $urlPath);
     return $statementResult;
 }
Exemple #3
0
 function it_is_equal_to_statement_ids_with_equal_value()
 {
     $value = '39e24cc4-69af-4b01-a824-1fdc6ea8a3af';
     $uuid = Uuid::fromString($value);
     $this->beConstructedThrough('fromUuid', array($uuid));
     $this->equals(StatementId::fromString($value))->shouldReturn(true);
     $this->equals(StatementId::fromUuid(Uuid::fromString($value)))->shouldReturn(true);
     $this->equals(StatementId::fromUuid($uuid))->shouldReturn(true);
 }
Exemple #4
0
 public function it_returns_a_new_instance_with_object()
 {
     $statementReference = new StatementReference(StatementId::fromString('12345678-1234-5678-8234-567812345678'));
     $subStatement = $this->withObject($statementReference);
     $subStatement->shouldNotBe($this);
     $subStatement->shouldBeAnInstanceOf('\\Xabbuh\\XApi\\Model\\SubStatement');
     $subStatement->getObject()->shouldReturn($statementReference);
 }
 public function getModel()
 {
     if (self::TYPE_AGENT === $this->type || self::TYPE_GROUP === $this->type) {
         return $this->getActorModel();
     }
     if (self::TYPE_STATEMENT_REFERENCE === $this->type) {
         return new StatementReference(StatementId::fromString($this->referencedStatementId));
     }
     if (self::TYPE_SUB_STATEMENT === $this->type) {
         return $this->getSubStatementModel();
     }
     return $this->getActivityModel();
 }
 public function getModel()
 {
     $result = null;
     $authority = null;
     $created = null;
     $stored = null;
     $context = null;
     $attachments = null;
     if (null !== $this->result) {
         $result = $this->result->getModel();
     }
     if (null !== $this->authority) {
         $authority = $this->authority->getModel();
     }
     if (null !== $this->created) {
         $created = new \DateTime('@' . $this->created);
     }
     if (null !== $this->stored) {
         $stored = new \DateTime('@' . $this->stored);
     }
     if (null !== $this->context) {
         $context = $this->context->getModel();
     }
     if ($this->hasAttachments) {
         $attachments = array();
         foreach ($this->attachments as $attachment) {
             $attachments[] = $attachment->getModel();
         }
     }
     return new StatementModel(StatementId::fromString($this->id), $this->actor->getModel(), $this->verb->getModel(), $this->object->getModel(), $result, $authority, $created, $stored, $context, $attachments);
 }
Exemple #7
0
 function it_is_not_equal_to_other_context_if_statement_references_are_not_equal()
 {
     $context = $this->withStatement(new StatementReference(StatementId::fromString('16fd2706-8baf-433b-82eb-8c7fada847da')));
     $otherContext = new Context();
     $otherContext = $otherContext->withStatement(new StatementReference(StatementId::fromString('39e24cc4-69af-4b01-a824-1fdc6ea8a3af')));
     $context->equals($otherContext)->shouldReturn(false);
 }
 private function configureAllProperties()
 {
     $id = StatementId::fromString('39e24cc4-69af-4b01-a824-1fdc6ea8a3af');
     $actor = new Agent(InverseFunctionalIdentifier::withMbox(IRI::fromString('mailto:conformancetest@tincanapi.com')));
     $verb = new Verb(IRI::fromString('http://tincanapi.com/conformancetest/verbid'));
     $object = new Activity(IRI::fromString('http://tincanapi.com/conformancetest/activityid'));
     $result = new Result();
     $context = new Context();
     $created = new \DateTime('2014-07-23T12:34:02-05:00');
     $stored = new \DateTime('2014-07-24T12:34:02-05:00');
     $authority = new Agent(InverseFunctionalIdentifier::withOpenId('http://openid.tincanapi.com'));
     $this->withId($id);
     $this->withActor($actor);
     $this->withVerb($verb);
     $this->withObject($object);
     $this->withResult($result);
     $this->withContext($context);
     $this->withCreated($created);
     $this->withStored($stored);
     $this->withAuthority($authority);
 }
 public function testFindStatementById()
 {
     $statementId = StatementId::fromUuid(Uuid::uuid4());
     $this->mappedStatementRepository->expects($this->once())->method('findStatement')->with(array('id' => $statementId->getValue()))->will($this->returnValue(MappedStatement::fromModel(StatementFixtures::getMinimalStatement())));
     $this->statementRepository->findStatementById($statementId);
 }
 public function getObjectsToValidate()
 {
     $withStatementId = new StatementReference(StatementId::fromUuid(Uuid::uuid4()));
     return array(array($withStatementId, 0));
 }
 public static function getAllPropertiesStatement($id = self::DEFAULT_STATEMENT_ID)
 {
     if (null === $id) {
         $id = UuidFixtures::getUniqueUuid();
     }
     return new Statement(StatementId::fromString($id), ActorFixtures::getTypicalAgent(), VerbFixtures::getTypicalVerb(), ActivityFixtures::getTypicalActivity(), ResultFixtures::getAllPropertiesResult(), ActorFixtures::getAccountAgent(), new \DateTime('2013-05-18T05:32:34+00:00'), new \DateTime('2014-07-23T12:34:02-05:00'), ContextFixtures::getAllPropertiesContext(), array(AttachmentFixtures::getTextAttachment()));
 }
 public function getModel()
 {
     $context = new ContextModel();
     $context = $context->withRegistration($this->registration);
     $context = $context->withRevision($this->revision);
     $context = $context->withPlatform($this->platform);
     $context = $context->withLanguage($this->language);
     if (null !== $this->instructor) {
         $context = $context->withInstructor($this->instructor->getModel());
     }
     if (null !== $this->team) {
         $context = $context->withTeam($this->team->getModel());
     }
     if ($this->hasContextActivities) {
         $contextActivities = new ContextActivities();
         if (null !== $this->parentActivities) {
             foreach ($this->parentActivities as $contextParentActivity) {
                 $contextActivities = $contextActivities->withAddedParentActivity($contextParentActivity->getModel());
             }
         }
         if (null !== $this->groupingActivities) {
             foreach ($this->groupingActivities as $contextGroupingActivity) {
                 $contextActivities = $contextActivities->withAddedGroupingActivity($contextGroupingActivity->getModel());
             }
         }
         if (null !== $this->categoryActivities) {
             foreach ($this->categoryActivities as $contextCategoryActivity) {
                 $contextActivities = $contextActivities->withAddedCategoryActivity($contextCategoryActivity->getModel());
             }
         }
         if (null !== $this->otherActivities) {
             foreach ($this->otherActivities as $contextOtherActivity) {
                 $contextActivities = $contextActivities->withAddedOtherActivity($contextOtherActivity->getModel());
             }
         }
         $context = $context->withContextActivities($contextActivities);
     }
     if (null !== $this->statement) {
         $context = $context->withStatement(new StatementReference(StatementId::fromString($this->statement)));
     }
     if (null !== $this->extensions) {
         $context = $context->withExtensions($this->extensions->getModel());
     }
     return $context;
 }
 public static function getAllPropertiesStatementReference()
 {
     return new StatementReference(StatementId::fromString('16fd2706-8baf-433b-82eb-8c7fada847da'));
 }
 /**
  * @expectedException \Xabbuh\XApi\Common\Exception\NotFoundException
  */
 public function testGetVoidedStatementWithNotExistingStatement()
 {
     $statementId = '12345678-1234-5678-1234-567812345678';
     $this->validateRetrieveApiCall('get', 'statements', array('voidedStatementId' => $statementId, 'attachments' => 'true'), 404, 'Statement', 'There is no statement associated with this id');
     $this->client->getVoidedStatement(StatementId::fromString($statementId));
 }
 function it_triggers_a_conflict_if_id_parameter_and_statement_id_do_not_match()
 {
     $statement = StatementFixtures::getTypicalStatement();
     $statementId = StatementId::fromUuid(Uuid::uuid4());
     $this->shouldThrow('Xabbuh\\XApi\\Common\\Exception\\ConflictException')->during('putStatement', array($statementId, $statement));
 }
 /**
  * @param Statement|Statement[] $statements
  * @param string                $method
  * @param string[]              $parameters
  * @param int                   $validStatusCode
  *
  * @return Statement|Statement[] The created statement(s)
  */
 private function doStoreStatements($statements, $method = 'post', $parameters = array(), $validStatusCode = 200)
 {
     $attachments = array();
     if (is_array($statements)) {
         foreach ($statements as $statement) {
             if (null !== $statement->getAttachments()) {
                 foreach ($statement->getAttachments() as $attachment) {
                     if ($attachment->getContent()) {
                         $attachments[] = $attachment;
                     }
                 }
             }
         }
         $serializedStatements = $this->statementSerializer->serializeStatements($statements);
     } else {
         if (null !== $statements->getAttachments()) {
             foreach ($statements->getAttachments() as $attachment) {
                 if ($attachment->getContent()) {
                     $attachments[] = $attachment;
                 }
             }
         }
         $serializedStatements = $this->statementSerializer->serializeStatement($statements);
     }
     $headers = array();
     if (!empty($attachments)) {
         $builder = new MultipartStatementBody($serializedStatements, $attachments);
         $headers = array('Content-Type' => 'multipart/mixed; boundary=' . $builder->getBoundary());
         $body = $builder->build();
     } else {
         $body = $serializedStatements;
     }
     $request = $this->requestHandler->createRequest($method, 'statements', $parameters, $body, $headers);
     $response = $this->requestHandler->executeRequest($request, array($validStatusCode));
     $statementIds = json_decode((string) $response->getBody());
     if (is_array($statements)) {
         /** @var Statement[] $statements */
         $createdStatements = array();
         foreach ($statements as $index => $statement) {
             $createdStatements[] = $statement->withId(StatementId::fromString($statementIds[$index]));
         }
         return $createdStatements;
     } else {
         /** @var Statement $statements */
         if (200 === $validStatusCode) {
             return $statements->withId(StatementId::fromString($statementIds[0]));
         } else {
             return $statements;
         }
     }
 }
 function it_is_equal_to_another_reference_with_the_same_statement_id()
 {
     $this->beConstructedWith(StatementId::fromString('16fd2706-8baf-433b-82eb-8c7fada847da'));
     $statementReference = new StatementReference(StatementId::fromString('16fd2706-8baf-433b-82eb-8c7fada847da'));
     $this->equals($statementReference)->shouldReturn(true);
 }
Exemple #18
0
 function it_is_not_equal_with_other_statement_if_ids_differ()
 {
     $statement = $this->withId(StatementId::fromString('12345678-1234-5678-8234-567812345678'));
     $this->equals($statement)->shouldReturn(false);
 }
 /**
  * {@inheritdoc}
  */
 public final function storeStatement(Statement $statement, $flush = true)
 {
     if (null === $statement->getId()) {
         $statement = $statement->withId(StatementId::fromUuid(Uuid::uuid4()));
     }
     $mappedStatement = MappedStatement::fromModel($statement);
     $mappedStatement->stored = time();
     $this->repository->storeStatement($mappedStatement, $flush);
     return $statement->getId();
 }
 /**
  * @expectedException \Xabbuh\XApi\Common\Exception\NotFoundException
  */
 public function testFetchingNonExistingVoidStatementThrowsException()
 {
     $this->statementRepository->findVoidedStatementById(StatementId::fromString('12345678-1234-5678-8234-567812345678'));
 }