[Pb] save and retrieve events from 2 different table


nice job for the scheduler :smiley:!

But i’m now having a pb that i tried to fix it without any success.
I have a scheduler where i can store 2 different kind of events. I have thus 2 different table in my database.
For loading events from my 2 tables it’s ok by using scheduler.load([firstTable.php, secondeTable.php]).
It’s ok also to save events in my 2 different table but the pb is that i can have the same id for 2 different events between my 2 tables.

For example :
Table 1
id start_date end_date …
1 2013-08-21 2013-08-22 …

Table 2
id start_date end_date …
1 2013-08-27 2013-08-28 …

These 2 events are completely different but then when i load them with the load method explain above it does not show the 2 events on my scheduler at the same time cause they both have the same id which is 1. I finally only see the last event loaded on my scheduler.

Any idea to help me to fix this big problem?

Thanks a lot guys :wink:

If you are using custom server side code you can just add some prefix to the id value ( table name for example ), so ids will be unique, and during data saving it will be easy to detect for which table update need to be done.

If you are using connector, it is a bit more complicated. You can use onEventLoading handler to preprocess loaded data

docs.dhtmlx.com/scheduler/api__s … event.html

Something like next

scheduler.attachEvent("onEventLoading", function(data){ if (scheduler.getEvent(data.id) data.id = "t2_"+id; return true; })

Thanks for your answer :smiley:

I’m using connector and unfortunatly this does not work in my case… I have to refresh my page to use this function “onEventLoading”.
I mean if i create by dragging 3 events of the type “event”, these 3 events will have ids 1,2 and 3 (before refreshing the page). Then, if i create 3 other events of the other type “activity” without refreshing my pages, my 3 other events of a different type will have the same id then 1,2 and 3 and this is a really big problem because it can’t show all of them on the same scheduler until i refresh my page and use the “onEventLoading”.

Don’t know if i’m clear? but thanks to try to help me!!

i maybe found a solution to fix my pb, i saw that the sheduler automatically change the id by the DB’s id with the function “onEventIdChange” http://docs.dhtmlx.com/scheduler/api__scheduler_oneventidchange_event.html

There is any way to not change id and still keep the old id maybe?

Yep, I have missed event creation logic. While it possible to catch the ID changing event, there is no way to block or change it.

There is any way to not change id and still keep the old id maybe?
After valid server side response, event id will be changed ( it is necessary to correctly update event after that )

Unfortunately it seems you will need to replace connectors with custom code, at least for new record inserting. You can redife insert action ( for example through beforeInsert server side events ), in such case you will be able to return a custom id, instead of db generated one.

Thanks again for your answer, this helps me a little but unfortunatly still have some pb.

I already tried to use the beforeInsert function, something like this just to test and hcnage event_id :

function beforeInsert( $action){ $action->set_value("event_id", "10"); }

But this does not work because i don’t know how to save my own new event_id in the DB? I use the method render table and it seems there is no way to send event_id to the DB?

$scheduler->render_table("my_table", "event_id", "start_date,end_date,event_name,section_id");

The event_id is my primary key and auto_increment? maybe this is wrong?

Thanks again to help me!

You need to use one of next two ways

[code]//custom insert logic
function beforeInsert( $action){
global $scheduler;

//you can use $action->get_value($name);  to access values
$scheduler->sql->query("insert into (...) values (...) ");
$id = $scheduler->sql->get_new_id();



function afterInsert($action){
$scheduler->event->attach("afterInsert", afterInsert);

For second approach, you may need to update dataprocessor.php with the attached one.
dataprocessor.zip (3.6 KB)

Thanks for you anwer, i think now my pb is fixed.

I used what you said me in the beforeInsert. But after i still have a pb if i want to update my event cause now the ids of my events are different with the id in the database. Then i just added something in the afterProcessing function to update the id in the database as well.