I am attempting to set up a History table using a delegate class. Eventually this will be implemented with the stored procedures in MySQL. But the Dataface Delegate class looks like it can handle it immediately if I figure out a couple of things.
So to accomplish this I have a regular Data table. I duplicate that table into a History table and add two fields: H_ID and H_DATETIME. The H_ID is the true autoincrement for the History table. The H_DATETIME will be a timestamp of a change. So whenever a record is added or changed, an exact duplicate gets saved to the H_ table. If a record is Deleted I will probably have to note that also. And of course add fields for USERS..so we can note who did the add/change/delete. But for now I am just trying to get the basic Delegate Class/Trigger code prepared.
Thus I have two tables:
CREATE TABLE `D_TASK` (
`ID` mediumint(8) unsigned zerofill NOT NULL auto_increment,
`TYPE` enum('Task','Project') NOT NULL default 'Task',
`DESCRIPTION` varchar(80) default NULL,
`PRIORITY` enum('URGENT','High','Medium','Low','Whenever','Just a Brain Storm','Nevermind') default NULL,
`STATUS` enum('Assigned','Under Consideration','Started','Halfway','Almost Done','Completed','On Going','Repeating','Delayed','Requires Outside Help','Postponed','Cancelled') default NULL,
`ID_USER_CREATED` mediumint(8) unsigned zerofill default NULL,
`ID_USER_ASSIGNED` mediumint(8) unsigned zerofill default NULL,
`DATE_PROJECTED_START` date default NULL,
`DATE_PROJECTED_FINISH` date default NULL,
`DATE_ACTUAL_START` date default NULL,
`DATE_ACTUAL_FINISH` date default NULL,
`COMMENT` text,
PRIMARY KEY (`ID`)\n) ENGINE=MyISAM DEFAULT CHARSET=latin1
CREATE TABLE `H_TASK` (
`H_ID` int(10) unsigned zerofill NOT NULL auto_increment,
`H_DATETIME` timestamp NOT NULL default '0000-00-00 00:00:00' on update CURRENT_TIMESTAMP,
`ID` mediumint(8) unsigned zerofill NOT NULL auto_increment,
`TYPE` enum('Task','Project') NOT NULL default 'Task',
`DESCRIPTION` varchar(80) default NULL,
`PRIORITY` enum('URGENT','High','Medium','Low','Whenever','Just a Brain Storm','Nevermind') default NULL,
`STATUS` enum('Assigned','Under Consideration','Started','Halfway','Almost Done','Completed','On Going','Repeating','Delayed','Requires Outside Help','Postponed','Cancelled') default NULL,
`ID_USER_CREATED` mediumint(8) unsigned zerofill default NULL,
`ID_USER_ASSIGNED` mediumint(8) unsigned zerofill default NULL,
`DATE_PROJECTED_START` date default NULL,
`DATE_PROJECTED_FINISH` date default NULL,
`DATE_ACTUAL_START` date default NULL,
`DATE_ACTUAL_FINISH` date default NULL,
`COMMENT` text,
PRIMARY KEY (`ID`)\n) ENGINE=MyISAM DEFAULT CHARSET=latin1
So in planning/tables/D_TASK/D_TASK.php I wish to set up the triggers. Thus far I have the following code:
<---?
class tables_D_TASK {
function block__html_title(){
echo "YO TASKS!";
}
function afterInsert(&$record){
}
function afterSave(&$record){
}
function afterDelete(&$record){
}
}
?--->
So the basic triggers are prepared. Now I just need to add line for the proper SQL to Insert/Select. Or insert using the php variables of the just added record. I would probably move that SQL code to a function of itsown, and have each of the above triggers simply call that function. It would be nice of course to push the entire code base off onto its own class, so that, as Dataface can read all the fields from a table, so too could this class. Then from those fields build the appropriate history insert/select statement on its own. For now though, my SQL looks something like this:
INSERT INTO H_TASK (
`H_DATETIME`,
`ID`,
`TYPE`,
`DESCRIPTION`,
`PRIORITY`,
`STATUS`,
`ID_USER_CREATED`,
`ID_USER_ASSIGNED`,
`DATE_PROJECTED_START`,
`DATE_PROJECTED_FINISH`,
`DATE_ACTUAL_START`,
`DATE_ACTUAL_FINISH`,
`COMMENT`)
SELECT
NOW(),
`ID`,
`TYPE`,
`DESCRIPTION`,
`PRIORITY`,
`STATUS`,
`ID_USER_CREATED`,
`ID_USER_ASSIGNED`,
`DATE_PROJECTED_START`,
`DATE_PROJECTED_FINISH`,
`DATE_ACTUAL_START`,
`DATE_ACTUAL_FINISH`,
`COMMENT`
FROM D_TASK;
So my question is, how to implement an SQL call to do so? Just regular PHP calls or do I have to do something fancy in dataface?
And, would this be something we could add to the tracker (if I have not done so already)?
Thank you kindly.