แต่ทั้งนี้ในบางกรณีจำเป้นต้องเข้าไปปรับแก้ไขผลของการแจ้งเตือน เช่นไม่อยากให้มีการแสดง รายชื่อบางรายชื่อก็จะมีขั้นตอน ปรับแก้ไขดังนี้
โดยมีขั้นตอนดังนี้
1.ปรับเพิ่มข้อมูลโคดใน ไฟล์ services.yml
โค้ด: เลือกทั้งหมด
notification.type.bookmark:
class: mindphp\m_anonymous\notification\bookmark //ตำแหน้งที่จัดเก็บไฟล์ ที่เป็นส่วนการจัดการกการแจ้งเตือน bookmark
shared: false
parent: notification.type.base
calls:
- [set_user_loader, ['@user_loader']]
- [set_config, ['@config']]
tags:
- { name: notification.type }
โค้ด: เลือกทั้งหมด
<?php
namespace mindphp\m_anonymous\notification;
class bookmark extends \phpbb\notification\type\post {
public function get_type() {
return 'notification.type.bookmark';
}
protected $language_key = 'NOTIFICATION_BOOKMARK';
static public $notification_option = array(
'lang' => 'NOTIFICATION_TYPE_BOOKMARK',
'group' => 'NOTIFICATION_GROUP_POSTING',
);
public function is_available() {
return $this->config['allow_bookmarks'];
}
public function get_title() {
global $auth, $db, $request, $table_prefix;
$moderator_permissions_forum = $auth->acl_get('m_');
$responders = $this->get_data('responders');
$usernames = array();
if (!is_array($responders)) {
$responders = array();
}
$responders = array_merge(array(array(
'poster_id' => $this->get_data('poster_id'),
'username' => $this->get_data('post_username'),
)), $responders);
$user_a = array();
$responders_cnt = count($responders);
$responders = $this->trim_user_ary($responders);
$trimmed_responders_cnt = $responders_cnt - count($responders);
// ส่วนของการจัดการรายชื่อจะเป็นนี้ที่ทำหน้าที่ปรับเพิ่ท หรือ แก้ไขรายชื่อที่จะไปนำแสดงสำหรับยส่วนของการแจ้งเตือน
foreach ($responders as $responder) {
if ($responder['poster_id'] != $user_a[$responder['poster_id']] || $responder['username'] == '') {
if ($responder['username']) {
if ($moderator_permissions_forum == 1) {
if ($responder['username'] != 'ANONYMOUS') {
$sql = 'SELECT username FROM ' . $table_prefix . 'm_anonymous' . ' a LEFT JOIN `phpbb_users` u ON (a.user_id = u.user_id) WHERE `anonymous_code` = "' . $responder['username'] . '" ORDER BY `u`.`username` DESC LIMIT 1 ';
$result = $db->sql_query($sql);
$row = $db->sql_fetchrow($result);
if ($row['username'] != null) {
$usernames[] = $responder['username'] . '(' . $row['username'] . ')';
} else {
$usernames[] = $responder['username'];
}
} else {
$usernames[] = $responder['username'];
}
} else {
$usernames[] = $responder['username'];
}
} else {
if ($responder['poster_id'] != $user_a[$responder['poster_id']] && $responder['username'] == '') {
$usernames[] = $this->user_loader->get_username($responder['poster_id'], 'no_profile');
}
}
}
$user_a[$responder['poster_id']] = $responder['poster_id'];
if ($responder['poster_id'] == 1) {
preg_match('/A0(.*)0(.*)/', $responder['username'], $output_array);
$user_a[$responder['poster_id']] = str_replace($output_array['2'], '', $responder['username']);
}
}
// สิ้นสุดส่วนของการจัดการรายชื่อจะเป็นนี้ที่ทำหน้าที่ปรับเพิ่ท หรือ แก้ไขรายชื่อที่จะไปนำแสดงสำหรับยส่วนของการแจ้งเตือน
if ($trimmed_responders_cnt > 20) {
$usernames[] = $this->language->lang('NOTIFICATION_MANY_OTHERS');
} else if ($trimmed_responders_cnt) {
$usernames[] = $this->language->lang('NOTIFICATION_X_OTHERS', $trimmed_responders_cnt);
}
return $this->language->lang(
$this->language_key, phpbb_generate_string_list($usernames, $this->user), $responders_cnt
);
}
public function find_users_for_notification($post, $options = array()) {
$options = array_merge(array(
'ignore_users' => array(),
), $options);
$users = array();
$sql = 'SELECT user_id
FROM ' . BOOKMARKS_TABLE . '
WHERE ' . $this->db->sql_in_set('topic_id', $post['topic_id']) . '
AND user_id <> ' . (int) $post['poster_id'];
$result = $this->db->sql_query($sql);
while ($row = $this->db->sql_fetchrow($result)) {
$users[] = (int) $row['user_id'];
}
$this->db->sql_freeresult($result);
$notify_users = $this->get_authorised_recipients($users, $post['forum_id'], $options, true);
if (empty($notify_users)) {
return array();
}
// Try to find the users who already have been notified about replies and have not read the topic since and just update their notifications
$notified_users = $this->notification_manager->get_notified_users($this->get_type(), array(
'item_parent_id' => static::get_item_parent_id($post),
'read' => 0,
));
foreach ($notified_users as $user => $notification_data) {
unset($notify_users[$user]);
/** @var bookmark $notification */
$notification = $this->notification_manager->get_item_type_class($this->get_type(), $notification_data);
$update_responders = $notification->add_responders($post);
if (!empty($update_responders)) {
$this->notification_manager->update_notification($notification, $update_responders, array(
'item_parent_id' => self::get_item_parent_id($post),
'read' => 0,
'user_id' => $user,
));
}
}
return $notify_users;
}
public function add_responders($post) {
global $request;
if ($this->get_data('poster_id') == $post['poster_id']) {
return array();
}
$responders = $this->get_data('responders');
$responders = ($responders === null) ? array() : $responders;
if (count($responders) > 25) {
return array();
}
foreach ($responders as $responder) {
// Do not add them as a responder multiple times
}
$anonymous_code = 'A' . str_pad($post['poster_id'], $this->config['m_anonymous_post_name'] - 1, "0", STR_PAD_BOTH);
global $auth;
$moderator_permissions_forum = $auth->acl_get('m_');
if ($request->variable('mod_anonymous', 0, true)) {
$responders[] = array(
'poster_id' => $post['poster_id'],
'username' => (($post['poster_id'] == ANONYMOUS) ? $post['post_username'] : $anonymous_code),
);
} else {
$responders[] = array(
'poster_id' => $post['poster_id'],
'username' => (($post['poster_id'] == ANONYMOUS) ? $post['post_username'] : ''),
);
}
$this->set_data('responders', $responders);
$serialized_data = serialize($this->get_data(false));
if (utf8_strlen($serialized_data) >= 4000) {
return array();
}
$data_array = array_merge(array(
'post_time' => $post['post_time'],
'post_id' => $post['post_id'],
'topic_id' => $post['topic_id']
), $this->get_data(false));
return $data_array;
}
public function get_email_template() {
return 'bookmark';
}
}
ตัวอย่างก่อนใช้งาน
ตัวอย่างหลังใช้งาน
บทความที่เกี่ยวข้อง
การสร้าง Extension ใน phpbb
การสร้าง controller สำหรับ phpbb
Event listenner - เขียน Extension บน phpBB 3.1
วิธีการจัดทำการระบบแจ้้งเตือนใน phpbb