static function forEvent(Happening $event) { $keypart = sprintf('rsvp:for-event:%s', $event->getUri()); $idstr = self::cacheGet($keypart); if ($idstr !== false) { $ids = explode(',', $idstr); } else { $ids = array(); $rsvp = new RSVP(); $rsvp->selectAdd(); $rsvp->selectAdd('id'); $rsvp->event_uri = $event->getUri(); if ($rsvp->find()) { while ($rsvp->fetch()) { $ids[] = $rsvp->id; } } self::cacheSet($keypart, implode(',', $ids)); } $rsvps = array(RSVP::POSITIVE => array(), RSVP::NEGATIVE => array(), RSVP::POSSIBLE => array()); foreach ($ids as $id) { $rsvp = RSVP::getKV('id', $id); if (!empty($rsvp)) { $verb = self::verbFor($rsvp->response); $rsvps[$verb][] = $rsvp; } } return $rsvps; }
static function saveNew($profile, $start_time, $end_time, $title, $location, $description, $url, $options = array()) { if (array_key_exists('uri', $options)) { $other = Happening::getKV('uri', $options['uri']); if (!empty($other)) { // TRANS: Client exception thrown when trying to create an event that already exists. throw new ClientException(_m('Event already exists.')); } } $ev = new Happening(); $ev->id = UUID::gen(); $ev->profile_id = $profile->id; $ev->start_time = $start_time; $ev->end_time = $end_time; $ev->title = $title; $ev->location = $location; $ev->description = $description; $ev->url = $url; if (array_key_exists('created', $options)) { $ev->created = $options['created']; } else { $ev->created = common_sql_now(); } if (array_key_exists('uri', $options)) { $ev->uri = $options['uri']; } else { $ev->uri = common_local_url('showevent', array('id' => $ev->id)); } $ev->insert(); // XXX: does this get truncated? // TRANS: Event description. %1$s is a title, %2$s is start time, %3$s is end time, // TRANS: %4$s is location, %5$s is a description. $content = sprintf(_m('"%1$s" %2$s - %3$s (%4$s): %5$s'), $title, common_exact_date($ev->start_time), common_exact_date($ev->end_time), $location, $description); // TRANS: Rendered microformats2 tagged event description. // TRANS: %1$s is a title, %2$s is start time, %3$s is start time, // TRANS: %4$s is end time, %5$s is end time, %6$s is location, %7$s is description. // TRANS: Class names should not be translated. $rendered = sprintf(_m('<div class="h-event">' . '<p class="p-name p-summary">%1$s</p> ' . '<time class="dt-start" datetime="%2$s">%3$s</time> - ' . '<time class="dt-end" datetime="%4$s">%5$s</time> ' . '(<span class="p-location">%6$s</span>): ' . '<div class="p-description">%7$s</div> ' . '</div>'), htmlspecialchars($title), htmlspecialchars(common_date_iso8601($ev->start_time)), htmlspecialchars(common_exact_date($ev->start_time)), htmlspecialchars(common_date_iso8601($ev->end_time)), htmlspecialchars(common_exact_date($ev->end_time)), htmlspecialchars($location), htmlspecialchars($description)); $options = array_merge(array('object_type' => Happening::OBJECT_TYPE), $options); if (!array_key_exists('uri', $options)) { $options['uri'] = $ev->getUri(); } if (!empty($url)) { $options['urls'] = array($url); } $saved = Notice::saveNew($profile->getID(), $content, array_key_exists('source', $options) ? $options['source'] : 'web', $options); return $saved; }