17
17
class agWebservicesHelper
20
* Retrieve staff from database based on filters.
21
* Possible array indices:
26
* - order: person|staff|organization
27
* @param array $filters
29
public static function getStaff(array $filters)
20
public static function getStaff()
31
$whereIsAvailable = 'srs.is_available = ?';
32
$wherePerson = 'p.id = ?';
33
$whereOrg = 'org.id = ?';
35
23
$staff_dql = agDoctrineQuery::create()
36
->select('st.*, p.*, sr.id, srs.*, srt.*, org.*')
38
->innerJoin('st.agPerson p')
39
->leftJoin('st.agStaffResource sr')
40
->leftJoin('sr.agStaffResourceStatus srs')
41
->leftJoin('sr.agOrganization org')
42
->leftJoin('sr.agStaffResourceType srt');
44
if (isset($filters['is_available'])) {
45
$staff_dql->andWhere($whereIsAvailable, $filters['is_available']);
47
if (isset($filters['person'])) {
48
$staff_dql->andWhere($wherePerson, $filters['person']);
50
if (isset($filters['org'])) {
51
$staff_dql->andWhere($whereOrg, $filters['org']);
53
$staff_dql->limit(isset($filters['limit'])?$filters['limit']:30);
55
if (isset($filters['order'])) {
56
switch($filters['order']) {
57
case 'person': $staff_dql->orderBy('p.id'); break;
58
case 'staff' : $staff_dql->orderBy('st.id'); break;
59
case 'org' : $staff_dql->orderBy('org.id'); break;
24
->select('st.*, p.*, srt.*, pn.*, pdb.*')
26
->innerJoin('st.agPerson p')
27
->innerJoin('p.agPersonName pn')
28
->innerJoin('p.agPersonDateOfBirth pdb')
29
->leftJoin('st.agStaffResourceType srt');
30
$v = $staff_dql->execute()->toArray();
62
31
return self::asStaffArray($staff_dql->execute());
66
* Prototype for persons - should be edited to 'public' when is done
69
private static function getPerson($personId)
72
$person_dql = agDoctrineQuery::create()
73
->select('st.*, p.*, e.*, pmpn.id, pn.*, epc.id, pc.*, eec.id, ec.*')
74
->addSelect('pml.id, pmp.id, prof.id, peth.id, pnat.id, prel.id, pmar.id, psex.id, presid.id')
75
->addSelect('st.*, p.*, l.*, nat.*, rel.*, mar.*, sex.*, resid.*, nat.*, eth.*, pdb.*')
77
->innerJoin('p.agPersonMjAgPersonName pmpn')
78
->innerJoin('pmpn.agPersonName pn')
80
->innerJoin('p.agEntity e')
81
->innerJoin('e.agEntityPhoneContact epc')
82
->innerJoin('epc.agPhoneContact pc')
83
->innerJoin('e.agEntityEmailContact eec')
84
->innerJoin('eec.agEmailContact ec')
86
->innerJoin('p.agPersonMjAgLanguage pml')
87
->innerJoin('pml.agLanguage l')
88
->innerJoin('p.agPersonMjAgProfession pmp')
89
->innerJoin('pmp.agProfession prof')
90
->innerJoin('p.agPersonEthnicity peth')
91
->innerJoin('peth.agEthnicity eth')
92
->innerJoin('p.agPersonMjAgNationality pnat')
93
->innerJoin('pnat.agNationality nat')
94
->innerJoin('p.agPersonMjAgReligion prel')
95
->innerJoin('prel.agReligion rel')
96
->innerJoin('p.agPersonMaritalStatus pmar')
97
->innerJoin('pmar.agMaritalStatus mar')
98
->innerJoin('p.agPersonSex psex')
99
->innerJoin('psex.agSex sex')
100
->innerJoin('p.agPersonResidentialStatus presid')
101
->innerJoin('presid.agResidentialStatus resid')
102
->innerJoin('p.agPersonDateOfBirth pdb')
104
->where('p.id = ?', $personId);
106
return self::asPersonArray($person_dql->execute());
110
34
public static function getEvents()
113
$whereStr = 'EXISTS (SELECT subEs.id
37
$whereStr = 'EXISTS (SELECT subEs.id
114
38
FROM agEventStatus subEs
115
39
WHERE subEs.time_stamp <= CURRENT_TIMESTAMP
116
40
AND subEs.event_id = a.id
117
41
HAVING MAX(subEs.time_stamp) = st.time_stamp)';
119
43
$ag_events = agDoctrineQuery::create()
121
->addSelect('s.scenario')
122
->addSelect('est.event_status_type, est.description')
124
->innerJoin('a.agEventScenario es')
125
->innerJoin('es.agScenario s')
126
->innerJoin('a.agEventStatus st')
127
->innerJoin('st.agEventStatusType est')
128
->andWhere($whereStr)
129
->execute(array(), Doctrine_Core::HYDRATE_SCALAR);
45
->addSelect('s.scenario')
46
->addSelect('est.event_status_type, est.description')
48
->innerJoin('a.agEventScenario es')
49
->innerJoin('es.agScenario s')
50
->innerJoin('a.agEventStatus st')
51
->innerJoin('st.agEventStatusType est')
53
->execute(array(), Doctrine_Core::HYDRATE_SCALAR);
132
56
return $ag_events;
145
69
public static function getOrganizations()
147
72
$organization_dql = agDoctrineQuery::create()
148
->select('ent.*, org.*, bran.*, enemail.*, email.*, enphone.*, phone.*, enaddr.*, addr.*')
149
->from('agOrganization org')
150
->leftJoin('org.agBranch bran')
151
->leftJoin('org.agEntity ent')
152
->leftJoin('ent.agEntityEmailContact enemail')
153
->leftJoin('enemail.agEmailContact email')
154
->leftJoin('ent.agEntityPhoneContact enphone')
155
->leftJoin('enphone.agPhoneContact phone')
156
->leftJoin('ent.agEntityAddressContact enaddr');
73
->select('ent.*, org.*, bra.*, email.*, phone.*')
74
->from('agOrganization org')
75
->innerJoin('org.agEntity ent')
76
->leftJoin('org.agBranch bra')
77
->leftJoin('ent.agPhoneContact phone')
78
->leftJoin('ent.agEmailContact email')
79
->leftJoin('ent.agEntityAddressContact eaddr');
158
80
return self::asOrganizationArray($organization_dql->execute());
163
85
$results = $result->toArray();
164
86
$response = array();
165
foreach ($results as $result) {
169
$srOrganization = array();
170
foreach ($result['agStaffResource'] as $key => $resource) {
172
$srType['resource_type_'.$key] = $resource['agStaffResourceType'];
174
$srStatus['resource_status_'.$key] = $resource['agStaffResourceStatus'];
176
$srOrganization['organization_'.$key] = $resource['agOrganization'];
179
// at last, we create an associative array to facilitate the creation of json and xml documents
180
$response[$result['id']] = array(
181
'id' => $result['id'],
182
'person_id' => $result['agPerson']['id'],
183
'person' => $result['agPerson'],
184
'id' => $result['id'],
185
'created_at' => $result['created_at'],
186
'updated_at' => $result['updated_at'],
187
'resources' => array('resource_type' => $srType, 'resource_status' => $srStatus),
188
'organizations' => $srOrganization
87
foreach ($results as $k => $array) {
88
$staffResourceTypes = array();
89
$staffResourceTypesAbbr = array();
90
$descriptions = array();
93
// foreach: adds the values in the same order for the type of staff resource,
94
// its abbreviation and description. Here those three share the same keys
95
foreach ($array['agStaffResourceType'] as $key => $staffResourceType) {
96
$staffResourceTypes[$key] = $staffResourceType['staff_resource_type'];
97
$staffResourceTypesAbbr[$key] = $staffResourceType['staff_resource_type_abbr'];
98
$descriptions[$key] = $staffResourceType['description'];
101
// foreach: some as above, but only for names, in order to get all staff's names
102
// in a single array of names
103
foreach ($array['agPerson']['agPersonName'] as $key => $name) {
104
$names[$key] = $name['person_name'];
107
// at least, we create an associative array to facilitate the creation
108
// of the documents in json and xml
109
$response[$k] = array(
110
'id' => $array['id'],
111
'person_id' => $array['person_id'],
112
'created_at' => $array['created_at'],
113
'updated_at' => $array['updated_at'],
114
'person_names' => $names,
115
'staff_resource_type' => $staffResourceTypes,
116
'staff_resource_type_abbr' => $staffResourceTypesAbbr,
117
'staff_resource_type_description' => $descriptions,
118
'date_of_birth' => $array['agPerson']['agPersonDateOfBirth']['date_of_birth'],
191
121
return $response;
205
135
'description' => $array['description'],
206
136
'created_at' => $array['created_at'],
207
137
'updated_at' => $array['updated_at'],
208
// avoid empty values or get subvalues of the result array
209
'branch' => (!empty($array['agBranch'])) ? $array['agBranch']['branch'] : null,
210
'phone' => (!empty($array['agEntity']['agEntityPhoneContact']['agPhoneContact'])) ? $array['agEntity']['agEntityPhoneContact']['agPhoneContact']['phone_contact'] : null,
211
'email' => (!empty($array['agEntity']['agEntityEmailContact']['agEmailContact'])) ? $array['agEntity']['agEntityEmailContact']['agEmailContact']['email_contact'] : null,
212
'address' => (!empty($array['agEntity']['agEntityAddressContact']['agEmailContact'])) ? $array['agEntity']['agEntityEmailContact']['agEmailContact']['email_contact'] : null
138
// avoid empty values or get subvalues of the result array
139
'branch' => (!isset($array['agBranch'])) ? $array['agBranch']['branch'] : null,
140
// avoid empty values or get subvalues of the result array
141
'phone' => (!isset($array['agEntity']['agPhoneContact'])) ? $array['agEntity']['agPhoneContact'] : null,
142
// avoid empty values or get subvalues of the result array
143
'email' => (!isset($array['agEntity']['agEmailContact'])) ? $array['agEntity']['agEmailContact'] : null
216
146
return $response;