~fabiocbalbuquerque/sahana-agasti/web-services

« back to all changes in this revision

Viewing changes to apps/frontend/lib/packages/agWebservicesPackage/lib/agWebservicesHelper.class.php

  • Committer: Clayton Kramer
  • Date: 2011-07-26 18:12:28 UTC
  • mto: (1.26.1 push-trunk)
  • mto: This revision was merged to the branch mainline in revision 25.
  • Revision ID: clayton.kramer@mail.cuny.edu-20110726181228-ldpybh717xkhuq25
Added event facilities export to webservices

Show diffs side-by-side

added added

removed removed

Lines of Context:
10
10
 * http://www.gnu.org/licenses/lgpl-2.1.html
11
11
 *
12
12
 * @author Fabio Albuquerque <fabiocbalbuquerque@gmail.com>
 
13
 * @author Clayton Kramer <clayton.kramer@mail.cuny.edu>
13
14
 *
14
15
 * Copyright of the Sahana Software Foundation, sahanafoundation.org
15
16
 * */
16
 
 
17
17
class agWebservicesHelper
18
18
{
19
 
  
20
 
  public static function getStaff()
21
 
  {
22
 
    // Incomplete yet
23
 
    $staff_dql = agDoctrineQuery::create()
24
 
    ->select('st.*, p.*, srt.*, pn.*, pdb.*')
25
 
    ->from('agStaff st')
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());
32
 
  }
33
 
 
34
 
  public static function getOrganizations()
35
 
  {
36
 
    // Incomplete yet
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());
46
 
  }
47
 
 
48
 
  private static function asStaffArray($result) {
49
 
    $results = $result->toArray();
50
 
    $response = array();
51
 
    foreach($results as $k => $array) {
52
 
      $staffResourceTypes     = array();
53
 
      $staffResourceTypesAbbr = array();
54
 
      $descriptions           = array();
55
 
      $names                  = array();
56
 
 
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'];
63
 
      }
64
 
 
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'];
69
 
      }
70
 
 
71
 
      // at least, we create an associative array to facilitate the creation
72
 
      // of the documents in json and xml
73
 
      $response[$k] = array(
74
 
        'id'           => $array['id'],
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'],
83
 
      );
84
 
    }
85
 
    return $response;
86
 
  }
87
 
 
88
 
  private static function asOrganizationArray($result) {
89
 
    $results = $result->toArray();
90
 
    $response = array();
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(
95
 
        'id'           => $array['id'],
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
107
 
      );
108
 
    }
109
 
    return $response;
110
 
  }
 
19
 
 
20
    public static function getStaff()
 
21
    {
 
22
        // Incomplete yet
 
23
        $staff_dql = agDoctrineQuery::create()
 
24
            ->select('st.*, p.*, srt.*, pn.*, pdb.*')
 
25
            ->from('agStaff st')
 
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());
 
32
    }
 
33
 
 
34
    public static function getEventFacilities($eventId)
 
35
    {
 
36
        // Let's use Chad's magic method for getting event facilities
 
37
        $facilityData = agEvent::getEventFacilities($eventId);
 
38
 
 
39
        return self::asFacilityArray($facilityData);
 
40
    }
 
41
 
 
42
    public static function getOrganizations()
 
43
    {
 
44
        // Incomplete yet
 
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());
 
54
    }
 
55
 
 
56
    private static function asStaffArray($result)
 
57
    {
 
58
        $results = $result->toArray();
 
59
        $response = array();
 
60
        foreach ($results as $k => $array) {
 
61
            $staffResourceTypes = array();
 
62
            $staffResourceTypesAbbr = array();
 
63
            $descriptions = array();
 
64
            $names = array();
 
65
 
 
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'];
 
72
            }
 
73
 
 
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'];
 
78
            }
 
79
 
 
80
            // at least, we create an associative array to facilitate the creation
 
81
            // of the documents in json and xml
 
82
            $response[$k] = array(
 
83
              'id' => $array['id'],
 
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'],
 
92
            );
 
93
        }
 
94
        return $response;
 
95
    }
 
96
 
 
97
    private static function asOrganizationArray($result)
 
98
    {
 
99
        $results = $result->toArray();
 
100
        $response = array();
 
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
 
117
            );
 
118
        }
 
119
        return $response;
 
120
    }
 
121
 
 
122
    private static function asFacilityArray($results)
 
123
    {
 
124
        $response = array();
 
125
 
 
126
        foreach ($results as $k => $array) {
 
127
            // an associative array to facilitate the creation
 
128
            // of the documents in json and xml
 
129
 
 
130
            
 
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']);
 
135
            }
 
136
            
 
137
            if (isset($array['line 2'])) {
 
138
                $array['street_2'] = $array['line 2'];
 
139
                unset($array['line 2']);
 
140
            }
 
141
 
 
142
            $response[$k] = $array;
 
143
        }
 
144
        return $response;
 
145
    }
 
146
 
111
147
}
 
 
b'\\ No newline at end of file'