]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
better formatting for RSVPs
authorEvan Prodromou <evan@status.net>
Wed, 16 Mar 2011 21:51:27 +0000 (17:51 -0400)
committerEvan Prodromou <evan@status.net>
Wed, 16 Mar 2011 21:51:27 +0000 (17:51 -0400)
plugins/Event/EventPlugin.php
plugins/Event/RSVP.php
theme/rebase/css/display.css

index 1a43bac3480a6488dad9352e6f523911c0ea1f15..038e1106275aa09eabb94668226b7ff684002193 100644 (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;
     }
 
index fad87aabc84ee7f8a21fb31fe96e42ffeb166a92..7b61cc34adb84beca36de9cf965bf6ff186dee9b 100644 (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);
+    }
 }
index ee88b312a791f67930668fca227dfb06700f9d36..6c3c9e62961835f09c6d6cc109c3e3d3195ecaf5 100644 (file)
@@ -451,6 +451,10 @@ address .poweredby {
 overflow:visible;
 }
 
+.notice .automatic { 
+font-style:italic;
+}
+
 #showstream h1 { 
     display:none;
 }