]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - plugins/Event/newevent.php
Merge branch '1.0.x' into limitdist2
[quix0rs-gnu-social.git] / plugins / Event / newevent.php
index fe23e8825df00dd18f4d8ba1d24043262925e370..5551e0ce2c71380d003dc63044b3a1d9707d2577 100644 (file)
@@ -52,8 +52,8 @@ class NeweventAction extends Action
     protected $title       = null;
     protected $location    = null;
     protected $description = null;
-    protected $start_time  = null;
-    protected $end_time    = null;
+    protected $startTime  = null;
+    protected $endTime    = null;
 
     /**
      * Returns the title of the action
@@ -90,16 +90,60 @@ class NeweventAction extends Action
         }
 
         $this->title       = $this->trimmed('title');
+
+        if (empty($this->title)) {
+            throw new ClientException(_('Title required.'));
+        }
+
         $this->location    = $this->trimmed('location');
+        $this->url         = $this->trimmed('url');
         $this->description = $this->trimmed('description');
 
-        $start_date = $this->trimmed('start_date');
-        $start_time = $this->trimmed('start_time');
-        $end_date   = $this->trimmed('end_date');
-        $end_time   = $this->trimmed('end_time');
+        $startDate = $this->trimmed('startdate');
+
+        if (empty($startDate)) {
+            throw new ClientException(_('Start date required.'));
+        }
+
+        $startTime = $this->trimmed('starttime');
+
+        if (empty($startTime)) {
+            $startTime = '00:00';
+        }
+
+        $endDate   = $this->trimmed('enddate');
+
+        if (empty($endDate)) {
+            throw new ClientException(_('End date required.'));
+        }
+
+        $endTime   = $this->trimmed('endtime');
+
+        if (empty($endTime)) {
+            $endTime = '00:00';
+        }
+
+        $start = $startDate . ' ' . $startTime;
 
-        $this->start_time = strtotime($start_date . ' ' . $start_time);
-        $this->end_time   = strtotime($end_date . ' ' . $end_time);
+        common_debug("Event start: '$start'");
+
+        $end = $endDate . ' ' . $endTime;
+
+        common_debug("Event start: '$end'");
+
+        $this->startTime = strtotime($start);
+        $this->endTime   = strtotime($end);
+
+        if ($this->startTime == 0) {
+            throw new Exception(sprintf(_('Could not parse date "%s"'),
+                                        $start));
+        }
+
+
+        if ($this->endTime == 0) {
+            throw new Exception(sprintf(_('Could not parse date "%s"'),
+                                        $end));
+        }
 
         return true;
     }
@@ -138,20 +182,27 @@ class NeweventAction extends Action
                 throw new ClientException(_('Event must have a title.'));
             }
 
-            if (empty($this->start_time)) {
+            if (empty($this->startTime)) {
                 throw new ClientException(_('Event must have a start time.'));
             }
 
-            if (empty($this->end_time)) {
+            if (empty($this->endTime)) {
                 throw new ClientException(_('Event must have an end time.'));
             }
 
-            $saved = Event::saveNew($this->user->getProfile(),
-                                    $this->start_time,
-                                    $this->end_time,
-                                    $this->title,
-                                    $this->location,
-                                    $this->description);
+            $profile = $this->user->getProfile();
+
+            $saved = Happening::saveNew($profile,
+                                        $this->startTime,
+                                        $this->endTime,
+                                        $this->title,
+                                        $this->location,
+                                        $this->description,
+                                        $this->url);
+
+            $event = Happening::fromNotice($saved);
+
+            RSVP::saveNew($profile, $event, RSVP::POSITIVE);
 
         } catch (ClientException $ce) {
             $this->error = $ce->getMessage();
@@ -159,7 +210,21 @@ class NeweventAction extends Action
             return;
         }
 
-
+        if ($this->boolean('ajax')) {
+            header('Content-Type: text/xml;charset=utf-8');
+            $this->xw->startDocument('1.0', 'UTF-8');
+            $this->elementStart('html');
+            $this->elementStart('head');
+            // TRANS: Page title after sending a notice.
+            $this->element('title', null, _('Event saved'));
+            $this->elementEnd('head');
+            $this->elementStart('body');
+            $this->showNotice($saved);
+            $this->elementEnd('body');
+            $this->elementEnd('html');
+        } else {
+            common_redirect($saved->bestUrl(), 303);
+        }
     }
 
     /**
@@ -200,4 +265,20 @@ class NeweventAction extends Action
             return false;
         }
     }
+
+
+    /**
+     * Output a notice
+     *
+     * Used to generate the notice code for Ajax results.
+     *
+     * @param Notice $notice Notice that was saved
+     *
+     * @return void
+     */
+    function showNotice($notice)
+    {
+        $nli = new NoticeListItem($notice, $this);
+        $nli->show();
+    }
 }