Move DFRN::birthdayEvent() to Event::createBirthday
This commit is contained in:
parent
d71e856535
commit
de5ee56d2f
|
@ -322,6 +322,10 @@ class Event extends BaseObject
|
|||
// New event. Store it.
|
||||
DBA::insert('event', $event);
|
||||
|
||||
$item_id = 0;
|
||||
|
||||
// Don't create an item for birthday events
|
||||
if ($event['type'] == 'event') {
|
||||
$event['id'] = DBA::lastInsertId();
|
||||
|
||||
$item_arr = [];
|
||||
|
@ -359,6 +363,7 @@ class Event extends BaseObject
|
|||
$item_arr['object'] .= '</object>' . "\n";
|
||||
|
||||
$item_id = Item::insert($item_arr);
|
||||
}
|
||||
|
||||
Addon::callHooks("event_created", $event['id']);
|
||||
}
|
||||
|
@ -981,4 +986,47 @@ class Event extends BaseObject
|
|||
|
||||
return $location;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Add new birthday event for this person
|
||||
*
|
||||
* @param array $contact Contact array, expects: id, uid, url, name
|
||||
* @param string $birthday Birthday of the contact
|
||||
* @return bool
|
||||
*/
|
||||
public static function createBirthday($contact, $birthday)
|
||||
{
|
||||
// Check for duplicates
|
||||
$condition = [
|
||||
'uid' => $contact['uid'],
|
||||
'cid' => $contact['id'],
|
||||
'start' => DateTimeFormat::utc($birthday),
|
||||
'type' => 'birthday'
|
||||
];
|
||||
if (DBA::exists('event', $condition)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Add new birthday event for this person
|
||||
*
|
||||
* summary is just a readable placeholder in case the event is shared
|
||||
* with others. We will replace it during presentation to our $importer
|
||||
* to contain a sparkle link and perhaps a photo.
|
||||
*/
|
||||
$values = [
|
||||
'uid' => $contact['uid'],
|
||||
'cid' => $contact['id'],
|
||||
'start' => DateTimeFormat::utc($birthday),
|
||||
'finish' => DateTimeFormat::utc($birthday . ' + 1 day '),
|
||||
'summary' => L10n::t('%s\'s birthday', $contact['name']),
|
||||
'desc' => L10n::t('Happy Birthday %s', ' [url=' . $contact['url'] . ']' . $contact['name'] . '[/url]'),
|
||||
'type' => 'birthday',
|
||||
'adjust' => 0
|
||||
];
|
||||
|
||||
self::store($values);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1509,43 +1509,6 @@ class DFRN
|
|||
return intval($res->status);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Add new birthday event for this person
|
||||
*
|
||||
* @param array $contact Contact record
|
||||
* @param string $birthday Birthday of the contact
|
||||
* @return void
|
||||
* @todo Add array type-hint for $contact
|
||||
*/
|
||||
private static function birthdayEvent($contact, $birthday)
|
||||
{
|
||||
// Check for duplicates
|
||||
$condition = ['uid' => $contact['uid'], 'cid' => $contact['id'],
|
||||
'start' => DateTimeFormat::utc($birthday), 'type' => 'birthday'];
|
||||
if (DBA::exists('event', $condition)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Logger::log('updating birthday: ' . $birthday . ' for contact ' . $contact['id']);
|
||||
|
||||
$bdtext = L10n::t('%s\'s birthday', $contact['name']);
|
||||
$bdtext2 = L10n::t('Happy Birthday %s', ' [url=' . $contact['url'] . ']' . $contact['name'] . '[/url]');
|
||||
|
||||
$r = q(
|
||||
"INSERT INTO `event` (`uid`,`cid`,`created`,`edited`,`start`,`finish`,`summary`,`desc`,`type`)
|
||||
VALUES ( %d, %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s') ",
|
||||
intval($contact['uid']),
|
||||
intval($contact['id']),
|
||||
DBA::escape(DateTimeFormat::utcNow()),
|
||||
DBA::escape(DateTimeFormat::utcNow()),
|
||||
DBA::escape(DateTimeFormat::utc($birthday)),
|
||||
DBA::escape(DateTimeFormat::utc($birthday . ' + 1 day ')),
|
||||
DBA::escape($bdtext),
|
||||
DBA::escape($bdtext2),
|
||||
DBA::escape('birthday')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Fetch the author data from head or entry items
|
||||
*
|
||||
|
@ -1736,7 +1699,7 @@ class DFRN
|
|||
$contact = array_merge($contact_old, $poco);
|
||||
|
||||
if ($contact_old["bdyear"] != $contact["bdyear"]) {
|
||||
self::birthdayEvent($contact, $birthday);
|
||||
Event::createBirthday($contact, $birthday);
|
||||
}
|
||||
|
||||
// Get all field names
|
||||
|
|
Loading…
Reference in New Issue
Block a user