gnu-social/plugins/Event/actions/rsvp.php

105 lines
3.3 KiB
PHP
Raw Permalink Normal View History

2011-03-08 16:15:17 +00:00
<?php
/**
2011-03-09 17:28:25 +00:00
* StatusNet - the distributed open-source microblogging tool
* Copyright (C) 2011, StatusNet, Inc.
2011-03-08 16:15:17 +00:00
*
2011-03-09 17:28:25 +00:00
* RSVP for an event
*
2011-03-08 16:15:17 +00:00
* PHP version 5
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
2011-03-09 17:28:25 +00:00
*
* @category Event
* @package StatusNet
* @author Evan Prodromou <evan@status.net>
* @copyright 2011 StatusNet, Inc.
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
* @link http://status.net/
2011-03-08 16:15:17 +00:00
*/
if (!defined('GNUSOCIAL')) { exit(1); }
2011-03-08 16:15:17 +00:00
/**
2011-03-09 17:28:25 +00:00
* RSVP for an event
2011-03-08 16:15:17 +00:00
*
2011-03-09 17:28:25 +00:00
* @category Event
* @package StatusNet
* @author Evan Prodromou <evan@status.net>
* @copyright 2011 StatusNet, Inc.
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
* @link http://status.net/
2011-03-08 16:15:17 +00:00
*/
2016-01-20 15:10:10 +00:00
class RsvpAction extends FormAction
2011-03-08 16:15:17 +00:00
{
protected $form = 'RSVP';
2016-01-20 15:10:10 +00:00
protected $event = null;
2011-03-08 16:15:17 +00:00
2011-03-09 17:28:25 +00:00
function title()
{
// TRANS: Title for RSVP ("please respond") action.
return _m('TITLE','New RSVP');
2011-03-09 17:28:25 +00:00
}
protected function doPreparation()
2011-03-08 16:15:17 +00:00
{
2016-01-21 01:10:34 +00:00
if ($this->trimmed('notice')) {
$stored = Notice::getByID($this->trimmed('notice'));
$this->event = Happening::fromStored($stored);
} else {
$this->event = Happening::getByKeys(['uri'=>$this->trimmed('event')]);
}
2011-03-08 16:15:17 +00:00
$this->formOpts['event'] = $this->event;
2011-03-08 16:15:17 +00:00
}
protected function doPost()
2011-03-08 16:15:17 +00:00
{
2016-01-20 15:10:10 +00:00
if ($this->trimmed('rsvp') === 'cancel') {
$rsvp = RSVP::byEventAndActor($this->event, $this->scoped);
try {
$notice = $rsvp->getStored();
$notice->deleteAs($this->scoped);
} catch (NoResultException $e) {
// Notice already gone
$rsvp->delete();
2016-01-21 01:20:50 +00:00
} catch (Exception $e) {
// emergency cleanup in case database is screwed up
$rsvp->delete();
2016-01-20 15:10:10 +00:00
}
return _m('Cancelled RSVP');
}
2011-03-08 16:15:17 +00:00
2016-01-20 15:10:10 +00:00
$verb = RSVP::verbFor(strtolower($this->trimmed('rsvp')));
$options = array('source' => 'web');
2011-03-09 17:28:25 +00:00
$act = new Activity();
$act->id = UUID::gen();
$act->verb = $verb;
$act->time = time();
$act->title = _m('RSVP');
$act->actor = $this->scoped->asActivityObject();
$act->target = $this->event->getStored()->asActivityObject();
$act->objects = array(clone($act->target));
$act->content = RSVP::toHTML($this->scoped, $this->event, RSVP::codeFor($verb));
2011-03-09 17:28:25 +00:00
2016-01-21 01:10:34 +00:00
$act->context = new ActivityContext();
$act->context->replyToID = $this->event->getUri();
$stored = Notice::saveActivity($act, $this->scoped, $options);
2011-03-08 16:15:17 +00:00
return _m('Saved RSVP');
2011-03-08 16:15:17 +00:00
}
}