repo stringlengths 6 63 | path stringlengths 5 140 | func_name stringlengths 3 151 | original_string stringlengths 84 13k | language stringclasses 1 value | code stringlengths 84 13k | code_tokens list | docstring stringlengths 3 47.2k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 91 247 | partition stringclasses 1 value |
|---|---|---|---|---|---|---|---|---|---|---|---|
googleads/googleads-php-lib | src/Google/AdsApi/AdWords/Reporting/ReportDownloadResult.php | ReportDownloadResult.saveToFile | public function saveToFile($filePath)
{
$this->adsUtilityRegistry->addUtility(
AdsUtility::REPORT_DOWNLOADER_FILE
);
$this->reportDownloadResultDelegate->saveToFile($filePath);
} | php | public function saveToFile($filePath)
{
$this->adsUtilityRegistry->addUtility(
AdsUtility::REPORT_DOWNLOADER_FILE
);
$this->reportDownloadResultDelegate->saveToFile($filePath);
} | [
"public",
"function",
"saveToFile",
"(",
"$",
"filePath",
")",
"{",
"$",
"this",
"->",
"adsUtilityRegistry",
"->",
"addUtility",
"(",
"AdsUtility",
"::",
"REPORT_DOWNLOADER_FILE",
")",
";",
"$",
"this",
"->",
"reportDownloadResultDelegate",
"->",
"saveToFile",
"(",
"$",
"filePath",
")",
";",
"}"
] | Writes the contents of the report download response to the specified
file.
@param string $filePath the path to the file to which the contents are
saved
@throws RuntimeException in case the stream of this download result is
read more than once | [
"Writes",
"the",
"contents",
"of",
"the",
"report",
"download",
"response",
"to",
"the",
"specified",
"file",
"."
] | d552b800ad53c400b1a50c7852e7ad184245d2ea | https://github.com/googleads/googleads-php-lib/blob/d552b800ad53c400b1a50c7852e7ad184245d2ea/src/Google/AdsApi/AdWords/Reporting/ReportDownloadResult.php#L98-L104 | train |
googleads/googleads-php-lib | src/Google/AdsApi/AdWords/AdWordsSessionBuilder.php | AdWordsSessionBuilder.fromFile | public function fromFile($path = null)
{
if ($path === null) {
$path = self::DEFAULT_CONFIGURATION_FILENAME;
}
return $this->from($this->configurationLoader->fromFile($path));
} | php | public function fromFile($path = null)
{
if ($path === null) {
$path = self::DEFAULT_CONFIGURATION_FILENAME;
}
return $this->from($this->configurationLoader->fromFile($path));
} | [
"public",
"function",
"fromFile",
"(",
"$",
"path",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"path",
"===",
"null",
")",
"{",
"$",
"path",
"=",
"self",
"::",
"DEFAULT_CONFIGURATION_FILENAME",
";",
"}",
"return",
"$",
"this",
"->",
"from",
"(",
"$",
"this",
"->",
"configurationLoader",
"->",
"fromFile",
"(",
"$",
"path",
")",
")",
";",
"}"
] | Reads configuration settings from the specified filepath. The filepath
is
optional, and if omitted, it will look for the default configuration
filename in the home directory of the user running PHP.
@see AdsBuilder::DEFAULT_CONFIGURATION_FILENAME
@param string $path the filepath
@return AdWordsSessionBuilder this builder populated from the
configuration
@throws InvalidArgumentException if the configuration file could not be
found | [
"Reads",
"configuration",
"settings",
"from",
"the",
"specified",
"filepath",
".",
"The",
"filepath",
"is",
"optional",
"and",
"if",
"omitted",
"it",
"will",
"look",
"for",
"the",
"default",
"configuration",
"filename",
"in",
"the",
"home",
"directory",
"of",
"the",
"user",
"running",
"PHP",
"."
] | d552b800ad53c400b1a50c7852e7ad184245d2ea | https://github.com/googleads/googleads-php-lib/blob/d552b800ad53c400b1a50c7852e7ad184245d2ea/src/Google/AdsApi/AdWords/AdWordsSessionBuilder.php#L104-L111 | train |
googleads/googleads-php-lib | src/Google/AdsApi/AdManager/Util/v201805/ReportDownloader.php | ReportDownloader.waitForReportToFinish | public function waitForReportToFinish()
{
$reportJobStatus = $this->reportService
->getReportJobStatus($this->reportJobId);
while ($reportJobStatus === ReportJobStatus::IN_PROGRESS) {
$this->logger->info(
sprintf(
'Report job ID %d has status %s. Sleeping for %d seconds '
. 'before polling again for report status.',
$this->reportJobId,
$reportJobStatus,
$this->pollTimeSeconds
)
);
sleep($this->pollTimeSeconds);
$reportJobStatus = $this->reportService
->getReportJobStatus($this->reportJobId);
}
return $reportJobStatus === ReportJobStatus::COMPLETED;
} | php | public function waitForReportToFinish()
{
$reportJobStatus = $this->reportService
->getReportJobStatus($this->reportJobId);
while ($reportJobStatus === ReportJobStatus::IN_PROGRESS) {
$this->logger->info(
sprintf(
'Report job ID %d has status %s. Sleeping for %d seconds '
. 'before polling again for report status.',
$this->reportJobId,
$reportJobStatus,
$this->pollTimeSeconds
)
);
sleep($this->pollTimeSeconds);
$reportJobStatus = $this->reportService
->getReportJobStatus($this->reportJobId);
}
return $reportJobStatus === ReportJobStatus::COMPLETED;
} | [
"public",
"function",
"waitForReportToFinish",
"(",
")",
"{",
"$",
"reportJobStatus",
"=",
"$",
"this",
"->",
"reportService",
"->",
"getReportJobStatus",
"(",
"$",
"this",
"->",
"reportJobId",
")",
";",
"while",
"(",
"$",
"reportJobStatus",
"===",
"ReportJobStatus",
"::",
"IN_PROGRESS",
")",
"{",
"$",
"this",
"->",
"logger",
"->",
"info",
"(",
"sprintf",
"(",
"'Report job ID %d has status %s. Sleeping for %d seconds '",
".",
"'before polling again for report status.'",
",",
"$",
"this",
"->",
"reportJobId",
",",
"$",
"reportJobStatus",
",",
"$",
"this",
"->",
"pollTimeSeconds",
")",
")",
";",
"sleep",
"(",
"$",
"this",
"->",
"pollTimeSeconds",
")",
";",
"$",
"reportJobStatus",
"=",
"$",
"this",
"->",
"reportService",
"->",
"getReportJobStatus",
"(",
"$",
"this",
"->",
"reportJobId",
")",
";",
"}",
"return",
"$",
"reportJobStatus",
"===",
"ReportJobStatus",
"::",
"COMPLETED",
";",
"}"
] | Blocks and waits for the report to finish running by polling for the
report's status and sleeping in between polls.
@return bool whether or not the report finished successfully | [
"Blocks",
"and",
"waits",
"for",
"the",
"report",
"to",
"finish",
"running",
"by",
"polling",
"for",
"the",
"report",
"s",
"status",
"and",
"sleeping",
"in",
"between",
"polls",
"."
] | d552b800ad53c400b1a50c7852e7ad184245d2ea | https://github.com/googleads/googleads-php-lib/blob/d552b800ad53c400b1a50c7852e7ad184245d2ea/src/Google/AdsApi/AdManager/Util/v201805/ReportDownloader.php#L104-L124 | train |
googleads/googleads-php-lib | src/Google/AdsApi/AdManager/Util/v201805/ReportDownloader.php | ReportDownloader.downloadReport | public function downloadReport($exportFormat, $filePath = null)
{
$downloadUrl = $this->getDownloadUrl($exportFormat);
$requestOptions = [];
$requestOptions[RequestOptions::HEADERS] = [
'User-Agent' => $this->getFormattedUserAgent()
];
$proxy = $this->reportService->getAdsSession()->getConnectionSettings()
->getProxyUrl();
if (!empty($proxy)) {
$requestOptions[RequestOptions::PROXY] = ['https' => $proxy];
}
if ($filePath !== null) {
$requestOptions[RequestOptions::SINK] = $filePath;
$this->httpClient->request('GET', $downloadUrl, $requestOptions);
} else {
$requestOptions[RequestOptions::STREAM] = true;
$response = $this->httpClient->request(
'GET',
$downloadUrl,
$requestOptions
);
return $response->getBody();
}
} | php | public function downloadReport($exportFormat, $filePath = null)
{
$downloadUrl = $this->getDownloadUrl($exportFormat);
$requestOptions = [];
$requestOptions[RequestOptions::HEADERS] = [
'User-Agent' => $this->getFormattedUserAgent()
];
$proxy = $this->reportService->getAdsSession()->getConnectionSettings()
->getProxyUrl();
if (!empty($proxy)) {
$requestOptions[RequestOptions::PROXY] = ['https' => $proxy];
}
if ($filePath !== null) {
$requestOptions[RequestOptions::SINK] = $filePath;
$this->httpClient->request('GET', $downloadUrl, $requestOptions);
} else {
$requestOptions[RequestOptions::STREAM] = true;
$response = $this->httpClient->request(
'GET',
$downloadUrl,
$requestOptions
);
return $response->getBody();
}
} | [
"public",
"function",
"downloadReport",
"(",
"$",
"exportFormat",
",",
"$",
"filePath",
"=",
"null",
")",
"{",
"$",
"downloadUrl",
"=",
"$",
"this",
"->",
"getDownloadUrl",
"(",
"$",
"exportFormat",
")",
";",
"$",
"requestOptions",
"=",
"[",
"]",
";",
"$",
"requestOptions",
"[",
"RequestOptions",
"::",
"HEADERS",
"]",
"=",
"[",
"'User-Agent'",
"=>",
"$",
"this",
"->",
"getFormattedUserAgent",
"(",
")",
"]",
";",
"$",
"proxy",
"=",
"$",
"this",
"->",
"reportService",
"->",
"getAdsSession",
"(",
")",
"->",
"getConnectionSettings",
"(",
")",
"->",
"getProxyUrl",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"proxy",
")",
")",
"{",
"$",
"requestOptions",
"[",
"RequestOptions",
"::",
"PROXY",
"]",
"=",
"[",
"'https'",
"=>",
"$",
"proxy",
"]",
";",
"}",
"if",
"(",
"$",
"filePath",
"!==",
"null",
")",
"{",
"$",
"requestOptions",
"[",
"RequestOptions",
"::",
"SINK",
"]",
"=",
"$",
"filePath",
";",
"$",
"this",
"->",
"httpClient",
"->",
"request",
"(",
"'GET'",
",",
"$",
"downloadUrl",
",",
"$",
"requestOptions",
")",
";",
"}",
"else",
"{",
"$",
"requestOptions",
"[",
"RequestOptions",
"::",
"STREAM",
"]",
"=",
"true",
";",
"$",
"response",
"=",
"$",
"this",
"->",
"httpClient",
"->",
"request",
"(",
"'GET'",
",",
"$",
"downloadUrl",
",",
"$",
"requestOptions",
")",
";",
"return",
"$",
"response",
"->",
"getBody",
"(",
")",
";",
"}",
"}"
] | Downloads the report with the specified export format.
@param string $exportFormat the export format of the report
@param string $filePath an optional file path to download the report to
@return void|StreamInterface nothing if a file path is specified,
otherwise report contents as a stream
@throws UnexpectedValueException if the report is still in progress or
has failed | [
"Downloads",
"the",
"report",
"with",
"the",
"specified",
"export",
"format",
"."
] | d552b800ad53c400b1a50c7852e7ad184245d2ea | https://github.com/googleads/googleads-php-lib/blob/d552b800ad53c400b1a50c7852e7ad184245d2ea/src/Google/AdsApi/AdManager/Util/v201805/ReportDownloader.php#L136-L162 | train |
googleads/googleads-php-lib | src/Google/AdsApi/AdManager/Util/v201805/ReportDownloader.php | ReportDownloader.getDownloadUrl | private function getDownloadUrl($exportFormat)
{
$reportJobStatus = $this->reportService
->getReportJobStatus($this->reportJobId);
if ($reportJobStatus === ReportJobStatus::IN_PROGRESS) {
throw new UnexpectedValueException(
sprintf(
'Report %d must be completed before downloading. '
. 'Report is still %s.',
$this->reportJobId,
ReportJobStatus::IN_PROGRESS
)
);
} elseif ($reportJobStatus === ReportJobStatus::FAILED) {
throw new UnexpectedValueException(
sprintf(
'Cannot download report %d because it has a status of %s.',
$this->reportJobId,
ReportJobStatus::FAILED
)
);
}
return $this->reportService->getReportDownloadURL(
$this->reportJobId,
$exportFormat
);
} | php | private function getDownloadUrl($exportFormat)
{
$reportJobStatus = $this->reportService
->getReportJobStatus($this->reportJobId);
if ($reportJobStatus === ReportJobStatus::IN_PROGRESS) {
throw new UnexpectedValueException(
sprintf(
'Report %d must be completed before downloading. '
. 'Report is still %s.',
$this->reportJobId,
ReportJobStatus::IN_PROGRESS
)
);
} elseif ($reportJobStatus === ReportJobStatus::FAILED) {
throw new UnexpectedValueException(
sprintf(
'Cannot download report %d because it has a status of %s.',
$this->reportJobId,
ReportJobStatus::FAILED
)
);
}
return $this->reportService->getReportDownloadURL(
$this->reportJobId,
$exportFormat
);
} | [
"private",
"function",
"getDownloadUrl",
"(",
"$",
"exportFormat",
")",
"{",
"$",
"reportJobStatus",
"=",
"$",
"this",
"->",
"reportService",
"->",
"getReportJobStatus",
"(",
"$",
"this",
"->",
"reportJobId",
")",
";",
"if",
"(",
"$",
"reportJobStatus",
"===",
"ReportJobStatus",
"::",
"IN_PROGRESS",
")",
"{",
"throw",
"new",
"UnexpectedValueException",
"(",
"sprintf",
"(",
"'Report %d must be completed before downloading. '",
".",
"'Report is still %s.'",
",",
"$",
"this",
"->",
"reportJobId",
",",
"ReportJobStatus",
"::",
"IN_PROGRESS",
")",
")",
";",
"}",
"elseif",
"(",
"$",
"reportJobStatus",
"===",
"ReportJobStatus",
"::",
"FAILED",
")",
"{",
"throw",
"new",
"UnexpectedValueException",
"(",
"sprintf",
"(",
"'Cannot download report %d because it has a status of %s.'",
",",
"$",
"this",
"->",
"reportJobId",
",",
"ReportJobStatus",
"::",
"FAILED",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"reportService",
"->",
"getReportDownloadURL",
"(",
"$",
"this",
"->",
"reportJobId",
",",
"$",
"exportFormat",
")",
";",
"}"
] | Gets the download URL for the report.
@param string $exportFormat the export format of the report
@return string the download URL for the report
@throws UnexpectedValueException if the report is still in progress or
has failed | [
"Gets",
"the",
"download",
"URL",
"for",
"the",
"report",
"."
] | d552b800ad53c400b1a50c7852e7ad184245d2ea | https://github.com/googleads/googleads-php-lib/blob/d552b800ad53c400b1a50c7852e7ad184245d2ea/src/Google/AdsApi/AdManager/Util/v201805/ReportDownloader.php#L172-L199 | train |
googleads/googleads-php-lib | src/Google/AdsApi/AdWords/Query/ValidationResult.php | ValidationResult.pass | public static function pass()
{
if (is_null(self::$passedResult)) {
self::$passedResult = new self(true);
}
return self::$passedResult;
} | php | public static function pass()
{
if (is_null(self::$passedResult)) {
self::$passedResult = new self(true);
}
return self::$passedResult;
} | [
"public",
"static",
"function",
"pass",
"(",
")",
"{",
"if",
"(",
"is_null",
"(",
"self",
"::",
"$",
"passedResult",
")",
")",
"{",
"self",
"::",
"$",
"passedResult",
"=",
"new",
"self",
"(",
"true",
")",
";",
"}",
"return",
"self",
"::",
"$",
"passedResult",
";",
"}"
] | Creates a validation pass result.
@return ValidationResult the validation pass result | [
"Creates",
"a",
"validation",
"pass",
"result",
"."
] | d552b800ad53c400b1a50c7852e7ad184245d2ea | https://github.com/googleads/googleads-php-lib/blob/d552b800ad53c400b1a50c7852e7ad184245d2ea/src/Google/AdsApi/AdWords/Query/ValidationResult.php#L79-L86 | train |
googleads/googleads-php-lib | src/Google/AdsApi/Common/Util/SoapHeaders.php | SoapHeaders.getSoapHeaderValue | public static function getSoapHeaderValue($xml, $soapHeaderName)
{
$headerValue = '';
if ($xml === null || $xml === '') {
return $headerValue;
}
$xmlReader = new XMLReader();
$xmlReader->xml($xml);
while ($xmlReader->read()) {
if ($xmlReader->nodeType === XMLReader::ELEMENT
&& $xmlReader->localName === $soapHeaderName) {
$xmlReader->read();
$headerValue = $xmlReader->value;
} elseif ($xmlReader->nodeType === XMLReader::END_ELEMENT
&& $xmlReader->localName === self::$SOAP_HEADER_NODE_NAME) {
break;
}
}
$xmlReader->close();
return $headerValue;
} | php | public static function getSoapHeaderValue($xml, $soapHeaderName)
{
$headerValue = '';
if ($xml === null || $xml === '') {
return $headerValue;
}
$xmlReader = new XMLReader();
$xmlReader->xml($xml);
while ($xmlReader->read()) {
if ($xmlReader->nodeType === XMLReader::ELEMENT
&& $xmlReader->localName === $soapHeaderName) {
$xmlReader->read();
$headerValue = $xmlReader->value;
} elseif ($xmlReader->nodeType === XMLReader::END_ELEMENT
&& $xmlReader->localName === self::$SOAP_HEADER_NODE_NAME) {
break;
}
}
$xmlReader->close();
return $headerValue;
} | [
"public",
"static",
"function",
"getSoapHeaderValue",
"(",
"$",
"xml",
",",
"$",
"soapHeaderName",
")",
"{",
"$",
"headerValue",
"=",
"''",
";",
"if",
"(",
"$",
"xml",
"===",
"null",
"||",
"$",
"xml",
"===",
"''",
")",
"{",
"return",
"$",
"headerValue",
";",
"}",
"$",
"xmlReader",
"=",
"new",
"XMLReader",
"(",
")",
";",
"$",
"xmlReader",
"->",
"xml",
"(",
"$",
"xml",
")",
";",
"while",
"(",
"$",
"xmlReader",
"->",
"read",
"(",
")",
")",
"{",
"if",
"(",
"$",
"xmlReader",
"->",
"nodeType",
"===",
"XMLReader",
"::",
"ELEMENT",
"&&",
"$",
"xmlReader",
"->",
"localName",
"===",
"$",
"soapHeaderName",
")",
"{",
"$",
"xmlReader",
"->",
"read",
"(",
")",
";",
"$",
"headerValue",
"=",
"$",
"xmlReader",
"->",
"value",
";",
"}",
"elseif",
"(",
"$",
"xmlReader",
"->",
"nodeType",
"===",
"XMLReader",
"::",
"END_ELEMENT",
"&&",
"$",
"xmlReader",
"->",
"localName",
"===",
"self",
"::",
"$",
"SOAP_HEADER_NODE_NAME",
")",
"{",
"break",
";",
"}",
"}",
"$",
"xmlReader",
"->",
"close",
"(",
")",
";",
"return",
"$",
"headerValue",
";",
"}"
] | Gets the value of the specified SOAP header from the specified SOAP request
or response payload as an XML string.
@param string $xml
@param string $soapHeaderName
@return string the SOAP header value or an empty string if the header isn't
found | [
"Gets",
"the",
"value",
"of",
"the",
"specified",
"SOAP",
"header",
"from",
"the",
"specified",
"SOAP",
"request",
"or",
"response",
"payload",
"as",
"an",
"XML",
"string",
"."
] | d552b800ad53c400b1a50c7852e7ad184245d2ea | https://github.com/googleads/googleads-php-lib/blob/d552b800ad53c400b1a50c7852e7ad184245d2ea/src/Google/AdsApi/Common/Util/SoapHeaders.php#L40-L63 | train |
googleads/googleads-php-lib | src/Google/AdsApi/Common/GuzzleLogMessageFormatter.php | GuzzleLogMessageFormatter.formatDetailed | public function formatDetailed(
RequestInterface $request,
ResponseInterface &$response = null,
Exception &$error = null
) {
$needRewind = $this->shouldLogResponsePayload
&& !is_null($response) && !is_null($response->getBody());
// Create a new response with its body as a rewindable caching stream.
// This is needed when we want to both log the response body
// and use it in other cases, e.g. creating an exception with this
// response body, reading the content of the downloaded report.
if ($needRewind && !$response->getBody()->isSeekable()) {
$response =
$response->withBody(new CachingStream($response->getBody()));
if (!is_null($error)) {
// Creates a new RequestException with the response whose stream
// can be rewound.
$error = RequestException::create(
$request,
$response,
$error
);
}
}
$detailedLog =
$this->scrubAndFormatDetailedMessage($request, $response, $error);
// Rewind the response stream so it can be used again, e.g. reading
// the content of the downloaded report.
if ($needRewind) {
\GuzzleHttp\Psr7\rewind_body($response);
}
return $detailedLog;
} | php | public function formatDetailed(
RequestInterface $request,
ResponseInterface &$response = null,
Exception &$error = null
) {
$needRewind = $this->shouldLogResponsePayload
&& !is_null($response) && !is_null($response->getBody());
// Create a new response with its body as a rewindable caching stream.
// This is needed when we want to both log the response body
// and use it in other cases, e.g. creating an exception with this
// response body, reading the content of the downloaded report.
if ($needRewind && !$response->getBody()->isSeekable()) {
$response =
$response->withBody(new CachingStream($response->getBody()));
if (!is_null($error)) {
// Creates a new RequestException with the response whose stream
// can be rewound.
$error = RequestException::create(
$request,
$response,
$error
);
}
}
$detailedLog =
$this->scrubAndFormatDetailedMessage($request, $response, $error);
// Rewind the response stream so it can be used again, e.g. reading
// the content of the downloaded report.
if ($needRewind) {
\GuzzleHttp\Psr7\rewind_body($response);
}
return $detailedLog;
} | [
"public",
"function",
"formatDetailed",
"(",
"RequestInterface",
"$",
"request",
",",
"ResponseInterface",
"&",
"$",
"response",
"=",
"null",
",",
"Exception",
"&",
"$",
"error",
"=",
"null",
")",
"{",
"$",
"needRewind",
"=",
"$",
"this",
"->",
"shouldLogResponsePayload",
"&&",
"!",
"is_null",
"(",
"$",
"response",
")",
"&&",
"!",
"is_null",
"(",
"$",
"response",
"->",
"getBody",
"(",
")",
")",
";",
"// Create a new response with its body as a rewindable caching stream.",
"// This is needed when we want to both log the response body",
"// and use it in other cases, e.g. creating an exception with this",
"// response body, reading the content of the downloaded report.",
"if",
"(",
"$",
"needRewind",
"&&",
"!",
"$",
"response",
"->",
"getBody",
"(",
")",
"->",
"isSeekable",
"(",
")",
")",
"{",
"$",
"response",
"=",
"$",
"response",
"->",
"withBody",
"(",
"new",
"CachingStream",
"(",
"$",
"response",
"->",
"getBody",
"(",
")",
")",
")",
";",
"if",
"(",
"!",
"is_null",
"(",
"$",
"error",
")",
")",
"{",
"// Creates a new RequestException with the response whose stream",
"// can be rewound.",
"$",
"error",
"=",
"RequestException",
"::",
"create",
"(",
"$",
"request",
",",
"$",
"response",
",",
"$",
"error",
")",
";",
"}",
"}",
"$",
"detailedLog",
"=",
"$",
"this",
"->",
"scrubAndFormatDetailedMessage",
"(",
"$",
"request",
",",
"$",
"response",
",",
"$",
"error",
")",
";",
"// Rewind the response stream so it can be used again, e.g. reading",
"// the content of the downloaded report.",
"if",
"(",
"$",
"needRewind",
")",
"{",
"\\",
"GuzzleHttp",
"\\",
"Psr7",
"\\",
"rewind_body",
"(",
"$",
"response",
")",
";",
"}",
"return",
"$",
"detailedLog",
";",
"}"
] | Formats a detailed message based on the specified HTTP request and
response, and errors, if present. This function also replaces the
original response with a new one with a seekable stream, if the original
one contains forward-only stream.
@param RequestInterface $request the HTTP request
@param ResponseInterface|null &$response the HTTP response containing the
body to be formatted. This original response with forward-only body
stream will be replaced with a new response with a seekable stream
@param Exception|null &$error the HTTP error whose body would be modified
to use a seekable stream
@return string the formatted detailed log message | [
"Formats",
"a",
"detailed",
"message",
"based",
"on",
"the",
"specified",
"HTTP",
"request",
"and",
"response",
"and",
"errors",
"if",
"present",
".",
"This",
"function",
"also",
"replaces",
"the",
"original",
"response",
"with",
"a",
"new",
"one",
"with",
"a",
"seekable",
"stream",
"if",
"the",
"original",
"one",
"contains",
"forward",
"-",
"only",
"stream",
"."
] | d552b800ad53c400b1a50c7852e7ad184245d2ea | https://github.com/googleads/googleads-php-lib/blob/d552b800ad53c400b1a50c7852e7ad184245d2ea/src/Google/AdsApi/Common/GuzzleLogMessageFormatter.php#L127-L163 | train |
googleads/googleads-php-lib | src/Google/AdsApi/Common/GuzzleLogMessageFormatter.php | GuzzleLogMessageFormatter.scrubAndFormatDetailedMessage | private function scrubAndFormatDetailedMessage(
RequestInterface $request,
ResponseInterface $response = null,
Exception $error = null
) {
$requestHeaders = LogMessageScrubbers::scrubHttpHeadersArray(
$request->getHeaders(),
$this->requestHttpHeadersToScrub
);
$changes = [
'set_headers' => $requestHeaders,
// The request body is encoded and thus needed to be decoded here
// to provide a readable log message.
'body' => urldecode($request->getBody())
];
$clonedRequest = \GuzzleHttp\Psr7\modify_request($request, $changes);
return $this->detailedMessageFormatter->format(
$clonedRequest,
$response,
$error
);
} | php | private function scrubAndFormatDetailedMessage(
RequestInterface $request,
ResponseInterface $response = null,
Exception $error = null
) {
$requestHeaders = LogMessageScrubbers::scrubHttpHeadersArray(
$request->getHeaders(),
$this->requestHttpHeadersToScrub
);
$changes = [
'set_headers' => $requestHeaders,
// The request body is encoded and thus needed to be decoded here
// to provide a readable log message.
'body' => urldecode($request->getBody())
];
$clonedRequest = \GuzzleHttp\Psr7\modify_request($request, $changes);
return $this->detailedMessageFormatter->format(
$clonedRequest,
$response,
$error
);
} | [
"private",
"function",
"scrubAndFormatDetailedMessage",
"(",
"RequestInterface",
"$",
"request",
",",
"ResponseInterface",
"$",
"response",
"=",
"null",
",",
"Exception",
"$",
"error",
"=",
"null",
")",
"{",
"$",
"requestHeaders",
"=",
"LogMessageScrubbers",
"::",
"scrubHttpHeadersArray",
"(",
"$",
"request",
"->",
"getHeaders",
"(",
")",
",",
"$",
"this",
"->",
"requestHttpHeadersToScrub",
")",
";",
"$",
"changes",
"=",
"[",
"'set_headers'",
"=>",
"$",
"requestHeaders",
",",
"// The request body is encoded and thus needed to be decoded here",
"// to provide a readable log message.",
"'body'",
"=>",
"urldecode",
"(",
"$",
"request",
"->",
"getBody",
"(",
")",
")",
"]",
";",
"$",
"clonedRequest",
"=",
"\\",
"GuzzleHttp",
"\\",
"Psr7",
"\\",
"modify_request",
"(",
"$",
"request",
",",
"$",
"changes",
")",
";",
"return",
"$",
"this",
"->",
"detailedMessageFormatter",
"->",
"format",
"(",
"$",
"clonedRequest",
",",
"$",
"response",
",",
"$",
"error",
")",
";",
"}"
] | Scrubs and formats a detailed message containing HTTP request and
response, and errors if exist.
@param RequestInterface $request the HTTP request
@param ResponseInterface|null $response the HTTP response
@param Exception $error the HTTP error
@return string the formatted detailed log message | [
"Scrubs",
"and",
"formats",
"a",
"detailed",
"message",
"containing",
"HTTP",
"request",
"and",
"response",
"and",
"errors",
"if",
"exist",
"."
] | d552b800ad53c400b1a50c7852e7ad184245d2ea | https://github.com/googleads/googleads-php-lib/blob/d552b800ad53c400b1a50c7852e7ad184245d2ea/src/Google/AdsApi/Common/GuzzleLogMessageFormatter.php#L174-L196 | train |
googleads/googleads-php-lib | src/Google/AdsApi/AdWords/v201809/mcm/CustomerService.php | CustomerService.mutate | public function mutate(\Google\AdsApi\AdWords\v201809\mcm\Customer $customer)
{
return $this->__soapCall('mutate', array(array('customer' => $customer)))->getRval();
} | php | public function mutate(\Google\AdsApi\AdWords\v201809\mcm\Customer $customer)
{
return $this->__soapCall('mutate', array(array('customer' => $customer)))->getRval();
} | [
"public",
"function",
"mutate",
"(",
"\\",
"Google",
"\\",
"AdsApi",
"\\",
"AdWords",
"\\",
"v201809",
"\\",
"mcm",
"\\",
"Customer",
"$",
"customer",
")",
"{",
"return",
"$",
"this",
"->",
"__soapCall",
"(",
"'mutate'",
",",
"array",
"(",
"array",
"(",
"'customer'",
"=>",
"$",
"customer",
")",
")",
")",
"->",
"getRval",
"(",
")",
";",
"}"
] | Update the authorized customer.
<p>While there are a limited set of properties available to update, please read this
<a href="https://support.google.com/analytics/answer/1033981">help center article
on auto-tagging</a> before updating {@code customer.autoTaggingEnabled}.
@param \Google\AdsApi\AdWords\v201809\mcm\Customer $customer
@return \Google\AdsApi\AdWords\v201809\mcm\Customer
@throws \Google\AdsApi\AdWords\v201809\cm\ApiException | [
"Update",
"the",
"authorized",
"customer",
"."
] | d552b800ad53c400b1a50c7852e7ad184245d2ea | https://github.com/googleads/googleads-php-lib/blob/d552b800ad53c400b1a50c7852e7ad184245d2ea/src/Google/AdsApi/AdWords/v201809/mcm/CustomerService.php#L122-L125 | train |
googleads/googleads-php-lib | src/Google/AdsApi/Common/AdsGuzzleHttpClientFactory.php | AdsGuzzleHttpClientFactory.generateHttpClient | public function generateHttpClient()
{
$config = $this->config;
if (!array_key_exists('handler', $config)
|| $config['handler'] === null) {
$config['handler'] = HandlerStack::create();
}
// Add a logging middleware required by this library.
$config['handler']->before(
'http_errors',
GuzzleLogMessageHandler::log($this->logger, $this->messageFormatter)
);
return new Client($config);
} | php | public function generateHttpClient()
{
$config = $this->config;
if (!array_key_exists('handler', $config)
|| $config['handler'] === null) {
$config['handler'] = HandlerStack::create();
}
// Add a logging middleware required by this library.
$config['handler']->before(
'http_errors',
GuzzleLogMessageHandler::log($this->logger, $this->messageFormatter)
);
return new Client($config);
} | [
"public",
"function",
"generateHttpClient",
"(",
")",
"{",
"$",
"config",
"=",
"$",
"this",
"->",
"config",
";",
"if",
"(",
"!",
"array_key_exists",
"(",
"'handler'",
",",
"$",
"config",
")",
"||",
"$",
"config",
"[",
"'handler'",
"]",
"===",
"null",
")",
"{",
"$",
"config",
"[",
"'handler'",
"]",
"=",
"HandlerStack",
"::",
"create",
"(",
")",
";",
"}",
"// Add a logging middleware required by this library.",
"$",
"config",
"[",
"'handler'",
"]",
"->",
"before",
"(",
"'http_errors'",
",",
"GuzzleLogMessageHandler",
"::",
"log",
"(",
"$",
"this",
"->",
"logger",
",",
"$",
"this",
"->",
"messageFormatter",
")",
")",
";",
"return",
"new",
"Client",
"(",
"$",
"config",
")",
";",
"}"
] | Generates a Guzzle HTTP client for making HTTP calls by using configs of
the user-provided client. This method adds the logging middleware required
by this library to the handler stack of the generated client.
@return Client the Guzzle HTTP client | [
"Generates",
"a",
"Guzzle",
"HTTP",
"client",
"for",
"making",
"HTTP",
"calls",
"by",
"using",
"configs",
"of",
"the",
"user",
"-",
"provided",
"client",
".",
"This",
"method",
"adds",
"the",
"logging",
"middleware",
"required",
"by",
"this",
"library",
"to",
"the",
"handler",
"stack",
"of",
"the",
"generated",
"client",
"."
] | d552b800ad53c400b1a50c7852e7ad184245d2ea | https://github.com/googleads/googleads-php-lib/blob/d552b800ad53c400b1a50c7852e7ad184245d2ea/src/Google/AdsApi/Common/AdsGuzzleHttpClientFactory.php#L64-L79 | train |
googleads/googleads-php-lib | examples/AdWords/v201809/AdvancedOperations/AddDynamicPageFeed.php | AddDynamicPageFeed.createFeed | private static function createFeed(
AdWordsServices $adWordsServices,
AdWordsSession $session
) {
$feedService = $adWordsServices->get($session, FeedService::class);
// Create feed attributes.
$urlAttribute = new FeedAttribute();
$urlAttribute->setType(FeedAttributeType::URL_LIST);
$urlAttribute->setName('Page URL');
$labelAttribute = new FeedAttribute();
$labelAttribute->setType(FeedAttributeType::STRING_LIST);
$labelAttribute->setName('Label');
// Create the feed.
$dsaPageFeed = new Feed();
$dsaPageFeed->setName('DSA Feed #' . uniqid());
$dsaPageFeed->setAttributes([$urlAttribute, $labelAttribute]);
$dsaPageFeed->setOrigin(FeedOrigin::USER);
// Create the feed operation and add it on the server.
$operation = new FeedOperation();
$operation->setOperator(Operator::ADD);
$operation->setOperand($dsaPageFeed);
$result = $feedService->mutate([$operation]);
// Holds the feeds metadata.
$feedDetails = new DSAFeedDetails();
$savedFeed = $result->getValue()[0];
$feedDetails->feedId = $savedFeed->getId();
$savedAttributes = $savedFeed->getAttributes();
$feedDetails->urlAttributeId = $savedAttributes[0]->getId();
$feedDetails->labelAttributeId = $savedAttributes[1]->getId();
// Print out some information about the created feed.
printf(
"Feed with name '%s', ID %d with urlAttributeId %d and labelAttributeId %d was created.\n",
$savedFeed->getName(),
$feedDetails->feedId,
$feedDetails->urlAttributeId,
$feedDetails->labelAttributeId
);
return $feedDetails;
} | php | private static function createFeed(
AdWordsServices $adWordsServices,
AdWordsSession $session
) {
$feedService = $adWordsServices->get($session, FeedService::class);
// Create feed attributes.
$urlAttribute = new FeedAttribute();
$urlAttribute->setType(FeedAttributeType::URL_LIST);
$urlAttribute->setName('Page URL');
$labelAttribute = new FeedAttribute();
$labelAttribute->setType(FeedAttributeType::STRING_LIST);
$labelAttribute->setName('Label');
// Create the feed.
$dsaPageFeed = new Feed();
$dsaPageFeed->setName('DSA Feed #' . uniqid());
$dsaPageFeed->setAttributes([$urlAttribute, $labelAttribute]);
$dsaPageFeed->setOrigin(FeedOrigin::USER);
// Create the feed operation and add it on the server.
$operation = new FeedOperation();
$operation->setOperator(Operator::ADD);
$operation->setOperand($dsaPageFeed);
$result = $feedService->mutate([$operation]);
// Holds the feeds metadata.
$feedDetails = new DSAFeedDetails();
$savedFeed = $result->getValue()[0];
$feedDetails->feedId = $savedFeed->getId();
$savedAttributes = $savedFeed->getAttributes();
$feedDetails->urlAttributeId = $savedAttributes[0]->getId();
$feedDetails->labelAttributeId = $savedAttributes[1]->getId();
// Print out some information about the created feed.
printf(
"Feed with name '%s', ID %d with urlAttributeId %d and labelAttributeId %d was created.\n",
$savedFeed->getName(),
$feedDetails->feedId,
$feedDetails->urlAttributeId,
$feedDetails->labelAttributeId
);
return $feedDetails;
} | [
"private",
"static",
"function",
"createFeed",
"(",
"AdWordsServices",
"$",
"adWordsServices",
",",
"AdWordsSession",
"$",
"session",
")",
"{",
"$",
"feedService",
"=",
"$",
"adWordsServices",
"->",
"get",
"(",
"$",
"session",
",",
"FeedService",
"::",
"class",
")",
";",
"// Create feed attributes.",
"$",
"urlAttribute",
"=",
"new",
"FeedAttribute",
"(",
")",
";",
"$",
"urlAttribute",
"->",
"setType",
"(",
"FeedAttributeType",
"::",
"URL_LIST",
")",
";",
"$",
"urlAttribute",
"->",
"setName",
"(",
"'Page URL'",
")",
";",
"$",
"labelAttribute",
"=",
"new",
"FeedAttribute",
"(",
")",
";",
"$",
"labelAttribute",
"->",
"setType",
"(",
"FeedAttributeType",
"::",
"STRING_LIST",
")",
";",
"$",
"labelAttribute",
"->",
"setName",
"(",
"'Label'",
")",
";",
"// Create the feed.",
"$",
"dsaPageFeed",
"=",
"new",
"Feed",
"(",
")",
";",
"$",
"dsaPageFeed",
"->",
"setName",
"(",
"'DSA Feed #'",
".",
"uniqid",
"(",
")",
")",
";",
"$",
"dsaPageFeed",
"->",
"setAttributes",
"(",
"[",
"$",
"urlAttribute",
",",
"$",
"labelAttribute",
"]",
")",
";",
"$",
"dsaPageFeed",
"->",
"setOrigin",
"(",
"FeedOrigin",
"::",
"USER",
")",
";",
"// Create the feed operation and add it on the server.",
"$",
"operation",
"=",
"new",
"FeedOperation",
"(",
")",
";",
"$",
"operation",
"->",
"setOperator",
"(",
"Operator",
"::",
"ADD",
")",
";",
"$",
"operation",
"->",
"setOperand",
"(",
"$",
"dsaPageFeed",
")",
";",
"$",
"result",
"=",
"$",
"feedService",
"->",
"mutate",
"(",
"[",
"$",
"operation",
"]",
")",
";",
"// Holds the feeds metadata.",
"$",
"feedDetails",
"=",
"new",
"DSAFeedDetails",
"(",
")",
";",
"$",
"savedFeed",
"=",
"$",
"result",
"->",
"getValue",
"(",
")",
"[",
"0",
"]",
";",
"$",
"feedDetails",
"->",
"feedId",
"=",
"$",
"savedFeed",
"->",
"getId",
"(",
")",
";",
"$",
"savedAttributes",
"=",
"$",
"savedFeed",
"->",
"getAttributes",
"(",
")",
";",
"$",
"feedDetails",
"->",
"urlAttributeId",
"=",
"$",
"savedAttributes",
"[",
"0",
"]",
"->",
"getId",
"(",
")",
";",
"$",
"feedDetails",
"->",
"labelAttributeId",
"=",
"$",
"savedAttributes",
"[",
"1",
"]",
"->",
"getId",
"(",
")",
";",
"// Print out some information about the created feed.",
"printf",
"(",
"\"Feed with name '%s', ID %d with urlAttributeId %d and labelAttributeId %d was created.\\n\"",
",",
"$",
"savedFeed",
"->",
"getName",
"(",
")",
",",
"$",
"feedDetails",
"->",
"feedId",
",",
"$",
"feedDetails",
"->",
"urlAttributeId",
",",
"$",
"feedDetails",
"->",
"labelAttributeId",
")",
";",
"return",
"$",
"feedDetails",
";",
"}"
] | Creates the feed for DSA page URLs. | [
"Creates",
"the",
"feed",
"for",
"DSA",
"page",
"URLs",
"."
] | d552b800ad53c400b1a50c7852e7ad184245d2ea | https://github.com/googleads/googleads-php-lib/blob/d552b800ad53c400b1a50c7852e7ad184245d2ea/examples/AdWords/v201809/AdvancedOperations/AddDynamicPageFeed.php#L128-L175 | train |
googleads/googleads-php-lib | examples/AdWords/v201809/AdvancedOperations/AddDynamicPageFeed.php | AddDynamicPageFeed.createFeedMapping | private static function createFeedMapping(
AdWordsServices $adWordsServices,
AdWordsSession $session,
DSAFeedDetails $feedDetails
) {
$feedMappingService = $adWordsServices->get($session, FeedMappingService::class);
// Map the feed attribute IDs to the field ID constants.
$urlFieldMapping = new AttributeFieldMapping();
$urlFieldMapping->setFeedAttributeId(
$feedDetails->urlAttributeId
);
$urlFieldMapping->setFieldId(self::DSA_PAGE_URLS_FIELD_ID);
$labelFieldMapping = new AttributeFieldMapping();
$labelFieldMapping->setFeedAttributeId(
$feedDetails->labelAttributeId
);
$labelFieldMapping->setFieldId(self::DSA_LABEL_FIELD_ID);
// Create the feed mapping and feed mapping operation.
$feedMapping = new FeedMapping();
$feedMapping->setCriterionType(self::DSA_PAGE_FEED_CRITERION_TYPE);
$feedMapping->setFeedId($feedDetails->feedId);
$feedMapping->setAttributeFieldMappings(
[$urlFieldMapping, $labelFieldMapping]
);
$operation = new FeedMappingOperation();
$operation->setOperand($feedMapping);
$operation->setOperator(Operator::ADD);
// Create the feed mapping operation on the server and print out some
// information.
$result = $feedMappingService->mutate([$operation]);
$feedMapping = $result->getValue()[0];
printf(
"Feed mapping with ID %d and criterion type %d was saved for feed with ID %d.\n",
$feedMapping->getFeedMappingId(),
$feedMapping->getCriterionType(),
$feedMapping->getFeedId()
);
} | php | private static function createFeedMapping(
AdWordsServices $adWordsServices,
AdWordsSession $session,
DSAFeedDetails $feedDetails
) {
$feedMappingService = $adWordsServices->get($session, FeedMappingService::class);
// Map the feed attribute IDs to the field ID constants.
$urlFieldMapping = new AttributeFieldMapping();
$urlFieldMapping->setFeedAttributeId(
$feedDetails->urlAttributeId
);
$urlFieldMapping->setFieldId(self::DSA_PAGE_URLS_FIELD_ID);
$labelFieldMapping = new AttributeFieldMapping();
$labelFieldMapping->setFeedAttributeId(
$feedDetails->labelAttributeId
);
$labelFieldMapping->setFieldId(self::DSA_LABEL_FIELD_ID);
// Create the feed mapping and feed mapping operation.
$feedMapping = new FeedMapping();
$feedMapping->setCriterionType(self::DSA_PAGE_FEED_CRITERION_TYPE);
$feedMapping->setFeedId($feedDetails->feedId);
$feedMapping->setAttributeFieldMappings(
[$urlFieldMapping, $labelFieldMapping]
);
$operation = new FeedMappingOperation();
$operation->setOperand($feedMapping);
$operation->setOperator(Operator::ADD);
// Create the feed mapping operation on the server and print out some
// information.
$result = $feedMappingService->mutate([$operation]);
$feedMapping = $result->getValue()[0];
printf(
"Feed mapping with ID %d and criterion type %d was saved for feed with ID %d.\n",
$feedMapping->getFeedMappingId(),
$feedMapping->getCriterionType(),
$feedMapping->getFeedId()
);
} | [
"private",
"static",
"function",
"createFeedMapping",
"(",
"AdWordsServices",
"$",
"adWordsServices",
",",
"AdWordsSession",
"$",
"session",
",",
"DSAFeedDetails",
"$",
"feedDetails",
")",
"{",
"$",
"feedMappingService",
"=",
"$",
"adWordsServices",
"->",
"get",
"(",
"$",
"session",
",",
"FeedMappingService",
"::",
"class",
")",
";",
"// Map the feed attribute IDs to the field ID constants.",
"$",
"urlFieldMapping",
"=",
"new",
"AttributeFieldMapping",
"(",
")",
";",
"$",
"urlFieldMapping",
"->",
"setFeedAttributeId",
"(",
"$",
"feedDetails",
"->",
"urlAttributeId",
")",
";",
"$",
"urlFieldMapping",
"->",
"setFieldId",
"(",
"self",
"::",
"DSA_PAGE_URLS_FIELD_ID",
")",
";",
"$",
"labelFieldMapping",
"=",
"new",
"AttributeFieldMapping",
"(",
")",
";",
"$",
"labelFieldMapping",
"->",
"setFeedAttributeId",
"(",
"$",
"feedDetails",
"->",
"labelAttributeId",
")",
";",
"$",
"labelFieldMapping",
"->",
"setFieldId",
"(",
"self",
"::",
"DSA_LABEL_FIELD_ID",
")",
";",
"// Create the feed mapping and feed mapping operation.",
"$",
"feedMapping",
"=",
"new",
"FeedMapping",
"(",
")",
";",
"$",
"feedMapping",
"->",
"setCriterionType",
"(",
"self",
"::",
"DSA_PAGE_FEED_CRITERION_TYPE",
")",
";",
"$",
"feedMapping",
"->",
"setFeedId",
"(",
"$",
"feedDetails",
"->",
"feedId",
")",
";",
"$",
"feedMapping",
"->",
"setAttributeFieldMappings",
"(",
"[",
"$",
"urlFieldMapping",
",",
"$",
"labelFieldMapping",
"]",
")",
";",
"$",
"operation",
"=",
"new",
"FeedMappingOperation",
"(",
")",
";",
"$",
"operation",
"->",
"setOperand",
"(",
"$",
"feedMapping",
")",
";",
"$",
"operation",
"->",
"setOperator",
"(",
"Operator",
"::",
"ADD",
")",
";",
"// Create the feed mapping operation on the server and print out some",
"// information.",
"$",
"result",
"=",
"$",
"feedMappingService",
"->",
"mutate",
"(",
"[",
"$",
"operation",
"]",
")",
";",
"$",
"feedMapping",
"=",
"$",
"result",
"->",
"getValue",
"(",
")",
"[",
"0",
"]",
";",
"printf",
"(",
"\"Feed mapping with ID %d and criterion type %d was saved for feed with ID %d.\\n\"",
",",
"$",
"feedMapping",
"->",
"getFeedMappingId",
"(",
")",
",",
"$",
"feedMapping",
"->",
"getCriterionType",
"(",
")",
",",
"$",
"feedMapping",
"->",
"getFeedId",
"(",
")",
")",
";",
"}"
] | Creates the feed mapping for the DSA page feeds. | [
"Creates",
"the",
"feed",
"mapping",
"for",
"the",
"DSA",
"page",
"feeds",
"."
] | d552b800ad53c400b1a50c7852e7ad184245d2ea | https://github.com/googleads/googleads-php-lib/blob/d552b800ad53c400b1a50c7852e7ad184245d2ea/examples/AdWords/v201809/AdvancedOperations/AddDynamicPageFeed.php#L180-L221 | train |
googleads/googleads-php-lib | examples/AdWords/v201809/AdvancedOperations/AddDynamicPageFeed.php | AddDynamicPageFeed.createFeedItems | private static function createFeedItems(
AdWordsServices $adWordsServices,
AdWordsSession $session,
DSAFeedDetails $feedDetails,
$labelName
) {
$feedItemService = $adWordsServices->get($session, FeedItemService::class);
// Create operations to add feed items.
$rentalCars = self::createDsaUrlAddOperation(
$feedDetails,
'http://www.example.com/discounts/rental-cars',
$labelName
);
$hotelDeals = self::createDsaUrlAddOperation(
$feedDetails,
'http://www.example.com/discounts/hotel-deals',
$labelName
);
$flightDeals = self::createDsaUrlAddOperation(
$feedDetails,
'http://www.example.com/discounts/flight-deals',
$labelName
);
// Add feed item operations on the server and print out some information.
$result = $feedItemService->mutate(
[$rentalCars, $hotelDeals, $flightDeals]
);
foreach ($result->getValue() as $feedItem) {
printf(
"Feed item with feed item ID %d was added.\n",
$feedItem->getFeedItemId()
);
}
} | php | private static function createFeedItems(
AdWordsServices $adWordsServices,
AdWordsSession $session,
DSAFeedDetails $feedDetails,
$labelName
) {
$feedItemService = $adWordsServices->get($session, FeedItemService::class);
// Create operations to add feed items.
$rentalCars = self::createDsaUrlAddOperation(
$feedDetails,
'http://www.example.com/discounts/rental-cars',
$labelName
);
$hotelDeals = self::createDsaUrlAddOperation(
$feedDetails,
'http://www.example.com/discounts/hotel-deals',
$labelName
);
$flightDeals = self::createDsaUrlAddOperation(
$feedDetails,
'http://www.example.com/discounts/flight-deals',
$labelName
);
// Add feed item operations on the server and print out some information.
$result = $feedItemService->mutate(
[$rentalCars, $hotelDeals, $flightDeals]
);
foreach ($result->getValue() as $feedItem) {
printf(
"Feed item with feed item ID %d was added.\n",
$feedItem->getFeedItemId()
);
}
} | [
"private",
"static",
"function",
"createFeedItems",
"(",
"AdWordsServices",
"$",
"adWordsServices",
",",
"AdWordsSession",
"$",
"session",
",",
"DSAFeedDetails",
"$",
"feedDetails",
",",
"$",
"labelName",
")",
"{",
"$",
"feedItemService",
"=",
"$",
"adWordsServices",
"->",
"get",
"(",
"$",
"session",
",",
"FeedItemService",
"::",
"class",
")",
";",
"// Create operations to add feed items.",
"$",
"rentalCars",
"=",
"self",
"::",
"createDsaUrlAddOperation",
"(",
"$",
"feedDetails",
",",
"'http://www.example.com/discounts/rental-cars'",
",",
"$",
"labelName",
")",
";",
"$",
"hotelDeals",
"=",
"self",
"::",
"createDsaUrlAddOperation",
"(",
"$",
"feedDetails",
",",
"'http://www.example.com/discounts/hotel-deals'",
",",
"$",
"labelName",
")",
";",
"$",
"flightDeals",
"=",
"self",
"::",
"createDsaUrlAddOperation",
"(",
"$",
"feedDetails",
",",
"'http://www.example.com/discounts/flight-deals'",
",",
"$",
"labelName",
")",
";",
"// Add feed item operations on the server and print out some information.",
"$",
"result",
"=",
"$",
"feedItemService",
"->",
"mutate",
"(",
"[",
"$",
"rentalCars",
",",
"$",
"hotelDeals",
",",
"$",
"flightDeals",
"]",
")",
";",
"foreach",
"(",
"$",
"result",
"->",
"getValue",
"(",
")",
"as",
"$",
"feedItem",
")",
"{",
"printf",
"(",
"\"Feed item with feed item ID %d was added.\\n\"",
",",
"$",
"feedItem",
"->",
"getFeedItemId",
"(",
")",
")",
";",
"}",
"}"
] | Creates the page URLs in the DSA page feed. | [
"Creates",
"the",
"page",
"URLs",
"in",
"the",
"DSA",
"page",
"feed",
"."
] | d552b800ad53c400b1a50c7852e7ad184245d2ea | https://github.com/googleads/googleads-php-lib/blob/d552b800ad53c400b1a50c7852e7ad184245d2ea/examples/AdWords/v201809/AdvancedOperations/AddDynamicPageFeed.php#L226-L261 | train |
googleads/googleads-php-lib | examples/AdWords/v201809/AdvancedOperations/AddDynamicPageFeed.php | AddDynamicPageFeed.createDsaUrlAddOperation | private static function createDsaUrlAddOperation(
DSAFeedDetails $feedDetails,
$url,
$labelName
) {
// Create the FeedItemAttributeValues for the URL and label.
$urlAttributeValue = new FeedItemAttributeValue();
$urlAttributeValue->setFeedAttributeId($feedDetails->urlAttributeId);
// See https://support.google.com/adwords/answer/7166527 for page feed
// URL recommendations and rules.
$urlAttributeValue->setStringValues([$url]);
$labelAttributeValue = new FeedItemAttributeValue();
$labelAttributeValue->setFeedAttributeId(
$feedDetails->labelAttributeId
);
$labelAttributeValue->setStringValues([$labelName]);
// Create the feed item.
$feedItem = new FeedItem();
$feedItem->setFeedId($feedDetails->feedId);
$feedItem->setAttributeValues([$urlAttributeValue, $labelAttributeValue]);
// Create the feed item operation.
$operation = new FeedItemOperation();
$operation->setOperand($feedItem);
$operation->setOperator(Operator::ADD);
return $operation;
} | php | private static function createDsaUrlAddOperation(
DSAFeedDetails $feedDetails,
$url,
$labelName
) {
// Create the FeedItemAttributeValues for the URL and label.
$urlAttributeValue = new FeedItemAttributeValue();
$urlAttributeValue->setFeedAttributeId($feedDetails->urlAttributeId);
// See https://support.google.com/adwords/answer/7166527 for page feed
// URL recommendations and rules.
$urlAttributeValue->setStringValues([$url]);
$labelAttributeValue = new FeedItemAttributeValue();
$labelAttributeValue->setFeedAttributeId(
$feedDetails->labelAttributeId
);
$labelAttributeValue->setStringValues([$labelName]);
// Create the feed item.
$feedItem = new FeedItem();
$feedItem->setFeedId($feedDetails->feedId);
$feedItem->setAttributeValues([$urlAttributeValue, $labelAttributeValue]);
// Create the feed item operation.
$operation = new FeedItemOperation();
$operation->setOperand($feedItem);
$operation->setOperator(Operator::ADD);
return $operation;
} | [
"private",
"static",
"function",
"createDsaUrlAddOperation",
"(",
"DSAFeedDetails",
"$",
"feedDetails",
",",
"$",
"url",
",",
"$",
"labelName",
")",
"{",
"// Create the FeedItemAttributeValues for the URL and label.",
"$",
"urlAttributeValue",
"=",
"new",
"FeedItemAttributeValue",
"(",
")",
";",
"$",
"urlAttributeValue",
"->",
"setFeedAttributeId",
"(",
"$",
"feedDetails",
"->",
"urlAttributeId",
")",
";",
"// See https://support.google.com/adwords/answer/7166527 for page feed",
"// URL recommendations and rules.",
"$",
"urlAttributeValue",
"->",
"setStringValues",
"(",
"[",
"$",
"url",
"]",
")",
";",
"$",
"labelAttributeValue",
"=",
"new",
"FeedItemAttributeValue",
"(",
")",
";",
"$",
"labelAttributeValue",
"->",
"setFeedAttributeId",
"(",
"$",
"feedDetails",
"->",
"labelAttributeId",
")",
";",
"$",
"labelAttributeValue",
"->",
"setStringValues",
"(",
"[",
"$",
"labelName",
"]",
")",
";",
"// Create the feed item.",
"$",
"feedItem",
"=",
"new",
"FeedItem",
"(",
")",
";",
"$",
"feedItem",
"->",
"setFeedId",
"(",
"$",
"feedDetails",
"->",
"feedId",
")",
";",
"$",
"feedItem",
"->",
"setAttributeValues",
"(",
"[",
"$",
"urlAttributeValue",
",",
"$",
"labelAttributeValue",
"]",
")",
";",
"// Create the feed item operation.",
"$",
"operation",
"=",
"new",
"FeedItemOperation",
"(",
")",
";",
"$",
"operation",
"->",
"setOperand",
"(",
"$",
"feedItem",
")",
";",
"$",
"operation",
"->",
"setOperator",
"(",
"Operator",
"::",
"ADD",
")",
";",
"return",
"$",
"operation",
";",
"}"
] | Creates a feed item operation to add the DSA URL. | [
"Creates",
"a",
"feed",
"item",
"operation",
"to",
"add",
"the",
"DSA",
"URL",
"."
] | d552b800ad53c400b1a50c7852e7ad184245d2ea | https://github.com/googleads/googleads-php-lib/blob/d552b800ad53c400b1a50c7852e7ad184245d2ea/examples/AdWords/v201809/AdvancedOperations/AddDynamicPageFeed.php#L266-L296 | train |
googleads/googleads-php-lib | examples/AdWords/v201809/AdvancedOperations/AddDynamicPageFeed.php | AddDynamicPageFeed.updateCampaignDsaSetting | private static function updateCampaignDsaSetting(
AdWordsServices $adWordsServices,
AdWordsSession $session,
$campaignId,
DSAFeedDetails $feedDetails
) {
$campaignService = $adWordsServices->get($session, CampaignService::class);
// Create selector.
$selector = new Selector();
$selector->setFields(['Id', 'Settings']);
$selector->setPredicates(
[new Predicate('CampaignId', PredicateOperator::IN, [$campaignId])]
);
$result = $campaignService->get($selector);
if (empty($result->getEntries()) || $result->getTotalNumEntries() === 0) {
throw new InvalidArgumentException(
'No campaign found with ID: ' . $campaignId
);
}
$campaign = $result->getEntries()[0];
if ($campaign->getSettings() === null) {
throw new InvalidArgumentException(
'Campaign with ID ' . $campaignId . ' is not a DSA campaign.'
);
}
$dsaSetting = null;
foreach ($campaign->getSettings() as $setting) {
if ($setting instanceof DynamicSearchAdsSetting) {
$dsaSetting = $setting;
break;
}
}
if ($dsaSetting === null) {
throw new InvalidArgumentException(
'Campaign with ID ' . $campaignId . ' is not a DSA campaign.'
);
}
// Use a page feed to specify precisely which URLs to use with your
// Dynamic Search Ads.
$pageFeed = new PageFeed();
$pageFeed->setFeedIds([$feedDetails->feedId]);
$dsaSetting->setPageFeed($pageFeed);
// Optional: Specify whether only the supplied URLs should be used with your
// Dynamic Search Ads.
$dsaSetting->setUseSuppliedUrlsOnly(true);
$updatedCampaign = new Campaign();
$updatedCampaign->setId($campaignId);
$updatedCampaign->setSettings($campaign->getSettings());
$operation = new CampaignOperation();
$operation->setOperand($updatedCampaign);
$operation->setOperator(Operator::SET);
// Update the campaign on the server and print out some information.
$result = $campaignService->mutate([$operation]);
$updatedCampaign = $result->getValue()[0];
printf(
"DSA page feed for campaign ID %d was updated with feed ID %d.\n",
$updatedCampaign->getId(),
$feedDetails->feedId
);
} | php | private static function updateCampaignDsaSetting(
AdWordsServices $adWordsServices,
AdWordsSession $session,
$campaignId,
DSAFeedDetails $feedDetails
) {
$campaignService = $adWordsServices->get($session, CampaignService::class);
// Create selector.
$selector = new Selector();
$selector->setFields(['Id', 'Settings']);
$selector->setPredicates(
[new Predicate('CampaignId', PredicateOperator::IN, [$campaignId])]
);
$result = $campaignService->get($selector);
if (empty($result->getEntries()) || $result->getTotalNumEntries() === 0) {
throw new InvalidArgumentException(
'No campaign found with ID: ' . $campaignId
);
}
$campaign = $result->getEntries()[0];
if ($campaign->getSettings() === null) {
throw new InvalidArgumentException(
'Campaign with ID ' . $campaignId . ' is not a DSA campaign.'
);
}
$dsaSetting = null;
foreach ($campaign->getSettings() as $setting) {
if ($setting instanceof DynamicSearchAdsSetting) {
$dsaSetting = $setting;
break;
}
}
if ($dsaSetting === null) {
throw new InvalidArgumentException(
'Campaign with ID ' . $campaignId . ' is not a DSA campaign.'
);
}
// Use a page feed to specify precisely which URLs to use with your
// Dynamic Search Ads.
$pageFeed = new PageFeed();
$pageFeed->setFeedIds([$feedDetails->feedId]);
$dsaSetting->setPageFeed($pageFeed);
// Optional: Specify whether only the supplied URLs should be used with your
// Dynamic Search Ads.
$dsaSetting->setUseSuppliedUrlsOnly(true);
$updatedCampaign = new Campaign();
$updatedCampaign->setId($campaignId);
$updatedCampaign->setSettings($campaign->getSettings());
$operation = new CampaignOperation();
$operation->setOperand($updatedCampaign);
$operation->setOperator(Operator::SET);
// Update the campaign on the server and print out some information.
$result = $campaignService->mutate([$operation]);
$updatedCampaign = $result->getValue()[0];
printf(
"DSA page feed for campaign ID %d was updated with feed ID %d.\n",
$updatedCampaign->getId(),
$feedDetails->feedId
);
} | [
"private",
"static",
"function",
"updateCampaignDsaSetting",
"(",
"AdWordsServices",
"$",
"adWordsServices",
",",
"AdWordsSession",
"$",
"session",
",",
"$",
"campaignId",
",",
"DSAFeedDetails",
"$",
"feedDetails",
")",
"{",
"$",
"campaignService",
"=",
"$",
"adWordsServices",
"->",
"get",
"(",
"$",
"session",
",",
"CampaignService",
"::",
"class",
")",
";",
"// Create selector.",
"$",
"selector",
"=",
"new",
"Selector",
"(",
")",
";",
"$",
"selector",
"->",
"setFields",
"(",
"[",
"'Id'",
",",
"'Settings'",
"]",
")",
";",
"$",
"selector",
"->",
"setPredicates",
"(",
"[",
"new",
"Predicate",
"(",
"'CampaignId'",
",",
"PredicateOperator",
"::",
"IN",
",",
"[",
"$",
"campaignId",
"]",
")",
"]",
")",
";",
"$",
"result",
"=",
"$",
"campaignService",
"->",
"get",
"(",
"$",
"selector",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"result",
"->",
"getEntries",
"(",
")",
")",
"||",
"$",
"result",
"->",
"getTotalNumEntries",
"(",
")",
"===",
"0",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'No campaign found with ID: '",
".",
"$",
"campaignId",
")",
";",
"}",
"$",
"campaign",
"=",
"$",
"result",
"->",
"getEntries",
"(",
")",
"[",
"0",
"]",
";",
"if",
"(",
"$",
"campaign",
"->",
"getSettings",
"(",
")",
"===",
"null",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Campaign with ID '",
".",
"$",
"campaignId",
".",
"' is not a DSA campaign.'",
")",
";",
"}",
"$",
"dsaSetting",
"=",
"null",
";",
"foreach",
"(",
"$",
"campaign",
"->",
"getSettings",
"(",
")",
"as",
"$",
"setting",
")",
"{",
"if",
"(",
"$",
"setting",
"instanceof",
"DynamicSearchAdsSetting",
")",
"{",
"$",
"dsaSetting",
"=",
"$",
"setting",
";",
"break",
";",
"}",
"}",
"if",
"(",
"$",
"dsaSetting",
"===",
"null",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Campaign with ID '",
".",
"$",
"campaignId",
".",
"' is not a DSA campaign.'",
")",
";",
"}",
"// Use a page feed to specify precisely which URLs to use with your",
"// Dynamic Search Ads.",
"$",
"pageFeed",
"=",
"new",
"PageFeed",
"(",
")",
";",
"$",
"pageFeed",
"->",
"setFeedIds",
"(",
"[",
"$",
"feedDetails",
"->",
"feedId",
"]",
")",
";",
"$",
"dsaSetting",
"->",
"setPageFeed",
"(",
"$",
"pageFeed",
")",
";",
"// Optional: Specify whether only the supplied URLs should be used with your",
"// Dynamic Search Ads.",
"$",
"dsaSetting",
"->",
"setUseSuppliedUrlsOnly",
"(",
"true",
")",
";",
"$",
"updatedCampaign",
"=",
"new",
"Campaign",
"(",
")",
";",
"$",
"updatedCampaign",
"->",
"setId",
"(",
"$",
"campaignId",
")",
";",
"$",
"updatedCampaign",
"->",
"setSettings",
"(",
"$",
"campaign",
"->",
"getSettings",
"(",
")",
")",
";",
"$",
"operation",
"=",
"new",
"CampaignOperation",
"(",
")",
";",
"$",
"operation",
"->",
"setOperand",
"(",
"$",
"updatedCampaign",
")",
";",
"$",
"operation",
"->",
"setOperator",
"(",
"Operator",
"::",
"SET",
")",
";",
"// Update the campaign on the server and print out some information.",
"$",
"result",
"=",
"$",
"campaignService",
"->",
"mutate",
"(",
"[",
"$",
"operation",
"]",
")",
";",
"$",
"updatedCampaign",
"=",
"$",
"result",
"->",
"getValue",
"(",
")",
"[",
"0",
"]",
";",
"printf",
"(",
"\"DSA page feed for campaign ID %d was updated with feed ID %d.\\n\"",
",",
"$",
"updatedCampaign",
"->",
"getId",
"(",
")",
",",
"$",
"feedDetails",
"->",
"feedId",
")",
";",
"}"
] | Updates the campaign DSA setting to add DSA pagefeeds. | [
"Updates",
"the",
"campaign",
"DSA",
"setting",
"to",
"add",
"DSA",
"pagefeeds",
"."
] | d552b800ad53c400b1a50c7852e7ad184245d2ea | https://github.com/googleads/googleads-php-lib/blob/d552b800ad53c400b1a50c7852e7ad184245d2ea/examples/AdWords/v201809/AdvancedOperations/AddDynamicPageFeed.php#L301-L370 | train |
googleads/googleads-php-lib | examples/AdWords/v201809/AdvancedOperations/AddDynamicPageFeed.php | AddDynamicPageFeed.addDsaTargeting | private static function addDsaTargeting(
AdWordsServices $adWordsServices,
AdWordsSession $session,
$adGroupId,
$dsaPageUrlLabel
) {
$adGroupCriterionService = $adWordsServices->get($session, AdGroupCriterionService::class);
// Create a webpage criterion.
$webpage = new Webpage();
$parameter = new WebpageParameter();
$parameter->setCriterionName('Test criterion');
$webpage->setParameter($parameter);
// Add a condition for label=specified_label_name.
$condition = new WebpageCondition();
$condition->setOperand(WebpageConditionOperand::CUSTOM_LABEL);
$condition->setArgument($dsaPageUrlLabel);
$parameter->setConditions([$condition]);
$criterion = new BiddableAdGroupCriterion();
$criterion->setAdGroupId($adGroupId);
$criterion->setCriterion($webpage);
// Set a custom bid for this criterion.
$biddingStrategyConfiguration = new BiddingStrategyConfiguration();
$cpcBid = new CpcBid();
$money = new Money();
$money->setMicroAmount(1500000);
$cpcBid->setBid($money);
$biddingStrategyConfiguration->setBids([$cpcBid]);
$criterion->setBiddingStrategyConfiguration($biddingStrategyConfiguration);
$operation = new AdGroupCriterionOperation();
$operation->setOperand($criterion);
$operation->setOperator(Operator::ADD);
// Create ad group criterion on the server and print out some information.
$result = $adGroupCriterionService->mutate([$operation]);
$criterion = $result->getValue()[0];
printf(
"Web page criterion with ID %d and status '%s' was created.\n",
$criterion->getCriterion()->getId(),
$criterion->getUserStatus()
);
} | php | private static function addDsaTargeting(
AdWordsServices $adWordsServices,
AdWordsSession $session,
$adGroupId,
$dsaPageUrlLabel
) {
$adGroupCriterionService = $adWordsServices->get($session, AdGroupCriterionService::class);
// Create a webpage criterion.
$webpage = new Webpage();
$parameter = new WebpageParameter();
$parameter->setCriterionName('Test criterion');
$webpage->setParameter($parameter);
// Add a condition for label=specified_label_name.
$condition = new WebpageCondition();
$condition->setOperand(WebpageConditionOperand::CUSTOM_LABEL);
$condition->setArgument($dsaPageUrlLabel);
$parameter->setConditions([$condition]);
$criterion = new BiddableAdGroupCriterion();
$criterion->setAdGroupId($adGroupId);
$criterion->setCriterion($webpage);
// Set a custom bid for this criterion.
$biddingStrategyConfiguration = new BiddingStrategyConfiguration();
$cpcBid = new CpcBid();
$money = new Money();
$money->setMicroAmount(1500000);
$cpcBid->setBid($money);
$biddingStrategyConfiguration->setBids([$cpcBid]);
$criterion->setBiddingStrategyConfiguration($biddingStrategyConfiguration);
$operation = new AdGroupCriterionOperation();
$operation->setOperand($criterion);
$operation->setOperator(Operator::ADD);
// Create ad group criterion on the server and print out some information.
$result = $adGroupCriterionService->mutate([$operation]);
$criterion = $result->getValue()[0];
printf(
"Web page criterion with ID %d and status '%s' was created.\n",
$criterion->getCriterion()->getId(),
$criterion->getUserStatus()
);
} | [
"private",
"static",
"function",
"addDsaTargeting",
"(",
"AdWordsServices",
"$",
"adWordsServices",
",",
"AdWordsSession",
"$",
"session",
",",
"$",
"adGroupId",
",",
"$",
"dsaPageUrlLabel",
")",
"{",
"$",
"adGroupCriterionService",
"=",
"$",
"adWordsServices",
"->",
"get",
"(",
"$",
"session",
",",
"AdGroupCriterionService",
"::",
"class",
")",
";",
"// Create a webpage criterion.",
"$",
"webpage",
"=",
"new",
"Webpage",
"(",
")",
";",
"$",
"parameter",
"=",
"new",
"WebpageParameter",
"(",
")",
";",
"$",
"parameter",
"->",
"setCriterionName",
"(",
"'Test criterion'",
")",
";",
"$",
"webpage",
"->",
"setParameter",
"(",
"$",
"parameter",
")",
";",
"// Add a condition for label=specified_label_name.",
"$",
"condition",
"=",
"new",
"WebpageCondition",
"(",
")",
";",
"$",
"condition",
"->",
"setOperand",
"(",
"WebpageConditionOperand",
"::",
"CUSTOM_LABEL",
")",
";",
"$",
"condition",
"->",
"setArgument",
"(",
"$",
"dsaPageUrlLabel",
")",
";",
"$",
"parameter",
"->",
"setConditions",
"(",
"[",
"$",
"condition",
"]",
")",
";",
"$",
"criterion",
"=",
"new",
"BiddableAdGroupCriterion",
"(",
")",
";",
"$",
"criterion",
"->",
"setAdGroupId",
"(",
"$",
"adGroupId",
")",
";",
"$",
"criterion",
"->",
"setCriterion",
"(",
"$",
"webpage",
")",
";",
"// Set a custom bid for this criterion.",
"$",
"biddingStrategyConfiguration",
"=",
"new",
"BiddingStrategyConfiguration",
"(",
")",
";",
"$",
"cpcBid",
"=",
"new",
"CpcBid",
"(",
")",
";",
"$",
"money",
"=",
"new",
"Money",
"(",
")",
";",
"$",
"money",
"->",
"setMicroAmount",
"(",
"1500000",
")",
";",
"$",
"cpcBid",
"->",
"setBid",
"(",
"$",
"money",
")",
";",
"$",
"biddingStrategyConfiguration",
"->",
"setBids",
"(",
"[",
"$",
"cpcBid",
"]",
")",
";",
"$",
"criterion",
"->",
"setBiddingStrategyConfiguration",
"(",
"$",
"biddingStrategyConfiguration",
")",
";",
"$",
"operation",
"=",
"new",
"AdGroupCriterionOperation",
"(",
")",
";",
"$",
"operation",
"->",
"setOperand",
"(",
"$",
"criterion",
")",
";",
"$",
"operation",
"->",
"setOperator",
"(",
"Operator",
"::",
"ADD",
")",
";",
"// Create ad group criterion on the server and print out some information.",
"$",
"result",
"=",
"$",
"adGroupCriterionService",
"->",
"mutate",
"(",
"[",
"$",
"operation",
"]",
")",
";",
"$",
"criterion",
"=",
"$",
"result",
"->",
"getValue",
"(",
")",
"[",
"0",
"]",
";",
"printf",
"(",
"\"Web page criterion with ID %d and status '%s' was created.\\n\"",
",",
"$",
"criterion",
"->",
"getCriterion",
"(",
")",
"->",
"getId",
"(",
")",
",",
"$",
"criterion",
"->",
"getUserStatus",
"(",
")",
")",
";",
"}"
] | Sets custom targeting for the page feed URLs based on a list of labels. | [
"Sets",
"custom",
"targeting",
"for",
"the",
"page",
"feed",
"URLs",
"based",
"on",
"a",
"list",
"of",
"labels",
"."
] | d552b800ad53c400b1a50c7852e7ad184245d2ea | https://github.com/googleads/googleads-php-lib/blob/d552b800ad53c400b1a50c7852e7ad184245d2ea/examples/AdWords/v201809/AdvancedOperations/AddDynamicPageFeed.php#L375-L423 | train |
googleads/googleads-php-lib | examples/AdWords/v201809/Reporting/ParallelReportDownload.php | ParallelReportDownload.getAllManagedCustomerIds | private static function getAllManagedCustomerIds(
AdWordsServices $adWordsServices,
AdWordsSession $session
) {
$managedCustomerService = $adWordsServices->get($session, ManagedCustomerService::class);
$selector = new Selector();
$selector->setFields(['CustomerId']);
$selector->setPaging(new Paging(0, self::PAGE_LIMIT));
$selector->setPredicates(
[
new Predicate(
'CanManageClients',
PredicateOperator::EQUALS,
['false']
)
]
);
$customerIds = [];
$totalNumEntries = 0;
do {
$page = $managedCustomerService->get($selector);
if ($page->getEntries() !== null) {
$totalNumEntries = $page->getTotalNumEntries();
foreach ($page->getEntries() as $customer) {
$customerIds[] = $customer->getCustomerId();
}
}
$selector->getPaging()->setStartIndex(
$selector->getPaging()->getStartIndex() + self::PAGE_LIMIT
);
} while ($selector->getPaging()->getStartIndex() < $totalNumEntries);
return $customerIds;
} | php | private static function getAllManagedCustomerIds(
AdWordsServices $adWordsServices,
AdWordsSession $session
) {
$managedCustomerService = $adWordsServices->get($session, ManagedCustomerService::class);
$selector = new Selector();
$selector->setFields(['CustomerId']);
$selector->setPaging(new Paging(0, self::PAGE_LIMIT));
$selector->setPredicates(
[
new Predicate(
'CanManageClients',
PredicateOperator::EQUALS,
['false']
)
]
);
$customerIds = [];
$totalNumEntries = 0;
do {
$page = $managedCustomerService->get($selector);
if ($page->getEntries() !== null) {
$totalNumEntries = $page->getTotalNumEntries();
foreach ($page->getEntries() as $customer) {
$customerIds[] = $customer->getCustomerId();
}
}
$selector->getPaging()->setStartIndex(
$selector->getPaging()->getStartIndex() + self::PAGE_LIMIT
);
} while ($selector->getPaging()->getStartIndex() < $totalNumEntries);
return $customerIds;
} | [
"private",
"static",
"function",
"getAllManagedCustomerIds",
"(",
"AdWordsServices",
"$",
"adWordsServices",
",",
"AdWordsSession",
"$",
"session",
")",
"{",
"$",
"managedCustomerService",
"=",
"$",
"adWordsServices",
"->",
"get",
"(",
"$",
"session",
",",
"ManagedCustomerService",
"::",
"class",
")",
";",
"$",
"selector",
"=",
"new",
"Selector",
"(",
")",
";",
"$",
"selector",
"->",
"setFields",
"(",
"[",
"'CustomerId'",
"]",
")",
";",
"$",
"selector",
"->",
"setPaging",
"(",
"new",
"Paging",
"(",
"0",
",",
"self",
"::",
"PAGE_LIMIT",
")",
")",
";",
"$",
"selector",
"->",
"setPredicates",
"(",
"[",
"new",
"Predicate",
"(",
"'CanManageClients'",
",",
"PredicateOperator",
"::",
"EQUALS",
",",
"[",
"'false'",
"]",
")",
"]",
")",
";",
"$",
"customerIds",
"=",
"[",
"]",
";",
"$",
"totalNumEntries",
"=",
"0",
";",
"do",
"{",
"$",
"page",
"=",
"$",
"managedCustomerService",
"->",
"get",
"(",
"$",
"selector",
")",
";",
"if",
"(",
"$",
"page",
"->",
"getEntries",
"(",
")",
"!==",
"null",
")",
"{",
"$",
"totalNumEntries",
"=",
"$",
"page",
"->",
"getTotalNumEntries",
"(",
")",
";",
"foreach",
"(",
"$",
"page",
"->",
"getEntries",
"(",
")",
"as",
"$",
"customer",
")",
"{",
"$",
"customerIds",
"[",
"]",
"=",
"$",
"customer",
"->",
"getCustomerId",
"(",
")",
";",
"}",
"}",
"$",
"selector",
"->",
"getPaging",
"(",
")",
"->",
"setStartIndex",
"(",
"$",
"selector",
"->",
"getPaging",
"(",
")",
"->",
"getStartIndex",
"(",
")",
"+",
"self",
"::",
"PAGE_LIMIT",
")",
";",
"}",
"while",
"(",
"$",
"selector",
"->",
"getPaging",
"(",
")",
"->",
"getStartIndex",
"(",
")",
"<",
"$",
"totalNumEntries",
")",
";",
"return",
"$",
"customerIds",
";",
"}"
] | Retrieves all the customer IDs under a manager account.
To set clientCustomerId to any manager account you want to get
reports for its client accounts, use `AdWordsSessionBuilder` to
create new session. | [
"Retrieves",
"all",
"the",
"customer",
"IDs",
"under",
"a",
"manager",
"account",
"."
] | d552b800ad53c400b1a50c7852e7ad184245d2ea | https://github.com/googleads/googleads-php-lib/blob/d552b800ad53c400b1a50c7852e7ad184245d2ea/examples/AdWords/v201809/Reporting/ParallelReportDownload.php#L179-L214 | train |
googleads/googleads-php-lib | src/Google/AdsApi/Common/SoapLogMessageFormatter.php | SoapLogMessageFormatter.formatDetailed | public function formatDetailed(
$requestHeaders,
$request,
$responseHeaders,
$response
) {
$requestHeaders = LogMessageScrubbers::scrubRequestHttpHeaders(
trim($requestHeaders),
$this->requestHttpHeadersToScrub
);
$request = LogMessageScrubbers::scrubRequestSoapHeaders(
$request,
$this->requestSoapHeadersToScrub
);
$request = LogMessageScrubbers::scrubRequestSoapBodyTags(
$request,
$this->requestSoapBodyTagsToScrub
);
$responseHeaders = trim($responseHeaders);
return sprintf(
"%s\n\n%s\n%s\n\n%s\n",
$requestHeaders,
$request,
$responseHeaders,
$response
);
} | php | public function formatDetailed(
$requestHeaders,
$request,
$responseHeaders,
$response
) {
$requestHeaders = LogMessageScrubbers::scrubRequestHttpHeaders(
trim($requestHeaders),
$this->requestHttpHeadersToScrub
);
$request = LogMessageScrubbers::scrubRequestSoapHeaders(
$request,
$this->requestSoapHeadersToScrub
);
$request = LogMessageScrubbers::scrubRequestSoapBodyTags(
$request,
$this->requestSoapBodyTagsToScrub
);
$responseHeaders = trim($responseHeaders);
return sprintf(
"%s\n\n%s\n%s\n\n%s\n",
$requestHeaders,
$request,
$responseHeaders,
$response
);
} | [
"public",
"function",
"formatDetailed",
"(",
"$",
"requestHeaders",
",",
"$",
"request",
",",
"$",
"responseHeaders",
",",
"$",
"response",
")",
"{",
"$",
"requestHeaders",
"=",
"LogMessageScrubbers",
"::",
"scrubRequestHttpHeaders",
"(",
"trim",
"(",
"$",
"requestHeaders",
")",
",",
"$",
"this",
"->",
"requestHttpHeadersToScrub",
")",
";",
"$",
"request",
"=",
"LogMessageScrubbers",
"::",
"scrubRequestSoapHeaders",
"(",
"$",
"request",
",",
"$",
"this",
"->",
"requestSoapHeadersToScrub",
")",
";",
"$",
"request",
"=",
"LogMessageScrubbers",
"::",
"scrubRequestSoapBodyTags",
"(",
"$",
"request",
",",
"$",
"this",
"->",
"requestSoapBodyTagsToScrub",
")",
";",
"$",
"responseHeaders",
"=",
"trim",
"(",
"$",
"responseHeaders",
")",
";",
"return",
"sprintf",
"(",
"\"%s\\n\\n%s\\n%s\\n\\n%s\\n\"",
",",
"$",
"requestHeaders",
",",
"$",
"request",
",",
"$",
"responseHeaders",
",",
"$",
"response",
")",
";",
"}"
] | Formats this log message as a detailed message containing full SOAP XML
request and response payloads, along with their HTTP headers.
@param string $requestHeaders the HTTP headers from the request
@param string $request the SOAP request
@param string $responseHeaders the HTTP headers from the response
@param string $response the SOAP response for the request
@return string the formatted detailed log message | [
"Formats",
"this",
"log",
"message",
"as",
"a",
"detailed",
"message",
"containing",
"full",
"SOAP",
"XML",
"request",
"and",
"response",
"payloads",
"along",
"with",
"their",
"HTTP",
"headers",
"."
] | d552b800ad53c400b1a50c7852e7ad184245d2ea | https://github.com/googleads/googleads-php-lib/blob/d552b800ad53c400b1a50c7852e7ad184245d2ea/src/Google/AdsApi/Common/SoapLogMessageFormatter.php#L138-L165 | train |
googleads/googleads-php-lib | src/Google/AdsApi/Common/SoapLogMessageFormatter.php | SoapLogMessageFormatter.formatSoapFaultForSummary | private function formatSoapFaultForSummary($soapFault)
{
$soapFault = str_replace(["\r\n", "\n", "\r"], '', $soapFault);
if (mb_strlen($soapFault, 'UTF-8') > $this->faultMsgMaxLength) {
$soapFault = mb_substr($soapFault, 0, $this->faultMsgMaxLength, 'UTF-8') . '...';
};
return $soapFault;
} | php | private function formatSoapFaultForSummary($soapFault)
{
$soapFault = str_replace(["\r\n", "\n", "\r"], '', $soapFault);
if (mb_strlen($soapFault, 'UTF-8') > $this->faultMsgMaxLength) {
$soapFault = mb_substr($soapFault, 0, $this->faultMsgMaxLength, 'UTF-8') . '...';
};
return $soapFault;
} | [
"private",
"function",
"formatSoapFaultForSummary",
"(",
"$",
"soapFault",
")",
"{",
"$",
"soapFault",
"=",
"str_replace",
"(",
"[",
"\"\\r\\n\"",
",",
"\"\\n\"",
",",
"\"\\r\"",
"]",
",",
"''",
",",
"$",
"soapFault",
")",
";",
"if",
"(",
"mb_strlen",
"(",
"$",
"soapFault",
",",
"'UTF-8'",
")",
">",
"$",
"this",
"->",
"faultMsgMaxLength",
")",
"{",
"$",
"soapFault",
"=",
"mb_substr",
"(",
"$",
"soapFault",
",",
"0",
",",
"$",
"this",
"->",
"faultMsgMaxLength",
",",
"'UTF-8'",
")",
".",
"'...'",
";",
"}",
";",
"return",
"$",
"soapFault",
";",
"}"
] | Removes line breaks and truncates the SOAP fault if necessary.
@param string $soapFault
@return string | [
"Removes",
"line",
"breaks",
"and",
"truncates",
"the",
"SOAP",
"fault",
"if",
"necessary",
"."
] | d552b800ad53c400b1a50c7852e7ad184245d2ea | https://github.com/googleads/googleads-php-lib/blob/d552b800ad53c400b1a50c7852e7ad184245d2ea/src/Google/AdsApi/Common/SoapLogMessageFormatter.php#L173-L181 | train |
googleads/googleads-php-lib | src/Google/AdsApi/Common/Util/Reflection.php | Reflection.createInstance | public function createInstance($className, $args = null)
{
$reflectionClass = new ReflectionClass($className);
$args = func_get_args();
array_shift($args);
return $reflectionClass->newInstanceArgs($args);
} | php | public function createInstance($className, $args = null)
{
$reflectionClass = new ReflectionClass($className);
$args = func_get_args();
array_shift($args);
return $reflectionClass->newInstanceArgs($args);
} | [
"public",
"function",
"createInstance",
"(",
"$",
"className",
",",
"$",
"args",
"=",
"null",
")",
"{",
"$",
"reflectionClass",
"=",
"new",
"ReflectionClass",
"(",
"$",
"className",
")",
";",
"$",
"args",
"=",
"func_get_args",
"(",
")",
";",
"array_shift",
"(",
"$",
"args",
")",
";",
"return",
"$",
"reflectionClass",
"->",
"newInstanceArgs",
"(",
"$",
"args",
")",
";",
"}"
] | Creates a new instance of the specified class name.
@param string $className the fully qualified class name
@param mixed $args a variable number of arguments to pass to the class
constructor
@return mixed the created object instance
@throws \ReflectionException if the object instance could not be created | [
"Creates",
"a",
"new",
"instance",
"of",
"the",
"specified",
"class",
"name",
"."
] | d552b800ad53c400b1a50c7852e7ad184245d2ea | https://github.com/googleads/googleads-php-lib/blob/d552b800ad53c400b1a50c7852e7ad184245d2ea/src/Google/AdsApi/Common/Util/Reflection.php#L37-L44 | train |
googleads/googleads-php-lib | examples/AdWords/v201809/AdvancedOperations/AddShoppingDynamicRemarketingCampaign.php | AddShoppingDynamicRemarketingCampaign.createAdGroup | private static function createAdGroup(
AdWordsServices $adWordsServices,
AdWordsSession $session,
Campaign $campaign
) {
$adGroupService =
$adWordsServices->get($session, AdGroupService::class);
// Creates ad group.
$adGroup = new AdGroup();
$adGroup->setCampaignId($campaign->getId());
$adGroup->setName('Dynamic remarketing ad group #' . uniqid());
$adGroup->setStatus(AdGroupStatus::ENABLED);
// Creates operation.
$adGroupOperation = new AdGroupOperation();
$adGroupOperation->setOperand($adGroup);
$adGroupOperation->setOperator(Operator::ADD);
// Makes the mutate request.
$adGroupAddResult = $adGroupService->mutate([$adGroupOperation]);
$adGroup = $adGroupAddResult->getValue()[0];
return $adGroup;
} | php | private static function createAdGroup(
AdWordsServices $adWordsServices,
AdWordsSession $session,
Campaign $campaign
) {
$adGroupService =
$adWordsServices->get($session, AdGroupService::class);
// Creates ad group.
$adGroup = new AdGroup();
$adGroup->setCampaignId($campaign->getId());
$adGroup->setName('Dynamic remarketing ad group #' . uniqid());
$adGroup->setStatus(AdGroupStatus::ENABLED);
// Creates operation.
$adGroupOperation = new AdGroupOperation();
$adGroupOperation->setOperand($adGroup);
$adGroupOperation->setOperator(Operator::ADD);
// Makes the mutate request.
$adGroupAddResult = $adGroupService->mutate([$adGroupOperation]);
$adGroup = $adGroupAddResult->getValue()[0];
return $adGroup;
} | [
"private",
"static",
"function",
"createAdGroup",
"(",
"AdWordsServices",
"$",
"adWordsServices",
",",
"AdWordsSession",
"$",
"session",
",",
"Campaign",
"$",
"campaign",
")",
"{",
"$",
"adGroupService",
"=",
"$",
"adWordsServices",
"->",
"get",
"(",
"$",
"session",
",",
"AdGroupService",
"::",
"class",
")",
";",
"// Creates ad group.",
"$",
"adGroup",
"=",
"new",
"AdGroup",
"(",
")",
";",
"$",
"adGroup",
"->",
"setCampaignId",
"(",
"$",
"campaign",
"->",
"getId",
"(",
")",
")",
";",
"$",
"adGroup",
"->",
"setName",
"(",
"'Dynamic remarketing ad group #'",
".",
"uniqid",
"(",
")",
")",
";",
"$",
"adGroup",
"->",
"setStatus",
"(",
"AdGroupStatus",
"::",
"ENABLED",
")",
";",
"// Creates operation.",
"$",
"adGroupOperation",
"=",
"new",
"AdGroupOperation",
"(",
")",
";",
"$",
"adGroupOperation",
"->",
"setOperand",
"(",
"$",
"adGroup",
")",
";",
"$",
"adGroupOperation",
"->",
"setOperator",
"(",
"Operator",
"::",
"ADD",
")",
";",
"// Makes the mutate request.",
"$",
"adGroupAddResult",
"=",
"$",
"adGroupService",
"->",
"mutate",
"(",
"[",
"$",
"adGroupOperation",
"]",
")",
";",
"$",
"adGroup",
"=",
"$",
"adGroupAddResult",
"->",
"getValue",
"(",
")",
"[",
"0",
"]",
";",
"return",
"$",
"adGroup",
";",
"}"
] | Creates an ad group in the specified campaign.
@param AdWordsServices $adWordsServices the AdWords services
@param AdWordsSession $session the AdWords session
@param Campaign $campaign the campaign to which the ad group should be
attached
@return AdGroup the created ad group | [
"Creates",
"an",
"ad",
"group",
"in",
"the",
"specified",
"campaign",
"."
] | d552b800ad53c400b1a50c7852e7ad184245d2ea | https://github.com/googleads/googleads-php-lib/blob/d552b800ad53c400b1a50c7852e7ad184245d2ea/examples/AdWords/v201809/AdvancedOperations/AddShoppingDynamicRemarketingCampaign.php#L207-L231 | train |
googleads/googleads-php-lib | examples/AdWords/v201809/AdvancedOperations/AddShoppingDynamicRemarketingCampaign.php | AddShoppingDynamicRemarketingCampaign.attachUserList | private static function attachUserList(
AdWordsServices $adWordsServices,
AdWordsSession $session,
AdGroup $adGroup,
$userListId
) {
$adGroupCriterionService =
$adWordsServices->get($session, AdGroupCriterionService::class);
// Creates criterion user list.
$userList = new CriterionUserList();
$userList->setUserListId($userListId);
// Creates ad group criterion.
$adGroupCriterion = new BiddableAdGroupCriterion();
$adGroupCriterion->setCriterion($userList);
$adGroupCriterion->setAdGroupId($adGroup->getId());
// Creates operation.
$adGroupCriterionOperation = new AdGroupCriterionOperation();
$adGroupCriterionOperation->setOperand($adGroupCriterion);
$adGroupCriterionOperation->setOperator(Operator::ADD);
// Makes the mutate request.
$adGroupCriterionAddResult =
$adGroupCriterionService->mutate([$adGroupCriterionOperation]);
$adGroupCriterion = $adGroupCriterionAddResult->getValue()[0];
return $adGroupCriterion;
} | php | private static function attachUserList(
AdWordsServices $adWordsServices,
AdWordsSession $session,
AdGroup $adGroup,
$userListId
) {
$adGroupCriterionService =
$adWordsServices->get($session, AdGroupCriterionService::class);
// Creates criterion user list.
$userList = new CriterionUserList();
$userList->setUserListId($userListId);
// Creates ad group criterion.
$adGroupCriterion = new BiddableAdGroupCriterion();
$adGroupCriterion->setCriterion($userList);
$adGroupCriterion->setAdGroupId($adGroup->getId());
// Creates operation.
$adGroupCriterionOperation = new AdGroupCriterionOperation();
$adGroupCriterionOperation->setOperand($adGroupCriterion);
$adGroupCriterionOperation->setOperator(Operator::ADD);
// Makes the mutate request.
$adGroupCriterionAddResult =
$adGroupCriterionService->mutate([$adGroupCriterionOperation]);
$adGroupCriterion = $adGroupCriterionAddResult->getValue()[0];
return $adGroupCriterion;
} | [
"private",
"static",
"function",
"attachUserList",
"(",
"AdWordsServices",
"$",
"adWordsServices",
",",
"AdWordsSession",
"$",
"session",
",",
"AdGroup",
"$",
"adGroup",
",",
"$",
"userListId",
")",
"{",
"$",
"adGroupCriterionService",
"=",
"$",
"adWordsServices",
"->",
"get",
"(",
"$",
"session",
",",
"AdGroupCriterionService",
"::",
"class",
")",
";",
"// Creates criterion user list.",
"$",
"userList",
"=",
"new",
"CriterionUserList",
"(",
")",
";",
"$",
"userList",
"->",
"setUserListId",
"(",
"$",
"userListId",
")",
";",
"// Creates ad group criterion.",
"$",
"adGroupCriterion",
"=",
"new",
"BiddableAdGroupCriterion",
"(",
")",
";",
"$",
"adGroupCriterion",
"->",
"setCriterion",
"(",
"$",
"userList",
")",
";",
"$",
"adGroupCriterion",
"->",
"setAdGroupId",
"(",
"$",
"adGroup",
"->",
"getId",
"(",
")",
")",
";",
"// Creates operation.",
"$",
"adGroupCriterionOperation",
"=",
"new",
"AdGroupCriterionOperation",
"(",
")",
";",
"$",
"adGroupCriterionOperation",
"->",
"setOperand",
"(",
"$",
"adGroupCriterion",
")",
";",
"$",
"adGroupCriterionOperation",
"->",
"setOperator",
"(",
"Operator",
"::",
"ADD",
")",
";",
"// Makes the mutate request.",
"$",
"adGroupCriterionAddResult",
"=",
"$",
"adGroupCriterionService",
"->",
"mutate",
"(",
"[",
"$",
"adGroupCriterionOperation",
"]",
")",
";",
"$",
"adGroupCriterion",
"=",
"$",
"adGroupCriterionAddResult",
"->",
"getValue",
"(",
")",
"[",
"0",
"]",
";",
"return",
"$",
"adGroupCriterion",
";",
"}"
] | Attaches a user list to an ad group. The user list provides positive
targeting and feed information to drive the dynamic content of the ad.
<p>Note: User lists are only supported at the ad group level for
positive targeting in dynamic remarketing campaigns.
@param AdWordsServices $adWordsServices the AdWords services
@param AdWordsSession $session the AdWords session
@param AdGroup $adGroup the ad group to attach the user list used for
dynamic feed content
@param int $userListId the user list ID to use for targeting and dynamic
content.
@return BiddableAdGroupCriterion the attached ad group criterion | [
"Attaches",
"a",
"user",
"list",
"to",
"an",
"ad",
"group",
".",
"The",
"user",
"list",
"provides",
"positive",
"targeting",
"and",
"feed",
"information",
"to",
"drive",
"the",
"dynamic",
"content",
"of",
"the",
"ad",
"."
] | d552b800ad53c400b1a50c7852e7ad184245d2ea | https://github.com/googleads/googleads-php-lib/blob/d552b800ad53c400b1a50c7852e7ad184245d2ea/examples/AdWords/v201809/AdvancedOperations/AddShoppingDynamicRemarketingCampaign.php#L248-L277 | train |
googleads/googleads-php-lib | examples/AdWords/v201809/AdvancedOperations/AddShoppingDynamicRemarketingCampaign.php | AddShoppingDynamicRemarketingCampaign.createAd | private static function createAd(
AdWordsServices $adWordsServices,
AdWordsSession $session,
AdGroup $adGroup
) {
$adGroupAdService =
$adWordsServices->get($session, AdGroupAdService::class);
$responsiveDisplayAd = new ResponsiveDisplayAd();
// This ad format does not allow the creation of an image using the
// Image.data field. An image must first be created using the
// MediaService and Image.mediaId must be populated when creating the
// ad.
$marketingImage = self::uploadImage(
$adWordsServices,
$session,
'https://goo.gl/3b9Wfh'
);
$responsiveDisplayAd->setMarketingImage($marketingImage);
$responsiveDisplayAd->setShortHeadline('Travel');
$responsiveDisplayAd->setLongHeadline('Travel the World.');
$responsiveDisplayAd->setDescription('Take to the air!');
$responsiveDisplayAd->setBusinessName('Interplanetary Cruises');
$responsiveDisplayAd->setFinalUrls(['http://www.example.com']);
// Optional: Set the call-to-action text.
// Valid texts: https://support.google.com/adwords/answer/7005917.
$responsiveDisplayAd->setCallToActionText('Apply Now');
// Optional: Set dynamic display ad settings, composed of landscape logo
// image, promotion text, and price prefix.
$dynamicDisplayAdSettings =
self::createDynamicDisplayAdSettings($adWordsServices, $session);
$responsiveDisplayAd->setDynamicDisplayAdSettings(
$dynamicDisplayAdSettings
);
// Optional: Creates a square marketing image using MediaService, and
// set it to the ad.
$squareMarketingImage = self::uploadImage(
$adWordsServices,
$session,
'https://goo.gl/mtt54n'
);
$responsiveDisplayAd->setSquareMarketingImage($squareMarketingImage);
// Optional: Set the logo image.
$logoImage = self::uploadImage(
$adWordsServices,
$session,
'https://goo.gl/mtt54n'
);
$responsiveDisplayAd->setLogoImage($logoImage);
// Whitelisted accounts only: Set color settings using hexadecimal
// values. Set allowFlexibleColor to false if you want your ads to
// render by always using your colors strictly.
/*
$responsiveDisplayAd->setMainColor('#0000ff');
$responsiveDisplayAd->setAccentColor('#ffff00');
$responsiveDisplayAd->setFlexibleColor(false);
*/
// Whitelisted accounts only: Set the format setting that the ad will be
// served in.
/*
$responsiveDisplayAd->setFormatSetting(
\Google\AdsApi\AdWords\v201809\cm\DisplayAdFormatSetting::NON_NATIVE
);
*/
// Creates ad group ad.
$adGroupAd = new AdGroupAd();
$adGroupAd->setAdGroupId($adGroup->getId());
$adGroupAd->setAd($responsiveDisplayAd);
// Create an ad group ad operation.
$adGroupAdOperation = new AdGroupAdOperation();
$adGroupAdOperation->setOperand($adGroupAd);
$adGroupAdOperation->setOperator(Operator::ADD);
// Creates an ad group ad on the server.
$adGroupAdAddResult = $adGroupAdService->mutate([$adGroupAdOperation]);
$adGroupAd = $adGroupAdAddResult->getValue()[0];
return $adGroupAd;
} | php | private static function createAd(
AdWordsServices $adWordsServices,
AdWordsSession $session,
AdGroup $adGroup
) {
$adGroupAdService =
$adWordsServices->get($session, AdGroupAdService::class);
$responsiveDisplayAd = new ResponsiveDisplayAd();
// This ad format does not allow the creation of an image using the
// Image.data field. An image must first be created using the
// MediaService and Image.mediaId must be populated when creating the
// ad.
$marketingImage = self::uploadImage(
$adWordsServices,
$session,
'https://goo.gl/3b9Wfh'
);
$responsiveDisplayAd->setMarketingImage($marketingImage);
$responsiveDisplayAd->setShortHeadline('Travel');
$responsiveDisplayAd->setLongHeadline('Travel the World.');
$responsiveDisplayAd->setDescription('Take to the air!');
$responsiveDisplayAd->setBusinessName('Interplanetary Cruises');
$responsiveDisplayAd->setFinalUrls(['http://www.example.com']);
// Optional: Set the call-to-action text.
// Valid texts: https://support.google.com/adwords/answer/7005917.
$responsiveDisplayAd->setCallToActionText('Apply Now');
// Optional: Set dynamic display ad settings, composed of landscape logo
// image, promotion text, and price prefix.
$dynamicDisplayAdSettings =
self::createDynamicDisplayAdSettings($adWordsServices, $session);
$responsiveDisplayAd->setDynamicDisplayAdSettings(
$dynamicDisplayAdSettings
);
// Optional: Creates a square marketing image using MediaService, and
// set it to the ad.
$squareMarketingImage = self::uploadImage(
$adWordsServices,
$session,
'https://goo.gl/mtt54n'
);
$responsiveDisplayAd->setSquareMarketingImage($squareMarketingImage);
// Optional: Set the logo image.
$logoImage = self::uploadImage(
$adWordsServices,
$session,
'https://goo.gl/mtt54n'
);
$responsiveDisplayAd->setLogoImage($logoImage);
// Whitelisted accounts only: Set color settings using hexadecimal
// values. Set allowFlexibleColor to false if you want your ads to
// render by always using your colors strictly.
/*
$responsiveDisplayAd->setMainColor('#0000ff');
$responsiveDisplayAd->setAccentColor('#ffff00');
$responsiveDisplayAd->setFlexibleColor(false);
*/
// Whitelisted accounts only: Set the format setting that the ad will be
// served in.
/*
$responsiveDisplayAd->setFormatSetting(
\Google\AdsApi\AdWords\v201809\cm\DisplayAdFormatSetting::NON_NATIVE
);
*/
// Creates ad group ad.
$adGroupAd = new AdGroupAd();
$adGroupAd->setAdGroupId($adGroup->getId());
$adGroupAd->setAd($responsiveDisplayAd);
// Create an ad group ad operation.
$adGroupAdOperation = new AdGroupAdOperation();
$adGroupAdOperation->setOperand($adGroupAd);
$adGroupAdOperation->setOperator(Operator::ADD);
// Creates an ad group ad on the server.
$adGroupAdAddResult = $adGroupAdService->mutate([$adGroupAdOperation]);
$adGroupAd = $adGroupAdAddResult->getValue()[0];
return $adGroupAd;
} | [
"private",
"static",
"function",
"createAd",
"(",
"AdWordsServices",
"$",
"adWordsServices",
",",
"AdWordsSession",
"$",
"session",
",",
"AdGroup",
"$",
"adGroup",
")",
"{",
"$",
"adGroupAdService",
"=",
"$",
"adWordsServices",
"->",
"get",
"(",
"$",
"session",
",",
"AdGroupAdService",
"::",
"class",
")",
";",
"$",
"responsiveDisplayAd",
"=",
"new",
"ResponsiveDisplayAd",
"(",
")",
";",
"// This ad format does not allow the creation of an image using the",
"// Image.data field. An image must first be created using the",
"// MediaService and Image.mediaId must be populated when creating the",
"// ad.",
"$",
"marketingImage",
"=",
"self",
"::",
"uploadImage",
"(",
"$",
"adWordsServices",
",",
"$",
"session",
",",
"'https://goo.gl/3b9Wfh'",
")",
";",
"$",
"responsiveDisplayAd",
"->",
"setMarketingImage",
"(",
"$",
"marketingImage",
")",
";",
"$",
"responsiveDisplayAd",
"->",
"setShortHeadline",
"(",
"'Travel'",
")",
";",
"$",
"responsiveDisplayAd",
"->",
"setLongHeadline",
"(",
"'Travel the World.'",
")",
";",
"$",
"responsiveDisplayAd",
"->",
"setDescription",
"(",
"'Take to the air!'",
")",
";",
"$",
"responsiveDisplayAd",
"->",
"setBusinessName",
"(",
"'Interplanetary Cruises'",
")",
";",
"$",
"responsiveDisplayAd",
"->",
"setFinalUrls",
"(",
"[",
"'http://www.example.com'",
"]",
")",
";",
"// Optional: Set the call-to-action text.",
"// Valid texts: https://support.google.com/adwords/answer/7005917.",
"$",
"responsiveDisplayAd",
"->",
"setCallToActionText",
"(",
"'Apply Now'",
")",
";",
"// Optional: Set dynamic display ad settings, composed of landscape logo",
"// image, promotion text, and price prefix.",
"$",
"dynamicDisplayAdSettings",
"=",
"self",
"::",
"createDynamicDisplayAdSettings",
"(",
"$",
"adWordsServices",
",",
"$",
"session",
")",
";",
"$",
"responsiveDisplayAd",
"->",
"setDynamicDisplayAdSettings",
"(",
"$",
"dynamicDisplayAdSettings",
")",
";",
"// Optional: Creates a square marketing image using MediaService, and",
"// set it to the ad.",
"$",
"squareMarketingImage",
"=",
"self",
"::",
"uploadImage",
"(",
"$",
"adWordsServices",
",",
"$",
"session",
",",
"'https://goo.gl/mtt54n'",
")",
";",
"$",
"responsiveDisplayAd",
"->",
"setSquareMarketingImage",
"(",
"$",
"squareMarketingImage",
")",
";",
"// Optional: Set the logo image.",
"$",
"logoImage",
"=",
"self",
"::",
"uploadImage",
"(",
"$",
"adWordsServices",
",",
"$",
"session",
",",
"'https://goo.gl/mtt54n'",
")",
";",
"$",
"responsiveDisplayAd",
"->",
"setLogoImage",
"(",
"$",
"logoImage",
")",
";",
"// Whitelisted accounts only: Set color settings using hexadecimal",
"// values. Set allowFlexibleColor to false if you want your ads to",
"// render by always using your colors strictly.",
"/*\n $responsiveDisplayAd->setMainColor('#0000ff');\n $responsiveDisplayAd->setAccentColor('#ffff00');\n $responsiveDisplayAd->setFlexibleColor(false);\n */",
"// Whitelisted accounts only: Set the format setting that the ad will be",
"// served in.",
"/*\n $responsiveDisplayAd->setFormatSetting(\n \\Google\\AdsApi\\AdWords\\v201809\\cm\\DisplayAdFormatSetting::NON_NATIVE\n );\n */",
"// Creates ad group ad.",
"$",
"adGroupAd",
"=",
"new",
"AdGroupAd",
"(",
")",
";",
"$",
"adGroupAd",
"->",
"setAdGroupId",
"(",
"$",
"adGroup",
"->",
"getId",
"(",
")",
")",
";",
"$",
"adGroupAd",
"->",
"setAd",
"(",
"$",
"responsiveDisplayAd",
")",
";",
"// Create an ad group ad operation.",
"$",
"adGroupAdOperation",
"=",
"new",
"AdGroupAdOperation",
"(",
")",
";",
"$",
"adGroupAdOperation",
"->",
"setOperand",
"(",
"$",
"adGroupAd",
")",
";",
"$",
"adGroupAdOperation",
"->",
"setOperator",
"(",
"Operator",
"::",
"ADD",
")",
";",
"// Creates an ad group ad on the server.",
"$",
"adGroupAdAddResult",
"=",
"$",
"adGroupAdService",
"->",
"mutate",
"(",
"[",
"$",
"adGroupAdOperation",
"]",
")",
";",
"$",
"adGroupAd",
"=",
"$",
"adGroupAdAddResult",
"->",
"getValue",
"(",
")",
"[",
"0",
"]",
";",
"return",
"$",
"adGroupAd",
";",
"}"
] | Creates an ad for serving dynamic content in a remarketing campaign.
@param AdWordsServices $adWordsServices the AdWords services
@param AdWordsSession $session the AdWords session
@param AdGroup $adGroup the ad group under wich to create the ad
@return AdGroupAd the created ad group ad | [
"Creates",
"an",
"ad",
"for",
"serving",
"dynamic",
"content",
"in",
"a",
"remarketing",
"campaign",
"."
] | d552b800ad53c400b1a50c7852e7ad184245d2ea | https://github.com/googleads/googleads-php-lib/blob/d552b800ad53c400b1a50c7852e7ad184245d2ea/examples/AdWords/v201809/AdvancedOperations/AddShoppingDynamicRemarketingCampaign.php#L287-L375 | train |
googleads/googleads-php-lib | examples/AdWords/v201809/AdvancedOperations/AddShoppingDynamicRemarketingCampaign.php | AddShoppingDynamicRemarketingCampaign.createDynamicDisplayAdSettings | private static function createDynamicDisplayAdSettings(
AdWordsServices $adWordsServices,
AdWordsSession $session
) {
$landscapeLogoImage = self::uploadImage(
$adWordsServices,
$session,
'https://goo.gl/dEvQeF'
);
$dynamicSettings = new DynamicSettings();
$dynamicSettings->setLandscapeLogoImage($landscapeLogoImage);
$dynamicSettings->setPricePrefix('as low as');
$dynamicSettings->setPromoText('Free shipping!');
return $dynamicSettings;
} | php | private static function createDynamicDisplayAdSettings(
AdWordsServices $adWordsServices,
AdWordsSession $session
) {
$landscapeLogoImage = self::uploadImage(
$adWordsServices,
$session,
'https://goo.gl/dEvQeF'
);
$dynamicSettings = new DynamicSettings();
$dynamicSettings->setLandscapeLogoImage($landscapeLogoImage);
$dynamicSettings->setPricePrefix('as low as');
$dynamicSettings->setPromoText('Free shipping!');
return $dynamicSettings;
} | [
"private",
"static",
"function",
"createDynamicDisplayAdSettings",
"(",
"AdWordsServices",
"$",
"adWordsServices",
",",
"AdWordsSession",
"$",
"session",
")",
"{",
"$",
"landscapeLogoImage",
"=",
"self",
"::",
"uploadImage",
"(",
"$",
"adWordsServices",
",",
"$",
"session",
",",
"'https://goo.gl/dEvQeF'",
")",
";",
"$",
"dynamicSettings",
"=",
"new",
"DynamicSettings",
"(",
")",
";",
"$",
"dynamicSettings",
"->",
"setLandscapeLogoImage",
"(",
"$",
"landscapeLogoImage",
")",
";",
"$",
"dynamicSettings",
"->",
"setPricePrefix",
"(",
"'as low as'",
")",
";",
"$",
"dynamicSettings",
"->",
"setPromoText",
"(",
"'Free shipping!'",
")",
";",
"return",
"$",
"dynamicSettings",
";",
"}"
] | Creates dynamic display ad settings.
@param AdWordsServices $adWordsServices the AdWords services
@param AdWordsSession $session the AdWords session
@return DynamicSettings the created dynamic settings | [
"Creates",
"dynamic",
"display",
"ad",
"settings",
"."
] | d552b800ad53c400b1a50c7852e7ad184245d2ea | https://github.com/googleads/googleads-php-lib/blob/d552b800ad53c400b1a50c7852e7ad184245d2ea/examples/AdWords/v201809/AdvancedOperations/AddShoppingDynamicRemarketingCampaign.php#L410-L425 | train |
googleads/googleads-php-lib | src/Google/AdsApi/Common/GuzzleLogMessageHandler.php | GuzzleLogMessageHandler.log | public static function log(
LoggerInterface $logger,
GuzzleLogMessageFormatter $messageFormatter
) {
return function (callable $handler) use ($logger, $messageFormatter) {
return function ($request, array $options) use ($handler, $logger, $messageFormatter) {
return $handler($request, $options)->then(
function ($response) use ($request, $logger, $messageFormatter) {
// Logs messages in case of successful HTTP calls.
$logger->info(
$messageFormatter->formatSummary($request, $response)
);
// formatDetailed() can produce long log messages
// so check if it handles DEBUG level when possible.
if (!($logger instanceof Logger)
|| $logger->isHandling(Logger::DEBUG)) {
$logger->debug($messageFormatter->formatDetailed(
$request,
$response
));
}
return $response;
},
function ($reason) use ($request, $logger, $messageFormatter) {
// Logs messages in case of failing HTTP calls.
$response = is_subclass_of(
$reason,
'GuzzleHttp\Exception\RequestException'
) ? $reason->getResponse() : null;
$logger->warning(
$messageFormatter->formatSummary($request, $response)
);
// formatDetailed() can produce long log messages
// so check if it handles NOTICE level when
// possible.
if (!($logger instanceof Logger)
|| $logger->isHandling(Logger::NOTICE)) {
$logger->notice($messageFormatter->formatDetailed(
$request,
$response,
$reason
));
}
return \GuzzleHttp\Promise\rejection_for($reason);
}
);
};
};
} | php | public static function log(
LoggerInterface $logger,
GuzzleLogMessageFormatter $messageFormatter
) {
return function (callable $handler) use ($logger, $messageFormatter) {
return function ($request, array $options) use ($handler, $logger, $messageFormatter) {
return $handler($request, $options)->then(
function ($response) use ($request, $logger, $messageFormatter) {
// Logs messages in case of successful HTTP calls.
$logger->info(
$messageFormatter->formatSummary($request, $response)
);
// formatDetailed() can produce long log messages
// so check if it handles DEBUG level when possible.
if (!($logger instanceof Logger)
|| $logger->isHandling(Logger::DEBUG)) {
$logger->debug($messageFormatter->formatDetailed(
$request,
$response
));
}
return $response;
},
function ($reason) use ($request, $logger, $messageFormatter) {
// Logs messages in case of failing HTTP calls.
$response = is_subclass_of(
$reason,
'GuzzleHttp\Exception\RequestException'
) ? $reason->getResponse() : null;
$logger->warning(
$messageFormatter->formatSummary($request, $response)
);
// formatDetailed() can produce long log messages
// so check if it handles NOTICE level when
// possible.
if (!($logger instanceof Logger)
|| $logger->isHandling(Logger::NOTICE)) {
$logger->notice($messageFormatter->formatDetailed(
$request,
$response,
$reason
));
}
return \GuzzleHttp\Promise\rejection_for($reason);
}
);
};
};
} | [
"public",
"static",
"function",
"log",
"(",
"LoggerInterface",
"$",
"logger",
",",
"GuzzleLogMessageFormatter",
"$",
"messageFormatter",
")",
"{",
"return",
"function",
"(",
"callable",
"$",
"handler",
")",
"use",
"(",
"$",
"logger",
",",
"$",
"messageFormatter",
")",
"{",
"return",
"function",
"(",
"$",
"request",
",",
"array",
"$",
"options",
")",
"use",
"(",
"$",
"handler",
",",
"$",
"logger",
",",
"$",
"messageFormatter",
")",
"{",
"return",
"$",
"handler",
"(",
"$",
"request",
",",
"$",
"options",
")",
"->",
"then",
"(",
"function",
"(",
"$",
"response",
")",
"use",
"(",
"$",
"request",
",",
"$",
"logger",
",",
"$",
"messageFormatter",
")",
"{",
"// Logs messages in case of successful HTTP calls.",
"$",
"logger",
"->",
"info",
"(",
"$",
"messageFormatter",
"->",
"formatSummary",
"(",
"$",
"request",
",",
"$",
"response",
")",
")",
";",
"// formatDetailed() can produce long log messages",
"// so check if it handles DEBUG level when possible.",
"if",
"(",
"!",
"(",
"$",
"logger",
"instanceof",
"Logger",
")",
"||",
"$",
"logger",
"->",
"isHandling",
"(",
"Logger",
"::",
"DEBUG",
")",
")",
"{",
"$",
"logger",
"->",
"debug",
"(",
"$",
"messageFormatter",
"->",
"formatDetailed",
"(",
"$",
"request",
",",
"$",
"response",
")",
")",
";",
"}",
"return",
"$",
"response",
";",
"}",
",",
"function",
"(",
"$",
"reason",
")",
"use",
"(",
"$",
"request",
",",
"$",
"logger",
",",
"$",
"messageFormatter",
")",
"{",
"// Logs messages in case of failing HTTP calls.",
"$",
"response",
"=",
"is_subclass_of",
"(",
"$",
"reason",
",",
"'GuzzleHttp\\Exception\\RequestException'",
")",
"?",
"$",
"reason",
"->",
"getResponse",
"(",
")",
":",
"null",
";",
"$",
"logger",
"->",
"warning",
"(",
"$",
"messageFormatter",
"->",
"formatSummary",
"(",
"$",
"request",
",",
"$",
"response",
")",
")",
";",
"// formatDetailed() can produce long log messages",
"// so check if it handles NOTICE level when",
"// possible.",
"if",
"(",
"!",
"(",
"$",
"logger",
"instanceof",
"Logger",
")",
"||",
"$",
"logger",
"->",
"isHandling",
"(",
"Logger",
"::",
"NOTICE",
")",
")",
"{",
"$",
"logger",
"->",
"notice",
"(",
"$",
"messageFormatter",
"->",
"formatDetailed",
"(",
"$",
"request",
",",
"$",
"response",
",",
"$",
"reason",
")",
")",
";",
"}",
"return",
"\\",
"GuzzleHttp",
"\\",
"Promise",
"\\",
"rejection_for",
"(",
"$",
"reason",
")",
";",
"}",
")",
";",
"}",
";",
"}",
";",
"}"
] | Logs requests and responses for Guzzle HTTP calls to non-SOAP ads API
endpoints to the specified logger.
@param LoggerInterface $logger
@param GuzzleLogMessageFormatter $messageFormatter
@return callable a function that accepts the next handler | [
"Logs",
"requests",
"and",
"responses",
"for",
"Guzzle",
"HTTP",
"calls",
"to",
"non",
"-",
"SOAP",
"ads",
"API",
"endpoints",
"to",
"the",
"specified",
"logger",
"."
] | d552b800ad53c400b1a50c7852e7ad184245d2ea | https://github.com/googleads/googleads-php-lib/blob/d552b800ad53c400b1a50c7852e7ad184245d2ea/src/Google/AdsApi/Common/GuzzleLogMessageHandler.php#L38-L92 | train |
googleads/googleads-php-lib | examples/AdWords/v201809/Extensions/AddPrices.php | AddPrices.createPriceTableRow | private static function createPriceTableRow(
$header,
$description,
$finalUrl,
$priceInMicros,
$currencyCode,
$priceUnit,
$finalMobileUrl = null
) {
$priceTableRow = new PriceTableRow();
$priceTableRow->setHeader($header);
$priceTableRow->setDescription($description);
$priceTableRow->setFinalUrls(new UrlList([$finalUrl]));
$money = new Money();
$money->setMicroAmount($priceInMicros);
$moneyWithCurrency = new MoneyWithCurrency();
$moneyWithCurrency->setMoney($money);
$moneyWithCurrency->setCurrencyCode($currencyCode);
$priceTableRow->setPrice($moneyWithCurrency);
$priceTableRow->setPriceUnit($priceUnit);
if ($finalMobileUrl !== null) {
$priceTableRow->setFinalMobileUrls(new UrlList([$finalMobileUrl]));
}
return $priceTableRow;
} | php | private static function createPriceTableRow(
$header,
$description,
$finalUrl,
$priceInMicros,
$currencyCode,
$priceUnit,
$finalMobileUrl = null
) {
$priceTableRow = new PriceTableRow();
$priceTableRow->setHeader($header);
$priceTableRow->setDescription($description);
$priceTableRow->setFinalUrls(new UrlList([$finalUrl]));
$money = new Money();
$money->setMicroAmount($priceInMicros);
$moneyWithCurrency = new MoneyWithCurrency();
$moneyWithCurrency->setMoney($money);
$moneyWithCurrency->setCurrencyCode($currencyCode);
$priceTableRow->setPrice($moneyWithCurrency);
$priceTableRow->setPriceUnit($priceUnit);
if ($finalMobileUrl !== null) {
$priceTableRow->setFinalMobileUrls(new UrlList([$finalMobileUrl]));
}
return $priceTableRow;
} | [
"private",
"static",
"function",
"createPriceTableRow",
"(",
"$",
"header",
",",
"$",
"description",
",",
"$",
"finalUrl",
",",
"$",
"priceInMicros",
",",
"$",
"currencyCode",
",",
"$",
"priceUnit",
",",
"$",
"finalMobileUrl",
"=",
"null",
")",
"{",
"$",
"priceTableRow",
"=",
"new",
"PriceTableRow",
"(",
")",
";",
"$",
"priceTableRow",
"->",
"setHeader",
"(",
"$",
"header",
")",
";",
"$",
"priceTableRow",
"->",
"setDescription",
"(",
"$",
"description",
")",
";",
"$",
"priceTableRow",
"->",
"setFinalUrls",
"(",
"new",
"UrlList",
"(",
"[",
"$",
"finalUrl",
"]",
")",
")",
";",
"$",
"money",
"=",
"new",
"Money",
"(",
")",
";",
"$",
"money",
"->",
"setMicroAmount",
"(",
"$",
"priceInMicros",
")",
";",
"$",
"moneyWithCurrency",
"=",
"new",
"MoneyWithCurrency",
"(",
")",
";",
"$",
"moneyWithCurrency",
"->",
"setMoney",
"(",
"$",
"money",
")",
";",
"$",
"moneyWithCurrency",
"->",
"setCurrencyCode",
"(",
"$",
"currencyCode",
")",
";",
"$",
"priceTableRow",
"->",
"setPrice",
"(",
"$",
"moneyWithCurrency",
")",
";",
"$",
"priceTableRow",
"->",
"setPriceUnit",
"(",
"$",
"priceUnit",
")",
";",
"if",
"(",
"$",
"finalMobileUrl",
"!==",
"null",
")",
"{",
"$",
"priceTableRow",
"->",
"setFinalMobileUrls",
"(",
"new",
"UrlList",
"(",
"[",
"$",
"finalMobileUrl",
"]",
")",
")",
";",
"}",
"return",
"$",
"priceTableRow",
";",
"}"
] | Creates a new price table row with the specified attributes.
@param string $header the header of price table row
@param string $description the description of price table row
@param string $finalUrl the final URL of price table row
@param integer $priceInMicros the price in micro amount
@param string $currencyCode the 3-character currency code
@param string $priceUnit the unit of shown price
@param string|null $finalMobileUrl the mobile final URL of price table row
@return PriceTableRow the created price table row | [
"Creates",
"a",
"new",
"price",
"table",
"row",
"with",
"the",
"specified",
"attributes",
"."
] | d552b800ad53c400b1a50c7852e7ad184245d2ea | https://github.com/googleads/googleads-php-lib/blob/d552b800ad53c400b1a50c7852e7ad184245d2ea/examples/AdWords/v201809/Extensions/AddPrices.php#L167-L193 | train |
googleads/googleads-php-lib | src/Google/AdsApi/AdManager/v201808/NetworkService.php | NetworkService.updateNetwork | public function updateNetwork(\Google\AdsApi\AdManager\v201808\Network $network)
{
return $this->__soapCall('updateNetwork', array(array('network' => $network)))->getRval();
} | php | public function updateNetwork(\Google\AdsApi\AdManager\v201808\Network $network)
{
return $this->__soapCall('updateNetwork', array(array('network' => $network)))->getRval();
} | [
"public",
"function",
"updateNetwork",
"(",
"\\",
"Google",
"\\",
"AdsApi",
"\\",
"AdManager",
"\\",
"v201808",
"\\",
"Network",
"$",
"network",
")",
"{",
"return",
"$",
"this",
"->",
"__soapCall",
"(",
"'updateNetwork'",
",",
"array",
"(",
"array",
"(",
"'network'",
"=>",
"$",
"network",
")",
")",
")",
"->",
"getRval",
"(",
")",
";",
"}"
] | Updates the specified network. Currently, only the network display name can
be updated.
@param \Google\AdsApi\AdManager\v201808\Network $network
@return \Google\AdsApi\AdManager\v201808\Network
@throws \Google\AdsApi\AdManager\v201808\ApiException | [
"Updates",
"the",
"specified",
"network",
".",
"Currently",
"only",
"the",
"network",
"display",
"name",
"can",
"be",
"updated",
"."
] | d552b800ad53c400b1a50c7852e7ad184245d2ea | https://github.com/googleads/googleads-php-lib/blob/d552b800ad53c400b1a50c7852e7ad184245d2ea/src/Google/AdsApi/AdManager/v201808/NetworkService.php#L140-L143 | train |
googleads/googleads-php-lib | src/Google/AdsApi/AdWords/Query/v201809/ExpressionBuilder.php | ExpressionBuilder.copyFrom | public static function copyFrom(ExpressionBuilder $otherInstance)
{
$copyingInstance = new self($otherInstance->fieldName);
$copyingInstance->simpleOperator = $otherInstance->simpleOperator;
$copyingInstance->simpleValue = $otherInstance->simpleValue;
$copyingInstance->listOperator = $otherInstance->listOperator;
$copyingInstance->listValues = $otherInstance->listValues;
return $copyingInstance;
} | php | public static function copyFrom(ExpressionBuilder $otherInstance)
{
$copyingInstance = new self($otherInstance->fieldName);
$copyingInstance->simpleOperator = $otherInstance->simpleOperator;
$copyingInstance->simpleValue = $otherInstance->simpleValue;
$copyingInstance->listOperator = $otherInstance->listOperator;
$copyingInstance->listValues = $otherInstance->listValues;
return $copyingInstance;
} | [
"public",
"static",
"function",
"copyFrom",
"(",
"ExpressionBuilder",
"$",
"otherInstance",
")",
"{",
"$",
"copyingInstance",
"=",
"new",
"self",
"(",
"$",
"otherInstance",
"->",
"fieldName",
")",
";",
"$",
"copyingInstance",
"->",
"simpleOperator",
"=",
"$",
"otherInstance",
"->",
"simpleOperator",
";",
"$",
"copyingInstance",
"->",
"simpleValue",
"=",
"$",
"otherInstance",
"->",
"simpleValue",
";",
"$",
"copyingInstance",
"->",
"listOperator",
"=",
"$",
"otherInstance",
"->",
"listOperator",
";",
"$",
"copyingInstance",
"->",
"listValues",
"=",
"$",
"otherInstance",
"->",
"listValues",
";",
"return",
"$",
"copyingInstance",
";",
"}"
] | Creates a new expression builder object by copying the operands and
operators from another expression builder object.
@param ExpressionBuilder $otherInstance the other expression builder
object for copying the operands and operators
@return ExpressionBuilder a new expression builder object that copies
from the input one | [
"Creates",
"a",
"new",
"expression",
"builder",
"object",
"by",
"copying",
"the",
"operands",
"and",
"operators",
"from",
"another",
"expression",
"builder",
"object",
"."
] | d552b800ad53c400b1a50c7852e7ad184245d2ea | https://github.com/googleads/googleads-php-lib/blob/d552b800ad53c400b1a50c7852e7ad184245d2ea/src/Google/AdsApi/AdWords/Query/v201809/ExpressionBuilder.php#L66-L74 | train |
googleads/googleads-php-lib | src/Google/AdsApi/AdWords/Query/v201809/ExpressionBuilder.php | ExpressionBuilder.setSimpleOperator | private function setSimpleOperator($operator, $value)
{
if (empty($operator)) {
throw new InvalidArgumentException('The operator must not be null' .
' or empty.');
}
if (is_null($value) || $value === '') {
throw new InvalidArgumentException('The value string must not be' .
' null or empty');
}
$this->simpleOperator = $operator;
$this->simpleValue = $value;
} | php | private function setSimpleOperator($operator, $value)
{
if (empty($operator)) {
throw new InvalidArgumentException('The operator must not be null' .
' or empty.');
}
if (is_null($value) || $value === '') {
throw new InvalidArgumentException('The value string must not be' .
' null or empty');
}
$this->simpleOperator = $operator;
$this->simpleValue = $value;
} | [
"private",
"function",
"setSimpleOperator",
"(",
"$",
"operator",
",",
"$",
"value",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"operator",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'The operator must not be null'",
".",
"' or empty.'",
")",
";",
"}",
"if",
"(",
"is_null",
"(",
"$",
"value",
")",
"||",
"$",
"value",
"===",
"''",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'The value string must not be'",
".",
"' null or empty'",
")",
";",
"}",
"$",
"this",
"->",
"simpleOperator",
"=",
"$",
"operator",
";",
"$",
"this",
"->",
"simpleValue",
"=",
"$",
"value",
";",
"}"
] | Sets an operator and a single value that follows the operator.
@param string $operator the operator that works with a single value
@param string $value a number or string that follows the operator | [
"Sets",
"an",
"operator",
"and",
"a",
"single",
"value",
"that",
"follows",
"the",
"operator",
"."
] | d552b800ad53c400b1a50c7852e7ad184245d2ea | https://github.com/googleads/googleads-php-lib/blob/d552b800ad53c400b1a50c7852e7ad184245d2ea/src/Google/AdsApi/AdWords/Query/v201809/ExpressionBuilder.php#L82-L96 | train |
googleads/googleads-php-lib | src/Google/AdsApi/AdWords/Query/v201809/ExpressionBuilder.php | ExpressionBuilder.formatValue | private static function formatValue($value)
{
// The `$value` argument could be a number (example: 123) or a numeric
// string (example: '123'). A numeric string is recommended for
// 32-bit systems to prevent unexpected truncation.
//
// To use a numeric string in a WHERE condition, it needs to be
// wrapped in a pair of quotes.
// For example:
// SELECT Id WHERE Id = '9223372036854775807'
if (is_numeric($value) && !is_string($value)) {
return $value;
}
return sprintf('\'%s\'', addslashes($value));
} | php | private static function formatValue($value)
{
// The `$value` argument could be a number (example: 123) or a numeric
// string (example: '123'). A numeric string is recommended for
// 32-bit systems to prevent unexpected truncation.
//
// To use a numeric string in a WHERE condition, it needs to be
// wrapped in a pair of quotes.
// For example:
// SELECT Id WHERE Id = '9223372036854775807'
if (is_numeric($value) && !is_string($value)) {
return $value;
}
return sprintf('\'%s\'', addslashes($value));
} | [
"private",
"static",
"function",
"formatValue",
"(",
"$",
"value",
")",
"{",
"// The `$value` argument could be a number (example: 123) or a numeric",
"// string (example: '123'). A numeric string is recommended for",
"// 32-bit systems to prevent unexpected truncation.",
"//",
"// To use a numeric string in a WHERE condition, it needs to be",
"// wrapped in a pair of quotes.",
"// For example:",
"// SELECT Id WHERE Id = '9223372036854775807'",
"if",
"(",
"is_numeric",
"(",
"$",
"value",
")",
"&&",
"!",
"is_string",
"(",
"$",
"value",
")",
")",
"{",
"return",
"$",
"value",
";",
"}",
"return",
"sprintf",
"(",
"'\\'%s\\''",
",",
"addslashes",
"(",
"$",
"value",
")",
")",
";",
"}"
] | If the input value is not numeric, escape all quotes, then wrap the
string in a pair of quotes.
@param mixed $value a value to be formatted
@return int|string a number if the input is a numeric value; Otherwise,
returns a quoted string | [
"If",
"the",
"input",
"value",
"is",
"not",
"numeric",
"escape",
"all",
"quotes",
"then",
"wrap",
"the",
"string",
"in",
"a",
"pair",
"of",
"quotes",
"."
] | d552b800ad53c400b1a50c7852e7ad184245d2ea | https://github.com/googleads/googleads-php-lib/blob/d552b800ad53c400b1a50c7852e7ad184245d2ea/src/Google/AdsApi/AdWords/Query/v201809/ExpressionBuilder.php#L106-L121 | train |
googleads/googleads-php-lib | src/Google/AdsApi/AdWords/Query/v201809/ExpressionBuilder.php | ExpressionBuilder.formatValues | private static function formatValues($listValues)
{
$formattedValues = [];
foreach ($listValues as $value) {
$formattedValues[] = self::formatValue($value);
}
return $formattedValues;
} | php | private static function formatValues($listValues)
{
$formattedValues = [];
foreach ($listValues as $value) {
$formattedValues[] = self::formatValue($value);
}
return $formattedValues;
} | [
"private",
"static",
"function",
"formatValues",
"(",
"$",
"listValues",
")",
"{",
"$",
"formattedValues",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"listValues",
"as",
"$",
"value",
")",
"{",
"$",
"formattedValues",
"[",
"]",
"=",
"self",
"::",
"formatValue",
"(",
"$",
"value",
")",
";",
"}",
"return",
"$",
"formattedValues",
";",
"}"
] | Formats each individual value in an array.
@param array $listValues the array containing values to be formatted
@return array a new array containing formatted values | [
"Formats",
"each",
"individual",
"value",
"in",
"an",
"array",
"."
] | d552b800ad53c400b1a50c7852e7ad184245d2ea | https://github.com/googleads/googleads-php-lib/blob/d552b800ad53c400b1a50c7852e7ad184245d2ea/src/Google/AdsApi/AdWords/Query/v201809/ExpressionBuilder.php#L129-L136 | train |
googleads/googleads-php-lib | src/Google/AdsApi/AdWords/Query/v201809/ExpressionBuilder.php | ExpressionBuilder.setListOperator | private function setListOperator($listOperator, array $values)
{
if (empty($listOperator)) {
throw new InvalidArgumentException('The list operator must not' .
' be null or empty.');
}
if (empty($values)) {
throw new InvalidArgumentException('The list of values must not' .
' be null or empty.');
}
$this->listOperator = $listOperator;
$this->listValues = $values;
} | php | private function setListOperator($listOperator, array $values)
{
if (empty($listOperator)) {
throw new InvalidArgumentException('The list operator must not' .
' be null or empty.');
}
if (empty($values)) {
throw new InvalidArgumentException('The list of values must not' .
' be null or empty.');
}
$this->listOperator = $listOperator;
$this->listValues = $values;
} | [
"private",
"function",
"setListOperator",
"(",
"$",
"listOperator",
",",
"array",
"$",
"values",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"listOperator",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'The list operator must not'",
".",
"' be null or empty.'",
")",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"values",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'The list of values must not'",
".",
"' be null or empty.'",
")",
";",
"}",
"$",
"this",
"->",
"listOperator",
"=",
"$",
"listOperator",
";",
"$",
"this",
"->",
"listValues",
"=",
"$",
"values",
";",
"}"
] | Sets the list operator and values; Also, adds quotes to string values.
@param string $listOperator an operator that works with a list of values
@param array $values the list of values that follows the operator | [
"Sets",
"the",
"list",
"operator",
"and",
"values",
";",
"Also",
"adds",
"quotes",
"to",
"string",
"values",
"."
] | d552b800ad53c400b1a50c7852e7ad184245d2ea | https://github.com/googleads/googleads-php-lib/blob/d552b800ad53c400b1a50c7852e7ad184245d2ea/src/Google/AdsApi/AdWords/Query/v201809/ExpressionBuilder.php#L282-L296 | train |
googleads/googleads-php-lib | src/Google/AdsApi/AdWords/Query/v201809/ExpressionBuilder.php | ExpressionBuilder.buildExpression | public function buildExpression()
{
if (isset($this->simpleOperator)) {
return sprintf(
'%s %s %s',
$this->fieldName,
$this->simpleOperator,
self::formatValue($this->simpleValue)
);
}
if (isset($this->listOperator)) {
return sprintf(
'%s %s [%s]',
$this->fieldName,
$this->listOperator,
implode(', ', self::formatValues($this->listValues))
);
}
throw new BadFunctionCallException('An operator must be set' .
' prior to calling this function.');
} | php | public function buildExpression()
{
if (isset($this->simpleOperator)) {
return sprintf(
'%s %s %s',
$this->fieldName,
$this->simpleOperator,
self::formatValue($this->simpleValue)
);
}
if (isset($this->listOperator)) {
return sprintf(
'%s %s [%s]',
$this->fieldName,
$this->listOperator,
implode(', ', self::formatValues($this->listValues))
);
}
throw new BadFunctionCallException('An operator must be set' .
' prior to calling this function.');
} | [
"public",
"function",
"buildExpression",
"(",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"simpleOperator",
")",
")",
"{",
"return",
"sprintf",
"(",
"'%s %s %s'",
",",
"$",
"this",
"->",
"fieldName",
",",
"$",
"this",
"->",
"simpleOperator",
",",
"self",
"::",
"formatValue",
"(",
"$",
"this",
"->",
"simpleValue",
")",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"listOperator",
")",
")",
"{",
"return",
"sprintf",
"(",
"'%s %s [%s]'",
",",
"$",
"this",
"->",
"fieldName",
",",
"$",
"this",
"->",
"listOperator",
",",
"implode",
"(",
"', '",
",",
"self",
"::",
"formatValues",
"(",
"$",
"this",
"->",
"listValues",
")",
")",
")",
";",
"}",
"throw",
"new",
"BadFunctionCallException",
"(",
"'An operator must be set'",
".",
"' prior to calling this function.'",
")",
";",
"}"
] | Builds a logic expression in the WHERE clause of an AWQL string.
@return string a logic expression in the WHERE clause of an AWQL string
@throws BadFunctionCallException when no operators was specified prior
to calling this function | [
"Builds",
"a",
"logic",
"expression",
"in",
"the",
"WHERE",
"clause",
"of",
"an",
"AWQL",
"string",
"."
] | d552b800ad53c400b1a50c7852e7ad184245d2ea | https://github.com/googleads/googleads-php-lib/blob/d552b800ad53c400b1a50c7852e7ad184245d2ea/src/Google/AdsApi/AdWords/Query/v201809/ExpressionBuilder.php#L374-L396 | train |
googleads/googleads-php-lib | examples/AdWords/v201809/Remarketing/AddRuleBasedUserLists.php | AddRuleBasedUserLists.createUserListRule | private static function createUserListRule()
{
// First rule item group - users who visited the checkout page and had more
// than one item in their shopping cart.
$checkoutStringRuleItem = new StringRuleItem();
$checkoutStringKey = new StringKey();
$checkoutStringKey->setName('ecomm_pagetype');
$checkoutStringRuleItem->setKey($checkoutStringKey);
$checkoutStringRuleItem->setOp(StringRuleItemStringOperator::EQUALS);
$checkoutStringRuleItem->setValue('checkout');
$checkoutRuleItem = new RuleItem();
$checkoutRuleItem->setStringRuleItem($checkoutStringRuleItem);
$cartSizeNumberRuleItem = new NumberRuleItem();
$cartSizeNumberKey = new NumberKey();
$cartSizeNumberKey->setName('cartsize');
$cartSizeNumberRuleItem->setKey($cartSizeNumberKey);
$cartSizeNumberRuleItem->setOp(NumberRuleItemNumberOperator::GREATER_THAN);
$cartSizeNumberRuleItem->setValue(1.0);
$cartSizeRuleItem = new RuleItem();
$cartSizeRuleItem->setNumberRuleItem($cartSizeNumberRuleItem);
// Combine the two rule items into a RuleItemGroup so AdWords will AND their
// rules together.
$checkoutMultipleItemGroup = new RuleItemGroup();
$checkoutMultipleItemGroup->setItems(
[$checkoutRuleItem, $cartSizeRuleItem]
);
// Second rule item group - users who checked out within the next 3 months.
$today = new DateTime();
$startDateDateRuleItem = new DateRuleItem();
$startDateDateKey = new DateKey();
$startDateDateKey->setName('checkoutdate');
$startDateDateRuleItem->setKey($startDateDateKey);
$startDateDateRuleItem->setOp(DateRuleItemDateOperator::AFTER);
$startDateDateRuleItem->setValue($today->format('Ymd'));
$startDateRuleItem = new RuleItem();
$startDateRuleItem->setDateRuleItem($startDateDateRuleItem);
$threeMonthsLater = new DateTime('+3 month');
$endDateDateRuleItem = new DateRuleItem();
$endDateDateKey = new DateKey();
$endDateDateKey->setName('checkoutdate');
$endDateDateRuleItem->setKey($endDateDateKey);
$endDateDateRuleItem->setOp(DateRuleItemDateOperator::BEFORE);
$endDateDateRuleItem->setValue($threeMonthsLater->format('Ymd'));
$endDateRuleItem = new RuleItem();
$endDateRuleItem->setDateRuleItem($endDateDateRuleItem);
// Combine the date rule items into a RuleItemGroup.
$checkedOutDateRangeItemGroup = new RuleItemGroup();
$checkedOutDateRangeItemGroup->setItems(
[$startDateRuleItem, $endDateRuleItem]
);
// Combine the rule item groups into a Rule so AdWords knows how to apply
// the rules.
$rule = new Rule();
$rule->setGroups(
[$checkoutMultipleItemGroup, $checkedOutDateRangeItemGroup]
);
// ExpressionRuleUserLists can use either CNF or DNF for matching. CNF means
// 'at least one item in each rule item group must match', and DNF means 'at
// least one entire rule item group must match'. DateSpecificRuleUserList
// only supports DNF. You can also omit the rule type altogether to default
// to DNF.
$rule->setRuleType(UserListRuleTypeEnumsEnum::DNF);
return $rule;
} | php | private static function createUserListRule()
{
// First rule item group - users who visited the checkout page and had more
// than one item in their shopping cart.
$checkoutStringRuleItem = new StringRuleItem();
$checkoutStringKey = new StringKey();
$checkoutStringKey->setName('ecomm_pagetype');
$checkoutStringRuleItem->setKey($checkoutStringKey);
$checkoutStringRuleItem->setOp(StringRuleItemStringOperator::EQUALS);
$checkoutStringRuleItem->setValue('checkout');
$checkoutRuleItem = new RuleItem();
$checkoutRuleItem->setStringRuleItem($checkoutStringRuleItem);
$cartSizeNumberRuleItem = new NumberRuleItem();
$cartSizeNumberKey = new NumberKey();
$cartSizeNumberKey->setName('cartsize');
$cartSizeNumberRuleItem->setKey($cartSizeNumberKey);
$cartSizeNumberRuleItem->setOp(NumberRuleItemNumberOperator::GREATER_THAN);
$cartSizeNumberRuleItem->setValue(1.0);
$cartSizeRuleItem = new RuleItem();
$cartSizeRuleItem->setNumberRuleItem($cartSizeNumberRuleItem);
// Combine the two rule items into a RuleItemGroup so AdWords will AND their
// rules together.
$checkoutMultipleItemGroup = new RuleItemGroup();
$checkoutMultipleItemGroup->setItems(
[$checkoutRuleItem, $cartSizeRuleItem]
);
// Second rule item group - users who checked out within the next 3 months.
$today = new DateTime();
$startDateDateRuleItem = new DateRuleItem();
$startDateDateKey = new DateKey();
$startDateDateKey->setName('checkoutdate');
$startDateDateRuleItem->setKey($startDateDateKey);
$startDateDateRuleItem->setOp(DateRuleItemDateOperator::AFTER);
$startDateDateRuleItem->setValue($today->format('Ymd'));
$startDateRuleItem = new RuleItem();
$startDateRuleItem->setDateRuleItem($startDateDateRuleItem);
$threeMonthsLater = new DateTime('+3 month');
$endDateDateRuleItem = new DateRuleItem();
$endDateDateKey = new DateKey();
$endDateDateKey->setName('checkoutdate');
$endDateDateRuleItem->setKey($endDateDateKey);
$endDateDateRuleItem->setOp(DateRuleItemDateOperator::BEFORE);
$endDateDateRuleItem->setValue($threeMonthsLater->format('Ymd'));
$endDateRuleItem = new RuleItem();
$endDateRuleItem->setDateRuleItem($endDateDateRuleItem);
// Combine the date rule items into a RuleItemGroup.
$checkedOutDateRangeItemGroup = new RuleItemGroup();
$checkedOutDateRangeItemGroup->setItems(
[$startDateRuleItem, $endDateRuleItem]
);
// Combine the rule item groups into a Rule so AdWords knows how to apply
// the rules.
$rule = new Rule();
$rule->setGroups(
[$checkoutMultipleItemGroup, $checkedOutDateRangeItemGroup]
);
// ExpressionRuleUserLists can use either CNF or DNF for matching. CNF means
// 'at least one item in each rule item group must match', and DNF means 'at
// least one entire rule item group must match'. DateSpecificRuleUserList
// only supports DNF. You can also omit the rule type altogether to default
// to DNF.
$rule->setRuleType(UserListRuleTypeEnumsEnum::DNF);
return $rule;
} | [
"private",
"static",
"function",
"createUserListRule",
"(",
")",
"{",
"// First rule item group - users who visited the checkout page and had more",
"// than one item in their shopping cart.",
"$",
"checkoutStringRuleItem",
"=",
"new",
"StringRuleItem",
"(",
")",
";",
"$",
"checkoutStringKey",
"=",
"new",
"StringKey",
"(",
")",
";",
"$",
"checkoutStringKey",
"->",
"setName",
"(",
"'ecomm_pagetype'",
")",
";",
"$",
"checkoutStringRuleItem",
"->",
"setKey",
"(",
"$",
"checkoutStringKey",
")",
";",
"$",
"checkoutStringRuleItem",
"->",
"setOp",
"(",
"StringRuleItemStringOperator",
"::",
"EQUALS",
")",
";",
"$",
"checkoutStringRuleItem",
"->",
"setValue",
"(",
"'checkout'",
")",
";",
"$",
"checkoutRuleItem",
"=",
"new",
"RuleItem",
"(",
")",
";",
"$",
"checkoutRuleItem",
"->",
"setStringRuleItem",
"(",
"$",
"checkoutStringRuleItem",
")",
";",
"$",
"cartSizeNumberRuleItem",
"=",
"new",
"NumberRuleItem",
"(",
")",
";",
"$",
"cartSizeNumberKey",
"=",
"new",
"NumberKey",
"(",
")",
";",
"$",
"cartSizeNumberKey",
"->",
"setName",
"(",
"'cartsize'",
")",
";",
"$",
"cartSizeNumberRuleItem",
"->",
"setKey",
"(",
"$",
"cartSizeNumberKey",
")",
";",
"$",
"cartSizeNumberRuleItem",
"->",
"setOp",
"(",
"NumberRuleItemNumberOperator",
"::",
"GREATER_THAN",
")",
";",
"$",
"cartSizeNumberRuleItem",
"->",
"setValue",
"(",
"1.0",
")",
";",
"$",
"cartSizeRuleItem",
"=",
"new",
"RuleItem",
"(",
")",
";",
"$",
"cartSizeRuleItem",
"->",
"setNumberRuleItem",
"(",
"$",
"cartSizeNumberRuleItem",
")",
";",
"// Combine the two rule items into a RuleItemGroup so AdWords will AND their",
"// rules together.",
"$",
"checkoutMultipleItemGroup",
"=",
"new",
"RuleItemGroup",
"(",
")",
";",
"$",
"checkoutMultipleItemGroup",
"->",
"setItems",
"(",
"[",
"$",
"checkoutRuleItem",
",",
"$",
"cartSizeRuleItem",
"]",
")",
";",
"// Second rule item group - users who checked out within the next 3 months.",
"$",
"today",
"=",
"new",
"DateTime",
"(",
")",
";",
"$",
"startDateDateRuleItem",
"=",
"new",
"DateRuleItem",
"(",
")",
";",
"$",
"startDateDateKey",
"=",
"new",
"DateKey",
"(",
")",
";",
"$",
"startDateDateKey",
"->",
"setName",
"(",
"'checkoutdate'",
")",
";",
"$",
"startDateDateRuleItem",
"->",
"setKey",
"(",
"$",
"startDateDateKey",
")",
";",
"$",
"startDateDateRuleItem",
"->",
"setOp",
"(",
"DateRuleItemDateOperator",
"::",
"AFTER",
")",
";",
"$",
"startDateDateRuleItem",
"->",
"setValue",
"(",
"$",
"today",
"->",
"format",
"(",
"'Ymd'",
")",
")",
";",
"$",
"startDateRuleItem",
"=",
"new",
"RuleItem",
"(",
")",
";",
"$",
"startDateRuleItem",
"->",
"setDateRuleItem",
"(",
"$",
"startDateDateRuleItem",
")",
";",
"$",
"threeMonthsLater",
"=",
"new",
"DateTime",
"(",
"'+3 month'",
")",
";",
"$",
"endDateDateRuleItem",
"=",
"new",
"DateRuleItem",
"(",
")",
";",
"$",
"endDateDateKey",
"=",
"new",
"DateKey",
"(",
")",
";",
"$",
"endDateDateKey",
"->",
"setName",
"(",
"'checkoutdate'",
")",
";",
"$",
"endDateDateRuleItem",
"->",
"setKey",
"(",
"$",
"endDateDateKey",
")",
";",
"$",
"endDateDateRuleItem",
"->",
"setOp",
"(",
"DateRuleItemDateOperator",
"::",
"BEFORE",
")",
";",
"$",
"endDateDateRuleItem",
"->",
"setValue",
"(",
"$",
"threeMonthsLater",
"->",
"format",
"(",
"'Ymd'",
")",
")",
";",
"$",
"endDateRuleItem",
"=",
"new",
"RuleItem",
"(",
")",
";",
"$",
"endDateRuleItem",
"->",
"setDateRuleItem",
"(",
"$",
"endDateDateRuleItem",
")",
";",
"// Combine the date rule items into a RuleItemGroup.",
"$",
"checkedOutDateRangeItemGroup",
"=",
"new",
"RuleItemGroup",
"(",
")",
";",
"$",
"checkedOutDateRangeItemGroup",
"->",
"setItems",
"(",
"[",
"$",
"startDateRuleItem",
",",
"$",
"endDateRuleItem",
"]",
")",
";",
"// Combine the rule item groups into a Rule so AdWords knows how to apply",
"// the rules.",
"$",
"rule",
"=",
"new",
"Rule",
"(",
")",
";",
"$",
"rule",
"->",
"setGroups",
"(",
"[",
"$",
"checkoutMultipleItemGroup",
",",
"$",
"checkedOutDateRangeItemGroup",
"]",
")",
";",
"// ExpressionRuleUserLists can use either CNF or DNF for matching. CNF means",
"// 'at least one item in each rule item group must match', and DNF means 'at",
"// least one entire rule item group must match'. DateSpecificRuleUserList",
"// only supports DNF. You can also omit the rule type altogether to default",
"// to DNF.",
"$",
"rule",
"->",
"setRuleType",
"(",
"UserListRuleTypeEnumsEnum",
"::",
"DNF",
")",
";",
"return",
"$",
"rule",
";",
"}"
] | Create a user list rule composed of two rule item groups.
@return Rule the created rule | [
"Create",
"a",
"user",
"list",
"rule",
"composed",
"of",
"two",
"rule",
"item",
"groups",
"."
] | d552b800ad53c400b1a50c7852e7ad184245d2ea | https://github.com/googleads/googleads-php-lib/blob/d552b800ad53c400b1a50c7852e7ad184245d2ea/examples/AdWords/v201809/Remarketing/AddRuleBasedUserLists.php#L151-L221 | train |
googleads/googleads-php-lib | examples/AdWords/v201809/Remarketing/AddRuleBasedUserLists.php | AddRuleBasedUserLists.createCombinedUserListRules | private static function createCombinedUserListRules()
{
// Third and fourth rule item groups
// Visitors of a page who visited another page.
$site1StringRuleItem = new StringRuleItem();
$site1StringKey = new StringKey();
$site1StringKey->setName('url__');
$site1StringRuleItem->setKey($site1StringKey);
$site1StringRuleItem->setOp(StringRuleItemStringOperator::EQUALS);
$site1StringRuleItem->setValue('example.com/example1');
$site1RuleItem = new RuleItem();
$site1RuleItem->setStringRuleItem($site1StringRuleItem);
$site2StringRuleItem = new StringRuleItem();
$site2StringKey = new StringKey();
$site2StringKey->setName('url__');
$site2StringRuleItem->setKey($site2StringKey);
$site2StringRuleItem->setOp(StringRuleItemStringOperator::EQUALS);
$site2StringRuleItem->setValue('example.com/example2');
$site2RuleItem = new RuleItem();
$site2RuleItem->setStringRuleItem($site2StringRuleItem);
// Create two RuleItemGroups to show that a visitor browsed two sites.
$site1ItemGroup = new RuleItemGroup();
$site1ItemGroup->setItems([$site1RuleItem]);
$site2ItemGroup = new RuleItemGroup();
$site2ItemGroup->setItems([$site2RuleItem]);
// Create two rules to show that a visitor browsed two sites.
$userVisitedSite1Rule = new Rule();
$userVisitedSite1Rule->setGroups([$site1ItemGroup]);
$userVisitedSite2Rule = new Rule();
$userVisitedSite2Rule->setGroups([$site2ItemGroup]);
return [$userVisitedSite1Rule, $userVisitedSite2Rule];
} | php | private static function createCombinedUserListRules()
{
// Third and fourth rule item groups
// Visitors of a page who visited another page.
$site1StringRuleItem = new StringRuleItem();
$site1StringKey = new StringKey();
$site1StringKey->setName('url__');
$site1StringRuleItem->setKey($site1StringKey);
$site1StringRuleItem->setOp(StringRuleItemStringOperator::EQUALS);
$site1StringRuleItem->setValue('example.com/example1');
$site1RuleItem = new RuleItem();
$site1RuleItem->setStringRuleItem($site1StringRuleItem);
$site2StringRuleItem = new StringRuleItem();
$site2StringKey = new StringKey();
$site2StringKey->setName('url__');
$site2StringRuleItem->setKey($site2StringKey);
$site2StringRuleItem->setOp(StringRuleItemStringOperator::EQUALS);
$site2StringRuleItem->setValue('example.com/example2');
$site2RuleItem = new RuleItem();
$site2RuleItem->setStringRuleItem($site2StringRuleItem);
// Create two RuleItemGroups to show that a visitor browsed two sites.
$site1ItemGroup = new RuleItemGroup();
$site1ItemGroup->setItems([$site1RuleItem]);
$site2ItemGroup = new RuleItemGroup();
$site2ItemGroup->setItems([$site2RuleItem]);
// Create two rules to show that a visitor browsed two sites.
$userVisitedSite1Rule = new Rule();
$userVisitedSite1Rule->setGroups([$site1ItemGroup]);
$userVisitedSite2Rule = new Rule();
$userVisitedSite2Rule->setGroups([$site2ItemGroup]);
return [$userVisitedSite1Rule, $userVisitedSite2Rule];
} | [
"private",
"static",
"function",
"createCombinedUserListRules",
"(",
")",
"{",
"// Third and fourth rule item groups",
"// Visitors of a page who visited another page.",
"$",
"site1StringRuleItem",
"=",
"new",
"StringRuleItem",
"(",
")",
";",
"$",
"site1StringKey",
"=",
"new",
"StringKey",
"(",
")",
";",
"$",
"site1StringKey",
"->",
"setName",
"(",
"'url__'",
")",
";",
"$",
"site1StringRuleItem",
"->",
"setKey",
"(",
"$",
"site1StringKey",
")",
";",
"$",
"site1StringRuleItem",
"->",
"setOp",
"(",
"StringRuleItemStringOperator",
"::",
"EQUALS",
")",
";",
"$",
"site1StringRuleItem",
"->",
"setValue",
"(",
"'example.com/example1'",
")",
";",
"$",
"site1RuleItem",
"=",
"new",
"RuleItem",
"(",
")",
";",
"$",
"site1RuleItem",
"->",
"setStringRuleItem",
"(",
"$",
"site1StringRuleItem",
")",
";",
"$",
"site2StringRuleItem",
"=",
"new",
"StringRuleItem",
"(",
")",
";",
"$",
"site2StringKey",
"=",
"new",
"StringKey",
"(",
")",
";",
"$",
"site2StringKey",
"->",
"setName",
"(",
"'url__'",
")",
";",
"$",
"site2StringRuleItem",
"->",
"setKey",
"(",
"$",
"site2StringKey",
")",
";",
"$",
"site2StringRuleItem",
"->",
"setOp",
"(",
"StringRuleItemStringOperator",
"::",
"EQUALS",
")",
";",
"$",
"site2StringRuleItem",
"->",
"setValue",
"(",
"'example.com/example2'",
")",
";",
"$",
"site2RuleItem",
"=",
"new",
"RuleItem",
"(",
")",
";",
"$",
"site2RuleItem",
"->",
"setStringRuleItem",
"(",
"$",
"site2StringRuleItem",
")",
";",
"// Create two RuleItemGroups to show that a visitor browsed two sites.",
"$",
"site1ItemGroup",
"=",
"new",
"RuleItemGroup",
"(",
")",
";",
"$",
"site1ItemGroup",
"->",
"setItems",
"(",
"[",
"$",
"site1RuleItem",
"]",
")",
";",
"$",
"site2ItemGroup",
"=",
"new",
"RuleItemGroup",
"(",
")",
";",
"$",
"site2ItemGroup",
"->",
"setItems",
"(",
"[",
"$",
"site2RuleItem",
"]",
")",
";",
"// Create two rules to show that a visitor browsed two sites.",
"$",
"userVisitedSite1Rule",
"=",
"new",
"Rule",
"(",
")",
";",
"$",
"userVisitedSite1Rule",
"->",
"setGroups",
"(",
"[",
"$",
"site1ItemGroup",
"]",
")",
";",
"$",
"userVisitedSite2Rule",
"=",
"new",
"Rule",
"(",
")",
";",
"$",
"userVisitedSite2Rule",
"->",
"setGroups",
"(",
"[",
"$",
"site2ItemGroup",
"]",
")",
";",
"return",
"[",
"$",
"userVisitedSite1Rule",
",",
"$",
"userVisitedSite2Rule",
"]",
";",
"}"
] | Create rules to be used as left and right operands of
a combined user list.
@return Rule[] the array of created rules | [
"Create",
"rules",
"to",
"be",
"used",
"as",
"left",
"and",
"right",
"operands",
"of",
"a",
"combined",
"user",
"list",
"."
] | d552b800ad53c400b1a50c7852e7ad184245d2ea | https://github.com/googleads/googleads-php-lib/blob/d552b800ad53c400b1a50c7852e7ad184245d2ea/examples/AdWords/v201809/Remarketing/AddRuleBasedUserLists.php#L229-L265 | train |
googleads/googleads-php-lib | src/Google/AdsApi/AdWords/Shopping/v201809/ProductPartitions.php | ProductPartitions.asBiddableAdGroupCriterion | public static function asBiddableAdGroupCriterion(
$adGroupId,
ProductPartition $productPartition,
$bidAmount = null
) {
$criterion = new BiddableAdGroupCriterion();
if ($bidAmount !== null && $bidAmount > 0) {
$biddingStrategyConfiguration = new BiddingStrategyConfiguration();
$cpcBid = new CpcBid();
$money = new Money();
$money->setMicroAmount($bidAmount);
$cpcBid->setBid($money);
$biddingStrategyConfiguration->setBids([$cpcBid]);
$criterion->setBiddingStrategyConfiguration(
$biddingStrategyConfiguration
);
}
$criterion->setAdGroupId($adGroupId);
$criterion->setCriterion($productPartition);
return $criterion;
} | php | public static function asBiddableAdGroupCriterion(
$adGroupId,
ProductPartition $productPartition,
$bidAmount = null
) {
$criterion = new BiddableAdGroupCriterion();
if ($bidAmount !== null && $bidAmount > 0) {
$biddingStrategyConfiguration = new BiddingStrategyConfiguration();
$cpcBid = new CpcBid();
$money = new Money();
$money->setMicroAmount($bidAmount);
$cpcBid->setBid($money);
$biddingStrategyConfiguration->setBids([$cpcBid]);
$criterion->setBiddingStrategyConfiguration(
$biddingStrategyConfiguration
);
}
$criterion->setAdGroupId($adGroupId);
$criterion->setCriterion($productPartition);
return $criterion;
} | [
"public",
"static",
"function",
"asBiddableAdGroupCriterion",
"(",
"$",
"adGroupId",
",",
"ProductPartition",
"$",
"productPartition",
",",
"$",
"bidAmount",
"=",
"null",
")",
"{",
"$",
"criterion",
"=",
"new",
"BiddableAdGroupCriterion",
"(",
")",
";",
"if",
"(",
"$",
"bidAmount",
"!==",
"null",
"&&",
"$",
"bidAmount",
">",
"0",
")",
"{",
"$",
"biddingStrategyConfiguration",
"=",
"new",
"BiddingStrategyConfiguration",
"(",
")",
";",
"$",
"cpcBid",
"=",
"new",
"CpcBid",
"(",
")",
";",
"$",
"money",
"=",
"new",
"Money",
"(",
")",
";",
"$",
"money",
"->",
"setMicroAmount",
"(",
"$",
"bidAmount",
")",
";",
"$",
"cpcBid",
"->",
"setBid",
"(",
"$",
"money",
")",
";",
"$",
"biddingStrategyConfiguration",
"->",
"setBids",
"(",
"[",
"$",
"cpcBid",
"]",
")",
";",
"$",
"criterion",
"->",
"setBiddingStrategyConfiguration",
"(",
"$",
"biddingStrategyConfiguration",
")",
";",
"}",
"$",
"criterion",
"->",
"setAdGroupId",
"(",
"$",
"adGroupId",
")",
";",
"$",
"criterion",
"->",
"setCriterion",
"(",
"$",
"productPartition",
")",
";",
"return",
"$",
"criterion",
";",
"}"
] | Returns the biddable ad group criterion with by specifying the product
partition and bid amount.
@param int $adGroupId the ID of ad group that this ad group criterion is
created under
@param ProductPartition $productPartition the product partition to create
an ad group criterion
@param null|$bidAmount the bid for the product partition in micro amount
@return BiddableAdGroupCriterion the created biddable ad group criterion | [
"Returns",
"the",
"biddable",
"ad",
"group",
"criterion",
"with",
"by",
"specifying",
"the",
"product",
"partition",
"and",
"bid",
"amount",
"."
] | d552b800ad53c400b1a50c7852e7ad184245d2ea | https://github.com/googleads/googleads-php-lib/blob/d552b800ad53c400b1a50c7852e7ad184245d2ea/src/Google/AdsApi/AdWords/Shopping/v201809/ProductPartitions.php#L128-L151 | train |
googleads/googleads-php-lib | src/Google/AdsApi/AdWords/Shopping/v201809/ProductPartitions.php | ProductPartitions.asNegativeAdGroupCriterion | public static function asNegativeAdGroupCriterion(
$adGroupId,
ProductPartition $productPartition
) {
$criterion = new NegativeAdGroupCriterion();
$criterion->setAdGroupId($adGroupId);
$criterion->setCriterion($productPartition);
return $criterion;
} | php | public static function asNegativeAdGroupCriterion(
$adGroupId,
ProductPartition $productPartition
) {
$criterion = new NegativeAdGroupCriterion();
$criterion->setAdGroupId($adGroupId);
$criterion->setCriterion($productPartition);
return $criterion;
} | [
"public",
"static",
"function",
"asNegativeAdGroupCriterion",
"(",
"$",
"adGroupId",
",",
"ProductPartition",
"$",
"productPartition",
")",
"{",
"$",
"criterion",
"=",
"new",
"NegativeAdGroupCriterion",
"(",
")",
";",
"$",
"criterion",
"->",
"setAdGroupId",
"(",
"$",
"adGroupId",
")",
";",
"$",
"criterion",
"->",
"setCriterion",
"(",
"$",
"productPartition",
")",
";",
"return",
"$",
"criterion",
";",
"}"
] | Returns the negative ad group criterion with by specifying the product
partition.
@param int $adGroupId the ID of ad group that this ad group criterion is
created under
@param ProductPartition $productPartition the product partition to create
an ad group criterion
@return NegativeAdGroupCriterion the created negative ad group criterion | [
"Returns",
"the",
"negative",
"ad",
"group",
"criterion",
"with",
"by",
"specifying",
"the",
"product",
"partition",
"."
] | d552b800ad53c400b1a50c7852e7ad184245d2ea | https://github.com/googleads/googleads-php-lib/blob/d552b800ad53c400b1a50c7852e7ad184245d2ea/src/Google/AdsApi/AdWords/Shopping/v201809/ProductPartitions.php#L163-L172 | train |
googleads/googleads-php-lib | src/Google/AdsApi/AdWords/Shopping/v201809/ProductPartitions.php | ProductPartitions.createAdGroupCriterionOperation | private static function createAdGroupCriterionOperation(
AdGroupCriterion $criterion,
$operator
) {
$operation = new AdGroupCriterionOperation();
$operation->setOperand($criterion);
$operation->setOperator($operator);
return $operation;
} | php | private static function createAdGroupCriterionOperation(
AdGroupCriterion $criterion,
$operator
) {
$operation = new AdGroupCriterionOperation();
$operation->setOperand($criterion);
$operation->setOperator($operator);
return $operation;
} | [
"private",
"static",
"function",
"createAdGroupCriterionOperation",
"(",
"AdGroupCriterion",
"$",
"criterion",
",",
"$",
"operator",
")",
"{",
"$",
"operation",
"=",
"new",
"AdGroupCriterionOperation",
"(",
")",
";",
"$",
"operation",
"->",
"setOperand",
"(",
"$",
"criterion",
")",
";",
"$",
"operation",
"->",
"setOperator",
"(",
"$",
"operator",
")",
";",
"return",
"$",
"operation",
";",
"}"
] | Creates an ad group criterion operation for the given ad group criterion.
@param AdGroupCriterion $criterion the ad group criterion
@param string $operator the operator for the operation
@return AdGroupCriterionOperation the ad group criterion operation | [
"Creates",
"an",
"ad",
"group",
"criterion",
"operation",
"for",
"the",
"given",
"ad",
"group",
"criterion",
"."
] | d552b800ad53c400b1a50c7852e7ad184245d2ea | https://github.com/googleads/googleads-php-lib/blob/d552b800ad53c400b1a50c7852e7ad184245d2ea/src/Google/AdsApi/AdWords/Shopping/v201809/ProductPartitions.php#L220-L229 | train |
googleads/googleads-php-lib | src/Google/AdsApi/AdWords/Shopping/v201809/ProductPartitions.php | ProductPartitions.showAdGroupTree | public static function showAdGroupTree(
AdWordsServices $adWordsServices,
AdWordsSession $session,
$adGroupId
) {
$adGroupCriterionService =
$adWordsServices->get($session, AdGroupCriterionService::class);
$children = [];
$rootNode = null;
$totalNumEntries = 0;
$offset = 0;
do {
$query = sprintf(
'SELECT AdGroupId, Id, ParentCriterionId, CaseValue, PartitionType'
. ' WHERE AdGroupId = %s AND CriteriaType = PRODUCT_PARTITION'
. ' AND Status IN [ENABLED, PAUSED]',
$adGroupId
);
// Retrieve ad group criteria one page at a time.
$page = $adGroupCriterionService->query($query);
// Print out some information for each keyword.
if ($page->getEntries() !== null) {
$totalNumEntries = $page->getTotalNumEntries();
foreach ($page->getEntries() as $adGroupCriterion) {
$criterionId = $adGroupCriterion->getCriterion()->getId();
if (!array_key_exists($criterionId, $children)) {
$children[$criterionId] = [];
}
if ($adGroupCriterion->getCriterion()->getParentCriterionId()
!== null) {
$parentCriterionId =
$adGroupCriterion->getCriterion()
->getParentCriterionId();
$children[$parentCriterionId][] =
$adGroupCriterion->getCriterion();
} else {
$rootNode = $adGroupCriterion->getCriterion();
}
}
}
$offset += self::PAGE_LIMIT;
} while ($offset < $totalNumEntries);
if ($rootNode === null) {
return 'Empty tree';
}
return self::traverseTree($rootNode, $children, 0);
} | php | public static function showAdGroupTree(
AdWordsServices $adWordsServices,
AdWordsSession $session,
$adGroupId
) {
$adGroupCriterionService =
$adWordsServices->get($session, AdGroupCriterionService::class);
$children = [];
$rootNode = null;
$totalNumEntries = 0;
$offset = 0;
do {
$query = sprintf(
'SELECT AdGroupId, Id, ParentCriterionId, CaseValue, PartitionType'
. ' WHERE AdGroupId = %s AND CriteriaType = PRODUCT_PARTITION'
. ' AND Status IN [ENABLED, PAUSED]',
$adGroupId
);
// Retrieve ad group criteria one page at a time.
$page = $adGroupCriterionService->query($query);
// Print out some information for each keyword.
if ($page->getEntries() !== null) {
$totalNumEntries = $page->getTotalNumEntries();
foreach ($page->getEntries() as $adGroupCriterion) {
$criterionId = $adGroupCriterion->getCriterion()->getId();
if (!array_key_exists($criterionId, $children)) {
$children[$criterionId] = [];
}
if ($adGroupCriterion->getCriterion()->getParentCriterionId()
!== null) {
$parentCriterionId =
$adGroupCriterion->getCriterion()
->getParentCriterionId();
$children[$parentCriterionId][] =
$adGroupCriterion->getCriterion();
} else {
$rootNode = $adGroupCriterion->getCriterion();
}
}
}
$offset += self::PAGE_LIMIT;
} while ($offset < $totalNumEntries);
if ($rootNode === null) {
return 'Empty tree';
}
return self::traverseTree($rootNode, $children, 0);
} | [
"public",
"static",
"function",
"showAdGroupTree",
"(",
"AdWordsServices",
"$",
"adWordsServices",
",",
"AdWordsSession",
"$",
"session",
",",
"$",
"adGroupId",
")",
"{",
"$",
"adGroupCriterionService",
"=",
"$",
"adWordsServices",
"->",
"get",
"(",
"$",
"session",
",",
"AdGroupCriterionService",
"::",
"class",
")",
";",
"$",
"children",
"=",
"[",
"]",
";",
"$",
"rootNode",
"=",
"null",
";",
"$",
"totalNumEntries",
"=",
"0",
";",
"$",
"offset",
"=",
"0",
";",
"do",
"{",
"$",
"query",
"=",
"sprintf",
"(",
"'SELECT AdGroupId, Id, ParentCriterionId, CaseValue, PartitionType'",
".",
"' WHERE AdGroupId = %s AND CriteriaType = PRODUCT_PARTITION'",
".",
"' AND Status IN [ENABLED, PAUSED]'",
",",
"$",
"adGroupId",
")",
";",
"// Retrieve ad group criteria one page at a time.",
"$",
"page",
"=",
"$",
"adGroupCriterionService",
"->",
"query",
"(",
"$",
"query",
")",
";",
"// Print out some information for each keyword.",
"if",
"(",
"$",
"page",
"->",
"getEntries",
"(",
")",
"!==",
"null",
")",
"{",
"$",
"totalNumEntries",
"=",
"$",
"page",
"->",
"getTotalNumEntries",
"(",
")",
";",
"foreach",
"(",
"$",
"page",
"->",
"getEntries",
"(",
")",
"as",
"$",
"adGroupCriterion",
")",
"{",
"$",
"criterionId",
"=",
"$",
"adGroupCriterion",
"->",
"getCriterion",
"(",
")",
"->",
"getId",
"(",
")",
";",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"criterionId",
",",
"$",
"children",
")",
")",
"{",
"$",
"children",
"[",
"$",
"criterionId",
"]",
"=",
"[",
"]",
";",
"}",
"if",
"(",
"$",
"adGroupCriterion",
"->",
"getCriterion",
"(",
")",
"->",
"getParentCriterionId",
"(",
")",
"!==",
"null",
")",
"{",
"$",
"parentCriterionId",
"=",
"$",
"adGroupCriterion",
"->",
"getCriterion",
"(",
")",
"->",
"getParentCriterionId",
"(",
")",
";",
"$",
"children",
"[",
"$",
"parentCriterionId",
"]",
"[",
"]",
"=",
"$",
"adGroupCriterion",
"->",
"getCriterion",
"(",
")",
";",
"}",
"else",
"{",
"$",
"rootNode",
"=",
"$",
"adGroupCriterion",
"->",
"getCriterion",
"(",
")",
";",
"}",
"}",
"}",
"$",
"offset",
"+=",
"self",
"::",
"PAGE_LIMIT",
";",
"}",
"while",
"(",
"$",
"offset",
"<",
"$",
"totalNumEntries",
")",
";",
"if",
"(",
"$",
"rootNode",
"===",
"null",
")",
"{",
"return",
"'Empty tree'",
";",
"}",
"return",
"self",
"::",
"traverseTree",
"(",
"$",
"rootNode",
",",
"$",
"children",
",",
"0",
")",
";",
"}"
] | Returns the string representation of ad group criteria of the specified
ad group ID by showing them hierarchically.
@param AdWordsServices $adWordsServices the AdWords services used to send
the operations to be created on the server
@param AdWordsSession $session the AdWords session used to call AdWords
API server
@param int $adGroupId the ID of ad group whose members will be presented
hierarchically
@return string the representation of the ad group criteria | [
"Returns",
"the",
"string",
"representation",
"of",
"ad",
"group",
"criteria",
"of",
"the",
"specified",
"ad",
"group",
"ID",
"by",
"showing",
"them",
"hierarchically",
"."
] | d552b800ad53c400b1a50c7852e7ad184245d2ea | https://github.com/googleads/googleads-php-lib/blob/d552b800ad53c400b1a50c7852e7ad184245d2ea/src/Google/AdsApi/AdWords/Shopping/v201809/ProductPartitions.php#L243-L295 | train |
googleads/googleads-php-lib | src/Google/AdsApi/AdWords/Shopping/v201809/ProductPartitions.php | ProductPartitions.traverseTree | private static function traverseTree(
Criterion $node,
array $children,
$level
) {
$type = 'n/a';
$value = 'n/a';
if ($node->getCaseValue() !== null) {
$type =
(new ReflectionClass($node->getCaseValue()))->getShortName();
if ($node->getCaseValue() instanceof ProductCanonicalCondition) {
$value = $node->getCaseValue()->getCondition();
} elseif ($node->getCaseValue() instanceof
ProductBiddingCategory) {
$value = sprintf(
'%s (%s)',
$node->getCaseValue()->getType(),
$node->getCaseValue()->getValue()
);
} else {
$value = $node->getCaseValue()->getValue();
}
}
$result = sprintf(
"%sID: %d, type: %s, value: %s\n",
str_repeat(" ", $level),
$node->getId(),
$type,
$value
);
foreach ($children[$node->getId()] as $childNode) {
$result .= self::traverseTree($childNode, $children, $level + 1);
}
return $result;
} | php | private static function traverseTree(
Criterion $node,
array $children,
$level
) {
$type = 'n/a';
$value = 'n/a';
if ($node->getCaseValue() !== null) {
$type =
(new ReflectionClass($node->getCaseValue()))->getShortName();
if ($node->getCaseValue() instanceof ProductCanonicalCondition) {
$value = $node->getCaseValue()->getCondition();
} elseif ($node->getCaseValue() instanceof
ProductBiddingCategory) {
$value = sprintf(
'%s (%s)',
$node->getCaseValue()->getType(),
$node->getCaseValue()->getValue()
);
} else {
$value = $node->getCaseValue()->getValue();
}
}
$result = sprintf(
"%sID: %d, type: %s, value: %s\n",
str_repeat(" ", $level),
$node->getId(),
$type,
$value
);
foreach ($children[$node->getId()] as $childNode) {
$result .= self::traverseTree($childNode, $children, $level + 1);
}
return $result;
} | [
"private",
"static",
"function",
"traverseTree",
"(",
"Criterion",
"$",
"node",
",",
"array",
"$",
"children",
",",
"$",
"level",
")",
"{",
"$",
"type",
"=",
"'n/a'",
";",
"$",
"value",
"=",
"'n/a'",
";",
"if",
"(",
"$",
"node",
"->",
"getCaseValue",
"(",
")",
"!==",
"null",
")",
"{",
"$",
"type",
"=",
"(",
"new",
"ReflectionClass",
"(",
"$",
"node",
"->",
"getCaseValue",
"(",
")",
")",
")",
"->",
"getShortName",
"(",
")",
";",
"if",
"(",
"$",
"node",
"->",
"getCaseValue",
"(",
")",
"instanceof",
"ProductCanonicalCondition",
")",
"{",
"$",
"value",
"=",
"$",
"node",
"->",
"getCaseValue",
"(",
")",
"->",
"getCondition",
"(",
")",
";",
"}",
"elseif",
"(",
"$",
"node",
"->",
"getCaseValue",
"(",
")",
"instanceof",
"ProductBiddingCategory",
")",
"{",
"$",
"value",
"=",
"sprintf",
"(",
"'%s (%s)'",
",",
"$",
"node",
"->",
"getCaseValue",
"(",
")",
"->",
"getType",
"(",
")",
",",
"$",
"node",
"->",
"getCaseValue",
"(",
")",
"->",
"getValue",
"(",
")",
")",
";",
"}",
"else",
"{",
"$",
"value",
"=",
"$",
"node",
"->",
"getCaseValue",
"(",
")",
"->",
"getValue",
"(",
")",
";",
"}",
"}",
"$",
"result",
"=",
"sprintf",
"(",
"\"%sID: %d, type: %s, value: %s\\n\"",
",",
"str_repeat",
"(",
"\" \"",
",",
"$",
"level",
")",
",",
"$",
"node",
"->",
"getId",
"(",
")",
",",
"$",
"type",
",",
"$",
"value",
")",
";",
"foreach",
"(",
"$",
"children",
"[",
"$",
"node",
"->",
"getId",
"(",
")",
"]",
"as",
"$",
"childNode",
")",
"{",
"$",
"result",
".=",
"self",
"::",
"traverseTree",
"(",
"$",
"childNode",
",",
"$",
"children",
",",
"$",
"level",
"+",
"1",
")",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | Recursively traverses this tree and returns its string representation. | [
"Recursively",
"traverses",
"this",
"tree",
"and",
"returns",
"its",
"string",
"representation",
"."
] | d552b800ad53c400b1a50c7852e7ad184245d2ea | https://github.com/googleads/googleads-php-lib/blob/d552b800ad53c400b1a50c7852e7ad184245d2ea/src/Google/AdsApi/AdWords/Shopping/v201809/ProductPartitions.php#L300-L337 | train |
googleads/googleads-php-lib | src/Google/AdsApi/Common/Util/OAuth2TokenRefresher.php | OAuth2TokenRefresher.getOrFetchAccessToken | public function getOrFetchAccessToken(
FetchAuthTokenInterface $fetchAuthTokenInterface,
callable $httpHandler = null
) {
if ($this->shouldFetchAccessToken($fetchAuthTokenInterface)) {
return $fetchAuthTokenInterface->fetchAuthToken($httpHandler)
['access_token'];
}
return $fetchAuthTokenInterface->getLastReceivedToken()['access_token'];
} | php | public function getOrFetchAccessToken(
FetchAuthTokenInterface $fetchAuthTokenInterface,
callable $httpHandler = null
) {
if ($this->shouldFetchAccessToken($fetchAuthTokenInterface)) {
return $fetchAuthTokenInterface->fetchAuthToken($httpHandler)
['access_token'];
}
return $fetchAuthTokenInterface->getLastReceivedToken()['access_token'];
} | [
"public",
"function",
"getOrFetchAccessToken",
"(",
"FetchAuthTokenInterface",
"$",
"fetchAuthTokenInterface",
",",
"callable",
"$",
"httpHandler",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"shouldFetchAccessToken",
"(",
"$",
"fetchAuthTokenInterface",
")",
")",
"{",
"return",
"$",
"fetchAuthTokenInterface",
"->",
"fetchAuthToken",
"(",
"$",
"httpHandler",
")",
"[",
"'access_token'",
"]",
";",
"}",
"return",
"$",
"fetchAuthTokenInterface",
"->",
"getLastReceivedToken",
"(",
")",
"[",
"'access_token'",
"]",
";",
"}"
] | Gets the existing access token, or fetches a new one if an existing one is
about to expire within the refresh window, or fetches a new one if there is
no existing access token.
@param FetchAuthTokenInterface $fetchAuthTokenInterface the underlying
OAuth2 access token fetcher
@param callable|null $httpHandler the HTTP handler for making requests
to refresh OAuth2 credentials
@return string | [
"Gets",
"the",
"existing",
"access",
"token",
"or",
"fetches",
"a",
"new",
"one",
"if",
"an",
"existing",
"one",
"is",
"about",
"to",
"expire",
"within",
"the",
"refresh",
"window",
"or",
"fetches",
"a",
"new",
"one",
"if",
"there",
"is",
"no",
"existing",
"access",
"token",
"."
] | d552b800ad53c400b1a50c7852e7ad184245d2ea | https://github.com/googleads/googleads-php-lib/blob/d552b800ad53c400b1a50c7852e7ad184245d2ea/src/Google/AdsApi/Common/Util/OAuth2TokenRefresher.php#L61-L71 | train |
googleads/googleads-php-lib | examples/AdManager/v201811/CustomTargetingService/GetPredefinedCustomTargetingKeysAndValues.php | GetPredefinedCustomTargetingKeysAndValues.getPredefinedCustomTargetingKeyIds | private static function getPredefinedCustomTargetingKeyIds(
ServiceFactory $serviceFactory,
AdManagerSession $session
) {
$customTargetingKeyIds = [];
$customTargetingService = $serviceFactory->createCustomTargetingService(
$session
);
// Create a statement to get all custom targeting keys.
$pageSize = StatementBuilder::SUGGESTED_PAGE_LIMIT;
$statementBuilder = (new StatementBuilder())->where('type = :type')
->orderBy('id ASC')
->limit($pageSize)
->withBindVariableValue('type', CustomTargetingKeyType::PREDEFINED);
// Retrieve a small amount of custom targeting keys at a time, paging
// through until all custom targeting keys have been retrieved.
$totalResultSetSize = 0;
do {
$page = $customTargetingService->getCustomTargetingKeysByStatement(
$statementBuilder->toStatement()
);
if ($page->getResults() !== null) {
$totalResultSetSize = $page->getTotalResultSetSize();
$i = $page->getStartIndex();
foreach ($page->getResults() as $customTargetingKey) {
printf(
"%d) Custom targeting key with ID %d, name '%s', and"
. " display name '%s' was found.%s",
$i++,
$customTargetingKey->getId(),
$customTargetingKey->getName(),
$customTargetingKey->getDisplayName(),
PHP_EOL
);
$customTargetingKeyIds[] = $customTargetingKey->getId();
}
}
$statementBuilder->increaseOffsetBy($pageSize);
} while ($statementBuilder->getOffset() < $totalResultSetSize);
printf(
"Number of keys found: %d%s%s",
$totalResultSetSize,
PHP_EOL,
PHP_EOL
);
return $customTargetingKeyIds;
} | php | private static function getPredefinedCustomTargetingKeyIds(
ServiceFactory $serviceFactory,
AdManagerSession $session
) {
$customTargetingKeyIds = [];
$customTargetingService = $serviceFactory->createCustomTargetingService(
$session
);
// Create a statement to get all custom targeting keys.
$pageSize = StatementBuilder::SUGGESTED_PAGE_LIMIT;
$statementBuilder = (new StatementBuilder())->where('type = :type')
->orderBy('id ASC')
->limit($pageSize)
->withBindVariableValue('type', CustomTargetingKeyType::PREDEFINED);
// Retrieve a small amount of custom targeting keys at a time, paging
// through until all custom targeting keys have been retrieved.
$totalResultSetSize = 0;
do {
$page = $customTargetingService->getCustomTargetingKeysByStatement(
$statementBuilder->toStatement()
);
if ($page->getResults() !== null) {
$totalResultSetSize = $page->getTotalResultSetSize();
$i = $page->getStartIndex();
foreach ($page->getResults() as $customTargetingKey) {
printf(
"%d) Custom targeting key with ID %d, name '%s', and"
. " display name '%s' was found.%s",
$i++,
$customTargetingKey->getId(),
$customTargetingKey->getName(),
$customTargetingKey->getDisplayName(),
PHP_EOL
);
$customTargetingKeyIds[] = $customTargetingKey->getId();
}
}
$statementBuilder->increaseOffsetBy($pageSize);
} while ($statementBuilder->getOffset() < $totalResultSetSize);
printf(
"Number of keys found: %d%s%s",
$totalResultSetSize,
PHP_EOL,
PHP_EOL
);
return $customTargetingKeyIds;
} | [
"private",
"static",
"function",
"getPredefinedCustomTargetingKeyIds",
"(",
"ServiceFactory",
"$",
"serviceFactory",
",",
"AdManagerSession",
"$",
"session",
")",
"{",
"$",
"customTargetingKeyIds",
"=",
"[",
"]",
";",
"$",
"customTargetingService",
"=",
"$",
"serviceFactory",
"->",
"createCustomTargetingService",
"(",
"$",
"session",
")",
";",
"// Create a statement to get all custom targeting keys.",
"$",
"pageSize",
"=",
"StatementBuilder",
"::",
"SUGGESTED_PAGE_LIMIT",
";",
"$",
"statementBuilder",
"=",
"(",
"new",
"StatementBuilder",
"(",
")",
")",
"->",
"where",
"(",
"'type = :type'",
")",
"->",
"orderBy",
"(",
"'id ASC'",
")",
"->",
"limit",
"(",
"$",
"pageSize",
")",
"->",
"withBindVariableValue",
"(",
"'type'",
",",
"CustomTargetingKeyType",
"::",
"PREDEFINED",
")",
";",
"// Retrieve a small amount of custom targeting keys at a time, paging",
"// through until all custom targeting keys have been retrieved.",
"$",
"totalResultSetSize",
"=",
"0",
";",
"do",
"{",
"$",
"page",
"=",
"$",
"customTargetingService",
"->",
"getCustomTargetingKeysByStatement",
"(",
"$",
"statementBuilder",
"->",
"toStatement",
"(",
")",
")",
";",
"if",
"(",
"$",
"page",
"->",
"getResults",
"(",
")",
"!==",
"null",
")",
"{",
"$",
"totalResultSetSize",
"=",
"$",
"page",
"->",
"getTotalResultSetSize",
"(",
")",
";",
"$",
"i",
"=",
"$",
"page",
"->",
"getStartIndex",
"(",
")",
";",
"foreach",
"(",
"$",
"page",
"->",
"getResults",
"(",
")",
"as",
"$",
"customTargetingKey",
")",
"{",
"printf",
"(",
"\"%d) Custom targeting key with ID %d, name '%s', and\"",
".",
"\" display name '%s' was found.%s\"",
",",
"$",
"i",
"++",
",",
"$",
"customTargetingKey",
"->",
"getId",
"(",
")",
",",
"$",
"customTargetingKey",
"->",
"getName",
"(",
")",
",",
"$",
"customTargetingKey",
"->",
"getDisplayName",
"(",
")",
",",
"PHP_EOL",
")",
";",
"$",
"customTargetingKeyIds",
"[",
"]",
"=",
"$",
"customTargetingKey",
"->",
"getId",
"(",
")",
";",
"}",
"}",
"$",
"statementBuilder",
"->",
"increaseOffsetBy",
"(",
"$",
"pageSize",
")",
";",
"}",
"while",
"(",
"$",
"statementBuilder",
"->",
"getOffset",
"(",
")",
"<",
"$",
"totalResultSetSize",
")",
";",
"printf",
"(",
"\"Number of keys found: %d%s%s\"",
",",
"$",
"totalResultSetSize",
",",
"PHP_EOL",
",",
"PHP_EOL",
")",
";",
"return",
"$",
"customTargetingKeyIds",
";",
"}"
] | Gets predefined custom targeting key IDs. | [
"Gets",
"predefined",
"custom",
"targeting",
"key",
"IDs",
"."
] | d552b800ad53c400b1a50c7852e7ad184245d2ea | https://github.com/googleads/googleads-php-lib/blob/d552b800ad53c400b1a50c7852e7ad184245d2ea/examples/AdManager/v201811/CustomTargetingService/GetPredefinedCustomTargetingKeysAndValues.php#L110-L163 | train |
googleads/googleads-php-lib | examples/AdWords/v201809/ShoppingCampaigns/AddShoppingCampaignForShowcaseAds.php | AddShoppingCampaignForShowcaseAds.createAdGroup | private static function createAdGroup(
AdWordsServices $adWordsServices,
AdWordsSession $session,
Campaign $campaign
) {
$adGroupService = $adWordsServices->get($session, AdGroupService::class);
// Create ad group.
$adGroup = new AdGroup();
$adGroup->setCampaignId($campaign->getId());
$adGroup->setName('Ad Group #' . uniqid());
// Required: Set the ad group type to SHOPPING_SHOWCASE_ADS.
$adGroup->setAdGroupType(AdGroupType::SHOPPING_SHOWCASE_ADS);
// Required: Set the ad group's bidding strategy configuration.
// Note: Showcase ads require that the campaign has a ManualCpc
// BiddingStrategyConfiguration.
$biddingStrategyConfiguration = new BiddingStrategyConfiguration();
// Optional: Set the bids.
$bidAmount = new Money();
$bidAmount->setMicroAmount(100000);
$cpcBid = new CpcBid();
$cpcBid->setBid($bidAmount);
$biddingStrategyConfiguration->setBids([$cpcBid]);
$adGroup->setBiddingStrategyConfiguration($biddingStrategyConfiguration);
// Create operation.
$adGroupOperation = new AdGroupOperation();
$adGroupOperation->setOperand($adGroup);
$adGroupOperation->setOperator(Operator::ADD);
// Make the mutate request.
$adGroupAddResult = $adGroupService->mutate([$adGroupOperation]);
$adGroup = $adGroupAddResult->getValue()[0];
return $adGroup;
} | php | private static function createAdGroup(
AdWordsServices $adWordsServices,
AdWordsSession $session,
Campaign $campaign
) {
$adGroupService = $adWordsServices->get($session, AdGroupService::class);
// Create ad group.
$adGroup = new AdGroup();
$adGroup->setCampaignId($campaign->getId());
$adGroup->setName('Ad Group #' . uniqid());
// Required: Set the ad group type to SHOPPING_SHOWCASE_ADS.
$adGroup->setAdGroupType(AdGroupType::SHOPPING_SHOWCASE_ADS);
// Required: Set the ad group's bidding strategy configuration.
// Note: Showcase ads require that the campaign has a ManualCpc
// BiddingStrategyConfiguration.
$biddingStrategyConfiguration = new BiddingStrategyConfiguration();
// Optional: Set the bids.
$bidAmount = new Money();
$bidAmount->setMicroAmount(100000);
$cpcBid = new CpcBid();
$cpcBid->setBid($bidAmount);
$biddingStrategyConfiguration->setBids([$cpcBid]);
$adGroup->setBiddingStrategyConfiguration($biddingStrategyConfiguration);
// Create operation.
$adGroupOperation = new AdGroupOperation();
$adGroupOperation->setOperand($adGroup);
$adGroupOperation->setOperator(Operator::ADD);
// Make the mutate request.
$adGroupAddResult = $adGroupService->mutate([$adGroupOperation]);
$adGroup = $adGroupAddResult->getValue()[0];
return $adGroup;
} | [
"private",
"static",
"function",
"createAdGroup",
"(",
"AdWordsServices",
"$",
"adWordsServices",
",",
"AdWordsSession",
"$",
"session",
",",
"Campaign",
"$",
"campaign",
")",
"{",
"$",
"adGroupService",
"=",
"$",
"adWordsServices",
"->",
"get",
"(",
"$",
"session",
",",
"AdGroupService",
"::",
"class",
")",
";",
"// Create ad group.",
"$",
"adGroup",
"=",
"new",
"AdGroup",
"(",
")",
";",
"$",
"adGroup",
"->",
"setCampaignId",
"(",
"$",
"campaign",
"->",
"getId",
"(",
")",
")",
";",
"$",
"adGroup",
"->",
"setName",
"(",
"'Ad Group #'",
".",
"uniqid",
"(",
")",
")",
";",
"// Required: Set the ad group type to SHOPPING_SHOWCASE_ADS.",
"$",
"adGroup",
"->",
"setAdGroupType",
"(",
"AdGroupType",
"::",
"SHOPPING_SHOWCASE_ADS",
")",
";",
"// Required: Set the ad group's bidding strategy configuration.",
"// Note: Showcase ads require that the campaign has a ManualCpc",
"// BiddingStrategyConfiguration.",
"$",
"biddingStrategyConfiguration",
"=",
"new",
"BiddingStrategyConfiguration",
"(",
")",
";",
"// Optional: Set the bids.",
"$",
"bidAmount",
"=",
"new",
"Money",
"(",
")",
";",
"$",
"bidAmount",
"->",
"setMicroAmount",
"(",
"100000",
")",
";",
"$",
"cpcBid",
"=",
"new",
"CpcBid",
"(",
")",
";",
"$",
"cpcBid",
"->",
"setBid",
"(",
"$",
"bidAmount",
")",
";",
"$",
"biddingStrategyConfiguration",
"->",
"setBids",
"(",
"[",
"$",
"cpcBid",
"]",
")",
";",
"$",
"adGroup",
"->",
"setBiddingStrategyConfiguration",
"(",
"$",
"biddingStrategyConfiguration",
")",
";",
"// Create operation.",
"$",
"adGroupOperation",
"=",
"new",
"AdGroupOperation",
"(",
")",
";",
"$",
"adGroupOperation",
"->",
"setOperand",
"(",
"$",
"adGroup",
")",
";",
"$",
"adGroupOperation",
"->",
"setOperator",
"(",
"Operator",
"::",
"ADD",
")",
";",
"// Make the mutate request.",
"$",
"adGroupAddResult",
"=",
"$",
"adGroupService",
"->",
"mutate",
"(",
"[",
"$",
"adGroupOperation",
"]",
")",
";",
"$",
"adGroup",
"=",
"$",
"adGroupAddResult",
"->",
"getValue",
"(",
")",
"[",
"0",
"]",
";",
"return",
"$",
"adGroup",
";",
"}"
] | Creates an ad group in the Shopping campaign. | [
"Creates",
"an",
"ad",
"group",
"in",
"the",
"Shopping",
"campaign",
"."
] | d552b800ad53c400b1a50c7852e7ad184245d2ea | https://github.com/googleads/googleads-php-lib/blob/d552b800ad53c400b1a50c7852e7ad184245d2ea/examples/AdWords/v201809/ShoppingCampaigns/AddShoppingCampaignForShowcaseAds.php#L162-L201 | train |
googleads/googleads-php-lib | examples/AdWords/v201809/ShoppingCampaigns/AddShoppingCampaignForShowcaseAds.php | AddShoppingCampaignForShowcaseAds.createShowcaseAd | private static function createShowcaseAd(
AdWordsServices $adWordsServices,
AdWordsSession $session,
AdGroup $adGroup
) {
// Create the Showcase ad.
$adGroupAdService = $adWordsServices->get($session, AdGroupAdService::class);
$showcaseAd = new ShowcaseAd();
$showcaseAd->setName('Showcase ad #' . uniqid());
$showcaseAd->setFinalUrls(['http://example.com/showcase']);
$showcaseAd->setDisplayUrl('example.com');
// Required: Set the ad's expanded image.
$expandedImage = new Image();
$expandedImage->setMediaId(
self::uploadImage(
$adWordsServices,
$session,
'https://goo.gl/IfVlpF'
)
);
$showcaseAd->setExpandedImage($expandedImage);
// Optional: Set the collapsed image.
$collapsedImage = new Image();
$collapsedImage->setMediaId(
self::uploadImage(
$adWordsServices,
$session,
'https://goo.gl/NqTxAE'
)
);
$showcaseAd->setCollapsedImage($collapsedImage);
// Create ad group ad.
$adGroupAd = new AdGroupAd();
$adGroupAd->setAdGroupId($adGroup->getId());
$adGroupAd->setAd($showcaseAd);
// Create an ad group ad operation.
$adGroupAdOperation = new AdGroupAdOperation();
$adGroupAdOperation->setOperand($adGroupAd);
$adGroupAdOperation->setOperator(Operator::ADD);
// Creates an ad group ad on the server.
$adGroupAdAddResult = $adGroupAdService->mutate([$adGroupAdOperation]);
$adGroupAd = $adGroupAdAddResult->getValue()[0];
return $adGroupAd;
} | php | private static function createShowcaseAd(
AdWordsServices $adWordsServices,
AdWordsSession $session,
AdGroup $adGroup
) {
// Create the Showcase ad.
$adGroupAdService = $adWordsServices->get($session, AdGroupAdService::class);
$showcaseAd = new ShowcaseAd();
$showcaseAd->setName('Showcase ad #' . uniqid());
$showcaseAd->setFinalUrls(['http://example.com/showcase']);
$showcaseAd->setDisplayUrl('example.com');
// Required: Set the ad's expanded image.
$expandedImage = new Image();
$expandedImage->setMediaId(
self::uploadImage(
$adWordsServices,
$session,
'https://goo.gl/IfVlpF'
)
);
$showcaseAd->setExpandedImage($expandedImage);
// Optional: Set the collapsed image.
$collapsedImage = new Image();
$collapsedImage->setMediaId(
self::uploadImage(
$adWordsServices,
$session,
'https://goo.gl/NqTxAE'
)
);
$showcaseAd->setCollapsedImage($collapsedImage);
// Create ad group ad.
$adGroupAd = new AdGroupAd();
$adGroupAd->setAdGroupId($adGroup->getId());
$adGroupAd->setAd($showcaseAd);
// Create an ad group ad operation.
$adGroupAdOperation = new AdGroupAdOperation();
$adGroupAdOperation->setOperand($adGroupAd);
$adGroupAdOperation->setOperator(Operator::ADD);
// Creates an ad group ad on the server.
$adGroupAdAddResult = $adGroupAdService->mutate([$adGroupAdOperation]);
$adGroupAd = $adGroupAdAddResult->getValue()[0];
return $adGroupAd;
} | [
"private",
"static",
"function",
"createShowcaseAd",
"(",
"AdWordsServices",
"$",
"adWordsServices",
",",
"AdWordsSession",
"$",
"session",
",",
"AdGroup",
"$",
"adGroup",
")",
"{",
"// Create the Showcase ad.",
"$",
"adGroupAdService",
"=",
"$",
"adWordsServices",
"->",
"get",
"(",
"$",
"session",
",",
"AdGroupAdService",
"::",
"class",
")",
";",
"$",
"showcaseAd",
"=",
"new",
"ShowcaseAd",
"(",
")",
";",
"$",
"showcaseAd",
"->",
"setName",
"(",
"'Showcase ad #'",
".",
"uniqid",
"(",
")",
")",
";",
"$",
"showcaseAd",
"->",
"setFinalUrls",
"(",
"[",
"'http://example.com/showcase'",
"]",
")",
";",
"$",
"showcaseAd",
"->",
"setDisplayUrl",
"(",
"'example.com'",
")",
";",
"// Required: Set the ad's expanded image.",
"$",
"expandedImage",
"=",
"new",
"Image",
"(",
")",
";",
"$",
"expandedImage",
"->",
"setMediaId",
"(",
"self",
"::",
"uploadImage",
"(",
"$",
"adWordsServices",
",",
"$",
"session",
",",
"'https://goo.gl/IfVlpF'",
")",
")",
";",
"$",
"showcaseAd",
"->",
"setExpandedImage",
"(",
"$",
"expandedImage",
")",
";",
"// Optional: Set the collapsed image.",
"$",
"collapsedImage",
"=",
"new",
"Image",
"(",
")",
";",
"$",
"collapsedImage",
"->",
"setMediaId",
"(",
"self",
"::",
"uploadImage",
"(",
"$",
"adWordsServices",
",",
"$",
"session",
",",
"'https://goo.gl/NqTxAE'",
")",
")",
";",
"$",
"showcaseAd",
"->",
"setCollapsedImage",
"(",
"$",
"collapsedImage",
")",
";",
"// Create ad group ad.",
"$",
"adGroupAd",
"=",
"new",
"AdGroupAd",
"(",
")",
";",
"$",
"adGroupAd",
"->",
"setAdGroupId",
"(",
"$",
"adGroup",
"->",
"getId",
"(",
")",
")",
";",
"$",
"adGroupAd",
"->",
"setAd",
"(",
"$",
"showcaseAd",
")",
";",
"// Create an ad group ad operation.",
"$",
"adGroupAdOperation",
"=",
"new",
"AdGroupAdOperation",
"(",
")",
";",
"$",
"adGroupAdOperation",
"->",
"setOperand",
"(",
"$",
"adGroupAd",
")",
";",
"$",
"adGroupAdOperation",
"->",
"setOperator",
"(",
"Operator",
"::",
"ADD",
")",
";",
"// Creates an ad group ad on the server.",
"$",
"adGroupAdAddResult",
"=",
"$",
"adGroupAdService",
"->",
"mutate",
"(",
"[",
"$",
"adGroupAdOperation",
"]",
")",
";",
"$",
"adGroupAd",
"=",
"$",
"adGroupAdAddResult",
"->",
"getValue",
"(",
")",
"[",
"0",
"]",
";",
"return",
"$",
"adGroupAd",
";",
"}"
] | Creates a Showcase ad. | [
"Creates",
"a",
"Showcase",
"ad",
"."
] | d552b800ad53c400b1a50c7852e7ad184245d2ea | https://github.com/googleads/googleads-php-lib/blob/d552b800ad53c400b1a50c7852e7ad184245d2ea/examples/AdWords/v201809/ShoppingCampaigns/AddShoppingCampaignForShowcaseAds.php#L204-L254 | train |
googleads/googleads-php-lib | examples/AdWords/v201809/ShoppingCampaigns/AddShoppingCampaignForShowcaseAds.php | AddShoppingCampaignForShowcaseAds.createProductPartitions | private static function createProductPartitions(
AdWordsServices $adWordsServices,
AdWordsSession $session,
$adGroupId
) {
$operations = [];
$root = ProductPartitions::createSubdivision();
$criterion = ProductPartitions::asBiddableAdGroupCriterion($adGroupId, $root);
$operation = ProductPartitions::createAddOperation($criterion);
$operations[] = $operation;
$newCondition = new ProductCanonicalCondition();
$newCondition->setCondition(ProductCanonicalConditionCondition::NEW_VALUE);
$newConditionUnit = ProductPartitions::createUnit($root, $newCondition);
$criterion = ProductPartitions::asBiddableAdGroupCriterion(
$adGroupId,
$newConditionUnit
);
$operation = ProductPartitions::createAddOperation($criterion);
$operations[] = $operation;
$usedCondition = new ProductCanonicalCondition();
$usedCondition->setCondition(ProductCanonicalConditionCondition::USED);
$usedConditionUnit = ProductPartitions::createUnit($root, $usedCondition);
$criterion = ProductPartitions::asBiddableAdGroupCriterion(
$adGroupId,
$usedConditionUnit
);
$operation = ProductPartitions::createAddOperation($criterion);
$operations[] = $operation;
// Exclude everything else.
$excludedUnit = ProductPartitions::createUnit($root, new ProductCanonicalCondition());
$criterion = ProductPartitions::asNegativeAdGroupCriterion(
$adGroupId,
$excludedUnit
);
$operation = ProductPartitions::createAddOperation($criterion);
$operations[] = $operation;
$adGroupCriterionService = $adWordsServices->get($session, AdGroupCriterionService::class);
// Creates ad group criteria on the server.
$adGroupCriterionService->mutate($operations);
} | php | private static function createProductPartitions(
AdWordsServices $adWordsServices,
AdWordsSession $session,
$adGroupId
) {
$operations = [];
$root = ProductPartitions::createSubdivision();
$criterion = ProductPartitions::asBiddableAdGroupCriterion($adGroupId, $root);
$operation = ProductPartitions::createAddOperation($criterion);
$operations[] = $operation;
$newCondition = new ProductCanonicalCondition();
$newCondition->setCondition(ProductCanonicalConditionCondition::NEW_VALUE);
$newConditionUnit = ProductPartitions::createUnit($root, $newCondition);
$criterion = ProductPartitions::asBiddableAdGroupCriterion(
$adGroupId,
$newConditionUnit
);
$operation = ProductPartitions::createAddOperation($criterion);
$operations[] = $operation;
$usedCondition = new ProductCanonicalCondition();
$usedCondition->setCondition(ProductCanonicalConditionCondition::USED);
$usedConditionUnit = ProductPartitions::createUnit($root, $usedCondition);
$criterion = ProductPartitions::asBiddableAdGroupCriterion(
$adGroupId,
$usedConditionUnit
);
$operation = ProductPartitions::createAddOperation($criterion);
$operations[] = $operation;
// Exclude everything else.
$excludedUnit = ProductPartitions::createUnit($root, new ProductCanonicalCondition());
$criterion = ProductPartitions::asNegativeAdGroupCriterion(
$adGroupId,
$excludedUnit
);
$operation = ProductPartitions::createAddOperation($criterion);
$operations[] = $operation;
$adGroupCriterionService = $adWordsServices->get($session, AdGroupCriterionService::class);
// Creates ad group criteria on the server.
$adGroupCriterionService->mutate($operations);
} | [
"private",
"static",
"function",
"createProductPartitions",
"(",
"AdWordsServices",
"$",
"adWordsServices",
",",
"AdWordsSession",
"$",
"session",
",",
"$",
"adGroupId",
")",
"{",
"$",
"operations",
"=",
"[",
"]",
";",
"$",
"root",
"=",
"ProductPartitions",
"::",
"createSubdivision",
"(",
")",
";",
"$",
"criterion",
"=",
"ProductPartitions",
"::",
"asBiddableAdGroupCriterion",
"(",
"$",
"adGroupId",
",",
"$",
"root",
")",
";",
"$",
"operation",
"=",
"ProductPartitions",
"::",
"createAddOperation",
"(",
"$",
"criterion",
")",
";",
"$",
"operations",
"[",
"]",
"=",
"$",
"operation",
";",
"$",
"newCondition",
"=",
"new",
"ProductCanonicalCondition",
"(",
")",
";",
"$",
"newCondition",
"->",
"setCondition",
"(",
"ProductCanonicalConditionCondition",
"::",
"NEW_VALUE",
")",
";",
"$",
"newConditionUnit",
"=",
"ProductPartitions",
"::",
"createUnit",
"(",
"$",
"root",
",",
"$",
"newCondition",
")",
";",
"$",
"criterion",
"=",
"ProductPartitions",
"::",
"asBiddableAdGroupCriterion",
"(",
"$",
"adGroupId",
",",
"$",
"newConditionUnit",
")",
";",
"$",
"operation",
"=",
"ProductPartitions",
"::",
"createAddOperation",
"(",
"$",
"criterion",
")",
";",
"$",
"operations",
"[",
"]",
"=",
"$",
"operation",
";",
"$",
"usedCondition",
"=",
"new",
"ProductCanonicalCondition",
"(",
")",
";",
"$",
"usedCondition",
"->",
"setCondition",
"(",
"ProductCanonicalConditionCondition",
"::",
"USED",
")",
";",
"$",
"usedConditionUnit",
"=",
"ProductPartitions",
"::",
"createUnit",
"(",
"$",
"root",
",",
"$",
"usedCondition",
")",
";",
"$",
"criterion",
"=",
"ProductPartitions",
"::",
"asBiddableAdGroupCriterion",
"(",
"$",
"adGroupId",
",",
"$",
"usedConditionUnit",
")",
";",
"$",
"operation",
"=",
"ProductPartitions",
"::",
"createAddOperation",
"(",
"$",
"criterion",
")",
";",
"$",
"operations",
"[",
"]",
"=",
"$",
"operation",
";",
"// Exclude everything else.",
"$",
"excludedUnit",
"=",
"ProductPartitions",
"::",
"createUnit",
"(",
"$",
"root",
",",
"new",
"ProductCanonicalCondition",
"(",
")",
")",
";",
"$",
"criterion",
"=",
"ProductPartitions",
"::",
"asNegativeAdGroupCriterion",
"(",
"$",
"adGroupId",
",",
"$",
"excludedUnit",
")",
";",
"$",
"operation",
"=",
"ProductPartitions",
"::",
"createAddOperation",
"(",
"$",
"criterion",
")",
";",
"$",
"operations",
"[",
"]",
"=",
"$",
"operation",
";",
"$",
"adGroupCriterionService",
"=",
"$",
"adWordsServices",
"->",
"get",
"(",
"$",
"session",
",",
"AdGroupCriterionService",
"::",
"class",
")",
";",
"// Creates ad group criteria on the server.",
"$",
"adGroupCriterionService",
"->",
"mutate",
"(",
"$",
"operations",
")",
";",
"}"
] | Creates the product partition tree for the ad group. | [
"Creates",
"the",
"product",
"partition",
"tree",
"for",
"the",
"ad",
"group",
"."
] | d552b800ad53c400b1a50c7852e7ad184245d2ea | https://github.com/googleads/googleads-php-lib/blob/d552b800ad53c400b1a50c7852e7ad184245d2ea/examples/AdWords/v201809/ShoppingCampaigns/AddShoppingCampaignForShowcaseAds.php#L257-L302 | train |
googleads/googleads-php-lib | examples/AdWords/v201809/ShoppingCampaigns/AddShoppingCampaignForShowcaseAds.php | AddShoppingCampaignForShowcaseAds.uploadImage | private static function uploadImage(
AdWordsServices $adWordsServices,
AdWordsSession $session,
$url
) {
$mediaService = $adWordsServices->get($session, MediaService::class);
// Create image.
$image = new Image();
$image->setData(file_get_contents($url));
$image->setType(MediaMediaType::IMAGE);
// Upload image into the server.
$result = $mediaService->upload([$image]);
return $result[0]->getMediaId();
} | php | private static function uploadImage(
AdWordsServices $adWordsServices,
AdWordsSession $session,
$url
) {
$mediaService = $adWordsServices->get($session, MediaService::class);
// Create image.
$image = new Image();
$image->setData(file_get_contents($url));
$image->setType(MediaMediaType::IMAGE);
// Upload image into the server.
$result = $mediaService->upload([$image]);
return $result[0]->getMediaId();
} | [
"private",
"static",
"function",
"uploadImage",
"(",
"AdWordsServices",
"$",
"adWordsServices",
",",
"AdWordsSession",
"$",
"session",
",",
"$",
"url",
")",
"{",
"$",
"mediaService",
"=",
"$",
"adWordsServices",
"->",
"get",
"(",
"$",
"session",
",",
"MediaService",
"::",
"class",
")",
";",
"// Create image.",
"$",
"image",
"=",
"new",
"Image",
"(",
")",
";",
"$",
"image",
"->",
"setData",
"(",
"file_get_contents",
"(",
"$",
"url",
")",
")",
";",
"$",
"image",
"->",
"setType",
"(",
"MediaMediaType",
"::",
"IMAGE",
")",
";",
"// Upload image into the server.",
"$",
"result",
"=",
"$",
"mediaService",
"->",
"upload",
"(",
"[",
"$",
"image",
"]",
")",
";",
"return",
"$",
"result",
"[",
"0",
"]",
"->",
"getMediaId",
"(",
")",
";",
"}"
] | Uploads an image. | [
"Uploads",
"an",
"image",
"."
] | d552b800ad53c400b1a50c7852e7ad184245d2ea | https://github.com/googleads/googleads-php-lib/blob/d552b800ad53c400b1a50c7852e7ad184245d2ea/examples/AdWords/v201809/ShoppingCampaigns/AddShoppingCampaignForShowcaseAds.php#L305-L321 | train |
googleads/googleads-php-lib | src/Google/AdsApi/Common/AdsHeaderFormatter.php | AdsHeaderFormatter.formatApplicationNameForSoapHeader | public function formatApplicationNameForSoapHeader(
$applicationName,
$productNameForSoapHeader,
$includeUtilityUsage
) {
$adsUtilities = $this->adsUtilityRegistry->popAllUtilities();
return sprintf(
'%s (%sApi-PHP, %s/%s, PHP/%s%s)',
$applicationName,
$productNameForSoapHeader,
$this->libraryMetadataProvider->getLibName(),
$this->libraryMetadataProvider->getLibVersion(),
PHP_VERSION,
$this->formatUtilUsages($adsUtilities, $includeUtilityUsage)
);
} | php | public function formatApplicationNameForSoapHeader(
$applicationName,
$productNameForSoapHeader,
$includeUtilityUsage
) {
$adsUtilities = $this->adsUtilityRegistry->popAllUtilities();
return sprintf(
'%s (%sApi-PHP, %s/%s, PHP/%s%s)',
$applicationName,
$productNameForSoapHeader,
$this->libraryMetadataProvider->getLibName(),
$this->libraryMetadataProvider->getLibVersion(),
PHP_VERSION,
$this->formatUtilUsages($adsUtilities, $includeUtilityUsage)
);
} | [
"public",
"function",
"formatApplicationNameForSoapHeader",
"(",
"$",
"applicationName",
",",
"$",
"productNameForSoapHeader",
",",
"$",
"includeUtilityUsage",
")",
"{",
"$",
"adsUtilities",
"=",
"$",
"this",
"->",
"adsUtilityRegistry",
"->",
"popAllUtilities",
"(",
")",
";",
"return",
"sprintf",
"(",
"'%s (%sApi-PHP, %s/%s, PHP/%s%s)'",
",",
"$",
"applicationName",
",",
"$",
"productNameForSoapHeader",
",",
"$",
"this",
"->",
"libraryMetadataProvider",
"->",
"getLibName",
"(",
")",
",",
"$",
"this",
"->",
"libraryMetadataProvider",
"->",
"getLibVersion",
"(",
")",
",",
"PHP_VERSION",
",",
"$",
"this",
"->",
"formatUtilUsages",
"(",
"$",
"adsUtilities",
",",
"$",
"includeUtilityUsage",
")",
")",
";",
"}"
] | Formats an application name in a format standard to the ads libraries to
include in the SOAP header.
@param string $applicationName the application name to format
@param string $productNameForSoapHeader the ads product API calls are
being made against, formatted to be used in the SOAP header
@param boolean $includeUtilityUsage true if logging of utilities usages is
turned on
@return string the formatted application name | [
"Formats",
"an",
"application",
"name",
"in",
"a",
"format",
"standard",
"to",
"the",
"ads",
"libraries",
"to",
"include",
"in",
"the",
"SOAP",
"header",
"."
] | d552b800ad53c400b1a50c7852e7ad184245d2ea | https://github.com/googleads/googleads-php-lib/blob/d552b800ad53c400b1a50c7852e7ad184245d2ea/src/Google/AdsApi/Common/AdsHeaderFormatter.php#L59-L75 | train |
googleads/googleads-php-lib | src/Google/AdsApi/Common/AdsHeaderFormatter.php | AdsHeaderFormatter.formatApplicationNameForGuzzleHeader | public function formatApplicationNameForGuzzleHeader(
$applicationName,
$productName,
$includeUtilityUsage,
$isReportingGzipEnabled = null
) {
$adsUtilities = $this->adsUtilityRegistry->popAllUtilities();
return sprintf(
'%s (%sApi-PHP, %s/%s, PHP/%s, %s%s%s)',
$applicationName,
$productName,
$this->libraryMetadataProvider->getLibName(),
$this->libraryMetadataProvider->getLibVersion(),
PHP_VERSION,
$this->formatGuzzleInfo(),
$this->formatUtilUsages($adsUtilities, $includeUtilityUsage),
$isReportingGzipEnabled === true ? ', gzip' : ''
);
} | php | public function formatApplicationNameForGuzzleHeader(
$applicationName,
$productName,
$includeUtilityUsage,
$isReportingGzipEnabled = null
) {
$adsUtilities = $this->adsUtilityRegistry->popAllUtilities();
return sprintf(
'%s (%sApi-PHP, %s/%s, PHP/%s, %s%s%s)',
$applicationName,
$productName,
$this->libraryMetadataProvider->getLibName(),
$this->libraryMetadataProvider->getLibVersion(),
PHP_VERSION,
$this->formatGuzzleInfo(),
$this->formatUtilUsages($adsUtilities, $includeUtilityUsage),
$isReportingGzipEnabled === true ? ', gzip' : ''
);
} | [
"public",
"function",
"formatApplicationNameForGuzzleHeader",
"(",
"$",
"applicationName",
",",
"$",
"productName",
",",
"$",
"includeUtilityUsage",
",",
"$",
"isReportingGzipEnabled",
"=",
"null",
")",
"{",
"$",
"adsUtilities",
"=",
"$",
"this",
"->",
"adsUtilityRegistry",
"->",
"popAllUtilities",
"(",
")",
";",
"return",
"sprintf",
"(",
"'%s (%sApi-PHP, %s/%s, PHP/%s, %s%s%s)'",
",",
"$",
"applicationName",
",",
"$",
"productName",
",",
"$",
"this",
"->",
"libraryMetadataProvider",
"->",
"getLibName",
"(",
")",
",",
"$",
"this",
"->",
"libraryMetadataProvider",
"->",
"getLibVersion",
"(",
")",
",",
"PHP_VERSION",
",",
"$",
"this",
"->",
"formatGuzzleInfo",
"(",
")",
",",
"$",
"this",
"->",
"formatUtilUsages",
"(",
"$",
"adsUtilities",
",",
"$",
"includeUtilityUsage",
")",
",",
"$",
"isReportingGzipEnabled",
"===",
"true",
"?",
"', gzip'",
":",
"''",
")",
";",
"}"
] | Formats an application name in a format standard to the ads libraries to
include in the Guzzle HTTP header.
@param string $applicationName the application name to format
@param string $productName the ads product API calls are being made against
@param boolean $includeUtilityUsage true if logging of utilities usages is
turned on
@param null|boolean $isReportingGzipEnabled true if the user agent should
include "gzip" to indicate that this request should be gzip-compressed
@return string the formatted application name | [
"Formats",
"an",
"application",
"name",
"in",
"a",
"format",
"standard",
"to",
"the",
"ads",
"libraries",
"to",
"include",
"in",
"the",
"Guzzle",
"HTTP",
"header",
"."
] | d552b800ad53c400b1a50c7852e7ad184245d2ea | https://github.com/googleads/googleads-php-lib/blob/d552b800ad53c400b1a50c7852e7ad184245d2ea/src/Google/AdsApi/Common/AdsHeaderFormatter.php#L89-L108 | train |
googleads/googleads-php-lib | src/Google/AdsApi/AdWords/BatchJobs/BatchJobUploadStatus.php | BatchJobUploadStatus.initiateResumableUpload | private function initiateResumableUpload($uploadUrl)
{
$requestOptions = [];
$requestOptions[RequestOptions::HEADERS] = [
'Content-Type' => 'application/xml',
'Content-Length' => 0,
'x-goog-resumable' => 'start'
];
if (!empty($this->connectionSettings->getProxyUrl())) {
$requestOptions[RequestOptions::PROXY] = [
'https' => $this->connectionSettings->getProxyUrl()
];
}
// This follows the Google Cloud Storage guidelines for initiating
// resumable uploads:
// https://cloud.google.com/storage/docs/resumable-uploads-xml
$response =
$this->httpClient->request('POST', $uploadUrl, $requestOptions);
return $response->getHeader('Location')[0];
} | php | private function initiateResumableUpload($uploadUrl)
{
$requestOptions = [];
$requestOptions[RequestOptions::HEADERS] = [
'Content-Type' => 'application/xml',
'Content-Length' => 0,
'x-goog-resumable' => 'start'
];
if (!empty($this->connectionSettings->getProxyUrl())) {
$requestOptions[RequestOptions::PROXY] = [
'https' => $this->connectionSettings->getProxyUrl()
];
}
// This follows the Google Cloud Storage guidelines for initiating
// resumable uploads:
// https://cloud.google.com/storage/docs/resumable-uploads-xml
$response =
$this->httpClient->request('POST', $uploadUrl, $requestOptions);
return $response->getHeader('Location')[0];
} | [
"private",
"function",
"initiateResumableUpload",
"(",
"$",
"uploadUrl",
")",
"{",
"$",
"requestOptions",
"=",
"[",
"]",
";",
"$",
"requestOptions",
"[",
"RequestOptions",
"::",
"HEADERS",
"]",
"=",
"[",
"'Content-Type'",
"=>",
"'application/xml'",
",",
"'Content-Length'",
"=>",
"0",
",",
"'x-goog-resumable'",
"=>",
"'start'",
"]",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"connectionSettings",
"->",
"getProxyUrl",
"(",
")",
")",
")",
"{",
"$",
"requestOptions",
"[",
"RequestOptions",
"::",
"PROXY",
"]",
"=",
"[",
"'https'",
"=>",
"$",
"this",
"->",
"connectionSettings",
"->",
"getProxyUrl",
"(",
")",
"]",
";",
"}",
"// This follows the Google Cloud Storage guidelines for initiating",
"// resumable uploads:",
"// https://cloud.google.com/storage/docs/resumable-uploads-xml",
"$",
"response",
"=",
"$",
"this",
"->",
"httpClient",
"->",
"request",
"(",
"'POST'",
",",
"$",
"uploadUrl",
",",
"$",
"requestOptions",
")",
";",
"return",
"$",
"response",
"->",
"getHeader",
"(",
"'Location'",
")",
"[",
"0",
"]",
";",
"}"
] | Initiates the resumable upload by sending a request to Google Cloud
Storage.
@param string $uploadUrl the upload URL of a batch job
@return string the URL for the initiated resumable upload | [
"Initiates",
"the",
"resumable",
"upload",
"by",
"sending",
"a",
"request",
"to",
"Google",
"Cloud",
"Storage",
"."
] | d552b800ad53c400b1a50c7852e7ad184245d2ea | https://github.com/googleads/googleads-php-lib/blob/d552b800ad53c400b1a50c7852e7ad184245d2ea/src/Google/AdsApi/AdWords/BatchJobs/BatchJobUploadStatus.php#L88-L108 | train |
googleads/googleads-php-lib | src/Google/AdsApi/Common/AdsSoapClientFactory.php | AdsSoapClientFactory.generateSoapClient | public function generateSoapClient(
AdsSession $session,
AdsHeaderHandler $headerHandler,
AdsServiceDescriptor $serviceDescriptor
) {
$options = [
'trace' => true,
'encoding' => 'utf-8',
'connection_timeout' => $this->soapCallTimeout,
'features' => SOAP_SINGLE_ELEMENT_ARRAYS
];
$soapSettings = $session->getSoapSettings();
$options = $this->populateOptions($session, $options, $soapSettings);
$soapClient = $this->reflection->createInstance(
$serviceDescriptor->getServiceClass(),
$options
);
$soapClient->setStreamContext($options['stream_context']);
$soapClient->setSoapLogMessageFormatter($this->soapLogMessageFormatter);
$soapClient->setAdsSession($session);
$soapClient->setHeaderHandler($headerHandler);
$soapClient->setServiceDescriptor($serviceDescriptor);
$soapClient->setSoapCallTimeout($this->soapCallTimeout);
$soapClient->__setLocation(
str_replace(
sprintf(
'%s://%s',
parse_url($soapClient->getWsdlUri(), PHP_URL_SCHEME),
parse_url($soapClient->getWsdlUri(), PHP_URL_HOST)
),
rtrim($session->getEndpoint(), '/'),
$soapClient->getWsdlUri()
)
);
return $soapClient;
} | php | public function generateSoapClient(
AdsSession $session,
AdsHeaderHandler $headerHandler,
AdsServiceDescriptor $serviceDescriptor
) {
$options = [
'trace' => true,
'encoding' => 'utf-8',
'connection_timeout' => $this->soapCallTimeout,
'features' => SOAP_SINGLE_ELEMENT_ARRAYS
];
$soapSettings = $session->getSoapSettings();
$options = $this->populateOptions($session, $options, $soapSettings);
$soapClient = $this->reflection->createInstance(
$serviceDescriptor->getServiceClass(),
$options
);
$soapClient->setStreamContext($options['stream_context']);
$soapClient->setSoapLogMessageFormatter($this->soapLogMessageFormatter);
$soapClient->setAdsSession($session);
$soapClient->setHeaderHandler($headerHandler);
$soapClient->setServiceDescriptor($serviceDescriptor);
$soapClient->setSoapCallTimeout($this->soapCallTimeout);
$soapClient->__setLocation(
str_replace(
sprintf(
'%s://%s',
parse_url($soapClient->getWsdlUri(), PHP_URL_SCHEME),
parse_url($soapClient->getWsdlUri(), PHP_URL_HOST)
),
rtrim($session->getEndpoint(), '/'),
$soapClient->getWsdlUri()
)
);
return $soapClient;
} | [
"public",
"function",
"generateSoapClient",
"(",
"AdsSession",
"$",
"session",
",",
"AdsHeaderHandler",
"$",
"headerHandler",
",",
"AdsServiceDescriptor",
"$",
"serviceDescriptor",
")",
"{",
"$",
"options",
"=",
"[",
"'trace'",
"=>",
"true",
",",
"'encoding'",
"=>",
"'utf-8'",
",",
"'connection_timeout'",
"=>",
"$",
"this",
"->",
"soapCallTimeout",
",",
"'features'",
"=>",
"SOAP_SINGLE_ELEMENT_ARRAYS",
"]",
";",
"$",
"soapSettings",
"=",
"$",
"session",
"->",
"getSoapSettings",
"(",
")",
";",
"$",
"options",
"=",
"$",
"this",
"->",
"populateOptions",
"(",
"$",
"session",
",",
"$",
"options",
",",
"$",
"soapSettings",
")",
";",
"$",
"soapClient",
"=",
"$",
"this",
"->",
"reflection",
"->",
"createInstance",
"(",
"$",
"serviceDescriptor",
"->",
"getServiceClass",
"(",
")",
",",
"$",
"options",
")",
";",
"$",
"soapClient",
"->",
"setStreamContext",
"(",
"$",
"options",
"[",
"'stream_context'",
"]",
")",
";",
"$",
"soapClient",
"->",
"setSoapLogMessageFormatter",
"(",
"$",
"this",
"->",
"soapLogMessageFormatter",
")",
";",
"$",
"soapClient",
"->",
"setAdsSession",
"(",
"$",
"session",
")",
";",
"$",
"soapClient",
"->",
"setHeaderHandler",
"(",
"$",
"headerHandler",
")",
";",
"$",
"soapClient",
"->",
"setServiceDescriptor",
"(",
"$",
"serviceDescriptor",
")",
";",
"$",
"soapClient",
"->",
"setSoapCallTimeout",
"(",
"$",
"this",
"->",
"soapCallTimeout",
")",
";",
"$",
"soapClient",
"->",
"__setLocation",
"(",
"str_replace",
"(",
"sprintf",
"(",
"'%s://%s'",
",",
"parse_url",
"(",
"$",
"soapClient",
"->",
"getWsdlUri",
"(",
")",
",",
"PHP_URL_SCHEME",
")",
",",
"parse_url",
"(",
"$",
"soapClient",
"->",
"getWsdlUri",
"(",
")",
",",
"PHP_URL_HOST",
")",
")",
",",
"rtrim",
"(",
"$",
"session",
"->",
"getEndpoint",
"(",
")",
",",
"'/'",
")",
",",
"$",
"soapClient",
"->",
"getWsdlUri",
"(",
")",
")",
")",
";",
"return",
"$",
"soapClient",
";",
"}"
] | Generates a SOAP client that interfaces with the specified service using
configuration data from the specified ads session.
@param AdsSession $session the session to read configuration information
from
@param AdsHeaderHandler $headerHandler the header handler that will
generate HTTP and SOAP headers
@param AdsServiceDescriptor $serviceDescriptor descriptor for the service
the SOAP client is being generated to interface with
@return \SoapClient a SOAP client
@throws \UnexpectedValueException if the SOAP client could not be generated | [
"Generates",
"a",
"SOAP",
"client",
"that",
"interfaces",
"with",
"the",
"specified",
"service",
"using",
"configuration",
"data",
"from",
"the",
"specified",
"ads",
"session",
"."
] | d552b800ad53c400b1a50c7852e7ad184245d2ea | https://github.com/googleads/googleads-php-lib/blob/d552b800ad53c400b1a50c7852e7ad184245d2ea/src/Google/AdsApi/Common/AdsSoapClientFactory.php#L72-L110 | train |
googleads/googleads-php-lib | src/Google/AdsApi/Common/AdsSoapClient.php | AdsSoapClient.getLocalWsdlPath | private function getLocalWsdlPath($wsdl)
{
$resourcesWsdlsPath = sprintf(
self::$RESOURCES_WSDLS_PATH_FORMAT,
__DIR__,
DIRECTORY_SEPARATOR
);
// parse_url() returns the path part of any URLs, which may be composed of
// many sub-paths delimited by forward slashes. We replace them with
// DIRECTORY_SEPARATOR (which works with any OSs) here to get paths to local
// WSDLs.
$wsdlFilePath = str_replace(
'/',
DIRECTORY_SEPARATOR,
parse_url($wsdl, PHP_URL_PATH)
);
return $resourcesWsdlsPath . $wsdlFilePath . self::$WSDL_FILE_EXTENSION;
} | php | private function getLocalWsdlPath($wsdl)
{
$resourcesWsdlsPath = sprintf(
self::$RESOURCES_WSDLS_PATH_FORMAT,
__DIR__,
DIRECTORY_SEPARATOR
);
// parse_url() returns the path part of any URLs, which may be composed of
// many sub-paths delimited by forward slashes. We replace them with
// DIRECTORY_SEPARATOR (which works with any OSs) here to get paths to local
// WSDLs.
$wsdlFilePath = str_replace(
'/',
DIRECTORY_SEPARATOR,
parse_url($wsdl, PHP_URL_PATH)
);
return $resourcesWsdlsPath . $wsdlFilePath . self::$WSDL_FILE_EXTENSION;
} | [
"private",
"function",
"getLocalWsdlPath",
"(",
"$",
"wsdl",
")",
"{",
"$",
"resourcesWsdlsPath",
"=",
"sprintf",
"(",
"self",
"::",
"$",
"RESOURCES_WSDLS_PATH_FORMAT",
",",
"__DIR__",
",",
"DIRECTORY_SEPARATOR",
")",
";",
"// parse_url() returns the path part of any URLs, which may be composed of",
"// many sub-paths delimited by forward slashes. We replace them with",
"// DIRECTORY_SEPARATOR (which works with any OSs) here to get paths to local",
"// WSDLs.",
"$",
"wsdlFilePath",
"=",
"str_replace",
"(",
"'/'",
",",
"DIRECTORY_SEPARATOR",
",",
"parse_url",
"(",
"$",
"wsdl",
",",
"PHP_URL_PATH",
")",
")",
";",
"return",
"$",
"resourcesWsdlsPath",
".",
"$",
"wsdlFilePath",
".",
"self",
"::",
"$",
"WSDL_FILE_EXTENSION",
";",
"}"
] | Gets the path to stored WSDLs from the provided live WSDL URI. | [
"Gets",
"the",
"path",
"to",
"stored",
"WSDLs",
"from",
"the",
"provided",
"live",
"WSDL",
"URI",
"."
] | d552b800ad53c400b1a50c7852e7ad184245d2ea | https://github.com/googleads/googleads-php-lib/blob/d552b800ad53c400b1a50c7852e7ad184245d2ea/src/Google/AdsApi/Common/AdsSoapClient.php#L430-L448 | train |
googleads/googleads-php-lib | src/Google/AdsApi/AdManager/Util/v201805/CsvFiles.php | CsvFiles.writeCsvToStream | public static function writeCsvToStream(array $csvData, $handle)
{
if (is_null($handle)) {
throw new InvalidArgumentException('File handle is null.');
}
foreach ($csvData as $line) {
fputcsv($handle, $line);
}
} | php | public static function writeCsvToStream(array $csvData, $handle)
{
if (is_null($handle)) {
throw new InvalidArgumentException('File handle is null.');
}
foreach ($csvData as $line) {
fputcsv($handle, $line);
}
} | [
"public",
"static",
"function",
"writeCsvToStream",
"(",
"array",
"$",
"csvData",
",",
"$",
"handle",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"handle",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'File handle is null.'",
")",
";",
"}",
"foreach",
"(",
"$",
"csvData",
"as",
"$",
"line",
")",
"{",
"fputcsv",
"(",
"$",
"handle",
",",
"$",
"line",
")",
";",
"}",
"}"
] | Writes the CSV data to a stream handle.
@param array $csvData the CSV data including the header
@param resource $handle the stream handle to write the CSV data to
@throws InvalidArgumentException if `$csvData` is null or
`$fileName` is null | [
"Writes",
"the",
"CSV",
"data",
"to",
"a",
"stream",
"handle",
"."
] | d552b800ad53c400b1a50c7852e7ad184245d2ea | https://github.com/googleads/googleads-php-lib/blob/d552b800ad53c400b1a50c7852e7ad184245d2ea/src/Google/AdsApi/AdManager/Util/v201805/CsvFiles.php#L69-L78 | train |
googleads/googleads-php-lib | examples/AdWords/v201809/Optimization/EstimateKeywordTraffic.php | EstimateKeywordTraffic.printMeanEstimate | private static function printMeanEstimate(
StatsEstimate $minEstimate,
StatsEstimate $maxEstimate
) {
$meanAverageCpc = self::calculateMeanMicroAmount(
$minEstimate->getAverageCpc(),
$maxEstimate->getAverageCpc()
);
$meanAveragePosition = self::calculateMean(
$minEstimate->getAveragePosition(),
$maxEstimate->getAveragePosition()
);
$meanClicks = self::calculateMean(
$minEstimate->getClicksPerDay(),
$maxEstimate->getClicksPerDay()
);
$meanTotalCost = self::calculateMeanMicroAmount(
$minEstimate->getTotalCost(),
$maxEstimate->getTotalCost()
);
printf(
" Estimated average CPC: %s\n",
self::formatMean($meanAverageCpc)
);
printf(
" Estimated ad position: %s\n",
self::formatMean($meanAveragePosition)
);
printf(" Estimated daily clicks: %s\n", self::formatMean($meanClicks));
printf(
" Estimated daily cost: %s\n\n",
self::formatMean($meanTotalCost)
);
} | php | private static function printMeanEstimate(
StatsEstimate $minEstimate,
StatsEstimate $maxEstimate
) {
$meanAverageCpc = self::calculateMeanMicroAmount(
$minEstimate->getAverageCpc(),
$maxEstimate->getAverageCpc()
);
$meanAveragePosition = self::calculateMean(
$minEstimate->getAveragePosition(),
$maxEstimate->getAveragePosition()
);
$meanClicks = self::calculateMean(
$minEstimate->getClicksPerDay(),
$maxEstimate->getClicksPerDay()
);
$meanTotalCost = self::calculateMeanMicroAmount(
$minEstimate->getTotalCost(),
$maxEstimate->getTotalCost()
);
printf(
" Estimated average CPC: %s\n",
self::formatMean($meanAverageCpc)
);
printf(
" Estimated ad position: %s\n",
self::formatMean($meanAveragePosition)
);
printf(" Estimated daily clicks: %s\n", self::formatMean($meanClicks));
printf(
" Estimated daily cost: %s\n\n",
self::formatMean($meanTotalCost)
);
} | [
"private",
"static",
"function",
"printMeanEstimate",
"(",
"StatsEstimate",
"$",
"minEstimate",
",",
"StatsEstimate",
"$",
"maxEstimate",
")",
"{",
"$",
"meanAverageCpc",
"=",
"self",
"::",
"calculateMeanMicroAmount",
"(",
"$",
"minEstimate",
"->",
"getAverageCpc",
"(",
")",
",",
"$",
"maxEstimate",
"->",
"getAverageCpc",
"(",
")",
")",
";",
"$",
"meanAveragePosition",
"=",
"self",
"::",
"calculateMean",
"(",
"$",
"minEstimate",
"->",
"getAveragePosition",
"(",
")",
",",
"$",
"maxEstimate",
"->",
"getAveragePosition",
"(",
")",
")",
";",
"$",
"meanClicks",
"=",
"self",
"::",
"calculateMean",
"(",
"$",
"minEstimate",
"->",
"getClicksPerDay",
"(",
")",
",",
"$",
"maxEstimate",
"->",
"getClicksPerDay",
"(",
")",
")",
";",
"$",
"meanTotalCost",
"=",
"self",
"::",
"calculateMeanMicroAmount",
"(",
"$",
"minEstimate",
"->",
"getTotalCost",
"(",
")",
",",
"$",
"maxEstimate",
"->",
"getTotalCost",
"(",
")",
")",
";",
"printf",
"(",
"\" Estimated average CPC: %s\\n\"",
",",
"self",
"::",
"formatMean",
"(",
"$",
"meanAverageCpc",
")",
")",
";",
"printf",
"(",
"\" Estimated ad position: %s\\n\"",
",",
"self",
"::",
"formatMean",
"(",
"$",
"meanAveragePosition",
")",
")",
";",
"printf",
"(",
"\" Estimated daily clicks: %s\\n\"",
",",
"self",
"::",
"formatMean",
"(",
"$",
"meanClicks",
")",
")",
";",
"printf",
"(",
"\" Estimated daily cost: %s\\n\\n\"",
",",
"self",
"::",
"formatMean",
"(",
"$",
"meanTotalCost",
")",
")",
";",
"}"
] | Prints estimated average CPC, ad position, daily clicks, and daily costs
between the provided lower bound and upper bound of estimated stats.
@param StatsEstimate $minEstimate the lower bound on the estimated stats
@param StatsEstimate $maxEstimate the upper bound on the estimated stats | [
"Prints",
"estimated",
"average",
"CPC",
"ad",
"position",
"daily",
"clicks",
"and",
"daily",
"costs",
"between",
"the",
"provided",
"lower",
"bound",
"and",
"upper",
"bound",
"of",
"estimated",
"stats",
"."
] | d552b800ad53c400b1a50c7852e7ad184245d2ea | https://github.com/googleads/googleads-php-lib/blob/d552b800ad53c400b1a50c7852e7ad184245d2ea/examples/AdWords/v201809/Optimization/EstimateKeywordTraffic.php#L183-L220 | train |
googleads/googleads-php-lib | examples/AdWords/v201809/Optimization/EstimateKeywordTraffic.php | EstimateKeywordTraffic.calculateMean | private static function calculateMean($min, $max)
{
if ($min === null || $max === null) {
return null;
}
return ($min + $max) / 2;
} | php | private static function calculateMean($min, $max)
{
if ($min === null || $max === null) {
return null;
}
return ($min + $max) / 2;
} | [
"private",
"static",
"function",
"calculateMean",
"(",
"$",
"min",
",",
"$",
"max",
")",
"{",
"if",
"(",
"$",
"min",
"===",
"null",
"||",
"$",
"max",
"===",
"null",
")",
"{",
"return",
"null",
";",
"}",
"return",
"(",
"$",
"min",
"+",
"$",
"max",
")",
"/",
"2",
";",
"}"
] | Returns the mean of the two numbers if neither is null, else returns null. | [
"Returns",
"the",
"mean",
"of",
"the",
"two",
"numbers",
"if",
"neither",
"is",
"null",
"else",
"returns",
"null",
"."
] | d552b800ad53c400b1a50c7852e7ad184245d2ea | https://github.com/googleads/googleads-php-lib/blob/d552b800ad53c400b1a50c7852e7ad184245d2ea/examples/AdWords/v201809/Optimization/EstimateKeywordTraffic.php#L225-L232 | train |
googleads/googleads-php-lib | examples/AdWords/v201809/Optimization/EstimateKeywordTraffic.php | EstimateKeywordTraffic.calculateMeanMicroAmount | private static function calculateMeanMicroAmount($min, $max)
{
if ($min === null || $max === null) {
return null;
}
if ($min->getMicroAmount() === null
|| $max->getMicroAmount() === null) {
return null;
}
return ($min->getMicroAmount() + $max->getMicroAmount()) / 2;
} | php | private static function calculateMeanMicroAmount($min, $max)
{
if ($min === null || $max === null) {
return null;
}
if ($min->getMicroAmount() === null
|| $max->getMicroAmount() === null) {
return null;
}
return ($min->getMicroAmount() + $max->getMicroAmount()) / 2;
} | [
"private",
"static",
"function",
"calculateMeanMicroAmount",
"(",
"$",
"min",
",",
"$",
"max",
")",
"{",
"if",
"(",
"$",
"min",
"===",
"null",
"||",
"$",
"max",
"===",
"null",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"$",
"min",
"->",
"getMicroAmount",
"(",
")",
"===",
"null",
"||",
"$",
"max",
"->",
"getMicroAmount",
"(",
")",
"===",
"null",
")",
"{",
"return",
"null",
";",
"}",
"return",
"(",
"$",
"min",
"->",
"getMicroAmount",
"(",
")",
"+",
"$",
"max",
"->",
"getMicroAmount",
"(",
")",
")",
"/",
"2",
";",
"}"
] | Returns the mean of the two object's microAmounts if neither is null, else
returns null. | [
"Returns",
"the",
"mean",
"of",
"the",
"two",
"object",
"s",
"microAmounts",
"if",
"neither",
"is",
"null",
"else",
"returns",
"null",
"."
] | d552b800ad53c400b1a50c7852e7ad184245d2ea | https://github.com/googleads/googleads-php-lib/blob/d552b800ad53c400b1a50c7852e7ad184245d2ea/examples/AdWords/v201809/Optimization/EstimateKeywordTraffic.php#L238-L249 | train |
googleads/googleads-php-lib | src/Google/AdsApi/AdWords/BatchJobs/v201809/BatchJobs.php | BatchJobs.uploadBatchJobOperations | public function uploadBatchJobOperations(array $operations, $uploadUrl)
{
$this->adsUtilityRegistry->addUtility(AdsUtility::BATCH_JOBS);
return $this->batchJobsDelegate->uploadBatchJobOperations(
$operations,
$uploadUrl
);
} | php | public function uploadBatchJobOperations(array $operations, $uploadUrl)
{
$this->adsUtilityRegistry->addUtility(AdsUtility::BATCH_JOBS);
return $this->batchJobsDelegate->uploadBatchJobOperations(
$operations,
$uploadUrl
);
} | [
"public",
"function",
"uploadBatchJobOperations",
"(",
"array",
"$",
"operations",
",",
"$",
"uploadUrl",
")",
"{",
"$",
"this",
"->",
"adsUtilityRegistry",
"->",
"addUtility",
"(",
"AdsUtility",
"::",
"BATCH_JOBS",
")",
";",
"return",
"$",
"this",
"->",
"batchJobsDelegate",
"->",
"uploadBatchJobOperations",
"(",
"$",
"operations",
",",
"$",
"uploadUrl",
")",
";",
"}"
] | Uploads all batch job operations to the specified upload URL.
@param array $operations operations to be uploaded via the upload URL
$uploadUrl
@param string $uploadUrl the upload URL for uploading operations
@return BatchJobUploadStatus the updated batch job upload status
@throws ApiException if the upload process failed | [
"Uploads",
"all",
"batch",
"job",
"operations",
"to",
"the",
"specified",
"upload",
"URL",
"."
] | d552b800ad53c400b1a50c7852e7ad184245d2ea | https://github.com/googleads/googleads-php-lib/blob/d552b800ad53c400b1a50c7852e7ad184245d2ea/src/Google/AdsApi/AdWords/BatchJobs/v201809/BatchJobs.php#L86-L94 | train |
googleads/googleads-php-lib | src/Google/AdsApi/AdWords/BatchJobs/v201809/BatchJobs.php | BatchJobs.uploadIncrementalBatchJobOperations | public function uploadIncrementalBatchJobOperations(
array $operations,
BatchJobUploadStatus $batchJobUploadStatus
) {
$this->adsUtilityRegistry->addUtility(AdsUtility::BATCH_JOBS);
return $this->batchJobsDelegate->uploadIncrementalBatchJobOperations(
$operations,
$batchJobUploadStatus
);
} | php | public function uploadIncrementalBatchJobOperations(
array $operations,
BatchJobUploadStatus $batchJobUploadStatus
) {
$this->adsUtilityRegistry->addUtility(AdsUtility::BATCH_JOBS);
return $this->batchJobsDelegate->uploadIncrementalBatchJobOperations(
$operations,
$batchJobUploadStatus
);
} | [
"public",
"function",
"uploadIncrementalBatchJobOperations",
"(",
"array",
"$",
"operations",
",",
"BatchJobUploadStatus",
"$",
"batchJobUploadStatus",
")",
"{",
"$",
"this",
"->",
"adsUtilityRegistry",
"->",
"addUtility",
"(",
"AdsUtility",
"::",
"BATCH_JOBS",
")",
";",
"return",
"$",
"this",
"->",
"batchJobsDelegate",
"->",
"uploadIncrementalBatchJobOperations",
"(",
"$",
"operations",
",",
"$",
"batchJobUploadStatus",
")",
";",
"}"
] | Uploads batch job operations incrementally to the specified upload URL.
@param Operation[] $operations operations to be uploaded via the upload
URL
@param BatchJobUploadStatus $batchJobUploadStatus the batch job upload
status
@return BatchJobUploadStatus the updated batch job upload status
@throws ApiException if the upload process failed | [
"Uploads",
"batch",
"job",
"operations",
"incrementally",
"to",
"the",
"specified",
"upload",
"URL",
"."
] | d552b800ad53c400b1a50c7852e7ad184245d2ea | https://github.com/googleads/googleads-php-lib/blob/d552b800ad53c400b1a50c7852e7ad184245d2ea/src/Google/AdsApi/AdWords/BatchJobs/v201809/BatchJobs.php#L106-L116 | train |
googleads/googleads-php-lib | src/Google/AdsApi/AdWords/BatchJobs/v201809/BatchJobs.php | BatchJobs.downloadBatchJobResults | public function downloadBatchJobResults($downloadUrl)
{
$this->adsUtilityRegistry->addUtility(AdsUtility::BATCH_JOBS);
return $this->batchJobsDelegate->downloadBatchJobResults($downloadUrl);
} | php | public function downloadBatchJobResults($downloadUrl)
{
$this->adsUtilityRegistry->addUtility(AdsUtility::BATCH_JOBS);
return $this->batchJobsDelegate->downloadBatchJobResults($downloadUrl);
} | [
"public",
"function",
"downloadBatchJobResults",
"(",
"$",
"downloadUrl",
")",
"{",
"$",
"this",
"->",
"adsUtilityRegistry",
"->",
"addUtility",
"(",
"AdsUtility",
"::",
"BATCH_JOBS",
")",
";",
"return",
"$",
"this",
"->",
"batchJobsDelegate",
"->",
"downloadBatchJobResults",
"(",
"$",
"downloadUrl",
")",
";",
"}"
] | Downloads the results of batch processing from the download URL.
@param string $downloadUrl the download URL from which the results are
downloaded
@return MutateResult[] the array of results from batch processing
@throws ApiException if the download process failed | [
"Downloads",
"the",
"results",
"of",
"batch",
"processing",
"from",
"the",
"download",
"URL",
"."
] | d552b800ad53c400b1a50c7852e7ad184245d2ea | https://github.com/googleads/googleads-php-lib/blob/d552b800ad53c400b1a50c7852e7ad184245d2ea/src/Google/AdsApi/AdWords/BatchJobs/v201809/BatchJobs.php#L143-L148 | train |
googleads/googleads-php-lib | src/Google/AdsApi/AdManager/Util/v201805/Pql.php | Pql.createValue | public static function createValue($value)
{
if ($value instanceof Value) {
return $value;
} elseif (is_bool($value)) {
return new BooleanValue($value);
} elseif (is_float($value) || is_int($value)) {
return new NumberValue(strval($value));
} elseif (is_string($value)) {
return new TextValue($value);
} elseif ($value instanceof AdManagerDateTime) {
return new DateTimeValue($value);
} elseif ($value instanceof Date) {
return new DateValue($value);
} elseif (is_array($value)) {
$values = [];
foreach ($value as $valueEntry) {
$values[] = self::createValue($valueEntry);
}
$setValue = new SetValue();
$setValue->setValues($values);
return $setValue;
} elseif ($value instanceof Targeting) {
return new TargetingValue($value);
} else {
throw new InvalidArgumentException(
sprintf(
'Unsupported value type [%s]',
is_object($value) ? get_class($value) : gettype($value)
)
);
}
} | php | public static function createValue($value)
{
if ($value instanceof Value) {
return $value;
} elseif (is_bool($value)) {
return new BooleanValue($value);
} elseif (is_float($value) || is_int($value)) {
return new NumberValue(strval($value));
} elseif (is_string($value)) {
return new TextValue($value);
} elseif ($value instanceof AdManagerDateTime) {
return new DateTimeValue($value);
} elseif ($value instanceof Date) {
return new DateValue($value);
} elseif (is_array($value)) {
$values = [];
foreach ($value as $valueEntry) {
$values[] = self::createValue($valueEntry);
}
$setValue = new SetValue();
$setValue->setValues($values);
return $setValue;
} elseif ($value instanceof Targeting) {
return new TargetingValue($value);
} else {
throw new InvalidArgumentException(
sprintf(
'Unsupported value type [%s]',
is_object($value) ? get_class($value) : gettype($value)
)
);
}
} | [
"public",
"static",
"function",
"createValue",
"(",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"value",
"instanceof",
"Value",
")",
"{",
"return",
"$",
"value",
";",
"}",
"elseif",
"(",
"is_bool",
"(",
"$",
"value",
")",
")",
"{",
"return",
"new",
"BooleanValue",
"(",
"$",
"value",
")",
";",
"}",
"elseif",
"(",
"is_float",
"(",
"$",
"value",
")",
"||",
"is_int",
"(",
"$",
"value",
")",
")",
"{",
"return",
"new",
"NumberValue",
"(",
"strval",
"(",
"$",
"value",
")",
")",
";",
"}",
"elseif",
"(",
"is_string",
"(",
"$",
"value",
")",
")",
"{",
"return",
"new",
"TextValue",
"(",
"$",
"value",
")",
";",
"}",
"elseif",
"(",
"$",
"value",
"instanceof",
"AdManagerDateTime",
")",
"{",
"return",
"new",
"DateTimeValue",
"(",
"$",
"value",
")",
";",
"}",
"elseif",
"(",
"$",
"value",
"instanceof",
"Date",
")",
"{",
"return",
"new",
"DateValue",
"(",
"$",
"value",
")",
";",
"}",
"elseif",
"(",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"$",
"values",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"value",
"as",
"$",
"valueEntry",
")",
"{",
"$",
"values",
"[",
"]",
"=",
"self",
"::",
"createValue",
"(",
"$",
"valueEntry",
")",
";",
"}",
"$",
"setValue",
"=",
"new",
"SetValue",
"(",
")",
";",
"$",
"setValue",
"->",
"setValues",
"(",
"$",
"values",
")",
";",
"return",
"$",
"setValue",
";",
"}",
"elseif",
"(",
"$",
"value",
"instanceof",
"Targeting",
")",
"{",
"return",
"new",
"TargetingValue",
"(",
"$",
"value",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Unsupported value type [%s]'",
",",
"is_object",
"(",
"$",
"value",
")",
"?",
"get_class",
"(",
"$",
"value",
")",
":",
"gettype",
"(",
"$",
"value",
")",
")",
")",
";",
"}",
"}"
] | Creates a PQL `Value` from the specified value.
For example:
- A `TextValue` for a value of type `string`.
- A `BooleanValue` for type `bool`.
- A `NumberValue` for type `float` or `int`.
- A `DateTimeValue` for type Ad Manager `DateTime`
- A `DateValue` for type Ad Manager `Date`
- A `SetValue` for type `array`.
If the specified value is already a PQL `Value`, the value is returned.
@param mixed $value the value to convert to a PQL value
@return Value a PQL value of the appropriate type
@throws InvalidArgumentException if value cannot be converted | [
"Creates",
"a",
"PQL",
"Value",
"from",
"the",
"specified",
"value",
"."
] | d552b800ad53c400b1a50c7852e7ad184245d2ea | https://github.com/googleads/googleads-php-lib/blob/d552b800ad53c400b1a50c7852e7ad184245d2ea/src/Google/AdsApi/AdManager/Util/v201805/Pql.php#L62-L95 | train |
googleads/googleads-php-lib | src/Google/AdsApi/AdManager/Util/v201805/Pql.php | Pql.toString | public static function toString(Value $value)
{
if ($value instanceof BooleanValue) {
return $value->getValue() ? 'true' : 'false';
} elseif ($value instanceof NumberValue || $value instanceof TextValue) {
return strval($value->getValue());
} elseif ($value instanceof DateTimeValue) {
return $value->getValue() !== null
? AdManagerDateTimes::toDateTimeString($value->getValue()) : '';
} elseif ($value instanceof DateValue) {
return AdManagerDates::toDateString($value->getValue());
} elseif ($value instanceof SetValue) {
$pqlValues = $value->getValues();
if ($pqlValues !== null) {
$valuesAsStrings = [];
foreach ($pqlValues as $pqlValue) {
$valuesAsStrings[] = self::toString($pqlValue);
}
return implode(',', $valuesAsStrings);
} else {
return '';
}
} else {
throw new InvalidArgumentException(
sprintf('Unsupported value type [%s]', get_class($value))
);
}
} | php | public static function toString(Value $value)
{
if ($value instanceof BooleanValue) {
return $value->getValue() ? 'true' : 'false';
} elseif ($value instanceof NumberValue || $value instanceof TextValue) {
return strval($value->getValue());
} elseif ($value instanceof DateTimeValue) {
return $value->getValue() !== null
? AdManagerDateTimes::toDateTimeString($value->getValue()) : '';
} elseif ($value instanceof DateValue) {
return AdManagerDates::toDateString($value->getValue());
} elseif ($value instanceof SetValue) {
$pqlValues = $value->getValues();
if ($pqlValues !== null) {
$valuesAsStrings = [];
foreach ($pqlValues as $pqlValue) {
$valuesAsStrings[] = self::toString($pqlValue);
}
return implode(',', $valuesAsStrings);
} else {
return '';
}
} else {
throw new InvalidArgumentException(
sprintf('Unsupported value type [%s]', get_class($value))
);
}
} | [
"public",
"static",
"function",
"toString",
"(",
"Value",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"value",
"instanceof",
"BooleanValue",
")",
"{",
"return",
"$",
"value",
"->",
"getValue",
"(",
")",
"?",
"'true'",
":",
"'false'",
";",
"}",
"elseif",
"(",
"$",
"value",
"instanceof",
"NumberValue",
"||",
"$",
"value",
"instanceof",
"TextValue",
")",
"{",
"return",
"strval",
"(",
"$",
"value",
"->",
"getValue",
"(",
")",
")",
";",
"}",
"elseif",
"(",
"$",
"value",
"instanceof",
"DateTimeValue",
")",
"{",
"return",
"$",
"value",
"->",
"getValue",
"(",
")",
"!==",
"null",
"?",
"AdManagerDateTimes",
"::",
"toDateTimeString",
"(",
"$",
"value",
"->",
"getValue",
"(",
")",
")",
":",
"''",
";",
"}",
"elseif",
"(",
"$",
"value",
"instanceof",
"DateValue",
")",
"{",
"return",
"AdManagerDates",
"::",
"toDateString",
"(",
"$",
"value",
"->",
"getValue",
"(",
")",
")",
";",
"}",
"elseif",
"(",
"$",
"value",
"instanceof",
"SetValue",
")",
"{",
"$",
"pqlValues",
"=",
"$",
"value",
"->",
"getValues",
"(",
")",
";",
"if",
"(",
"$",
"pqlValues",
"!==",
"null",
")",
"{",
"$",
"valuesAsStrings",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"pqlValues",
"as",
"$",
"pqlValue",
")",
"{",
"$",
"valuesAsStrings",
"[",
"]",
"=",
"self",
"::",
"toString",
"(",
"$",
"pqlValue",
")",
";",
"}",
"return",
"implode",
"(",
"','",
",",
"$",
"valuesAsStrings",
")",
";",
"}",
"else",
"{",
"return",
"''",
";",
"}",
"}",
"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 | [
"Creates",
"a",
"string",
"from",
"the",
"Value",
"."
] | d552b800ad53c400b1a50c7852e7ad184245d2ea | https://github.com/googleads/googleads-php-lib/blob/d552b800ad53c400b1a50c7852e7ad184245d2ea/src/Google/AdsApi/AdManager/Util/v201805/Pql.php#L104-L132 | train |
googleads/googleads-php-lib | src/Google/AdsApi/AdManager/Util/v201805/Pql.php | Pql.getColumnLabels | public static function getColumnLabels(ResultSet $resultSet)
{
$columnLabels = [];
foreach ($resultSet->getColumnTypes() as $columnType) {
$columnLabels[] = $columnType->getLabelName();
}
return $columnLabels;
} | php | public static function getColumnLabels(ResultSet $resultSet)
{
$columnLabels = [];
foreach ($resultSet->getColumnTypes() as $columnType) {
$columnLabels[] = $columnType->getLabelName();
}
return $columnLabels;
} | [
"public",
"static",
"function",
"getColumnLabels",
"(",
"ResultSet",
"$",
"resultSet",
")",
"{",
"$",
"columnLabels",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"resultSet",
"->",
"getColumnTypes",
"(",
")",
"as",
"$",
"columnType",
")",
"{",
"$",
"columnLabels",
"[",
"]",
"=",
"$",
"columnType",
"->",
"getLabelName",
"(",
")",
";",
"}",
"return",
"$",
"columnLabels",
";",
"}"
] | Gets the column labels for the result set.
@param ResultSet $resultSet the result set to get the column labels for
@return string[] the string list of column labels | [
"Gets",
"the",
"column",
"labels",
"for",
"the",
"result",
"set",
"."
] | d552b800ad53c400b1a50c7852e7ad184245d2ea | https://github.com/googleads/googleads-php-lib/blob/d552b800ad53c400b1a50c7852e7ad184245d2ea/src/Google/AdsApi/AdManager/Util/v201805/Pql.php#L140-L148 | train |
googleads/googleads-php-lib | src/Google/AdsApi/AdManager/Util/v201805/Pql.php | Pql.combineResultSets | public static function combineResultSets(
ResultSet $first,
ResultSet $second
) {
$firstColumns = self::getColumnLabels($first);
$secondColumns = self::getColumnLabels($second);
if ($firstColumns !== $secondColumns) {
throw new InvalidArgumentException(
sprintf(
'First result set columns [%s] do not match second result '
. 'set columns [%s]',
implode(
', ',
$firstColumns
),
implode(', ', $secondColumns)
)
);
}
$combinedRows = $first->getRows();
if (!empty($second->getRows())) {
$combinedRows = array_merge($combinedRows, $second->getRows());
}
return new ResultSet($first->getColumnTypes(), $combinedRows);
} | php | public static function combineResultSets(
ResultSet $first,
ResultSet $second
) {
$firstColumns = self::getColumnLabels($first);
$secondColumns = self::getColumnLabels($second);
if ($firstColumns !== $secondColumns) {
throw new InvalidArgumentException(
sprintf(
'First result set columns [%s] do not match second result '
. 'set columns [%s]',
implode(
', ',
$firstColumns
),
implode(', ', $secondColumns)
)
);
}
$combinedRows = $first->getRows();
if (!empty($second->getRows())) {
$combinedRows = array_merge($combinedRows, $second->getRows());
}
return new ResultSet($first->getColumnTypes(), $combinedRows);
} | [
"public",
"static",
"function",
"combineResultSets",
"(",
"ResultSet",
"$",
"first",
",",
"ResultSet",
"$",
"second",
")",
"{",
"$",
"firstColumns",
"=",
"self",
"::",
"getColumnLabels",
"(",
"$",
"first",
")",
";",
"$",
"secondColumns",
"=",
"self",
"::",
"getColumnLabels",
"(",
"$",
"second",
")",
";",
"if",
"(",
"$",
"firstColumns",
"!==",
"$",
"secondColumns",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'First result set columns [%s] do not match second result '",
".",
"'set columns [%s]'",
",",
"implode",
"(",
"', '",
",",
"$",
"firstColumns",
")",
",",
"implode",
"(",
"', '",
",",
"$",
"secondColumns",
")",
")",
")",
";",
"}",
"$",
"combinedRows",
"=",
"$",
"first",
"->",
"getRows",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"second",
"->",
"getRows",
"(",
")",
")",
")",
"{",
"$",
"combinedRows",
"=",
"array_merge",
"(",
"$",
"combinedRows",
",",
"$",
"second",
"->",
"getRows",
"(",
")",
")",
";",
"}",
"return",
"new",
"ResultSet",
"(",
"$",
"first",
"->",
"getColumnTypes",
"(",
")",
",",
"$",
"combinedRows",
")",
";",
"}"
] | Combines the first and second result sets, if and only if, the columns
of both result sets match.
@param ResultSet $first the first result set
@param ResultSet $second the second result set
@return ResultSet the combined result set
@throws InvalidArgumentException if the result sets to combine do not
have identical column headers | [
"Combines",
"the",
"first",
"and",
"second",
"result",
"sets",
"if",
"and",
"only",
"if",
"the",
"columns",
"of",
"both",
"result",
"sets",
"match",
"."
] | d552b800ad53c400b1a50c7852e7ad184245d2ea | https://github.com/googleads/googleads-php-lib/blob/d552b800ad53c400b1a50c7852e7ad184245d2ea/src/Google/AdsApi/AdManager/Util/v201805/Pql.php#L171-L198 | train |
googleads/googleads-php-lib | src/Google/AdsApi/AdWords/Query/v201809/ServiceQueryBuilderDelegate.php | ServiceQueryBuilderDelegate.copyFrom | public static function copyFrom(
ServiceQueryBuilderDelegate $otherInstance,
ServiceQueryBuilder $queryBuilder
) {
$copyingInstance = new self();
$copyingInstance->startIndex = $otherInstance->startIndex;
$copyingInstance->pageSize = $otherInstance->pageSize;
$copyingInstance->orderByFields = $otherInstance->orderByFields;
$copyingInstance->selectFields = $otherInstance->selectFields;
if (isset($otherInstance->whereBuilders)) {
$copyingInstance->whereBuilders = [];
foreach ($otherInstance->whereBuilders as $whereBuilder) {
$copyingInstance->whereBuilders[] =
ServiceQueryWhereBuilder::copyFrom(
$whereBuilder,
$queryBuilder
);
}
}
return $copyingInstance;
} | php | public static function copyFrom(
ServiceQueryBuilderDelegate $otherInstance,
ServiceQueryBuilder $queryBuilder
) {
$copyingInstance = new self();
$copyingInstance->startIndex = $otherInstance->startIndex;
$copyingInstance->pageSize = $otherInstance->pageSize;
$copyingInstance->orderByFields = $otherInstance->orderByFields;
$copyingInstance->selectFields = $otherInstance->selectFields;
if (isset($otherInstance->whereBuilders)) {
$copyingInstance->whereBuilders = [];
foreach ($otherInstance->whereBuilders as $whereBuilder) {
$copyingInstance->whereBuilders[] =
ServiceQueryWhereBuilder::copyFrom(
$whereBuilder,
$queryBuilder
);
}
}
return $copyingInstance;
} | [
"public",
"static",
"function",
"copyFrom",
"(",
"ServiceQueryBuilderDelegate",
"$",
"otherInstance",
",",
"ServiceQueryBuilder",
"$",
"queryBuilder",
")",
"{",
"$",
"copyingInstance",
"=",
"new",
"self",
"(",
")",
";",
"$",
"copyingInstance",
"->",
"startIndex",
"=",
"$",
"otherInstance",
"->",
"startIndex",
";",
"$",
"copyingInstance",
"->",
"pageSize",
"=",
"$",
"otherInstance",
"->",
"pageSize",
";",
"$",
"copyingInstance",
"->",
"orderByFields",
"=",
"$",
"otherInstance",
"->",
"orderByFields",
";",
"$",
"copyingInstance",
"->",
"selectFields",
"=",
"$",
"otherInstance",
"->",
"selectFields",
";",
"if",
"(",
"isset",
"(",
"$",
"otherInstance",
"->",
"whereBuilders",
")",
")",
"{",
"$",
"copyingInstance",
"->",
"whereBuilders",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"otherInstance",
"->",
"whereBuilders",
"as",
"$",
"whereBuilder",
")",
"{",
"$",
"copyingInstance",
"->",
"whereBuilders",
"[",
"]",
"=",
"ServiceQueryWhereBuilder",
"::",
"copyFrom",
"(",
"$",
"whereBuilder",
",",
"$",
"queryBuilder",
")",
";",
"}",
"}",
"return",
"$",
"copyingInstance",
";",
"}"
] | Creates a new query builder delegate object by copying field names,
WHERE conditions and pagination data from another query builder
delegate object.
@param ServiceQueryBuilderDelegate $otherInstance the other query
builder delegate object for copying field names, WHERE conditions
and pagination data
@param ServiceQueryBuilder $queryBuilder the query builder object for
continuation of building a complete AWQL string
@return ServiceQueryBuilderDelegate a new query builder delegate object
that copies from the input one | [
"Creates",
"a",
"new",
"query",
"builder",
"delegate",
"object",
"by",
"copying",
"field",
"names",
"WHERE",
"conditions",
"and",
"pagination",
"data",
"from",
"another",
"query",
"builder",
"delegate",
"object",
"."
] | d552b800ad53c400b1a50c7852e7ad184245d2ea | https://github.com/googleads/googleads-php-lib/blob/d552b800ad53c400b1a50c7852e7ad184245d2ea/src/Google/AdsApi/AdWords/Query/v201809/ServiceQueryBuilderDelegate.php#L57-L78 | train |
googleads/googleads-php-lib | src/Google/AdsApi/AdWords/Query/v201809/ServiceQueryBuilderDelegate.php | ServiceQueryBuilderDelegate.select | public function select(array $fields)
{
if (empty($fields)) {
throw new InvalidArgumentException('The field array must not be' .
' empty.');
}
foreach ($fields as $field) {
$validationResult = QueryValidator::validateFieldName($field);
if ($validationResult->isFailed()) {
throw new InvalidArgumentException('The field array for' .
' building the SELECT clause contains invalid field name.' .
' Validation fail reason: ' .
$validationResult->getFailReason());
}
}
// Flipping an array will create a new associative array. The keys of
// the new associative array make a set of distinct fields.
$distinctFields = array_flip($fields);
$this->selectFields = array_keys($distinctFields);
} | php | public function select(array $fields)
{
if (empty($fields)) {
throw new InvalidArgumentException('The field array must not be' .
' empty.');
}
foreach ($fields as $field) {
$validationResult = QueryValidator::validateFieldName($field);
if ($validationResult->isFailed()) {
throw new InvalidArgumentException('The field array for' .
' building the SELECT clause contains invalid field name.' .
' Validation fail reason: ' .
$validationResult->getFailReason());
}
}
// Flipping an array will create a new associative array. The keys of
// the new associative array make a set of distinct fields.
$distinctFields = array_flip($fields);
$this->selectFields = array_keys($distinctFields);
} | [
"public",
"function",
"select",
"(",
"array",
"$",
"fields",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"fields",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'The field array must not be'",
".",
"' empty.'",
")",
";",
"}",
"foreach",
"(",
"$",
"fields",
"as",
"$",
"field",
")",
"{",
"$",
"validationResult",
"=",
"QueryValidator",
"::",
"validateFieldName",
"(",
"$",
"field",
")",
";",
"if",
"(",
"$",
"validationResult",
"->",
"isFailed",
"(",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'The field array for'",
".",
"' building the SELECT clause contains invalid field name.'",
".",
"' Validation fail reason: '",
".",
"$",
"validationResult",
"->",
"getFailReason",
"(",
")",
")",
";",
"}",
"}",
"// Flipping an array will create a new associative array. The keys of",
"// the new associative array make a set of distinct fields.",
"$",
"distinctFields",
"=",
"array_flip",
"(",
"$",
"fields",
")",
";",
"$",
"this",
"->",
"selectFields",
"=",
"array_keys",
"(",
"$",
"distinctFields",
")",
";",
"}"
] | Sets the fields for the SELECT clause. Repeated field names will be
included exactly once.
@param array $fields the fields for building the SELECT clause | [
"Sets",
"the",
"fields",
"for",
"the",
"SELECT",
"clause",
".",
"Repeated",
"field",
"names",
"will",
"be",
"included",
"exactly",
"once",
"."
] | d552b800ad53c400b1a50c7852e7ad184245d2ea | https://github.com/googleads/googleads-php-lib/blob/d552b800ad53c400b1a50c7852e7ad184245d2ea/src/Google/AdsApi/AdWords/Query/v201809/ServiceQueryBuilderDelegate.php#L86-L107 | train |
googleads/googleads-php-lib | src/Google/AdsApi/AdWords/Query/v201809/ServiceQueryBuilderDelegate.php | ServiceQueryBuilderDelegate.appendOrderByClause | private function appendOrderByClause($awqlString)
{
if (empty($this->orderByFields)) {
return $awqlString;
}
return sprintf(
'%s ORDER BY %s',
$awqlString,
implode(', ', $this->orderByFields)
);
} | php | private function appendOrderByClause($awqlString)
{
if (empty($this->orderByFields)) {
return $awqlString;
}
return sprintf(
'%s ORDER BY %s',
$awqlString,
implode(', ', $this->orderByFields)
);
} | [
"private",
"function",
"appendOrderByClause",
"(",
"$",
"awqlString",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"orderByFields",
")",
")",
"{",
"return",
"$",
"awqlString",
";",
"}",
"return",
"sprintf",
"(",
"'%s ORDER BY %s'",
",",
"$",
"awqlString",
",",
"implode",
"(",
"', '",
",",
"$",
"this",
"->",
"orderByFields",
")",
")",
";",
"}"
] | Appends the ORDER BY clause to a partial AWQL string.
@param string $awqlString a partial AWQL string to append an ORDER BY
clause
@return string the complete AWQL string with the ORDER BY clause | [
"Appends",
"the",
"ORDER",
"BY",
"clause",
"to",
"a",
"partial",
"AWQL",
"string",
"."
] | d552b800ad53c400b1a50c7852e7ad184245d2ea | https://github.com/googleads/googleads-php-lib/blob/d552b800ad53c400b1a50c7852e7ad184245d2ea/src/Google/AdsApi/AdWords/Query/v201809/ServiceQueryBuilderDelegate.php#L232-L243 | train |
googleads/googleads-php-lib | src/Google/AdsApi/AdWords/Reporting/v201809/ReportDownloader.php | ReportDownloader.downloadReport | public function downloadReport(
ReportDefinition $reportDefinition,
ReportSettings $reportSettingsOverride = null
) {
return $this->makeReportRequest(
$this->requestOptionsFactory
->createRequestOptionsWithReportDefinition(
$reportDefinition,
$reportSettingsOverride
)
);
} | php | public function downloadReport(
ReportDefinition $reportDefinition,
ReportSettings $reportSettingsOverride = null
) {
return $this->makeReportRequest(
$this->requestOptionsFactory
->createRequestOptionsWithReportDefinition(
$reportDefinition,
$reportSettingsOverride
)
);
} | [
"public",
"function",
"downloadReport",
"(",
"ReportDefinition",
"$",
"reportDefinition",
",",
"ReportSettings",
"$",
"reportSettingsOverride",
"=",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"makeReportRequest",
"(",
"$",
"this",
"->",
"requestOptionsFactory",
"->",
"createRequestOptionsWithReportDefinition",
"(",
"$",
"reportDefinition",
",",
"$",
"reportSettingsOverride",
")",
")",
";",
"}"
] | Downloads a report using report definition.
@param ReportDefinition $reportDefinition the report definition to
download
@param null|ReportSettings $reportSettingsOverride the report settings
used to override the report settings of the AdWords session for this
request
@return ReportDownloadResult the report download result
@throws ApiException if there are errors during downloading reports | [
"Downloads",
"a",
"report",
"using",
"report",
"definition",
"."
] | d552b800ad53c400b1a50c7852e7ad184245d2ea | https://github.com/googleads/googleads-php-lib/blob/d552b800ad53c400b1a50c7852e7ad184245d2ea/src/Google/AdsApi/AdWords/Reporting/v201809/ReportDownloader.php#L116-L127 | train |
googleads/googleads-php-lib | src/Google/AdsApi/AdWords/Reporting/v201809/ReportDownloader.php | ReportDownloader.downloadReportWithAwql | public function downloadReportWithAwql(
$reportQuery,
$reportFormat,
ReportSettings $reportSettingsOverride = null
) {
// The `$reportQuery` argument must be a string. If it is an object
// of other types, the object must be converted to a string for this
// function to accept it.
if (!is_string($reportQuery)) {
throw new InvalidArgumentException('The report query must be a' .
' string.');
}
return $this->makeReportRequest(
$this->requestOptionsFactory
->createRequestOptionsWithAwqlQuery(
$reportQuery,
$reportFormat,
$reportSettingsOverride
)
);
} | php | public function downloadReportWithAwql(
$reportQuery,
$reportFormat,
ReportSettings $reportSettingsOverride = null
) {
// The `$reportQuery` argument must be a string. If it is an object
// of other types, the object must be converted to a string for this
// function to accept it.
if (!is_string($reportQuery)) {
throw new InvalidArgumentException('The report query must be a' .
' string.');
}
return $this->makeReportRequest(
$this->requestOptionsFactory
->createRequestOptionsWithAwqlQuery(
$reportQuery,
$reportFormat,
$reportSettingsOverride
)
);
} | [
"public",
"function",
"downloadReportWithAwql",
"(",
"$",
"reportQuery",
",",
"$",
"reportFormat",
",",
"ReportSettings",
"$",
"reportSettingsOverride",
"=",
"null",
")",
"{",
"// The `$reportQuery` argument must be a string. If it is an object",
"// of other types, the object must be converted to a string for this",
"// function to accept it.",
"if",
"(",
"!",
"is_string",
"(",
"$",
"reportQuery",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'The report query must be a'",
".",
"' string.'",
")",
";",
"}",
"return",
"$",
"this",
"->",
"makeReportRequest",
"(",
"$",
"this",
"->",
"requestOptionsFactory",
"->",
"createRequestOptionsWithAwqlQuery",
"(",
"$",
"reportQuery",
",",
"$",
"reportFormat",
",",
"$",
"reportSettingsOverride",
")",
")",
";",
"}"
] | Downloads a report using AWQL.
@param string $reportQuery the query to use for the report
@param string $reportFormat the report format to request
@param null|ReportSettings $reportSettingsOverride the report settings
used to override the report settings of the AdWords session for this
request
@return ReportDownloadResult the report download result
@throws ApiException if there are errors during downloading reports | [
"Downloads",
"a",
"report",
"using",
"AWQL",
"."
] | d552b800ad53c400b1a50c7852e7ad184245d2ea | https://github.com/googleads/googleads-php-lib/blob/d552b800ad53c400b1a50c7852e7ad184245d2ea/src/Google/AdsApi/AdWords/Reporting/v201809/ReportDownloader.php#L140-L161 | train |
googleads/googleads-php-lib | src/Google/AdsApi/AdWords/Reporting/v201809/ReportDownloader.php | ReportDownloader.downloadReportWithReportQuery | public function downloadReportWithReportQuery(
ReportQuery $reportQuery,
$reportFormat,
ReportSettings $reportSettingsOverride = null
) {
$awqlString = sprintf('%s', $reportQuery);
return $this->downloadReportWithAwql(
$awqlString,
$reportFormat,
$reportSettingsOverride
);
} | php | public function downloadReportWithReportQuery(
ReportQuery $reportQuery,
$reportFormat,
ReportSettings $reportSettingsOverride = null
) {
$awqlString = sprintf('%s', $reportQuery);
return $this->downloadReportWithAwql(
$awqlString,
$reportFormat,
$reportSettingsOverride
);
} | [
"public",
"function",
"downloadReportWithReportQuery",
"(",
"ReportQuery",
"$",
"reportQuery",
",",
"$",
"reportFormat",
",",
"ReportSettings",
"$",
"reportSettingsOverride",
"=",
"null",
")",
"{",
"$",
"awqlString",
"=",
"sprintf",
"(",
"'%s'",
",",
"$",
"reportQuery",
")",
";",
"return",
"$",
"this",
"->",
"downloadReportWithAwql",
"(",
"$",
"awqlString",
",",
"$",
"reportFormat",
",",
"$",
"reportSettingsOverride",
")",
";",
"}"
] | Downloads a report using a report query object.
@param ReportQuery $reportQuery the report query object that can
generate an AWQL string
@param string $reportFormat the report format to request
@param null|ReportSettings $reportSettingsOverride the report settings
used to override the report settings of the AdWords session for this
request
@return ReportDownloadResult the report download result
@throws ApiException if there are errors during downloading reports | [
"Downloads",
"a",
"report",
"using",
"a",
"report",
"query",
"object",
"."
] | d552b800ad53c400b1a50c7852e7ad184245d2ea | https://github.com/googleads/googleads-php-lib/blob/d552b800ad53c400b1a50c7852e7ad184245d2ea/src/Google/AdsApi/AdWords/Reporting/v201809/ReportDownloader.php#L175-L187 | train |
googleads/googleads-php-lib | src/Google/AdsApi/AdWords/Reporting/v201809/ReportDownloader.php | ReportDownloader.makeReportRequest | private function makeReportRequest(array $requestOptions)
{
$requestOptions[RequestOptions::STREAM] = true;
$proxy = $this->session->getConnectionSettings()->getProxyUrl();
if (!empty($proxy)) {
$requestOptions[RequestOptions::PROXY] = ['https' => $proxy];
}
if ($this->session->getConnectionSettings()->isReportingGzipEnabled()
=== true) {
$requestOptions[RequestOptions::DECODE_CONTENT] = 'gzip';
}
try {
$response = $this->httpClient->request(
'POST',
rtrim($this->session->getEndpoint(), '/')
. self::$REPORT_DOWNLOAD_URL_PATH,
$requestOptions
);
} catch (ClientException $e) {
$decodedResponse = $this->apiErrorSerializer->decode(
$e->getResponse()->getBody()->getContents(),
'xml'
);
// If the decoded response is an associative array, this means there is
// only one error and the members of the array are the fields of ApiError.
$apiErrorList =
AdWordsNormalizer::isOneOrMany($decodedResponse['ApiError'])
? [$decodedResponse['ApiError']]
: $decodedResponse['ApiError'];
$reportDownloadErrors =
$this->apiErrorSerializer->denormalize(
$apiErrorList,
'Google\AdsApi\AdWords\Reporting\v201809\ReportDownloadError[]'
);
$reportDownloadException = new ApiException(
sprintf('Details: [%s]', implode(', ', $reportDownloadErrors))
);
$reportDownloadException->setErrors($reportDownloadErrors);
throw $reportDownloadException;
} catch (ServerException $e) {
throw new ApiException(
'Temporary problem with the server. Please retry the request'
. ' after a few moments'
);
}
return new ReportDownloadResult($response);
} | php | private function makeReportRequest(array $requestOptions)
{
$requestOptions[RequestOptions::STREAM] = true;
$proxy = $this->session->getConnectionSettings()->getProxyUrl();
if (!empty($proxy)) {
$requestOptions[RequestOptions::PROXY] = ['https' => $proxy];
}
if ($this->session->getConnectionSettings()->isReportingGzipEnabled()
=== true) {
$requestOptions[RequestOptions::DECODE_CONTENT] = 'gzip';
}
try {
$response = $this->httpClient->request(
'POST',
rtrim($this->session->getEndpoint(), '/')
. self::$REPORT_DOWNLOAD_URL_PATH,
$requestOptions
);
} catch (ClientException $e) {
$decodedResponse = $this->apiErrorSerializer->decode(
$e->getResponse()->getBody()->getContents(),
'xml'
);
// If the decoded response is an associative array, this means there is
// only one error and the members of the array are the fields of ApiError.
$apiErrorList =
AdWordsNormalizer::isOneOrMany($decodedResponse['ApiError'])
? [$decodedResponse['ApiError']]
: $decodedResponse['ApiError'];
$reportDownloadErrors =
$this->apiErrorSerializer->denormalize(
$apiErrorList,
'Google\AdsApi\AdWords\Reporting\v201809\ReportDownloadError[]'
);
$reportDownloadException = new ApiException(
sprintf('Details: [%s]', implode(', ', $reportDownloadErrors))
);
$reportDownloadException->setErrors($reportDownloadErrors);
throw $reportDownloadException;
} catch (ServerException $e) {
throw new ApiException(
'Temporary problem with the server. Please retry the request'
. ' after a few moments'
);
}
return new ReportDownloadResult($response);
} | [
"private",
"function",
"makeReportRequest",
"(",
"array",
"$",
"requestOptions",
")",
"{",
"$",
"requestOptions",
"[",
"RequestOptions",
"::",
"STREAM",
"]",
"=",
"true",
";",
"$",
"proxy",
"=",
"$",
"this",
"->",
"session",
"->",
"getConnectionSettings",
"(",
")",
"->",
"getProxyUrl",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"proxy",
")",
")",
"{",
"$",
"requestOptions",
"[",
"RequestOptions",
"::",
"PROXY",
"]",
"=",
"[",
"'https'",
"=>",
"$",
"proxy",
"]",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"session",
"->",
"getConnectionSettings",
"(",
")",
"->",
"isReportingGzipEnabled",
"(",
")",
"===",
"true",
")",
"{",
"$",
"requestOptions",
"[",
"RequestOptions",
"::",
"DECODE_CONTENT",
"]",
"=",
"'gzip'",
";",
"}",
"try",
"{",
"$",
"response",
"=",
"$",
"this",
"->",
"httpClient",
"->",
"request",
"(",
"'POST'",
",",
"rtrim",
"(",
"$",
"this",
"->",
"session",
"->",
"getEndpoint",
"(",
")",
",",
"'/'",
")",
".",
"self",
"::",
"$",
"REPORT_DOWNLOAD_URL_PATH",
",",
"$",
"requestOptions",
")",
";",
"}",
"catch",
"(",
"ClientException",
"$",
"e",
")",
"{",
"$",
"decodedResponse",
"=",
"$",
"this",
"->",
"apiErrorSerializer",
"->",
"decode",
"(",
"$",
"e",
"->",
"getResponse",
"(",
")",
"->",
"getBody",
"(",
")",
"->",
"getContents",
"(",
")",
",",
"'xml'",
")",
";",
"// If the decoded response is an associative array, this means there is",
"// only one error and the members of the array are the fields of ApiError.",
"$",
"apiErrorList",
"=",
"AdWordsNormalizer",
"::",
"isOneOrMany",
"(",
"$",
"decodedResponse",
"[",
"'ApiError'",
"]",
")",
"?",
"[",
"$",
"decodedResponse",
"[",
"'ApiError'",
"]",
"]",
":",
"$",
"decodedResponse",
"[",
"'ApiError'",
"]",
";",
"$",
"reportDownloadErrors",
"=",
"$",
"this",
"->",
"apiErrorSerializer",
"->",
"denormalize",
"(",
"$",
"apiErrorList",
",",
"'Google\\AdsApi\\AdWords\\Reporting\\v201809\\ReportDownloadError[]'",
")",
";",
"$",
"reportDownloadException",
"=",
"new",
"ApiException",
"(",
"sprintf",
"(",
"'Details: [%s]'",
",",
"implode",
"(",
"', '",
",",
"$",
"reportDownloadErrors",
")",
")",
")",
";",
"$",
"reportDownloadException",
"->",
"setErrors",
"(",
"$",
"reportDownloadErrors",
")",
";",
"throw",
"$",
"reportDownloadException",
";",
"}",
"catch",
"(",
"ServerException",
"$",
"e",
")",
"{",
"throw",
"new",
"ApiException",
"(",
"'Temporary problem with the server. Please retry the request'",
".",
"' after a few moments'",
")",
";",
"}",
"return",
"new",
"ReportDownloadResult",
"(",
"$",
"response",
")",
";",
"}"
] | Make an HTTP request to download a report with the specified request
options.
@param array $requestOptions the options for making HTTP request via
Guzzle
@return ReportDownloadResult the report download result
@throws ApiException if there are errors during downloading reports | [
"Make",
"an",
"HTTP",
"request",
"to",
"download",
"a",
"report",
"with",
"the",
"specified",
"request",
"options",
"."
] | d552b800ad53c400b1a50c7852e7ad184245d2ea | https://github.com/googleads/googleads-php-lib/blob/d552b800ad53c400b1a50c7852e7ad184245d2ea/src/Google/AdsApi/AdWords/Reporting/v201809/ReportDownloader.php#L198-L247 | train |
googleads/googleads-php-lib | examples/AdWords/v201809/Migration/MigrateToExtensionSettings.php | MigrateToExtensionSettings.getFeeds | private static function getFeeds(
AdWordsServices $adWordsServices,
AdWordsSession $session
) {
$feedService = $adWordsServices->get($session, FeedService::class);
// Create paging controls.
$totalNumEntries = 0;
$offset = 0;
$query = 'SELECT Id, Name, Attributes WHERE Origin="USER" AND '
. 'FeedStatus="ENABLED"';
$feeds = [];
do {
$pageQuery =
sprintf('%s LIMIT %d,%d', $query, $offset, self::PAGE_LIMIT);
// Make the query request.
$page = $feedService->query($pageQuery);
if ($page->getEntries() !== null) {
$totalNumEntries = $page->getTotalNumEntries();
foreach ($page->getEntries() as $feed) {
$feeds[] = $feed;
}
}
// Advance the paging offset.
$offset += self::PAGE_LIMIT;
} while ($offset < $totalNumEntries);
return $feeds;
} | php | private static function getFeeds(
AdWordsServices $adWordsServices,
AdWordsSession $session
) {
$feedService = $adWordsServices->get($session, FeedService::class);
// Create paging controls.
$totalNumEntries = 0;
$offset = 0;
$query = 'SELECT Id, Name, Attributes WHERE Origin="USER" AND '
. 'FeedStatus="ENABLED"';
$feeds = [];
do {
$pageQuery =
sprintf('%s LIMIT %d,%d', $query, $offset, self::PAGE_LIMIT);
// Make the query request.
$page = $feedService->query($pageQuery);
if ($page->getEntries() !== null) {
$totalNumEntries = $page->getTotalNumEntries();
foreach ($page->getEntries() as $feed) {
$feeds[] = $feed;
}
}
// Advance the paging offset.
$offset += self::PAGE_LIMIT;
} while ($offset < $totalNumEntries);
return $feeds;
} | [
"private",
"static",
"function",
"getFeeds",
"(",
"AdWordsServices",
"$",
"adWordsServices",
",",
"AdWordsSession",
"$",
"session",
")",
"{",
"$",
"feedService",
"=",
"$",
"adWordsServices",
"->",
"get",
"(",
"$",
"session",
",",
"FeedService",
"::",
"class",
")",
";",
"// Create paging controls.",
"$",
"totalNumEntries",
"=",
"0",
";",
"$",
"offset",
"=",
"0",
";",
"$",
"query",
"=",
"'SELECT Id, Name, Attributes WHERE Origin=\"USER\" AND '",
".",
"'FeedStatus=\"ENABLED\"'",
";",
"$",
"feeds",
"=",
"[",
"]",
";",
"do",
"{",
"$",
"pageQuery",
"=",
"sprintf",
"(",
"'%s LIMIT %d,%d'",
",",
"$",
"query",
",",
"$",
"offset",
",",
"self",
"::",
"PAGE_LIMIT",
")",
";",
"// Make the query request.",
"$",
"page",
"=",
"$",
"feedService",
"->",
"query",
"(",
"$",
"pageQuery",
")",
";",
"if",
"(",
"$",
"page",
"->",
"getEntries",
"(",
")",
"!==",
"null",
")",
"{",
"$",
"totalNumEntries",
"=",
"$",
"page",
"->",
"getTotalNumEntries",
"(",
")",
";",
"foreach",
"(",
"$",
"page",
"->",
"getEntries",
"(",
")",
"as",
"$",
"feed",
")",
"{",
"$",
"feeds",
"[",
"]",
"=",
"$",
"feed",
";",
"}",
"}",
"// Advance the paging offset.",
"$",
"offset",
"+=",
"self",
"::",
"PAGE_LIMIT",
";",
"}",
"while",
"(",
"$",
"offset",
"<",
"$",
"totalNumEntries",
")",
";",
"return",
"$",
"feeds",
";",
"}"
] | Gets all enabled feeds. | [
"Gets",
"all",
"enabled",
"feeds",
"."
] | d552b800ad53c400b1a50c7852e7ad184245d2ea | https://github.com/googleads/googleads-php-lib/blob/d552b800ad53c400b1a50c7852e7ad184245d2ea/examples/AdWords/v201809/Migration/MigrateToExtensionSettings.php#L162-L192 | train |
googleads/googleads-php-lib | examples/AdWords/v201809/Migration/MigrateToExtensionSettings.php | MigrateToExtensionSettings.getFeedItems | private static function getFeedItems(
AdWordsServices $adWordsServices,
AdWordsSession $session,
$feedId
) {
$feedItemService =
$adWordsServices->get($session, FeedItemService::class);
// Create paging controls.
$totalNumEntries = 0;
$offset = 0;
$query = sprintf(
'SELECT FeedItemId, AttributeValues WHERE Status = '
. '"ENABLED" AND FeedId = %d',
$feedId
);
$feedItems = [];
do {
$pageQuery =
sprintf('%s LIMIT %d,%d', $query, $offset, self::PAGE_LIMIT);
// Make the query request.
$page = $feedItemService->query($pageQuery);
if ($page->getEntries() !== null) {
$totalNumEntries = $page->getTotalNumEntries();
foreach ($page->getEntries() as $feedItem) {
$feedItems[] = $feedItem;
}
}
// Advance the paging offset.
$offset += self::PAGE_LIMIT;
} while ($offset < $totalNumEntries);
return $feedItems;
} | php | private static function getFeedItems(
AdWordsServices $adWordsServices,
AdWordsSession $session,
$feedId
) {
$feedItemService =
$adWordsServices->get($session, FeedItemService::class);
// Create paging controls.
$totalNumEntries = 0;
$offset = 0;
$query = sprintf(
'SELECT FeedItemId, AttributeValues WHERE Status = '
. '"ENABLED" AND FeedId = %d',
$feedId
);
$feedItems = [];
do {
$pageQuery =
sprintf('%s LIMIT %d,%d', $query, $offset, self::PAGE_LIMIT);
// Make the query request.
$page = $feedItemService->query($pageQuery);
if ($page->getEntries() !== null) {
$totalNumEntries = $page->getTotalNumEntries();
foreach ($page->getEntries() as $feedItem) {
$feedItems[] = $feedItem;
}
}
// Advance the paging offset.
$offset += self::PAGE_LIMIT;
} while ($offset < $totalNumEntries);
return $feedItems;
} | [
"private",
"static",
"function",
"getFeedItems",
"(",
"AdWordsServices",
"$",
"adWordsServices",
",",
"AdWordsSession",
"$",
"session",
",",
"$",
"feedId",
")",
"{",
"$",
"feedItemService",
"=",
"$",
"adWordsServices",
"->",
"get",
"(",
"$",
"session",
",",
"FeedItemService",
"::",
"class",
")",
";",
"// Create paging controls.",
"$",
"totalNumEntries",
"=",
"0",
";",
"$",
"offset",
"=",
"0",
";",
"$",
"query",
"=",
"sprintf",
"(",
"'SELECT FeedItemId, AttributeValues WHERE Status = '",
".",
"'\"ENABLED\" AND FeedId = %d'",
",",
"$",
"feedId",
")",
";",
"$",
"feedItems",
"=",
"[",
"]",
";",
"do",
"{",
"$",
"pageQuery",
"=",
"sprintf",
"(",
"'%s LIMIT %d,%d'",
",",
"$",
"query",
",",
"$",
"offset",
",",
"self",
"::",
"PAGE_LIMIT",
")",
";",
"// Make the query request.",
"$",
"page",
"=",
"$",
"feedItemService",
"->",
"query",
"(",
"$",
"pageQuery",
")",
";",
"if",
"(",
"$",
"page",
"->",
"getEntries",
"(",
")",
"!==",
"null",
")",
"{",
"$",
"totalNumEntries",
"=",
"$",
"page",
"->",
"getTotalNumEntries",
"(",
")",
";",
"foreach",
"(",
"$",
"page",
"->",
"getEntries",
"(",
")",
"as",
"$",
"feedItem",
")",
"{",
"$",
"feedItems",
"[",
"]",
"=",
"$",
"feedItem",
";",
"}",
"}",
"// Advance the paging offset.",
"$",
"offset",
"+=",
"self",
"::",
"PAGE_LIMIT",
";",
"}",
"while",
"(",
"$",
"offset",
"<",
"$",
"totalNumEntries",
")",
";",
"return",
"$",
"feedItems",
";",
"}"
] | Gets all enabled feed items of the specified feed. | [
"Gets",
"all",
"enabled",
"feed",
"items",
"of",
"the",
"specified",
"feed",
"."
] | d552b800ad53c400b1a50c7852e7ad184245d2ea | https://github.com/googleads/googleads-php-lib/blob/d552b800ad53c400b1a50c7852e7ad184245d2ea/examples/AdWords/v201809/Migration/MigrateToExtensionSettings.php#L197-L232 | train |
googleads/googleads-php-lib | examples/AdWords/v201809/Migration/MigrateToExtensionSettings.php | MigrateToExtensionSettings.getCampaignFeeds | private static function getCampaignFeeds(
AdWordsServices $adWordsServices,
AdWordsSession $session,
$feedId,
$placeholderId
) {
$campaignFeedService = $adWordsServices->get($session, CampaignFeedService::class);
$page = $campaignFeedService->query(
sprintf(
'SELECT CampaignId, MatchingFunction, PlaceholderTypes WHERE '
. 'Status="ENABLED" AND FeedId = %d AND PlaceholderTypes ' . 'CONTAINS_ANY[%d]',
$feedId,
$placeholderId
)
);
return $page->getEntries();
} | php | private static function getCampaignFeeds(
AdWordsServices $adWordsServices,
AdWordsSession $session,
$feedId,
$placeholderId
) {
$campaignFeedService = $adWordsServices->get($session, CampaignFeedService::class);
$page = $campaignFeedService->query(
sprintf(
'SELECT CampaignId, MatchingFunction, PlaceholderTypes WHERE '
. 'Status="ENABLED" AND FeedId = %d AND PlaceholderTypes ' . 'CONTAINS_ANY[%d]',
$feedId,
$placeholderId
)
);
return $page->getEntries();
} | [
"private",
"static",
"function",
"getCampaignFeeds",
"(",
"AdWordsServices",
"$",
"adWordsServices",
",",
"AdWordsSession",
"$",
"session",
",",
"$",
"feedId",
",",
"$",
"placeholderId",
")",
"{",
"$",
"campaignFeedService",
"=",
"$",
"adWordsServices",
"->",
"get",
"(",
"$",
"session",
",",
"CampaignFeedService",
"::",
"class",
")",
";",
"$",
"page",
"=",
"$",
"campaignFeedService",
"->",
"query",
"(",
"sprintf",
"(",
"'SELECT CampaignId, MatchingFunction, PlaceholderTypes WHERE '",
".",
"'Status=\"ENABLED\" AND FeedId = %d AND PlaceholderTypes '",
".",
"'CONTAINS_ANY[%d]'",
",",
"$",
"feedId",
",",
"$",
"placeholderId",
")",
")",
";",
"return",
"$",
"page",
"->",
"getEntries",
"(",
")",
";",
"}"
] | Gets all enabled campaign feeds for the specified feed and placeholder
type. | [
"Gets",
"all",
"enabled",
"campaign",
"feeds",
"for",
"the",
"specified",
"feed",
"and",
"placeholder",
"type",
"."
] | d552b800ad53c400b1a50c7852e7ad184245d2ea | https://github.com/googleads/googleads-php-lib/blob/d552b800ad53c400b1a50c7852e7ad184245d2ea/examples/AdWords/v201809/Migration/MigrateToExtensionSettings.php#L238-L255 | train |
googleads/googleads-php-lib | examples/AdWords/v201809/Migration/MigrateToExtensionSettings.php | MigrateToExtensionSettings.getAttributeFieldMappings | private static function getAttributeFieldMappings(
AdWordsServices $adWordsServices,
AdWordsSession $session,
$feedId,
$placeholderTypeId
) {
$feedMappingService = $adWordsServices->get($session, FeedMappingService::class);
$page = $feedMappingService->query(
sprintf(
'SELECT FeedMappingId, AttributeFieldMappings WHERE FeedId="%d" '
. 'AND PlaceholderType="%d" AND Status="ENABLED"',
$feedId,
$placeholderTypeId
)
);
$attributeMappings = [];
if ($page->getEntries() !== null) {
// Normally, a feed attribute is mapped only to one field. However,
// you may map it to more than one field if needed.
foreach ($page->getEntries() as $feedMapping) {
foreach ($feedMapping->getAttributeFieldMappings() as $attributeMapping) {
if (array_key_exists(
$attributeMapping->getFeedAttributeId(),
$attributeMappings
) === false) {
$attributeMappings[$attributeMapping->getFeedAttributeId()] = [];
}
$attributeMappings[$attributeMapping->getFeedAttributeId()][] = $attributeMapping->getFieldId();
}
}
}
return $attributeMappings;
} | php | private static function getAttributeFieldMappings(
AdWordsServices $adWordsServices,
AdWordsSession $session,
$feedId,
$placeholderTypeId
) {
$feedMappingService = $adWordsServices->get($session, FeedMappingService::class);
$page = $feedMappingService->query(
sprintf(
'SELECT FeedMappingId, AttributeFieldMappings WHERE FeedId="%d" '
. 'AND PlaceholderType="%d" AND Status="ENABLED"',
$feedId,
$placeholderTypeId
)
);
$attributeMappings = [];
if ($page->getEntries() !== null) {
// Normally, a feed attribute is mapped only to one field. However,
// you may map it to more than one field if needed.
foreach ($page->getEntries() as $feedMapping) {
foreach ($feedMapping->getAttributeFieldMappings() as $attributeMapping) {
if (array_key_exists(
$attributeMapping->getFeedAttributeId(),
$attributeMappings
) === false) {
$attributeMappings[$attributeMapping->getFeedAttributeId()] = [];
}
$attributeMappings[$attributeMapping->getFeedAttributeId()][] = $attributeMapping->getFieldId();
}
}
}
return $attributeMappings;
} | [
"private",
"static",
"function",
"getAttributeFieldMappings",
"(",
"AdWordsServices",
"$",
"adWordsServices",
",",
"AdWordsSession",
"$",
"session",
",",
"$",
"feedId",
",",
"$",
"placeholderTypeId",
")",
"{",
"$",
"feedMappingService",
"=",
"$",
"adWordsServices",
"->",
"get",
"(",
"$",
"session",
",",
"FeedMappingService",
"::",
"class",
")",
";",
"$",
"page",
"=",
"$",
"feedMappingService",
"->",
"query",
"(",
"sprintf",
"(",
"'SELECT FeedMappingId, AttributeFieldMappings WHERE FeedId=\"%d\" '",
".",
"'AND PlaceholderType=\"%d\" AND Status=\"ENABLED\"'",
",",
"$",
"feedId",
",",
"$",
"placeholderTypeId",
")",
")",
";",
"$",
"attributeMappings",
"=",
"[",
"]",
";",
"if",
"(",
"$",
"page",
"->",
"getEntries",
"(",
")",
"!==",
"null",
")",
"{",
"// Normally, a feed attribute is mapped only to one field. However,",
"// you may map it to more than one field if needed.",
"foreach",
"(",
"$",
"page",
"->",
"getEntries",
"(",
")",
"as",
"$",
"feedMapping",
")",
"{",
"foreach",
"(",
"$",
"feedMapping",
"->",
"getAttributeFieldMappings",
"(",
")",
"as",
"$",
"attributeMapping",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"attributeMapping",
"->",
"getFeedAttributeId",
"(",
")",
",",
"$",
"attributeMappings",
")",
"===",
"false",
")",
"{",
"$",
"attributeMappings",
"[",
"$",
"attributeMapping",
"->",
"getFeedAttributeId",
"(",
")",
"]",
"=",
"[",
"]",
";",
"}",
"$",
"attributeMappings",
"[",
"$",
"attributeMapping",
"->",
"getFeedAttributeId",
"(",
")",
"]",
"[",
"]",
"=",
"$",
"attributeMapping",
"->",
"getFieldId",
"(",
")",
";",
"}",
"}",
"}",
"return",
"$",
"attributeMappings",
";",
"}"
] | Gets attribute field mappings from the specified feed and placeholder type. | [
"Gets",
"attribute",
"field",
"mappings",
"from",
"the",
"specified",
"feed",
"and",
"placeholder",
"type",
"."
] | d552b800ad53c400b1a50c7852e7ad184245d2ea | https://github.com/googleads/googleads-php-lib/blob/d552b800ad53c400b1a50c7852e7ad184245d2ea/examples/AdWords/v201809/Migration/MigrateToExtensionSettings.php#L260-L294 | train |
googleads/googleads-php-lib | examples/AdWords/v201809/Migration/MigrateToExtensionSettings.php | MigrateToExtensionSettings.getSitelinksFromFeed | private static function getSitelinksFromFeed(
AdWordsServices $adWordsServices,
AdWordsSession $session,
$feedId
) {
printf("Processing feed ID %d...\n", $feedId);
$sitelinks = [];
// Retrieve all the feed items from the feed.
$feedItems = self::getFeedItems($adWordsServices, $session, $feedId);
if ($feedItems !== null) {
// Retrieve the feed's attribute mapping.
$attributeFieldMappings = self::getAttributeFieldMappings(
$adWordsServices,
$session,
$feedId,
self::PLACEHOLDER_TYPE_SITELINKS
);
foreach ($feedItems as $feedItem) {
$sitelinkFromFeed = new SitelinkFromFeed(
$feedItem->getFeedId(),
$feedItem->getFeedItemId()
);
foreach ($feedItem->getAttributeValues() as $attributeValue) {
// This attribute hasn't been mapped to a field.
if (array_key_exists(
$attributeValue->getFeedAttributeId(),
$attributeFieldMappings
) === false) {
continue;
}
// Get the list of all the fields to which this attribute has been
// mapped.
foreach ($attributeFieldMappings[$attributeValue->getFeedAttributeId()] as $fieldId) {
// Read the appropriate value depending on the ID of the mapped
// field.
switch ($fieldId) {
case self::PLACEHOLDER_FIELD_TEXT:
$sitelinkFromFeed->setText($attributeValue->getStringValue());
break;
case self::PLACEHOLDER_FIELD_URL:
$sitelinkFromFeed->setUrl($attributeValue->getStringValue());
break;
case self::PLACEHOLDER_FIELD_FINAL_URLS:
$sitelinkFromFeed->setFinalUrls(
$attributeValue->getStringValues()
);
break;
case self::PLACEHOLDER_FIELD_FINAL_MOBILE_URLS:
$sitelinkFromFeed->setFinalMobileUrls(
$attributeValue->getStringValues()
);
break;
case self::PLACEHOLDER_FIELD_TRACKING_URL_TEMPLATE:
$sitelinkFromFeed->setTrackingUrlTemplate(
$attributeValue->getStringValue()
);
break;
case self::PLACEHOLDER_FIELD_LINE2:
$sitelinkFromFeed->setLine2($attributeValue->getStringValue());
break;
case self::PLACEHOLDER_FIELD_LINE3:
$sitelinkFromFeed->setLine3($attributeValue->getStringValue());
break;
}
}
}
$sitelinks[$feedItem->getFeedItemId()] = $sitelinkFromFeed;
}
}
return $sitelinks;
} | php | private static function getSitelinksFromFeed(
AdWordsServices $adWordsServices,
AdWordsSession $session,
$feedId
) {
printf("Processing feed ID %d...\n", $feedId);
$sitelinks = [];
// Retrieve all the feed items from the feed.
$feedItems = self::getFeedItems($adWordsServices, $session, $feedId);
if ($feedItems !== null) {
// Retrieve the feed's attribute mapping.
$attributeFieldMappings = self::getAttributeFieldMappings(
$adWordsServices,
$session,
$feedId,
self::PLACEHOLDER_TYPE_SITELINKS
);
foreach ($feedItems as $feedItem) {
$sitelinkFromFeed = new SitelinkFromFeed(
$feedItem->getFeedId(),
$feedItem->getFeedItemId()
);
foreach ($feedItem->getAttributeValues() as $attributeValue) {
// This attribute hasn't been mapped to a field.
if (array_key_exists(
$attributeValue->getFeedAttributeId(),
$attributeFieldMappings
) === false) {
continue;
}
// Get the list of all the fields to which this attribute has been
// mapped.
foreach ($attributeFieldMappings[$attributeValue->getFeedAttributeId()] as $fieldId) {
// Read the appropriate value depending on the ID of the mapped
// field.
switch ($fieldId) {
case self::PLACEHOLDER_FIELD_TEXT:
$sitelinkFromFeed->setText($attributeValue->getStringValue());
break;
case self::PLACEHOLDER_FIELD_URL:
$sitelinkFromFeed->setUrl($attributeValue->getStringValue());
break;
case self::PLACEHOLDER_FIELD_FINAL_URLS:
$sitelinkFromFeed->setFinalUrls(
$attributeValue->getStringValues()
);
break;
case self::PLACEHOLDER_FIELD_FINAL_MOBILE_URLS:
$sitelinkFromFeed->setFinalMobileUrls(
$attributeValue->getStringValues()
);
break;
case self::PLACEHOLDER_FIELD_TRACKING_URL_TEMPLATE:
$sitelinkFromFeed->setTrackingUrlTemplate(
$attributeValue->getStringValue()
);
break;
case self::PLACEHOLDER_FIELD_LINE2:
$sitelinkFromFeed->setLine2($attributeValue->getStringValue());
break;
case self::PLACEHOLDER_FIELD_LINE3:
$sitelinkFromFeed->setLine3($attributeValue->getStringValue());
break;
}
}
}
$sitelinks[$feedItem->getFeedItemId()] = $sitelinkFromFeed;
}
}
return $sitelinks;
} | [
"private",
"static",
"function",
"getSitelinksFromFeed",
"(",
"AdWordsServices",
"$",
"adWordsServices",
",",
"AdWordsSession",
"$",
"session",
",",
"$",
"feedId",
")",
"{",
"printf",
"(",
"\"Processing feed ID %d...\\n\"",
",",
"$",
"feedId",
")",
";",
"$",
"sitelinks",
"=",
"[",
"]",
";",
"// Retrieve all the feed items from the feed.",
"$",
"feedItems",
"=",
"self",
"::",
"getFeedItems",
"(",
"$",
"adWordsServices",
",",
"$",
"session",
",",
"$",
"feedId",
")",
";",
"if",
"(",
"$",
"feedItems",
"!==",
"null",
")",
"{",
"// Retrieve the feed's attribute mapping.",
"$",
"attributeFieldMappings",
"=",
"self",
"::",
"getAttributeFieldMappings",
"(",
"$",
"adWordsServices",
",",
"$",
"session",
",",
"$",
"feedId",
",",
"self",
"::",
"PLACEHOLDER_TYPE_SITELINKS",
")",
";",
"foreach",
"(",
"$",
"feedItems",
"as",
"$",
"feedItem",
")",
"{",
"$",
"sitelinkFromFeed",
"=",
"new",
"SitelinkFromFeed",
"(",
"$",
"feedItem",
"->",
"getFeedId",
"(",
")",
",",
"$",
"feedItem",
"->",
"getFeedItemId",
"(",
")",
")",
";",
"foreach",
"(",
"$",
"feedItem",
"->",
"getAttributeValues",
"(",
")",
"as",
"$",
"attributeValue",
")",
"{",
"// This attribute hasn't been mapped to a field.",
"if",
"(",
"array_key_exists",
"(",
"$",
"attributeValue",
"->",
"getFeedAttributeId",
"(",
")",
",",
"$",
"attributeFieldMappings",
")",
"===",
"false",
")",
"{",
"continue",
";",
"}",
"// Get the list of all the fields to which this attribute has been",
"// mapped.",
"foreach",
"(",
"$",
"attributeFieldMappings",
"[",
"$",
"attributeValue",
"->",
"getFeedAttributeId",
"(",
")",
"]",
"as",
"$",
"fieldId",
")",
"{",
"// Read the appropriate value depending on the ID of the mapped",
"// field.",
"switch",
"(",
"$",
"fieldId",
")",
"{",
"case",
"self",
"::",
"PLACEHOLDER_FIELD_TEXT",
":",
"$",
"sitelinkFromFeed",
"->",
"setText",
"(",
"$",
"attributeValue",
"->",
"getStringValue",
"(",
")",
")",
";",
"break",
";",
"case",
"self",
"::",
"PLACEHOLDER_FIELD_URL",
":",
"$",
"sitelinkFromFeed",
"->",
"setUrl",
"(",
"$",
"attributeValue",
"->",
"getStringValue",
"(",
")",
")",
";",
"break",
";",
"case",
"self",
"::",
"PLACEHOLDER_FIELD_FINAL_URLS",
":",
"$",
"sitelinkFromFeed",
"->",
"setFinalUrls",
"(",
"$",
"attributeValue",
"->",
"getStringValues",
"(",
")",
")",
";",
"break",
";",
"case",
"self",
"::",
"PLACEHOLDER_FIELD_FINAL_MOBILE_URLS",
":",
"$",
"sitelinkFromFeed",
"->",
"setFinalMobileUrls",
"(",
"$",
"attributeValue",
"->",
"getStringValues",
"(",
")",
")",
";",
"break",
";",
"case",
"self",
"::",
"PLACEHOLDER_FIELD_TRACKING_URL_TEMPLATE",
":",
"$",
"sitelinkFromFeed",
"->",
"setTrackingUrlTemplate",
"(",
"$",
"attributeValue",
"->",
"getStringValue",
"(",
")",
")",
";",
"break",
";",
"case",
"self",
"::",
"PLACEHOLDER_FIELD_LINE2",
":",
"$",
"sitelinkFromFeed",
"->",
"setLine2",
"(",
"$",
"attributeValue",
"->",
"getStringValue",
"(",
")",
")",
";",
"break",
";",
"case",
"self",
"::",
"PLACEHOLDER_FIELD_LINE3",
":",
"$",
"sitelinkFromFeed",
"->",
"setLine3",
"(",
"$",
"attributeValue",
"->",
"getStringValue",
"(",
")",
")",
";",
"break",
";",
"}",
"}",
"}",
"$",
"sitelinks",
"[",
"$",
"feedItem",
"->",
"getFeedItemId",
"(",
")",
"]",
"=",
"$",
"sitelinkFromFeed",
";",
"}",
"}",
"return",
"$",
"sitelinks",
";",
"}"
] | Gets sitelinks from the specified feed. | [
"Gets",
"sitelinks",
"from",
"the",
"specified",
"feed",
"."
] | d552b800ad53c400b1a50c7852e7ad184245d2ea | https://github.com/googleads/googleads-php-lib/blob/d552b800ad53c400b1a50c7852e7ad184245d2ea/examples/AdWords/v201809/Migration/MigrateToExtensionSettings.php#L299-L374 | train |
googleads/googleads-php-lib | examples/AdWords/v201809/Migration/MigrateToExtensionSettings.php | MigrateToExtensionSettings.getPlatformRestrictionsForCampaignFeed | private static function getPlatformRestrictionsForCampaignFeed(
$campaignFeed
) {
$platformRestrictions = ExtensionSettingPlatform::NONE;
if ($campaignFeed->getMatchingFunction()->getOperator() === FunctionOperator::AND_VALUE) {
foreach ($campaignFeed->getMatchingFunction()->getLhsOperand() as $argument) {
if ($argument instanceof FunctionOperand) {
if ($argument->getValue()->getOperator() === FunctionOperator::EQUALS
&& $argument->getValue()->getLhsOperand()[0] instanceof RequestContextOperand) {
$requestContextOperand = $argument->getValue()->getLhsOperand()[0];
if ($requestContextOperand->getContextType()
=== RequestContextOperandContextType::DEVICE_PLATFORM) {
$platformRestrictions = strtoupper(
$argument->getValue()->getRhsOperand()[0]->getStringValue()
);
}
}
}
}
}
return $platformRestrictions;
} | php | private static function getPlatformRestrictionsForCampaignFeed(
$campaignFeed
) {
$platformRestrictions = ExtensionSettingPlatform::NONE;
if ($campaignFeed->getMatchingFunction()->getOperator() === FunctionOperator::AND_VALUE) {
foreach ($campaignFeed->getMatchingFunction()->getLhsOperand() as $argument) {
if ($argument instanceof FunctionOperand) {
if ($argument->getValue()->getOperator() === FunctionOperator::EQUALS
&& $argument->getValue()->getLhsOperand()[0] instanceof RequestContextOperand) {
$requestContextOperand = $argument->getValue()->getLhsOperand()[0];
if ($requestContextOperand->getContextType()
=== RequestContextOperandContextType::DEVICE_PLATFORM) {
$platformRestrictions = strtoupper(
$argument->getValue()->getRhsOperand()[0]->getStringValue()
);
}
}
}
}
}
return $platformRestrictions;
} | [
"private",
"static",
"function",
"getPlatformRestrictionsForCampaignFeed",
"(",
"$",
"campaignFeed",
")",
"{",
"$",
"platformRestrictions",
"=",
"ExtensionSettingPlatform",
"::",
"NONE",
";",
"if",
"(",
"$",
"campaignFeed",
"->",
"getMatchingFunction",
"(",
")",
"->",
"getOperator",
"(",
")",
"===",
"FunctionOperator",
"::",
"AND_VALUE",
")",
"{",
"foreach",
"(",
"$",
"campaignFeed",
"->",
"getMatchingFunction",
"(",
")",
"->",
"getLhsOperand",
"(",
")",
"as",
"$",
"argument",
")",
"{",
"if",
"(",
"$",
"argument",
"instanceof",
"FunctionOperand",
")",
"{",
"if",
"(",
"$",
"argument",
"->",
"getValue",
"(",
")",
"->",
"getOperator",
"(",
")",
"===",
"FunctionOperator",
"::",
"EQUALS",
"&&",
"$",
"argument",
"->",
"getValue",
"(",
")",
"->",
"getLhsOperand",
"(",
")",
"[",
"0",
"]",
"instanceof",
"RequestContextOperand",
")",
"{",
"$",
"requestContextOperand",
"=",
"$",
"argument",
"->",
"getValue",
"(",
")",
"->",
"getLhsOperand",
"(",
")",
"[",
"0",
"]",
";",
"if",
"(",
"$",
"requestContextOperand",
"->",
"getContextType",
"(",
")",
"===",
"RequestContextOperandContextType",
"::",
"DEVICE_PLATFORM",
")",
"{",
"$",
"platformRestrictions",
"=",
"strtoupper",
"(",
"$",
"argument",
"->",
"getValue",
"(",
")",
"->",
"getRhsOperand",
"(",
")",
"[",
"0",
"]",
"->",
"getStringValue",
"(",
")",
")",
";",
"}",
"}",
"}",
"}",
"}",
"return",
"$",
"platformRestrictions",
";",
"}"
] | Gets plaftform restrictions for the specified campaign feed. | [
"Gets",
"plaftform",
"restrictions",
"for",
"the",
"specified",
"campaign",
"feed",
"."
] | d552b800ad53c400b1a50c7852e7ad184245d2ea | https://github.com/googleads/googleads-php-lib/blob/d552b800ad53c400b1a50c7852e7ad184245d2ea/examples/AdWords/v201809/Migration/MigrateToExtensionSettings.php#L379-L402 | train |
googleads/googleads-php-lib | examples/AdWords/v201809/Migration/MigrateToExtensionSettings.php | MigrateToExtensionSettings.getFeedItemIdsForCampaignFeed | private static function getFeedItemIdsForCampaignFeed($campaignFeed)
{
$feedItemIds = [];
if ($campaignFeed->getMatchingFunction()->getOperator() === FunctionOperator::IN) {
// Check if matchingFunction is of the form IN(FEED_ITEM_ID,{xxx,xxx}).
// Extract feed items if applicable.
$feedItemIds = array_merge(
$feedItemIds,
self::getFeedItemIdsFromArgument($campaignFeed->getMatchingFunction())
);
} elseif ($campaignFeed->getMatchingFunction()->getOperator() === FunctionOperator::AND_VALUE) {
foreach ($campaignFeed->getMatchingFunction()->getLhsOperand() as $argument) {
// Check if matchingFunction is of the form IN(FEED_ITEM_ID,{xxx,xxx}).
// Extract feed items if applicable.
if ($argument instanceof FunctionOperand) {
if ($argument->getValue()->getOperator() === FunctionOperator::IN) {
$feedItemIds = array_merge(
$feedItemIds,
self::getFeedItemIdsFromArgument($argument->getValue())
);
}
}
}
}
return $feedItemIds;
} | php | private static function getFeedItemIdsForCampaignFeed($campaignFeed)
{
$feedItemIds = [];
if ($campaignFeed->getMatchingFunction()->getOperator() === FunctionOperator::IN) {
// Check if matchingFunction is of the form IN(FEED_ITEM_ID,{xxx,xxx}).
// Extract feed items if applicable.
$feedItemIds = array_merge(
$feedItemIds,
self::getFeedItemIdsFromArgument($campaignFeed->getMatchingFunction())
);
} elseif ($campaignFeed->getMatchingFunction()->getOperator() === FunctionOperator::AND_VALUE) {
foreach ($campaignFeed->getMatchingFunction()->getLhsOperand() as $argument) {
// Check if matchingFunction is of the form IN(FEED_ITEM_ID,{xxx,xxx}).
// Extract feed items if applicable.
if ($argument instanceof FunctionOperand) {
if ($argument->getValue()->getOperator() === FunctionOperator::IN) {
$feedItemIds = array_merge(
$feedItemIds,
self::getFeedItemIdsFromArgument($argument->getValue())
);
}
}
}
}
return $feedItemIds;
} | [
"private",
"static",
"function",
"getFeedItemIdsForCampaignFeed",
"(",
"$",
"campaignFeed",
")",
"{",
"$",
"feedItemIds",
"=",
"[",
"]",
";",
"if",
"(",
"$",
"campaignFeed",
"->",
"getMatchingFunction",
"(",
")",
"->",
"getOperator",
"(",
")",
"===",
"FunctionOperator",
"::",
"IN",
")",
"{",
"// Check if matchingFunction is of the form IN(FEED_ITEM_ID,{xxx,xxx}).",
"// Extract feed items if applicable.",
"$",
"feedItemIds",
"=",
"array_merge",
"(",
"$",
"feedItemIds",
",",
"self",
"::",
"getFeedItemIdsFromArgument",
"(",
"$",
"campaignFeed",
"->",
"getMatchingFunction",
"(",
")",
")",
")",
";",
"}",
"elseif",
"(",
"$",
"campaignFeed",
"->",
"getMatchingFunction",
"(",
")",
"->",
"getOperator",
"(",
")",
"===",
"FunctionOperator",
"::",
"AND_VALUE",
")",
"{",
"foreach",
"(",
"$",
"campaignFeed",
"->",
"getMatchingFunction",
"(",
")",
"->",
"getLhsOperand",
"(",
")",
"as",
"$",
"argument",
")",
"{",
"// Check if matchingFunction is of the form IN(FEED_ITEM_ID,{xxx,xxx}).",
"// Extract feed items if applicable.",
"if",
"(",
"$",
"argument",
"instanceof",
"FunctionOperand",
")",
"{",
"if",
"(",
"$",
"argument",
"->",
"getValue",
"(",
")",
"->",
"getOperator",
"(",
")",
"===",
"FunctionOperator",
"::",
"IN",
")",
"{",
"$",
"feedItemIds",
"=",
"array_merge",
"(",
"$",
"feedItemIds",
",",
"self",
"::",
"getFeedItemIdsFromArgument",
"(",
"$",
"argument",
"->",
"getValue",
"(",
")",
")",
")",
";",
"}",
"}",
"}",
"}",
"return",
"$",
"feedItemIds",
";",
"}"
] | Gets feed item IDs from the specified campaign feed. | [
"Gets",
"feed",
"item",
"IDs",
"from",
"the",
"specified",
"campaign",
"feed",
"."
] | d552b800ad53c400b1a50c7852e7ad184245d2ea | https://github.com/googleads/googleads-php-lib/blob/d552b800ad53c400b1a50c7852e7ad184245d2ea/examples/AdWords/v201809/Migration/MigrateToExtensionSettings.php#L408-L435 | train |
googleads/googleads-php-lib | examples/AdWords/v201809/Migration/MigrateToExtensionSettings.php | MigrateToExtensionSettings.getFeedItemIdsFromArgument | private static function getFeedItemIdsFromArgument($function)
{
$feedItemIds = [];
if (count($function->getLhsOperand()) === 1
&& $function->getLhsOperand()[0] instanceof RequestContextOperand
&& $function->getLhsOperand()[0]->getContextType() === RequestContextOperandContextType::FEED_ITEM_ID
&& $function->getOperator() === FunctionOperator::IN) {
foreach ($function->getRhsOperand() as $argument) {
$feedItemIds[] = $argument->getLongValue();
}
}
return $feedItemIds;
} | php | private static function getFeedItemIdsFromArgument($function)
{
$feedItemIds = [];
if (count($function->getLhsOperand()) === 1
&& $function->getLhsOperand()[0] instanceof RequestContextOperand
&& $function->getLhsOperand()[0]->getContextType() === RequestContextOperandContextType::FEED_ITEM_ID
&& $function->getOperator() === FunctionOperator::IN) {
foreach ($function->getRhsOperand() as $argument) {
$feedItemIds[] = $argument->getLongValue();
}
}
return $feedItemIds;
} | [
"private",
"static",
"function",
"getFeedItemIdsFromArgument",
"(",
"$",
"function",
")",
"{",
"$",
"feedItemIds",
"=",
"[",
"]",
";",
"if",
"(",
"count",
"(",
"$",
"function",
"->",
"getLhsOperand",
"(",
")",
")",
"===",
"1",
"&&",
"$",
"function",
"->",
"getLhsOperand",
"(",
")",
"[",
"0",
"]",
"instanceof",
"RequestContextOperand",
"&&",
"$",
"function",
"->",
"getLhsOperand",
"(",
")",
"[",
"0",
"]",
"->",
"getContextType",
"(",
")",
"===",
"RequestContextOperandContextType",
"::",
"FEED_ITEM_ID",
"&&",
"$",
"function",
"->",
"getOperator",
"(",
")",
"===",
"FunctionOperator",
"::",
"IN",
")",
"{",
"foreach",
"(",
"$",
"function",
"->",
"getRhsOperand",
"(",
")",
"as",
"$",
"argument",
")",
"{",
"$",
"feedItemIds",
"[",
"]",
"=",
"$",
"argument",
"->",
"getLongValue",
"(",
")",
";",
"}",
"}",
"return",
"$",
"feedItemIds",
";",
"}"
] | Gets feed item IDs from the specified function argument. | [
"Gets",
"feed",
"item",
"IDs",
"from",
"the",
"specified",
"function",
"argument",
"."
] | d552b800ad53c400b1a50c7852e7ad184245d2ea | https://github.com/googleads/googleads-php-lib/blob/d552b800ad53c400b1a50c7852e7ad184245d2ea/examples/AdWords/v201809/Migration/MigrateToExtensionSettings.php#L440-L454 | train |
googleads/googleads-php-lib | examples/AdWords/v201809/Migration/MigrateToExtensionSettings.php | MigrateToExtensionSettings.createExtensionSetting | private static function createExtensionSetting(
AdWordsServices $adWordsServices,
AdWordsSession $session,
array $sitelinksFromFeed,
$campaignId,
array $feedItemIds,
$platformRestrictions
) {
$campaignExtensionSettingService = $adWordsServices->get($session, CampaignExtensionSettingService::class);
$extensionSetting = new CampaignExtensionSetting();
$extensionSetting->setCampaignId($campaignId);
$extensionSetting->setExtensionType(FeedType::SITELINK);
$extensionSetting->setExtensionSetting(new ExtensionSetting());
$extensionFeedItems = [];
foreach ($feedItemIds as $feedItemId) {
$sitelink = $sitelinksFromFeed[$feedItemId];
$newFeedItem = new SitelinkFeedItem();
$newFeedItem->setSitelinkText($sitelink->getText());
$newFeedItem->setSitelinkUrl($sitelink->getUrl());
$newFeedItem->setSitelinkLine2($sitelink->getLine2());
$newFeedItem->setSitelinkLine3($sitelink->getLine3());
$newFeedItem->setSitelinkFinalUrls($sitelink->getFinalUrls());
$newFeedItem->setSitelinkFinalMobileUrls($sitelink->getFinalMobileUrls());
$newFeedItem->setSitelinkTrackingUrlTemplate(
$sitelink->getTrackingUrlTemplate()
);
$extensionFeedItems[] = $newFeedItem;
}
$extensionSetting->getExtensionSetting()->setExtensions(
$extensionFeedItems
);
$extensionSetting->getExtensionSetting()->setPlatformRestrictions(
$platformRestrictions
);
$operation = new CampaignExtensionSettingOperation();
$operation->setOperand($extensionSetting);
$operation->setOperator(Operator::ADD);
printf(
"Adding %d sitelinks for campaign ID %d...\n",
count($feedItemIds),
$campaignId
);
return $campaignExtensionSettingService->mutate([$operation]);
} | php | private static function createExtensionSetting(
AdWordsServices $adWordsServices,
AdWordsSession $session,
array $sitelinksFromFeed,
$campaignId,
array $feedItemIds,
$platformRestrictions
) {
$campaignExtensionSettingService = $adWordsServices->get($session, CampaignExtensionSettingService::class);
$extensionSetting = new CampaignExtensionSetting();
$extensionSetting->setCampaignId($campaignId);
$extensionSetting->setExtensionType(FeedType::SITELINK);
$extensionSetting->setExtensionSetting(new ExtensionSetting());
$extensionFeedItems = [];
foreach ($feedItemIds as $feedItemId) {
$sitelink = $sitelinksFromFeed[$feedItemId];
$newFeedItem = new SitelinkFeedItem();
$newFeedItem->setSitelinkText($sitelink->getText());
$newFeedItem->setSitelinkUrl($sitelink->getUrl());
$newFeedItem->setSitelinkLine2($sitelink->getLine2());
$newFeedItem->setSitelinkLine3($sitelink->getLine3());
$newFeedItem->setSitelinkFinalUrls($sitelink->getFinalUrls());
$newFeedItem->setSitelinkFinalMobileUrls($sitelink->getFinalMobileUrls());
$newFeedItem->setSitelinkTrackingUrlTemplate(
$sitelink->getTrackingUrlTemplate()
);
$extensionFeedItems[] = $newFeedItem;
}
$extensionSetting->getExtensionSetting()->setExtensions(
$extensionFeedItems
);
$extensionSetting->getExtensionSetting()->setPlatformRestrictions(
$platformRestrictions
);
$operation = new CampaignExtensionSettingOperation();
$operation->setOperand($extensionSetting);
$operation->setOperator(Operator::ADD);
printf(
"Adding %d sitelinks for campaign ID %d...\n",
count($feedItemIds),
$campaignId
);
return $campaignExtensionSettingService->mutate([$operation]);
} | [
"private",
"static",
"function",
"createExtensionSetting",
"(",
"AdWordsServices",
"$",
"adWordsServices",
",",
"AdWordsSession",
"$",
"session",
",",
"array",
"$",
"sitelinksFromFeed",
",",
"$",
"campaignId",
",",
"array",
"$",
"feedItemIds",
",",
"$",
"platformRestrictions",
")",
"{",
"$",
"campaignExtensionSettingService",
"=",
"$",
"adWordsServices",
"->",
"get",
"(",
"$",
"session",
",",
"CampaignExtensionSettingService",
"::",
"class",
")",
";",
"$",
"extensionSetting",
"=",
"new",
"CampaignExtensionSetting",
"(",
")",
";",
"$",
"extensionSetting",
"->",
"setCampaignId",
"(",
"$",
"campaignId",
")",
";",
"$",
"extensionSetting",
"->",
"setExtensionType",
"(",
"FeedType",
"::",
"SITELINK",
")",
";",
"$",
"extensionSetting",
"->",
"setExtensionSetting",
"(",
"new",
"ExtensionSetting",
"(",
")",
")",
";",
"$",
"extensionFeedItems",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"feedItemIds",
"as",
"$",
"feedItemId",
")",
"{",
"$",
"sitelink",
"=",
"$",
"sitelinksFromFeed",
"[",
"$",
"feedItemId",
"]",
";",
"$",
"newFeedItem",
"=",
"new",
"SitelinkFeedItem",
"(",
")",
";",
"$",
"newFeedItem",
"->",
"setSitelinkText",
"(",
"$",
"sitelink",
"->",
"getText",
"(",
")",
")",
";",
"$",
"newFeedItem",
"->",
"setSitelinkUrl",
"(",
"$",
"sitelink",
"->",
"getUrl",
"(",
")",
")",
";",
"$",
"newFeedItem",
"->",
"setSitelinkLine2",
"(",
"$",
"sitelink",
"->",
"getLine2",
"(",
")",
")",
";",
"$",
"newFeedItem",
"->",
"setSitelinkLine3",
"(",
"$",
"sitelink",
"->",
"getLine3",
"(",
")",
")",
";",
"$",
"newFeedItem",
"->",
"setSitelinkFinalUrls",
"(",
"$",
"sitelink",
"->",
"getFinalUrls",
"(",
")",
")",
";",
"$",
"newFeedItem",
"->",
"setSitelinkFinalMobileUrls",
"(",
"$",
"sitelink",
"->",
"getFinalMobileUrls",
"(",
")",
")",
";",
"$",
"newFeedItem",
"->",
"setSitelinkTrackingUrlTemplate",
"(",
"$",
"sitelink",
"->",
"getTrackingUrlTemplate",
"(",
")",
")",
";",
"$",
"extensionFeedItems",
"[",
"]",
"=",
"$",
"newFeedItem",
";",
"}",
"$",
"extensionSetting",
"->",
"getExtensionSetting",
"(",
")",
"->",
"setExtensions",
"(",
"$",
"extensionFeedItems",
")",
";",
"$",
"extensionSetting",
"->",
"getExtensionSetting",
"(",
")",
"->",
"setPlatformRestrictions",
"(",
"$",
"platformRestrictions",
")",
";",
"$",
"operation",
"=",
"new",
"CampaignExtensionSettingOperation",
"(",
")",
";",
"$",
"operation",
"->",
"setOperand",
"(",
"$",
"extensionSetting",
")",
";",
"$",
"operation",
"->",
"setOperator",
"(",
"Operator",
"::",
"ADD",
")",
";",
"printf",
"(",
"\"Adding %d sitelinks for campaign ID %d...\\n\"",
",",
"count",
"(",
"$",
"feedItemIds",
")",
",",
"$",
"campaignId",
")",
";",
"return",
"$",
"campaignExtensionSettingService",
"->",
"mutate",
"(",
"[",
"$",
"operation",
"]",
")",
";",
"}"
] | Creates a new extension setting for the specified feed items. | [
"Creates",
"a",
"new",
"extension",
"setting",
"for",
"the",
"specified",
"feed",
"items",
"."
] | d552b800ad53c400b1a50c7852e7ad184245d2ea | https://github.com/googleads/googleads-php-lib/blob/d552b800ad53c400b1a50c7852e7ad184245d2ea/examples/AdWords/v201809/Migration/MigrateToExtensionSettings.php#L459-L509 | train |
googleads/googleads-php-lib | examples/AdWords/v201809/Migration/MigrateToExtensionSettings.php | MigrateToExtensionSettings.deleteCampaignFeed | private static function deleteCampaignFeed(
AdWordsServices $adWordsServices,
AdWordsSession $session,
$campaignFeed
) {
$campaignFeedService = $adWordsServices->get($session, CampaignFeedService::class);
printf(
"Deleting association of feed ID %d and campaign ID %d...\n",
$campaignFeed->getFeedId(),
$campaignFeed->getCampaignId()
);
$operation = new CampaignFeedOperation();
$operation->setOperand($campaignFeed);
$operation->setOperator(Operator::REMOVE);
return $campaignFeedService->mutate([$operation]);
} | php | private static function deleteCampaignFeed(
AdWordsServices $adWordsServices,
AdWordsSession $session,
$campaignFeed
) {
$campaignFeedService = $adWordsServices->get($session, CampaignFeedService::class);
printf(
"Deleting association of feed ID %d and campaign ID %d...\n",
$campaignFeed->getFeedId(),
$campaignFeed->getCampaignId()
);
$operation = new CampaignFeedOperation();
$operation->setOperand($campaignFeed);
$operation->setOperator(Operator::REMOVE);
return $campaignFeedService->mutate([$operation]);
} | [
"private",
"static",
"function",
"deleteCampaignFeed",
"(",
"AdWordsServices",
"$",
"adWordsServices",
",",
"AdWordsSession",
"$",
"session",
",",
"$",
"campaignFeed",
")",
"{",
"$",
"campaignFeedService",
"=",
"$",
"adWordsServices",
"->",
"get",
"(",
"$",
"session",
",",
"CampaignFeedService",
"::",
"class",
")",
";",
"printf",
"(",
"\"Deleting association of feed ID %d and campaign ID %d...\\n\"",
",",
"$",
"campaignFeed",
"->",
"getFeedId",
"(",
")",
",",
"$",
"campaignFeed",
"->",
"getCampaignId",
"(",
")",
")",
";",
"$",
"operation",
"=",
"new",
"CampaignFeedOperation",
"(",
")",
";",
"$",
"operation",
"->",
"setOperand",
"(",
"$",
"campaignFeed",
")",
";",
"$",
"operation",
"->",
"setOperator",
"(",
"Operator",
"::",
"REMOVE",
")",
";",
"return",
"$",
"campaignFeedService",
"->",
"mutate",
"(",
"[",
"$",
"operation",
"]",
")",
";",
"}"
] | Deletes associations of the specified feed IDs and campaign IDs. | [
"Deletes",
"associations",
"of",
"the",
"specified",
"feed",
"IDs",
"and",
"campaign",
"IDs",
"."
] | d552b800ad53c400b1a50c7852e7ad184245d2ea | https://github.com/googleads/googleads-php-lib/blob/d552b800ad53c400b1a50c7852e7ad184245d2ea/examples/AdWords/v201809/Migration/MigrateToExtensionSettings.php#L514-L532 | train |
googleads/googleads-php-lib | examples/AdWords/v201809/Migration/MigrateToExtensionSettings.php | MigrateToExtensionSettings.deleteOldFeedItems | private static function deleteOldFeedItems(
AdWordsServices $adWordsServices,
AdWordsSession $session,
$feedItemIds,
$feedId
) {
if (count($feedItemIds) === 0) {
return;
}
$feedItemService = $adWordsServices->get($session, FeedItemService::class);
$operations = [];
foreach ($feedItemIds as $feedItemId) {
$feedItem = new FeedItem();
$feedItem->setFeedId($feedId);
$feedItem->setFeedItemId($feedItemId);
$operation = new FeedItemOperation();
$operation->setOperand($feedItem);
$operation->setOperator(Operator::REMOVE);
$operations[] = $operation;
}
printf(
"Deleting %d old feed items from feed ID %d...\n",
count($feedItemIds),
$feedId
);
return $feedItemService->mutate($operations);
} | php | private static function deleteOldFeedItems(
AdWordsServices $adWordsServices,
AdWordsSession $session,
$feedItemIds,
$feedId
) {
if (count($feedItemIds) === 0) {
return;
}
$feedItemService = $adWordsServices->get($session, FeedItemService::class);
$operations = [];
foreach ($feedItemIds as $feedItemId) {
$feedItem = new FeedItem();
$feedItem->setFeedId($feedId);
$feedItem->setFeedItemId($feedItemId);
$operation = new FeedItemOperation();
$operation->setOperand($feedItem);
$operation->setOperator(Operator::REMOVE);
$operations[] = $operation;
}
printf(
"Deleting %d old feed items from feed ID %d...\n",
count($feedItemIds),
$feedId
);
return $feedItemService->mutate($operations);
} | [
"private",
"static",
"function",
"deleteOldFeedItems",
"(",
"AdWordsServices",
"$",
"adWordsServices",
",",
"AdWordsSession",
"$",
"session",
",",
"$",
"feedItemIds",
",",
"$",
"feedId",
")",
"{",
"if",
"(",
"count",
"(",
"$",
"feedItemIds",
")",
"===",
"0",
")",
"{",
"return",
";",
"}",
"$",
"feedItemService",
"=",
"$",
"adWordsServices",
"->",
"get",
"(",
"$",
"session",
",",
"FeedItemService",
"::",
"class",
")",
";",
"$",
"operations",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"feedItemIds",
"as",
"$",
"feedItemId",
")",
"{",
"$",
"feedItem",
"=",
"new",
"FeedItem",
"(",
")",
";",
"$",
"feedItem",
"->",
"setFeedId",
"(",
"$",
"feedId",
")",
";",
"$",
"feedItem",
"->",
"setFeedItemId",
"(",
"$",
"feedItemId",
")",
";",
"$",
"operation",
"=",
"new",
"FeedItemOperation",
"(",
")",
";",
"$",
"operation",
"->",
"setOperand",
"(",
"$",
"feedItem",
")",
";",
"$",
"operation",
"->",
"setOperator",
"(",
"Operator",
"::",
"REMOVE",
")",
";",
"$",
"operations",
"[",
"]",
"=",
"$",
"operation",
";",
"}",
"printf",
"(",
"\"Deleting %d old feed items from feed ID %d...\\n\"",
",",
"count",
"(",
"$",
"feedItemIds",
")",
",",
"$",
"feedId",
")",
";",
"return",
"$",
"feedItemService",
"->",
"mutate",
"(",
"$",
"operations",
")",
";",
"}"
] | Deletes old feed items that became unused anymore after migration. | [
"Deletes",
"old",
"feed",
"items",
"that",
"became",
"unused",
"anymore",
"after",
"migration",
"."
] | d552b800ad53c400b1a50c7852e7ad184245d2ea | https://github.com/googleads/googleads-php-lib/blob/d552b800ad53c400b1a50c7852e7ad184245d2ea/examples/AdWords/v201809/Migration/MigrateToExtensionSettings.php#L537-L568 | train |
googleads/googleads-php-lib | examples/AdWords/v201809/AdvancedOperations/AddAdCustomizer.php | AddAdCustomizer.createCustomizerFeed | private static function createCustomizerFeed(
AdWordsServices $adWordsServices,
AdWordsSession $session,
$feedName
) {
$adCustomizerFeedService = $adWordsServices->get($session, AdCustomizerFeedService::class);
$nameAttribute = new AdCustomizerFeedAttribute();
$nameAttribute->setName('Name');
$nameAttribute->setType(AdCustomizerFeedAttributeType::STRING);
$priceAttribute = new AdCustomizerFeedAttribute();
$priceAttribute->setName('Price');
$priceAttribute->setType(AdCustomizerFeedAttributeType::STRING);
$dateAttribute = new AdCustomizerFeedAttribute();
$dateAttribute->setName('Date');
$dateAttribute->setType(AdCustomizerFeedAttributeType::DATE_TIME);
$customizerFeed = new AdCustomizerFeed();
$customizerFeed->setFeedName($feedName);
$customizerFeed->setFeedAttributes(
[$nameAttribute, $priceAttribute, $dateAttribute]
);
$feedOperation = new AdCustomizerFeedOperation();
$feedOperation->setOperand($customizerFeed);
$feedOperation->setOperator(Operator::ADD);
$operations = [$feedOperation];
$result = $adCustomizerFeedService->mutate($operations);
$addedFeed = $result->getValue()[0];
printf(
"Created ad customizer feed with ID %d, name '%s' and attributes:\n",
$addedFeed->getFeedId(),
$addedFeed->getFeedName()
);
if (empty($addedFeed)) {
print " No attributes\n";
} else {
foreach ($addedFeed->getFeedAttributes() as $feedAttribute) {
printf(
" ID: %d, name: '%s', type: %s\n",
$feedAttribute->getId(),
$feedAttribute->getName(),
$feedAttribute->getType()
);
}
}
return $addedFeed;
} | php | private static function createCustomizerFeed(
AdWordsServices $adWordsServices,
AdWordsSession $session,
$feedName
) {
$adCustomizerFeedService = $adWordsServices->get($session, AdCustomizerFeedService::class);
$nameAttribute = new AdCustomizerFeedAttribute();
$nameAttribute->setName('Name');
$nameAttribute->setType(AdCustomizerFeedAttributeType::STRING);
$priceAttribute = new AdCustomizerFeedAttribute();
$priceAttribute->setName('Price');
$priceAttribute->setType(AdCustomizerFeedAttributeType::STRING);
$dateAttribute = new AdCustomizerFeedAttribute();
$dateAttribute->setName('Date');
$dateAttribute->setType(AdCustomizerFeedAttributeType::DATE_TIME);
$customizerFeed = new AdCustomizerFeed();
$customizerFeed->setFeedName($feedName);
$customizerFeed->setFeedAttributes(
[$nameAttribute, $priceAttribute, $dateAttribute]
);
$feedOperation = new AdCustomizerFeedOperation();
$feedOperation->setOperand($customizerFeed);
$feedOperation->setOperator(Operator::ADD);
$operations = [$feedOperation];
$result = $adCustomizerFeedService->mutate($operations);
$addedFeed = $result->getValue()[0];
printf(
"Created ad customizer feed with ID %d, name '%s' and attributes:\n",
$addedFeed->getFeedId(),
$addedFeed->getFeedName()
);
if (empty($addedFeed)) {
print " No attributes\n";
} else {
foreach ($addedFeed->getFeedAttributes() as $feedAttribute) {
printf(
" ID: %d, name: '%s', type: %s\n",
$feedAttribute->getId(),
$feedAttribute->getName(),
$feedAttribute->getType()
);
}
}
return $addedFeed;
} | [
"private",
"static",
"function",
"createCustomizerFeed",
"(",
"AdWordsServices",
"$",
"adWordsServices",
",",
"AdWordsSession",
"$",
"session",
",",
"$",
"feedName",
")",
"{",
"$",
"adCustomizerFeedService",
"=",
"$",
"adWordsServices",
"->",
"get",
"(",
"$",
"session",
",",
"AdCustomizerFeedService",
"::",
"class",
")",
";",
"$",
"nameAttribute",
"=",
"new",
"AdCustomizerFeedAttribute",
"(",
")",
";",
"$",
"nameAttribute",
"->",
"setName",
"(",
"'Name'",
")",
";",
"$",
"nameAttribute",
"->",
"setType",
"(",
"AdCustomizerFeedAttributeType",
"::",
"STRING",
")",
";",
"$",
"priceAttribute",
"=",
"new",
"AdCustomizerFeedAttribute",
"(",
")",
";",
"$",
"priceAttribute",
"->",
"setName",
"(",
"'Price'",
")",
";",
"$",
"priceAttribute",
"->",
"setType",
"(",
"AdCustomizerFeedAttributeType",
"::",
"STRING",
")",
";",
"$",
"dateAttribute",
"=",
"new",
"AdCustomizerFeedAttribute",
"(",
")",
";",
"$",
"dateAttribute",
"->",
"setName",
"(",
"'Date'",
")",
";",
"$",
"dateAttribute",
"->",
"setType",
"(",
"AdCustomizerFeedAttributeType",
"::",
"DATE_TIME",
")",
";",
"$",
"customizerFeed",
"=",
"new",
"AdCustomizerFeed",
"(",
")",
";",
"$",
"customizerFeed",
"->",
"setFeedName",
"(",
"$",
"feedName",
")",
";",
"$",
"customizerFeed",
"->",
"setFeedAttributes",
"(",
"[",
"$",
"nameAttribute",
",",
"$",
"priceAttribute",
",",
"$",
"dateAttribute",
"]",
")",
";",
"$",
"feedOperation",
"=",
"new",
"AdCustomizerFeedOperation",
"(",
")",
";",
"$",
"feedOperation",
"->",
"setOperand",
"(",
"$",
"customizerFeed",
")",
";",
"$",
"feedOperation",
"->",
"setOperator",
"(",
"Operator",
"::",
"ADD",
")",
";",
"$",
"operations",
"=",
"[",
"$",
"feedOperation",
"]",
";",
"$",
"result",
"=",
"$",
"adCustomizerFeedService",
"->",
"mutate",
"(",
"$",
"operations",
")",
";",
"$",
"addedFeed",
"=",
"$",
"result",
"->",
"getValue",
"(",
")",
"[",
"0",
"]",
";",
"printf",
"(",
"\"Created ad customizer feed with ID %d, name '%s' and attributes:\\n\"",
",",
"$",
"addedFeed",
"->",
"getFeedId",
"(",
")",
",",
"$",
"addedFeed",
"->",
"getFeedName",
"(",
")",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"addedFeed",
")",
")",
"{",
"print",
"\" No attributes\\n\"",
";",
"}",
"else",
"{",
"foreach",
"(",
"$",
"addedFeed",
"->",
"getFeedAttributes",
"(",
")",
"as",
"$",
"feedAttribute",
")",
"{",
"printf",
"(",
"\" ID: %d, name: '%s', type: %s\\n\"",
",",
"$",
"feedAttribute",
"->",
"getId",
"(",
")",
",",
"$",
"feedAttribute",
"->",
"getName",
"(",
")",
",",
"$",
"feedAttribute",
"->",
"getType",
"(",
")",
")",
";",
"}",
"}",
"return",
"$",
"addedFeed",
";",
"}"
] | Creates a new feed for AdCustomizerFeed.
@param AdWordsServices $adWordsServices the AdWords services
@param AdWordsSession $session the AdWords session
@param string $feedName the name of feed to be created
@return AdCustomizerFeed the ad customizer feed | [
"Creates",
"a",
"new",
"feed",
"for",
"AdCustomizerFeed",
"."
] | d552b800ad53c400b1a50c7852e7ad184245d2ea | https://github.com/googleads/googleads-php-lib/blob/d552b800ad53c400b1a50c7852e7ad184245d2ea/examples/AdWords/v201809/AdvancedOperations/AddAdCustomizer.php#L89-L141 | train |
googleads/googleads-php-lib | examples/AdWords/v201809/AdvancedOperations/AddAdCustomizer.php | AddAdCustomizer.createCustomizerFeedItems | private static function createCustomizerFeedItems(
AdWordsServices $adWordsServices,
AdWordsSession $session,
AdCustomizerFeed $adCustomizerFeed,
array $adGroupIds
) {
$feedItemService = $adWordsServices->get($session, FeedItemService::class);
$operations = [];
$marsDate = mktime(0, 0, 0, date('m'), 1, date('Y'));
$venusDate = mktime(0, 0, 0, date('m'), 15, date('Y'));
// Create multiple feed item operations and add them to the operations list.
$operations[] = self::createFeedItemAddOperation(
'Mars',
'$1234.56',
date('Ymd His', $marsDate),
$adCustomizerFeed
);
$operations[] = self::createFeedItemAddOperation(
'Venus',
'$1450.00',
date('Ymd His', $venusDate),
$adCustomizerFeed
);
$result = $feedItemService->mutate($operations);
foreach ($result->getValue() as $feedItem) {
printf(
'FeedItem with ID %d was added.%s',
$feedItem->getFeedItemId(),
PHP_EOL
);
}
for ($i = 0; $i < count($result->getValue()); $i++) {
// Add feed item targeting to restrict the feed item to specific ad
// groups.
self::restrictFeedItemToAdGroup(
$adWordsServices,
$session,
$result->getValue()[$i],
$adGroupIds[$i]
);
}
} | php | private static function createCustomizerFeedItems(
AdWordsServices $adWordsServices,
AdWordsSession $session,
AdCustomizerFeed $adCustomizerFeed,
array $adGroupIds
) {
$feedItemService = $adWordsServices->get($session, FeedItemService::class);
$operations = [];
$marsDate = mktime(0, 0, 0, date('m'), 1, date('Y'));
$venusDate = mktime(0, 0, 0, date('m'), 15, date('Y'));
// Create multiple feed item operations and add them to the operations list.
$operations[] = self::createFeedItemAddOperation(
'Mars',
'$1234.56',
date('Ymd His', $marsDate),
$adCustomizerFeed
);
$operations[] = self::createFeedItemAddOperation(
'Venus',
'$1450.00',
date('Ymd His', $venusDate),
$adCustomizerFeed
);
$result = $feedItemService->mutate($operations);
foreach ($result->getValue() as $feedItem) {
printf(
'FeedItem with ID %d was added.%s',
$feedItem->getFeedItemId(),
PHP_EOL
);
}
for ($i = 0; $i < count($result->getValue()); $i++) {
// Add feed item targeting to restrict the feed item to specific ad
// groups.
self::restrictFeedItemToAdGroup(
$adWordsServices,
$session,
$result->getValue()[$i],
$adGroupIds[$i]
);
}
} | [
"private",
"static",
"function",
"createCustomizerFeedItems",
"(",
"AdWordsServices",
"$",
"adWordsServices",
",",
"AdWordsSession",
"$",
"session",
",",
"AdCustomizerFeed",
"$",
"adCustomizerFeed",
",",
"array",
"$",
"adGroupIds",
")",
"{",
"$",
"feedItemService",
"=",
"$",
"adWordsServices",
"->",
"get",
"(",
"$",
"session",
",",
"FeedItemService",
"::",
"class",
")",
";",
"$",
"operations",
"=",
"[",
"]",
";",
"$",
"marsDate",
"=",
"mktime",
"(",
"0",
",",
"0",
",",
"0",
",",
"date",
"(",
"'m'",
")",
",",
"1",
",",
"date",
"(",
"'Y'",
")",
")",
";",
"$",
"venusDate",
"=",
"mktime",
"(",
"0",
",",
"0",
",",
"0",
",",
"date",
"(",
"'m'",
")",
",",
"15",
",",
"date",
"(",
"'Y'",
")",
")",
";",
"// Create multiple feed item operations and add them to the operations list.",
"$",
"operations",
"[",
"]",
"=",
"self",
"::",
"createFeedItemAddOperation",
"(",
"'Mars'",
",",
"'$1234.56'",
",",
"date",
"(",
"'Ymd His'",
",",
"$",
"marsDate",
")",
",",
"$",
"adCustomizerFeed",
")",
";",
"$",
"operations",
"[",
"]",
"=",
"self",
"::",
"createFeedItemAddOperation",
"(",
"'Venus'",
",",
"'$1450.00'",
",",
"date",
"(",
"'Ymd His'",
",",
"$",
"venusDate",
")",
",",
"$",
"adCustomizerFeed",
")",
";",
"$",
"result",
"=",
"$",
"feedItemService",
"->",
"mutate",
"(",
"$",
"operations",
")",
";",
"foreach",
"(",
"$",
"result",
"->",
"getValue",
"(",
")",
"as",
"$",
"feedItem",
")",
"{",
"printf",
"(",
"'FeedItem with ID %d was added.%s'",
",",
"$",
"feedItem",
"->",
"getFeedItemId",
"(",
")",
",",
"PHP_EOL",
")",
";",
"}",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"count",
"(",
"$",
"result",
"->",
"getValue",
"(",
")",
")",
";",
"$",
"i",
"++",
")",
"{",
"// Add feed item targeting to restrict the feed item to specific ad",
"// groups.",
"self",
"::",
"restrictFeedItemToAdGroup",
"(",
"$",
"adWordsServices",
",",
"$",
"session",
",",
"$",
"result",
"->",
"getValue",
"(",
")",
"[",
"$",
"i",
"]",
",",
"$",
"adGroupIds",
"[",
"$",
"i",
"]",
")",
";",
"}",
"}"
] | Creates feed items with the values to use in ad customizations for each ad
group.
@param AdWordsServices $adWordsServices the AdWords services
@param AdWordsSession $session the AdWords session
@param AdCustomizerFeed $adCustomizerFeed the ad customizer feed
@param int[] $adGroupIds the ad group IDs to add the ad customizer | [
"Creates",
"feed",
"items",
"with",
"the",
"values",
"to",
"use",
"in",
"ad",
"customizations",
"for",
"each",
"ad",
"group",
"."
] | d552b800ad53c400b1a50c7852e7ad184245d2ea | https://github.com/googleads/googleads-php-lib/blob/d552b800ad53c400b1a50c7852e7ad184245d2ea/examples/AdWords/v201809/AdvancedOperations/AddAdCustomizer.php#L152-L198 | train |
googleads/googleads-php-lib | examples/AdWords/v201809/AdvancedOperations/AddAdCustomizer.php | AddAdCustomizer.createFeedItemAddOperation | private static function createFeedItemAddOperation(
$name,
$price,
$date,
AdCustomizerFeed $adCustomizerFeed
) {
$nameAttributeValue = new FeedItemAttributeValue();
$nameAttributeValue->setFeedAttributeId(
$adCustomizerFeed->getFeedAttributes()[0]->getId()
);
$nameAttributeValue->setStringValue($name);
$priceAttributeValue = new FeedItemAttributeValue();
$priceAttributeValue->setFeedAttributeId(
$adCustomizerFeed->getFeedAttributes()[1]->getId()
);
$priceAttributeValue->setStringValue($price);
$dateAttributeValue = new FeedItemAttributeValue();
$dateAttributeValue->setFeedAttributeId(
$adCustomizerFeed->getFeedAttributes()[2]->getId()
);
$dateAttributeValue->setStringValue($date);
$item = new FeedItem();
$item->setFeedId($adCustomizerFeed->getFeedId());
$item->setAttributeValues(
[$nameAttributeValue, $priceAttributeValue, $dateAttributeValue]
);
$operation = new FeedItemOperation();
$operation->setOperand($item);
$operation->setOperator('ADD');
return $operation;
} | php | private static function createFeedItemAddOperation(
$name,
$price,
$date,
AdCustomizerFeed $adCustomizerFeed
) {
$nameAttributeValue = new FeedItemAttributeValue();
$nameAttributeValue->setFeedAttributeId(
$adCustomizerFeed->getFeedAttributes()[0]->getId()
);
$nameAttributeValue->setStringValue($name);
$priceAttributeValue = new FeedItemAttributeValue();
$priceAttributeValue->setFeedAttributeId(
$adCustomizerFeed->getFeedAttributes()[1]->getId()
);
$priceAttributeValue->setStringValue($price);
$dateAttributeValue = new FeedItemAttributeValue();
$dateAttributeValue->setFeedAttributeId(
$adCustomizerFeed->getFeedAttributes()[2]->getId()
);
$dateAttributeValue->setStringValue($date);
$item = new FeedItem();
$item->setFeedId($adCustomizerFeed->getFeedId());
$item->setAttributeValues(
[$nameAttributeValue, $priceAttributeValue, $dateAttributeValue]
);
$operation = new FeedItemOperation();
$operation->setOperand($item);
$operation->setOperator('ADD');
return $operation;
} | [
"private",
"static",
"function",
"createFeedItemAddOperation",
"(",
"$",
"name",
",",
"$",
"price",
",",
"$",
"date",
",",
"AdCustomizerFeed",
"$",
"adCustomizerFeed",
")",
"{",
"$",
"nameAttributeValue",
"=",
"new",
"FeedItemAttributeValue",
"(",
")",
";",
"$",
"nameAttributeValue",
"->",
"setFeedAttributeId",
"(",
"$",
"adCustomizerFeed",
"->",
"getFeedAttributes",
"(",
")",
"[",
"0",
"]",
"->",
"getId",
"(",
")",
")",
";",
"$",
"nameAttributeValue",
"->",
"setStringValue",
"(",
"$",
"name",
")",
";",
"$",
"priceAttributeValue",
"=",
"new",
"FeedItemAttributeValue",
"(",
")",
";",
"$",
"priceAttributeValue",
"->",
"setFeedAttributeId",
"(",
"$",
"adCustomizerFeed",
"->",
"getFeedAttributes",
"(",
")",
"[",
"1",
"]",
"->",
"getId",
"(",
")",
")",
";",
"$",
"priceAttributeValue",
"->",
"setStringValue",
"(",
"$",
"price",
")",
";",
"$",
"dateAttributeValue",
"=",
"new",
"FeedItemAttributeValue",
"(",
")",
";",
"$",
"dateAttributeValue",
"->",
"setFeedAttributeId",
"(",
"$",
"adCustomizerFeed",
"->",
"getFeedAttributes",
"(",
")",
"[",
"2",
"]",
"->",
"getId",
"(",
")",
")",
";",
"$",
"dateAttributeValue",
"->",
"setStringValue",
"(",
"$",
"date",
")",
";",
"$",
"item",
"=",
"new",
"FeedItem",
"(",
")",
";",
"$",
"item",
"->",
"setFeedId",
"(",
"$",
"adCustomizerFeed",
"->",
"getFeedId",
"(",
")",
")",
";",
"$",
"item",
"->",
"setAttributeValues",
"(",
"[",
"$",
"nameAttributeValue",
",",
"$",
"priceAttributeValue",
",",
"$",
"dateAttributeValue",
"]",
")",
";",
"$",
"operation",
"=",
"new",
"FeedItemOperation",
"(",
")",
";",
"$",
"operation",
"->",
"setOperand",
"(",
"$",
"item",
")",
";",
"$",
"operation",
"->",
"setOperator",
"(",
"'ADD'",
")",
";",
"return",
"$",
"operation",
";",
"}"
] | Creates a feed item operation that will create a feed item with the
specified values and ad group target when sent to FeedItemService.mutate.
@param string $name the value for the name attribute of the feed item
@param string $price the value for the price attribute of the feed item
@param string $date the value for the date attribute of the feed item
@param AdCustomizerFeed $adCustomizerFeed the customizer feed
@return FeedItemOperation the feed item operation | [
"Creates",
"a",
"feed",
"item",
"operation",
"that",
"will",
"create",
"a",
"feed",
"item",
"with",
"the",
"specified",
"values",
"and",
"ad",
"group",
"target",
"when",
"sent",
"to",
"FeedItemService",
".",
"mutate",
"."
] | d552b800ad53c400b1a50c7852e7ad184245d2ea | https://github.com/googleads/googleads-php-lib/blob/d552b800ad53c400b1a50c7852e7ad184245d2ea/examples/AdWords/v201809/AdvancedOperations/AddAdCustomizer.php#L210-L245 | train |
googleads/googleads-php-lib | examples/AdWords/v201809/AdvancedOperations/AddAdCustomizer.php | AddAdCustomizer.restrictFeedItemToAdGroup | private static function restrictFeedItemToAdGroup(
AdWordsServices $adWordsServices,
AdWordsSession $session,
FeedItem $feedItem,
$adGroupId
) {
$feedItemTargetService =
$adWordsServices->get($session, FeedItemTargetService::class);
// Create a feed item ad group target.
$adGroupTarget = new FeedItemAdGroupTarget();
$adGroupTarget->setFeedId($feedItem->getFeedId());
$adGroupTarget->setFeedItemId($feedItem->getFeedItemId());
$adGroupTarget->setAdGroupId($adGroupId);
// Create a feed item target operation.
$operation = new FeedItemTargetOperation();
$operation->setOperator(Operator::ADD);
$operation->setOperand($adGroupTarget);
// Add a feed item target on the server and print out some information.
$result = $feedItemTargetService->mutate([$operation]);
$addedAdGroupTarget = $result->getValue()[0];
sprintf(
'Feed item target for feed ID %s and feed item ID %s '
. 'was created to restrict serving to ad group ID %s.%s',
$addedAdGroupTarget->getFeedId(),
$addedAdGroupTarget->getFeedItemId(),
$addedAdGroupTarget->getAdGroupId(),
PHP_EOL
);
} | php | private static function restrictFeedItemToAdGroup(
AdWordsServices $adWordsServices,
AdWordsSession $session,
FeedItem $feedItem,
$adGroupId
) {
$feedItemTargetService =
$adWordsServices->get($session, FeedItemTargetService::class);
// Create a feed item ad group target.
$adGroupTarget = new FeedItemAdGroupTarget();
$adGroupTarget->setFeedId($feedItem->getFeedId());
$adGroupTarget->setFeedItemId($feedItem->getFeedItemId());
$adGroupTarget->setAdGroupId($adGroupId);
// Create a feed item target operation.
$operation = new FeedItemTargetOperation();
$operation->setOperator(Operator::ADD);
$operation->setOperand($adGroupTarget);
// Add a feed item target on the server and print out some information.
$result = $feedItemTargetService->mutate([$operation]);
$addedAdGroupTarget = $result->getValue()[0];
sprintf(
'Feed item target for feed ID %s and feed item ID %s '
. 'was created to restrict serving to ad group ID %s.%s',
$addedAdGroupTarget->getFeedId(),
$addedAdGroupTarget->getFeedItemId(),
$addedAdGroupTarget->getAdGroupId(),
PHP_EOL
);
} | [
"private",
"static",
"function",
"restrictFeedItemToAdGroup",
"(",
"AdWordsServices",
"$",
"adWordsServices",
",",
"AdWordsSession",
"$",
"session",
",",
"FeedItem",
"$",
"feedItem",
",",
"$",
"adGroupId",
")",
"{",
"$",
"feedItemTargetService",
"=",
"$",
"adWordsServices",
"->",
"get",
"(",
"$",
"session",
",",
"FeedItemTargetService",
"::",
"class",
")",
";",
"// Create a feed item ad group target.",
"$",
"adGroupTarget",
"=",
"new",
"FeedItemAdGroupTarget",
"(",
")",
";",
"$",
"adGroupTarget",
"->",
"setFeedId",
"(",
"$",
"feedItem",
"->",
"getFeedId",
"(",
")",
")",
";",
"$",
"adGroupTarget",
"->",
"setFeedItemId",
"(",
"$",
"feedItem",
"->",
"getFeedItemId",
"(",
")",
")",
";",
"$",
"adGroupTarget",
"->",
"setAdGroupId",
"(",
"$",
"adGroupId",
")",
";",
"// Create a feed item target operation.",
"$",
"operation",
"=",
"new",
"FeedItemTargetOperation",
"(",
")",
";",
"$",
"operation",
"->",
"setOperator",
"(",
"Operator",
"::",
"ADD",
")",
";",
"$",
"operation",
"->",
"setOperand",
"(",
"$",
"adGroupTarget",
")",
";",
"// Add a feed item target on the server and print out some information.",
"$",
"result",
"=",
"$",
"feedItemTargetService",
"->",
"mutate",
"(",
"[",
"$",
"operation",
"]",
")",
";",
"$",
"addedAdGroupTarget",
"=",
"$",
"result",
"->",
"getValue",
"(",
")",
"[",
"0",
"]",
";",
"sprintf",
"(",
"'Feed item target for feed ID %s and feed item ID %s '",
".",
"'was created to restrict serving to ad group ID %s.%s'",
",",
"$",
"addedAdGroupTarget",
"->",
"getFeedId",
"(",
")",
",",
"$",
"addedAdGroupTarget",
"->",
"getFeedItemId",
"(",
")",
",",
"$",
"addedAdGroupTarget",
"->",
"getAdGroupId",
"(",
")",
",",
"PHP_EOL",
")",
";",
"}"
] | Restricts the feed item to an ad group.
@param AdWordsServices $adWordsServices the AdWords services
@param AdWordsSession $session the AdWords session
@param FeedItem $feedItem the feed item to restrict
@param int $adGroupId the ad group ID to which the feed item will be
restricted | [
"Restricts",
"the",
"feed",
"item",
"to",
"an",
"ad",
"group",
"."
] | d552b800ad53c400b1a50c7852e7ad184245d2ea | https://github.com/googleads/googleads-php-lib/blob/d552b800ad53c400b1a50c7852e7ad184245d2ea/examples/AdWords/v201809/AdvancedOperations/AddAdCustomizer.php#L256-L287 | train |
googleads/googleads-php-lib | examples/AdWords/v201809/AdvancedOperations/AddAdCustomizer.php | AddAdCustomizer.createAdsWithCustomizations | private static function createAdsWithCustomizations(
AdWordsServices $adWordsServices,
AdWordsSession $session,
array $adGroupIds,
$feedName
) {
$adGroupAdService = $adWordsServices->get($session, AdGroupAdService::class);
$operations = [];
// Create an expanded text ad that uses ad customization.
$expandedTextAd = new ExpandedTextAd();
$expandedTextAd->setHeadlinePart1(
sprintf('Luxury Cruise to {=%s.Name}', $feedName)
);
$expandedTextAd->setHeadlinePart2(
sprintf('Only {=%s.Price}', $feedName)
);
$expandedTextAd->setDescription(
sprintf('Offer ends in {=countdown(%s.Date)}!', $feedName)
);
$expandedTextAd->setFinalUrls(['http://www.example.com']);
$adGroupAd = new AdGroupAd();
$adGroupAd->setAdGroupId($adGroupIds[0]);
$adGroupAd->setAd($expandedTextAd);
$operation = new AdGroupAdOperation();
$operation->setOperand($adGroupAd);
$operation->setOperator(Operator::ADD);
$operations[] = $operation;
// Create another expanded text ad with the same properties as the first
// one for another ad group.
// This is done to prevent PHP SoapClient from making a reference
// to this object in the generated XML payload, which is not recognized by
// AdWords API.
$expandedTextAd2 = new ExpandedTextAd();
$expandedTextAd2->setHeadlinePart1(
sprintf('Luxury Cruise to {=%s.Name}', $feedName)
);
$expandedTextAd2->setHeadlinePart2(
sprintf('Only {=%s.Price}', $feedName)
);
$expandedTextAd2->setDescription(
sprintf('Offer ends in {=countdown(%s.Date)}!', $feedName)
);
$expandedTextAd2->setFinalUrls(['http://www.example.com']);
$adGroupAd = new AdGroupAd();
$adGroupAd->setAdGroupId($adGroupIds[1]);
$adGroupAd->setAd($expandedTextAd2);
$operation = new AdGroupAdOperation();
$operation->setOperand($adGroupAd);
$operation->setOperator(Operator::ADD);
$operations[] = $operation;
$result = $adGroupAdService->mutate($operations);
foreach ($result->getValue() as $adGroupAd) {
printf(
"Expanded text ad with ID %d and status '%s' was added.\n",
$adGroupAd->getAd()->getId(),
$adGroupAd->getStatus()
);
}
} | php | private static function createAdsWithCustomizations(
AdWordsServices $adWordsServices,
AdWordsSession $session,
array $adGroupIds,
$feedName
) {
$adGroupAdService = $adWordsServices->get($session, AdGroupAdService::class);
$operations = [];
// Create an expanded text ad that uses ad customization.
$expandedTextAd = new ExpandedTextAd();
$expandedTextAd->setHeadlinePart1(
sprintf('Luxury Cruise to {=%s.Name}', $feedName)
);
$expandedTextAd->setHeadlinePart2(
sprintf('Only {=%s.Price}', $feedName)
);
$expandedTextAd->setDescription(
sprintf('Offer ends in {=countdown(%s.Date)}!', $feedName)
);
$expandedTextAd->setFinalUrls(['http://www.example.com']);
$adGroupAd = new AdGroupAd();
$adGroupAd->setAdGroupId($adGroupIds[0]);
$adGroupAd->setAd($expandedTextAd);
$operation = new AdGroupAdOperation();
$operation->setOperand($adGroupAd);
$operation->setOperator(Operator::ADD);
$operations[] = $operation;
// Create another expanded text ad with the same properties as the first
// one for another ad group.
// This is done to prevent PHP SoapClient from making a reference
// to this object in the generated XML payload, which is not recognized by
// AdWords API.
$expandedTextAd2 = new ExpandedTextAd();
$expandedTextAd2->setHeadlinePart1(
sprintf('Luxury Cruise to {=%s.Name}', $feedName)
);
$expandedTextAd2->setHeadlinePart2(
sprintf('Only {=%s.Price}', $feedName)
);
$expandedTextAd2->setDescription(
sprintf('Offer ends in {=countdown(%s.Date)}!', $feedName)
);
$expandedTextAd2->setFinalUrls(['http://www.example.com']);
$adGroupAd = new AdGroupAd();
$adGroupAd->setAdGroupId($adGroupIds[1]);
$adGroupAd->setAd($expandedTextAd2);
$operation = new AdGroupAdOperation();
$operation->setOperand($adGroupAd);
$operation->setOperator(Operator::ADD);
$operations[] = $operation;
$result = $adGroupAdService->mutate($operations);
foreach ($result->getValue() as $adGroupAd) {
printf(
"Expanded text ad with ID %d and status '%s' was added.\n",
$adGroupAd->getAd()->getId(),
$adGroupAd->getStatus()
);
}
} | [
"private",
"static",
"function",
"createAdsWithCustomizations",
"(",
"AdWordsServices",
"$",
"adWordsServices",
",",
"AdWordsSession",
"$",
"session",
",",
"array",
"$",
"adGroupIds",
",",
"$",
"feedName",
")",
"{",
"$",
"adGroupAdService",
"=",
"$",
"adWordsServices",
"->",
"get",
"(",
"$",
"session",
",",
"AdGroupAdService",
"::",
"class",
")",
";",
"$",
"operations",
"=",
"[",
"]",
";",
"// Create an expanded text ad that uses ad customization.",
"$",
"expandedTextAd",
"=",
"new",
"ExpandedTextAd",
"(",
")",
";",
"$",
"expandedTextAd",
"->",
"setHeadlinePart1",
"(",
"sprintf",
"(",
"'Luxury Cruise to {=%s.Name}'",
",",
"$",
"feedName",
")",
")",
";",
"$",
"expandedTextAd",
"->",
"setHeadlinePart2",
"(",
"sprintf",
"(",
"'Only {=%s.Price}'",
",",
"$",
"feedName",
")",
")",
";",
"$",
"expandedTextAd",
"->",
"setDescription",
"(",
"sprintf",
"(",
"'Offer ends in {=countdown(%s.Date)}!'",
",",
"$",
"feedName",
")",
")",
";",
"$",
"expandedTextAd",
"->",
"setFinalUrls",
"(",
"[",
"'http://www.example.com'",
"]",
")",
";",
"$",
"adGroupAd",
"=",
"new",
"AdGroupAd",
"(",
")",
";",
"$",
"adGroupAd",
"->",
"setAdGroupId",
"(",
"$",
"adGroupIds",
"[",
"0",
"]",
")",
";",
"$",
"adGroupAd",
"->",
"setAd",
"(",
"$",
"expandedTextAd",
")",
";",
"$",
"operation",
"=",
"new",
"AdGroupAdOperation",
"(",
")",
";",
"$",
"operation",
"->",
"setOperand",
"(",
"$",
"adGroupAd",
")",
";",
"$",
"operation",
"->",
"setOperator",
"(",
"Operator",
"::",
"ADD",
")",
";",
"$",
"operations",
"[",
"]",
"=",
"$",
"operation",
";",
"// Create another expanded text ad with the same properties as the first",
"// one for another ad group.",
"// This is done to prevent PHP SoapClient from making a reference",
"// to this object in the generated XML payload, which is not recognized by",
"// AdWords API.",
"$",
"expandedTextAd2",
"=",
"new",
"ExpandedTextAd",
"(",
")",
";",
"$",
"expandedTextAd2",
"->",
"setHeadlinePart1",
"(",
"sprintf",
"(",
"'Luxury Cruise to {=%s.Name}'",
",",
"$",
"feedName",
")",
")",
";",
"$",
"expandedTextAd2",
"->",
"setHeadlinePart2",
"(",
"sprintf",
"(",
"'Only {=%s.Price}'",
",",
"$",
"feedName",
")",
")",
";",
"$",
"expandedTextAd2",
"->",
"setDescription",
"(",
"sprintf",
"(",
"'Offer ends in {=countdown(%s.Date)}!'",
",",
"$",
"feedName",
")",
")",
";",
"$",
"expandedTextAd2",
"->",
"setFinalUrls",
"(",
"[",
"'http://www.example.com'",
"]",
")",
";",
"$",
"adGroupAd",
"=",
"new",
"AdGroupAd",
"(",
")",
";",
"$",
"adGroupAd",
"->",
"setAdGroupId",
"(",
"$",
"adGroupIds",
"[",
"1",
"]",
")",
";",
"$",
"adGroupAd",
"->",
"setAd",
"(",
"$",
"expandedTextAd2",
")",
";",
"$",
"operation",
"=",
"new",
"AdGroupAdOperation",
"(",
")",
";",
"$",
"operation",
"->",
"setOperand",
"(",
"$",
"adGroupAd",
")",
";",
"$",
"operation",
"->",
"setOperator",
"(",
"Operator",
"::",
"ADD",
")",
";",
"$",
"operations",
"[",
"]",
"=",
"$",
"operation",
";",
"$",
"result",
"=",
"$",
"adGroupAdService",
"->",
"mutate",
"(",
"$",
"operations",
")",
";",
"foreach",
"(",
"$",
"result",
"->",
"getValue",
"(",
")",
"as",
"$",
"adGroupAd",
")",
"{",
"printf",
"(",
"\"Expanded text ad with ID %d and status '%s' was added.\\n\"",
",",
"$",
"adGroupAd",
"->",
"getAd",
"(",
")",
"->",
"getId",
"(",
")",
",",
"$",
"adGroupAd",
"->",
"getStatus",
"(",
")",
")",
";",
"}",
"}"
] | Creates expanded text ads that use ad customizations for the specified
ad group IDs.
@param AdWordsServices $adWordsServices the AdWords services
@param AdWordsSession $session the AdWords session
@param int[] $adGroupIds the ad group IDs to add the ad customizer
@param string $feedName the name of feed to be created | [
"Creates",
"expanded",
"text",
"ads",
"that",
"use",
"ad",
"customizations",
"for",
"the",
"specified",
"ad",
"group",
"IDs",
"."
] | d552b800ad53c400b1a50c7852e7ad184245d2ea | https://github.com/googleads/googleads-php-lib/blob/d552b800ad53c400b1a50c7852e7ad184245d2ea/examples/AdWords/v201809/AdvancedOperations/AddAdCustomizer.php#L299-L365 | train |
googleads/googleads-php-lib | src/Google/AdsApi/Common/Configuration.php | Configuration.getConfiguration | public function getConfiguration($name, $section = null)
{
$configValue = null;
if ($section === null) {
if (array_key_exists($name, $this->config)) {
$configValue = $this->config[$name];
}
} else {
if (array_key_exists($section, $this->config)) {
$sectionSettings = $this->config[$section];
if (array_key_exists($name, $sectionSettings)) {
$configValue = $sectionSettings[$name];
}
}
}
return $configValue;
} | php | public function getConfiguration($name, $section = null)
{
$configValue = null;
if ($section === null) {
if (array_key_exists($name, $this->config)) {
$configValue = $this->config[$name];
}
} else {
if (array_key_exists($section, $this->config)) {
$sectionSettings = $this->config[$section];
if (array_key_exists($name, $sectionSettings)) {
$configValue = $sectionSettings[$name];
}
}
}
return $configValue;
} | [
"public",
"function",
"getConfiguration",
"(",
"$",
"name",
",",
"$",
"section",
"=",
"null",
")",
"{",
"$",
"configValue",
"=",
"null",
";",
"if",
"(",
"$",
"section",
"===",
"null",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"name",
",",
"$",
"this",
"->",
"config",
")",
")",
"{",
"$",
"configValue",
"=",
"$",
"this",
"->",
"config",
"[",
"$",
"name",
"]",
";",
"}",
"}",
"else",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"section",
",",
"$",
"this",
"->",
"config",
")",
")",
"{",
"$",
"sectionSettings",
"=",
"$",
"this",
"->",
"config",
"[",
"$",
"section",
"]",
";",
"if",
"(",
"array_key_exists",
"(",
"$",
"name",
",",
"$",
"sectionSettings",
")",
")",
"{",
"$",
"configValue",
"=",
"$",
"sectionSettings",
"[",
"$",
"name",
"]",
";",
"}",
"}",
"}",
"return",
"$",
"configValue",
";",
"}"
] | Gets the value for the specified setting name.
@param string $name the setting name
@param string $section optional, the name of the section containing the
setting
@return string|null the value of the setting, or null if it doesn't exist | [
"Gets",
"the",
"value",
"for",
"the",
"specified",
"setting",
"name",
"."
] | d552b800ad53c400b1a50c7852e7ad184245d2ea | https://github.com/googleads/googleads-php-lib/blob/d552b800ad53c400b1a50c7852e7ad184245d2ea/src/Google/AdsApi/Common/Configuration.php#L47-L65 | train |
googleads/googleads-php-lib | src/Google/AdsApi/AdManager/AdManagerHeaderHandler.php | AdManagerHeaderHandler.createSoapHeaderObject | private function createSoapHeaderObject(
AdsServiceDescriptor $serviceDescriptor
) {
// The SOAP header object is in the same namespace as the Ad Manager
// service we are generating headers for.
$reflectionClass = new ReflectionClass(
$serviceDescriptor->getServiceClass()
);
return $this->reflection->createInstance(
sprintf(
'%s\\%s',
$reflectionClass->getNamespaceName(),
self::SOAP_HEADER_CLASS_NAME
)
);
} | php | private function createSoapHeaderObject(
AdsServiceDescriptor $serviceDescriptor
) {
// The SOAP header object is in the same namespace as the Ad Manager
// service we are generating headers for.
$reflectionClass = new ReflectionClass(
$serviceDescriptor->getServiceClass()
);
return $this->reflection->createInstance(
sprintf(
'%s\\%s',
$reflectionClass->getNamespaceName(),
self::SOAP_HEADER_CLASS_NAME
)
);
} | [
"private",
"function",
"createSoapHeaderObject",
"(",
"AdsServiceDescriptor",
"$",
"serviceDescriptor",
")",
"{",
"// The SOAP header object is in the same namespace as the Ad Manager",
"// service we are generating headers for.",
"$",
"reflectionClass",
"=",
"new",
"ReflectionClass",
"(",
"$",
"serviceDescriptor",
"->",
"getServiceClass",
"(",
")",
")",
";",
"return",
"$",
"this",
"->",
"reflection",
"->",
"createInstance",
"(",
"sprintf",
"(",
"'%s\\\\%s'",
",",
"$",
"reflectionClass",
"->",
"getNamespaceName",
"(",
")",
",",
"self",
"::",
"SOAP_HEADER_CLASS_NAME",
")",
")",
";",
"}"
] | Creates a new instance of the SOAP header object used by the Ad Manager
API. | [
"Creates",
"a",
"new",
"instance",
"of",
"the",
"SOAP",
"header",
"object",
"used",
"by",
"the",
"Ad",
"Manager",
"API",
"."
] | d552b800ad53c400b1a50c7852e7ad184245d2ea | https://github.com/googleads/googleads-php-lib/blob/d552b800ad53c400b1a50c7852e7ad184245d2ea/src/Google/AdsApi/AdManager/AdManagerHeaderHandler.php#L113-L129 | train |
googleads/googleads-php-lib | src/Google/AdsApi/AdManager/v201811/LineItemCreativeAssociationService.php | LineItemCreativeAssociationService.getPreviewUrl | public function getPreviewUrl($lineItemId, $creativeId, $siteUrl)
{
return $this->__soapCall('getPreviewUrl', array(array('lineItemId' => $lineItemId, 'creativeId' => $creativeId, 'siteUrl' => $siteUrl)))->getRval();
} | php | public function getPreviewUrl($lineItemId, $creativeId, $siteUrl)
{
return $this->__soapCall('getPreviewUrl', array(array('lineItemId' => $lineItemId, 'creativeId' => $creativeId, 'siteUrl' => $siteUrl)))->getRval();
} | [
"public",
"function",
"getPreviewUrl",
"(",
"$",
"lineItemId",
",",
"$",
"creativeId",
",",
"$",
"siteUrl",
")",
"{",
"return",
"$",
"this",
"->",
"__soapCall",
"(",
"'getPreviewUrl'",
",",
"array",
"(",
"array",
"(",
"'lineItemId'",
"=>",
"$",
"lineItemId",
",",
"'creativeId'",
"=>",
"$",
"creativeId",
",",
"'siteUrl'",
"=>",
"$",
"siteUrl",
")",
")",
")",
"->",
"getRval",
"(",
")",
";",
"}"
] | Returns an insite preview URL that references the specified site URL with
the specified creative from the association served to it. For Creative Set
previewing you may specify the master creative Id.
creative served to it
@param int $lineItemId
@param int $creativeId
@param string $siteUrl
@return string
@throws \Google\AdsApi\AdManager\v201811\ApiException | [
"Returns",
"an",
"insite",
"preview",
"URL",
"that",
"references",
"the",
"specified",
"site",
"URL",
"with",
"the",
"specified",
"creative",
"from",
"the",
"association",
"served",
"to",
"it",
".",
"For",
"Creative",
"Set",
"previewing",
"you",
"may",
"specify",
"the",
"master",
"creative",
"Id",
"."
] | d552b800ad53c400b1a50c7852e7ad184245d2ea | https://github.com/googleads/googleads-php-lib/blob/d552b800ad53c400b1a50c7852e7ad184245d2ea/src/Google/AdsApi/AdManager/v201811/LineItemCreativeAssociationService.php#L198-L201 | train |
googleads/googleads-php-lib | src/Google/AdsApi/AdManager/v201811/LineItemCreativeAssociationService.php | LineItemCreativeAssociationService.getPreviewUrlsForNativeStyles | public function getPreviewUrlsForNativeStyles($lineItemId, $creativeId, $siteUrl)
{
return $this->__soapCall('getPreviewUrlsForNativeStyles', array(array('lineItemId' => $lineItemId, 'creativeId' => $creativeId, 'siteUrl' => $siteUrl)))->getRval();
} | php | public function getPreviewUrlsForNativeStyles($lineItemId, $creativeId, $siteUrl)
{
return $this->__soapCall('getPreviewUrlsForNativeStyles', array(array('lineItemId' => $lineItemId, 'creativeId' => $creativeId, 'siteUrl' => $siteUrl)))->getRval();
} | [
"public",
"function",
"getPreviewUrlsForNativeStyles",
"(",
"$",
"lineItemId",
",",
"$",
"creativeId",
",",
"$",
"siteUrl",
")",
"{",
"return",
"$",
"this",
"->",
"__soapCall",
"(",
"'getPreviewUrlsForNativeStyles'",
",",
"array",
"(",
"array",
"(",
"'lineItemId'",
"=>",
"$",
"lineItemId",
",",
"'creativeId'",
"=>",
"$",
"creativeId",
",",
"'siteUrl'",
"=>",
"$",
"siteUrl",
")",
")",
")",
"->",
"getRval",
"(",
")",
";",
"}"
] | Returns a list of URLs that reference the specified site URL with the specified creative from
the association served to it. For Creative Set previewing you may specify the master creative
Id. Each URL corresponds to one available native style for previewing the specified creative.
creative
specified creative with the available native styles
@param int $lineItemId
@param int $creativeId
@param string $siteUrl
@return \Google\AdsApi\AdManager\v201811\CreativeNativeStylePreview[]
@throws \Google\AdsApi\AdManager\v201811\ApiException | [
"Returns",
"a",
"list",
"of",
"URLs",
"that",
"reference",
"the",
"specified",
"site",
"URL",
"with",
"the",
"specified",
"creative",
"from",
"the",
"association",
"served",
"to",
"it",
".",
"For",
"Creative",
"Set",
"previewing",
"you",
"may",
"specify",
"the",
"master",
"creative",
"Id",
".",
"Each",
"URL",
"corresponds",
"to",
"one",
"available",
"native",
"style",
"for",
"previewing",
"the",
"specified",
"creative",
"."
] | d552b800ad53c400b1a50c7852e7ad184245d2ea | https://github.com/googleads/googleads-php-lib/blob/d552b800ad53c400b1a50c7852e7ad184245d2ea/src/Google/AdsApi/AdManager/v201811/LineItemCreativeAssociationService.php#L217-L220 | train |
googleads/googleads-php-lib | examples/AdWords/v201809/AccountManagement/GetAccountHierarchy.php | GetAccountHierarchy.printAccountHierarchy | private static function printAccountHierarchy(
$account,
$customerIdsToAccounts,
$customerIdsToChildLinks,
$depth = null
) {
if ($depth === null) {
print "(Customer ID, Account Name)\n";
self::printAccountHierarchy(
$account,
$customerIdsToAccounts,
$customerIdsToChildLinks,
0
);
return;
}
print str_repeat('-', $depth * 2);
$customerId = $account->getCustomerId();
printf("%s, %s\n", $customerId, $account->getName());
if (array_key_exists($customerId, $customerIdsToChildLinks)) {
foreach ($customerIdsToChildLinks[strval($customerId)] as $childLink) {
$childAccount = $customerIdsToAccounts[strval($childLink->getClientCustomerId())];
self::printAccountHierarchy(
$childAccount,
$customerIdsToAccounts,
$customerIdsToChildLinks,
$depth + 1
);
}
}
} | php | private static function printAccountHierarchy(
$account,
$customerIdsToAccounts,
$customerIdsToChildLinks,
$depth = null
) {
if ($depth === null) {
print "(Customer ID, Account Name)\n";
self::printAccountHierarchy(
$account,
$customerIdsToAccounts,
$customerIdsToChildLinks,
0
);
return;
}
print str_repeat('-', $depth * 2);
$customerId = $account->getCustomerId();
printf("%s, %s\n", $customerId, $account->getName());
if (array_key_exists($customerId, $customerIdsToChildLinks)) {
foreach ($customerIdsToChildLinks[strval($customerId)] as $childLink) {
$childAccount = $customerIdsToAccounts[strval($childLink->getClientCustomerId())];
self::printAccountHierarchy(
$childAccount,
$customerIdsToAccounts,
$customerIdsToChildLinks,
$depth + 1
);
}
}
} | [
"private",
"static",
"function",
"printAccountHierarchy",
"(",
"$",
"account",
",",
"$",
"customerIdsToAccounts",
",",
"$",
"customerIdsToChildLinks",
",",
"$",
"depth",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"depth",
"===",
"null",
")",
"{",
"print",
"\"(Customer ID, Account Name)\\n\"",
";",
"self",
"::",
"printAccountHierarchy",
"(",
"$",
"account",
",",
"$",
"customerIdsToAccounts",
",",
"$",
"customerIdsToChildLinks",
",",
"0",
")",
";",
"return",
";",
"}",
"print",
"str_repeat",
"(",
"'-'",
",",
"$",
"depth",
"*",
"2",
")",
";",
"$",
"customerId",
"=",
"$",
"account",
"->",
"getCustomerId",
"(",
")",
";",
"printf",
"(",
"\"%s, %s\\n\"",
",",
"$",
"customerId",
",",
"$",
"account",
"->",
"getName",
"(",
")",
")",
";",
"if",
"(",
"array_key_exists",
"(",
"$",
"customerId",
",",
"$",
"customerIdsToChildLinks",
")",
")",
"{",
"foreach",
"(",
"$",
"customerIdsToChildLinks",
"[",
"strval",
"(",
"$",
"customerId",
")",
"]",
"as",
"$",
"childLink",
")",
"{",
"$",
"childAccount",
"=",
"$",
"customerIdsToAccounts",
"[",
"strval",
"(",
"$",
"childLink",
"->",
"getClientCustomerId",
"(",
")",
")",
"]",
";",
"self",
"::",
"printAccountHierarchy",
"(",
"$",
"childAccount",
",",
"$",
"customerIdsToAccounts",
",",
"$",
"customerIdsToChildLinks",
",",
"$",
"depth",
"+",
"1",
")",
";",
"}",
"}",
"}"
] | Prints the specified account's hierarchy using recursion.
@param ManagedCustomer $account the account to print
@param array $customerIdsToAccounts a map from customer IDs to accounts
@param array $customerIdsToChildLinks a map from customer IDs to child
links
@param int|null $depth the current depth we are printing from in the
account hierarchy; i.e., how far we've recursed | [
"Prints",
"the",
"specified",
"account",
"s",
"hierarchy",
"using",
"recursion",
"."
] | d552b800ad53c400b1a50c7852e7ad184245d2ea | https://github.com/googleads/googleads-php-lib/blob/d552b800ad53c400b1a50c7852e7ad184245d2ea/examples/AdWords/v201809/AccountManagement/GetAccountHierarchy.php#L125-L158 | train |
googleads/googleads-php-lib | examples/AdWords/LaravelSampleApp/app/Http/Controllers/AdWordsApiController.php | AdWordsApiController.getCampaignsAction | public function getCampaignsAction(
Request $request,
FetchAuthTokenInterface $oAuth2Credential,
AdWordsServices $adWordsServices,
AdWordsSessionBuilder $adWordsSessionBuilder
) {
if ($request->method() === 'POST') {
// Always select at least the "Id" field.
$selectedFields = array_values(
['id' => 'Id'] + $request->except(
['_token', 'clientCustomerId', 'entriesPerPage']
)
);
$clientCustomerId = $request->input('clientCustomerId');
$entriesPerPage = $request->input('entriesPerPage');
// Construct an API session configured from a properties file and
// the OAuth2 credentials above.
$session =
$adWordsSessionBuilder->fromFile(config('app.adsapi_php_path'))
->withOAuth2Credential($oAuth2Credential)
->withClientCustomerId($clientCustomerId)
->build();
$request->session()->put('selectedFields', $selectedFields);
$request->session()->put('entriesPerPage', $entriesPerPage);
$request->session()->put('session', $session);
} else {
$selectedFields = $request->session()->get('selectedFields');
$entriesPerPage = $request->session()->get('entriesPerPage');
$session = $request->session()->get('session');
}
$pageNo = $request->input('page') ?: 1;
$collection = self::fetchCampaigns(
$request,
$adWordsServices->get($session, CampaignService::class),
$selectedFields,
$entriesPerPage,
$pageNo
);
// Create a length aware paginator to supply campaigns for the view,
// based on the specified number of entries per page.
$campaigns = new LengthAwarePaginator(
$collection,
$request->session()->get('totalNumEntries'),
$entriesPerPage,
$pageNo,
['path' => url('get-campaigns')]
);
return view('campaigns', compact('campaigns', 'selectedFields'));
} | php | public function getCampaignsAction(
Request $request,
FetchAuthTokenInterface $oAuth2Credential,
AdWordsServices $adWordsServices,
AdWordsSessionBuilder $adWordsSessionBuilder
) {
if ($request->method() === 'POST') {
// Always select at least the "Id" field.
$selectedFields = array_values(
['id' => 'Id'] + $request->except(
['_token', 'clientCustomerId', 'entriesPerPage']
)
);
$clientCustomerId = $request->input('clientCustomerId');
$entriesPerPage = $request->input('entriesPerPage');
// Construct an API session configured from a properties file and
// the OAuth2 credentials above.
$session =
$adWordsSessionBuilder->fromFile(config('app.adsapi_php_path'))
->withOAuth2Credential($oAuth2Credential)
->withClientCustomerId($clientCustomerId)
->build();
$request->session()->put('selectedFields', $selectedFields);
$request->session()->put('entriesPerPage', $entriesPerPage);
$request->session()->put('session', $session);
} else {
$selectedFields = $request->session()->get('selectedFields');
$entriesPerPage = $request->session()->get('entriesPerPage');
$session = $request->session()->get('session');
}
$pageNo = $request->input('page') ?: 1;
$collection = self::fetchCampaigns(
$request,
$adWordsServices->get($session, CampaignService::class),
$selectedFields,
$entriesPerPage,
$pageNo
);
// Create a length aware paginator to supply campaigns for the view,
// based on the specified number of entries per page.
$campaigns = new LengthAwarePaginator(
$collection,
$request->session()->get('totalNumEntries'),
$entriesPerPage,
$pageNo,
['path' => url('get-campaigns')]
);
return view('campaigns', compact('campaigns', 'selectedFields'));
} | [
"public",
"function",
"getCampaignsAction",
"(",
"Request",
"$",
"request",
",",
"FetchAuthTokenInterface",
"$",
"oAuth2Credential",
",",
"AdWordsServices",
"$",
"adWordsServices",
",",
"AdWordsSessionBuilder",
"$",
"adWordsSessionBuilder",
")",
"{",
"if",
"(",
"$",
"request",
"->",
"method",
"(",
")",
"===",
"'POST'",
")",
"{",
"// Always select at least the \"Id\" field.",
"$",
"selectedFields",
"=",
"array_values",
"(",
"[",
"'id'",
"=>",
"'Id'",
"]",
"+",
"$",
"request",
"->",
"except",
"(",
"[",
"'_token'",
",",
"'clientCustomerId'",
",",
"'entriesPerPage'",
"]",
")",
")",
";",
"$",
"clientCustomerId",
"=",
"$",
"request",
"->",
"input",
"(",
"'clientCustomerId'",
")",
";",
"$",
"entriesPerPage",
"=",
"$",
"request",
"->",
"input",
"(",
"'entriesPerPage'",
")",
";",
"// Construct an API session configured from a properties file and",
"// the OAuth2 credentials above.",
"$",
"session",
"=",
"$",
"adWordsSessionBuilder",
"->",
"fromFile",
"(",
"config",
"(",
"'app.adsapi_php_path'",
")",
")",
"->",
"withOAuth2Credential",
"(",
"$",
"oAuth2Credential",
")",
"->",
"withClientCustomerId",
"(",
"$",
"clientCustomerId",
")",
"->",
"build",
"(",
")",
";",
"$",
"request",
"->",
"session",
"(",
")",
"->",
"put",
"(",
"'selectedFields'",
",",
"$",
"selectedFields",
")",
";",
"$",
"request",
"->",
"session",
"(",
")",
"->",
"put",
"(",
"'entriesPerPage'",
",",
"$",
"entriesPerPage",
")",
";",
"$",
"request",
"->",
"session",
"(",
")",
"->",
"put",
"(",
"'session'",
",",
"$",
"session",
")",
";",
"}",
"else",
"{",
"$",
"selectedFields",
"=",
"$",
"request",
"->",
"session",
"(",
")",
"->",
"get",
"(",
"'selectedFields'",
")",
";",
"$",
"entriesPerPage",
"=",
"$",
"request",
"->",
"session",
"(",
")",
"->",
"get",
"(",
"'entriesPerPage'",
")",
";",
"$",
"session",
"=",
"$",
"request",
"->",
"session",
"(",
")",
"->",
"get",
"(",
"'session'",
")",
";",
"}",
"$",
"pageNo",
"=",
"$",
"request",
"->",
"input",
"(",
"'page'",
")",
"?",
":",
"1",
";",
"$",
"collection",
"=",
"self",
"::",
"fetchCampaigns",
"(",
"$",
"request",
",",
"$",
"adWordsServices",
"->",
"get",
"(",
"$",
"session",
",",
"CampaignService",
"::",
"class",
")",
",",
"$",
"selectedFields",
",",
"$",
"entriesPerPage",
",",
"$",
"pageNo",
")",
";",
"// Create a length aware paginator to supply campaigns for the view,",
"// based on the specified number of entries per page.",
"$",
"campaigns",
"=",
"new",
"LengthAwarePaginator",
"(",
"$",
"collection",
",",
"$",
"request",
"->",
"session",
"(",
")",
"->",
"get",
"(",
"'totalNumEntries'",
")",
",",
"$",
"entriesPerPage",
",",
"$",
"pageNo",
",",
"[",
"'path'",
"=>",
"url",
"(",
"'get-campaigns'",
")",
"]",
")",
";",
"return",
"view",
"(",
"'campaigns'",
",",
"compact",
"(",
"'campaigns'",
",",
"'selectedFields'",
")",
")",
";",
"}"
] | Controls a POST and GET request that is submitted from the "Get All
Campaigns" form.
@param Request $request
@param FetchAuthTokenInterface $oAuth2Credential
@param AdWordsServices $adWordsServices
@param AdWordsSessionBuilder $adWordsSessionBuilder
@return View | [
"Controls",
"a",
"POST",
"and",
"GET",
"request",
"that",
"is",
"submitted",
"from",
"the",
"Get",
"All",
"Campaigns",
"form",
"."
] | d552b800ad53c400b1a50c7852e7ad184245d2ea | https://github.com/googleads/googleads-php-lib/blob/d552b800ad53c400b1a50c7852e7ad184245d2ea/examples/AdWords/LaravelSampleApp/app/Http/Controllers/AdWordsApiController.php#L67-L120 | train |
googleads/googleads-php-lib | examples/AdWords/LaravelSampleApp/app/Http/Controllers/AdWordsApiController.php | AdWordsApiController.fetchCampaigns | private function fetchCampaigns(
Request $request,
CampaignService $campaignService,
array $selectedFields,
$entriesPerPage,
$pageNo
) {
$query = (new ServiceQueryBuilder())
->select($selectedFields)
->orderByAsc('Name')
->limit(
($pageNo - 1) * $entriesPerPage,
intval($entriesPerPage)
)->build();
$totalNumEntries = 0;
$results = [];
$page = $campaignService->query("$query");
if (!empty($page->getEntries())) {
$totalNumEntries = $page->getTotalNumEntries();
$results = $page->getEntries();
}
$request->session()->put('totalNumEntries', $totalNumEntries);
return collect($results);
} | php | private function fetchCampaigns(
Request $request,
CampaignService $campaignService,
array $selectedFields,
$entriesPerPage,
$pageNo
) {
$query = (new ServiceQueryBuilder())
->select($selectedFields)
->orderByAsc('Name')
->limit(
($pageNo - 1) * $entriesPerPage,
intval($entriesPerPage)
)->build();
$totalNumEntries = 0;
$results = [];
$page = $campaignService->query("$query");
if (!empty($page->getEntries())) {
$totalNumEntries = $page->getTotalNumEntries();
$results = $page->getEntries();
}
$request->session()->put('totalNumEntries', $totalNumEntries);
return collect($results);
} | [
"private",
"function",
"fetchCampaigns",
"(",
"Request",
"$",
"request",
",",
"CampaignService",
"$",
"campaignService",
",",
"array",
"$",
"selectedFields",
",",
"$",
"entriesPerPage",
",",
"$",
"pageNo",
")",
"{",
"$",
"query",
"=",
"(",
"new",
"ServiceQueryBuilder",
"(",
")",
")",
"->",
"select",
"(",
"$",
"selectedFields",
")",
"->",
"orderByAsc",
"(",
"'Name'",
")",
"->",
"limit",
"(",
"(",
"$",
"pageNo",
"-",
"1",
")",
"*",
"$",
"entriesPerPage",
",",
"intval",
"(",
"$",
"entriesPerPage",
")",
")",
"->",
"build",
"(",
")",
";",
"$",
"totalNumEntries",
"=",
"0",
";",
"$",
"results",
"=",
"[",
"]",
";",
"$",
"page",
"=",
"$",
"campaignService",
"->",
"query",
"(",
"\"$query\"",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"page",
"->",
"getEntries",
"(",
")",
")",
")",
"{",
"$",
"totalNumEntries",
"=",
"$",
"page",
"->",
"getTotalNumEntries",
"(",
")",
";",
"$",
"results",
"=",
"$",
"page",
"->",
"getEntries",
"(",
")",
";",
"}",
"$",
"request",
"->",
"session",
"(",
")",
"->",
"put",
"(",
"'totalNumEntries'",
",",
"$",
"totalNumEntries",
")",
";",
"return",
"collect",
"(",
"$",
"results",
")",
";",
"}"
] | Fetch campaigns using the provided campaign service, selected fields, the
number of entries per page and the specified page number.
@param Request $request
@param CampaignService $campaignService
@param string[] $selectedFields
@param int $entriesPerPage
@param int $pageNo
@return Collection | [
"Fetch",
"campaigns",
"using",
"the",
"provided",
"campaign",
"service",
"selected",
"fields",
"the",
"number",
"of",
"entries",
"per",
"page",
"and",
"the",
"specified",
"page",
"number",
"."
] | d552b800ad53c400b1a50c7852e7ad184245d2ea | https://github.com/googleads/googleads-php-lib/blob/d552b800ad53c400b1a50c7852e7ad184245d2ea/examples/AdWords/LaravelSampleApp/app/Http/Controllers/AdWordsApiController.php#L133-L160 | train |
googleads/googleads-php-lib | examples/AdWords/LaravelSampleApp/app/Http/Controllers/AdWordsApiController.php | AdWordsApiController.downloadReportAction | public function downloadReportAction(
Request $request,
FetchAuthTokenInterface $oAuth2Credential,
AdWordsServices $adWordsServices,
AdWordsSessionBuilder $adWordsSessionBuilder
) {
if ($request->method() === 'POST') {
$clientCustomerId = $request->input('clientCustomerId');
$reportType = $request->input('reportType');
$reportRange = $request->input('reportRange');
$entriesPerPage = $request->input('entriesPerPage');
$selectedFields = array_values(
$request->except(
[
'_token',
'clientCustomerId',
'reportType',
'entriesPerPage',
'reportRange'
]
)
);
$selectedFields = array_merge(
self::$REPORT_TYPE_TO_DEFAULT_SELECTED_FIELDS[$reportType],
$selectedFields
);
$request->session()->put('clientCustomerId', $clientCustomerId);
$request->session()->put('reportType', $reportType);
$request->session()->put('reportRange', $reportRange);
$request->session()->put('selectedFields', $selectedFields);
$request->session()->put('entriesPerPage', $entriesPerPage);
// Construct an API session configured from a properties file and
// the OAuth2 credentials above.
$session =
$adWordsSessionBuilder->fromFile(config('app.adsapi_php_path'))
->withOAuth2Credential($oAuth2Credential)
->withClientCustomerId($clientCustomerId)
->build();
// There is no paging mechanism for reporting, so we fetch all
// results at once.
$collection = self::downloadReport(
$reportType,
$reportRange,
new ReportDownloader($session),
$selectedFields
);
$request->session()->put('collection', $collection);
} else {
$selectedFields = $request->session()->get('selectedFields');
$entriesPerPage = $request->session()->get('entriesPerPage');
$collection = $request->session()->get('collection');
}
$pageNo = $request->input('page') ?: 1;
// Create a length aware paginator to supply report results for the
// view, based on the specified number of entries per page.
$reportResults = new LengthAwarePaginator(
$collection->forPage($pageNo, $entriesPerPage),
$collection->count(),
$entriesPerPage,
$pageNo,
['path' => url('download-report')]
);
return view(
'report-results',
compact('reportResults', 'selectedFields')
);
} | php | public function downloadReportAction(
Request $request,
FetchAuthTokenInterface $oAuth2Credential,
AdWordsServices $adWordsServices,
AdWordsSessionBuilder $adWordsSessionBuilder
) {
if ($request->method() === 'POST') {
$clientCustomerId = $request->input('clientCustomerId');
$reportType = $request->input('reportType');
$reportRange = $request->input('reportRange');
$entriesPerPage = $request->input('entriesPerPage');
$selectedFields = array_values(
$request->except(
[
'_token',
'clientCustomerId',
'reportType',
'entriesPerPage',
'reportRange'
]
)
);
$selectedFields = array_merge(
self::$REPORT_TYPE_TO_DEFAULT_SELECTED_FIELDS[$reportType],
$selectedFields
);
$request->session()->put('clientCustomerId', $clientCustomerId);
$request->session()->put('reportType', $reportType);
$request->session()->put('reportRange', $reportRange);
$request->session()->put('selectedFields', $selectedFields);
$request->session()->put('entriesPerPage', $entriesPerPage);
// Construct an API session configured from a properties file and
// the OAuth2 credentials above.
$session =
$adWordsSessionBuilder->fromFile(config('app.adsapi_php_path'))
->withOAuth2Credential($oAuth2Credential)
->withClientCustomerId($clientCustomerId)
->build();
// There is no paging mechanism for reporting, so we fetch all
// results at once.
$collection = self::downloadReport(
$reportType,
$reportRange,
new ReportDownloader($session),
$selectedFields
);
$request->session()->put('collection', $collection);
} else {
$selectedFields = $request->session()->get('selectedFields');
$entriesPerPage = $request->session()->get('entriesPerPage');
$collection = $request->session()->get('collection');
}
$pageNo = $request->input('page') ?: 1;
// Create a length aware paginator to supply report results for the
// view, based on the specified number of entries per page.
$reportResults = new LengthAwarePaginator(
$collection->forPage($pageNo, $entriesPerPage),
$collection->count(),
$entriesPerPage,
$pageNo,
['path' => url('download-report')]
);
return view(
'report-results',
compact('reportResults', 'selectedFields')
);
} | [
"public",
"function",
"downloadReportAction",
"(",
"Request",
"$",
"request",
",",
"FetchAuthTokenInterface",
"$",
"oAuth2Credential",
",",
"AdWordsServices",
"$",
"adWordsServices",
",",
"AdWordsSessionBuilder",
"$",
"adWordsSessionBuilder",
")",
"{",
"if",
"(",
"$",
"request",
"->",
"method",
"(",
")",
"===",
"'POST'",
")",
"{",
"$",
"clientCustomerId",
"=",
"$",
"request",
"->",
"input",
"(",
"'clientCustomerId'",
")",
";",
"$",
"reportType",
"=",
"$",
"request",
"->",
"input",
"(",
"'reportType'",
")",
";",
"$",
"reportRange",
"=",
"$",
"request",
"->",
"input",
"(",
"'reportRange'",
")",
";",
"$",
"entriesPerPage",
"=",
"$",
"request",
"->",
"input",
"(",
"'entriesPerPage'",
")",
";",
"$",
"selectedFields",
"=",
"array_values",
"(",
"$",
"request",
"->",
"except",
"(",
"[",
"'_token'",
",",
"'clientCustomerId'",
",",
"'reportType'",
",",
"'entriesPerPage'",
",",
"'reportRange'",
"]",
")",
")",
";",
"$",
"selectedFields",
"=",
"array_merge",
"(",
"self",
"::",
"$",
"REPORT_TYPE_TO_DEFAULT_SELECTED_FIELDS",
"[",
"$",
"reportType",
"]",
",",
"$",
"selectedFields",
")",
";",
"$",
"request",
"->",
"session",
"(",
")",
"->",
"put",
"(",
"'clientCustomerId'",
",",
"$",
"clientCustomerId",
")",
";",
"$",
"request",
"->",
"session",
"(",
")",
"->",
"put",
"(",
"'reportType'",
",",
"$",
"reportType",
")",
";",
"$",
"request",
"->",
"session",
"(",
")",
"->",
"put",
"(",
"'reportRange'",
",",
"$",
"reportRange",
")",
";",
"$",
"request",
"->",
"session",
"(",
")",
"->",
"put",
"(",
"'selectedFields'",
",",
"$",
"selectedFields",
")",
";",
"$",
"request",
"->",
"session",
"(",
")",
"->",
"put",
"(",
"'entriesPerPage'",
",",
"$",
"entriesPerPage",
")",
";",
"// Construct an API session configured from a properties file and",
"// the OAuth2 credentials above.",
"$",
"session",
"=",
"$",
"adWordsSessionBuilder",
"->",
"fromFile",
"(",
"config",
"(",
"'app.adsapi_php_path'",
")",
")",
"->",
"withOAuth2Credential",
"(",
"$",
"oAuth2Credential",
")",
"->",
"withClientCustomerId",
"(",
"$",
"clientCustomerId",
")",
"->",
"build",
"(",
")",
";",
"// There is no paging mechanism for reporting, so we fetch all",
"// results at once.",
"$",
"collection",
"=",
"self",
"::",
"downloadReport",
"(",
"$",
"reportType",
",",
"$",
"reportRange",
",",
"new",
"ReportDownloader",
"(",
"$",
"session",
")",
",",
"$",
"selectedFields",
")",
";",
"$",
"request",
"->",
"session",
"(",
")",
"->",
"put",
"(",
"'collection'",
",",
"$",
"collection",
")",
";",
"}",
"else",
"{",
"$",
"selectedFields",
"=",
"$",
"request",
"->",
"session",
"(",
")",
"->",
"get",
"(",
"'selectedFields'",
")",
";",
"$",
"entriesPerPage",
"=",
"$",
"request",
"->",
"session",
"(",
")",
"->",
"get",
"(",
"'entriesPerPage'",
")",
";",
"$",
"collection",
"=",
"$",
"request",
"->",
"session",
"(",
")",
"->",
"get",
"(",
"'collection'",
")",
";",
"}",
"$",
"pageNo",
"=",
"$",
"request",
"->",
"input",
"(",
"'page'",
")",
"?",
":",
"1",
";",
"// Create a length aware paginator to supply report results for the",
"// view, based on the specified number of entries per page.",
"$",
"reportResults",
"=",
"new",
"LengthAwarePaginator",
"(",
"$",
"collection",
"->",
"forPage",
"(",
"$",
"pageNo",
",",
"$",
"entriesPerPage",
")",
",",
"$",
"collection",
"->",
"count",
"(",
")",
",",
"$",
"entriesPerPage",
",",
"$",
"pageNo",
",",
"[",
"'path'",
"=>",
"url",
"(",
"'download-report'",
")",
"]",
")",
";",
"return",
"view",
"(",
"'report-results'",
",",
"compact",
"(",
"'reportResults'",
",",
"'selectedFields'",
")",
")",
";",
"}"
] | Controls a POST and GET request that is submitted from the "Download
Report" form.
@param Request $request
@param FetchAuthTokenInterface $oAuth2Credential
@param AdWordsServices $adWordsServices
@param AdWordsSessionBuilder $adWordsSessionBuilder
@return View | [
"Controls",
"a",
"POST",
"and",
"GET",
"request",
"that",
"is",
"submitted",
"from",
"the",
"Download",
"Report",
"form",
"."
] | d552b800ad53c400b1a50c7852e7ad184245d2ea | https://github.com/googleads/googleads-php-lib/blob/d552b800ad53c400b1a50c7852e7ad184245d2ea/examples/AdWords/LaravelSampleApp/app/Http/Controllers/AdWordsApiController.php#L172-L245 | train |
googleads/googleads-php-lib | examples/AdWords/LaravelSampleApp/app/Http/Controllers/AdWordsApiController.php | AdWordsApiController.downloadReport | private function downloadReport(
$reportType,
$reportRange,
ReportDownloader $reportDownloader,
array $selectedFields
) {
$query = (new ReportQueryBuilder())
->select($selectedFields)
->from($reportType)
->duringDateRange($reportRange)->build();
// For brevity, this sample app always excludes zero-impression rows.
$reportSettingsOverride = (new ReportSettingsBuilder())
->includeZeroImpressions(false)
->build();
$reportDownloadResult = $reportDownloader->downloadReportWithAwql(
"$query",
DownloadFormat::XML,
$reportSettingsOverride
);
$json = json_encode(
simplexml_load_string($reportDownloadResult->getAsString())
);
$resultTable = json_decode($json, true)['table'];
if (array_key_exists('row', $resultTable)) {
// When there is only one row, PHP decodes it by automatically
// removing the containing array. We need to add it back, so the
// "view" can render this data properly.
$row = $resultTable['row'];
$row = count($row) > 1 ? $row : [$row];
return collect($row);
}
// No results returned for this query.
return collect([]);
} | php | private function downloadReport(
$reportType,
$reportRange,
ReportDownloader $reportDownloader,
array $selectedFields
) {
$query = (new ReportQueryBuilder())
->select($selectedFields)
->from($reportType)
->duringDateRange($reportRange)->build();
// For brevity, this sample app always excludes zero-impression rows.
$reportSettingsOverride = (new ReportSettingsBuilder())
->includeZeroImpressions(false)
->build();
$reportDownloadResult = $reportDownloader->downloadReportWithAwql(
"$query",
DownloadFormat::XML,
$reportSettingsOverride
);
$json = json_encode(
simplexml_load_string($reportDownloadResult->getAsString())
);
$resultTable = json_decode($json, true)['table'];
if (array_key_exists('row', $resultTable)) {
// When there is only one row, PHP decodes it by automatically
// removing the containing array. We need to add it back, so the
// "view" can render this data properly.
$row = $resultTable['row'];
$row = count($row) > 1 ? $row : [$row];
return collect($row);
}
// No results returned for this query.
return collect([]);
} | [
"private",
"function",
"downloadReport",
"(",
"$",
"reportType",
",",
"$",
"reportRange",
",",
"ReportDownloader",
"$",
"reportDownloader",
",",
"array",
"$",
"selectedFields",
")",
"{",
"$",
"query",
"=",
"(",
"new",
"ReportQueryBuilder",
"(",
")",
")",
"->",
"select",
"(",
"$",
"selectedFields",
")",
"->",
"from",
"(",
"$",
"reportType",
")",
"->",
"duringDateRange",
"(",
"$",
"reportRange",
")",
"->",
"build",
"(",
")",
";",
"// For brevity, this sample app always excludes zero-impression rows.",
"$",
"reportSettingsOverride",
"=",
"(",
"new",
"ReportSettingsBuilder",
"(",
")",
")",
"->",
"includeZeroImpressions",
"(",
"false",
")",
"->",
"build",
"(",
")",
";",
"$",
"reportDownloadResult",
"=",
"$",
"reportDownloader",
"->",
"downloadReportWithAwql",
"(",
"\"$query\"",
",",
"DownloadFormat",
"::",
"XML",
",",
"$",
"reportSettingsOverride",
")",
";",
"$",
"json",
"=",
"json_encode",
"(",
"simplexml_load_string",
"(",
"$",
"reportDownloadResult",
"->",
"getAsString",
"(",
")",
")",
")",
";",
"$",
"resultTable",
"=",
"json_decode",
"(",
"$",
"json",
",",
"true",
")",
"[",
"'table'",
"]",
";",
"if",
"(",
"array_key_exists",
"(",
"'row'",
",",
"$",
"resultTable",
")",
")",
"{",
"// When there is only one row, PHP decodes it by automatically",
"// removing the containing array. We need to add it back, so the",
"// \"view\" can render this data properly.",
"$",
"row",
"=",
"$",
"resultTable",
"[",
"'row'",
"]",
";",
"$",
"row",
"=",
"count",
"(",
"$",
"row",
")",
">",
"1",
"?",
"$",
"row",
":",
"[",
"$",
"row",
"]",
";",
"return",
"collect",
"(",
"$",
"row",
")",
";",
"}",
"// No results returned for this query.",
"return",
"collect",
"(",
"[",
"]",
")",
";",
"}"
] | Download a report of the specified report type and date range, selected
fields, and the number of entries per page.
@param string $reportType
@param string $reportRange
@param ReportDownloader $reportDownloader
@param string[] $selectedFields
@return Collection | [
"Download",
"a",
"report",
"of",
"the",
"specified",
"report",
"type",
"and",
"date",
"range",
"selected",
"fields",
"and",
"the",
"number",
"of",
"entries",
"per",
"page",
"."
] | d552b800ad53c400b1a50c7852e7ad184245d2ea | https://github.com/googleads/googleads-php-lib/blob/d552b800ad53c400b1a50c7852e7ad184245d2ea/examples/AdWords/LaravelSampleApp/app/Http/Controllers/AdWordsApiController.php#L257-L294 | train |
googleads/googleads-php-lib | src/Google/AdsApi/AdWords/BatchJobs/v201809/BatchJobsDelegate.php | BatchJobsDelegate.padContent | private function padContent($content)
{
// The request is part of a set of incremental uploads, so pad to the
// required content length. This is not necessary if all operations for the
// job are being uploaded in a single request.
$numBytes = mb_strlen($content, '8bit');
$remainder = $numBytes % self::$REQUIRED_CONTENT_BYTES_INCREMENT;
if ($remainder > 0) {
$targetLength = $numBytes +
(self::$REQUIRED_CONTENT_BYTES_INCREMENT - $remainder);
$content = str_pad($content, $targetLength, ' ');
}
return $content;
} | php | private function padContent($content)
{
// The request is part of a set of incremental uploads, so pad to the
// required content length. This is not necessary if all operations for the
// job are being uploaded in a single request.
$numBytes = mb_strlen($content, '8bit');
$remainder = $numBytes % self::$REQUIRED_CONTENT_BYTES_INCREMENT;
if ($remainder > 0) {
$targetLength = $numBytes +
(self::$REQUIRED_CONTENT_BYTES_INCREMENT - $remainder);
$content = str_pad($content, $targetLength, ' ');
}
return $content;
} | [
"private",
"function",
"padContent",
"(",
"$",
"content",
")",
"{",
"// The request is part of a set of incremental uploads, so pad to the",
"// required content length. This is not necessary if all operations for the",
"// job are being uploaded in a single request.",
"$",
"numBytes",
"=",
"mb_strlen",
"(",
"$",
"content",
",",
"'8bit'",
")",
";",
"$",
"remainder",
"=",
"$",
"numBytes",
"%",
"self",
"::",
"$",
"REQUIRED_CONTENT_BYTES_INCREMENT",
";",
"if",
"(",
"$",
"remainder",
">",
"0",
")",
"{",
"$",
"targetLength",
"=",
"$",
"numBytes",
"+",
"(",
"self",
"::",
"$",
"REQUIRED_CONTENT_BYTES_INCREMENT",
"-",
"$",
"remainder",
")",
";",
"$",
"content",
"=",
"str_pad",
"(",
"$",
"content",
",",
"$",
"targetLength",
",",
"' '",
")",
";",
"}",
"return",
"$",
"content",
";",
"}"
] | Pads the request content to conform to the requirements of
Google Cloud Storage.
@param string $content the request content
@return string the post-processed content | [
"Pads",
"the",
"request",
"content",
"to",
"conform",
"to",
"the",
"requirements",
"of",
"Google",
"Cloud",
"Storage",
"."
] | d552b800ad53c400b1a50c7852e7ad184245d2ea | https://github.com/googleads/googleads-php-lib/blob/d552b800ad53c400b1a50c7852e7ad184245d2ea/src/Google/AdsApi/AdWords/BatchJobs/v201809/BatchJobsDelegate.php#L328-L342 | train |
googleads/googleads-php-lib | src/Google/AdsApi/Common/AdsLoggerFactory.php | AdsLoggerFactory.createLogger | public function createLogger($channel, $stream = null, $level = null)
{
$stream = $stream === null ? fopen('php://stderr', 'w') : $stream;
$level = $level === null ? Logger::INFO : $level;
$handler = new StreamHandler($stream, $level);
$handler->getFormatter()
->ignoreEmptyContextAndExtra();
$handler->getFormatter()
->allowInlineLineBreaks();
return new Logger($channel, [$handler]);
} | php | public function createLogger($channel, $stream = null, $level = null)
{
$stream = $stream === null ? fopen('php://stderr', 'w') : $stream;
$level = $level === null ? Logger::INFO : $level;
$handler = new StreamHandler($stream, $level);
$handler->getFormatter()
->ignoreEmptyContextAndExtra();
$handler->getFormatter()
->allowInlineLineBreaks();
return new Logger($channel, [$handler]);
} | [
"public",
"function",
"createLogger",
"(",
"$",
"channel",
",",
"$",
"stream",
"=",
"null",
",",
"$",
"level",
"=",
"null",
")",
"{",
"$",
"stream",
"=",
"$",
"stream",
"===",
"null",
"?",
"fopen",
"(",
"'php://stderr'",
",",
"'w'",
")",
":",
"$",
"stream",
";",
"$",
"level",
"=",
"$",
"level",
"===",
"null",
"?",
"Logger",
"::",
"INFO",
":",
"$",
"level",
";",
"$",
"handler",
"=",
"new",
"StreamHandler",
"(",
"$",
"stream",
",",
"$",
"level",
")",
";",
"$",
"handler",
"->",
"getFormatter",
"(",
")",
"->",
"ignoreEmptyContextAndExtra",
"(",
")",
";",
"$",
"handler",
"->",
"getFormatter",
"(",
")",
"->",
"allowInlineLineBreaks",
"(",
")",
";",
"return",
"new",
"Logger",
"(",
"$",
"channel",
",",
"[",
"$",
"handler",
"]",
")",
";",
"}"
] | Creates a Monolog logger with a stream handler configured for this library.
@param string $channel a description of what is being logged
@param string|resource|null $stream the stream the logger will log to; if
`null`, will log to STDERR
@param string|int|null $level the log level; can be a PSR3 log level
string, or a Monolog log level int
@return LoggerInterface
@see Logger | [
"Creates",
"a",
"Monolog",
"logger",
"with",
"a",
"stream",
"handler",
"configured",
"for",
"this",
"library",
"."
] | d552b800ad53c400b1a50c7852e7ad184245d2ea | https://github.com/googleads/googleads-php-lib/blob/d552b800ad53c400b1a50c7852e7ad184245d2ea/src/Google/AdsApi/Common/AdsLoggerFactory.php#L41-L52 | train |
googleads/googleads-php-lib | src/Google/AdsApi/AdManager/Util/v201805/StatementBuilder.php | StatementBuilder.withBindVariableValue | public function withBindVariableValue($key, $value)
{
$this->valueMap[$key] = Pql::createValue($value);
return $this;
} | php | public function withBindVariableValue($key, $value)
{
$this->valueMap[$key] = Pql::createValue($value);
return $this;
} | [
"public",
"function",
"withBindVariableValue",
"(",
"$",
"key",
",",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"valueMap",
"[",
"$",
"key",
"]",
"=",
"Pql",
"::",
"createValue",
"(",
"$",
"value",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Adds a bind variable value to the statement.
@param string $key the value key
@param mixed $value the value either as a primitive, which will be
converted to a PQL `Value` object, or a PQL `Value` object
@return StatementBuilder this builder | [
"Adds",
"a",
"bind",
"variable",
"value",
"to",
"the",
"statement",
"."
] | d552b800ad53c400b1a50c7852e7ad184245d2ea | https://github.com/googleads/googleads-php-lib/blob/d552b800ad53c400b1a50c7852e7ad184245d2ea/src/Google/AdsApi/AdManager/Util/v201805/StatementBuilder.php#L86-L91 | train |
googleads/googleads-php-lib | src/Google/AdsApi/AdManager/Util/v201805/StatementBuilder.php | StatementBuilder.toStatement | public function toStatement()
{
$statement = new Statement();
$statement->setQuery($this->buildQuery());
$statement->setValues(
MapEntries::fromAssociativeArray(
$this->getBindVariableMap(),
'Google\AdsApi\AdManager\v201805\String_ValueMapEntry'
)
);
return $statement;
} | php | public function toStatement()
{
$statement = new Statement();
$statement->setQuery($this->buildQuery());
$statement->setValues(
MapEntries::fromAssociativeArray(
$this->getBindVariableMap(),
'Google\AdsApi\AdManager\v201805\String_ValueMapEntry'
)
);
return $statement;
} | [
"public",
"function",
"toStatement",
"(",
")",
"{",
"$",
"statement",
"=",
"new",
"Statement",
"(",
")",
";",
"$",
"statement",
"->",
"setQuery",
"(",
"$",
"this",
"->",
"buildQuery",
"(",
")",
")",
";",
"$",
"statement",
"->",
"setValues",
"(",
"MapEntries",
"::",
"fromAssociativeArray",
"(",
"$",
"this",
"->",
"getBindVariableMap",
"(",
")",
",",
"'Google\\AdsApi\\AdManager\\v201805\\String_ValueMapEntry'",
")",
")",
";",
"return",
"$",
"statement",
";",
"}"
] | Gets the statement representing the state of this statement builder.
@return Statement | [
"Gets",
"the",
"statement",
"representing",
"the",
"state",
"of",
"this",
"statement",
"builder",
"."
] | d552b800ad53c400b1a50c7852e7ad184245d2ea | https://github.com/googleads/googleads-php-lib/blob/d552b800ad53c400b1a50c7852e7ad184245d2ea/src/Google/AdsApi/AdManager/Util/v201805/StatementBuilder.php#L98-L110 | train |
googleads/googleads-php-lib | src/Google/AdsApi/AdManager/Util/v201805/StatementBuilder.php | StatementBuilder.removeKeyword | private static function removeKeyword($clause, $keyword)
{
$keyword .= ' ';
if (stristr(substr($clause, 0, strlen($keyword)), $keyword) !== false) {
return substr($clause, strlen($keyword));
}
return $clause;
} | php | private static function removeKeyword($clause, $keyword)
{
$keyword .= ' ';
if (stristr(substr($clause, 0, strlen($keyword)), $keyword) !== false) {
return substr($clause, strlen($keyword));
}
return $clause;
} | [
"private",
"static",
"function",
"removeKeyword",
"(",
"$",
"clause",
",",
"$",
"keyword",
")",
"{",
"$",
"keyword",
".=",
"' '",
";",
"if",
"(",
"stristr",
"(",
"substr",
"(",
"$",
"clause",
",",
"0",
",",
"strlen",
"(",
"$",
"keyword",
")",
")",
",",
"$",
"keyword",
")",
"!==",
"false",
")",
"{",
"return",
"substr",
"(",
"$",
"clause",
",",
"strlen",
"(",
"$",
"keyword",
")",
")",
";",
"}",
"return",
"$",
"clause",
";",
"}"
] | Removes the specified keyword from the clause, if present. Will remove
`keyword + ' '`.
@param string $clause
@param string $keyword
@return string a new string with the `keyword + ' '` removed | [
"Removes",
"the",
"specified",
"keyword",
"from",
"the",
"clause",
"if",
"present",
".",
"Will",
"remove",
"keyword",
"+",
"."
] | d552b800ad53c400b1a50c7852e7ad184245d2ea | https://github.com/googleads/googleads-php-lib/blob/d552b800ad53c400b1a50c7852e7ad184245d2ea/src/Google/AdsApi/AdManager/Util/v201805/StatementBuilder.php#L120-L128 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.