How to handle additional db fields when adding/updating

I have dhtmlxGantt working with my Codeigniter app, but I’m struggling to work out how to do anything that involves custom database fields.

I’d like to use the same database task/link tables for multiple users, but I only want users to be able to see their own data. So need to add some additional fields to the basic table and be able to insert/update the appropriate data (I think I’ve found how to apply server-side filtering).

I can’t find any documentation for this type of customization – can somebody please give me some pointers.

Thanks

Maybe I need to use something like the method described here:
docs.dhtmlx.com/doku.php?id=tuto … er_objects

but this is for grid data. How would this method de used with gantt data?

$gantt->filter("user_id", $user_id); $gantt->render_links("gantt_links", "id", "source,target,type"); $gantt->render_table("gantt_tasks","id","start_date,duration,text,progress,parent","");

Where $user_id - id of the current user ( taken from session, or from some other storage )

Thanks for your help. I’ve figured out the filtering – I have a user_id field in the gantt_tasks table, so I can easily filter tasks based on user_id from a session.

The issue I have is I don’t know how to insert the current user_id into the gantt_tasks table when creating a new task? I’m afraid ‘update connector files’ is a little too vague for me.

Also, is it possible to pass a filter from the client-side to the server side when fetching tasks?

Thanks again.

I’ve tried using the server-side events described here: http://docs.dhtmlx.com/doku.php?id=dhtmlxconnector:data_management_how-tos_updating#how_can_i_change_values_before_saving, but it doesn’t seem to work.

This is what I’m doing (it’s using CodeIgniter, so maybe that’s the problem?):

public function data() {
	$gantt = new JSONGanttConnector($this->db, "phpCI");
	$gantt->filter("user_id", $this->session->userdata('user_id'));
	$gantt->render_links("gantt_links","id","source,target,type");
	$gantt->render_table("gantt_tasks","id","start_date,duration,text,progress,parent,user_id");
	
	$gantt->event->attach("beforeInsert","my_insert");
}

function my_insert($data) {
	$data->add_field("user_id",$this->session->userdata('user_id'));
}

Are these server-side events supported? If so, what am I doing wrong.

Thanks

The above code is fine, but you need to change the order of commands

$gantt = new JSONGanttConnector($this->db, "phpCI"); $gantt->event->attach("beforeInsert","my_insert"); $gantt->filter("user_id", $this->session->userdata('user_id')); $gantt->render_links("gantt_links","id","source,target,type"); $gantt->render_table("gantt_tasks","id","start_date,duration,text,progress,parent,user_id");

All commands after render_table will be ignored ( this command will start data processing )

Hi, I’ve reorganised the code in line with your suggestion, but it doesn’t work.

It doesn’t seem to matter what I put in:

$gantt->event->attach("beforeInsert", function_name);

it doesn’t do anything. Because I’m using CodeIgniter I’ve tried using $this->function_name and even placing the entire function in the $gantt->event->attach declaration, but it doesn’t do anything. The tasks database is updated, but the user_id field is not updated.

So the entire code I’m now trying (unsuccessully) is:

[code]
function my_insert($data){
$data->add_field(“user_id”,$this->session->userdata(‘user_id’));
}

public function data()
{
	$gantt = new JSONGanttConnector($this->db, "phpCI");
	$gantt->event->attach("beforeInsert", $this->my_insert);
	$gantt->filter("user_id", $this->session->userdata('user_id'));
	$gantt->render_links("gantt_links","id","source,target,type");
	$gantt->render_table("gantt_tasks","id","start_date,duration,text,progress,parent,user_id");

}[/code]

I’ve tried all the following (individually) without success:

$gantt->event->attach("beforeInsert", $this->my_insert);
$gantt->event->attach("beforeInsert", "$this->my_insert"); // surround with quotes
$gantt->event->attach("beforeInsert", this->my_insert); // remove dollar sign
$gantt->event->attach("beforeInsert", my_insert); // after moving the my_insert function inside the data() function
$gantt->event->attach("beforeInsert", $data->add_field("user_id",$this->session->userdata('user_id')));

All these update the gant_tasks table without the user_id field.

Any suggestions?

When you need to add the method of a class, it must have the next syntax

  $gantt->event->attach("beforeInsert", array($this, "my_insert") );

Great. That’s working now. Thanks.

Is there any documentation for this?

Thanks again.

I don’t think so :frowning:
The above approach is not dhtmlx specific, the same approach is used by PHP functions ( such as call_user_func and others )