/** * @covers Pql::CreateValue */ public function testCreateValue() { $this->assertEquals('hello', Pql::CreateValue(new TextValue('hello'))->value); $this->assertEquals('value1', Pql::CreateValue('value1')->value); $this->assertEquals(false, Pql::CreateValue(false)->value); $this->assertEquals('1', Pql::CreateValue(1)->value); $this->assertEquals('1.02', Pql::CreateValue(1.02)->value); $this->assertEquals('2012-12-02T12:45:00+08:00', DateTimeUtils::ToStringWithTimeZone(Pql::CreateValue($this->dateTime1)->value)); $this->assertEquals('2012-12-02', DateTimeUtils::ToString(Pql::CreateValue($this->dateTime1->date)->value)); }
/** * @covers Pql::CreateValue */ public function testCreateValue() { $this->assertEquals('hello', Pql::CreateValue(new TextValue('hello'))->value); $this->assertEquals('value1', Pql::CreateValue('value1')->value); $this->assertEquals(false, Pql::CreateValue(false)->value); $this->assertEquals('1', Pql::CreateValue(1)->value); $this->assertEquals('1.02', Pql::CreateValue(1.02)->value); $this->assertEquals('2012-12-02T12:45:00+08:00', DateTimeUtils::ToStringWithTimeZone(Pql::CreateValue($this->dateTime1)->value)); $this->assertEquals('2012-12-02', DateTimeUtils::ToString(Pql::CreateValue($this->dateTime1->date)->value)); $values = Pql::CreateValue([23, 42, 5, 10, 1])->values; $this->assertEquals(5, count($values)); $this->assertEquals(23, $values[0]->value); $this->assertEquals(42, $values[1]->value); $this->assertEquals(5, $values[2]->value); $this->assertEquals(10, $values[3]->value); $this->assertEquals(1, $values[4]->value); }
/** * Creates a String from the Value. * * @param Value $value the value to convert * @return string the string representation of the value * @throws InvalidArgumentException if value cannot be converted */ public static function ToString(Value $value) { if ($value instanceof BooleanValue) { return $value->value ? 'true' : 'false'; } else { if ($value instanceof NumberValue || $value instanceof TextValue) { return strval($value->value); } else { if ($value instanceof DateTimeValue) { return isset($value->value) ? DateTimeUtils::ToStringWithTimeZone($value->value) : ''; } else { if ($value instanceof DateValue) { return DateTimeUtils::ToString($value->value); } else { throw new InvalidArgumentException(sprintf("Unsupported Value type [%s]", get_class($value))); } } } } }
/** * Creates a String from the Value. * * @param Value $value the value to convert * @return string the string representation of the value * @throws InvalidArgumentException if value cannot be converted */ public static function ToString(Value $value) { if ($value instanceof BooleanValue) { return $value->value ? 'true' : 'false'; } else { if ($value instanceof NumberValue || $value instanceof TextValue) { return strval($value->value); } else { if ($value instanceof DateTimeValue) { return isset($value->value) ? DateTimeUtils::ToStringWithTimeZone($value->value) : ''; } else { if ($value instanceof DateValue) { return DateTimeUtils::ToString($value->value); } else { if ($value instanceof SetValue) { $pqlValues = $value->values; if (!isset($pqlValues)) { return ''; } else { $valuesAsStrings = array(); foreach ($pqlValues as $pqlValue) { $valuesAsStrings[] = self::ToString($pqlValue); } return implode(',', $valuesAsStrings); } } else { throw new InvalidArgumentException(sprintf("Unsupported Value type [%s]", get_class($value))); } } } } } }
/** * @covers DateTimeUtils::ToStringWithTimeZone */ public function testToStringWithTimeZone() { $this->assertEquals($this->stringDateTimeWithTimeZone1, DateTimeUtils::ToStringWithTimeZone($this->dfpDateTime1)); $this->assertEquals($this->stringDateTimeWithTimeZone2, DateTimeUtils::ToStringWithTimeZone($this->dfpDateTime2)); $this->assertEquals($this->stringDateTimeWithTimeZone3, DateTimeUtils::ToStringWithTimeZone($this->dfpDateTime3)); }
// relative to the DfpUser.php file's directory. $user = new DfpUser(); // Log SOAP XML request and response. $user->LogDefaults(); $proposalService = $user->GetService('ProposalService', 'v201608'); // Create a statement to select Marketplace comments. $statementBuilder = new StatementBuilder(); $statementBuilder->Where('proposalId = :proposalId')->WithBindVariableValue('proposalId', $proposalId); // Retrieve a small amount of Marketplace comments at a time, paging through // until all comments have been retrieved. $totalResultSetSize = 0; do { $page = $proposalService->getMarketplaceCommentsByStatement($statementBuilder->ToStatement()); if ($page->results !== null) { // Print out some information for each Marketplace comment. $totalResultSetSize = $page->totalResultSetSize; $i = $page->startIndex; foreach ($page->results as $marketplaceComment) { printf("%d) Marketplace comment with creation time '%s' and comment '%s' " . "was found.\n", $i++, DateTimeUtils::ToStringWithTimeZone($marketplaceComment->creationTime), $marketplaceComment->comment); } } $statementBuilder->IncreaseOffsetBy(StatementBuilder::SUGGESTED_PAGE_LIMIT); } while ($statementBuilder->GetOffset() < $totalResultSetSize); printf("Number of results found: %d\n", $totalResultSetSize); } catch (OAuth2Exception $e) { ExampleUtils::CheckForOAuth2Errors($e); } catch (ValidationException $e) { ExampleUtils::CheckForOAuth2Errors($e); } catch (Exception $e) { printf("%s\n", $e->getMessage()); }