Use arguments from PHP events?

Discussion forum for Extension Writers regarding Extension Development.
Post Reply
aster59
Registered User
Posts: 82
Joined: Sun Jun 26, 2016 1:47 pm
Location: United States

Use arguments from PHP events?

Post by aster59 »

I read around and I couldn't find anything on this.

I am using this event in my listener file that I am writing for an extension:

https://wiki.phpbb.com/Event_List#core. ... osts_after

It has arguments found in table:

delete_notifications_types, forum_ids, post_ids, poster_ids, topic_ids, where_ids, where_type

I want to access the poster ID.

I tried an $event parameter then tried to access it via an

Code: Select all

$event['poster_ids']
. Didn't really think that would work.

What is the proper way? I am on 3.2.0

Thanks all, looking forward to making useful extensions!
User avatar
RMcGirr83
Former Team Member
Posts: 21488
Joined: Wed Jun 22, 2005 4:33 pm
Location: Your display
Name: Rich McGirr

Re: Use arguments from PHP events?

Post by RMcGirr83 »

For the ACP?
Appreciate the extensions/mods/support then buy me a beerImage
Former Modifications/Extensions Team Member | My extensions | github | All requests for support via PM will be ignored
aster59
Registered User
Posts: 82
Joined: Sun Jun 26, 2016 1:47 pm
Location: United States

Re: Use arguments from PHP events?

Post by aster59 »

RMcGirr83 wrote:
Sun Feb 19, 2017 11:47 pm
For the ACP?
I am sorry I didn't specify, no in the listener file I am writing for an extension. I use the above event inside of the getSubscribedEvents() method attached to a function called delete_post, and that function needs to have access to the arguments I see from the event like Poster_ids.
User avatar
david63
Registered User
Posts: 18303
Joined: Thu Dec 19, 2002 8:08 am
Location: Lancashire, UK
Contact:

Re: Use arguments from PHP events?

Post by david63 »

aster59 wrote:
Sun Feb 19, 2017 9:34 pm
I want to access the poster ID.
Which poster ID?

The event that you are using is returning an array of poster IDs.

Perhaps explaining, with code, what it is that you are trying to do would make it easier for us to help.
David
Remember: You only know what you know and - you don't know what you don't know!
My CDB Contributions | How to install an extension
I will not be accepting translations for any of my extensions in Github - please post any translations in the appropriate topic.
No support requests via PM or email as they will be ignored
User avatar
RMcGirr83
Former Team Member
Posts: 21488
Joined: Wed Jun 22, 2005 4:33 pm
Location: Your display
Name: Rich McGirr

Re: Use arguments from PHP events?

Post by RMcGirr83 »

aster59 wrote:
Mon Feb 20, 2017 2:29 am
RMcGirr83 wrote:
Sun Feb 19, 2017 11:47 pm
For the ACP?
I am sorry I didn't specify, no in the listener file I am writing for an extension. I use the above event inside of the getSubscribedEvents() method attached to a function called delete_post, and that function needs to have access to the arguments I see from the event like Poster_ids.
You aren't understanding me. That event is used within the ACP of the forum. You aren't being clear if you are talking about you writing an extension for the ACP side of the forum or for the non-ACP side of the forum.
Appreciate the extensions/mods/support then buy me a beerImage
Former Modifications/Extensions Team Member | My extensions | github | All requests for support via PM will be ignored
aster59
Registered User
Posts: 82
Joined: Sun Jun 26, 2016 1:47 pm
Location: United States

Re: Use arguments from PHP events?

Post by aster59 »

RMcGirr83 wrote:
Mon Feb 20, 2017 10:51 am
aster59 wrote:
Mon Feb 20, 2017 2:29 am
RMcGirr83 wrote:
Sun Feb 19, 2017 11:47 pm
For the ACP?
I am sorry I didn't specify, no in the listener file I am writing for an extension. I use the above event inside of the getSubscribedEvents() method attached to a function called delete_post, and that function needs to have access to the arguments I see from the event like Poster_ids.
You aren't understanding me. That event is used within the ACP of the forum. You aren't being clear if you are talking about you writing an extension for the ACP side of the forum or for the non-ACP side of the forum.
I don't plan on doing anything with the ACP for now. Here is a screenshot of the listener file's event and then corresponding function:

Where $poster_IDs is where I need to grab the information for query.

david63 mentioned an array. How could I get the poster ID of the person whose post is being deleted, and not necessarily the moderator or admin deleting it?
Attachments
Screen Shot 2017-02-20 at 06.30.34.png
Screen Shot 2017-02-20 at 06.30.23.png
User avatar
RMcGirr83
Former Team Member
Posts: 21488
Joined: Wed Jun 22, 2005 4:33 pm
Location: Your display
Name: Rich McGirr

Re: Use arguments from PHP events?

Post by RMcGirr83 »

If you aren't planning on doing anything in the ACP then that isn't the event you want and I don't see where an event is given for when deleting posts outside of the ACP.

To be a bit more specific, when a user deletes a post it is deleted by calling the function phpbb_handle_post_delete which is defined within includes/functions_posting.php. If you look at that function you will see there aren't any events to attach to. So you would have to open a ticket and request an event within the tracker and then fork the code on github and make a PR against core to get your event added.
Appreciate the extensions/mods/support then buy me a beerImage
Former Modifications/Extensions Team Member | My extensions | github | All requests for support via PM will be ignored
aster59
Registered User
Posts: 82
Joined: Sun Jun 26, 2016 1:47 pm
Location: United States

Re: Use arguments from PHP events?

Post by aster59 »

It looks like I got it to work outside as long as the hard delete is the only thing users/admins/mods are allowed to do. No soft delete event, I'd prefer just hard deletes anyway. The $event variable I had can actually access the poster ids then in a DOUBLE array, which I guess would make sense since there is not one poster ID in poster_ids.

Code: Select all

$event['poster_ids'][0]
worked in giving the first poster id within the array, or author, all others are other posters, which is equal to their user ID to modify those fields!
User avatar
DavidIQ
Customisations Team Leader
Customisations Team Leader
Posts: 17316
Joined: Thu Jan 06, 2005 1:30 pm
Location: Fishkill, NY
Name: David Colón
Contact:

Re: Use arguments from PHP events?

Post by DavidIQ »

As was mentioned, poster_ids is an array of IDs so of course if you wanted to access a specific item in the array you would have to reference it as you did.
Apply to become a Jr. Extension Validator
My extensions | In need of phpBB services? | Was I helpful today?
No unsolicited PMs unless you're planning on asking for paid help.
User avatar
Steve
Registered User
Posts: 1092
Joined: Tue Apr 07, 2009 7:48 pm
Location: UK ,up north!!
Name: Steven Clark
Contact:

Re: Use arguments from PHP events?

Post by Steve »

Why not just access the poster_ids in this way?

Code: Select all

	public function my_function_delete_posts($event)
	{
		$poster_ids = $event['poster_ids'];
		foreach ($poster_ids as $poster_id)
		{
			//$poster_id do something with
		}		
	}
aster59
Registered User
Posts: 82
Joined: Sun Jun 26, 2016 1:47 pm
Location: United States

Re: Use arguments from PHP events?

Post by aster59 »

Steve wrote:
Mon Feb 20, 2017 6:29 pm
Why not just access the poster_ids in this way?

Code: Select all

	public function my_function_delete_posts($event)
	{
		$poster_ids = $event['poster_ids'];
		foreach ($poster_ids as $poster_id)
		{
			//$poster_id do something with
		}		
	}
Yeah, that is how I ended up structuring the loop.
User avatar
Steve
Registered User
Posts: 1092
Joined: Tue Apr 07, 2009 7:48 pm
Location: UK ,up north!!
Name: Steven Clark
Contact:

Re: Use arguments from PHP events?

Post by Steve »

aster59
Registered User
Posts: 82
Joined: Sun Jun 26, 2016 1:47 pm
Location: United States

Re: Use arguments from PHP events?

Post by aster59 »

RMcGirr83 wrote:
Mon Feb 20, 2017 11:47 am
So you would have to open a ticket and request an event within the tracker and then fork the code on github and make a PR against core to get your event added.
Just to revive this for a minute of a realization I made and for future people, I will make a request for this event. The ones they have such as https://wiki.phpbb.com/Event_List#core. ... ransaction are only for function_admins (as said above) and I think we need one for regular users deciding to delete their own posts.
Post Reply

Return to “Extension Writers Discussion”