PHP Класс StatementBuilder, googleads-php-lib

Typical usage is:

$statementBuilder = new StatementBuilder()
    ->Where("lastModifiedDateTime > :yesterday AND type = :type")
    ->OrderBy("name DESC")
    ->Limit(200)
    ->Offset(20)
    ->WithBindVariableValue("yesterday",
        date(DateTimeUtils::$DFP_DATE_TIME_STRING_FORMAT,
            strtotime('-1 day'))
    ->WithBindVariableValue("type", "Type")

$statement = $statementBuilder->ToStatement();
...
$statementBuilder->IncreaseOffsetBy(20);
$statement = $statementBuilder->ToStatement();
Показать файл Открыть проект Примеры использования класса

Открытые методы

Метод Описание
From ( string $table ) : StatementBuilder Sets the statement FROM clause in the form of "table".
GetBindVariableMap ( ) Returns the key to value map.
GetOffset ( ) : integer Gets the current offset.
IncreaseOffsetBy ( integer $amount ) : StatementBuilder Increases the offset by the {@code amount}.
Limit ( integer $count ) : StatementBuilder Sets the statement LIMIT clause in the form of

"LIMIT <count>"

e.g. 1000.
Offset ( integer $count ) : StatementBuilder Sets the statement OFFSET clause in the form of

"OFFSET <count>"

e.g. 200.
OrderBy ( string $orderBy ) : StatementBuilder Sets the statement ORDER BY clause in the form of

"ORDER BY <property> [ASC | DESC]"

e.g. "type ASC, lastModifiedDateTime DESC". The "ORDER BY " keyword will be ignored.
RemoveLimitAndOffset ( ) : StatementBuilder Removes the limit and offset from the query.
Select ( string $columns ) : StatementBuilder Sets the statement SELECT clause in the form of "a,b" or "*".
ToStatement ( ) : Statement Gets the {@link Statement} representing the state of this statement builder.
Where ( string $conditions ) : StatementBuilder Sets the statement WHERE clause in the form of

"WHERE <condition> {[AND | OR] <condition> .
WithBindVariableValue ( string $key, mixed $value ) : StatementBuilder Adds a value to the statement in the form of a {@code Value}.
__construct ( ) Constructs a new instance of this statement builder.

Приватные методы

Метод Описание
buildQuery ( ) : string Builds the query from the clauses.
removeKeyword ( string $clause, string $keyword ) : string Removes the {@code keyword} from the {@code clause} if present. Will remove {@code keyword + " "}.
validateQuery ( ) Checks that the query is valid.

Описание методов

From() публичный Метод

Only necessary for statements being sent to the {@code PublisherQueryLanguageService}. The "FROM " keyword will be ignored.
public From ( string $table ) : StatementBuilder
$table string the statement from clause without "FROM"
Результат StatementBuilder a reference to this object

GetBindVariableMap() публичный Метод

Returns the key to value map.
public GetBindVariableMap ( )

GetOffset() публичный Метод

Gets the current offset.
public GetOffset ( ) : integer
Результат integer the current offset

IncreaseOffsetBy() публичный Метод

Increases the offset by the {@code amount}.
public IncreaseOffsetBy ( integer $amount ) : StatementBuilder
$amount integer the amount to increase the offset
Результат StatementBuilder a reference to this object

Limit() публичный Метод

Sets the statement LIMIT clause in the form of

"LIMIT <count>"

e.g. 1000.
public Limit ( integer $count ) : StatementBuilder
$count integer the statement limit
Результат StatementBuilder a reference to this object

Offset() публичный Метод

Sets the statement OFFSET clause in the form of

"OFFSET <count>"

e.g. 200.
public Offset ( integer $count ) : StatementBuilder
$count integer the statement offset
Результат StatementBuilder a reference to this object

OrderBy() публичный Метод

Sets the statement ORDER BY clause in the form of

"ORDER BY <property> [ASC | DESC]"

e.g. "type ASC, lastModifiedDateTime DESC". The "ORDER BY " keyword will be ignored.
public OrderBy ( string $orderBy ) : StatementBuilder
$orderBy string the statement order by without "ORDER BY"
Результат StatementBuilder a reference to this object

RemoveLimitAndOffset() публичный Метод

Removes the limit and offset from the query.
public RemoveLimitAndOffset ( ) : StatementBuilder
Результат StatementBuilder a reference to this object

Select() публичный Метод

Only necessary for statements being sent to the {@code PublisherQueryLanguageService}. The "SELECT " keyword will be ignored.
public Select ( string $columns ) : StatementBuilder
$columns string the statement select clause without "SELECT"
Результат StatementBuilder a reference to this object

ToStatement() публичный Метод

Gets the {@link Statement} representing the state of this statement builder.
public ToStatement ( ) : Statement
Результат Statement the {@link Statement}

Where() публичный Метод

..}"

e.g. "a = b OR b = c". The "WHERE " keyword will be ignored.
public Where ( string $conditions ) : StatementBuilder
$conditions string the statement query without "WHERE"
Результат StatementBuilder a reference to this object

WithBindVariableValue() публичный Метод

Adds a value to the statement in the form of a {@code Value}.
public WithBindVariableValue ( string $key, mixed $value ) : StatementBuilder
$key string the value key
$value mixed the value either as a primitive, which will be converted to a PQL Value object, or a PQL Value object
Результат StatementBuilder a reference to this object

__construct() публичный Метод

Constructs a new instance of this statement builder.
public __construct ( )