10
10
* http://www.gnu.org/licenses/lgpl-2.1.html
12
12
* @author Fabio Albuquerque <fabiocbalbuquerque@gmail.com>
13
* @author Clayton Kramer <clayton.kramer@mail.cuny.edu>
14
15
* Copyright of the Sahana Software Foundation, sahanafoundation.org
17
17
class agWebservicesHelper
20
public static function getStaff()
23
$staff_dql = agDoctrineQuery::create()
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();
31
return self::asStaffArray($staff_dql->execute());
34
public static function getOrganizations()
37
$organization_dql = agDoctrineQuery::create()
38
->select('ent.*, org.*, bra.*, email.*, phone.*')
39
->from('agOrganization org')
40
->innerJoin('org.agEntity ent')
41
->leftJoin('org.agBranch bra')
42
->leftJoin('ent.agPhoneContact phone')
43
->leftJoin('ent.agEmailContact email')
44
->leftJoin('ent.agEntityAddressContact eaddr');
45
return self::asOrganizationArray($organization_dql->execute());
48
private static function asStaffArray($result) {
49
$results = $result->toArray();
51
foreach($results as $k => $array) {
52
$staffResourceTypes = array();
53
$staffResourceTypesAbbr = array();
54
$descriptions = array();
57
// foreach: adds the values in the same order for the type of staff resource,
58
// its abbreviation and description. Here those three share the same keys
59
foreach ($array['agStaffResourceType'] as $key => $staffResourceType) {
60
$staffResourceTypes[$key] = $staffResourceType['staff_resource_type'];
61
$staffResourceTypesAbbr[$key] = $staffResourceType['staff_resource_type_abbr'];
62
$descriptions[$key] = $staffResourceType['description'];
65
// foreach: some as above, but only for names, in order to get all staff's names
66
// in a single array of names
67
foreach($array['agPerson']['agPersonName'] as $key => $name) {
68
$names[$key] = $name['person_name'];
71
// at least, we create an associative array to facilitate the creation
72
// of the documents in json and xml
73
$response[$k] = array(
75
'person_id' => $array['person_id'],
76
'created_at' => $array['created_at'],
77
'updated_at' => $array['updated_at'],
78
'person_names' => $names,
79
'staff_resource_type' => $staffResourceTypes,
80
'staff_resource_type_abbr' => $staffResourceTypesAbbr,
81
'staff_resource_type_description' => $descriptions,
82
'date_of_birth' => $array['agPerson']['agPersonDateOfBirth']['date_of_birth'],
88
private static function asOrganizationArray($result) {
89
$results = $result->toArray();
91
foreach($results as $k => $array) {
92
// an associative array to facilitate the creation
93
// of the documents in json and xml
94
$response[$k] = array(
96
'entity_id' => $array['entity_id'],
97
'organization' => $array['organization'],
98
'description' => $array['description'],
99
'created_at' => $array['created_at'],
100
'updated_at' => $array['updated_at'],
101
// avoid empty values or get subvalues of the result array
102
'branch' => (!isset($array['agBranch']))?$array['agBranch']['branch']:null,
103
// avoid empty values or get subvalues of the result array
104
'phone' => (!isset($array['agEntity']['agPhoneContact']))?$array['agEntity']['agPhoneContact']:null,
105
// avoid empty values or get subvalues of the result array
106
'email' => (!isset($array['agEntity']['agEmailContact']))?$array['agEntity']['agEmailContact']:null
20
public static function getStaff()
23
$staff_dql = agDoctrineQuery::create()
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();
31
return self::asStaffArray($staff_dql->execute());
34
public static function getEventFacilities($eventId)
36
// Let's use Chad's magic method for getting event facilities
37
$facilityData = agEvent::getEventFacilities($eventId);
39
return self::asFacilityArray($facilityData);
42
public static function getOrganizations()
45
$organization_dql = agDoctrineQuery::create()
46
->select('ent.*, org.*, bra.*, email.*, phone.*')
47
->from('agOrganization org')
48
->innerJoin('org.agEntity ent')
49
->leftJoin('org.agBranch bra')
50
->leftJoin('ent.agPhoneContact phone')
51
->leftJoin('ent.agEmailContact email')
52
->leftJoin('ent.agEntityAddressContact eaddr');
53
return self::asOrganizationArray($organization_dql->execute());
56
private static function asStaffArray($result)
58
$results = $result->toArray();
60
foreach ($results as $k => $array) {
61
$staffResourceTypes = array();
62
$staffResourceTypesAbbr = array();
63
$descriptions = array();
66
// foreach: adds the values in the same order for the type of staff resource,
67
// its abbreviation and description. Here those three share the same keys
68
foreach ($array['agStaffResourceType'] as $key => $staffResourceType) {
69
$staffResourceTypes[$key] = $staffResourceType['staff_resource_type'];
70
$staffResourceTypesAbbr[$key] = $staffResourceType['staff_resource_type_abbr'];
71
$descriptions[$key] = $staffResourceType['description'];
74
// foreach: some as above, but only for names, in order to get all staff's names
75
// in a single array of names
76
foreach ($array['agPerson']['agPersonName'] as $key => $name) {
77
$names[$key] = $name['person_name'];
80
// at least, we create an associative array to facilitate the creation
81
// of the documents in json and xml
82
$response[$k] = array(
84
'person_id' => $array['person_id'],
85
'created_at' => $array['created_at'],
86
'updated_at' => $array['updated_at'],
87
'person_names' => $names,
88
'staff_resource_type' => $staffResourceTypes,
89
'staff_resource_type_abbr' => $staffResourceTypesAbbr,
90
'staff_resource_type_description' => $descriptions,
91
'date_of_birth' => $array['agPerson']['agPersonDateOfBirth']['date_of_birth'],
97
private static function asOrganizationArray($result)
99
$results = $result->toArray();
101
foreach ($results as $k => $array) {
102
// an associative array to facilitate the creation
103
// of the documents in json and xml
104
$response[$k] = array(
105
'id' => $array['id'],
106
'entity_id' => $array['entity_id'],
107
'organization' => $array['organization'],
108
'description' => $array['description'],
109
'created_at' => $array['created_at'],
110
'updated_at' => $array['updated_at'],
111
// avoid empty values or get subvalues of the result array
112
'branch' => (!isset($array['agBranch'])) ? $array['agBranch']['branch'] : null,
113
// avoid empty values or get subvalues of the result array
114
'phone' => (!isset($array['agEntity']['agPhoneContact'])) ? $array['agEntity']['agPhoneContact'] : null,
115
// avoid empty values or get subvalues of the result array
116
'email' => (!isset($array['agEntity']['agEmailContact'])) ? $array['agEntity']['agEmailContact'] : null
122
private static function asFacilityArray($results)
126
foreach ($results as $k => $array) {
127
// an associative array to facilitate the creation
128
// of the documents in json and xml
131
// Alter the street lines to match export spec
132
if (isset($array['line 1'])) {
133
$array['street_1'] = $array['line 1'];
134
unset($array['line 1']);
137
if (isset($array['line 2'])) {
138
$array['street_2'] = $array['line 2'];
139
unset($array['line 2']);
142
$response[$k] = $array;
b'\\ No newline at end of file'