Projekt

Obecné

Profil

Stáhnout (5.47 KB) Statistiky
| Větev: | Revize:
1 3b343aea Tomáš Pašek
<?php
2
require "../model/DB.php";
3 d9606f0d Tomáš Pašek
require "../model/Tag.php";
4
require "../model/Word.php";
5
require "../model/Lemma.php";
6 3b343aea Tomáš Pašek
$DB = new DB();
7
8 d9606f0d Tomáš Pašek
$parArray = Array();
9
$whereQuery = createWhereQuery($parArray);
10
11 3b343aea Tomáš Pašek
$results = $DB->select(
12 d9606f0d Tomáš Pašek
        "SELECT w.id, w.context, w.date, w.description, w.description2, w.description3, w.ending, w.finished,
13
w.namedentity, w.position1, w.position2, w.positiondetail, w.word, w.tag_id, w.lemma_id, t.tag, l.lemma, m.manuscript,
14
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);
15
16
$output = Array();
17
$output["data"] = Array();
18
$temp_value = null;
19
foreach ($results as $res) {
20
    if ($temp_value != null && $res["id"] != $temp_value->id) {
21
        array_push($output["data"], $temp_value);
22
        $temp_value = null;
23
    }
24
    if ($temp_value == null) {
25
        $tag = new Tag($res["tag_id"], $res["tag"]);
26
        $lemma = new Lemma($res["lemma_id"], $res["lemma"], $res["pos"]);
27
        $word = new Word($res["id"],  $res["context"], $res["date"], $res["description"], $res["description2"], $res["description3"], $res["ending"],
28
            $res["finished"], $res["namedentity"], $res["position1"], $res["position2"], $res["positiondetail"], $res["word"], $lemma, $tag);
29
        if (array_key_exists("manuscript", $res)) {
30
            array_push($word->manuscript, $res["manuscript"]);
31
        }
32
        $temp_value = $word;
33
    } else {
34
        array_push($temp_value->manuscript, $res["manuscript"]);
35
    }
36
}
37
$output["count"] = count($output["data"]);
38
if (array_key_exists("page", $_POST) && array_key_exists("items_per_page", $_POST)) {
39
    $output["data"] = array_slice($output["data"], $_POST['page'] * $_POST['items_per_page'], $_POST['items_per_page']);
40
} else {
41
    $output["data"] = array_slice($output["data"], 0, 50);
42
}
43
echo json_encode(count($output)==0 ? null : $output);
44
45 3b343aea Tomáš Pašek
46 d9606f0d Tomáš Pašek
function createWhereQuery(&$array) {
47
    $whereQuery = "WHERE";
48
    if (array_key_exists("lemma", $_POST) && $_POST['lemma'] != "") {
49
        $array['lemma'] = $_POST['lemma']."%";
50
        $whereQuery .= " l.lemma LIKE :lemma AND";
51
    }
52
    if (array_key_exists("word", $_POST) && $_POST['word'] != "") {
53
        $array['word'] = $_POST['word'];
54
        $whereQuery .= " w.word = :word AND";
55
    }
56
    if (array_key_exists("position1", $_POST) && $_POST['position1'] != "") {
57
        $array['position1'] = $_POST['position1'];
58
        $whereQuery .= " w.position1 = :position1 AND";
59
    }
60
    if (array_key_exists("position2", $_POST) && $_POST['position2'] != "") {
61
        $array['position2'] = $_POST['position2'];
62
        $whereQuery .= " w.position2 = :position2 AND";
63
    }
64
    if (array_key_exists("positiondetail", $_POST) && $_POST['positiondetail'] != "") {
65
        $array['positiondetail'] = $_POST['positiondetail'];
66
        $whereQuery .= " w.positiondetail = :positiondetail AND";
67
    }
68
    if (array_key_exists("finished", $_POST) && $_POST['finished'] != "") {
69
        $array['finished'] = $_POST['finished'];
70
        $whereQuery .= " w.finished = :finished AND";
71
    }
72
    if (array_key_exists("manuscript", $_POST) && $_POST['manuscript'] != "") {
73
        $array['manuscript'] = Array();
74
        $nums = explode(",", $_POST['manuscript']);
75
        $whereQuery .= " m.manuscript in (";
76
        for ($x = 0; $x < count($nums); $x += 1) {
77
            $array['manuscript'][$x] = $nums[$x];
78
            $whereQuery .= ":manuscript".$x.",";
79
        }
80
        $whereQuery = substr_replace($whereQuery, "", -1, 1);
81
        $whereQuery .= ") AND";
82
    }
83
    $tag = "____________%";
84
    if (array_key_exists("tag_pos", $_POST) && $_POST['tag_pos'] != "") {
85
        $tag = substr_replace($tag, $_POST['tag_pos'], 0, 1);
86
    }
87
    if (array_key_exists("tag_case", $_POST) && $_POST['tag_case'] != "") {
88
        $tag = substr_replace($tag, $_POST['tag_case'], 1, 1);
89
    }
90
    if (array_key_exists("tag_number", $_POST) && $_POST['tag_number'] != "") {
91
        $tag = substr_replace($tag, $_POST['tag_number'], 2, 1);
92
    }
93
    if (array_key_exists("tag_gender", $_POST) && $_POST['tag_gender'] != "") {
94
        $tag = substr_replace($tag, $_POST['tag_gender'], 3, 1);
95
    }
96
    if (array_key_exists("tag_degree", $_POST) && $_POST['tag_degree'] != "") {
97
        $tag = substr_replace($tag, $_POST['tag_degree'], 4, 1);
98
    }
99
    if (array_key_exists("tag_shape", $_POST) && $_POST['tag_shape'] != "") {
100
        $tag = substr_replace($tag, $_POST['tag_shape'], 5, 1);
101
    }
102
    if (array_key_exists("tag_num", $_POST) && $_POST['tag_num'] != "") {
103
        $tag = substr_replace($tag, $_POST['tag_num'], 6, 1);
104
    }
105
    if (array_key_exists("tag_sentence", $_POST) && $_POST['tag_sentence'] != "") {
106
        $tag = substr_replace($tag, $_POST['tag_sentence'], 7, 1);
107
    }
108
    if (array_key_exists("tag_verb_person", $_POST) && $_POST['tag_verb_person'] != "") {
109
        $tag = substr_replace($tag, $_POST['tag_verb_person'], 8, 1);
110
    }
111
    if (array_key_exists("tag_verb_time", $_POST) && $_POST['tag_verb_time'] != "") {
112
        $tag = substr_replace($tag, $_POST['tag_verb_time'], 9, 1);
113
    }
114
    if (array_key_exists("tag_verb_degree", $_POST) && $_POST['tag_verb_degree'] != "") {
115
        $tag = substr_replace($tag, $_POST['tag_verb_degree'], 10, 1);
116
    }
117
    if (array_key_exists("tag_verb_aspect", $_POST) && $_POST['tag_verb_aspect'] != "") {
118
        $tag = substr_replace($tag, $_POST['tag_verb_aspect'], 11, 1);
119
    }
120
    $array['tag'] = $tag;
121
    $whereQuery .= " t.tag LIKE :tag";
122
    return $whereQuery;
123
}