mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-28 06:08:52 +00:00
[ticket/11103] Starting work on combining notifications
Just for posts currently and not yet outputted. PHPBB3-11103
This commit is contained in:
parent
6ca2256f77
commit
bafb5b0eca
3 changed files with 65 additions and 1 deletions
|
@ -660,6 +660,12 @@ class phpbb_notification_manager
|
|||
*/
|
||||
public function get_item_type_class($item_type, $data = array())
|
||||
{
|
||||
if (!strpos($item_type, 'notification_type_'))
|
||||
{
|
||||
$item_class = $this->get_item_type_class_name($item_type);
|
||||
$item_type = $item_class;
|
||||
}
|
||||
|
||||
$item = new $item_type($this, $this->db, $this->cache, $this->template, $this->extension_manager, $this->user, $this->auth, $this->config, $this->phpbb_root_path, $this->php_ext);
|
||||
|
||||
$item->set_initial_data($data);
|
||||
|
|
|
@ -104,7 +104,7 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i
|
|||
*/
|
||||
protected function get_data($name)
|
||||
{
|
||||
return (isset($this->data['data'][$name])) ? $this->data['data'][$name] : null;
|
||||
return ($name === false) ? $this->data['data'] : ((isset($this->data['data'][$name])) ? $this->data['data'][$name] : null);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -132,6 +132,28 @@ class phpbb_notification_type_post extends phpbb_notification_type_base
|
|||
}
|
||||
$this->db->sql_freeresult($result);
|
||||
|
||||
// Try to find the users who already have been notified about replies and have not read the topic since and just update their notifications
|
||||
$update_notifications = array();
|
||||
$sql = 'SELECT *
|
||||
FROM ' . NOTIFICATIONS_TABLE . "
|
||||
WHERE item_type = '" . self::get_item_type() . "'
|
||||
AND item_parent_id = " . (int) self::get_item_parent_id($post) . '
|
||||
AND unread = 1';
|
||||
$result = $this->db->sql_query($sql);
|
||||
while ($row = $this->db->sql_fetchrow($result))
|
||||
{
|
||||
// Do not create a new notification
|
||||
unset($notify_users[$row['user_id']]);
|
||||
|
||||
$notification = $this->notification_manager->get_item_type_class(self::get_item_type(), $row);
|
||||
$sql = 'UPDATE ' . NOTIFICATIONS_TABLE . '
|
||||
SET ' . $this->db->sql_build_array('UPDATE', $notification->add_responders($post)) . '
|
||||
WHERE notification_id = ' . $row['notification_id'];
|
||||
echo $sql;
|
||||
$this->db->sql_query($sql);
|
||||
}
|
||||
$this->db->sql_freeresult($result);
|
||||
|
||||
return $notify_users;
|
||||
}
|
||||
|
||||
|
@ -234,4 +256,40 @@ class phpbb_notification_type_post extends phpbb_notification_type_base
|
|||
|
||||
return parent::create_insert_array($post);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add responders to the notification
|
||||
*
|
||||
* @param mixed $post
|
||||
*/
|
||||
public function add_responders($post)
|
||||
{
|
||||
// Do not add them as a responder if they were the original poster that created the notification
|
||||
if ($this->get_data('poster_id') == $post['poster_id'])
|
||||
{
|
||||
return array('data' => serialize($this->get_data(false)));
|
||||
}
|
||||
|
||||
$responders = $this->get_data('responders');
|
||||
|
||||
$responders = ($responders === null) ? array() : $responders;
|
||||
|
||||
foreach ($responders as $responder)
|
||||
{
|
||||
// Do not add them as a responder multiple times
|
||||
if ($responder['poster_id'] == $post['poster_id'])
|
||||
{
|
||||
return array('data' => serialize($this->get_data(false)));
|
||||
}
|
||||
}
|
||||
|
||||
$responders[] = array(
|
||||
'poster_id' => $post['poster_id'],
|
||||
'username' => (($post['poster_id'] == ANONYMOUS) ? $post['post_username'] : ''),
|
||||
);
|
||||
|
||||
$this->set_data('responders', $responders);
|
||||
|
||||
return array('data' => serialize($this->get_data(false)));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue