[ticket/11103] Fix some various issues, better comments

PHPBB3-11103
This commit is contained in:
Nathan Guse 2013-01-15 12:10:07 -06:00
parent 51e0f002ee
commit 07282a30ae
8 changed files with 190 additions and 48 deletions

View file

@ -25,8 +25,11 @@ services:
- @config
- %core.root_path%
- %core.php_ext%
- %tables.notification_types%
- %tables.notifications%
- %tables.user_notifications%
calls:
- [set_notification_manager, [@notification_manager]]
tags:
- { name: notification.type }
@ -42,8 +45,11 @@ services:
- @config
- %core.root_path%
- %core.php_ext%
- %tables.notification_types%
- %tables.notifications%
- %tables.user_notifications%
calls:
- [set_notification_manager, [@notification_manager]]
tags:
- { name: notification.type }
@ -59,8 +65,11 @@ services:
- @config
- %core.root_path%
- %core.php_ext%
- %tables.notification_types%
- %tables.notifications%
- %tables.user_notifications%
calls:
- [set_notification_manager, [@notification_manager]]
tags:
- { name: notification.type }
@ -76,8 +85,11 @@ services:
- @config
- %core.root_path%
- %core.php_ext%
- %tables.notification_types%
- %tables.notifications%
- %tables.user_notifications%
calls:
- [set_notification_manager, [@notification_manager]]
tags:
- { name: notification.type }
@ -93,8 +105,11 @@ services:
- @config
- %core.root_path%
- %core.php_ext%
- %tables.notification_types%
- %tables.notifications%
- %tables.user_notifications%
calls:
- [set_notification_manager, [@notification_manager]]
tags:
- { name: notification.type }
@ -110,8 +125,11 @@ services:
- @config
- %core.root_path%
- %core.php_ext%
- %tables.notification_types%
- %tables.notifications%
- %tables.user_notifications%
calls:
- [set_notification_manager, [@notification_manager]]
tags:
- { name: notification.type }
@ -127,8 +145,11 @@ services:
- @config
- %core.root_path%
- %core.php_ext%
- %tables.notification_types%
- %tables.notifications%
- %tables.user_notifications%
calls:
- [set_notification_manager, [@notification_manager]]
tags:
- { name: notification.type }
@ -144,8 +165,11 @@ services:
- @config
- %core.root_path%
- %core.php_ext%
- %tables.notification_types%
- %tables.notifications%
- %tables.user_notifications%
calls:
- [set_notification_manager, [@notification_manager]]
tags:
- { name: notification.type }
@ -161,8 +185,11 @@ services:
- @config
- %core.root_path%
- %core.php_ext%
- %tables.notification_types%
- %tables.notifications%
- %tables.user_notifications%
calls:
- [set_notification_manager, [@notification_manager]]
tags:
- { name: notification.type }
@ -178,8 +205,11 @@ services:
- @config
- %core.root_path%
- %core.php_ext%
- %tables.notification_types%
- %tables.notifications%
- %tables.user_notifications%
calls:
- [set_notification_manager, [@notification_manager]]
tags:
- { name: notification.type }
@ -195,8 +225,11 @@ services:
- @config
- %core.root_path%
- %core.php_ext%
- %tables.notification_types%
- %tables.notifications%
- %tables.user_notifications%
calls:
- [set_notification_manager, [@notification_manager]]
tags:
- { name: notification.type }
@ -212,8 +245,11 @@ services:
- @config
- %core.root_path%
- %core.php_ext%
- %tables.notification_types%
- %tables.notifications%
- %tables.user_notifications%
calls:
- [set_notification_manager, [@notification_manager]]
tags:
- { name: notification.type }
@ -229,8 +265,11 @@ services:
- @config
- %core.root_path%
- %core.php_ext%
- %tables.notification_types%
- %tables.notifications%
- %tables.user_notifications%
calls:
- [set_notification_manager, [@notification_manager]]
tags:
- { name: notification.type }
@ -246,8 +285,11 @@ services:
- @config
- %core.root_path%
- %core.php_ext%
- %tables.notification_types%
- %tables.notifications%
- %tables.user_notifications%
calls:
- [set_notification_manager, [@notification_manager]]
tags:
- { name: notification.type }
@ -263,8 +305,11 @@ services:
- @config
- %core.root_path%
- %core.php_ext%
- %tables.notification_types%
- %tables.notifications%
- %tables.user_notifications%
calls:
- [set_notification_manager, [@notification_manager]]
tags:
- { name: notification.type }
@ -280,6 +325,8 @@ services:
- @config
- %core.root_path%
- %core.php_ext%
calls:
- [set_notification_manager, [@notification_manager]]
tags:
- { name: notification.method }
@ -295,5 +342,7 @@ services:
- @config
- %core.root_path%
- %core.php_ext%
calls:
- [set_notification_manager, [@notification_manager]]
tags:
- { name: notification.method }

View file

@ -22,38 +22,54 @@ if (!defined('IN_PHPBB'))
class phpbb_notification_manager
{
/** @var array */
protected $notification_types = null;
protected $notification_types;
/** @var array */
protected $notification_methods = null;
protected $notification_methods;
/** @var ContainerBuilder */
protected $phpbb_container = null;
protected $phpbb_container;
/** @var phpbb_user_loader */
protected $user_loader = null;
protected $user_loader;
/** @var phpbb_db_driver */
protected $db = null;
protected $db;
/** @var phpbb_user */
protected $user = null;
protected $user;
/** @var string */
protected $phpbb_root_path = null;
protected $phpbb_root_path;
/** @var string */
protected $php_ext = null;
protected $php_ext;
/** @var string */
protected $notification_types_table = null;
protected $notification_types_table;
/** @var string */
protected $notifications_table = null;
protected $notifications_table;
/** @var string */
protected $user_notifications_table = null;
protected $user_notifications_table;
/**
* Notification Constructor
*
* @param array $notification_types
* @param array $notification_methods
* @param ContainerBuilder $phpbb_container
* @param phpbb_user_loader $user_loader
* @param phpbb_db_driver $db
* @param phpbb_user $user
* @param string $phpbb_root_path
* @param string $php_ext
* @param string $notification_types_table
* @param string $notifications_table
* @param string $user_notifications_table
* @return phpbb_notification_manager
*/
public function __construct($notification_types, $notification_methods, $phpbb_container, phpbb_user_loader $user_loader, phpbb_db_driver $db, $user, $phpbb_root_path, $php_ext, $notification_types_table, $notifications_table, $user_notifications_table)
{
$this->notification_types = $notification_types;
@ -78,7 +94,7 @@ class phpbb_notification_manager
* @param array $options Optional options to control what notifications are loaded
* notification_id Notification id to load (or array of notification ids)
* user_id User id to load notifications for (Default: $user->data['user_id'])
* order_by Order by (Default: time)
* order_by Order by (Default: notification_time)
* order_dir Order direction (Default: DESC)
* limit Number of notifications to load (Default: 5)
* start Notifications offset (Default: 0)

View file

@ -22,37 +22,37 @@ if (!defined('IN_PHPBB'))
abstract class phpbb_notification_method_base implements phpbb_notification_method_interface
{
/** @var phpbb_notification_manager */
protected $notification_manager = null;
protected $notification_manager;
/** @var phpbb_user_loader */
protected $user_loader = null;
protected $user_loader;
/** @var phpbb_db_driver */
protected $db = null;
protected $db;
/** @var phpbb_cache_service */
protected $cache = null;
protected $cache;
/** @var phpbb_template */
protected $template = null;
protected $template;
/** @var phpbb_extension_manager */
protected $extension_manager = null;
protected $extension_manager;
/** @var phpbb_user */
protected $user = null;
protected $user;
/** @var phpbb_auth */
protected $auth = null;
protected $auth;
/** @var phpbb_config */
protected $config = null;
protected $config;
/** @var string */
protected $phpbb_root_path = null;
protected $phpbb_root_path;
/** @var string */
protected $php_ext = null;
protected $php_ext;
/**
* Queue of messages to be sent
@ -61,6 +61,19 @@ abstract class phpbb_notification_method_base implements phpbb_notification_meth
*/
protected $queue = array();
/**
* Notification Method Base Constructor
*
* @param phpbb_user_loader $user_loader
* @param phpbb_db_driver $db
* @param phpbb_cache_driver_interface $cache
* @param mixed $user
* @param phpbb_auth $auth
* @param phpbb_config $config
* @param mixed $phpbb_root_path
* @param mixed $php_ext
* @return phpbb_notification_method_base
*/
public function __construct(phpbb_user_loader $user_loader, phpbb_db_driver $db, phpbb_cache_driver_interface $cache, $user, phpbb_auth $auth, phpbb_config $config, $phpbb_root_path, $php_ext)
{
$this->user_loader = $user_loader;
@ -73,6 +86,11 @@ abstract class phpbb_notification_method_base implements phpbb_notification_meth
$this->php_ext = $php_ext;
}
/**
* Set notification manager (required)
*
* @param phpbb_notification_manager $notification_manager
*/
public function set_notification_manager(phpbb_notification_manager $notification_manager)
{
$this->notification_manager = $notification_manager;

View file

@ -22,40 +22,43 @@ if (!defined('IN_PHPBB'))
abstract class phpbb_notification_type_base implements phpbb_notification_type_interface
{
/** @var phpbb_notification_manager */
protected $notification_manager = null;
protected $notification_manager;
/** @var phpbb_user_loader */
protected $user_loader = null;
protected $user_loader;
/** @var phpbb_db_driver */
protected $db = null;
protected $db;
/** @var phpbb_cache_service */
protected $cache = null;
protected $cache;
/** @var phpbb_template */
protected $template = null;
protected $template;
/** @var phpbb_user */
protected $user = null;
protected $user;
/** @var phpbb_auth */
protected $auth = null;
protected $auth;
/** @var phpbb_config */
protected $config = null;
protected $config;
/** @var string */
protected $phpbb_root_path = null;
protected $phpbb_root_path;
/** @var string */
protected $php_ext = null;
protected $php_ext;
/** @var string */
protected $notifications_table = null;
protected $notification_types_table;
/** @var string */
protected $user_notifications_table = null;
protected $notifications_table;
/** @var string */
protected $user_notifications_table;
/**
* Notification option data (for outputting to the user)
@ -80,7 +83,23 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i
*/
private $data = array();
public function __construct(phpbb_user_loader $user_loader, phpbb_db_driver $db, phpbb_cache_driver_interface $cache, $user, phpbb_auth $auth, phpbb_config $config, $phpbb_root_path, $php_ext, $notifications_table, $user_notifications_table)
/**
* Notification Type Base Constructor
*
* @param phpbb_user_loader $user_loader
* @param phpbb_db_driver $db
* @param phpbb_cache_driver_interface $cache
* @param phpbb_user $user
* @param phpbb_auth $auth
* @param phpbb_config $config
* @param string $phpbb_root_path
* @param string $php_ext
* @param string $notification_types_table
* @param string $notifications_table
* @param string $user_notifications_table
* @return phpbb_notification_type_base
*/
public function __construct(phpbb_user_loader $user_loader, phpbb_db_driver $db, phpbb_cache_driver_interface $cache, $user, phpbb_auth $auth, phpbb_config $config, $phpbb_root_path, $php_ext, $notification_types_table, $notifications_table, $user_notifications_table)
{
$this->user_loader = $user_loader;
$this->db = $db;
@ -92,10 +111,16 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i
$this->phpbb_root_path = $phpbb_root_path;
$this->php_ext = $php_ext;
$this->notification_types_table = $notification_types_table;
$this->notifications_table = $notifications_table;
$this->user_notifications_table = $user_notifications_table;
}
/**
* Set notification manager (required)
*
* @param phpbb_notification_manager $notification_manager
*/
public function set_notification_manager(phpbb_notification_manager $notification_manager)
{
$this->notification_manager = $notification_manager;
@ -113,16 +138,38 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i
$this->data['notification_data'] = (isset($this->data['notification_data'])) ? unserialize($this->data['notification_data']) : array();
}
/**
* Magic method to get data from this notification
*
* @param mixed $name
* @return mixed
*/
public function __get($name)
{
return (!isset($this->data[$name])) ? null : $this->data[$name];
}
/**
* Magic method to set data on this notification
*
* @param mixed $name
* @return mixed
*/
public function __set($name, $value)
{
$this->data[$name] = $value;
}
/**
* Magic method to get a string of this notification
*
* Primarily for testing
*
* @param string $name
* @return mixed
*/
public function __toString()
{
return (!empty($this->data)) ? var_export($this->data, true) : $this->get_type();
@ -132,7 +179,6 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i
* Get special data (only important for the classes that extend this)
*
* @param string $name Name of the variable to get
*
* @return mixed
*/
protected function get_data($name)
@ -157,7 +203,6 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i
*
* @param array $type_data Data unique to this notification type
* @param array $pre_create_data Data from pre_create_insert_array()
*
* @return array Array of data ready to be inserted into the database
*/
public function create_insert_array($type_data, $pre_create_data = array())
@ -186,7 +231,6 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i
* (The service handles insertion)
*
* @param array $type_data Data unique to this notification type
*
* @return array Array of data ready to be updated in the database
*/
public function create_update_array($type_data)
@ -208,7 +252,7 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i
* 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
* @return string|null If $return is False, nothing will be returned, else the sql code to update this item
*/
public function mark_read($return = false)
{
@ -219,7 +263,7 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i
* 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
* @return string|null If $return is False, nothing will be returned, else the sql code to update this item
*/
public function mark_unread($return = false)
{
@ -228,6 +272,8 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i
/**
* Prepare to output the notification to the template
*
* @return array Template variables
*/
public function prepare_for_display()
{
@ -274,6 +320,8 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i
/**
* Get the user's avatar (fall back)
*
* @return string
*/
public function get_avatar()
{
@ -282,6 +330,8 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i
/**
* Get the special items to load (fall back)
*
* @return array
*/
public function get_load_special()
{
@ -298,6 +348,8 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i
/**
* Is available (fall back)
*
* @return bool
*/
public function is_available()
{
@ -306,6 +358,8 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i
/**
* Pre create insert array function (fall back)
*
* @return array
*/
public function pre_create_insert_array($type_data, $notify_users)
{
@ -398,7 +452,7 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i
*
* @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
* @return string|null If $return is False, nothing will be returned, else the sql code to update this item
*/
protected function mark($unread = true, $return = false)
{

View file

@ -101,6 +101,10 @@ if (!defined('NOTIFICATION_TYPES_TABLE'))
{
define('NOTIFICATION_TYPES_TABLE', $table_prefix . 'notification_types');
}
if (!defined('NOTIFICATIONS_TYPES_TABLE'))
{
define('NOTIFICATIONS_TYPES_TABLE', $table_prefix . 'notifications_types');
}
if (!defined('NOTIFICATIONS_TABLE'))
{
define('NOTIFICATIONS_TABLE', $table_prefix . 'notifications');

View file

@ -44,7 +44,7 @@ class phpbb_mock_notifications_notification_manager extends phpbb_notification_m
{
$item_type = 'phpbb_notification_type_' . $item_type;
$item = new $item_type($this->user_loader, $this->db, $this->cache, $this->user, $this->auth, $this->config, $this->phpbb_root_path, $this->php_ext, $this->notifications_table, $this->user_notifications_table);
$item = new $item_type($this->user_loader, $this->db, $this->cache, $this->user, $this->auth, $this->config, $this->phpbb_root_path, $this->php_ext, $this->notification_types_table, $this->notifications_table, $this->user_notifications_table);
$item->set_notification_manager($this);
@ -60,7 +60,7 @@ class phpbb_mock_notifications_notification_manager extends phpbb_notification_m
{
$method_name = 'phpbb_notification_method_' . $method_name;
$method = new $method_name($this->user_loader, $this->db, $this->cache, $this->user, $this->auth, $this->config, $this->phpbb_root_path, $this->php_ext, $this->notifications_table, $this->user_notifications_table);
$method = new $method_name($this->user_loader, $this->db, $this->cache, $this->user, $this->auth, $this->config, $this->phpbb_root_path, $this->php_ext, $this->notification_types_table, $this->notifications_table, $this->user_notifications_table);
$method->set_notification_manager($this);

View file

@ -39,7 +39,7 @@ class phpbb_notification_type_test extends phpbb_notification_type_base
public function create_insert_array($post, $pre_create_data = array())
{
$this->time = $post['post_time'];
$this->notification_time = $post['post_time'];
return parent::create_insert_array($post, $pre_create_data);
}
@ -51,7 +51,7 @@ class phpbb_notification_type_test extends phpbb_notification_type_base
// Unset data unique to each row
unset(
$data['notification_id'],
$data['unread'],
$data['notification_read'],
$data['user_id']
);

View file

@ -6,7 +6,7 @@
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
//calls: [ [set_notification_manager, [@notification_manager]] ]
class phpbb_notification_test extends phpbb_database_test_case
{
protected $notifications, $db, $container, $user, $config, $auth, $cache;
@ -52,6 +52,7 @@ class phpbb_notification_test extends phpbb_database_test_case
$this->user,
$phpbb_root_path,
$phpEx,
'phpbb_notification_types',
'phpbb_notifications',
'phpbb_user_notifications'
);
@ -91,7 +92,7 @@ class phpbb_notification_test extends phpbb_database_test_case
{
global $phpbb_root_path, $phpEx;
return new $type($this->user_loader, $this->db, $this->cache, $this->user, $this->auth, $this->config, $phpbb_root_path, $phpEx, 'phpbb_notifications', 'phpbb_user_notifications');
return new $type($this->user_loader, $this->db, $this->cache, $this->user, $this->auth, $this->config, $phpbb_root_path, $phpEx, 'phpbb_notification_types', 'phpbb_notifications', 'phpbb_user_notifications');
}
public function test_get_subscription_types()