PluginProbe
ShiftController Employee Shift Scheduling / 4.9.77
ShiftController Employee Shift Scheduling v4.9.77
4.9.97 4.9.96 4.9.95 4.9.74 4.9.75 4.9.76 4.9.77 4.9.78 4.9.84 4.9.85 4.9.87 4.9.91 4.9.92 trunk 2.1.0 2.1.1 2.1.2 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 3.2.4 All 38 releases
shiftcontroller / hc3 / _wordpress / users / query.php

query.php in ShiftController Employee Shift Scheduling 4.9.77, at hc3/_wordpress/users/query.php

92 lines 1.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php if (! defined('ABSPATH')) exit; // Exit if accessed directly
2 class HC3_Users_Query implements HC3_Users_IQuery
3 {
4 protected $crud;
5 protected $self;
6
7 public function __construct( HC3_Hooks $hooks )
8 {
9 $this->crud = new HC3_Crud_Wordpress_User();
10 $this->self = $hooks->wrap( $this );
11 }
12
13 public function findByEmail( $email )
14 {
15 $return = NULL;
16
17 $args = array();
18 $args[] = array('email', '=', $email);
19 $args[] = array('limit', 1);
20
21 if( $array = $this->self->read( $args ) ){
22 $return = array_shift( $array );
23 }
24 return $return;
25 }
26
27 public function findById( $id )
28 {
29 $return = NULL;
30
31 if( ! $id ){
32 $array = array();
33 $array['display_name'] = '-Anonymous-';
34 $array['username'] = 'anonymous';
35 $array['email'] = NULL;
36
37 $return = $this->_arrayToModel( $array );
38 return $return;
39 }
40
41 $args = array();
42 $args[] = array('id', '=', $id);
43 $args[] = array('limit', 1);
44
45 if( $array = $this->self->read( $args ) ){
46 $return = array_shift( $array );
47 }
48 return $return;
49 }
50
51 public function findManyById( array $ids )
52 {
53 $return = array();
54 $args = array();
55 $args[] = array('id', 'IN', $ids);
56
57 $return = $this->self->read( $args );
58 return $return;
59 }
60
61 public function findAll()
62 {
63 $args = array();
64 return $this->self->read( $args );
65 }
66
67 public function read( array $args = array() )
68 {
69 $args[] = array( 'sort', 'display_name', 'asc' );
70
71 $return = $this->crud->read( $args );
72 $ids = array_keys($return);
73
74 foreach( $ids as $id ){
75 $return[$id] = $this->_arrayToModel( $return[$id] );
76 }
77
78 return $return;
79 }
80
81 protected function _arrayToModel( array $array )
82 {
83 $id = array_key_exists('id', $array) ? $array['id'] : NULL;
84
85 $displayName = $array['display_name'];
86 $username = $array['username'];
87 $email = $array['email'];
88
89 $return = new HC3_Users_Model( $id, $username, $email, $displayName );
90 return $return;
91 }
92 }