Page 1 of 1

Use arguments from PHP events?

Posted: Sun Feb 19, 2017 9:34 pm
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!

Re: Use arguments from PHP events?

Posted: Sun Feb 19, 2017 11:47 pm
by RMcGirr83
For the ACP?

Re: Use arguments from PHP events?

Posted: Mon Feb 20, 2017 2:29 am
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.

Re: Use arguments from PHP events?

Posted: Mon Feb 20, 2017 6:47 am
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.

Re: Use arguments from PHP events?

Posted: Mon Feb 20, 2017 10:51 am
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.

Re: Use arguments from PHP events?

Posted: Mon Feb 20, 2017 11:34 am
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?

Re: Use arguments from PHP events?

Posted: Mon Feb 20, 2017 11:47 am
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.

Re: Use arguments from PHP events?

Posted: Mon Feb 20, 2017 3:52 pm
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!

Re: Use arguments from PHP events?

Posted: Mon Feb 20, 2017 5:00 pm
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.

Re: Use arguments from PHP events?

Posted: Mon Feb 20, 2017 6:29 pm
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
		}		
	}

Re: Use arguments from PHP events?

Posted: Mon Feb 20, 2017 6:42 pm
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.

Re: Use arguments from PHP events?

Posted: Mon Feb 20, 2017 6:59 pm
by Steve

Re: Use arguments from PHP events?

Posted: Sat Feb 25, 2017 2:24 am
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.