]> git.mxchange.org Git - friendica.git/blobdiff - include/event.php
Merge remote-tracking branch 'upstream/develop' into 1702-null-date
[friendica.git] / include / event.php
index 616018bb77a629c848f875652b9ce7d7876ced6f..9e5bafbdb0837c200b0644edca11b51154ea3b17 100644 (file)
@@ -206,7 +206,7 @@ function bbtoevent($s) {
 }
 
 
-function sort_by_date(App $a) {
+function sort_by_date($a) {
 
        usort($a,'ev_compare');
        return $a;
@@ -493,6 +493,26 @@ function get_event_strings() {
        return $i18n;
 }
 
+/// @todo We should replace this with a separate update function if there is some time left
+/**
+ * @brief Removes duplicated birthday events
+ *
+ * @param array $dates Array of possibly duplicated events
+ * @return array Cleaned events
+ */
+function event_remove_duplicates($dates) {
+       $dates2 = array();
+
+       foreach ($dates AS $date) {
+               if ($date['type'] == 'birthday') {
+                       $dates2[$date['uid']."-".$date['cid']."-".$date['start']] = $date;
+               } else {
+                       $dates2[] = $date;
+               }
+       }
+       return $dates2;
+}
+
 /**
  * @brief Get an event by its event ID
  *
@@ -510,15 +530,15 @@ function event_by_id($owner_uid = 0, $event_params, $sql_extra = '') {
        // query for the event by event id
        $r = q("SELECT `event`.*, `item`.`id` AS `itemid`,`item`.`plink`,
                        `item`.`author-name`, `item`.`author-avatar`, `item`.`author-link` FROM `event`
-               STRAIGHT_JOIN `item` ON `item`.`event-id` = `event`.`id` AND `item`.`uid` = `event`.`uid`
+               LEFT JOIN `item` ON `item`.`event-id` = `event`.`id` AND `item`.`uid` = `event`.`uid`
                WHERE `event`.`uid` = %d AND `event`.`id` = %d $sql_extra",
                intval($owner_uid),
                intval($event_params["event_id"])
        );
 
-       if (dbm::is_result($r))
-               return $r;
-
+       if (dbm::is_result($r)) {
+               return event_remove_duplicates($r);
+       }
 }
 
 /**
@@ -543,7 +563,7 @@ function events_by_date($owner_uid = 0, $event_params, $sql_extra = '') {
        // query for the event by date
        $r = q("SELECT `event`.*, `item`.`id` AS `itemid`,`item`.`plink`,
                                `item`.`author-name`, `item`.`author-avatar`, `item`.`author-link` FROM `event`
-                       STRAIGHT_JOIN `item` ON `item`.`event-id` = `event`.`id` AND `item`.`uid` = `event`.`uid`
+                       LEFT JOIN `item` ON `item`.`event-id` = `event`.`id` AND `item`.`uid` = `event`.`uid`
                        WHERE `event`.`uid` = %d AND event.ignore = %d
                        AND ((`adjust` = 0 AND (`finish` >= '%s' OR (nofinish AND start >= '%s')) AND `start` <= '%s')
                        OR  (`adjust` = 1 AND (`finish` >= '%s' OR (nofinish AND start >= '%s')) AND `start` <= '%s'))
@@ -558,8 +578,9 @@ function events_by_date($owner_uid = 0, $event_params, $sql_extra = '') {
                        dbesc($event_params["adjust_finish"])
        );
 
-       if (dbm::is_result($r))
-               return $r;
+       if (dbm::is_result($r)) {
+               return event_remove_duplicates($r);
+       }
 }
 
 /**
@@ -568,7 +589,7 @@ function events_by_date($owner_uid = 0, $event_params, $sql_extra = '') {
  * @param array $arr Event query array
  * @return array Event array for the template
  */
-function process_events ($arr) {
+function process_events($arr) {
        $events=array();
 
        $last_date = '';