New Idea, Editor calls an Editor. seeking best-practices advice
New Idea, Editor calls an Editor. seeking best-practices advice
I have lots of tables. Often when you update one table, you need to update another (or even the same, different field).
Here is an example of such an "automation"...
if DTEditor changed Housekeeping to Clean, also set Overview to Available (but only if it was previously Not Ready):
//Now see if we need to adjust any other status
// Check if RoomStatus_Housekeeping was updated
$Editor->on('process', function ($action, $id, $data, $response)
{if ($action === Editor::ACTION_EDIT && isset($data['RoomStatus_Housekeeping']))
{ $hid = $data['Hotel_ID'];
$grid = $data['GuestRoom_ID'];
$stat = $data['RoomStatus_Housekeeping'];
$stid = $id;
// Update Overview status based on Housekeeping status
if ($stat == 'Clean')
{$sql = "UPDATE Hotel_GuestRoom_Status
SET RoomStatus_Overview='Available'
WHERE Hotel_ID=:hotel
AND RoomStatus_ID!=:stid
AND GuestRoom_ID=:room
AND RoomStatus_Overview='Not Ready'
AND RoomStatus_Maintenance IN ('No Issues', 'None', 'NONE')
;";
}
else
Now I want to do the following:
If a line-item price is updated, update charge total
if a charge is updated, update roomstay total
if a roomstay is updated, update booking total
Therefore... if a line-item is updated, it will cascade and update the charge, roomstay, and booking.
QUESTION: Rather than having a change to the line-item update 3 tables, my idea is to have it call a different DTEditor php to edit the Charge... and it will call a different DTEditor php to update the RoomStay, which will call the Booking. Is this possible / advisable? ...or do you think I should just update my 3 tables, 2 tables, 1 table in each editor?
If it is a good idea, I wouldn't mind being spoon fed how to have an editor call another php and pass it variables (along with what variables to pass to the 2nd editor to get it to think it was a standard datatable edit and process my update).
Would I have to / want to use the PHP output buffer to have the php call another php?
Thanks for any input on this idea.
This question has an accepted answers - jump to answer
Answers
PS: Happy to take advice on the code-snippet I provided as well... I'm sure there is probably an easier way I could be updating a different field of the same table using your DB connection instead of executing my own SQL.
EDIT: Only problem is I immediately update a different table right after that, so it I already need my own SQL for that, it is no big deal to do it the way I am... but, if I could chain a bunch of editors together for automations, I would not need my own SQL at all.
Yes it is possible. You just need to craft the data that is passed into
Editor->process()
to make it do the action you want. The data format is here.Is it advisable? I've only done it once before myself and it worked fine, but it very much depends on what you feel happiest maintaining. I don't know that it really gains you anything over an SQL update - I don't think the code would be any shorter for example - perhaps more modular since you could do a class or file per table, but I'd say it is personal preference. Normally I just do what you've done and do a specific action in SQL.
Allan
Ok cool, I'll just do it the straightforward way, with some minimal code duplication. I gotta stop trying to be so tricky
@Allan if you see this and have time, you may want to check out my HD-PMS again. I tried to upgrade things but ran into too many issues and gave up. BUT, I wanted to get rid of the + and - so I went to hacking your responsive css file.
Not only did I do some cool things with the control icon, I also added some animations that I just love!
(mid slide-down, arrow is mid-rotation)
(end of loading, shows left arrow only for 0.5s, then right-reveal for 0.5s)
Here is the css
Note: I already use #eef for empty tables all over the place like this:
...so having the white/blue background with the all-white arrows for a bit, before swiping open the rows, looks really cool (and brings attention to the arrows). And if the table is empty, you don't even notice the swipe because it is the same background.
Sorry for the delayed reply. I've just had a look and yeah, that looks really awesome. Nice one!
Allan
Another bonus to the animation, is that if you re-sort a paged table, the animations only occur on rows that were not previously viewable. It is a cool feature to see that extra info. I did have an issue though with a drop-down button in a table cell dropping behind the next row. I could only fix it by removing the animation... so thats what I do automatically after the animation is over:
Also, with help from Cody AI, I finally completed what this OP was all about, and I will share my solution here for anyone trying to do the same (make other table edits, when editor is used to edit specific fields). I opted not to call sub-editors, but I did learn how to use DT's db connection...
Very nice system Allan. Now I can do tons of "automation updates" on all my editors.
Here is another example:
I hope someone someday may find this post useful. I learn by example, and these show off a lot of DT power.
Epic - nice one
Thanks for introducing me to Cody AI as well - I'll enjoy having a play with that later on.
Allan
I keep it simple:
1) Go here: https://sourcegraph.com/cody/chat
2) Chat, and paste over some code.
3) Get help with all your syntax and repetitive task woes.
4) When switching topics, reload the page (and Cody's memory)
5) When not switching but it slowed to a crawl, ask it to summarize everything you did, then copy that, reload, and paste it back to "new Cody". Then continue.
Works a treat