I am constructing a scheduler for my company.
When creating a recurring event it is crucial to save on MySql all separate occurrences of the event separately along with the main record. The point is to have the data available at all times in other applications for statistical purposes.
I searched the forum for a solution and found a few posts dated almost three years ago. Up to a point they were useful as I managed to save both the master record along with the according repletions but I haven’t found a way to connect them using event_pid.
I used the onEventAdded function and I did not realize about a way to read the event_id of the master record.
Has anyone materialized a solution about this problem?
I would appreciate any help offered.
Client side part of scheduler expects that in case of recurring event there is only one record in DB, for all occurences. So if you are replacing single record with set of separate records - they will not be recognized as part of singe recurring events.
There is mechanic which allows to store separate data about recurreng event occurences ( alterations ), but this mechanic was not purposed for fully replacing normal processing logic
On server side you can create a set of events which have
event_pid = id of master event
event_length = timestamp of original instance start time / 1000
You can try to use the default recurring events sample, create recurring events and drag one of it occurences, to alter it start time - and check the result data in DB ( it will be a master event and one alteration record )
I use the following procedure to add each separate event without deleting the master event.
The first problem was that in order to see the events correctly on screen I had to refresh the page myself. No big deal there.
The basic problem is that this procedure does not work all the time. Sometimes it will save all the separate events correctly. Sometimes it will stop before completing all events. It is driving me crazy since I can not trust it to work efficiently.
Use of firebug results in firefox crashing. I did catch once a message ‘this.getevent(a) is undefined’.
I could not think of a way to do this proccess on server side, mainly I could not link the getrecdates function or get the master id. Any suggestion there would also be welcomed.
This is the code
[code]
</code]
var dp = new dataProcessor(“php/events_rec.php”);
dp.init(scheduler);
dp.attachEvent("onAfterUpdate", function(sid, action, tid, tag)
{
if (action == "inserted")
{
if(scheduler.getEvent(tid).rec_type!='' && scheduler.getEvent(tid).rec_type!='none')
{
var eventText = scheduler.getEvent(tid).text;
var repeatArray = new Array();
var repeatArray = scheduler.getRecDates(tid);
var repeatCount = repeatArray.length;
var new_id = scheduler.uid(); //added
var completed = scheduler.getEvent(tid).completed;
for (var i = 0; i < repeatCount; i++)
{
var start_date = repeatArray[i]['start_date'];
var end_date = repeatArray[i]['end_date'];
scheduler.addEvent({
id:new_id, //added
start_date: start_date,
end_date: end_date,
text:eventText,
event_length:start_date.valueOf()/1000,
rec_type:"",
event_pid:tid,
completed:completed
});
scheduler._add_rec_marker(scheduler.getEvent(new_id),start_date);
if (new_id!=tid){ //added
dp.setUpdated(new_id, true, "inserted"); //added
}
new_id = scheduler.uid(); //added
}// render updated event
alert(i);
//scheduler.clearAll(); // delete all current event
//scheduler.load("php/events_rec.php");
scheduler.render_view_data();
location.reload();
}
else return true;
}
})
I use the following procedure to add each separate event without deleting the master event.
The first problem was that in order to see the events correctly on screen I had to refresh the page myself. No big deal there.
The basic problem is that this procedure does not work all the time. Sometimes it will save all the separate events correctly. Sometimes it will stop before completing all events. It is driving me crazy since I can not trust it to work efficiently.
Use of firebug results in firefox crashing. I did catch once a message ‘this.getevent(a) is undefined’.
I could not think of a way to do this proccess on server side, mainly I could not link the getrecdates library or get the master id. Any suggestion there would also be welcomed.
This is the code
var dp = new dataProcessor("php/events_rec.php");
dp.init(scheduler);
dp.attachEvent("onAfterUpdate", function(sid, action, tid, tag)
{
if (action == "inserted")
{
if(scheduler.getEvent(tid).rec_type!='' && scheduler.getEvent(tid).rec_type!='none')
{
var eventText = scheduler.getEvent(tid).text;
var repeatArray = new Array();
var repeatArray = scheduler.getRecDates(tid);
var repeatCount = repeatArray.length;
var new_id = scheduler.uid(); //added
var completed = scheduler.getEvent(tid).completed;
for (var i = 0; i < repeatCount; i++)
{
var start_date = repeatArray[i]['start_date'];
var end_date = repeatArray[i]['end_date'];
scheduler.addEvent({
id:new_id, //added
start_date: start_date,
end_date: end_date,
text:eventText,
event_length:start_date.valueOf()/1000,
rec_type:"",
event_pid:tid,
completed:completed
});
scheduler._add_rec_marker(scheduler.getEvent(new_id),start_date);
if (new_id!=tid) //added
dp.setUpdated(new_id, true, "inserted"); //added
new_id = scheduler.uid(); //added
}// render updated event
scheduler.render_view_data();
location.reload();
}
else return true;
}
})
Each addEvent command will generate additional call to server side, so if you have 10 occurences - it will generate 10 calls, and they need some time to reach server side and be processed ( small time, but still )
location.reload call will force page reloading which will break all not-finished server side calls. So while first ones may be processed the last ones most probably will not be saved. So to be sure that all dat was saved you need to reload page only after all data is saved.
You have two options
a) instead of location.reload use
scheduler.clearAll();
scheduler.load(url);
which will reload data in scheduler without page reloading ( and without ajax calls breaking ). I’m not really sure that it will not have some other problem, because we still have inconsistent situation, because data which still in saving process will be removed from the scheduler.
b) you can have
dp.attachEvent("onFullSync", function(){
if (scheduler.reloadRequired)
location.reload();
})
dp.attachEvent("onAfterUpdate", function(sid, action, tid, tag)
{
...
if(scheduler.getEvent(tid).rec_type!='' && scheduler.getEvent(tid).rec_type!='none')
{
scheduler.reloadRequired = true; //this one added
...
scheduler.render_view_data();
// location.reload(); - this one commented
with such code scheduler will reload only after full sync of dataprocessor’s data and only after adding new events from custom onAfterUpdate handler
No luck I still have to refresh manually.
I did as you mentioned but dp.attachEvent(“onFullSync”… is never called.
When I tried to use firebug the browser always crashes. So the problem remains in the scope of onAfterUpdate procedure.
Another problem is when I try to delete one of the recurring events (e.g the second in series) I have several similar records with rectype none instead of only one (id: 11492,11501,11502)
I include the server side script
<?php
include ('../codebase/connector/scheduler_connector.php');
include ('../common/config.php');
include('../codebase/SchedulerHelper.php');
$res=mysql_connect($server, $user, $pass);
mysql_select_db($db_name);
mysql_query("set character set greek",$res);
mysql_query("SET NAMES greek",$res);
$scheduler = new schedulerConnector($res);
$scheduler->enable_log("log.txt",true);
function delete_related($action){
global $scheduler;
$status = $action->get_status();
$type =$action->get_value("rec_type");
$pid =$action->get_value("event_pid");
//when serie changed or deleted we need to remove all linked events
if (($status == "deleted" || $status == "updated") && $type!=""){
$scheduler->sql->query("DELETE FROM events_rec WHERE event_pid='".$scheduler->sql->escape($action->get_id())."'");
}
if ($status == "deleted" && $pid !=0){
$scheduler->sql->query("UPDATE events_rec SET rec_type='none' WHERE event_id='".$scheduler->sql->escape($action->get_id())."'");
$action->success();
}
}
function insert_related($action){global $scheduler;
$status = $action->get_status();
$type =$action->get_value("rec_type");
if ($status == "inserted" && $type=="none")
$action->set_status("deleted");
}
$list = new OptionsConnector($res);
$scheduler->set_encoding("greek");
$list->render_table("users","userId","userId(value),name(label)");
$scheduler->set_options("workers", $list);
//$scheduler->render_table("events","event_id","start_date,end_date,event_name,workers");
$list2 = new OptionsConnector($res);
$list2->set_encoding("greek");
$list2->render_table("jobs","jobsId","jobsId(value),Descr(label)");
$scheduler->set_options("jobs", $list2);
$list3 = new OptionsConnector($res);
$list3->set_encoding("greek");
$list3->render_table("status","statusId","statusKey(value),statusDescr(label)");
$scheduler->set_options("status", $list3);
//$scheduler->render_table("events","event_id","start_date,end_date,event_name,jobs");
$scheduler->event->attach("beforeProcessing","delete_related");
$scheduler->event->attach("afterProcessing","insert_related");
/*////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/
$scheduler->set_encoding("greek");
if ($scheduler->is_select_mode())//code for loading data
$scheduler->render_sql("SELECT events_rec.event_id AS event_id,events_rec.start_date AS start_date,events_rec.end_date AS end_date,events_rec.text AS text,events_rec.rec_type AS rec_type,events_rec.event_pid AS event_pid,events_rec.event_length AS event_length,events_rec.workers AS workers,events_rec.jobs AS jobs,events_rec.createdby AS createdby,events_rec.createdwhen AS createdwhen,events_rec.editedby AS editedby,events_rec.editedwhen AS editedwhen,events_rec.completed AS completed,events_rec.notes AS notes,events_rec.img,events_rec.interId, jobs.Descr AS JobsDescr,users.Name AS workersDescr,status.statusDescr FROM ((events_rec JOIN jobs ON ((events_rec.jobs = jobs.JobsId))) JOIN users ON ((events_rec.workers = users.userId))) INNER JOIN status ON events_rec.completed = status.statusKey","event_id","start_date,end_date,text,rec_type,event_pid,event_length,img,completed,notes,workers,jobs,status,JobsDescr,workersDescr,statusDescr,interId");
else
$scheduler->render_table("events_rec","event_id","start_date,end_date,text,rec_type,event_pid,event_length,completed,img,notes,workers,jobs,interId");
?>