Autodoc
  • Namespace
  • Class
  • Tree

Namespaces

  • BlueTihi
    • Context
  • Brickrouge
    • Element
      • Nodes
    • Renderer
    • Widget
  • ICanBoogie
    • ActiveRecord
    • AutoConfig
    • CLDR
    • Composer
    • Core
    • Event
    • Exception
    • HTTP
      • Dispatcher
      • Request
    • I18n
      • Translator
    • Mailer
    • Modules
      • Taxonomy
        • Support
      • Thumbnailer
        • Versions
    • Object
    • Operation
      • Dispatcher
    • Prototype
    • Routes
    • Routing
      • Dispatcher
    • Session
  • Icybee
    • ActiveRecord
      • Model
    • ConfigOperation
    • Document
    • EditBlock
    • Element
      • ActionbarContextual
      • ActionbarSearch
      • ActionbarToolbar
    • FormBlock
    • Installer
    • ManageBlock
    • Modules
      • Articles
      • Cache
        • Collection
        • ManageBlock
      • Comments
        • ManageBlock
      • Contents
        • ManageBlock
      • Dashboard
      • Editor
        • Collection
      • Files
        • File
        • ManageBlock
      • Forms
        • Form
        • ManageBlock
      • I18n
      • Images
        • ManageBlock
      • Members
      • Modules
        • ManageBlock
      • Nodes
        • ManageBlock
        • Module
      • Pages
        • BreadcrumbElement
        • LanguagesElement
        • ManageBlock
        • NavigationBranchElement
        • NavigationElement
        • Page
        • PageController
      • Registry
      • Search
      • Seo
      • Sites
        • ManageBlock
      • Taxonomy
        • Terms
          • ManageBlock
        • Vocabulary
          • ManageBlock
      • Users
        • ManageBlock
        • NonceLogin
        • Roles
      • Views
        • ActiveRecordProvider
        • Collection
        • View
    • Operation
      • ActiveRecord
      • Constructor
      • Module
      • Widget
    • Rendering
  • None
  • Patron
  • PHP

Classes

  • ActiveRecordCache
  • CollectDependenciesEvent
  • Connection
  • Connections
  • DateTimePropertySupport
  • Helpers
  • Hooks
  • Model
  • Models
  • Query
  • RunTimeActiveRecordCache
  • Statement
  • Table

Interfaces

  • ActiveRecordCacheInterface

Traits

  • CreatedAtProperty
  • DateTimeProperty
  • UpdatedAtProperty

Exceptions

  • ActiveRecordException
  • ConnectionAlreadyEstablished
  • ConnectionNotDefined
  • ConnectionNotEstablished
  • ModelAlreadyInstantiated
  • ModelNotDefined
  • RecordNotFound
  • ScopeNotDefined
  • StatementInvalid

Functions

  • get_model

Class Query

The class offers many features to compose model queries. Most query related methods of the ICanBoogie\ActiveRecord\Model class create a ICanBoogie\ActiveRecord\Query object that is returned for further specification, such as filters or limits.

ICanBoogie\Object implements ICanBoogie\ToArrayRecursive uses ICanBoogie\ToArrayRecursiveTrait, ICanBoogie\PrototypeTrait
Extended by ICanBoogie\ActiveRecord\Query implements IteratorAggregate
Namespace: ICanBoogie\ActiveRecord
See: http://dev.mysql.com/doc/refman/5.6/en/select.html
Located at vendor/icanboogie/activerecord/lib/query.php

Methods summary

public
# __construct( ICanBoogie\ActiveRecord\Model $model )

Constructor.

Constructor.

Parameters

$model
ICanBoogie\ActiveRecord\Model
$model The model to query.
public mixed
# __get( string $property )

Adds support for model's scopes.

Adds support for model's scopes.

Parameters

$property
string
$property

Returns

mixed
The value of the inaccessible property.

Throws

PropertyNotReadable
when the property has a protected or private scope and no suitable callback could be found to retrieve its value.
PropertyNotDefined
when the property is undefined and there is no suitable callback to retrieve its values.

Overrides

ICanBoogie\Object::__get
public mixed
# __call( string $method, array $arguments )

Override the method to handle magic 'filter_by_' methods.

Override the method to handle magic 'filter_by_' methods.

Parameters

$method
string
$method
$arguments
array
$arguments

Returns

mixed

Overrides

ICanBoogie\Object::__call
public string
# __toString( )

Converts the query into a string.

Converts the query into a string.

Returns

string
protected array[]string
# get_model_scope( )

Returns the available scopes for a model class.

Returns the available scopes for a model class.

The method uses reflexion to find the scopes, the result is cached.

Returns

array[]string
public ICanBoogie\ActiveRecord\Query
# select( string $expression )

Defines the SELECT clause.

Defines the SELECT clause.

Parameters

$expression
string
$expression The expression of the SELECT clause. e.g. 'nid, title'.

Returns

ICanBoogie\ActiveRecord\Query
public ICanBoogie\ActiveRecord\Query
# joins( string $expression )

Adds a JOIN clause.

Adds a JOIN clause.

Parameters

$expression
string
$expression The expression can be a full JOIN clause or a reference to a model defined as ":<model_id>" e.g. ":nodes".

Returns

ICanBoogie\ActiveRecord\Query
public ICanBoogie\ActiveRecord\Query
# where( mixed $conditions, mixed $conditions_args = null )

Add conditions to the SQL statement.

Add conditions to the SQL statement.

Conditions can either be specified as string or array.

1. Pure string conditions

If you'de like to add conditions to your statement, you could just specify them in there, just like $model->where('order_count = 2');. This will find all the entries, where the order_count field's value is 2.

2. Array conditions

Now what if that number could vary, say as an argument from somewhere, or perhaps from the user’s level status somewhere? The find then becomes something like:

$model->where('order_count = ?', 2);

or

$model->where([ 'order_count' => 2 ]);

Or if you want to specify two conditions, you can do it like:

$model->where('order_count = ? AND locked = ?', 2, false);

or

$model->where([ 'order_count' => 2, 'locked' => false ]);

Or if you want to specify subset conditions:

$model->where([ 'order_id' => [ 123, 456, 789 ] ]);

This will return the orders with the order_id 123, 456 or 789.

3. Modifiers

When using the "identifier" => "value" notation, you can switch the comparison method by prefixing the identifier with a bang "!"

$model->where([ '!order_id' => [ 123, 456, 789 ]]);

This will return the orders with the order_id different than 123, 456 and 789.

$model->where([ '!order_count' => 2 ];

This will return the orders with the order_count different than 2.

Parameters

$conditions
mixed
$conditions
$conditions_args
mixed
$conditions_args

Returns

ICanBoogie\ActiveRecord\Query
public ICanBoogie\ActiveRecord\Query
# order( string $order_or_field_name, mixed $field_values = null )

Defines the ORDER clause.

Defines the ORDER clause.

Parameters

$order_or_field_name
string
$order The order for the ORDER clause e.g. 'weight, date DESC'.
$field_values

Returns

ICanBoogie\ActiveRecord\Query
public ICanBoogie\ActiveRecord\Query
# group( mixed $group )

Defines the GROUP clause.

Defines the GROUP clause.

Parameters

$group
mixed
$group

Returns

ICanBoogie\ActiveRecord\Query
public ICanBoogie\ActiveRecord\Query
# having( mixed $conditions, array|null $conditions_args = null )

Defines the HAVING clause.

Defines the HAVING clause.

Parameters

$conditions
mixed
$conditions
$conditions_args
array|null
$conditions_args

Returns

ICanBoogie\ActiveRecord\Query
public ICanBoogie\ActiveRecord\Query
# offset( mixed $offset )

Defines the offset of the LIMIT clause.

Defines the offset of the LIMIT clause.

Parameters

$offset
mixed
$offset

Returns

ICanBoogie\ActiveRecord\Query
public ICanBoogie\ActiveRecord\Query
# limit( integer $limit )

Apply the limit and/or offset to the SQL fired.

Apply the limit and/or offset to the SQL fired.

You can use the limit to specify the number of records to be retrieved, ad use the offset to specify the number of records to skip before starting to return records:
$model->limit(10);

Will return a maximum of 10 clients and because ti specifies no offset it will return the first 10 in the table:
$model->limit(5, 10);

Will return a maximum of 10 clients beginning with the 5th.

Parameters

$limit
integer
$limit

Returns

ICanBoogie\ActiveRecord\Query
public ICanBoogie\ActiveRecord\Query
# mode( mixed $mode )

Set the fetch mode for the query.

Set the fetch mode for the query.

Parameters

$mode
mixed
$mode

Returns

ICanBoogie\ActiveRecord\Query

See

http://www.php.net/manual/en/pdostatement.setfetchmode.php
protected string
# build( )

Builds the query except for the SELECT and FROM parts.

Builds the query except for the SELECT and FROM parts.

Returns

string
The query as a string.
protected
# render_order( mixed $order )
protected
# render_offset_and_limit( mixed $offset, mixed $limit )
protected ICanBoogie\Database\Statement
# prepare( )

Prepares the query.

Prepares the query.

We use the connection's prepare() method because the statement has already been resolved during the __toString() method and we don't want for the statement to be parsed twice.

Returns

ICanBoogie\Database\Statement
public ICanBoogie\Database\Statement
# query( )

Prepares and executes the query.

Prepares and executes the query.

Returns

ICanBoogie\Database\Statement
protected ICanBoogie\Database\Statement
# get_prepared( )

Returns a prepared query.

Returns a prepared query.

Returns

ICanBoogie\Database\Statement
public array
# all( )

Executes the query and returns an array of records.

Executes the query and returns an array of records.

Returns

array
protected array
# get_all( )

Getter for the $all magic property.

Getter for the $all magic property.

Returns

array
public mixed
# one( )

Returns the first result of the query and close the cursor.

Returns the first result of the query and close the cursor.

Returns

mixed
The return value of this function on success depends on the fetch mode. In all cases, FALSE is returned on failure.
protected mixed
# get_one( )

Getter for the $one magic property.

Getter for the $one magic property.

Returns

mixed

See

ICanBoogie\ActiveRecord\Query::one()
protected array
# get_pairs( )

Execute que query and returns an array of key/value pairs, where the key is the value of the first column and the value of the key the value of the second column.

Execute que query and returns an array of key/value pairs, where the key is the value of the first column and the value of the key the value of the second column.

Returns

array
protected string
# get_rc( )

Returns the value of the first column of the first row.

Returns the value of the first column of the first row.

Returns

string
public boolean|array
# exists( mixed $key = null )

Checks the existence of records in the model.

Checks the existence of records in the model.

$model->exists; $model->where('name = "max"')->exists; $model->exists(1); $model->exists(1, 2); $model->exists([ 1, 2 ]);

Parameters

$key
mixed
$key

Returns

boolean|array
protected boolean|array
# get_exists( )

Getter for the $exists magic property.

Getter for the $exists magic property.

Returns

boolean|array

See

ICanBoogie\ActiveRecord\Query::exists()
public integer|array
# count( mixed $column = null )

Implements the 'COUNT' computation.

Implements the 'COUNT' computation.

Returns

integer|array
protected integer
# get_count( )

Getter for the $count magic property.

Getter for the $count magic property.

Returns

integer
public integer
# average( string $column )

Implements the 'AVG' computation.

Implements the 'AVG' computation.

Parameters

$column
string
$column

Returns

integer
public integer
# minimum( string $column )

Implements the 'MIN' computation.

Implements the 'MIN' computation.

Parameters

$column
string
$column

Returns

integer
public integer
# maximum( string $column )

Implements the 'MAX' computation.

Implements the 'MAX' computation.

Parameters

$column
string
$column

Returns

integer
public integer
# sum( string $column )

Implements the 'SUM' computation.

Implements the 'SUM' computation.

Parameters

$column
string
$column

Returns

integer
public mixed
# delete( )

Deletes the records matching the conditions and limits of the query.

Deletes the records matching the conditions and limits of the query.

Returns

mixed
The result of the operation.
public
# getIterator( )

Returns an iterator for the query.

Returns an iterator for the query.

Implementation of

IteratorAggregate::getIterator()

Methods inherited from ICanBoogie\Object

from(), resolve_facade_properties(), resolve_private_properties(), to_array(), to_json()

Methods inherited from ICanBoogie\ToArrayRecursive

to_array_recursive()

Methods used from ICanBoogie\ToArrayRecursiveTrait

to_array_recursive()

Methods used from ICanBoogie\PrototypeTrait

__set(), __sleep(), __wakeup(), get_prototype(), has_method(), has_property(), last_chance_get(), last_chance_set()

Magic methods summary

public ICanBoogie\ActiveRecord\Query
# and( mixed $conditions_args = null) Alias to {@link where( )

}.

}.

Parameters

$conditions_args

Returns

ICanBoogie\ActiveRecord\Query

Constants summary

string LIMIT_MAX '18446744073709551615'
#

Properties summary

protected mixed $select
#
protected mixed $join
#
protected array $conditions
#
protected array $conditions_args
#
protected mixed $group
#
protected mixed $order
#
protected mixed $having
#
protected array $having_args
#
protected mixed $offset
#
protected mixed $limit
#
protected mixed $mode
#
protected ICanBoogie\ActiveRecord\Model $model
#

The target model of the query.

The target model of the query.

protected static array[]string $scopes_by_classes
#

Caches available scopes by model class.

Caches available scopes by model class.

Magic properties

public read-only array $all
#

An array with all the records matching the query.

An array with all the records matching the query.

public read-only mixed $one
#

The first record matching the query.

The first record matching the query.

public read-only array $pairs
#

An array of key/value pairs.

An array of key/value pairs.

public read-only array $rc
#

The first column of the first row matching the query.

The first column of the first row matching the query.

public read-only integer $count
#

The number of records matching the query.

The number of records matching the query.

public read-only boolean|array $exists
#

true if a record matching the query exists, false otherwise. If there is multiple records, the property is an array of booleans.

true if a record matching the query exists, false otherwise. If there is multiple records, the property is an array of booleans.

public read-only ICanBoogie\ActiveRecord\Model $model
#

The target model of the query.

The target model of the query.

Magic properties inherited from ICanBoogie\Object

$prototype

Autodoc API documentation generated by ApiGen 2.8.0