| 1 |
<?php if (! defined('ABSPATH')) exit; // Exit if accessed directly |
| 2 |
interface SH4_Reminders_QueryLog_ |
| 3 |
{ |
| 4 |
public function findAll(); |
| 5 |
} |
| 6 |
|
| 7 |
class SH4_Reminders_QueryLog implements SH4_Reminders_QueryLog_ |
| 8 |
{ |
| 9 |
protected $_storage = array(); |
| 10 |
public $self, $crud; |
| 11 |
|
| 12 |
public function __construct( |
| 13 |
HC3_Hooks $hooks, |
| 14 |
HC3_CrudFactory $crudFactory |
| 15 |
) |
| 16 |
{ |
| 17 |
$crudFactory = $hooks->wrap( $crudFactory ); |
| 18 |
|
| 19 |
$this->crud = $hooks->wrap( $crudFactory->make('reminderlog') ); |
| 20 |
$this->self = $hooks->wrap( $this ); |
| 21 |
} |
| 22 |
|
| 23 |
public function findAll() |
| 24 |
{ |
| 25 |
$args = array(); |
| 26 |
$ret = $this->self->read( $args ); |
| 27 |
return $ret; |
| 28 |
} |
| 29 |
|
| 30 |
public function read( array $args = array() ) |
| 31 |
{ |
| 32 |
$args[] = array( 'sort', 'date', 'asc' ); |
| 33 |
|
| 34 |
$ret = $this->crud->read( $args ); |
| 35 |
$ids = array_keys( $ret ); |
| 36 |
|
| 37 |
foreach( $ids as $id ){ |
| 38 |
$ret[$id] = $this->_arrayToModel( $ret[$id] ); |
| 39 |
// $this->_storage[$id] = $return[$id]; |
| 40 |
} |
| 41 |
// uasort( $return, array($this, '_sort') ); |
| 42 |
|
| 43 |
return $ret; |
| 44 |
} |
| 45 |
|
| 46 |
protected function _arrayToModel( array $array ) |
| 47 |
{ |
| 48 |
static $sortOrder = 1; |
| 49 |
|
| 50 |
$id = array_key_exists('id', $array) ? $array['id'] : NULL; |
| 51 |
$range = array_key_exists('range', $array) ? $array['range'] : NULL; |
| 52 |
$date = array_key_exists('date', $array) ? $array['date'] : NULL; |
| 53 |
$employee_id = array_key_exists('employee_id', $array) ? $array['employee_id'] : NULL; |
| 54 |
$sent_on = array_key_exists('sent_on', $array) ? $array['sent_on'] : NULL; |
| 55 |
|
| 56 |
$ret = new SH4_Reminders_ModelLog; |
| 57 |
|
| 58 |
$ret->id = $id; |
| 59 |
$ret->range = $range; |
| 60 |
$ret->date = $date; |
| 61 |
$ret->employee_id = $employee_id; |
| 62 |
$ret->sent_on = $sent_on; |
| 63 |
|
| 64 |
return $ret; |
| 65 |
} |
| 66 |
} |