function saveNew($profile, $event, $verb, $options = array()) { if (array_key_exists('uri', $options)) { $other = RSVP::staticGet('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.')); } } $other = RSVP::pkeyGet(array('profile_id' => $profile->id, 'event_id' => $event->id)); if (!empty($other)) { // TRANS: Client exception thrown when trying to save an already existing RSVP ("please respond"). throw new ClientException(_m('RSVP already exists.')); } $rsvp = new RSVP(); $rsvp->id = UUID::gen(); $rsvp->profile_id = $profile->id; $rsvp->event_id = $event->id; $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)); } $rsvp->insert(); self::blow('rsvp:for-event:%s', $event->id); // 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->id; } $saved = Notice::saveNew($profile->id, $content, array_key_exists('source', $options) ? $options['source'] : 'web', $options); return $saved; }