X-Git-Url: https://git.mxchange.org/?p=quix0rs-gnu-social.git;a=blobdiff_plain;f=plugins%2FEvent%2Fclasses%2FRSVP.php;fp=plugins%2FEvent%2Fclasses%2FRSVP.php;h=0c39022b140433ccfba4a2cba5b940386a0f8bb4;hp=c4ffc3ee340bb74ba09be17eac457161f10167e7;hb=d6b28c64830f632bb2f4b6f3c9369b9e56ad217a;hpb=e2d85a39e7f82ceef2cb2fe66a3a9a62ac9a363e diff --git a/plugins/Event/classes/RSVP.php b/plugins/Event/classes/RSVP.php index c4ffc3ee34..0c39022b14 100644 --- a/plugins/Event/classes/RSVP.php +++ b/plugins/Event/classes/RSVP.php @@ -126,14 +126,37 @@ class RSVP extends Managed_DataObject function saveNew(Profile $profile, $event, $verb, array $options = array()) { - if (array_key_exists('uri', $options)) { - $other = RSVP::getKV('uri', $options['uri']); - if (!empty($other)) { - // TRANS: Client exception thrown when trying to save an already existing RSVP ("please respond"). - throw new ClientException(_m('RSVP already exists.')); - } + $eventNotice = $event->getNotice(); + $options = array_merge(array('source' => 'web'), $options); + + $act = new Activity(); + $act->type = ActivityObject::ACTIVITY; + $act->verb = $verb; + $act->time = $options['created'] ? strtotime($options['created']) : time(); + $act->title = _m("RSVP"); + $act->actor = $profile->asActivityObject(); + $act->target = $eventNotice->asActivityObject(); + $act->objects = array(clone($act->target)); + $act->content = RSVP::toHTML($profile, $event, self::codeFor($verb)); + + $act->id = common_local_url('showrsvp', array('id' => UUID::gen())); + $act->link = $act->id; + + $saved = Notice::saveActivity($act, $profile, $options); + + return $saved; + } + + function saveNewFromNotice($notice, $event, $verb) + { + $other = RSVP::getKV('uri', $notice->uri); + if (!empty($other)) { + // TRANS: Client exception thrown when trying to save an already existing RSVP ("please respond"). + throw new ClientException(_m('RSVP already exists.')); } + $profile = $notice->getProfile(); + try { $other = RSVP::getByKeys( [ 'profile_id' => $profile->getID(), 'event_uri' => $event->getUri(), @@ -146,54 +169,19 @@ class RSVP extends Managed_DataObject $rsvp = new RSVP(); - $rsvp->id = UUID::gen(); - $rsvp->profile_id = $profile->getID(); - $rsvp->event_uri = $event->getUri(); - $rsvp->response = self::codeFor($verb); - - if (array_key_exists('created', $options)) { - $rsvp->created = $options['created']; - } else { - $rsvp->created = common_sql_now(); - } - - if (array_key_exists('uri', $options)) { - $rsvp->uri = $options['uri']; - } else { - $rsvp->uri = common_local_url('showrsvp', - array('id' => $rsvp->id)); - } + preg_match('/\/([^\/]+)\/*/', $notice->uri, $match); + $rsvp->id = $match[1] ? $match[1] : UUID::gen(); + $rsvp->profile_id = $profile->id; + $rsvp->event_id = $event->id; + $rsvp->response = self::codeFor($verb); + $rsvp->created = $notice->created; + $rsvp->uri = $notice->uri; $rsvp->insert(); self::blow('rsvp:for-event:%s', $event->getUri()); - // XXX: come up with something sexier - - $content = $rsvp->asString(); - - $rendered = $rsvp->asHTML(); - - $options = array_merge(array('object_type' => $verb), - $options); - - if (!array_key_exists('uri', $options)) { - $options['uri'] = $rsvp->uri; - } - - $eventNotice = $event->getNotice(); - - if (!empty($eventNotice)) { - $options['reply_to'] = $eventNotice->getID(); - } - - $saved = Notice::saveNew($profile->getID(), - $content, - array_key_exists('source', $options) ? - $options['source'] : 'web', - $options); - - return $saved; + return $rsvp; } function codeFor($verb)