Working on some RSVP code stuff
This commit is contained in:
@@ -129,6 +129,13 @@ class EventPlugin extends ActivityVerbHandlerPlugin
|
||||
RSVP::POSSIBLE);
|
||||
}
|
||||
|
||||
function isMyNotice(Notice $notice) {
|
||||
if (!empty($notice->object_type)) {
|
||||
return parent::isMyNotice($notice);
|
||||
}
|
||||
return $this->isMyVerb($notice->verb);
|
||||
}
|
||||
|
||||
public function newFormAction() {
|
||||
// such as 'newbookmark' or 'newevent' route
|
||||
return 'new'.$this->tag();
|
||||
@@ -191,57 +198,22 @@ class EventPlugin extends ActivityVerbHandlerPlugin
|
||||
$happening = null;
|
||||
|
||||
switch (true) {
|
||||
case ActivityUtils::compareVerbs($stored->verb, array(ActivityVerb::POST)) &&
|
||||
ActivityUtils::compareTypes($stored->object_type, array(Happening::OBJECT_TYPE)):
|
||||
$happening = Happening::fromStored($stored);
|
||||
case $stored->isVerb([ActivityVerb::POST]) && $stored->isObjectType([Happening::OBJECT_TYPE]):
|
||||
$obj = Happening::fromStored($stored)->asActivityObject();
|
||||
break;
|
||||
// FIXME: Why are these object_type??
|
||||
case ActivityUtils::compareTypes($stored->object_type, array(RSVP::POSITIVE, RSVP::NEGATIVE, RSVP::POSSIBLE)):
|
||||
$rsvp = RSVP::fromNotice($stored);
|
||||
$happening = $rsvp->getEvent();
|
||||
// isObjectType here is because we had the verb stored in object_type previously for unknown reasons
|
||||
case $stored->isObjectType([RSVP::POSITIVE, RSVP::NEGATIVE, RSVP::POSSIBLE]):
|
||||
case $stored->isVerb([RSVP::POSITIVE, RSVP::NEGATIVE, RSVP::POSSIBLE]):
|
||||
$obj = RSVP::fromStored($stored)->asActivityObject();
|
||||
break;
|
||||
default:
|
||||
// TRANS: Exception thrown when event plugin comes across a unknown object type.
|
||||
throw new Exception(_m('Unknown object type.'));
|
||||
}
|
||||
|
||||
$obj = new ActivityObject();
|
||||
|
||||
$obj->id = $happening->getUri();
|
||||
$obj->type = Happening::OBJECT_TYPE;
|
||||
$obj->title = $happening->title;
|
||||
$obj->summary = $happening->description;
|
||||
$obj->link = $happening->getStored()->getUrl();
|
||||
|
||||
$obj->extra[] = array('dtstart',
|
||||
array('xmlns' => 'urn:ietf:params:xml:ns:xcal'),
|
||||
common_date_iso8601($happening->start_time));
|
||||
$obj->extra[] = array('dtend',
|
||||
array('xmlns' => 'urn:ietf:params:xml:ns:xcal'),
|
||||
common_date_iso8601($happening->end_time));
|
||||
$obj->extra[] = array('location', false, $happening->location);
|
||||
$obj->extra[] = array('url', false, $happening->url);
|
||||
|
||||
return $obj;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the verb on RSVP notices
|
||||
*
|
||||
* @param Notice $notice
|
||||
*
|
||||
* @return ActivityObject
|
||||
*/
|
||||
protected function extendActivity(Notice $stored, Activity $act, Profile $scoped=null) {
|
||||
switch (true) {
|
||||
// FIXME: Why are these object_type??
|
||||
case ActivityUtils::compareTypes($stored->object_type, array(RSVP::POSITIVE, RSVP::NEGATIVE, RSVP::POSSIBLE)):
|
||||
$act->verb = $stored->object_type;
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Form for our app
|
||||
*
|
||||
@@ -253,33 +225,29 @@ class EventPlugin extends ActivityVerbHandlerPlugin
|
||||
return new EventForm($out);
|
||||
}
|
||||
|
||||
/**
|
||||
* When a notice is deleted, clean up related tables.
|
||||
*
|
||||
* @param Notice $notice
|
||||
*/
|
||||
function deleteRelated(Notice $notice)
|
||||
function deleteRelated(Notice $stored)
|
||||
{
|
||||
switch ($notice->object_type) {
|
||||
case Happening::OBJECT_TYPE:
|
||||
switch (true) {
|
||||
case $stored->isObjectType([Happening::OBJECT_TYPE]):
|
||||
common_log(LOG_DEBUG, "Deleting event from notice...");
|
||||
try {
|
||||
$happening = Happening::fromStored($notice);
|
||||
$happening = Happening::fromStored($stored);
|
||||
$happening->delete();
|
||||
} catch (NoResultException $e) {
|
||||
// already gone
|
||||
}
|
||||
break;
|
||||
case RSVP::POSITIVE:
|
||||
case RSVP::NEGATIVE:
|
||||
case RSVP::POSSIBLE:
|
||||
// isObjectType here is because we had the verb stored in object_type previously for unknown reasons
|
||||
case $stored->isObjectType([RSVP::POSITIVE, RSVP::NEGATIVE, RSVP::POSSIBLE]):
|
||||
case $stored->isVerb([RSVP::POSITIVE, RSVP::NEGATIVE, RSVP::POSSIBLE]):
|
||||
common_log(LOG_DEBUG, "Deleting rsvp from notice...");
|
||||
$rsvp = RSVP::fromNotice($notice);
|
||||
common_log(LOG_DEBUG, "to delete: $rsvp->id");
|
||||
$rsvp->delete();
|
||||
try {
|
||||
$rsvp = RSVP::fromStored($stored);
|
||||
$rsvp->delete();
|
||||
} catch (NoResultException $e) {
|
||||
// already gone
|
||||
}
|
||||
break;
|
||||
default:
|
||||
common_log(LOG_DEBUG, "Not deleting related, wtf...");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -442,9 +410,9 @@ class EventPlugin extends ActivityVerbHandlerPlugin
|
||||
|
||||
protected function showRSVP(Notice $stored, HTMLOutputter $out, Profile $scoped=null)
|
||||
{
|
||||
$rsvp = RSVP::fromNotice($stored);
|
||||
|
||||
if (empty($rsvp)) {
|
||||
try {
|
||||
$rsvp = RSVP::fromStored($stored);
|
||||
} catch (NoResultException $e) {
|
||||
// TRANS: Content for a deleted RSVP list item (RSVP stands for "please respond").
|
||||
$out->element('p', null, _m('Deleted.'));
|
||||
return;
|
||||
|
@@ -54,7 +54,12 @@ class RsvpAction extends FormAction
|
||||
|
||||
protected function doPreparation()
|
||||
{
|
||||
$this->event = Happening::getByKeys(['uri'=>$this->trimmed('event')]);
|
||||
if ($this->trimmed('notice')) {
|
||||
$stored = Notice::getByID($this->trimmed('notice'));
|
||||
$this->event = Happening::fromStored($stored);
|
||||
} else {
|
||||
$this->event = Happening::getByKeys(['uri'=>$this->trimmed('event')]);
|
||||
}
|
||||
|
||||
$this->formOpts['event'] = $this->event;
|
||||
}
|
||||
@@ -86,6 +91,9 @@ class RsvpAction extends FormAction
|
||||
$act->objects = array(clone($act->target));
|
||||
$act->content = RSVP::toHTML($this->scoped, $this->event, RSVP::codeFor($verb));
|
||||
|
||||
$act->context = new ActivityContext();
|
||||
$act->context->replyToID = $this->event->getUri();
|
||||
|
||||
$stored = Notice::saveActivity($act, $this->scoped, $options);
|
||||
|
||||
return _m('Saved RSVP');
|
||||
|
@@ -211,6 +211,9 @@ class Happening extends Managed_DataObject
|
||||
|
||||
static function fromStored(Notice $stored)
|
||||
{
|
||||
if (!ActivityUtils::compareTypes($stored->getObjectType(), [self::OBJECT_TYPE])) {
|
||||
throw new ServerException('Notice is not of type '.self::OBJECT_TYPE);
|
||||
}
|
||||
return self::getByKeys(array('uri'=>$stored->getUri()));
|
||||
}
|
||||
|
||||
@@ -224,4 +227,43 @@ class Happening extends Managed_DataObject
|
||||
return RSVP::pkeyGet(array('profile_id' => $profile->getID(),
|
||||
'event_uri' => $this->getUri()));
|
||||
}
|
||||
|
||||
static public function getObjectType()
|
||||
{
|
||||
return self::OBJECT_TYPE;
|
||||
}
|
||||
|
||||
public function asActivityObject()
|
||||
{
|
||||
$actobj = new ActivityObject();
|
||||
$actobj->id = $this->getUri();
|
||||
$actobj->type = self::getObjectType();
|
||||
$actobj->title = $this->title;
|
||||
$actobj->summary = $this->description;
|
||||
$actobj->extra[] = array('dtstart',
|
||||
array('xmlns' => 'urn:ietf:params:xml:ns:xcal'),
|
||||
common_date_iso8601($this->start_time));
|
||||
$actobj->extra[] = array('dtend',
|
||||
array('xmlns' => 'urn:ietf:params:xml:ns:xcal'),
|
||||
common_date_iso8601($this->end_time));
|
||||
$actobj->extra[] = array('location',
|
||||
array('xmlns' => 'urn:ietf:params:xml:ns:xcal'),
|
||||
$this->location);
|
||||
$actobj->extra[] = array('url',
|
||||
array('xmlns' => 'urn:ietf:params:xml:ns:xcal'),
|
||||
$this->getUrl());
|
||||
|
||||
/* We don't use these ourselves, but we add them to be nice RSS/XML citizens */
|
||||
$actobj->extra[] = array('startdate',
|
||||
array('xmlns' => 'http://purl.org/rss/1.0/modules/event/'),
|
||||
common_date_iso8601($this->start_time));
|
||||
$actobj->extra[] = array('enddate',
|
||||
array('xmlns' => 'http://purl.org/rss/1.0/modules/event/'),
|
||||
common_date_iso8601($this->end_time));
|
||||
$actobj->extra[] = array('location',
|
||||
array('xmlns' => 'http://purl.org/rss/1.0/modules/event/'),
|
||||
$this->location);
|
||||
|
||||
return $actobj;
|
||||
}
|
||||
}
|
||||
|
@@ -128,6 +128,7 @@ class RSVP extends Managed_DataObject
|
||||
static function saveActivityObject(Activity $act, Notice $stored)
|
||||
{
|
||||
$target = Notice::getByKeys(array('uri'=>$act->target->id));
|
||||
common_debug(_ve('TARGET: '.$target));
|
||||
if (!ActivityUtils::compareTypes($target->getObjectType(), [ Happening::OBJECT_TYPE ])) {
|
||||
throw new ClientException('RSVP not aimed at a Happening');
|
||||
}
|
||||
@@ -159,6 +160,25 @@ class RSVP extends Managed_DataObject
|
||||
return $rsvp;
|
||||
}
|
||||
|
||||
static public function getObjectType()
|
||||
{
|
||||
return ActivityObject::ACTIVITY;
|
||||
}
|
||||
|
||||
public function asActivityObject()
|
||||
{
|
||||
$happening = $this->getEvent();
|
||||
|
||||
$actobj = new ActivityObject();
|
||||
$actobj->id = $rsvp->getUri();
|
||||
$actobj->type = self::getObjectType();
|
||||
$actobj->title = $this->asString();
|
||||
$actobj->content = $this->asString();
|
||||
$actobj->target = array($happening->asActivityObject());
|
||||
|
||||
return $actobj;
|
||||
}
|
||||
|
||||
static function codeFor($verb)
|
||||
{
|
||||
switch (true) {
|
||||
|
@@ -97,7 +97,8 @@ class RSVPForm extends Form
|
||||
// TRANS: Field label on form to RSVP ("please respond") for an event.
|
||||
$this->out->text(_m('RSVP:'));
|
||||
|
||||
$this->out->hidden('event-id', $this->event->getUri(), 'event');
|
||||
$this->out->hidden('notice', $this->event->getStored()->getID(), 'event');
|
||||
$this->out->hidden('event', $this->event->getUri(), 'event'); // not used
|
||||
$this->out->hidden('rsvp', '');
|
||||
|
||||
$this->out->elementEnd('fieldset');
|
||||
|
Reference in New Issue
Block a user