load_users() public method

Load user helper
public load_users ( array $user_ids )
$user_ids array
Ejemplo n.º 1
0
    /**
     * {@inheritdoc}
     */
    public function find_users_for_notification($group, $options = array())
    {
        $options = array_merge(array('ignore_users' => array()), $options);
        $sql = 'SELECT user_id
			FROM ' . USER_GROUP_TABLE . '
			WHERE group_leader = 1
				AND group_id = ' . (int) $group['group_id'];
        $result = $this->db->sql_query($sql);
        $user_ids = array();
        while ($row = $this->db->sql_fetchrow($result)) {
            $user_ids[] = (int) $row['user_id'];
        }
        $this->db->sql_freeresult($result);
        $this->user_loader->load_users($user_ids);
        return $this->check_user_notification_options($user_ids, $options);
    }
Ejemplo n.º 2
0
Archivo: pm.php Proyecto: MrAdder/phpbb
 /**
  * Find the users who want to receive notifications
  *
  * @param array $pm Data from submit_pm
  * @param array $options Options for finding users for notification
  *
  * @return array
  */
 public function find_users_for_notification($pm, $options = array())
 {
     $options = array_merge(array('ignore_users' => array()), $options);
     if (!sizeof($pm['recipients'])) {
         return array();
     }
     unset($pm['recipients'][$pm['from_user_id']]);
     $this->user_loader->load_users(array_keys($pm['recipients']));
     return $this->check_user_notification_options(array_keys($pm['recipients']), $options);
 }
Ejemplo n.º 3
0
 /**
  * Notify using phpBB messenger
  *
  * @param int $notify_method				Notify method for messenger (e.g. NOTIFY_IM)
  * @param string $template_dir_prefix	Base directory to prepend to the email template name
  *
  * @return null
  */
 protected function notify_using_messenger($notify_method, $template_dir_prefix = '')
 {
     if (empty($this->queue)) {
         return;
     }
     // Load all users we want to notify (we need their email address)
     $user_ids = $users = array();
     foreach ($this->queue as $notification) {
         $user_ids[] = $notification->user_id;
     }
     // We do not send emails to banned users
     if (!function_exists('phpbb_get_banned_user_ids')) {
         include $this->phpbb_root_path . 'includes/functions_user.' . $this->php_ext;
     }
     $banned_users = phpbb_get_banned_user_ids($user_ids);
     // Load all the users we need
     $this->user_loader->load_users($user_ids);
     // Load the messenger
     if (!class_exists('messenger')) {
         include $this->phpbb_root_path . 'includes/functions_messenger.' . $this->php_ext;
     }
     $messenger = new \messenger();
     // Time to go through the queue and send emails
     /** @var \phpbb\notification\type\type_interface $notification */
     foreach ($this->queue as $notification) {
         if ($notification->get_email_template() === false) {
             continue;
         }
         $user = $this->user_loader->get_user($notification->user_id);
         if ($user['user_type'] == USER_IGNORE || $user['user_type'] == USER_INACTIVE && $user['user_inactive_reason'] == INACTIVE_MANUAL || in_array($notification->user_id, $banned_users)) {
             continue;
         }
         $messenger->template($notification->get_email_template(), $user['user_lang'], '', $template_dir_prefix);
         $messenger->set_addresses($user);
         $messenger->assign_vars(array_merge(array('USERNAME' => $user['username'], 'U_NOTIFICATION_SETTINGS' => generate_board_url() . '/ucp.' . $this->php_ext . '?i=ucp_notifications&mode=notification_options'), $notification->get_email_template_variables()));
         $messenger->send($notify_method);
     }
     // Save the queue in the messenger class (has to be called or these emails could be lost?)
     $messenger->save_queue();
     // We're done, empty the queue
     $this->empty_queue();
 }
Ejemplo n.º 4
0
 /**
  * Add a notification for specific users
  *
  * @param string|array $notification_type_name Type identifier or array of item types (only acceptable if the $data is identical for the specified types)
  * @param array $data Data specific for this type that will be inserted
  * @param array $notify_users User list to notify
  */
 public function add_notifications_for_users($notification_type_name, $data, $notify_users)
 {
     if (is_array($notification_type_name)) {
         foreach ($notification_type_name as $type) {
             $this->add_notifications_for_users($type, $data, $notify_users);
         }
         return;
     }
     $notification_type_id = $this->get_notification_type_id($notification_type_name);
     $item_id = $this->get_item_type_class($notification_type_name)->get_item_id($data);
     $user_ids = array();
     $notification_methods = array();
     // Never send notifications to the anonymous user!
     unset($notify_users[ANONYMOUS]);
     // Make sure not to send new notifications to users who've already been notified about this item
     // This may happen when an item was added, but now new users are able to see the item
     // We remove each user which was already notified by at least one method.
     /** @var method\method_interface $method */
     foreach ($this->get_subscription_methods_instances() as $method) {
         $notified_users = $method->get_notified_users($notification_type_id, array('item_id' => $item_id));
         foreach ($notified_users as $user => $notifications) {
             unset($notify_users[$user]);
         }
     }
     if (!sizeof($notify_users)) {
         return;
     }
     // Allow notifications to perform actions before creating the insert array (such as run a query to cache some data needed for all notifications)
     $notification = $this->get_item_type_class($notification_type_name);
     $pre_create_data = $notification->pre_create_insert_array($data, $notify_users);
     unset($notification);
     // Go through each user so we can insert a row in the DB and then notify them by their desired means
     foreach ($notify_users as $user => $methods) {
         $notification = $this->get_item_type_class($notification_type_name);
         $notification->user_id = (int) $user;
         // Generate the insert_array
         $notification->create_insert_array($data, $pre_create_data);
         // Users are needed to send notifications
         $user_ids = array_merge($user_ids, $notification->users_to_query());
         foreach ($methods as $method) {
             // setup the notification methods and add the notification to the queue
             if (!isset($notification_methods[$method])) {
                 $notification_methods[$method] = $this->get_method_class($method);
             }
             $notification_methods[$method]->add_to_queue($notification);
         }
     }
     // We need to load all of the users to send notifications
     $this->user_loader->load_users($user_ids);
     // run the queue for each method to send notifications
     foreach ($notification_methods as $method) {
         $method->notify();
     }
 }
Ejemplo n.º 5
0
	/**
	* Add a notification for specific users
	*
	* @param string|array $notification_type_name Type identifier or array of item types (only acceptable if the $data is identical for the specified types)
	* @param array $data Data specific for this type that will be inserted
	* @param array $notify_users User list to notify
	*/
	public function add_notifications_for_users($notification_type_name, $data, $notify_users)
	{
		if (is_array($notification_type_name))
		{
			foreach ($notification_type_name as $type)
			{
				$this->add_notifications_for_users($type, $data, $notify_users);
			}

			return;
		}

		$notification_type_id = $this->get_notification_type_id($notification_type_name);

		$item_id = $this->get_item_type_class($notification_type_name)->get_item_id($data);

		$user_ids = array();
		$notification_objects = $notification_methods = array();

		// Never send notifications to the anonymous user!
		unset($notify_users[ANONYMOUS]);

		// Make sure not to send new notifications to users who've already been notified about this item
		// This may happen when an item was added, but now new users are able to see the item
		$sql = 'SELECT n.user_id
			FROM ' . $this->notifications_table . ' n, ' . $this->notification_types_table . ' nt
			WHERE n.notification_type_id = ' . (int) $notification_type_id . '
				AND n.item_id = ' . (int) $item_id . '
				AND nt.notification_type_id = n.notification_type_id
				AND nt.notification_type_enabled = 1';
		$result = $this->db->sql_query($sql);
		while ($row = $this->db->sql_fetchrow($result))
		{
			unset($notify_users[$row['user_id']]);
		}
		$this->db->sql_freeresult($result);

		if (!sizeof($notify_users))
		{
			return;
		}

		// Allow notifications to perform actions before creating the insert array (such as run a query to cache some data needed for all notifications)
		$notification = $this->get_item_type_class($notification_type_name);
		$pre_create_data = $notification->pre_create_insert_array($data, $notify_users);
		unset($notification);

		$insert_buffer = new \phpbb\db\sql_insert_buffer($this->db, $this->notifications_table);

		// Go through each user so we can insert a row in the DB and then notify them by their desired means
		foreach ($notify_users as $user => $methods)
		{
			$notification = $this->get_item_type_class($notification_type_name);

			$notification->user_id = (int) $user;

			// Insert notification row using buffer.
			$insert_buffer->insert($notification->create_insert_array($data, $pre_create_data));

			// Users are needed to send notifications
			$user_ids = array_merge($user_ids, $notification->users_to_query());

			foreach ($methods as $method)
			{
				// setup the notification methods and add the notification to the queue
				if ($method) // blank means we just insert it as a notification, but do not notify them by any other means
				{
					if (!isset($notification_methods[$method]))
					{
						$notification_methods[$method] = $this->get_method_class($method);
					}

					$notification_methods[$method]->add_to_queue($notification);
				}
			}
		}

		$insert_buffer->flush();

		// We need to load all of the users to send notifications
		$this->user_loader->load_users($user_ids);

		// run the queue for each method to send notifications
		foreach ($notification_methods as $method)
		{
			$method->notify();
		}
	}
Ejemplo n.º 6
0
    /**
     * {@inheritdoc}
     */
    public function load_notifications(array $options = array())
    {
        // Merge default options
        $options = array_merge(array('notification_id' => false, 'user_id' => $this->user->data['user_id'], 'order_by' => 'notification_time', 'order_dir' => 'DESC', 'limit' => 0, 'start' => 0, 'all_unread' => false, 'count_unread' => false, 'count_total' => false), $options);
        // If all_unread, count_unread must be true
        $options['count_unread'] = $options['all_unread'] ? true : $options['count_unread'];
        // Anonymous users and bots never receive notifications
        if ($options['user_id'] == $this->user->data['user_id'] && ($this->user->data['user_id'] == ANONYMOUS || $this->user->data['user_type'] == USER_IGNORE)) {
            return array('notifications' => array(), 'unread_count' => 0, 'total_count' => 0);
        }
        $notifications = $user_ids = array();
        $load_special = array();
        $total_count = $unread_count = 0;
        if ($options['count_unread']) {
            // Get the total number of unread notifications
            $sql = 'SELECT COUNT(n.notification_id) AS unread_count
				FROM ' . $this->notifications_table . ' n, ' . $this->notification_types_table . ' nt
				WHERE n.user_id = ' . (int) $options['user_id'] . '
					AND n.notification_read = 0
					AND nt.notification_type_id = n.notification_type_id
					AND nt.notification_type_enabled = 1';
            $result = $this->db->sql_query($sql);
            $unread_count = (int) $this->db->sql_fetchfield('unread_count');
            $this->db->sql_freeresult($result);
        }
        if ($options['count_total']) {
            // Get the total number of notifications
            $sql = 'SELECT COUNT(n.notification_id) AS total_count
				FROM ' . $this->notifications_table . ' n, ' . $this->notification_types_table . ' nt
				WHERE n.user_id = ' . (int) $options['user_id'] . '
					AND nt.notification_type_id = n.notification_type_id
					AND nt.notification_type_enabled = 1';
            $result = $this->db->sql_query($sql);
            $total_count = (int) $this->db->sql_fetchfield('total_count');
            $this->db->sql_freeresult($result);
        }
        if (!$options['count_total'] || $total_count) {
            $rowset = array();
            // Get the main notifications
            $sql = 'SELECT n.*, nt.notification_type_name
				FROM ' . $this->notifications_table . ' n, ' . $this->notification_types_table . ' nt
				WHERE n.user_id = ' . (int) $options['user_id'] . ($options['notification_id'] ? is_array($options['notification_id']) ? ' AND ' . $this->db->sql_in_set('n.notification_id', $options['notification_id']) : ' AND n.notification_id = ' . (int) $options['notification_id'] : '') . '
					AND nt.notification_type_id = n.notification_type_id
					AND nt.notification_type_enabled = 1
				ORDER BY n.' . $this->db->sql_escape($options['order_by']) . ' ' . $this->db->sql_escape($options['order_dir']);
            $result = $this->db->sql_query_limit($sql, $options['limit'], $options['start']);
            while ($row = $this->db->sql_fetchrow($result)) {
                $rowset[$row['notification_id']] = $row;
            }
            $this->db->sql_freeresult($result);
            // Get all unread notifications
            if ($unread_count && $options['all_unread'] && !empty($rowset)) {
                $sql = 'SELECT n.*, nt.notification_type_name
				FROM ' . $this->notifications_table . ' n, ' . $this->notification_types_table . ' nt
					WHERE n.user_id = ' . (int) $options['user_id'] . '
						AND n.notification_read = 0
						AND ' . $this->db->sql_in_set('n.notification_id', array_keys($rowset), true) . '
						AND nt.notification_type_id = n.notification_type_id
						AND nt.notification_type_enabled = 1
					ORDER BY n.' . $this->db->sql_escape($options['order_by']) . ' ' . $this->db->sql_escape($options['order_dir']);
                $result = $this->db->sql_query_limit($sql, $options['limit'], $options['start']);
                while ($row = $this->db->sql_fetchrow($result)) {
                    $rowset[$row['notification_id']] = $row;
                }
                $this->db->sql_freeresult($result);
            }
            foreach ($rowset as $row) {
                $notification = $this->notification_manager->get_item_type_class($row['notification_type_name'], $row);
                // Array of user_ids to query all at once
                $user_ids = array_merge($user_ids, $notification->users_to_query());
                // Some notification types also require querying additional tables themselves
                if (!isset($load_special[$row['notification_type_name']])) {
                    $load_special[$row['notification_type_name']] = array();
                }
                $load_special[$row['notification_type_name']] = array_merge($load_special[$row['notification_type_name']], $notification->get_load_special());
                $notifications[$row['notification_id']] = $notification;
            }
            $this->user_loader->load_users($user_ids);
            // Allow each type to load its own special items
            foreach ($load_special as $item_type => $data) {
                $item_class = $this->notification_manager->get_item_type_class($item_type);
                $item_class->load_special($data, $notifications);
            }
        }
        return array('notifications' => $notifications, 'unread_count' => $unread_count, 'total_count' => $total_count);
    }