Working on some RSVP code stuff

This commit is contained in:
Mikael Nordfeldth
2016-01-21 02:10:34 +01:00
parent 5999171c11
commit f74d2d555c
10 changed files with 126 additions and 66 deletions

View File

@@ -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;
}
}

View File

@@ -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) {