summaryrefslogtreecommitdiffstats
path: root/codebase/Dhtmlx/Connector/Data/JSONGanttDataUpdate.php
blob: eba380fcc04ea62902ed7e8b81a0dcda6f11e73e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php
namespace Dhtmlx\Connector\Data;

class JSONGanttDataUpdate extends JSONDataUpdate {

    public function get_updates() {
        $updates = $this->get_data_updates();
        //ToDo: Add rendering for data.
    }


    private function get_data_updates() {
        $actions_table = $this->table;
        $version = $this->request->get_version();
        $user = $this->request->get_user();

        $select_actions = "SELECT DATAID, TYPE, USER FROM {$actions_table}";
        $select_actions .= " WHERE {$actions_table}.ID > '{$version}' AND {$actions_table}.USER <> '{$user}'";


        $output = array();
        $index = 0;
        $actions_query = $this->sql->query($select_actions);
        while($action_data=$this->sql->get_next($actions_query)){
            $action_type = $action_data["TYPE"];
            $type_parts = explode("#", $action_type);
            $action_mode = $type_parts[1];
            if($action_mode == "links") {
                $data = $this->select_links_for_action($action_data["DATAID"]);
                $data = new DataItemUpdate($data, $this->config, $index, $this->item_class);
            }
            else {
                $data = $this->select_task_for_action($action_data["DATAID"]);
                $data = new DataItemUpdate($data, $this->config, $index, $this->item_class);
            }

            array_push($output, $data);
            $index++;
        }

        return $output;
    }

    protected function select_task_for_action($taskId) {
        $tasks_table = $this->request->get_source();
        $field_task_id = $this->config->id['db_name'];
        $select_actions_tasks = "SELECT * FROM {$tasks_table} WHERE {$taskId} = {$tasks_table}.{$field_task_id}";
        return $this->sql->get_next($this->sql->query($select_actions_tasks));
    }

    protected function select_links_for_action($taskId) {
        $links_connector_options = $this->options["connector"]->get_options();
        $links_table = $links_connector_options["links"]->get_request()->get_source();
        $field_task_id = $this->config->id['db_name'];
        $select_actions_tasks = "SELECT * FROM {$links_table} WHERE {$taskId} = {$links_table}.{$field_task_id}";
        return $this->sql->get_next($this->sql->query($select_actions_tasks));
    }
}