source: sandbox/webservice/api/rest/core/Expresso.php @ 6019

Revision 6019, 3.5 KB checked in by niltonneto, 12 years ago (diff)

Ticket #2507 - Modificada implementação para alinhamento com projeto de camada REST.

  • Property svn:executable set to *
Line 
1<?php
2class Expresso extends Resource {
3
4        protected $expressoVersion;
5        protected $ldapCatalog;
6        private $request;
7        private $params;
8        private $result;
9        private $error;
10        private $id;
11       
12        function __construct($id){
13                $GLOBALS['phpgw_info'] = array(
14                                'flags' => array(
15                                                'currentapp'            => 'login',
16                                                'noheader'              => True,
17                                                'disable_Template_class' => True
18                                )
19                );
20               
21                include_once('../../header.inc.php');
22                $this->expressoVersion = substr($GLOBALS['phpgw_info']['server']['versions']['phpgwapi'],0,3);                 
23        }
24       
25        protected function setRequest($request){
26                $this->request = $request;
27        }
28       
29        public function getRequest(){
30                return $this->request;
31        }
32       
33        protected function setResult($result){
34                $this->result = $result;
35        }
36       
37        public function getResult(){
38                return $this->result;
39        }
40       
41        protected function setId($id){
42                $this->id = $id;
43        }
44       
45        public function getId(){
46                return $this->id;
47        }
48       
49        protected function setParams($params){         
50                $this->params = $params;
51        }
52       
53        public function getParams(){   
54                return $this->params;
55        }
56       
57        public function getParam($param){
58                return $this->params->$param;
59        }
60       
61        public function setError($errorID, $arg1 = false) {
62                if($errorID)
63                        $this-> error = Errors::get($errorID, $arg1);
64                else
65                        $this-> error = null;
66        }
67       
68        protected function getError() {
69                return $this-> error;
70        }
71       
72        public function post($request){
73                $this->setRequest($request);           
74                parse_str($request->data, &$array);             
75                $data = (object)$array;         
76                if($data){
77                        if($data->params){                                                             
78                                $this->setParams(json_decode($data->params));
79                        }
80                        if($data->id)
81                                $this->setId($data->id);
82                }
83        }       
84       
85        public function get($request){
86                $response = new Response($request);
87                $response->code = Response::OK;
88                $response->addHeader('content-type', 'text/html');             
89                $response->body = "<H4>Metodo GET nao permitido para este recurso.</H4>";               
90                return $response;
91        }
92       
93        public function getResponse(){
94                $response = new Response($this->getRequest());
95                $response->code = Response::OK;
96                $response->addHeader('content-type', 'application/json');
97
98               
99                if($this->getResult()) {
100                        $body['result'] = $this->getResult();
101                }
102                elseif($this->getError()){
103                        $body['error'] = $this->getError();
104                }
105                else{
106                        $this->setError(Errors::E_INTERNAL_ERROR);
107                        $body['error'] = $this->getError();
108                }
109               
110                $response->body = json_encode($body);
111               
112                return $response;
113        }
114               
115        protected function getUserProfile(){
116                return array(
117                        'contactID'                     => $GLOBALS['phpgw_info']['user']['account_id'],
118                        'contactMails'          => array($GLOBALS['phpgw_info']['user']['email']),
119                        'contactPhones'         => array($GLOBALS['phpgw_info']['user']['telephonenumber']),
120                        'contactFullName'       => $GLOBALS['phpgw_info']['user']['fullname']
121                );
122        }
123        protected function getLdapCatalog(){
124                if(!$this->ldapCatalog) {
125                        $catalog_config = CreateObject("contactcenter.bo_ldap_manager");
126                        $_SESSION['phpgw_info']['expressomail']['ldap_server'] = $catalog_config ? $catalog_config->srcs[1] : null;
127                        $this->ldapCatalog = CreateObject("expressoMail1_2.ldap_functions");
128                }
129       
130                return $this->ldapCatalog;
131        }
132       
133        protected function getDb(){
134                return $GLOBALS['phpgw']->db;
135        }
136       
137        protected function isLoggedIn(){
138                if($this->getParam('auth') != null) {
139                        list($sessionid, $kp3) = explode(":", $this->getParam('auth'));
140                        if($GLOBALS['phpgw']->session->verify($sessionid, $kp3)){                                                                       
141                                return true;
142                        }
143                        else{
144                                $this-> setError(Errors::LOGIN_AUTH_INVALID);
145                                return false;
146                        }
147                }
148                else{
149                        $this-> setError(Errors::LOGIN_NOT_LOGGED_IN);
150                        return false;
151                }               
152        }       
153                       
154}
Note: See TracBrowser for help on using the repository browser.