PHP Class 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();
Mostra file Open project: googleads/googleads-php-lib Class Usage Examples

Public Methods

Method Description
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.

Private Methods

Method Description
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.

Method Details

From() public method

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"
return StatementBuilder a reference to this object

GetBindVariableMap() public method

Returns the key to value map.
public GetBindVariableMap ( )

GetOffset() public method

Gets the current offset.
public GetOffset ( ) : integer
return integer the current offset

IncreaseOffsetBy() public method

Increases the offset by the {@code amount}.
public IncreaseOffsetBy ( integer $amount ) : StatementBuilder
$amount integer the amount to increase the offset
return StatementBuilder a reference to this object

Limit() public method

Sets the statement LIMIT clause in the form of

"LIMIT <count>"

e.g. 1000.
public Limit ( integer $count ) : StatementBuilder
$count integer the statement limit
return StatementBuilder a reference to this object

Offset() public method

Sets the statement OFFSET clause in the form of

"OFFSET <count>"

e.g. 200.
public Offset ( integer $count ) : StatementBuilder
$count integer the statement offset
return StatementBuilder a reference to this object

OrderBy() public method

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"
return StatementBuilder a reference to this object

RemoveLimitAndOffset() public method

Removes the limit and offset from the query.
public RemoveLimitAndOffset ( ) : StatementBuilder
return StatementBuilder a reference to this object

Select() public method

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"
return StatementBuilder a reference to this object

ToStatement() public method

Gets the {@link Statement} representing the state of this statement builder.
public ToStatement ( ) : Statement
return Statement the {@link Statement}

Where() public method

..}"

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"
return StatementBuilder a reference to this object

WithBindVariableValue() public method

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
return StatementBuilder a reference to this object

__construct() public method

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