diff --git a/plugins/Event/RSVP.php b/plugins/Event/RSVP.php index dc7166b9ce..8bb2d2855d 100644 --- a/plugins/Event/RSVP.php +++ b/plugins/Event/RSVP.php @@ -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); } } diff --git a/plugins/Event/cancelrsvpform.php b/plugins/Event/cancelrsvpform.php index 8cccbdb661..955a782e62 100644 --- a/plugins/Event/cancelrsvpform.php +++ b/plugins/Event/cancelrsvpform.php @@ -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; diff --git a/plugins/Event/newrsvp.php b/plugins/Event/newrsvp.php index 4bacd129f4..2b28580b1d 100644 --- a/plugins/Event/newrsvp.php +++ b/plugins/Event/newrsvp.php @@ -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(); diff --git a/plugins/Event/rsvpform.php b/plugins/Event/rsvpform.php index ad30f6a36e..acc8cd8d12 100644 --- a/plugins/Event/rsvpform.php +++ b/plugins/Event/rsvpform.php @@ -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;')); } }