2011-03-09 16:33:26 +09:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Data class for happenings
|
|
|
|
*
|
|
|
|
* PHP version 5
|
|
|
|
*
|
|
|
|
* @category Data
|
|
|
|
* @package StatusNet
|
|
|
|
* @author Evan Prodromou <evan@status.net>
|
|
|
|
* @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
|
|
|
|
* @link http://status.net/
|
|
|
|
*
|
|
|
|
* StatusNet - the distributed open-source microblogging tool
|
|
|
|
* Copyright (C) 2011, StatusNet, Inc.
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2016-01-01 02:04:12 +09:00
|
|
|
if (!defined('GNUSOCIAL')) { exit(1); }
|
2011-03-09 16:33:26 +09:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Data class for happenings
|
|
|
|
*
|
|
|
|
* There's already an Event class in lib/event.php, so we couldn't
|
|
|
|
* call this an Event without causing a hole in space-time.
|
|
|
|
*
|
|
|
|
* "Happening" seemed good enough.
|
|
|
|
*
|
|
|
|
* @category Event
|
|
|
|
* @package StatusNet
|
|
|
|
* @author Evan Prodromou <evan@status.net>
|
|
|
|
* @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
|
|
|
|
* @link http://status.net/
|
|
|
|
*
|
|
|
|
* @see Managed_DataObject
|
|
|
|
*/
|
|
|
|
class Happening extends Managed_DataObject
|
|
|
|
{
|
|
|
|
const OBJECT_TYPE = 'http://activitystrea.ms/schema/1.0/event';
|
|
|
|
|
|
|
|
public $__table = 'happening'; // table name
|
|
|
|
public $id; // varchar(36) UUID
|
2015-02-13 02:18:55 +09:00
|
|
|
public $uri; // varchar(191) not 255 because utf8mb4 takes more space
|
2011-03-09 16:33:26 +09:00
|
|
|
public $profile_id; // int
|
|
|
|
public $start_time; // datetime
|
|
|
|
public $end_time; // datetime
|
2015-02-13 02:18:55 +09:00
|
|
|
public $title; // varchar(191) not 255 because utf8mb4 takes more space
|
|
|
|
public $location; // varchar(191) not 255 because utf8mb4 takes more space
|
|
|
|
public $url; // varchar(191) not 255 because utf8mb4 takes more space
|
2011-03-09 16:33:26 +09:00
|
|
|
public $description; // text
|
|
|
|
public $created; // datetime
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The One True Thingy that must be defined and declared.
|
|
|
|
*/
|
|
|
|
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',
|
2015-02-13 02:18:55 +09:00
|
|
|
'length' => 191,
|
2011-03-09 16:33:26 +09:00
|
|
|
'not null' => true),
|
2011-03-10 00:07:30 +09:00
|
|
|
'profile_id' => array('type' => 'int', 'not null' => true),
|
|
|
|
'start_time' => array('type' => 'datetime', 'not null' => true),
|
|
|
|
'end_time' => array('type' => 'datetime', 'not null' => true),
|
2011-03-09 16:33:26 +09:00
|
|
|
'title' => array('type' => 'varchar',
|
2015-02-13 02:18:55 +09:00
|
|
|
'length' => 191,
|
2011-03-09 16:33:26 +09:00
|
|
|
'not null' => true),
|
|
|
|
'location' => array('type' => 'varchar',
|
2015-02-13 02:18:55 +09:00
|
|
|
'length' => 191),
|
2011-03-10 00:07:30 +09:00
|
|
|
'url' => array('type' => 'varchar',
|
2015-02-13 02:18:55 +09:00
|
|
|
'length' => 191),
|
2011-03-09 16:33:26 +09:00
|
|
|
'description' => array('type' => 'text'),
|
|
|
|
'created' => array('type' => 'datetime',
|
|
|
|
'not null' => true),
|
|
|
|
),
|
|
|
|
'primary key' => array('id'),
|
|
|
|
'unique keys' => array(
|
|
|
|
'happening_uri_key' => array('uri'),
|
|
|
|
),
|
2011-03-10 00:07:30 +09:00
|
|
|
'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')),
|
2011-03-09 16:33:26 +09:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2011-07-02 12:03:41 +09:00
|
|
|
static function saveNew($profile, $start_time, $end_time, $title, $location, $description, $url, $options=array())
|
2011-03-09 16:33:26 +09:00
|
|
|
{
|
|
|
|
if (array_key_exists('uri', $options)) {
|
2013-08-18 20:04:58 +09:00
|
|
|
$other = Happening::getKV('uri', $options['uri']);
|
2011-03-09 16:33:26 +09:00
|
|
|
if (!empty($other)) {
|
2011-04-07 21:01:40 +09:00
|
|
|
// TRANS: Client exception thrown when trying to create an event that already exists.
|
2011-03-31 05:30:23 +09:00
|
|
|
throw new ClientException(_m('Event already exists.'));
|
2011-03-09 16:33:26 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$ev = new Happening();
|
|
|
|
|
|
|
|
$ev->id = UUID::gen();
|
|
|
|
$ev->profile_id = $profile->id;
|
2015-10-09 23:00:33 +09:00
|
|
|
$ev->start_time = $start_time;
|
|
|
|
$ev->end_time = $end_time;
|
2011-03-09 16:33:26 +09:00
|
|
|
$ev->title = $title;
|
|
|
|
$ev->location = $location;
|
|
|
|
$ev->description = $description;
|
2011-03-10 00:07:30 +09:00
|
|
|
$ev->url = $url;
|
2011-03-09 16:33:26 +09:00
|
|
|
|
|
|
|
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?
|
|
|
|
|
2011-03-31 05:30:23 +09:00
|
|
|
// TRANS: Event description. %1$s is a title, %2$s is start time, %3$s is end time,
|
2011-08-28 03:56:02 +09:00
|
|
|
// TRANS: %4$s is location, %5$s is a description.
|
2011-03-31 05:30:23 +09:00
|
|
|
$content = sprintf(_m('"%1$s" %2$s - %3$s (%4$s): %5$s'),
|
2011-03-09 16:33:26 +09:00
|
|
|
$title,
|
2011-03-31 04:50:56 +09:00
|
|
|
common_exact_date($ev->start_time),
|
|
|
|
common_exact_date($ev->end_time),
|
2011-03-09 16:33:26 +09:00
|
|
|
$location,
|
|
|
|
$description);
|
|
|
|
|
2014-06-23 21:18:59 +09:00
|
|
|
// TRANS: Rendered microformats2 tagged event description.
|
|
|
|
// TRANS: %1$s is a title, %2$s is start time, %3$s is start time,
|
2011-08-28 03:56:02 +09:00
|
|
|
// 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.
|
2014-06-23 21:18:59 +09:00
|
|
|
$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>'),
|
2011-03-09 16:33:26 +09:00
|
|
|
htmlspecialchars($title),
|
2011-03-31 04:50:56 +09:00
|
|
|
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)),
|
2011-03-09 16:33:26 +09:00
|
|
|
htmlspecialchars($location),
|
|
|
|
htmlspecialchars($description));
|
|
|
|
|
|
|
|
$options = array_merge(array('object_type' => Happening::OBJECT_TYPE),
|
|
|
|
$options);
|
|
|
|
|
|
|
|
if (!array_key_exists('uri', $options)) {
|
2016-01-01 02:04:12 +09:00
|
|
|
$options['uri'] = $ev->getUri();
|
2011-03-09 16:33:26 +09:00
|
|
|
}
|
|
|
|
|
2011-03-10 00:07:30 +09:00
|
|
|
if (!empty($url)) {
|
|
|
|
$options['urls'] = array($url);
|
|
|
|
}
|
|
|
|
|
2016-01-01 02:04:12 +09:00
|
|
|
$saved = Notice::saveNew($profile->getID(),
|
2011-03-09 16:33:26 +09:00
|
|
|
$content,
|
|
|
|
array_key_exists('source', $options) ?
|
|
|
|
$options['source'] : 'web',
|
|
|
|
$options);
|
|
|
|
|
|
|
|
return $saved;
|
|
|
|
}
|
|
|
|
|
2014-06-23 21:18:59 +09:00
|
|
|
/**
|
|
|
|
* Returns the profile's canonical url, not necessarily a uri/unique id
|
|
|
|
*
|
|
|
|
* @return string $url
|
|
|
|
*/
|
|
|
|
public function getUrl()
|
|
|
|
{
|
|
|
|
if (empty($this->url) ||
|
|
|
|
!filter_var($this->url, FILTER_VALIDATE_URL)) {
|
|
|
|
throw new InvalidUrlException($this->url);
|
|
|
|
}
|
|
|
|
return $this->url;
|
|
|
|
}
|
|
|
|
|
2016-01-01 02:04:12 +09:00
|
|
|
public function getUri()
|
|
|
|
{
|
|
|
|
return $this->uri;
|
|
|
|
}
|
|
|
|
|
2011-03-09 16:33:26 +09:00
|
|
|
function getNotice()
|
|
|
|
{
|
2016-01-01 02:04:12 +09:00
|
|
|
return Notice::getKV('uri', $this->getUri());
|
2011-03-09 16:33:26 +09:00
|
|
|
}
|
|
|
|
|
2011-03-10 00:07:30 +09:00
|
|
|
static function fromNotice($notice)
|
2011-03-09 16:33:26 +09:00
|
|
|
{
|
2016-01-01 02:04:12 +09:00
|
|
|
return Happening::getKV('uri', $notice->getUri());
|
2011-03-09 16:33:26 +09:00
|
|
|
}
|
2011-03-10 00:40:49 +09:00
|
|
|
|
|
|
|
function getRSVPs()
|
|
|
|
{
|
|
|
|
return RSVP::forEvent($this);
|
|
|
|
}
|
2011-03-10 02:28:25 +09:00
|
|
|
|
|
|
|
function getRSVP($profile)
|
|
|
|
{
|
2016-01-01 02:04:12 +09:00
|
|
|
return RSVP::pkeyGet(array('profile_id' => $profile->getID(),
|
2011-03-10 02:28:25 +09:00
|
|
|
'event_id' => $this->id));
|
|
|
|
}
|
2011-03-09 16:33:26 +09:00
|
|
|
}
|