วิธีการปรับการการแสดงการ รายชื่อของแจ้งเตือน bookmark โดย phpbb

PHP Knowledge เป็น บอร์ดรวามความรู้ php เน้นบทความ แนวทางการเขียนโปรแกรม บันทึกกันลืม เพื่อให้สมาชิกได้เขียนความรู้ที่ตัวเองมีให้สมาชิกท่านอื่นๆ ได้ เข้ามาอ่าน และ ไว้อ่านเองกันลืมด้วย

Moderator: mindphp, ผู้ดูแลกระดาน

ภาพประจำตัวสมาชิก
Ittichai_chupol
PHP VIP Members
PHP VIP Members
โพสต์: 5410
ลงทะเบียนเมื่อ: 19/09/2018 10:33 am

วิธีการปรับการการแสดงการ รายชื่อของแจ้งเตือน bookmark โดย phpbb

โพสต์ที่ยังไม่ได้อ่าน โดย Ittichai_chupol »

การใช้งานเว็บไซต์นั้นผู้ที่เข้ามาคงอยากได้รับความสะดวกต่อการใช้งานให้มากที่สุด เพื่อที่จะได้ทั้งการประหยัดด้านเวลา หรือการไม่ต้องเสี่ยงที่จะพลาดโอกาสต่างๆของสมาชิกผู้ใช้งานคนนั้นได้ ซึ่งการที่จะทำให้ผู้ใช้งานนั้นทราบถึงโอกาสเหล่านยั้นได้ในเว็บไซต์นั้นๆก็ควรที่จะมีระบบที่เป็นการแจ้งเตือน แต่โดยทั้งนี้รูปแบบการที่จะสร้างการที่จะสร้างระบบที่ใช้สำหรับการแจ้งเตือนนี้ ก็มีความแตกต่างกันต่ามแต่ผู้ที่จะพัฒนาออกมา ร่วมทั้งภาษาที่ใช้ในการพัฒนานั้นด้วย เพราะว่า php python หรือภาษาอื่นๆนั้นก็ร่วนแต่จะมีรูปแบบฟังชั่น การทำงานต่างกันไป อย่างเช่น เว็บบอร์ด phpbb ก็จะมีส่วนที่เป็นฟังชั่นสำหรับใช้งานในการแจ้งเตือนในส่วนที่เป็นมาตรฐานที่จำเป้นมาให้ตั้งตั้งแต่ติดตั้ง แต่ทั้งนี้ถ้าหากผู้ที่พัฒนาต้องการที่จะปรับเปลี่ยนข้อมูลหรือเนื้อหาในรส้วนของการแจ้งเตือนนั้น ก็สามารถที่จะใช้ Event ที่เป็นส่วนของการส่งค่าข้อมูลให้กับการแจ้งแจ้งก็ย่อมได้
แต่ทั้งนี้ในบางกรณีจำเป้นต้องเข้าไปปรับแก้ไขผลของการแจ้งเตือน เช่นไม่อยากให้มีการแสดง รายชื่อบางรายชื่อก็จะมีขั้นตอน ปรับแก้ไขดังนี้

โดยมีขั้นตอนดังนี้

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 }
2.สร้างโฟลเดอร์ ชื่อว่า notification และสร้างไฟล์ php bookmark.php

โค้ด: เลือกทั้งหมด


<?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';
    }
}

ตัวอย่างก่อนใช้งาน
PHP Knowledge-1.png
PHP Knowledge-1.png (25.56 KiB) Viewed 727 times

ตัวอย่างหลังใช้งาน

PHP Knowledge-2.png
PHP Knowledge-2.png (27.1 KiB) Viewed 727 times
บทความที่เกี่ยวข้อง

การสร้าง Extension ใน phpbb
การสร้าง controller สำหรับ phpbb
Event listenner - เขียน Extension บน phpBB 3.1
วิธีการจัดทำการระบบแจ้้งเตือนใน phpbb
ขอให้วันนี้เป็นวันที่ดี
  • Similar Topics
    ตอบกลับ
    แสดง
    โพสต์ล่าสุด

ผู้ใช้งานขณะนี้

สมาชิกกำลังดูบอร์ดนี้: ไม่มีสมาชิกใหม่ และบุคลทั่วไป 5