X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FModel%2FEvent.php;h=992b77badabaf8042907aae3df0b7d5af4eb0353;hb=0bc2fe66f54717a3f2e86fd9626dc565e9d00fd7;hp=1c848dcad74cec58ad790d726bd2be68e5718ef2;hpb=541f8634c0658dbafdbc1c50598737f7be133aa6;p=friendica.git
diff --git a/src/Model/Event.php b/src/Model/Event.php
index 1c848dcad7..992b77bada 100644
--- a/src/Model/Event.php
+++ b/src/Model/Event.php
@@ -5,15 +5,13 @@
namespace Friendica\Model;
-use dba;
use Friendica\BaseObject;
use Friendica\Content\Text\BBCode;
use Friendica\Core\Addon;
use Friendica\Core\L10n;
use Friendica\Core\PConfig;
use Friendica\Core\System;
-use Friendica\Database\DBM;
-use Friendica\Model\Item;
+use Friendica\Database\DBA;
use Friendica\Util\DateTimeFormat;
use Friendica\Util\Map;
@@ -36,19 +34,27 @@ class Event extends BaseObject
$bd_format = L10n::t('l F d, Y \@ g:i A'); // Friday January 18, 2011 @ 8 AM.
$event_start = day_translate(
- $event['adjust'] ?
+ !empty($event['adjust']) ?
DateTimeFormat::local($event['start'], $bd_format) : DateTimeFormat::utc($event['start'], $bd_format)
);
- $event_end = day_translate(
- $event['adjust'] ?
- DateTimeFormat::local($event['finish'], $bd_format) : DateTimeFormat::utc($event['finish'], $bd_format)
- );
+ if (!empty($event['finish'])) {
+ $event_end = day_translate(
+ !empty($event['adjust']) ?
+ DateTimeFormat::local($event['finish'], $bd_format) : DateTimeFormat::utc($event['finish'], $bd_format)
+ );
+ } else {
+ $event_end = '';
+ }
if ($simple) {
- $o = "
" . BBCode::convert($event['summary'], false, $simple) . "
";
+ if (!empty($event['summary'])) {
+ $o = "" . BBCode::convert($event['summary'], false, $simple) . "
";
+ }
- $o .= "" . BBCode::convert($event['desc'], false, $simple) . "
";
+ if (!empty($event['desc'])) {
+ $o .= "" . BBCode::convert($event['desc'], false, $simple) . "
";
+ }
$o .= "" . L10n::t('Starts:') . "
" . $event_start . "
";
@@ -56,7 +62,7 @@ class Event extends BaseObject
$o .= "" . L10n::t('Finishes:') . "
" . $event_end . "
";
}
- if (strlen($event['location'])) {
+ if (!empty($event['location'])) {
$o .= "" . L10n::t('Location:') . "
" . BBCode::convert($event['location'], false, $simple) . "
";
}
@@ -68,20 +74,22 @@ class Event extends BaseObject
$o .= '' . BBCode::convert($event['summary'], false, $simple) . '
' . "\r\n";
$o .= '' . L10n::t('Starts:') . ' ' . $event_start
. '
' . "\r\n";
if (!$event['nofinish']) {
$o .= '' . L10n::t('Finishes:') . ' ' . $event_end
. '
' . "\r\n";
}
- $o .= '' . BBCode::convert($event['desc'], false, $simple) . '
' . "\r\n";
+ if (!empty($event['desc'])) {
+ $o .= '' . BBCode::convert($event['desc'], false, $simple) . '
' . "\r\n";
+ }
- if (strlen($event['location'])) {
+ if (!empty($event['location'])) {
$o .= '' . L10n::t('Location:') . ' '
. BBCode::convert($event['location'], false, $simple)
. '
' . "\r\n";
@@ -214,7 +222,7 @@ class Event extends BaseObject
return;
}
- dba::delete('event', ['id' => $event_id]);
+ DBA::delete('event', ['id' => $event_id]);
logger("Deleted event ".$event_id, LOGGER_DEBUG);
}
@@ -234,7 +242,7 @@ class Event extends BaseObject
$event['id'] = intval(defaults($arr, 'id' , 0));
$event['uid'] = intval(defaults($arr, 'uid' , 0));
$event['cid'] = intval(defaults($arr, 'cid' , 0));
- $event['uri'] = defaults($arr, 'uri' , item_new_uri($a->get_hostname(), $event['uid']));
+ $event['uri'] = defaults($arr, 'uri' , Item::newURI($event['uid']));
$event['type'] = defaults($arr, 'type' , 'event');
$event['summary'] = defaults($arr, 'summary' , '');
$event['desc'] = defaults($arr, 'desc' , '');
@@ -262,17 +270,17 @@ class Event extends BaseObject
$conditions['self'] = true;
}
- $contact = dba::selectFirst('contact', [], $conditions);
+ $contact = DBA::selectFirst('contact', [], $conditions);
// Existing event being modified.
if ($event['id']) {
// has the event actually changed?
- $existing_event = dba::selectFirst('event', ['edited'], ['id' => $event['id'], 'uid' => $event['uid']]);
- if ((! DBM::is_result($existing_event)) || ($existing_event['edited'] === $event['edited'])) {
+ $existing_event = DBA::selectFirst('event', ['edited'], ['id' => $event['id'], 'uid' => $event['uid']]);
+ if (!DBA::isResult($existing_event) || ($existing_event['edited'] === $event['edited'])) {
- $item = dba::selectFirst('item', [], ['event-id' => $event['id'], 'uid' => $event['uid']]);
+ $item = Item::selectFirst(['id'], ['event-id' => $event['id'], 'uid' => $event['uid']]);
- return DBM::is_result($item) ? $item['id'] : 0;
+ return DBA::isResult($item) ? $item['id'] : 0;
}
$updated_fields = [
@@ -287,10 +295,10 @@ class Event extends BaseObject
'nofinish' => $event['nofinish'],
];
- dba::update('event', $updated_fields, ['id' => $event['id'], 'uid' => $event['uid']]);
+ DBA::update('event', $updated_fields, ['id' => $event['id'], 'uid' => $event['uid']]);
- $item = dba::selectFirst('item', ['id'], ['event-id' => $event['id'], 'uid' => $event['uid']]);
- if (DBM::is_result($item)) {
+ $item = Item::selectFirst(['id'], ['event-id' => $event['id'], 'uid' => $event['uid']]);
+ if (DBA::isResult($item)) {
$object = '' . "\n";
@@ -305,12 +313,12 @@ class Event extends BaseObject
Addon::callHooks('event_updated', $event['id']);
} else {
- $event['guid'] = get_guid(32);
+ $event['guid'] = defaults($arr, 'guid', System::createGUID(32));
// New event. Store it.
- dba::insert('event', $event);
+ DBA::insert('event', $event);
- $event['id'] = dba::lastInsertId();
+ $event['id'] = DBA::lastInsertId();
$item_arr = [];
@@ -319,7 +327,8 @@ class Event extends BaseObject
$item_arr['uri'] = $event['uri'];
$item_arr['parent-uri'] = $event['uri'];
$item_arr['guid'] = $event['guid'];
- $item_arr['type'] = 'activity';
+ $item_arr['plink'] = defaults($arr, 'plink', '');
+ $item_arr['post-type'] = Item::PT_EVENT;
$item_arr['wall'] = $event['cid'] ? 0 : 1;
$item_arr['contact-id'] = $contact['id'];
$item_arr['owner-name'] = $contact['name'];
@@ -464,15 +473,14 @@ class Event extends BaseObject
}
// 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`
+ $r = q("SELECT `event`.*, `item`.`id` AS `itemid` FROM `event`
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_id)
);
- if (DBM::is_result($r)) {
+ if (DBA::isResult($r)) {
$return = self::removeDuplicates($r);
}
@@ -505,8 +513,7 @@ class Event extends BaseObject
// Query for the event by date.
// @todo Slow query (518 seconds to run), to be optimzed
- $r = q("SELECT `event`.*, `item`.`id` AS `itemid`,`item`.`plink`,
- `item`.`author-name`, `item`.`author-avatar`, `item`.`author-link` FROM `event`
+ $r = q("SELECT `event`.*, `item`.`id` AS `itemid` FROM `event`
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')
@@ -514,15 +521,15 @@ class Event extends BaseObject
$sql_extra ",
intval($owner_uid),
intval($event_params["ignore"]),
- dbesc($event_params["start"]),
- dbesc($event_params["start"]),
- dbesc($event_params["finish"]),
- dbesc($event_params["adjust_start"]),
- dbesc($event_params["adjust_start"]),
- dbesc($event_params["adjust_finish"])
+ DBA::escape($event_params["start"]),
+ DBA::escape($event_params["start"]),
+ DBA::escape($event_params["finish"]),
+ DBA::escape($event_params["adjust_start"]),
+ DBA::escape($event_params["adjust_start"]),
+ DBA::escape($event_params["adjust_finish"])
);
- if (DBM::is_result($r)) {
+ if (DBA::isResult($r)) {
$return = self::removeDuplicates($r);
}
@@ -542,6 +549,14 @@ class Event extends BaseObject
$last_date = '';
$fmt = L10n::t('l, F j');
foreach ($event_result as $event) {
+ $item = Item::selectFirst(['plink', 'author-name', 'author-avatar', 'author-link'], ['id' => $event['itemid']]);
+ if (!DBA::isResult($item)) {
+ // Using default values when no item had been found
+ $item = ['plink' => '', 'author-name' => '', 'author-avatar' => '', 'author-link' => ''];
+ }
+
+ $event = array_merge($event, $item);
+
$start = $event['adjust'] ? DateTimeFormat::local($event['start'], 'c') : DateTimeFormat::utc($event['start'], 'c');
$j = $event['adjust'] ? DateTimeFormat::local($event['start'], 'j') : DateTimeFormat::utc($event['start'], 'j');
$day = $event['adjust'] ? DateTimeFormat::local($event['start'], $fmt) : DateTimeFormat::utc($event['start'], $fmt);
@@ -735,9 +750,9 @@ class Event extends BaseObject
$conditions += ['allow_cid' => '', 'allow_gid' => ''];
}
- $events = dba::select('event', $fields, $conditions);
- if (DBM::is_result($events)) {
- $return = dba::inArray($events);
+ $events = DBA::select('event', $fields, $conditions);
+ if (DBA::isResult($events)) {
+ $return = DBA::toArray($events);
}
return $return;
@@ -759,8 +774,8 @@ class Event extends BaseObject
{
$process = false;
- $user = dba::selectFirst('user', ['timezone'], ['uid' => $uid]);
- if (DBM::is_result($user)) {
+ $user = DBA::selectFirst('user', ['timezone'], ['uid' => $uid]);
+ if (DBA::isResult($user)) {
$timezone = $user['timezone'];
}
@@ -862,6 +877,11 @@ class Event extends BaseObject
if (substr($dtstart_title, 0, 10) === substr($dtend_title, 0, 10)) {
$same_date = true;
}
+ } else {
+ $dtend_title = '';
+ $dtend_dt = '';
+ $end_time = '';
+ $end_short = '';
}
// Format the event location.