PHP Class WordPress\ORM\Query

Author: Brandon Wamboldt ([email protected])
Show file Open project: brandonwamboldt/wp-orm

Protected Properties

Property Type Description
$limit integer
$model string
$offset integer
$order string
$primary_key string
$search_fields array
$search_term string | null
$sort_by string
$where array

Public Methods

Method Description
__construct ( string $model )
__toString ( ) : string Return the string representation of the query.
compose_query ( boolean $only_count = false ) : string Compose the actual SQL query from all of our filters and options.
find ( boolean $only_count = false ) : array Compose & execute our query.
limit ( integer $limit ) : self Set the maximum number of results to return at once.
offset ( integer $offset ) : self Set the offset to use when calculating results.
order ( string $order ) : self Set the order we should sort by.
search ( string $search_term ) : self Get models where any of the designated fields match the given value.
set_primary_key ( string $primary_key ) Set the primary key column.
set_searchable_fields ( array $fields ) Set the fields to include in the search.
sort_by ( string $sort_by ) : self Set the column we should sort by.
total_count ( ) : integer Runs the same query as find, but with no limit and don't retrieve the results, just the total items found.
where ( string $column, string $value ) : self Add a = clause to the search query.
where_all ( array $where ) : self Add an AND statement to the where clause (e.g. (var1 = foo AND var2 = bar AND var3 = baz)).
where_any ( array $where ) : self Add an OR statement to the where clause (e.g. (var = foo OR var = bar OR var = baz)).
where_gt ( string $column, string $value ) : self Add a > clause to the search query.
where_gte ( string $column, string $value ) : self Add a >= clause to the search query.
where_in ( string $column, array $in ) : self Add an IN clause to the search query.
where_like ( string $column, string $value ) : self Add a LIKE clause to the search query.
where_lt ( string $column, string $value ) : self Add a < clause to the search query.
where_lte ( string $column, string $value ) : self Add a <= clause to the search query.
where_not ( string $column, string $value ) : self Add a != clause to the search query.
where_not_in ( string $column, array $not_in ) : self Add a NOT IN clause to the search query.
where_not_like ( string $column, string $value ) : self Add a NOT LIKE clause to the search query.

Method Details

__construct() public method

public __construct ( string $model )
$model string

__toString() public method

Return the string representation of the query.
public __toString ( ) : string
return string

compose_query() public method

Compose the actual SQL query from all of our filters and options.
public compose_query ( boolean $only_count = false ) : string
$only_count boolean Whether to only return the row count
return string

find() public method

Compose & execute our query.
public find ( boolean $only_count = false ) : array
$only_count boolean Whether to only return the row count
return array

limit() public method

Set the maximum number of results to return at once.
public limit ( integer $limit ) : self
$limit integer
return self

offset() public method

Set the offset to use when calculating results.
public offset ( integer $offset ) : self
$offset integer
return self

order() public method

Set the order we should sort by.
public order ( string $order ) : self
$order string
return self

set_primary_key() public method

Set the primary key column.
public set_primary_key ( string $primary_key )
$primary_key string

set_searchable_fields() public method

Set the fields to include in the search.
public set_searchable_fields ( array $fields )
$fields array

sort_by() public method

Set the column we should sort by.
public sort_by ( string $sort_by ) : self
$sort_by string
return self

total_count() public method

Runs the same query as find, but with no limit and don't retrieve the results, just the total items found.
public total_count ( ) : integer
return integer

where() public method

Add a = clause to the search query.
public where ( string $column, string $value ) : self
$column string
$value string
return self

where_all() public method

Add an AND statement to the where clause (e.g. (var1 = foo AND var2 = bar AND var3 = baz)).
public where_all ( array $where ) : self
$where array
return self

where_any() public method

Add an OR statement to the where clause (e.g. (var = foo OR var = bar OR var = baz)).
public where_any ( array $where ) : self
$where array
return self

where_gt() public method

Add a > clause to the search query.
public where_gt ( string $column, string $value ) : self
$column string
$value string
return self

where_gte() public method

Add a >= clause to the search query.
public where_gte ( string $column, string $value ) : self
$column string
$value string
return self

where_in() public method

Add an IN clause to the search query.
public where_in ( string $column, array $in ) : self
$column string
$in array
return self

where_like() public method

Add a LIKE clause to the search query.
public where_like ( string $column, string $value ) : self
$column string
$value string
return self

where_lt() public method

Add a < clause to the search query.
public where_lt ( string $column, string $value ) : self
$column string
$value string
return self

where_lte() public method

Add a <= clause to the search query.
public where_lte ( string $column, string $value ) : self
$column string
$value string
return self

where_not() public method

Add a != clause to the search query.
public where_not ( string $column, string $value ) : self
$column string
$value string
return self

where_not_in() public method

Add a NOT IN clause to the search query.
public where_not_in ( string $column, array $not_in ) : self
$column string
$not_in array
return self

where_not_like() public method

Add a NOT LIKE clause to the search query.
public where_not_like ( string $column, string $value ) : self
$column string
$value string
return self

Property Details

$limit protected property

protected int $limit
return integer

$model protected property

protected string $model
return string

$offset protected property

protected int $offset
return integer

$order protected property

protected string $order
return string

$primary_key protected property

protected string $primary_key
return string

$search_fields protected property

protected array $search_fields
return array

$search_term protected property

protected string|null $search_term
return string | null

$sort_by protected property

protected string $sort_by
return string

$where protected property

protected array $where
return array