Best way to copy bID to another field only when adding a block and duplicating a page

Permalink
I'm making a simple ticket system on concrete5 (and planning to release it as open source package.) But it's no longer simple... :(

In my ticket system,
- Page (cID) represents an event.
- A block represents a ticket.

At first, I thought I would use bID itself as the ticket identification. But I realized that bID gets changed when someone edit the block.

So I could set $btIncludeAll true. But I would like to avoid it.

I now think about making additional parameter, tID (ticketID) which is generated upon block creation and gets changed when a block is duplicated only.

I would like to copy bID when a block gets created, then keep the same tID. Then tID only gets new number if that ticket block moved to a new page. Most likely when the page is being duplicated as an new event page.

1. Is there any best practice to copy bID to a new field at block creation?

2. I think duplicate(), function is executed even when you're editing a block. Is there any best way to fire

Here is my GitHub
https://github.com/katzueno/magnetty...

- Due to the development issue, I am including concrete5.7.4.2 itself.
- Please look under packages folder.

katz515
 
mnakalay replied on at Permalink Best Answer Reply
mnakalay
Hello,
Why not just make your life easier and generate your own tID instead of trying to make it same value as original bID?
You could either come up with a way to generate the number manually (last ID in the DB +1) or put the tickets ID in a different table and make the tID an auto increment key field. This last solution is probably a bit overkill and messy though.
JohntheFish replied on at Permalink Reply
JohntheFish
Definitely something along the lines @mnakalay suggests. Using bID always makes things unnecessarily complicated. Make ticketID a data item in the block's table, generated when a block is either created (start of add) or saved for the first time (add ends). Perhaps use the system time as a starting point.
katz515 replied on at Permalink Reply
katz515
@mnakalay
@Jomesthefish

Thanks a lot!
I guess I don't think I'm going to use bID for now.

@mnakalay
I'm now leaning towards creating another table.
Fetching the last ID and ID+1 is a bit troublesome. And it could slow down the DB when the table gets bigger.

@Jomesthefish
Making system time could cause a problem for a large site that could make the same ticket at the same system time although it would be a rare case.

Thanks a lot.

Now I will move to the next step :)