]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
use Y,N,? instead of 1,0,null for 3vl in RSVPs
authorEvan Prodromou <evan@status.net>
Wed, 16 Mar 2011 18:55:19 +0000 (14:55 -0400)
committerEvan Prodromou <evan@status.net>
Wed, 16 Mar 2011 18:55:19 +0000 (14:55 -0400)
plugins/Event/RSVP.php
plugins/Event/cancelrsvpform.php
plugins/Event/newrsvp.php
plugins/Event/rsvpform.php

index dc7166b9ce4972ff8d360deec89c21a46c3902cf..8bb2d2855d2f470d85f566f559353d7d77c91d1d 100644 (file)
@@ -54,7 +54,7 @@ class RSVP extends Managed_DataObject
     public $uri;               // varchar(255)
     public $profile_id;        // int
     public $event_id;          // varchar(36) UUID
-    public $result;            // tinyint
+    public $response;            // tinyint
     public $created;           // datetime
 
     /**
@@ -119,8 +119,9 @@ class RSVP extends Managed_DataObject
                               'length' => 36,
                               'not null' => true,
                               'description' => 'UUID'),
-                'result' => array('type' => 'tinyint',
-                                  'description' => '1, 0, or null for three-state yes, no, maybe'),
+                'response' => array('type' => 'char',
+                                  'length' => '1',
+                                  'description' => 'Y, N, or ? for three-state yes, no, maybe'),
                 'created' => array('type' => 'datetime',
                                    'not null' => true),
             ),
@@ -135,8 +136,10 @@ class RSVP extends Managed_DataObject
         );
     }
 
-    function saveNew($profile, $event, $result, $options=array())
+    function saveNew($profile, $event, $verb, $options=array())
     {
+        common_debug("RSVP::saveNew({$profile->id}, {$event->id}, '$verb', 'some options');");
+
         if (array_key_exists('uri', $options)) {
             $other = RSVP::staticGet('uri', $options['uri']);
             if (!empty($other)) {
@@ -156,7 +159,7 @@ class RSVP extends Managed_DataObject
         $rsvp->id          = UUID::gen();
         $rsvp->profile_id  = $profile->id;
         $rsvp->event_id    = $event->id;
-        $rsvp->result      = self::codeFor($result);
+        $rsvp->response      = self::codeFor($verb);
 
         if (array_key_exists('created', $options)) {
             $rsvp->created = $options['created'];
@@ -176,13 +179,13 @@ class RSVP extends Managed_DataObject
         // XXX: come up with something sexier
 
         $content = sprintf(_('RSVPed %s for an event.'),
-                           ($result == RSVP::POSITIVE) ? _('positively') :
-                           ($result == RSVP::NEGATIVE) ? _('negatively') :
+                           ($verb == RSVP::POSITIVE) ? _('positively') :
+                           ($verb == RSVP::NEGATIVE) ? _('negatively') :
                            _('possibly'));
         
         $rendered = $content;
 
-        $options = array_merge(array('object_type' => $result),
+        $options = array_merge(array('object_type' => $verb),
                                $options);
 
         if (!array_key_exists('uri', $options)) {
@@ -206,14 +209,16 @@ class RSVP extends Managed_DataObject
 
     function codeFor($verb)
     {
-        return ($verb == RSVP::POSITIVE) ? 1 :
-            ($verb == RSVP::NEGATIVE) ? 0 : null;
+        return ($verb == RSVP::POSITIVE) ? 'Y' :
+            ($verb == RSVP::NEGATIVE) ? 'N' :
+            ($verb == RSVP::POSSIBLE) ? '?' : null;
     }
 
     static function verbFor($code)
     {
-        return ($code == 1) ? RSVP::POSITIVE :
-            ($code == 0) ? RSVP::NEGATIVE : null;
+        return ($code == 'Y') ? RSVP::POSITIVE :
+            ($code == 'N') ? RSVP::NEGATIVE :
+            ($code == '?') ? RSVP::POSSIBLE : null;
     }
 
     function getNotice()
@@ -242,7 +247,7 @@ class RSVP extends Managed_DataObject
 
         if ($rsvp->find()) {
             while ($rsvp->fetch()) {
-                $verb = self::verbFor($rsvp->result);
+                $verb = self::verbFor($rsvp->response);
                 $rsvps[$verb][] = clone($rsvp);
             }
         }
index 8cccbdb66178456346904c747d36d3cf3e7ddb2d..955a782e62b8c0f29ad6932fda64625d7c87f206 100644 (file)
@@ -100,7 +100,7 @@ class CancelRSVPForm extends Form
 
         $this->out->hidden('rsvp', $this->rsvp->id);
 
-        switch (RSVP::verbFor($this->rsvp->result)) {
+        switch (RSVP::verbFor($this->rsvp->response)) {
         case RSVP::POSITIVE:
             $this->out->text(_('You will attend this event.'));
             break;
index 4bacd129f4412c497e20599dfe91fae9b75dd647..2b28580b1dbc6c18ccf0196908c533cbdde97e86 100644 (file)
@@ -48,7 +48,7 @@ class NewrsvpAction extends Action
 {
     protected $user  = null;
     protected $event = null;
-    protected $type  = null;
+    protected $verb  = null;
 
     /**
      * Returns the title of the action
@@ -94,13 +94,22 @@ class NewrsvpAction extends Action
             throw new ClientException(_('You must be logged in to RSVP for an event.'));
         }
 
-        if ($this->arg('yes')) {
-            $this->type = RSVP::POSITIVE;
-        } else if ($this->arg('no')) {
-            $this->type = RSVP::NEGATIVE;
-        } else {
-            $this->type = RSVP::POSSIBLE;
+        common_debug(print_r($this->args, true));
+
+        switch (strtolower($this->trimmed('submitvalue'))) {
+        case 'yes':
+            $this->verb = RSVP::POSITIVE;
+            break;
+        case 'no':
+            $this->verb = RSVP::NEGATIVE;
+            break;
+        case 'maybe':
+            $this->verb = RSVP::POSSIBLE;
+            break;
+        default:
+            throw new ClientException('Unknown submit value.');
         }
+
         return true;
     }
 
@@ -136,7 +145,7 @@ class NewrsvpAction extends Action
         try {
             $saved = RSVP::saveNew($this->user->getProfile(),
                                    $this->event,
-                                   $this->type);
+                                   $this->verb);
         } catch (ClientException $ce) {
             $this->error = $ce->getMessage();
             $this->showPage();
index ad30f6a36e137c166b45a1c4ea8d43d183188e4f..acc8cd8d12890893213fc3e6432003efe8cb9481 100644 (file)
@@ -101,6 +101,7 @@ class RSVPForm extends Form
         $this->out->text(_('RSVP: '));
 
         $this->out->hidden('event', $this->event->id);
+        $this->out->hidden('submitvalue', '');
 
         $this->out->elementEnd('fieldset');
     }
@@ -113,8 +114,19 @@ class RSVPForm extends Form
 
     function formActions()
     {
-        $this->out->submit('yes', _m('BUTTON', 'Yes'));
-        $this->out->submit('no', _m('BUTTON', 'No'));
-        $this->out->submit('maybe', _m('BUTTON', 'Maybe'));
+        $this->submitButton('yes', _m('BUTTON', 'Yes'));
+        $this->submitButton('no', _m('BUTTON', 'No'));
+        $this->submitButton('maybe', _m('BUTTON', 'Maybe'));
+    }
+    
+    function submitButton($id, $label)
+    {
+        $this->out->element('input', array('type' => 'submit',
+                                           'id' => $id,
+                                           'name' => $id,
+                                           'class' => 'submit',
+                                           'value' => $label,
+                                           'title' => $label,
+                                           'onClick' => 'this.form.submitvalue.value = this.name; return true;'));
     }
 }