Source for file AdiantiRecordService.php
Documentation is available at AdiantiRecordService.php
namespace
Adianti \
Service ;
* @author Pablo Dall'Oglio
* @copyright Copyright (c) 2006 Adianti Solutions Ltd. (http://www.adianti.com.br)
* @license http://www.adianti.com.br/framework-license
* Find a Active Record and returns it
* @return The Active Record itself as array
* @param $param HTTP parameter
public function load ( $param )
$database =
static :: DATABASE ;
$activeRecord =
static :: ACTIVE_RECORD ;
$object =
new $activeRecord ( $param [ 'id' ] , FALSE ) ;
$attributes =
defined ( 'static::ATTRIBUTES' ) ?
static :: ATTRIBUTES :
null ;
return $object -> toArray ( $attributes ) ;
* Delete an Active Record object from the database
* @param [$id] HTTP parameter
public function delete ( $param )
$database =
static :: DATABASE ;
$activeRecord =
static :: ACTIVE_RECORD ;
$object =
new $activeRecord ( $param [ 'id' ] ) ;
* Store the objects into the database
* @param $param HTTP parameter
public function store ( $param )
$database =
static :: DATABASE ;
$activeRecord =
static :: ACTIVE_RECORD ;
$object =
new $activeRecord ;
$pk =
$object -> getPrimaryKey ( ) ;
$param [ 'data' ] [ $pk ] =
$param [ 'data' ] [ 'id' ] ??
NULL ;
$object -> fromArray ( (array)
$param [ 'data' ] ) ;
return $object -> toArray ( ) ;
* List the Active Records by the filter
* @return The Active Record list as array
* @param $param HTTP parameter
$database =
static :: DATABASE ;
$activeRecord =
static :: ACTIVE_RECORD ;
if ( isset
( $param [ 'offset' ] ))
$criteria -> setProperty ( 'offset' , $param [ 'offset' ] ) ;
if ( isset
( $param [ 'limit' ] ))
$criteria -> setProperty ( 'limit' , $param [ 'limit' ] ) ;
if ( isset
( $param [ 'order' ] ))
$criteria -> setProperty ( 'order' , $param [ 'order' ] ) ;
if ( isset
( $param [ 'direction' ] ))
$criteria -> setProperty ( 'direction' , $param [ 'direction' ] ) ;
if ( isset
( $param [ 'filters' ] ))
foreach ( $param [ 'filters' ] as $filter )
$criteria -> add ( new TFilter ( $filter [ 0 ] , $filter [ 1 ] , $filter [ 2 ] )) ;
$objects =
$repository -> load ( $criteria , FALSE ) ;
$attributes =
defined ( 'static::ATTRIBUTES' ) ?
static :: ATTRIBUTES :
null ;
foreach ( $objects as $object )
$return [ ] =
$object -> toArray ( $attributes ) ;
* Delete the Active Records by the filter
* @return The result of operation
* @param $param HTTP parameter
$database =
static :: DATABASE ;
$activeRecord =
static :: ACTIVE_RECORD ;
if ( isset
( $param [ 'filters' ] ))
foreach ( $param [ 'filters' ] as $filter )
$criteria -> add ( new TFilter ( $filter [ 0 ] , $filter [ 1 ] , $filter [ 2 ] )) ;
$return =
$repository -> delete ( $criteria ) ;
* Find the count Records by the filter
* @return The Active Record list as array
* @param $param HTTP parameter
$database =
static :: DATABASE ;
$activeRecord =
static :: ACTIVE_RECORD ;
if ( isset
( $param [ 'offset' ] ))
$criteria -> setProperty ( 'offset' , $param [ 'offset' ] ) ;
if ( isset
( $param [ 'limit' ] ))
$criteria -> setProperty ( 'limit' , $param [ 'limit' ] ) ;
if ( isset
( $param [ 'order' ] ))
$criteria -> setProperty ( 'order' , $param [ 'order' ] ) ;
if ( isset
( $param [ 'direction' ] ))
$criteria -> setProperty ( 'direction' , $param [ 'direction' ] ) ;
if ( isset
( $param [ 'filters' ] ))
foreach ( $param [ 'filters' ] as $filter )
$criteria -> add ( new TFilter ( $filter [ 0 ] , $filter [ 1 ] , $filter [ 2 ] )) ;
$count =
$repository -> count ( $criteria , FALSE ) ;
* Handle HTTP Request and dispatch
* @param $param HTTP POST and php input vars
public function handle ( $param )
if ( ! empty ( $param [ 'id' ] ))
return self :: load ( $param ) ;
return self :: loadAll ( $param ) ;
return self :: store ( $param ) ;
return self :: store ( $param ) ;
if ( ! empty ( $param [ 'id' ] ))
return self :: delete ( $param ) ;
return self :: deleteAll ( $param ) ;