]> git.mxchange.org Git - friendica.git/blobdiff - src/Model/Event.php
Merge remote-tracking branch 'upstream/2022.09-rc' into language
[friendica.git] / src / Model / Event.php
index 857b6c5b88c6834eb650c2f77a735ed81281d0f9..712e5861ac23ef40954128fd3c3c13e1c1a08e6f 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * @copyright Copyright (C) 2010-2021, the Friendica project
+ * @copyright Copyright (C) 2010-2022, the Friendica project
  *
  * @license GNU AGPL version 3 or any later version
  *
@@ -41,7 +41,7 @@ use Friendica\Util\XML;
 class Event
 {
 
-       public static function getHTML(array $event, $simple = false, $uriid = 0)
+       public static function getHTML(array $event, bool $simple = false, int $uriid = 0): string
        {
                if (empty($event)) {
                        return '';
@@ -49,7 +49,7 @@ class Event
 
                $uriid = $event['uri-id'] ?? $uriid;
 
-               $bd_format = DI::l10n()->t('l F d, Y \@ g:i A'); // Friday January 18, 2011 @ 8 AM.
+               $bd_format = DI::l10n()->t('l F d, Y \@ g:i A \G\M\TP (e)'); // Friday October 29, 2021 @ 9:15 AM GMT-04:00 (America/New_York)
 
                $event_start = DI::l10n()->getDay(DateTimeFormat::local($event['start'], $bd_format));
 
@@ -127,7 +127,7 @@ class Event
         * @param array $event Array which contains the event data.
         * @return string The event as a bbcode formatted string.
         */
-       private static function getBBCode(array $event)
+       private static function getBBCode(array $event): string
        {
                $o = '';
 
@@ -157,11 +157,10 @@ class Event
        /**
         * Extract bbcode formatted event data from a string.
         *
-        * @params: string $s The string which should be parsed for event data.
-        * @param $text
+        * @param string $text The string which should be parsed for event data.
         * @return array The array with the event information.
         */
-       public static function fromBBCode($text)
+       public static function fromBBCode(string $text): array
        {
                $ev = [];
 
@@ -195,13 +194,13 @@ class Event
                return $ev;
        }
 
-       public static function sortByDate($event_list)
+       public static function sortByDate(array $event_list): array
        {
                usort($event_list, ['self', 'compareDatesCallback']);
                return $event_list;
        }
 
-       private static function compareDatesCallback($event_a, $event_b)
+       private static function compareDatesCallback(array $event_a, array $event_b)
        {
                $date_a = DateTimeFormat::local($event_a['start']);
                $date_b = DateTimeFormat::local($event_b['start']);
@@ -223,7 +222,7 @@ class Event
         * @return void
         * @throws \Exception
         */
-       public static function delete($event_id)
+       public static function delete(int $event_id)
        {
                if ($event_id == 0) {
                        return;
@@ -242,29 +241,33 @@ class Event
         * @return int The new event id.
         * @throws \Friendica\Network\HTTPException\InternalServerErrorException
         */
-       public static function store($arr)
+       public static function store(array $arr): int
        {
-               $event = [];
-               $event['id']        = intval($arr['id']        ?? 0);
-               $event['uid']       = intval($arr['uid']       ?? 0);
-               $event['cid']       = intval($arr['cid']       ?? 0);
-               $event['guid']      =       ($arr['guid']      ?? '') ?: System::createUUID();
-               $event['uri']       =       ($arr['uri']       ?? '') ?: Item::newURI($event['uid'], $event['guid']);
-               $event['uri-id']    = ItemURI::insert(['uri' => $event['uri'], 'guid' => $event['guid']]);
-               $event['type']      =       ($arr['type']      ?? '') ?: 'event';
-               $event['summary']   =        $arr['summary']   ?? '';
-               $event['desc']      =        $arr['desc']      ?? '';
-               $event['location']  =        $arr['location']  ?? '';
-               $event['allow_cid'] =        $arr['allow_cid'] ?? '';
-               $event['allow_gid'] =        $arr['allow_gid'] ?? '';
-               $event['deny_cid']  =        $arr['deny_cid']  ?? '';
-               $event['deny_gid']  =        $arr['deny_gid']  ?? '';
-               $event['nofinish']  = intval($arr['nofinish'] ?? (!empty($event['start']) && empty($event['finish'])));
-
-               $event['created']   = DateTimeFormat::utc(($arr['created'] ?? '') ?: 'now');
-               $event['edited']    = DateTimeFormat::utc(($arr['edited']  ?? '') ?: 'now');
-               $event['start']     = DateTimeFormat::utc(($arr['start']   ?? '') ?: DBA::NULL_DATETIME);
-               $event['finish']    = DateTimeFormat::utc(($arr['finish']  ?? '') ?: DBA::NULL_DATETIME);
+               $guid = $arr['guid'] ?? '' ?: System::createUUID();
+               $uri  = $arr['uri']  ?? '' ?: Item::newURI($guid);
+               $event = [
+                       'id'        => intval($arr['id']        ?? 0),
+                       'uid'       => intval($arr['uid']       ?? 0),
+                       'cid'       => intval($arr['cid']       ?? 0),
+                       'guid'      => $guid,
+                       'uri'       => $uri,
+                       'uri-id'    => ItemURI::insert(['uri' => $uri, 'guid' => $guid]),
+                       'type'      => ($arr['type']      ?? '') ?: 'event',
+                       'summary'   =>  $arr['summary']   ?? '',
+                       'desc'      =>  $arr['desc']      ?? '',
+                       'location'  =>  $arr['location']  ?? '',
+                       'allow_cid' =>  $arr['allow_cid'] ?? '',
+                       'allow_gid' =>  $arr['allow_gid'] ?? '',
+                       'deny_cid'  =>  $arr['deny_cid']  ?? '',
+                       'deny_gid'  =>  $arr['deny_gid']  ?? '',
+                       'nofinish'  => intval($arr['nofinish'] ?? (!empty($arr['start']) && empty($arr['finish']))),
+                       'created'   => DateTimeFormat::utc(($arr['created'] ?? '') ?: 'now'),
+                       'edited'    => DateTimeFormat::utc(($arr['edited']  ?? '') ?: 'now'),
+                       'start'     => DateTimeFormat::utc(($arr['start']   ?? '') ?: DBA::NULL_DATETIME),
+                       'finish'    => DateTimeFormat::utc(($arr['finish']  ?? '') ?: DBA::NULL_DATETIME),
+               ];
+
+
                if ($event['finish'] < DBA::NULL_DATETIME) {
                        $event['finish'] = DBA::NULL_DATETIME;
                }
@@ -317,7 +320,7 @@ class Event
                return $event['id'];
        }
 
-       public static function getItemArrayForId(int $event_id, array $item = []):array
+       public static function getItemArrayForId(int $event_id, array $item = []): array
        {
                if (empty($event_id)) {
                        return $item;
@@ -374,7 +377,7 @@ class Event
                return $item;
        }
 
-       public static function getItemArrayForImportedId(int $event_id, array $item = []):array
+       public static function getItemArrayForImportedId(int $event_id, array $item = []): array
        {
                if (empty($event_id)) {
                        return $item;
@@ -404,7 +407,7 @@ class Event
         * @return array Array with translations strings.
         * @throws \Friendica\Network\HTTPException\InternalServerErrorException
         */
-       public static function getStrings()
+       public static function getStrings(): array
        {
                // First day of the week (0 = Sunday).
                $firstDay = DI::pConfig()->get(local_user(), 'system', 'first_day_of_week', 0);
@@ -477,7 +480,7 @@ class Event
         *
         * @todo We should replace this with a separate update function if there is some time left.
         */
-       private static function removeDuplicates(array $dates)
+       private static function removeDuplicates(array $dates): array
        {
                $dates2 = [];
 
@@ -500,7 +503,7 @@ class Event
         * @return array Query result
         * @throws \Exception
         */
-       public static function getListById($owner_uid, $event_id, $sql_extra = '')
+       public static function getListById(int $owner_uid, int $event_id, string $sql_extra = ''): array
        {
                $return = [];
 
@@ -536,7 +539,7 @@ class Event
         * @return array Query results.
         * @throws \Exception
         */
-       public static function getListByDate($owner_uid, $event_params, $sql_extra = '')
+       public static function getListByDate(int $owner_uid, array $event_params, string $sql_extra = ''): array
        {
                $return = [];
 
@@ -570,7 +573,7 @@ class Event
         * @throws \Friendica\Network\HTTPException\InternalServerErrorException
         * @throws \ImagickException
         */
-       public static function prepareListForTemplate(array $event_result)
+       public static function prepareListForTemplate(array $event_result): array
        {
                $event_list = [];
 
@@ -651,12 +654,12 @@ class Event
         * @param array  $events Query result for events.
         * @param string $format The output format (ical/csv).
         *
-        * @param        $timezone
+        * @param string $timezone Timezone (missing parameter!)
         * @return string Content according to selected export format.
         *
         * @todo  Implement timezone support
         */
-       private static function formatListForExport(array $events, $format)
+       private static function formatListForExport(array $events, string $format): string
        {
                $o = '';
 
@@ -757,7 +760,7 @@ class Event
         * @return array Query results.
         * @throws \Exception
         */
-       private static function getListByUserId($uid = 0)
+       private static function getListByUserId(int $uid = 0): array
        {
                $return = [];
 
@@ -797,7 +800,7 @@ class Event
         * @throws \Exception
         * @todo Respect authenticated users with events_by_uid().
         */
-       public static function exportListByUserId($uid, $format = 'ical')
+       public static function exportListByUserId(int $uid, string $format = 'ical'): array
        {
                $process = false;
 
@@ -845,7 +848,8 @@ class Event
         * @throws \Friendica\Network\HTTPException\InternalServerErrorException
         * @throws \ImagickException
         */
-       public static function getItemHTML(array $item) {
+       public static function getItemHTML(array $item): string
+       {
                $same_date = false;
                $finish    = false;
 
@@ -933,10 +937,11 @@ class Event
         * @return array The array with the location data.
         *  'name' => The name of the location,<br>
         * 'address' => The address of the location,<br>
-        * 'coordinates' => Latitude‎ and longitude‎ (e.g. '48.864716,2.349014').<br>
+        * 'coordinates' => Latitude and longitude (e.g. '48.864716,2.349014').<br>
         * @throws \Friendica\Network\HTTPException\InternalServerErrorException
         */
-       private static function locationToArray($s = '') {
+       private static function locationToArray(string $s = ''): array
+       {
                if ($s == '') {
                        return [];
                }
@@ -981,7 +986,7 @@ class Event
         * @return bool
         * @throws \Exception
         */
-       public static function createBirthday($contact, $birthday)
+       public static function createBirthday(array $contact, string $birthday): bool
        {
                // Check for duplicates
                $condition = [
@@ -1011,8 +1016,7 @@ class Event
                        'type'    => 'birthday',
                ];
 
-               self::store($values);
-
-               return true;
+               // Check if self::store() was success
+               return (self::store($values) > 0);
        }
 }