source: sandbox/2.4-expresso-api/prototype/rest/calendar/CalendarLastResource.php @ 5888

Revision 5888, 1.7 KB checked in by cristiano, 12 years ago (diff)

Ticket #2598 - implementação base REST + oauth

Line 
1<?php
2
3class CalendarLastResource extends Resource{
4
5   
6    /**
7    * Busca os eventos contidos nas agendas assinas do usuário
8    *
9    * @license    http://www.gnu.org/copyleft/gpl.html GPL
10    * @author     Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br)
11    * @sponsor    Caixa EconÃŽmica Federal
12    * @author     Adriano Coutinho da Silva
13    * @return     Lista dos ultimos 10 eventos do usuário
14    * @access     public
15    **/
16    function GET($request){
17        $this->secured();
18       
19        $calendar = Controller::find( array( 'concept' => 'calendarSignature' ), array('calendar'), array( 'filter' => array( '=', 'user',  Config::me("uidNumber") ) ) );
20
21       
22       
23       
24        if($calendar){
25            $calendars = array();
26            $timezones = array();
27
28            foreach($calendar as $key => $value)
29                array_push($calendars, $value['calendar']);
30
31            $calendarTimezone = Controller::find( array( 'concept' => 'calendar' ), array('id', 'timezone'), array( 'filter' => array( 'IN', 'id',  $calendars ) ) );
32
33            foreach($calendarTimezone as $key => $value)
34                $timezones[ $value['id'] ] = $value['timezone'];
35
36
37            $schedulables = Controller::find( array( 'concept' => 'schedulable' ), false,
38                    array( 'filter' => array('AND', array('>=','rangeStart', (time() - 86400).'000'), array('<=','rangeEnd', (time() + 2592000).'000') ,array( 'IN', 'calendar', $calendars )), 'deepness' => 2, 'timezones' => $timezones) );
39
40        }
41       
42        $response = new Response($request);
43        $response->code = Response::OK;
44        $response->addHeader('Content-type', 'aplication/json');
45
46        $response->body = json_encode(( isset($schedulables) && $schedulables) ?  $schedulables : array());
47        return $response;
48    }
49}
50
51?>
Note: See TracBrowser for help on using the repository browser.