Ajout d'une extension
This commit is contained in:
147
ext/phpbbstudio/ass/notification/notification.php
Normal file
147
ext/phpbbstudio/ass/notification/notification.php
Normal file
@@ -0,0 +1,147 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* phpBB Studio - Advanced Shop System. An extension for the phpBB Forum Software package.
|
||||
*
|
||||
* @copyright (c) 2019, phpBB Studio, https://www.phpbbstudio.com
|
||||
* @license GNU General Public License, version 2 (GPL-2.0)
|
||||
*
|
||||
*/
|
||||
|
||||
namespace phpbbstudio\ass\notification;
|
||||
|
||||
use phpbbstudio\ass\entity\item;
|
||||
|
||||
/**
|
||||
* phpBB Studio - Advanced Shop System: Notification
|
||||
*/
|
||||
class notification
|
||||
{
|
||||
/** @var \phpbb\config\config */
|
||||
protected $config;
|
||||
|
||||
/** @var \phpbb\notification\manager */
|
||||
protected $manager;
|
||||
|
||||
/** @var \phpbbstudio\ass\operator\item */
|
||||
protected $operator_item;
|
||||
|
||||
/** @var \phpbb\user */
|
||||
protected $user;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param \phpbb\config\config $config Config object
|
||||
* @param \phpbb\notification\manager $manager Notification manager object
|
||||
* @param \phpbbstudio\ass\operator\item $operator_item Item operator object
|
||||
* @param \phpbb\user $user User object
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
public function __construct(
|
||||
\phpbb\config\config $config,
|
||||
\phpbb\notification\manager $manager,
|
||||
\phpbbstudio\ass\operator\item $operator_item,
|
||||
\phpbb\user $user
|
||||
)
|
||||
{
|
||||
$this->config = $config;
|
||||
$this->manager = $manager;
|
||||
$this->operator_item = $operator_item;
|
||||
$this->user = $user;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a "Received a gift" notification.
|
||||
*
|
||||
* @param item $item The item entity
|
||||
* @param int $user_id The user identifier
|
||||
* @param int $inventory_id The inventory identifier
|
||||
* @param int $inventory_index The inventory index identifier
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
public function gift(item $item, $user_id, $inventory_id, $inventory_index)
|
||||
{
|
||||
$this->config->increment('ass_notification_gift_id', 1);
|
||||
|
||||
$this->manager->add_notifications('phpbbstudio.ass.notification.type.gift', [
|
||||
'notification_id' => (int) $this->config['ass_notification_gift_id'],
|
||||
'inventory_id' => (int) $inventory_id,
|
||||
'inventory_index' => (int) $inventory_index,
|
||||
'category_slug' => $item->get_category_slug(),
|
||||
'item_slug' => $item->get_slug(),
|
||||
'user_id' => (int) $this->user->data['user_id'],
|
||||
'recipient_id' => (int) $user_id,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a "Low stock" notification.
|
||||
*
|
||||
* @param item $item The item entity
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
public function low_stock(item $item)
|
||||
{
|
||||
$this->config->increment('ass_notification_stock_id', 1);
|
||||
|
||||
$this->manager->add_notifications('phpbbstudio.ass.notification.type.stock', [
|
||||
'notification_id' => (int) $this->config['ass_notification_stock_id'],
|
||||
'category_slug' => $item->get_category_slug(),
|
||||
'item_slug' => $item->get_slug(),
|
||||
'item_title' => $item->get_title(),
|
||||
'item_avatar' => $this->get_avatar($item),
|
||||
'item_id' => $item->get_id(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an "avatar" (image or icon) for an item.
|
||||
*
|
||||
* @param item $item The item entity
|
||||
* @return string The item avatar
|
||||
* @access protected
|
||||
*/
|
||||
protected function get_avatar(item $item)
|
||||
{
|
||||
if ($item->get_background())
|
||||
{
|
||||
$src = $this->operator_item->get_background_path($item->get_background(), false);
|
||||
$src = generate_board_url() . '/' . $src;
|
||||
|
||||
return '<img src="' . $src . '" alt="' . $item->get_title() . '">';
|
||||
}
|
||||
else if ($item->get_icon())
|
||||
{
|
||||
return $this->get_avatar_icon($item->get_icon());
|
||||
}
|
||||
else if ($this->config['ass_no_image_icon'])
|
||||
{
|
||||
return $this->get_avatar_icon($this->config['ass_no_image_icon']);
|
||||
}
|
||||
else
|
||||
{
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an icon that can be used as item avatar.
|
||||
*
|
||||
* There is in-line style here to properly display (centered) an icon,
|
||||
* if this is not in-line, there has to be a CSS file included on all pages
|
||||
* -- as notifications can be viewed from all pages --
|
||||
* for an edge case scenario where the user has a "Low stock" notification.
|
||||
*
|
||||
* @param string $icon The icon
|
||||
* @return string The icon element
|
||||
* @access public
|
||||
*/
|
||||
protected function get_avatar_icon($icon)
|
||||
{
|
||||
return '<i class="icon ' . $icon . ' fa-fw pull-left" style="margin-right: 5px; width: 50px; height: 50px; line-height: 50px;" aria-hidden="true"></i>';
|
||||
}
|
||||
}
|
||||
229
ext/phpbbstudio/ass/notification/type/gift.php
Normal file
229
ext/phpbbstudio/ass/notification/type/gift.php
Normal file
@@ -0,0 +1,229 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* phpBB Studio - Advanced Shop System. An extension for the phpBB Forum Software package.
|
||||
*
|
||||
* @copyright (c) 2019, phpBB Studio, https://www.phpbbstudio.com
|
||||
* @license GNU General Public License, version 2 (GPL-2.0)
|
||||
*
|
||||
*/
|
||||
|
||||
namespace phpbbstudio\ass\notification\type;
|
||||
|
||||
/**
|
||||
* phpBB Studio - Advanced Shop System: Notification type "Gift"
|
||||
*/
|
||||
class gift extends \phpbb\notification\type\base
|
||||
{
|
||||
/** @var \phpbb\auth\auth */
|
||||
protected $auth;
|
||||
|
||||
/** @var \phpbbstudio\ass\helper\router */
|
||||
protected $router;
|
||||
|
||||
/** @var \phpbb\user_loader */
|
||||
protected $user_loader;
|
||||
|
||||
/**
|
||||
* Set the auth object.
|
||||
*
|
||||
* @param \phpbb\auth\auth $auth Auth object
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
public function set_auth(\phpbb\auth\auth $auth)
|
||||
{
|
||||
$this->auth = $auth;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the Advanced Shop System router object.
|
||||
*
|
||||
* @param \phpbbstudio\ass\helper\router $router ASS Router object
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
public function set_router(\phpbbstudio\ass\helper\router $router)
|
||||
{
|
||||
$this->router = $router;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the user loader object.
|
||||
*
|
||||
* @param \phpbb\user_loader $user_loader User loader object
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
public function set_user_loader(\phpbb\user_loader $user_loader)
|
||||
{
|
||||
$this->user_loader = $user_loader;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get notification type name.
|
||||
*
|
||||
* @return string The notification name as defined in services.yml
|
||||
* @access public
|
||||
*/
|
||||
public function get_type()
|
||||
{
|
||||
return 'phpbbstudio.ass.notification.type.gift';
|
||||
}
|
||||
|
||||
/**
|
||||
* Notification option data (for outputting to the user).
|
||||
*
|
||||
* @var bool|array False if the service should use it's default data
|
||||
* Array of data (including keys 'id', 'lang', and 'group')
|
||||
* @access public
|
||||
* @static
|
||||
*/
|
||||
static public $notification_option = [
|
||||
'lang' => 'ASS_NOTIFICATION_TYPE_GIFT',
|
||||
'group' => 'ASS_NOTIFICATION_GROUP',
|
||||
];
|
||||
|
||||
/**
|
||||
* Is this type available to the current user.
|
||||
* (defines whether or not it will be shown in the UCP Edit notification options)
|
||||
*
|
||||
* @return bool Whether or not this is available to the user
|
||||
* @access public
|
||||
*/
|
||||
public function is_available()
|
||||
{
|
||||
return $this->auth->acl_get('u_ass_can_receive_gift');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the id of the notification.
|
||||
*
|
||||
* @param array $data The notification type specific data
|
||||
* @return int Identifier of the notification
|
||||
* @access public
|
||||
* @static
|
||||
*/
|
||||
public static function get_item_id($data)
|
||||
{
|
||||
return $data['notification_id'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the id of the parent.
|
||||
*
|
||||
* @param array $data The type notification specific data
|
||||
* @return int Identifier of the parent
|
||||
* @access public
|
||||
* @static
|
||||
*/
|
||||
public static function get_item_parent_id($data)
|
||||
{
|
||||
return $data['inventory_id'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Find the users who want to receive notifications.
|
||||
*
|
||||
* @param array $data The type specific data
|
||||
* @param array $options Options for finding users for notification
|
||||
* ignore_users => array of users and user types that should not receive notifications from this type
|
||||
* because they've already been notified
|
||||
* e.g.: array(2 => array(''), 3 => array('', 'email'), ...)
|
||||
* @return array Array of user identifiers with their notification method(s)
|
||||
* @access public
|
||||
*/
|
||||
public function find_users_for_notification($data, $options = [])
|
||||
{
|
||||
return [
|
||||
$data['recipient_id'] => $this->notification_manager->get_default_methods(),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Users needed to query before this notification can be displayed.
|
||||
*
|
||||
* @return array Array of user identifiers to query.
|
||||
* @access public
|
||||
*/
|
||||
public function users_to_query()
|
||||
{
|
||||
return [$this->get_data('user_id')];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the user's avatar.
|
||||
*
|
||||
* @return string The HTML formatted avatar
|
||||
*/
|
||||
public function get_avatar()
|
||||
{
|
||||
return $this->user_loader->get_avatar($this->get_data('user_id'), false, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the HTML formatted title of this notification.
|
||||
*
|
||||
* @return string The HTML formatted title
|
||||
* @access public
|
||||
*/
|
||||
public function get_title()
|
||||
{
|
||||
return $this->language->lang('ASS_NOTIFICATION_GIFT', $this->user_loader->get_username($this->get_data('user_id'), 'no_profile'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the url to this item.
|
||||
*
|
||||
* @return string URL to the Inventory page
|
||||
* @access public
|
||||
*/
|
||||
public function get_url()
|
||||
{
|
||||
$index = $this->get_data('inventory_index');
|
||||
$index = $index ? $index : 1;
|
||||
|
||||
return $this->router->inventory($this->get_data('category_slug'), $this->get_data('item_slug'), $index, 'gift');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get email template.
|
||||
*
|
||||
* @return string|bool Whether or not this notification has an email option template
|
||||
* @access public
|
||||
*/
|
||||
public function get_email_template()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get email template variables.
|
||||
*
|
||||
* @return array Array of variables that can be used in the email template
|
||||
* @access public
|
||||
*/
|
||||
public function get_email_template_variables()
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Function for preparing the data for insertion in an SQL query.
|
||||
* (The service handles insertion)
|
||||
*
|
||||
* @param array $data The type specific data
|
||||
* @param array $pre_create_data Data from pre_create_insert_array()
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
public function create_insert_array($data, $pre_create_data = [])
|
||||
{
|
||||
$this->set_data('inventory_index', $data['inventory_index']);
|
||||
$this->set_data('category_slug', $data['category_slug']);
|
||||
$this->set_data('item_slug', $data['item_slug']);
|
||||
$this->set_data('user_id', $data['user_id']);
|
||||
|
||||
parent::create_insert_array($data, $pre_create_data);
|
||||
}
|
||||
}
|
||||
220
ext/phpbbstudio/ass/notification/type/stock.php
Normal file
220
ext/phpbbstudio/ass/notification/type/stock.php
Normal file
@@ -0,0 +1,220 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* phpBB Studio - Advanced Shop System. An extension for the phpBB Forum Software package.
|
||||
*
|
||||
* @copyright (c) 2019, phpBB Studio, https://www.phpbbstudio.com
|
||||
* @license GNU General Public License, version 2 (GPL-2.0)
|
||||
*
|
||||
*/
|
||||
|
||||
namespace phpbbstudio\ass\notification\type;
|
||||
|
||||
/**
|
||||
* phpBB Studio - Advanced Shop System: Notification type "Stock"
|
||||
*/
|
||||
class stock extends \phpbb\notification\type\base
|
||||
{
|
||||
/** @var \phpbb\auth\auth */
|
||||
protected $auth;
|
||||
|
||||
/** @var \phpbbstudio\ass\helper\router */
|
||||
protected $router;
|
||||
|
||||
/**
|
||||
* Set the auth object.
|
||||
*
|
||||
* @param \phpbb\auth\auth $auth Auth object
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
public function set_auth(\phpbb\auth\auth $auth)
|
||||
{
|
||||
$this->auth = $auth;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the Advanced Shop System router object.
|
||||
*
|
||||
* @param \phpbbstudio\ass\helper\router $router ASS Router object
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
public function set_router(\phpbbstudio\ass\helper\router $router)
|
||||
{
|
||||
$this->router = $router;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get notification type name.
|
||||
*
|
||||
* @return string The notification name as defined in services.yml
|
||||
* @access public
|
||||
*/
|
||||
public function get_type()
|
||||
{
|
||||
return 'phpbbstudio.ass.notification.type.stock';
|
||||
}
|
||||
|
||||
/**
|
||||
* Notification option data (for outputting to the user).
|
||||
*
|
||||
* @var bool|array False if the service should use it's default data
|
||||
* Array of data (including keys 'id', 'lang', and 'group')
|
||||
* @access public
|
||||
* @static
|
||||
*/
|
||||
static public $notification_option = [
|
||||
'lang' => 'ASS_NOTIFICATION_TYPE_STOCK',
|
||||
'group' => 'ASS_NOTIFICATION_GROUP',
|
||||
];
|
||||
|
||||
/**
|
||||
* Is this type available to the current user.
|
||||
* (defines whether or not it will be shown in the UCP Edit notification options)
|
||||
*
|
||||
* @return bool Whether or not this is available to the user
|
||||
* @access public
|
||||
*/
|
||||
public function is_available()
|
||||
{
|
||||
return $this->auth->acl_get('u_ass_can_receive_stock_notifications');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the id of the notification.
|
||||
*
|
||||
* @param array $data The notification type specific data
|
||||
* @return int Identifier of the notification
|
||||
* @access public
|
||||
* @static
|
||||
*/
|
||||
public static function get_item_id($data)
|
||||
{
|
||||
return $data['notification_id'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the id of the parent.
|
||||
*
|
||||
* @param array $data The type notification specific data
|
||||
* @return int Identifier of the parent
|
||||
* @access public
|
||||
* @static
|
||||
*/
|
||||
public static function get_item_parent_id($data)
|
||||
{
|
||||
return $data['item_id'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Find the users who want to receive notifications.
|
||||
*
|
||||
* @param array $data The type specific data
|
||||
* @param array $options Options for finding users for notification
|
||||
* ignore_users => array of users and user types that should not receive notifications from this type
|
||||
* because they've already been notified
|
||||
* e.g.: array(2 => array(''), 3 => array('', 'email'), ...)
|
||||
* @return array Array of user identifiers with their notification method(s)
|
||||
* @access public
|
||||
*/
|
||||
public function find_users_for_notification($data, $options = [])
|
||||
{
|
||||
$users = [];
|
||||
$authed = $this->auth->acl_get_list(false, 'u_ass_can_receive_stock_notifications');
|
||||
$authed = $authed[0]['u_ass_can_receive_stock_notifications'];
|
||||
|
||||
foreach ($authed as $user_id)
|
||||
{
|
||||
$users[(int) $user_id] = $this->notification_manager->get_default_methods();
|
||||
}
|
||||
|
||||
return $users;
|
||||
}
|
||||
|
||||
/**
|
||||
* Users needed to query before this notification can be displayed.
|
||||
*
|
||||
* @return array Array of user identifiers to query.
|
||||
* @access public
|
||||
*/
|
||||
public function users_to_query()
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the user's avatar.
|
||||
*
|
||||
* @return string The HTML formatted avatar
|
||||
*/
|
||||
public function get_avatar()
|
||||
{
|
||||
return $this->get_data('item_avatar');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the HTML formatted title of this notification.
|
||||
*
|
||||
* @return string The HTML formatted title
|
||||
* @access public
|
||||
*/
|
||||
public function get_title()
|
||||
{
|
||||
return $this->language->lang('ASS_NOTIFICATION_STOCK', $this->get_data('item_title'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the url to this item.
|
||||
*
|
||||
* @return string URL to the Inventory page
|
||||
* @access public
|
||||
*/
|
||||
public function get_url()
|
||||
{
|
||||
return $this->router->item($this->get_data('category_slug'), $this->get_data('item_slug'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get email template.
|
||||
*
|
||||
* @return string|bool Whether or not this notification has an email option template
|
||||
* @access public
|
||||
*/
|
||||
public function get_email_template()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get email template variables.
|
||||
*
|
||||
* @return array Array of variables that can be used in the email template
|
||||
* @access public
|
||||
*/
|
||||
public function get_email_template_variables()
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Function for preparing the data for insertion in an SQL query.
|
||||
* (The service handles insertion)
|
||||
*
|
||||
* @param array $data The type specific data
|
||||
* @param array $pre_create_data Data from pre_create_insert_array()
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
public function create_insert_array($data, $pre_create_data = [])
|
||||
{
|
||||
// notification id
|
||||
$this->set_data('category_slug', $data['category_slug']);
|
||||
$this->set_data('item_slug', $data['item_slug']);
|
||||
$this->set_data('item_title', $data['item_title']);
|
||||
$this->set_data('item_avatar', $data['item_avatar']);
|
||||
$this->set_data('item_id', $data['item_id']);
|
||||
|
||||
parent::create_insert_array($data, $pre_create_data);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user