]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/Event/lib/eventlistitem.php
Merge branch 'fixes/type-hints' of gitorious.org:statusnet/quix0rs-gnu-social into...
[quix0rs-gnu-social.git] / plugins / Event / lib / eventlistitem.php
1 <?php
2 /**
3  * StatusNet - the distributed open-source microblogging tool
4  * Copyright (C) 2011, StatusNet, Inc.
5  *
6  * Notice-list representation of an event
7  *
8  * PHP version 5
9  *
10  * This program is free software: you can redistribute it and/or modify
11  * it under the terms of the GNU Affero General Public License as published by
12  * the Free Software Foundation, either version 3 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Affero General Public License for more details.
19  *
20  * You should have received a copy of the GNU Affero General Public License
21  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
22  *
23  * @category  Event
24  * @package   StatusNet
25  * @author    Evan Prodromou <evan@status.net>
26  * @copyright 2011 StatusNet, Inc.
27  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
28  * @link      http://status.net/
29  */
30
31 if (!defined('STATUSNET')) {
32     // This check helps protect against security problems;
33     // your code file can't be executed directly from the web.
34     exit(1);
35 }
36
37 /**
38  * Notice-list representation of an event
39  *
40  * @category  General
41  * @package   StatusNet
42  * @author    Evan Prodromou <evan@status.net>
43  * @copyright 2011 StatusNet, Inc.
44  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
45  * @link      http://status.net/
46  */
47 class EventListItem extends NoticeListItemAdapter
48 {
49     function showNotice()
50     {
51         $this->nli->showAuthor();
52         $this->showContent();
53     }
54
55     function showContent()
56     {
57         $notice = $this->nli->notice;
58         $out    = $this->nli->out;
59
60         $profile = $notice->getProfile();
61         $event   = Happening::fromNotice($notice);
62
63         if (empty($event)) {
64             // TRANS: Content for a deleted RSVP list item (RSVP stands for "please respond").
65             $out->element('p', null, _m('Deleted.'));
66             return;
67         }
68
69         // e-content since we're part of a h-entry
70         $out->elementStart('div', 'h-event e-content'); // VEVENT IN
71
72         $out->elementStart('h3', 'p-summary p-name');  // VEVENT/H3 IN
73
74         try {
75             $out->element('a', array('href' => $event->getUrl()), $event->title);
76         } catch (InvalidUrlException $e) {
77             $out->text($event->title);
78         }
79
80         $out->elementEnd('h3'); // VEVENT/H3 OUT
81
82         $now       = new DateTime();
83         $startDate = new DateTime($event->start_time);
84         $endDate   = new DateTime($event->end_time);
85         $userTz    = new DateTimeZone(common_timezone());
86
87         // Localize the time for the observer
88         $now->setTimeZone($userTz);
89         $startDate->setTimezone($userTz);
90         $endDate->setTimezone($userTz);
91
92         $thisYear  = $now->format('Y');
93         $startYear = $startDate->format('Y');
94         $endYear   = $endDate->format('Y');
95
96         $dateFmt = 'D, F j, '; // e.g.: Mon, Aug 31
97
98         if ($startYear != $thisYear || $endYear != $thisYear) {
99             $dateFmt .= 'Y,'; // append year if we need to think about years
100         }
101
102         $startDateStr = $startDate->format($dateFmt);
103         $endDateStr = $endDate->format($dateFmt);
104
105         $timeFmt = 'g:ia';
106
107         $startTimeStr = $startDate->format($timeFmt);
108         $endTimeStr = $endDate->format("{$timeFmt} (T)");
109
110         $out->elementStart('div', 'event-times'); // VEVENT/EVENT-TIMES IN
111
112         // TRANS: Field label for event description.
113         $out->element('strong', null, _m('Time:'));
114
115         $out->element('time', array('class' => 'dt-start',
116                                     'datetime' => common_date_iso8601($event->start_time)),
117                       $startDateStr . ' ' . $startTimeStr);
118         $out->text(' – ');
119         $out->element('time', array('class' => 'dt-end',
120                                     'datetime' => common_date_iso8601($event->end_time)),
121                       $startDateStr != $endDateStr
122                                     ? "$endDateStr $endTimeStr"
123                                     :  $endTimeStr);
124
125         $out->elementEnd('div'); // VEVENT/EVENT-TIMES OUT
126
127         if (!empty($event->location)) {
128             $out->elementStart('div', 'event-location');
129             // TRANS: Field label for event description.
130             $out->element('strong', null, _m('Location:'));
131             $out->element('span', 'p-location', $event->location);
132             $out->elementEnd('div');
133         }
134
135         if (!empty($event->description)) {
136             $out->elementStart('div', 'event-description');
137             // TRANS: Field label for event description.
138             $out->element('strong', null, _m('Description:'));
139             $out->element('div', 'p-description', $event->description);
140             $out->elementEnd('div');
141         }
142
143         $rsvps = $event->getRSVPs();
144
145         $out->elementStart('div', 'event-rsvps');
146
147         // TRANS: Field label for event description.
148         $out->element('strong', null, _m('Attending:'));
149         $out->elementStart('ul', 'attending-list');
150
151         foreach ($rsvps as $verb => $responses) {
152             $out->elementStart('li', 'rsvp-list');
153             switch ($verb) {
154             case RSVP::POSITIVE:
155                 $out->text(_('Yes:'));
156                 break;
157             case RSVP::NEGATIVE:
158                 $out->text(_('No:'));
159                 break;
160             case RSVP::POSSIBLE:
161                 $out->text(_('Maybe:'));
162                 break;
163             }
164             $ids = array();
165             foreach ($responses as $response) {
166                 $ids[] = $response->profile_id;
167             }
168             $ids = array_slice($ids, 0, ProfileMiniList::MAX_PROFILES + 1);
169             $minilist = new ProfileMiniList(Profile::multiGet('id', $ids), $out);
170             $minilist->show();
171
172             $out->elementEnd('li');
173         }
174
175         $out->elementEnd('ul');
176         $out->elementEnd('div');
177
178         $user = common_current_user();
179
180         if (!empty($user)) {
181             $rsvp = $event->getRSVP($user->getProfile());
182
183             if (empty($rsvp)) {
184                 $form = new RSVPForm($event, $out);
185             } else {
186                 $form = new CancelRSVPForm($rsvp, $out);
187             }
188
189             $form->show();
190         }
191
192         $out->elementEnd('div'); // vevent out
193     }
194 }