Projekt

Obecné

Profil

Stáhnout (5.95 KB) Statistiky
| Větev: | Revize:
1
<?php
2
require "../model/DB.php";
3
require "../model/Tag.php";
4
require "../model/Word.php";
5
require "../model/Lemma.php";
6
$DB = new DB();
7

    
8
$parArray = Array();
9
$whereQuery = createWhereQuery($parArray);
10

    
11
if (array_key_exists("manuscript", $_POST) && $_POST['manuscript'] != "") {
12
    $results = $DB->select(
13
        "SELECT w.id, w.context, w.date, w.description, w.description2, w.description3, w.ending, w.finished,
14
w.namedentity, w.position1, w.position2, w.positiondetail, w.word, w.tag_id, w.lemma_id, t.tag, l.lemma, m.manuscript,
15
l.pos FROM dd_manuscript as m left join dd_wordform as w on m.wordform_id = w.id left join dd_tag as t on w.tag_id = t.id left join dd_lemma as l on w.lemma_id = l.id ".$whereQuery." order by w.id", $parArray);
16
} else {
17
    $results = $DB->select(
18
        "SELECT w.id, w.context, w.date, w.description, w.description2, w.description3, w.ending, w.finished,
19
w.namedentity, w.position1, w.position2, w.positiondetail, w.word, w.tag_id, w.lemma_id, t.tag, l.lemma,
20
l.pos FROM dd_wordform as w left join dd_tag as t on w.tag_id = t.id left join dd_lemma as l on w.lemma_id = l.id ".$whereQuery." order by w.id", $parArray);
21
}
22

    
23
$output = Array();
24
$output["data"] = Array();
25
$temp_value = null;
26
foreach ($results as $res) {
27
    if ($temp_value != null && $res["id"] != $temp_value->id) {
28
        array_push($output["data"], $temp_value);
29
        $temp_value = null;
30
    }
31
    if ($temp_value == null) {
32
        $tag = new Tag($res["tag_id"], $res["tag"]);
33
        $lemma = new Lemma($res["lemma_id"], $res["lemma"], $res["pos"]);
34
        $word = new Word($res["id"],  $res["context"], $res["date"], $res["description"], $res["description2"], $res["description3"], $res["ending"],
35
            $res["finished"], $res["namedentity"], $res["position1"], $res["position2"], $res["positiondetail"], $res["word"], $lemma, $tag);
36
        if (array_key_exists("manuscript", $res)) {
37
            array_push($word->manuscript, $res["manuscript"]);
38
        }
39
        $temp_value = $word;
40
    } else {
41
        array_push($temp_value->manuscript, $res["manuscript"]);
42
    }
43
}
44
$output["count"] = count($output["data"]);
45
if (array_key_exists("page", $_POST) && array_key_exists("items_per_page", $_POST)) {
46
    $output["data"] = array_slice($output["data"], $_POST['page'] * $_POST['items_per_page'], $_POST['items_per_page']);
47
} else {
48
    $output["data"] = array_slice($output["data"], 0, 50);
49
}
50
echo json_encode(count($output)==0 ? null : $output);
51

    
52

    
53
function createWhereQuery(&$array) {
54
    $whereQuery = "WHERE";
55
    if (array_key_exists("lemma", $_POST) && $_POST['lemma'] != "") {
56
        $array['lemma'] = $_POST['lemma']."%";
57
        $whereQuery .= " l.lemma LIKE :lemma AND";
58
    }
59
    if (array_key_exists("word", $_POST) && $_POST['word'] != "") {
60
        $array['word'] = $_POST['word'];
61
        $whereQuery .= " w.word = :word AND";
62
    }
63
    if (array_key_exists("position1", $_POST) && $_POST['position1'] != "") {
64
        $array['position1'] = $_POST['position1'];
65
        $whereQuery .= " w.position1 = :position1 AND";
66
    }
67
    if (array_key_exists("position2", $_POST) && $_POST['position2'] != "") {
68
        $array['position2'] = $_POST['position2'];
69
        $whereQuery .= " w.position2 = :position2 AND";
70
    }
71
    if (array_key_exists("positiondetail", $_POST) && $_POST['positiondetail'] != "") {
72
        $array['positiondetail'] = $_POST['positiondetail'];
73
        $whereQuery .= " w.positiondetail = :positiondetail AND";
74
    }
75
    if (array_key_exists("finished", $_POST) && $_POST['finished'] != "") {
76
        $array['finished'] = $_POST['finished'];
77
        $whereQuery .= " w.finished = :finished AND";
78
    }
79
    if (array_key_exists("manuscript", $_POST) && $_POST['manuscript'] != "") {
80
        $array['manuscript'] = Array();
81
        $nums = explode(",", $_POST['manuscript']);
82
        $whereQuery .= " m.manuscript in (";
83
        for ($x = 0; $x < count($nums); $x += 1) {
84
            $array['manuscript'][$x] = $nums[$x];
85
            $whereQuery .= ":manuscript".$x.",";
86
        }
87
        $whereQuery = substr_replace($whereQuery, "", -1, 1);
88
        $whereQuery .= ") AND";
89
    }
90
    $tag = "____________%";
91
    if (array_key_exists("tag_pos", $_POST) && $_POST['tag_pos'] != "") {
92
        $tag = substr_replace($tag, $_POST['tag_pos'], 0, 1);
93
    }
94
    if (array_key_exists("tag_case", $_POST) && $_POST['tag_case'] != "") {
95
        $tag = substr_replace($tag, $_POST['tag_case'], 1, 1);
96
    }
97
    if (array_key_exists("tag_number", $_POST) && $_POST['tag_number'] != "") {
98
        $tag = substr_replace($tag, $_POST['tag_number'], 2, 1);
99
    }
100
    if (array_key_exists("tag_gender", $_POST) && $_POST['tag_gender'] != "") {
101
        $tag = substr_replace($tag, $_POST['tag_gender'], 3, 1);
102
    }
103
    if (array_key_exists("tag_degree", $_POST) && $_POST['tag_degree'] != "") {
104
        $tag = substr_replace($tag, $_POST['tag_degree'], 4, 1);
105
    }
106
    if (array_key_exists("tag_shape", $_POST) && $_POST['tag_shape'] != "") {
107
        $tag = substr_replace($tag, $_POST['tag_shape'], 5, 1);
108
    }
109
    if (array_key_exists("tag_num", $_POST) && $_POST['tag_num'] != "") {
110
        $tag = substr_replace($tag, $_POST['tag_num'], 6, 1);
111
    }
112
    if (array_key_exists("tag_sentence", $_POST) && $_POST['tag_sentence'] != "") {
113
        $tag = substr_replace($tag, $_POST['tag_sentence'], 7, 1);
114
    }
115
    if (array_key_exists("tag_verb_person", $_POST) && $_POST['tag_verb_person'] != "") {
116
        $tag = substr_replace($tag, $_POST['tag_verb_person'], 8, 1);
117
    }
118
    if (array_key_exists("tag_verb_time", $_POST) && $_POST['tag_verb_time'] != "") {
119
        $tag = substr_replace($tag, $_POST['tag_verb_time'], 9, 1);
120
    }
121
    if (array_key_exists("tag_verb_degree", $_POST) && $_POST['tag_verb_degree'] != "") {
122
        $tag = substr_replace($tag, $_POST['tag_verb_degree'], 10, 1);
123
    }
124
    if (array_key_exists("tag_verb_aspect", $_POST) && $_POST['tag_verb_aspect'] != "") {
125
        $tag = substr_replace($tag, $_POST['tag_verb_aspect'], 11, 1);
126
    }
127
    $array['tag'] = $tag;
128
    $whereQuery .= " t.tag LIKE :tag";
129
    return $whereQuery;
130
}
    (1-1/1)