Support

Akeeba Ticket System

#21225 Plugin event on status change?

Posted in ‘Akeeba Ticket System for Joomla! 4 & 5’
This is a public ticket

Everybody will be able to see its contents. Do not include usernames, passwords or any other sensitive information.

Environment Information

Joomla! version
n/a
PHP version
n/a
Akeeba Ticket System version
n/a

Latest post by nicholas on Thursday, 16 October 2014 01:36 CDT

compojoom
Hey Nick,
In the past I asked you about this... but then the answer was nooooo way :)

Daniel is going crazy again, I know....

I told you that I want to make custom fields that would store the user's password for backend access, ftp access etc. Right now when I need this information, I change the status of the ticket to private and I ask the user to enter the information in the ticket. Now when I'm ready, I edit the user's ticket and change the passwords with XXX.
It works, but I often forget to delete the passwords, or the user doesn't tell me that the problem is resolved etc. So I end up with private information in those tickets & I don't want something like this to land in the hands of bad people. Another issue is as you can imagine that people don't block those accounts or leave them active for very long time.

Since you didn't wanted to make such a field in the past I decided that I'll code this myself.
I have a very easy plan for this. Build a plugin. In the plugin one would be able to enter the custom field slugs and the user group that should see the entered information in them. 

1. All users get to see the custom fields in the form.
2. Only an administrator (or a specified group) will see the stored information in the fields.
3. When a ticket is closed, I want to remove the value stored in those fields.

Point 1 is easy - ATS already works like this.
Point 2 -> I could create a template override here and remove the fields I don't want to show to the public. But do you actually have a plugin event here? I don't want to mess with template overrides that much. I saw that you do this:
$customFields = F0FModel::getTmpInstance('Tickets', 'AtsModel')
									->setId($item->ats_ticket_id)
									->loadCustomFields();


But in the ticketsModel I didn't see an event for onLoadedData or something of that sort? I see that you have some model behaviors, but I'm not sure how to use those? It seems that I can't use them in Plugins? I saw that the build query is triggering
// Call the behaviors
$this->modelDispatcher->trigger('onBeforeBuildQuery', array(&$this, &$query));

But can I use it in a plugin to actually load only the fields I want? ( I could modify the query to exclude fields with slug 'xyz')

3. I see that you are triggering OnContentChangeState in your models, but when I close the ticket using the ajax function, then nothing happens - this event is not triggered. When I change the state from public to private, then the event is triggered. Any ideas on this one?

Regards,
Daniel

nicholas
Akeeba Staff
Manager
You will need to fork the plgAtsCustomfields plugin, then unpublish the stock plugin and enable yours.

The onTicketFormRenderPerCatFields is called with a $cache parameter which contains the ticket fields in array format. If $cache['public'] == 1 you can return an empty array() to not render the extra fields. You may want to check JFactory::getUser()->id to make sure it's the owner of the ticket or support staff to render the fields normally instead of returning an empty array, otherwise you'll never get to see the extra fields.

Now, regarding removing these fields. The AtsModelTickets extends F0FModel which has built-in plugin support for events. It will load plugins in the "content" group and run the onContentBeforeSave event. The signature of this event is:
onContentBeforeSave($context, &$table, $isNewRecord)
The context for ATS tickets is "com_ats.tickets". The $table is the instance of AtsTableTicket being saved, therefore $table->status will be "C" and the ticket parameters will be in $table->params. $isNewRecord will be FALSE. $table->params contains the ticket parameters. It should be an array. If it's a string, it's JSON and you need to decode it first. This array contains the custom fields. Change them at will.

Nicholas K. Dionysopoulos

Lead Developer and Director

🇬🇷Greek: native 🇬🇧English: excellent 🇫🇷French: basic • 🕐 My time zone is Europe / Athens
Please keep in mind my timezone and cultural differences when reading my replies. Thank you!

Support Information

Working hours: We are open Monday to Friday, 9am to 7pm Cyprus timezone (EET / EEST). Support is provided by the same developers writing the software, all of which live in Europe. You can still file tickets outside of our working hours, but we cannot respond to them until we're back at the office.

Support policy: We would like to kindly inform you that when using our support you have already agreed to the Support Policy which is part of our Terms of Service. Thank you for your understanding and for helping us help you!