/** * @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::ToString */ public function testToString() { $this->assertEquals($this->stringDate1, DateTimeUtils::ToString($this->dfpDate1)); $this->assertEquals($this->stringDate2, DateTimeUtils::ToString($this->dfpDate2)); $this->assertEquals($this->stringDate3, DateTimeUtils::ToString($this->dfpDate3)); }
require_once 'Google/Api/Ads/Dfp/Util/v201511/StatementBuilder.php'; require_once dirname(__FILE__) . '/../../../Common/ExampleUtils.php'; try { // Get DfpUser from credentials in "../auth.ini" // relative to the DfpUser.php file's directory. $user = new DfpUser(); // Log SOAP XML request and response. $user->LogDefaults(); // Get the ReconciliationReportService. $reconciliationReportService = $user->GetService('ReconciliationReportService', 'v201511'); // Get the NetworkService. $networkService = $user->GetService('NetworkService', 'v201511'); $network = $networkService->getCurrentNetwork(); // Create a statement to select the last month's reconciliation report. $statementBuilder = new StatementBuilder(); $statementBuilder->Where('startDate = :startDate')->OrderBy('id ASC')->Limit(1)->WithBindVariableValue('startDate', DateTimeUtils::ToString(DateTimeUtils::ToDfpDateTime(new DateTime('first day of last month', new DateTimeZone($network->timeZone)))->date)); // Default for total result set size. $totalResultSetSize = 0; do { // Get reconciliation reports by statement. $page = $reconciliationReportService->getReconciliationReportsByStatement($statementBuilder->ToStatement()); // Display results. if (isset($page->results)) { $totalResultSetSize = $page->totalResultSetSize; $i = $page->startIndex; foreach ($page->results as $reconciliationReport) { printf("%d) Reconciliation report with ID %d for month %s/%s was found.\n", $i++, $reconciliationReport->id, $reconciliationReport->startDate->month, $reconciliationReport->startDate->year); } } $statementBuilder->IncreaseOffsetBy(StatementBuilder::SUGGESTED_PAGE_LIMIT); } while ($statementBuilder->GetOffset() < $totalResultSetSize);