can integers field be auto incremented through studio
can integers field be auto incremented through studio
I solved it using a LogicHook that called a function to autoInc for me. It looks like this
First, in Studio I added a new integer field to the ProjectTask module called 'project_task_id'
Then, in custom/modules/ProjectTask/logic_hooks.php I added the following:
$hook_version = 1;
$hook_array = Array();
// position, file, function
$hook_array['before_save'] = Array();
$hook_array['before_save'][] = Array(1, 'auto_inc_pt', 'custom/include/autoIncProjectTaskId.php','IncProjectTaskId', 'updateProjectTask');
Finally, I created a file 'custom/include/autoIncProjectTaskId.php' that looks like:
<?php
class IncProjectTaskId {
function updateProjectTask(&$bean, $event, $arguments)
{
if ( !isset( $bean->project_task_id ) || '' == $bean->project_task_id )
{
$query = "SELECT MAX(project_task_id) AS max_project_task_id FROM project_task pt ";
$results = $bean->db->query($query, true);
$row = $bean->db->fetchByAssoc( $results );
$pt_id = isset( $row )
? $row['max_project_task_id'] + 1
: 1 ;
//Change project_task_id value on Project Task
$bean->project_task_id = $pt_id;
}
}
}
Let me know if this helps.
Thanks a lot Timothy Turnquist , It Works
Thanks a lot Timothy Turnquist , It Works