use Y,N,? instead of 1,0,null for 3vl in RSVPs

This commit is contained in:
Evan Prodromou 2011-03-16 14:55:19 -04:00
parent c99f6f6afc
commit 9966c51625
4 changed files with 51 additions and 25 deletions

View File

@ -54,7 +54,7 @@ class RSVP extends Managed_DataObject
public $uri; // varchar(255) public $uri; // varchar(255)
public $profile_id; // int public $profile_id; // int
public $event_id; // varchar(36) UUID public $event_id; // varchar(36) UUID
public $result; // tinyint public $response; // tinyint
public $created; // datetime public $created; // datetime
/** /**
@ -119,8 +119,9 @@ class RSVP extends Managed_DataObject
'length' => 36, 'length' => 36,
'not null' => true, 'not null' => true,
'description' => 'UUID'), 'description' => 'UUID'),
'result' => array('type' => 'tinyint', 'response' => array('type' => 'char',
'description' => '1, 0, or null for three-state yes, no, maybe'), 'length' => '1',
'description' => 'Y, N, or ? for three-state yes, no, maybe'),
'created' => array('type' => 'datetime', 'created' => array('type' => 'datetime',
'not null' => true), '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)) { if (array_key_exists('uri', $options)) {
$other = RSVP::staticGet('uri', $options['uri']); $other = RSVP::staticGet('uri', $options['uri']);
if (!empty($other)) { if (!empty($other)) {
@ -156,7 +159,7 @@ class RSVP extends Managed_DataObject
$rsvp->id = UUID::gen(); $rsvp->id = UUID::gen();
$rsvp->profile_id = $profile->id; $rsvp->profile_id = $profile->id;
$rsvp->event_id = $event->id; $rsvp->event_id = $event->id;
$rsvp->result = self::codeFor($result); $rsvp->response = self::codeFor($verb);
if (array_key_exists('created', $options)) { if (array_key_exists('created', $options)) {
$rsvp->created = $options['created']; $rsvp->created = $options['created'];
@ -176,13 +179,13 @@ class RSVP extends Managed_DataObject
// XXX: come up with something sexier // XXX: come up with something sexier
$content = sprintf(_('RSVPed %s for an event.'), $content = sprintf(_('RSVPed %s for an event.'),
($result == RSVP::POSITIVE) ? _('positively') : ($verb == RSVP::POSITIVE) ? _('positively') :
($result == RSVP::NEGATIVE) ? _('negatively') : ($verb == RSVP::NEGATIVE) ? _('negatively') :
_('possibly')); _('possibly'));
$rendered = $content; $rendered = $content;
$options = array_merge(array('object_type' => $result), $options = array_merge(array('object_type' => $verb),
$options); $options);
if (!array_key_exists('uri', $options)) { if (!array_key_exists('uri', $options)) {
@ -206,14 +209,16 @@ class RSVP extends Managed_DataObject
function codeFor($verb) function codeFor($verb)
{ {
return ($verb == RSVP::POSITIVE) ? 1 : return ($verb == RSVP::POSITIVE) ? 'Y' :
($verb == RSVP::NEGATIVE) ? 0 : null; ($verb == RSVP::NEGATIVE) ? 'N' :
($verb == RSVP::POSSIBLE) ? '?' : null;
} }
static function verbFor($code) static function verbFor($code)
{ {
return ($code == 1) ? RSVP::POSITIVE : return ($code == 'Y') ? RSVP::POSITIVE :
($code == 0) ? RSVP::NEGATIVE : null; ($code == 'N') ? RSVP::NEGATIVE :
($code == '?') ? RSVP::POSSIBLE : null;
} }
function getNotice() function getNotice()
@ -242,7 +247,7 @@ class RSVP extends Managed_DataObject
if ($rsvp->find()) { if ($rsvp->find()) {
while ($rsvp->fetch()) { while ($rsvp->fetch()) {
$verb = self::verbFor($rsvp->result); $verb = self::verbFor($rsvp->response);
$rsvps[$verb][] = clone($rsvp); $rsvps[$verb][] = clone($rsvp);
} }
} }

View File

@ -100,7 +100,7 @@ class CancelRSVPForm extends Form
$this->out->hidden('rsvp', $this->rsvp->id); $this->out->hidden('rsvp', $this->rsvp->id);
switch (RSVP::verbFor($this->rsvp->result)) { switch (RSVP::verbFor($this->rsvp->response)) {
case RSVP::POSITIVE: case RSVP::POSITIVE:
$this->out->text(_('You will attend this event.')); $this->out->text(_('You will attend this event.'));
break; break;

View File

@ -48,7 +48,7 @@ class NewrsvpAction extends Action
{ {
protected $user = null; protected $user = null;
protected $event = null; protected $event = null;
protected $type = null; protected $verb = null;
/** /**
* Returns the title of the action * 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.')); throw new ClientException(_('You must be logged in to RSVP for an event.'));
} }
if ($this->arg('yes')) { common_debug(print_r($this->args, true));
$this->type = RSVP::POSITIVE;
} else if ($this->arg('no')) { switch (strtolower($this->trimmed('submitvalue'))) {
$this->type = RSVP::NEGATIVE; case 'yes':
} else { $this->verb = RSVP::POSITIVE;
$this->type = RSVP::POSSIBLE; break;
case 'no':
$this->verb = RSVP::NEGATIVE;
break;
case 'maybe':
$this->verb = RSVP::POSSIBLE;
break;
default:
throw new ClientException('Unknown submit value.');
} }
return true; return true;
} }
@ -136,7 +145,7 @@ class NewrsvpAction extends Action
try { try {
$saved = RSVP::saveNew($this->user->getProfile(), $saved = RSVP::saveNew($this->user->getProfile(),
$this->event, $this->event,
$this->type); $this->verb);
} catch (ClientException $ce) { } catch (ClientException $ce) {
$this->error = $ce->getMessage(); $this->error = $ce->getMessage();
$this->showPage(); $this->showPage();

View File

@ -101,6 +101,7 @@ class RSVPForm extends Form
$this->out->text(_('RSVP: ')); $this->out->text(_('RSVP: '));
$this->out->hidden('event', $this->event->id); $this->out->hidden('event', $this->event->id);
$this->out->hidden('submitvalue', '');
$this->out->elementEnd('fieldset'); $this->out->elementEnd('fieldset');
} }
@ -113,8 +114,19 @@ class RSVPForm extends Form
function formActions() function formActions()
{ {
$this->out->submit('yes', _m('BUTTON', 'Yes')); $this->submitButton('yes', _m('BUTTON', 'Yes'));
$this->out->submit('no', _m('BUTTON', 'No')); $this->submitButton('no', _m('BUTTON', 'No'));
$this->out->submit('maybe', _m('BUTTON', 'Maybe')); $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;'));
} }
} }