public $uri; // varchar(255)
public $profile_id; // int
public $event_id; // varchar(36) UUID
- public $result; // tinyint
+ public $response; // tinyint
public $created; // datetime
/**
'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),
),
);
}
- 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)) {
$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'];
// 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)) {
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()
if ($rsvp->find()) {
while ($rsvp->fetch()) {
- $verb = self::verbFor($rsvp->result);
+ $verb = self::verbFor($rsvp->response);
$rsvps[$verb][] = clone($rsvp);
}
}
{
protected $user = null;
protected $event = null;
- protected $type = null;
+ protected $verb = null;
/**
* Returns the title of the 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;
}
try {
$saved = RSVP::saveNew($this->user->getProfile(),
$this->event,
- $this->type);
+ $this->verb);
} catch (ClientException $ce) {
$this->error = $ce->getMessage();
$this->showPage();
$this->out->text(_('RSVP: '));
$this->out->hidden('event', $this->event->id);
+ $this->out->hidden('submitvalue', '');
$this->out->elementEnd('fieldset');
}
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;'));
}
}