I seeme to be having a problem with the sequencing of PHP editing events, which I will describe here:
I have a database of trouble tickets which have a status field, indicating whether a ticket is "unseen", "in progress", "closed", etc. Right now, when a technician opens an "unseen" ticket, he is supposed to set its status to be "in progress". The goal is to update the status automatically when the ticket is edited, rather than requiring the technician to do this. In the case of other prior values of the status field, nothing should be done automatically.
Perhaps I'm misunderstanding the PHP Events, or their sequencing.
I'm trying to use a postGet event handler to obtain the prior value of the status field. I intend to then test this prior value of the status field and set the value of the status field, if necessary, in a preEdit event handler. This did not work, so I inserted some debugging statements. These revealed that the preEdit event occurs before the postGet event, which I did not expect, and which cannot work.
Have I misunderstood what the postGet event? Have I misunderstood the sequence of events? Is there some other way I should be going about this?
Here are the relevant event handlers from my Editor code:
->on('postGet',function($editor,$data,$id) {
global $priorStatus;
error_log('t.t.p: pG.id= ' . $id);
if (isset($data['status'])) {
error_log('t.t.p: priorStatus= ' . $data['status']);
$priorStatus = $data['status']; // Fetch status at time of edit
}
} )
->on('preEdit', function($editor,$id,$values) {
global $priorStatus;
error_log('t.t.p: pE.id= ' . $id . ', priorStatus= ' . $priorStatus);
if (isset($values['status']) and $values['status'] == 'closed') {
$editor->field('priority')->setValue(NULL);
}
if ($priorStatus == 'unseen' or $priorStatus == 'urgent') {
$editor->field('status')->setValue('in queue');
}
} )
Thanks in advance,
Tom