Dotclear

source: plugins/eventdata/class.dc.event.rest.php @ 960

Revision 960, 2.6 KB checked in by JcDenis, 14 years ago (diff)

First commit

Line 
1<?php
2# -- BEGIN LICENSE BLOCK ----------------------------------
3# This file is part of eventdata, a plugin for Dotclear 2.
4#
5# Copyright (c) 2009 JC Denis and contributors
6# jcdenis@gdwd.com
7#
8# Licensed under the GPL version 2.0 license.
9# A copy of this license is available in LICENSE file or at
10# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
11# -- END LICENSE BLOCK ------------------------------------
12
13class dcEventRest
14{
15     public static function getEvent(&$core,$get)
16     {
17          $postId = !empty($get['postId']) ? $get['postId'] : null;
18          $eventType = !empty($get['eventType']) ? $get['eventType'] : null;
19          $eventStart = !empty($get['eventStart']) ? $get['eventStart'] : null;
20          $eventEnd = !empty($get['eventEnd']) ? $get['eventEnd'] : null;
21          $eventPeriod = !empty($get['eventPeriod']) ? $get['eventPeriod'] : null;
22
23          $limit = !empty($get['limit']) ? $get['limit'] : null;
24          $sortby = !empty($get['sortby']) ? $get['sortby'] : 'event_start,desc';
25
26          $event = new dcEvent($core);
27          $rs = $event->getEvent($eventType,$limit,$eventStart,$eventEnd,$postId,$eventPeriod);
28
29          $sortby = explode(',',$sortby);
30          $sort = $sortby[0];
31          $order = isset($sortby[1]) ? $sortby[1] : 'desc';
32
33          switch ($sort) {
34               case 'event_start':
35                    $sort = 'start_ts'; break;
36               case 'event_end':
37                    $sort = 'end_ts'; break;
38               default:
39                    $sort = 'event_start';
40          }
41
42          $rs->sort($sort,$order);
43         
44          $rsp = new xmlTag();
45         
46          while ($rs->fetch())
47          {
48               $xe = new xmlTag('event');
49               $xe->post = $rs->post_id;
50               $xe->type = $rs->event_type;
51               $xe->count = $rs->count;
52               $xe->start = $rs->event_start;
53               $xe->end = $rs->event_end;
54               $rsp->insertNode($xe);
55          }
56
57          return $rsp;
58     }
59     
60     public static function setEvent(&$core,$get,$post)
61     {
62          if (empty($post['postId'])) throw new Exception('No post ID');
63          if (empty($post['eventType'])) throw new Exception('No event type');
64          if (empty($post['eventStart'])) throw new Exception('No event start date');
65          if (empty($post['eventEnd'])) throw new Exception('No event end date');
66
67          $event = new dcEvent($core);
68          $event->setEvent($post['eventType'],$post['postId'],$post['eventStart'],$post['eventEnd'],);
69
70          return true;
71     }
72     
73     public static function delEvent(&$core,$get,$post)
74     {
75          if (empty($post['postId'])) throw new Exception('No post ID');
76          if (empty($post['eventType'])) throw new Exception('No event type');
77
78          $start = empty($post['eventStart']) ? null : $post['eventStart'];
79          $end = empty($post['eventEnd']) ? null : $post['eventEnd'];
80
81          $event = new dcEvent($core);
82          $event->delEvent($post['eventType'],$post['postId'],$start,$end);
83
84          return true;
85     }
86}
87?>
Note: See TracBrowser for help on using the repository browser.

Sites map