better formatting for RSVPs

This commit is contained in:
Evan Prodromou 2011-03-16 17:51:27 -04:00
parent ba2a246951
commit 29a4bb4d91
3 changed files with 97 additions and 6 deletions

View File

@ -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;
}

View File

@ -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 = _("<span class='automatic event-rsvp'><a href='%1s'>%2s</a> is attending <a href='%3s'>%4s</a>.</span>");
break;
case 'N':
$fmt = _("<span class='automatic event-rsvp'><a href='%1s'>%2s</a> is not attending <a href='%3s'>%4s</a>.</span>");
break;
case '?':
$fmt = _("<span class='automatic event-rsvp'><a href='%1s'>%2s</a> might attend <a href='%3s'>%4s</a>.</span>");
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);
}
}

View File

@ -451,6 +451,10 @@ address .poweredby {
overflow:visible;
}
.notice .automatic {
font-style:italic;
}
#showstream h1 {
display:none;
}