*
*/
+ // Check for duplicates
+ $s = q("SELECT `id` FROM `event` WHERE `uid` = %d AND `cid` = %d AND `start` = '%s' AND `type` = '%s' LIMIT 1",
+ intval($rr['uid']),
+ intval($rr['id']),
+ dbesc(datetime_convert('UTC','UTC', $nextbd)),
+ dbesc('birthday'));
+
+ if (dbm::is_result($s)) {
+ continue;
+ }
+
$bdtext = sprintf( t('%s\'s birthday'), $rr['name']);
$bdtext2 = sprintf( t('Happy Birthday %s'), ' [url=' . $rr['url'] . ']' . $rr['name'] . '[/url]') ;
*/
private function birthday_event($contact, $birthday) {
+ // Check for duplicates
+ $r = q("SELECT `id` FROM `event` WHERE `uid` = %d AND `cid` = %d AND `start` = '%s' AND `type` = '%s' LIMIT 1",
+ intval($contact["uid"]),
+ intval($contact["id"]),
+ dbesc(datetime_convert("UTC","UTC", $birthday)),
+ dbesc("birthday"));
+
+ if (dbm::is_result($r)) {
+ return;
+ }
+
logger("updating birthday: ".$birthday." for contact ".$contact["id"]);
$bdtext = sprintf(t("%s\'s birthday"), $contact["name"]);
$bdtext2 = sprintf(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"]),
return $i18n;
}
+/**
+ * @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
*
intval($event_params["event_id"])
);
- if (dbm::is_result($r))
- return $r;
-
+ if (dbm::is_result($r)) {
+ return event_remove_duplicates($r);
+ }
}
/**
dbesc($event_params["adjust_finish"])
);
- if (dbm::is_result($r))
- return $r;
+ if (dbm::is_result($r)) {
+ return event_remove_duplicates($r);
+ }
}
/**
* @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 = '';