mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-13 06:48:52 +00:00
[ticket/11445] Move get user's notification code into its own method
PHPBB3-11445
This commit is contained in:
parent
ac74dc876c
commit
f5415619eb
1 changed files with 33 additions and 18 deletions
|
@ -574,6 +574,34 @@ class manager
|
||||||
return $subscription_methods;
|
return $subscription_methods;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get user's notification data
|
||||||
|
*
|
||||||
|
* @param int $user_id The user_id of the user to get the notifications for
|
||||||
|
*
|
||||||
|
* @return array User's notification
|
||||||
|
*/
|
||||||
|
protected function get_user_notifications($user_id)
|
||||||
|
{
|
||||||
|
$sql = 'SELECT method, notify, item_type
|
||||||
|
FROM ' . $this->user_notifications_table . '
|
||||||
|
WHERE user_id = ' . (int) $user_id . '
|
||||||
|
AND item_id = 0';
|
||||||
|
|
||||||
|
$result = $this->db->sql_query($sql);
|
||||||
|
$user_notifications = array();
|
||||||
|
|
||||||
|
while ($row = $this->db->sql_fetchrow($result))
|
||||||
|
{
|
||||||
|
$user_notifications[$row['item_type']][] = $row;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->db->sql_freeresult($result);
|
||||||
|
|
||||||
|
return $user_notifications;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get global subscriptions (item_id = 0)
|
* Get global subscriptions (item_id = 0)
|
||||||
*
|
*
|
||||||
|
@ -587,36 +615,23 @@ class manager
|
||||||
|
|
||||||
$subscriptions = array();
|
$subscriptions = array();
|
||||||
|
|
||||||
$sql = 'SELECT method, notify, item_type
|
$user_notifications = $this->get_user_notifications($user_id);
|
||||||
FROM ' . $this->user_notifications_table . '
|
|
||||||
WHERE user_id = ' . (int) $user_id . '
|
|
||||||
AND item_id = 0';
|
|
||||||
|
|
||||||
$result = $this->db->sql_query($sql);
|
|
||||||
$rows = array();
|
|
||||||
|
|
||||||
while ($row = $this->db->sql_fetchrow($result))
|
|
||||||
{
|
|
||||||
$rows[$row['item_type']][] = $row;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->db->sql_freeresult($result);
|
|
||||||
|
|
||||||
foreach ($this->get_subscription_types() as $types)
|
foreach ($this->get_subscription_types() as $types)
|
||||||
{
|
{
|
||||||
foreach ($types as $id => $type)
|
foreach ($types as $id => $type)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (empty($rows[$id]))
|
if (empty($user_notifications[$id]))
|
||||||
{
|
{
|
||||||
// No rows at all, default to ''
|
// No rows at all, default to ''
|
||||||
$subscriptions[$id] = array('');
|
$subscriptions[$id] = array('');
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
foreach ($rows[$id] as $row)
|
foreach ($user_notifications[$id] as $user_notification)
|
||||||
{
|
{
|
||||||
if (!$row['notify'])
|
if (!$user_notification['notify'])
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -626,7 +641,7 @@ class manager
|
||||||
$subscriptions[$id] = array();
|
$subscriptions[$id] = array();
|
||||||
}
|
}
|
||||||
|
|
||||||
$subscriptions[$id][] = $row['method'];
|
$subscriptions[$id][] = $user_notification['method'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue