123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226 |
- <?php
- if (!defined('STATUSNET')) {
- exit(1);
- }
- class Happening extends Managed_DataObject
- {
- const OBJECT_TYPE = 'http://activitystrea.ms/schema/1.0/event';
- public $__table = 'happening';
- public $id;
- public $uri;
- public $profile_id;
- public $start_time;
- public $end_time;
- public $title;
- public $location;
- public $url;
- public $description;
- public $created;
-
- public static function schemaDef()
- {
- return array(
- 'description' => 'A real-world happening',
- 'fields' => array(
- 'id' => array('type' => 'char',
- 'length' => 36,
- 'not null' => true,
- 'description' => 'UUID'),
- 'uri' => array('type' => 'varchar',
- 'length' => 255,
- 'not null' => true),
- 'profile_id' => array('type' => 'int', 'not null' => true),
- 'start_time' => array('type' => 'datetime', 'not null' => true),
- 'end_time' => array('type' => 'datetime', 'not null' => true),
- 'title' => array('type' => 'varchar',
- 'length' => 255,
- 'not null' => true),
- 'location' => array('type' => 'varchar',
- 'length' => 255),
- 'url' => array('type' => 'varchar',
- 'length' => 255),
- 'description' => array('type' => 'text'),
- 'created' => array('type' => 'datetime',
- 'not null' => true),
- ),
- 'primary key' => array('id'),
- 'unique keys' => array(
- 'happening_uri_key' => array('uri'),
- ),
- 'foreign keys' => array('happening_profile_id__key' => array('profile', array('profile_id' => 'id'))),
- 'indexes' => array('happening_created_idx' => array('created'),
- 'happening_start_end_idx' => array('start_time', 'end_time')),
- );
- }
- 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)) {
-
- throw new ClientException(_m('Event already exists.'));
- }
- }
- $ev = new Happening();
- $ev->id = UUID::gen();
- $ev->profile_id = $profile->id;
- $ev->start_time = common_sql_date($start_time);
- $ev->end_time = common_sql_date($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();
-
-
-
- $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);
-
-
-
-
- $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->uri;
- }
- if (!empty($url)) {
- $options['urls'] = array($url);
- }
- $saved = Notice::saveNew($profile->id,
- $content,
- array_key_exists('source', $options) ?
- $options['source'] : 'web',
- $options);
- return $saved;
- }
-
- public function getUrl()
- {
- if (empty($this->url) ||
- !filter_var($this->url, FILTER_VALIDATE_URL)) {
- throw new InvalidUrlException($this->url);
- }
- return $this->url;
- }
- function getNotice()
- {
- return Notice::getKV('uri', $this->uri);
- }
- static function fromNotice($notice)
- {
- return Happening::getKV('uri', $notice->uri);
- }
- function getRSVPs()
- {
- return RSVP::forEvent($this);
- }
- function getRSVP($profile)
- {
- return RSVP::pkeyGet(array('profile_id' => $profile->id,
- 'event_id' => $this->id));
- }
- }
|