Code: Select all
$phpbb_notifications = $phpbb_container->get('notification_manager');
$phpbb_notifications->add_notifications('campaign', array(
'log_id' => $db->sql_nextid(),
'log_type' => 2,
'log_site_id' => $sit,
'log_start' => $startday,
'log_end' => $endday
));
Code: Select all
public static function get_item_id($post)
{
return (int) $post['post_id'];
}
$post
variable to the notification class?$post
whatever you want. Have a look at this example function in a controller and this example function in a notification file. In these, I used $notification_data
as the array.$this->get_data('example');
and how does it differ from using the above? Do they have completely different purposes?Code: Select all
public function get_avatar()
{
return $this->user_loader->get_avatar($this->get_data('poster_id'));
}
Code: Select all
$phpbb_notifications = $phpbb_container->get('notification_manager');
$mc_id = $submission_data['submission_id'];
$user_id = $submission_data['user_id'];
// all of these fields work
$notification_data = array(
'badge_subject' => 'Your recent FRQ has been graded.',
'graded_user_id' => $user->data['user_id'],
'mc_submission_id' => $mc_id,
'user_id' => $user_id
);
if($earn == true){
$phpbb_notifications->add_notifications('badge_earn', $notification_data);
}
Code: Select all
<?php
/**
*
* This file is part of the phpBB Forum Software package.
*
* @copyright (c) phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0)
*
* For full copyright and license information, please see
* the docs/CREDITS.txt file.
*
*/
namespace dgkim\calcmerit\notification;
/**
* Merit badge notifications class
* This class handles notifications for merit badges
*/
class badge_earn extends \phpbb\notification\type\base
{
/**
* Get notification type name
*
* @return string
*/
public function get_type()
{
return 'badge_earn';
}
protected $language_key = 'NOTIFICATION_BADGE_EARN';
/**
* 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(
'id' => 'badge_earn',
'lang' => 'NOTIFICATION_TYPE_BADGE_EARN',
'group' => 'NOTIFICATION_GROUP_MISCELLANEOUS'
);
/**
* Is available
*/
public function is_available()
{
return true;
}
/**
* Get the id of the item
*
* @param array $submission The data from the submission
*/
public static function get_item_id($submission)
{
return (int) $submission['mc_submission_id'];
}
/**
* Get the id of the parent
*
* @param array $submission The data from the submission
*/
public static function get_item_parent_id($submission)
{
// No parent
return 0;
}
/**
* Find the users who want to receive notifications
*
* @param array $submission The data from the submission
*
* @return array
*/
public function find_users_for_notification($submission, $options = array())
{
$user_array = array(
$submission['user_id'] => array('')
);
return $user_array;
}
/**
* Get the user's avatar
*/
public function get_avatar()
{
return $this->user_loader->get_avatar($this->get_data('graded_user_id'));
}
/**
* Get the HTML formatted title of this notification
*
* @return string
*/
public function get_title()
{
return $this->user->lang('NOTIFICATION_BADGE_EARN');
}
/**
* Get the HTML formatted reference of the notification
*
* @return string
*/
public function get_reference()
{
return $this->user->lang(
'NOTIFICATION_REFERENCE',
$this->get_data('badge_subject')
);
}
/**
* 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();
}
/**
* Get the url to this item
*
* @return string URL
*/
public function get_url()
{
return append_sid('../merit.' . $this->php_ext, "?&mode=progress&p={$this->item_id}");
}
/**
* Users needed to query before this notification can be displayed
*
* @return array Array of user_ids
*/
public function users_to_query()
{
return array();
}
/**
* Function for preparing the data for insertion in an SQL query
* (The service handles insertion)
*
* @param array $submission Data from grading
* @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($submission, $pre_create_data = array())
{
$this->set_data('badge_subject', $submission['badge_subject']);
$this->set_data('graded_user_id', $submission['graded_user_id']);
$this->set_data('mc_submission_id', $submission['mc_submission_id']);
$this->set_data('user_id', $submission['user_id']);
return parent::create_insert_array($submission, $pre_create_data);
$this->notification_time = $submission['notification_time'] = time();
return $submission;
}
}
Code: Select all
namespace dgkim\calcmerit\notification;
Code: Select all
namespace phpbb\notification\type;
Code: Select all
public static function get_item_id($submission)
{
return (int) $submission['mc_submission_id'];
}
$submission
with $notification_data
.Code: Select all
public static function get_item_parent_id($submission)
{
// No parent
return 0;
}
Code: Select all
public function find_users_for_notification($submission, $options = array())
{
$user_array = array(
$submission['user_id'] => array('')
);
return $user_array;
}
Code: Select all
public function create_insert_array($submission, $pre_create_data = array())
{
$this->set_data('badge_subject', $submission['badge_subject']);
$this->set_data('graded_user_id', $submission['graded_user_id']);
$this->set_data('mc_submission_id', $submission['mc_submission_id']);
$this->set_data('user_id', $submission['user_id']);
return parent::create_insert_array($submission, $pre_create_data);
$this->notification_time = $submission['notification_time'] = time();
return $submission;
}
return parent::create_insert_array($submission, $pre_create_data);
to $notification_data = parent::create_insert_array($notification_data, $pre_create_data);
.Code: Select all
<?php
/**
*
* This file is part of the phpBB Forum Software package.
*
* @copyright (c) phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0)
*
* For full copyright and license information, please see
* the docs/CREDITS.txt file.
*
*/
namespace phpbb\notification\type;
/**
* Merit badge notifications class
* This class handles notifications for merit badges
*/
class badge_earn extends \phpbb\notification\type\base
{
/**
* Get notification type name
*
* @return string
*/
public function get_type()
{
return 'badge_earn';
}
protected $language_key = 'NOTIFICATION_BADGE_EARN';
/**
* 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(
'id' => 'badge_earn',
'lang' => 'NOTIFICATION_TYPE_BADGE_EARN',
'group' => 'NOTIFICATION_GROUP_MISCELLANEOUS'
);
/**
* Is available
*/
public function is_available()
{
return true;
}
/**
* Get the id of the item
*
* @param array $notification_data The data from the submission
*/
public static function get_item_id($notification_data)
{
return (int) $notification_data['mc_submission_id'];
}
/**
* Get the id of the parent
*
* @param array $notification_data The data from the submission
*/
public static function get_item_parent_id($notification_data)
{
// No parent
return 0;
}
/**
* Find the users who want to receive notifications
*
* @param array $notification_data The data from the submission
*
* @return array
*/
public function find_users_for_notification($notification_data, $options = array())
{
$user_array = array(
$notification_data['user_id'] => array('')
);
return $user_array;
}
/**
* Get the user's avatar
*/
public function get_avatar()
{
return $this->user_loader->get_avatar($this->get_data('graded_user_id'));
}
/**
* Get the HTML formatted title of this notification
*
* @return string
*/
public function get_title()
{
return $this->user->lang('NOTIFICATION_BADGE_EARN');
}
/**
* Get the HTML formatted reference of the notification
*
* @return string
*/
public function get_reference()
{
return $this->user->lang(
'NOTIFICATION_REFERENCE',
$this->get_data('badge_subject')
);
}
/**
* 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();
}
/**
* Get the url to this item
*
* @return string URL
*/
public function get_url()
{
return append_sid('../merit.' . $this->php_ext, "?&mode=progress&id={$this->item_id}");
}
/**
* Users needed to query before this notification can be displayed
*
* @return array Array of user_ids
*/
public function users_to_query()
{
return array();
}
/**
* Function for preparing the data for insertion in an SQL query
* (The service handles insertion)
*
* @param array $notification_data Data from grading
* @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($notification_data, $pre_create_data = array())
{
$this->set_data('badge_subject', $notification_data['badge_subject']);
$this->set_data('graded_user_id', $notification_data['graded_user_id']);
$this->set_data('mc_submission_id', $notification_data['mc_submission_id']);
$this->set_data('user_id', $notification_data['user_id']);
$this->notification_time = $notification_data['notification_time'] = time();
return parent::create_insert_array($notification_data, $pre_create_data);
}
}
Code: Select all
notification.type.badge_earn:
class: phpbb\notification\type\badge_earn
scope: prototype # scope MUST be prototype for this to work!
arguments:
- @user_loader
- @dbal.conn
- @cache.driver
- @user
- @auth
- @config
- %core.root_path%
- %core.php_ext%
- %tables.notification_types%
- %tables.notifications%
- %tables.user_notifications%
tags:
- { name: notification.type }