notification system in extension

Discussion forum for Extension Writers regarding Extension Development.
User avatar
sebo
Registered User
Posts: 57
Joined: Mon Jan 22, 2024 10:28 pm

notification system in extension

Post by sebo »

hi there!
i'm creating my first extension.
my extension make the admin editing the phpbb_user table in the column user_donatore.
It works correctly but i want to send a notification to the user related of this editing.
Like:
- admin edits the column user_donatore for the user "sebo"
- user sebo has to get the notification of this editing

so:
(i'm quite new to PHP and this is my first extension, so it's quite difficult for me, but i'm trying to learn... :oops: )

i read this tutorial
https://area51.phpbb.com/docs/dev/3.3.x ... tions.html

i edited the file service.yml - '@notification_manager' to get notification into the acp_control
and

Code: Select all

   sebo.donatore.notification.type.attiva:
        class: sebo\donatore\notification\type\attiva
        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 }
i still don't unerstand what are "call" and "tag" for... :?: (i don't understand from the wiki)

after i've included in the acp_control.php

Code: Select all

/** @var \phpbb\notification\manager */
protected $notification_manager;
and the constructor

Code: Select all

public function __construct(\phpbb\notification\manager $notication_manager)
	{
		$this->notification_manager		= $notification_manager;
}
and tried to make a function.

like i said before, this function is:
- after the acp edit the db (changing the column "user_donatore" in table "phpbb_users"), it has to set a notification for the user that the column has been changed...so i've tried to start what to write...maybe something like

Code: Select all

$this->notification_manager->add_notifications('sebo.donatore.notification.type.attiva', [
            'user_id'         => 'user_id',
            'sender_id'       => 'user_admin_id',
            'message_subject' => 'notifica_subject',
        ]);
BUT before i can code this part, i've refreshed the page and appears
[phpBB Debug] PHP Warning: in file [ROOT]/ext/sebo/donatore/controller/acp_controller.php on line 67: Undefined variable $notification_manager
what do i miss?!?! :cry:
User avatar
Toxyy
Registered User
Posts: 966
Joined: Mon Oct 24, 2016 3:22 pm
Location: Namek

Re: notification system in extension

Post by Toxyy »

Whenever you're adding a variable to a php file via the service or any other yml you need to clear your cache before it is able to be used.
I am a web developer/administrator, specializing in forums. If you have work you need done or are too lazy to do, pm me!

Some of my extensions:
[3.3][BETA] Post Form Templates || [3.3][BETA] Anonymous Posts || [3.2][3.3][BETA] ACP Merge Child Forums || [3.2][BETA] Sticky Ad || [3.2][DEV] User Delete Topics || [3.3][DEV] Moderate While Searching || [3.3][RC] Short Number Twig Extension
User avatar
sebo
Registered User
Posts: 57
Joined: Mon Jan 22, 2024 10:28 pm

Re: notification system in extension

Post by sebo »

Toxyy wrote: Fri Mar 01, 2024 7:36 am Whenever you're adding a variable to a php file via the service or any other yml you need to clear your cache before it is able to be used.
i did it. that does not solve the problem :roll:
rxu
Extensions Development Team
Posts: 4018
Joined: Wed Oct 25, 2006 12:46 pm
Location: Siberia, Russian Federation

Re: notification system in extension

Post by rxu »

You have a typo in your constructor arguments list. Note
sebo wrote: Sun Feb 18, 2024 10:19 am $notication_manager
vs

sebo wrote: Sun Feb 18, 2024 10:19 am $notification_manager

Return to “Extension Writers Discussion”