pclib  2.9.5
Lightweight PHP framework
Public Member Functions | Data Fields | Protected Member Functions | Protected Attributes
Selection Class Reference

Selection of records in database. More...

Inheritance diagram for Selection:
BaseObject Relation

Public Member Functions

 rewind ()
 Iterator.rewind() implementation.
 
 current ()
 Iterator.current() implementation.
 
 key ()
 Iterator.key() implementation.
 
 next ()
 Iterator.next() implementation.
 
 valid ()
 Iterator.valid() implementation.
 
 __call ($name, $args)
 PHP magic method. More...
 
 first ()
 Return first record in the selection. More...
 
 isEmpty ()
 Is Selection empty? More...
 
 count ()
 Return number of rows in the Selection.
 
 sum ($s)
 Return summary of field $s. More...
 
 avg ($s)
 Return AVG of field $s. More...
 
 find ($id)
 Find record by primary key. More...
 
 update (array $values)
 Update records in selection with $values.
 
 delete ()
 Delete selection.
 
 getClone ()
 Clone selection.
 
 limit ($limit, $offset=0)
 Set selection limit. More...
 
 select ($columns)
 Execute selection and return array of rows. More...
 
 selectPair ($columns)
 See Db->selectPair().
 
 from ($s)
 Set source table $s. More...
 
 where ($s)
 Set where condition. More...
 
 whereJoin ($relName, $s)
 Set where condition. More...
 
 order ($s)
 Set order by clausule. More...
 
 group ($s)
 Set group by clausule. More...
 
 having ($s)
 Set having clausule. More...
 
 close ()
 Closes the cursor, enabling the query to be executed again. More...
 
 clear ()
 Clear selection query and data. More...
 
 getSql ()
 Build sql query for current selection. More...
 
 toArray ($deep=false)
 Return current selection as array. More...
 
 __toString ()
 Return string representation of selection for debugging purposes.
 
- Public Member Functions inherited from BaseObject
 loadDefaults ($className=null)
 Load default parameters of class $className into object instance.
 
 setProperties (array $defaults)
 Set public properties of object from the array. More...
 
 toArray ()
 Convert object to array. More...
 

Data Fields

 $db
 var Db
 
- Data Fields inherited from BaseObject
 $serviceLocator
 var function() Return service object when requested with service().
 

Protected Member Functions

 newModel ($data)
 Create model instance, fill its values with $data and return it. More...
 
 execute ()
 Execute query to the database and set $this->result. More...
 
- Protected Member Functions inherited from BaseObject
 service ($service, $default=null)
 Try acquire $service and load it into property $this->$service. More...
 

Protected Attributes

 $query = array()
 Array of sql query clausules.
 
 $result = null
 Result of underlying sql query.
 
 $data = array()
 Data of the current row.
 

Additional Inherited Members

- Static Public Member Functions inherited from BaseObject
static defaults ()
 Set or retireve default parameters of the object. More...
 

Detailed Description

Selection of records in database.

It represents any selection on database table and will return Model instances as records. It does not load records from the database before they are really requested.

Features:

Member Function Documentation

◆ __call()

__call (   $name,
  $args 
)

PHP magic method.

Redirect unknown method call to underlying model class.

Reimplemented from BaseObject.

◆ avg()

avg (   $s)

Return AVG of field $s.

@TODO: verify if $s is valid fieldname.

◆ clear()

clear ( )

Clear selection query and data.

Returns
Selection $this

Reimplemented in Relation.

◆ close()

close ( )

Closes the cursor, enabling the query to be executed again.

Returns
Selection $this

◆ execute()

execute ( )
protected

Execute query to the database and set $this->result.

Returns
$result

◆ find()

find (   $id)

Find record by primary key.

Returns
Model $model

◆ first()

first ( )

Return first record in the selection.

Returns
Model $model

◆ from()

from (   $s)

Set source table $s.

Fluent interface.

Returns
Selection $this

◆ getSql()

getSql ( )

Build sql query for current selection.

Returns
string $sql

◆ group()

group (   $s)

Set group by clausule.

Fluent interface.

Returns
Selection $this

◆ having()

having (   $s)

Set having clausule.

Fluent interface.

Returns
Selection $this

◆ isEmpty()

isEmpty ( )

Is Selection empty?

Returns
bool $isEmpty

◆ limit()

limit (   $limit,
  $offset = 0 
)

Set selection limit.

Fluent interface.

Returns
Selection $this

◆ newModel()

newModel (   $data)
protected

Create model instance, fill its values with $data and return it.

Returns
Model $model

◆ order()

order (   $s)

Set order by clausule.

Fluent interface.

Returns
Selection $this

◆ select()

select (   $columns)

Execute selection and return array of rows.

Parameters
array | string$columnsList of columns to select
Returns
array $rows

◆ sum()

sum (   $s)

Return summary of field $s.

@TODO: verify if $s is valid fieldname.

◆ toArray()

toArray (   $deep = false)

Return current selection as array.

Parameters
bool$deepReturn arrays instead of models
Returns
array $rows Array of models.

◆ where()

where (   $s)

Set where condition.

Fluent interface.

Returns
Selection $this

◆ whereJoin()

whereJoin (   $relName,
  $s 
)

Set where condition.

Fluent interface.

Parameters
$relNameName of relation
$sCondition used on relation
Returns
Selection $this

The documentation for this class was generated from the following file: