From 29a4bb4d9159ef337b3a80615c8a9f9f70f3b9bd Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Wed, 16 Mar 2011 17:51:27 -0400 Subject: [PATCH] better formatting for RSVPs --- plugins/Event/EventPlugin.php | 6 ++- plugins/Event/RSVP.php | 93 +++++++++++++++++++++++++++++++++-- theme/rebase/css/display.css | 4 ++ 3 files changed, 97 insertions(+), 6 deletions(-) diff --git a/plugins/Event/EventPlugin.php b/plugins/Event/EventPlugin.php index 1a43bac348..038e110627 100644 --- a/plugins/Event/EventPlugin.php +++ b/plugins/Event/EventPlugin.php @@ -324,7 +324,11 @@ class EventPlugin extends MicroappPlugin function showRSVPNotice($notice, $out) { - $out->raw($notice->rendered); + $rsvp = RSVP::fromNotice($notice); + + $out->elementStart('div', 'rsvp'); + $out->raw($rsvp->asHTML()); + $out->elementEnd('div'); return; } diff --git a/plugins/Event/RSVP.php b/plugins/Event/RSVP.php index fad87aabc8..7b61cc34ad 100644 --- a/plugins/Event/RSVP.php +++ b/plugins/Event/RSVP.php @@ -180,12 +180,9 @@ class RSVP extends Managed_DataObject // XXX: come up with something sexier - $content = sprintf(_('RSVPed %s for an event.'), - ($verb == RSVP::POSITIVE) ? _('positively') : - ($verb == RSVP::NEGATIVE) ? _('negatively') : - _('possibly')); + $content = $rsvp->asString(); - $rendered = $content; + $rendered = $rsvp->asHTML(); $options = array_merge(array('object_type' => $verb), $options); @@ -276,4 +273,90 @@ class RSVP extends Managed_DataObject return $rsvps; } + + function getProfile() + { + $profile = Profile::staticGet('id', $this->profile_id); + if (empty($profile)) { + throw new Exception("No profile with ID {$this->profile_id}"); + } + return $profile; + } + + function getEvent() + { + $event = Happening::staticGet('id', $this->event_id); + if (empty($event)) { + throw new Exception("No event with ID {$this->event_id}"); + } + return $event; + } + + function asHTML() + { + return self::toHTML($this->getProfile(), + $this->getEvent(), + $this->response); + } + + function asString() + { + return self::toString($this->getProfile(), + $this->getEvent(), + $this->response); + } + + static function toHTML($profile, $event, $response) + { + $fmt = null; + + $notice = $event->getNotice(); + + switch ($response) { + case 'Y': + $fmt = _("%2s is attending %4s."); + break; + case 'N': + $fmt = _("%2s is not attending %4s."); + break; + case '?': + $fmt = _("%2s might attend %4s."); + break; + default: + throw new Exception("Unknown response code {$response}"); + break; + } + + return sprintf($fmt, + htmlspecialchars($profile->profileurl), + htmlspecialchars($profile->getBestName()), + htmlspecialchars($notice->bestUrl()), + htmlspecialchars($event->title)); + } + + static function toString($profile, $event, $response) + { + $fmt = null; + + $notice = $event->getNotice(); + + switch ($response) { + case 'Y': + $fmt = _("%1s is attending %2s."); + break; + case 'N': + $fmt = _("%1s is not attending %2s."); + break; + case '?': + $fmt = _("%1s might attend %2s.>"); + break; + default: + throw new Exception("Unknown response code {$response}"); + break; + } + + return sprintf($fmt, + $profile->getBestName(), + $event->title); + } } diff --git a/theme/rebase/css/display.css b/theme/rebase/css/display.css index ee88b312a7..6c3c9e6296 100644 --- a/theme/rebase/css/display.css +++ b/theme/rebase/css/display.css @@ -451,6 +451,10 @@ address .poweredby { overflow:visible; } +.notice .automatic { +font-style:italic; +} + #showstream h1 { display:none; } -- 2.39.5