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

Revision 6061, 3.3 KB checked in by niltonneto, 12 years ago (diff)

Ticket #2507 - Modificada implementação para tratamento de erros por Exception.

  • 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($error) {
62                $this-> error = $error;
63        }
64       
65        protected function getError() {
66                return $this-> error;
67        }
68       
69        public function post($request){
70                $this->setRequest($request);           
71                parse_str($request->data, &$array);             
72                $data = (object)$array;         
73                if($data){
74                        if($data->params){                                                             
75                                $this->setParams(json_decode($data->params));
76                        }
77                        if($data->id)
78                                $this->setId($data->id);
79                }
80        }       
81       
82        public function get($request){
83                $response = new Response($request);
84                $response->code = Response::OK;
85                $response->addHeader('content-type', 'text/html');             
86                $response->body = "<H4>Metodo GET nao permitido para este recurso.</H4>";               
87                return $response;
88        }
89       
90        public function getResponse(){
91                $response = new Response($this->getRequest());
92                $response->code = Response::OK;
93                $response->addHeader('content-type', 'application/json');
94
95                if($this->getId())
96                        $body['id']     = $this->getId();
97                if($this->getResult())
98                        $body['result'] = $this->getResult();
99                else
100                        throw new ResponseException("",Errors::E_UNKNOWN_ERROR);
101               
102                $response->body = json_encode($body);
103               
104                return $response;
105        }
106               
107        protected function getUserProfile(){
108                return array(
109                        'contactID'                     => $GLOBALS['phpgw_info']['user']['account_id'],
110                        'contactMails'          => array($GLOBALS['phpgw_info']['user']['email']),
111                        'contactPhones'         => array($GLOBALS['phpgw_info']['user']['telephonenumber']),
112                        'contactFullName'       => $GLOBALS['phpgw_info']['user']['fullname']
113                );
114        }
115        protected function getLdapCatalog(){
116                if(!$this->ldapCatalog) {
117                        $catalog_config = CreateObject("contactcenter.bo_ldap_manager");
118                        $_SESSION['phpgw_info']['expressomail']['ldap_server'] = $catalog_config ? $catalog_config->srcs[1] : null;
119                        $this->ldapCatalog = CreateObject("expressoMail1_2.ldap_functions");
120                }
121       
122                return $this->ldapCatalog;
123        }
124       
125        protected function getDb(){
126                return $GLOBALS['phpgw']->db;
127        }
128       
129        protected function isLoggedIn(){
130                if($this->getParam('auth') != null) {
131                        list($sessionid, $kp3) = explode(":", $this->getParam('auth'));
132                        if($GLOBALS['phpgw']->session->verify($sessionid, $kp3)){                                                                       
133                                return $sessionid;
134                        }
135                        else{
136                                throw new ResponseException("",Errors::LOGIN_AUTH_INVALID);
137                        }
138                }
139                else{
140                        throw new ResponseException("",Errors::LOGIN_NOT_LOGGED_IN);
141                }               
142        }       
143                       
144}
Note: See TracBrowser for help on using the repository browser.