diff options
| author | Nathan Guse <nathaniel.guse@gmail.com> | 2012-09-12 22:29:48 -0500 | 
|---|---|---|
| committer | Nathan Guse <nathaniel.guse@gmail.com> | 2012-09-12 22:29:48 -0500 | 
| commit | 3d1549d43f42631c7be8d90a1f215db239baac92 (patch) | |
| tree | 3338c08b4db3dece9adf72788fc2caf5ce652264 | |
| parent | e14595621259edb093a8bb984a95747ede2041ff (diff) | |
| download | forums-3d1549d43f42631c7be8d90a1f215db239baac92.tar forums-3d1549d43f42631c7be8d90a1f215db239baac92.tar.gz forums-3d1549d43f42631c7be8d90a1f215db239baac92.tar.bz2 forums-3d1549d43f42631c7be8d90a1f215db239baac92.tar.xz forums-3d1549d43f42631c7be8d90a1f215db239baac92.zip  | |
[ticket/11103] Add ability for notification types to load special data
For consistency, links to posts do not include topic_id. As is done in
viewtopic, do not include the topic_id when linking to a post
PHPBB3-11103
| -rw-r--r-- | phpBB/includes/notifications/service.php | 17 | ||||
| -rw-r--r-- | phpBB/includes/notifications/type/base.php | 70 | ||||
| -rw-r--r-- | phpBB/includes/notifications/type/interface.php | 8 | ||||
| -rw-r--r-- | phpBB/includes/notifications/type/post.php | 13 | 
4 files changed, 105 insertions, 3 deletions
diff --git a/phpBB/includes/notifications/service.php b/phpBB/includes/notifications/service.php index e697374b0a..b6255309c7 100644 --- a/phpBB/includes/notifications/service.php +++ b/phpBB/includes/notifications/service.php @@ -65,6 +65,7 @@ class phpbb_notifications_service  		), $options);  		$notifications = $user_ids = array(); +		$load_special = array();  		$sql = 'SELECT *  			FROM ' . NOTIFICATIONS_TABLE . ' @@ -78,14 +79,30 @@ class phpbb_notifications_service  			$notification = new $item_type_class_name($this->phpbb_container, $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['item_type']])) +			{ +				$load_special[$row['item_type']] = array(); +			} +			$load_special[$row['item_type']] = array_merge($load_special[$row['item_type']], $notification->get_load_special()); +  			$notifications[] = $notification;  		}  		$this->db->sql_freeresult($result);  		$this->load_users($user_ids); +		// Allow each type to load it's own special items +		foreach ($load_special as $item_type => $data) +		{ +			$item_type_class_name = $this->get_item_type_class_name($item_type, true); + +			$item_type_class_name::load_special($this->phpbb_container, $data, $notifications); +		} +  		return $notifications;  	} diff --git a/phpBB/includes/notifications/type/base.php b/phpBB/includes/notifications/type/base.php index 859ffb5116..47db2c4aa7 100644 --- a/phpBB/includes/notifications/type/base.php +++ b/phpBB/includes/notifications/type/base.php @@ -124,6 +124,55 @@ abstract class phpbb_notifications_type_base implements phpbb_notifications_type  	}  	/** +	* Mark this item read +	* +	* @param bool $return True to return a string containing the SQL code to update this item, False to execute it (Default: False) +	* @return string +	*/ +	public function mark_read($return = true) +	{ +		return $this->mark(false, $return); +	} + +	/** +	* Mark this item unread +	* +	* @param bool $return True to return a string containing the SQL code to update this item, False to execute it (Default: False) +	* @return string +	*/ +	public function mark_unread($return = true) +	{ +		return $this->mark(true, $return); +	} + +	/** +	* Mark this item read/unread +	* +	* @param bool $unread Unread (True/False) (Default: False) +	* @param bool $return True to return a string containing the SQL code to update this item, False to execute it (Default: False) +	* @return string +	*/ +	protected function mark($unread = true, $return = false) +	{ +		$where = array( +			'item_type = ' . $this->db->sql_escape($this->item_type), +			'item_id = ' . (int) $this->item_id, +			'user_id = ' . (int) $this->user_id, +		); +		$where = implode(' AND ' . $where); + +		if ($return) +		{ +			return $where; +		} + +		$sql = 'UPDATE ' . NOTIFICATIONS_TABLE . ' +			SET unread = ' . (bool) $unread . ' +			WHERE ' . $where; +		$this->db->sql_query($sql); +	} + +	/**  	* Function for preparing the data for insertion in an SQL query  	* (The service handles insertion)  	* @@ -206,6 +255,11 @@ abstract class phpbb_notifications_type_base implements phpbb_notifications_type  	{  		$user = $this->service->get_user($user_id); +		if (!function_exists('get_user_avatar')) +		{ +			include($this->phpbb_root_path . 'includes/functions_display.' . $this->php_ext); +		} +  		return get_user_avatar($user['user_avatar'], $user['user_avatar_type'], $user['user_avatar_width'], $user['user_avatar_height'], $user['username'], false, 'notifications-avatar');  	} @@ -236,4 +290,20 @@ abstract class phpbb_notifications_type_base implements phpbb_notifications_type  	{  		return '';  	} + +	/** +	* Get the special items to load (fall-back) +	*/ +	public function get_load_special() +	{ +		return array(); +	} + +	/** +	* Load the special items (fall-back) +	*/ +	public static function load_special(ContainerBuilder $phpbb_container, $data, $notifications) +	{ +		return; +	}  } diff --git a/phpBB/includes/notifications/type/interface.php b/phpBB/includes/notifications/type/interface.php index c165815835..c1c0eb0b0c 100644 --- a/phpBB/includes/notifications/type/interface.php +++ b/phpBB/includes/notifications/type/interface.php @@ -37,5 +37,13 @@ interface phpbb_notifications_type_interface  	public function get_unsubscribe_url($method); +	public function mark_read($return); + +	public function mark_unread($return); +  	public function create_insert_array($type_data); + +	public function get_load_special(); + +	public static function load_special(ContainerBuilder $phpbb_container, $data, $notifications);  } diff --git a/phpBB/includes/notifications/type/post.php b/phpBB/includes/notifications/type/post.php index b951b79fa6..23358599a1 100644 --- a/phpBB/includes/notifications/type/post.php +++ b/phpBB/includes/notifications/type/post.php @@ -60,12 +60,19 @@ class phpbb_notifications_type_post extends phpbb_notifications_type_base  		$db = $phpbb_container->get('dbal.conn'); +		/* todo +		* find what type of notification they'd like to receive +		* make sure not to send duplicate notifications +		*/  		$sql = 'SELECT user_id  			FROM ' . TOPICS_WATCH_TABLE . '  			WHERE topic_id = ' . (int) $post['topic_id'] . '  				AND notify_status = ' . NOTIFY_YES;  		$result = $db->sql_query($sql); -		$users = $db->sql_fetchrowset($result); +		while ($row = $db->sql_fetchrow($result)) +		{ +			$users[$row['user_id']] = array(''); +		}  		$db->sql_freeresult($result);  		if (empty($users)) @@ -155,7 +162,7 @@ class phpbb_notifications_type_post extends phpbb_notifications_type_base  	*/  	public function get_url()  	{ -		return append_sid($this->phpbb_root_path . 'viewtopic.' . $this->php_ext, "t={$this->get_data('topic_id')}&p={$this->item_id}#p{$this->item_id}"); +		return append_sid($this->phpbb_root_path . 'viewtopic.' . $this->php_ext, "p={$this->item_id}#p{$this->item_id}");  	}  	/** @@ -165,7 +172,7 @@ class phpbb_notifications_type_post extends phpbb_notifications_type_base  	*/  	public function get_full_url()  	{ -		return generate_board_url() . "/viewtopic.{$this->php_ext}?t={$this->get_data('topic_id')}&p={$this->item_id}#p{$this->item_id}"; +		return generate_board_url() . "/viewtopic.{$this->php_ext}?p={$this->item_id}#p{$this->item_id}";  	}  	/**  | 
