]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - plugins/Event/Happening.php
Update translator documentation.
[quix0rs-gnu-social.git] / plugins / Event / Happening.php
index 5ede26706b8f3fbe8139e8bd7c8abc6d226ea11c..a2811252c00c998e51f1338f1cc2b09c1f015e8f 100644 (file)
@@ -47,7 +47,6 @@ if (!defined('STATUSNET')) {
  *
  * @see      Managed_DataObject
  */
-
 class Happening extends Managed_DataObject
 {
     const OBJECT_TYPE = 'http://activitystrea.ms/schema/1.0/event';
@@ -60,6 +59,7 @@ class Happening extends Managed_DataObject
     public $end_time;              // datetime
     public $title;                 // varchar(255)
     public $location;              // varchar(255)
+    public $url;                   // varchar(255)
     public $description;           // text
     public $created;               // datetime
 
@@ -92,15 +92,16 @@ class Happening extends Managed_DataObject
                 'uri' => array('type' => 'varchar',
                                'length' => 255,
                                'not null' => true),
-                'profile_id' => array('type' => 'int'),
-                'start_time' => array('type' => 'datetime'),
-                'end_time' => array('type' => 'datetime'),
+                '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,
-                                    'not null' => true),
+                                    'length' => 255),
+                'url' => array('type' => 'varchar',
+                               'length' => 255),
                 'description' => array('type' => 'text'),
                 'created' => array('type' => 'datetime',
                                    'not null' => true),
@@ -109,15 +110,19 @@ class Happening extends Managed_DataObject
             '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')),
         );
     }
 
-    function saveNew($profile, $start_time, $end_time, $title, $location, $description, $options=array())
+    function saveNew($profile, $start_time, $end_time, $title, $location, $description, $url, $options=array())
     {
         if (array_key_exists('uri', $options)) {
             $other = Happening::staticGet('uri', $options['uri']);
             if (!empty($other)) {
-                throw new ClientException(_('Event already exists.'));
+                // TRANS: Client exception thrown when trying to create an event that already exists.
+                throw new ClientException(_m('Event already exists.'));
             }
         }
 
@@ -130,6 +135,7 @@ class Happening extends Managed_DataObject
         $ev->title       = $title;
         $ev->location    = $location;
         $ev->description = $description;
+        $ev->url         = $url;
 
         if (array_key_exists('created', $options)) {
             $ev->created = $options['created'];
@@ -148,25 +154,30 @@ class Happening extends Managed_DataObject
 
         // XXX: does this get truncated?
 
-        $content = sprintf(_('"%s" %s - %s (%s): %s'),
+        // 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($start_time),
-                           common_exact_date($end_time),
+                           common_exact_date($ev->start_time),
+                           common_exact_date($ev->end_time),
                            $location,
                            $description);
 
-        $rendered = sprintf(_('<span class="vevent">'.
-                              '<span class="summary">%s</span> '.
-                              '<abbr class="dtstart" title="%s">%s</a> - '.
-                              '<abbr class="dtend" title="%s">%s</a> '.
-                              '(<span class="location">%s</span>): '.
-                              '<span class="description">%s</span> '.
+        // TRANS: Rendered event description. %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('<span class="vevent">'.
+                              '<span class="summary">%1$s</span> '.
+                              '<abbr class="dtstart" title="%2$s">%3$s</a> - '.
+                              '<abbr class="dtend" title="%4$s">%5$s</a> '.
+                              '(<span class="location">%6$s</span>): '.
+                              '<span class="description">%7$s</span> '.
                               '</span>'),
                             htmlspecialchars($title),
-                            htmlspecialchars(common_date_iso8601($start_time)),
-                            htmlspecialchars(common_exact_date($start_time)),
-                            htmlspecialchars(common_date_iso8601($end_time)),
-                            htmlspecialchars(common_exact_date($end_time)),
+                            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));
 
@@ -177,6 +188,10 @@ class Happening extends Managed_DataObject
             $options['uri'] = $ev->uri;
         }
 
+        if (!empty($url)) {
+            $options['urls'] = array($url);
+        }
+
         $saved = Notice::saveNew($profile->id,
                                  $content,
                                  array_key_exists('source', $options) ?
@@ -191,8 +206,19 @@ class Happening extends Managed_DataObject
         return Notice::staticGet('uri', $this->uri);
     }
 
-    static function fromNotice()
+    static function fromNotice($notice)
     {
         return Happening::staticGet('uri', $notice->uri);
     }
+
+    function getRSVPs()
+    {
+        return RSVP::forEvent($this);
+    }
+
+    function getRSVP($profile)
+    {
+        return RSVP::pkeyGet(array('profile_id' => $profile->id,
+                                   'event_id' => $this->id));
+    }
 }