The notification type "mael.blocks.notification.type.videos" is missing from the file system.
This notification is for users than want to send us a vid link to show it in a custom page. So the admin can accept or reject the vid.
Right now i have this:
services.yml
Code: Select all
mael.blocks.notification.type.videos:
class: mael\blocks\notification\videos
shared: false # service MUST not be shared for this to work!
parent: notification.type.base
calls:
- [set_controller_helper, ['@controller.helper']]
tags:
- { name: notification.type }
Code: Select all
<?php
/**
*
* Notification. An extension for the phpBB Forum Software package.
*
* @copyright (c) 2017
* @license GNU General Public License, version 2 (GPL-2.0)
*
*/
namespace mael\blocks\notification;
/**
* Notificaciones Notification class.
*/
class videos extends \phpbb\notification\type\base
{
/** @var \phpbb\controller\helper */
protected $helper;
/**
* Set the controller helper
*
* @param \phpbb\controller\helper $helper
*
* @return void
*/
public function set_controller_helper(\phpbb\controller\helper $helper)
{
$this->helper = $helper;
}
/**
* Get notification type name
*
* @return string
*/
public function get_type()
{
return 'mael.blocks.notification.type.videos';
}
/**
* Language key used to output the text
*
* @var string
*/
protected $language_key = 'NOTIFICATION_ARTICLE_IN_QUEUE';
/**
* 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')
*/
public static $notification_option = array(
'lang' => 'NOTIFICATION_TYPE_DEMO',
);
/**
* Is this type available to the current user (defines whether or not it will be shown in the UCP Edit notification options)
*
* @return bool True/False whether or not this is available to the user
*/
public function is_available()
{
return true;
}
/**
* Get the id of the notification
*
* @param array $data The type specific data
*
* @return int Id of the notification
*/
public static function get_item_id($my_notification_data)
{
return $my_notification_data['topic_id'];
}
/**
* Get the id of the parent
*
* @param array $data The type specific data
*
* @return int Id of the parent
*/
public static function get_item_parent_id($my_notification_data)
{
// No parent
return 0;
}
/**
* 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
*/
public function find_users_for_notification($my_notification_data, $options = array())
{
// Return an array of users to be notified, storing the user_ids as the array keys
$users = array();
$users[2] = $this->notification_manager->get_default_methods();
return $users;
}
/**
* Users needed to query before this notification can be displayed
*
* @return array Array of user_ids
*/
public function users_to_query()
{
return array();
}
/**
* Get the HTML formatted title of this notification
*
* @return string
*/
public function get_title()
{
return 'Este es el titulo';
}
/**
* Get the url to this item
*
* @return string URL
*/
public function get_url()
{
return 'http://my-page.lt/phpBB3/viewtopic.php?f=10&t=63';
}
/**
* Get email template
*
* @return string|bool
*/
public function get_email_template()
{
return false;
}
/**
* Get email template variables
*
* @return array
*/
public function get_email_template_variables()
{
return array();
}
/**
* 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 array Array of data ready to be inserted into the database
*/
public function create_insert_array($my_notification_data, $pre_create_data = array())
{
$this->set_data('user_id', $my_notification_data['user_id']);
$this->set_data('link', $my_notification_data['link']);
$this->set_data('topic_id', $my_notification_data['topic_id']);
parent::create_insert_array($my_notification_data, $pre_create_data);
}
}
Code: Select all
$my_notification_data = array(
'user_id' => (int) $this->user->data['user_id'],
'link' => $video_link,
'topic_id' => 9, //just for this example
);
$this->notification_manager->add_notifications(array(
'mael.blocks.notification.type.videos',
), $my_notification_data);
Code: Select all
<?php
/**
*
* Board Rules extension for the phpBB Forum Software package.
*
* @copyright (c) 2013 phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0)
*
*/
namespace mael\blocks;
/**
* Extension class for custom enable/disable/purge actions
*
* NOTE TO EXTENSION DEVELOPERS:
* Normally it is not necessary to define any functions inside the ext class below.
* The ext class may contain special (un)installation commands in the methods
* enable_step(), disable_step() and purge_step(). As it is, these methods are defined
* in phpbb_extension_base, which this class extends, but you can overwrite them to
* give special instructions for those cases. Board Rules must do this because it uses
* the notifications system, which requires the methods enable_notifications(),
* disable_notifications() and purge_notifications() be run to properly manage the
* notifications created by Board Rules when enabling, disabling or deleting this
* extension.
*/
class ext extends \phpbb\extension\base
{
/**
* Check whether or not the extension can be enabled.
* The current phpBB version should meet or exceed
* the minimum version required by this extension:
*
* Requires phpBB 3.2.0 due to new faq controller route for bbcodes,
* the revised notifications system, font awesome and the text reparser.
*
* @return bool
* @access public
*/
public function is_enableable()
{
return phpbb_version_compare(PHPBB_VERSION, '3.2.0', '>=');
}
/**
* Overwrite enable_step to enable board rules notifications
* before any included migrations are installed.
*
* @param mixed $old_state State returned by previous call of this method
* @return mixed Returns false after last step, otherwise temporary state
* @access public
*/
public function enable_step($old_state)
{
switch ($old_state)
{
case '': // Empty means nothing has run yet
// Enable board rules notifications
$phpbb_notifications = $this->container->get('notification_manager');
$phpbb_notifications->enable_notifications('mael.blocks.notification.type.videos');
return 'notifications';
break;
default:
// Run parent enable step method
return parent::enable_step($old_state);
break;
}
}
/**
* Overwrite disable_step to disable board rules notifications
* before the extension is disabled.
*
* @param mixed $old_state State returned by previous call of this method
* @return mixed Returns false after last step, otherwise temporary state
* @access public
*/
public function disable_step($old_state)
{
switch ($old_state)
{
case '': // Empty means nothing has run yet
// Disable board rules notifications
$phpbb_notifications = $this->container->get('notification_manager');
$phpbb_notifications->disable_notifications('mael.blocks.notification.type.videos');
return 'notifications';
break;
default:
// Run parent disable step method
return parent::disable_step($old_state);
break;
}
}
/**
* Overwrite purge_step to purge board rules notifications before
* any included and installed migrations are reverted.
*
* @param mixed $old_state State returned by previous call of this method
* @return mixed Returns false after last step, otherwise temporary state
* @access public
*/
public function purge_step($old_state)
{
switch ($old_state)
{
case '': // Empty means nothing has run yet
// Purge board rules notifications
$phpbb_notifications = $this->container->get('notification_manager');
$phpbb_notifications->purge_notifications('mael.blocks.notification.type.videos');
return 'notifications';
break;
default:
// Run parent purge step method
return parent::purge_step($old_state);
break;
}
}
}