/** * Central function to add a personal notification to the user. This could be * anything that needs to catch the attention of the user. The notification * will be displayed in realtime to the user and he/she can get to the url. * @param array|string $user_ids : array of user_ids or a single md5-user_id * @param string $url : URL of the point of interest of the notification * @param string $text : a displayed text that describes the notification * @param null|string $html_id : id in the html-document. If user reaches * this html-element the notification will be marked as read, so the user * does not need to handle the information twice. Optional. Default: null * @param string $avatar : URL of an image for the notification. Best size: 40px x 40px * @return boolean : true on success */ public static function add($user_ids, $url, $text, $html_id = null, $avatar = null) { if (!is_array($user_ids)) { $user_ids = array($user_ids); } if (!count($user_ids)) { return false; } $notification = new PersonalNotifications(); $notification['html_id'] = $html_id; $notification['url'] = $url; $notification['text'] = $text; $notification['avatar'] = $avatar; $notification->store(); $query = "INSERT INTO personal_notifications_user (user_id, personal_notification_id, seen)\n VALUES (:user_id, :id, '0')"; $insert_statement = DBManager::get()->prepare($query); $insert_statement->bindValue(':id', $notification->id); foreach ($user_ids as $user_id) { self::expireCache($user_id); if (self::isActivated($user_id)) { $insert_statement->bindValue(':user_id', $user_id); $insert_statement->execute(); } } return true; }