]> git.mxchange.org Git - friendica.git/blobdiff - src/Model/Event.php
Standards
[friendica.git] / src / Model / Event.php
index e6c60928320d4db60dde4d6b1ba208c586060902..81e33013fb6d2b2606b656a7b9a191b407db330a 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * @copyright Copyright (C) 2020, Friendica
+ * @copyright Copyright (C) 2010-2021, the Friendica project
  *
  * @license GNU AGPL version 3 or any later version
  *
@@ -242,7 +242,7 @@ class Event
                        return;
                }
 
-               DBA::delete('event', ['id' => $event_id], ['cascade' => false]);
+               DBA::delete('event', ['id' => $event_id]);
                Logger::log("Deleted event ".$event_id, Logger::DEBUG);
        }
 
@@ -293,11 +293,10 @@ class Event
                }
                $private = intval($arr['private'] ?? 0);
 
-               $conditions = ['uid' => $event['uid']];
                if ($event['cid']) {
-                       $conditions['id'] = $event['cid'];
+                       $conditions = ['id' => $event['cid']];
                } else {
-                       $conditions['self'] = true;
+                       $conditions = ['uid' => $event['uid'], 'self' => true];
                }
 
                $contact = DBA::selectFirst('contact', [], $conditions);
@@ -381,6 +380,7 @@ class Event
                                $item_arr['visible']       = 1;
                                $item_arr['verb']          = Activity::POST;
                                $item_arr['object-type']   = Activity\ObjectType::EVENT;
+                               $item_arr['post-type']     = Item::PT_EVENT;
                                $item_arr['origin']        = $event['cid'] === 0 ? 1 : 0;
                                $item_arr['body']          = self::getBBCode($event);
                                $item_arr['event-id']      = $event['id'];
@@ -516,9 +516,9 @@ class Event
                }
 
                // Query for the event by event id
-               $events = DBA::toArray(DBA::p("SELECT `event`.*, `post-view`.`id` AS `itemid` FROM `event`
-                       LEFT JOIN `post-view` ON `post-view`.`event-id` = `event`.`id` AND `post-view`.`uid` = `event`.`uid`
-                       WHERE `event`.`uid` = %d AND `event`.`id` = %d $sql_extra",
+               $events = DBA::toArray(DBA::p("SELECT `event`.*, `post-user-view`.`id` AS `itemid` FROM `event`
+                       LEFT JOIN `post-user-view` ON `post-user-view`.`event-id` = `event`.`id` AND `post-user-view`.`uid` = `event`.`uid`
+                       WHERE `event`.`uid` = ? AND `event`.`id` = ? $sql_extra",
                        $owner_uid, $event_id));
 
                if (DBA::isResult($events)) {
@@ -555,8 +555,8 @@ class Event
 
                // Query for the event by date.
                // @todo Slow query (518 seconds to run), to be optimzed
-               $events = DBA::toArray(DBA::p("SELECT `event`.*, `post-view`.`id` AS `itemid` FROM `event`
-                               LEFT JOIN `post-view` ON `post-view`.`event-id` = `event`.`id` AND `post-view`.`uid` = `event`.`uid`
+               $events = DBA::toArray(DBA::p("SELECT `event`.*, `post-user-view`.`id` AS `itemid` FROM `event`
+                               LEFT JOIN `post-user-view` ON `post-user-view`.`event-id` = `event`.`id` AND `post-user-view`.`uid` = `event`.`uid`
                                WHERE `event`.`uid` = ? AND `event`.`ignore` = ?
                                AND ((NOT `adjust` AND (`finish` >= ? OR (`nofinish` AND `start` >= ?)) AND `start` <= ?)
                                OR  (`adjust` AND (`finish` >= ? OR (`nofinish` AND `start` >= ?)) AND `start` <= ?))" . $sql_extra,
@@ -586,10 +586,10 @@ class Event
                $last_date = '';
                $fmt = DI::l10n()->t('l, F j');
                foreach ($event_result as $event) {
-                       $item = Post::selectFirst(['plink', 'author-name', 'author-avatar', 'author-link'], ['id' => $event['itemid']]);
+                       $item = Post::selectFirst(['plink', 'author-name', 'author-avatar', 'author-link', 'private'], ['id' => $event['itemid']]);
                        if (!DBA::isResult($item)) {
                                // Using default values when no item had been found
-                               $item = ['plink' => '', 'author-name' => '', 'author-avatar' => '', 'author-link' => ''];
+                               $item = ['plink' => '', 'author-name' => '', 'author-avatar' => '', 'author-link' => '', 'private' => Item::PUBLIC];
                        }
 
                        $event = array_merge($event, $item);
@@ -930,7 +930,9 @@ class Event
                $location = self::locationToArray($item['event-location']);
 
                // Construct the profile link (magic-auth).
-               $profile_link = Contact::magicLinkById($item['author-id']);
+               $author = ['uid' => 0, 'id' => $item['author-id'],
+                               'network' => $item['author-network'], 'url' => $item['author-link']];
+               $profile_link = Contact::magicLinkByContact($author);
 
                $tpl = Renderer::getMarkupTemplate('event_stream_item.tpl');
                $return = Renderer::replaceMacros($tpl, [