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
|
$results = $DB->select(
|
12
|
"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
|
|
38
|
if ($temp_value != null) {
|
39
|
array_push($output["data"], $temp_value);
|
40
|
}
|
41
|
$output["count"] = count($output["data"]);
|
42
|
if (array_key_exists("page", $_POST) && array_key_exists("items_per_page", $_POST)) {
|
43
|
$output["data"] = array_slice($output["data"], $_POST['page'] * $_POST['items_per_page'], $_POST['items_per_page']);
|
44
|
} else {
|
45
|
$output["data"] = array_slice($output["data"], 0, 50);
|
46
|
}
|
47
|
echo json_encode(count($output)==0 ? null : $output);
|
48
|
|
49
|
|
50
|
function createWhereQuery(&$array) {
|
51
|
$whereQuery = "WHERE";
|
52
|
if (array_key_exists("lemma", $_POST) && $_POST['lemma'] != "") {
|
53
|
$array['lemma'] = $_POST['lemma']."%";
|
54
|
$whereQuery .= " upper(l.lemma) LIKE upper(:lemma) AND";
|
55
|
}
|
56
|
if (array_key_exists("word", $_POST) && $_POST['word'] != "") {
|
57
|
$array['word'] = $_POST['word'];
|
58
|
$whereQuery .= " upper(w.word) = upper(:word) AND";
|
59
|
}
|
60
|
if (array_key_exists("position1", $_POST) && $_POST['position1'] != "") {
|
61
|
$array['position1'] = $_POST['position1'];
|
62
|
$whereQuery .= " w.position1 = :position1 AND";
|
63
|
}
|
64
|
if (array_key_exists("position2", $_POST) && $_POST['position2'] != "") {
|
65
|
$array['position2'] = $_POST['position2'];
|
66
|
$whereQuery .= " w.position2 = :position2 AND";
|
67
|
}
|
68
|
if (array_key_exists("positiondetail", $_POST) && $_POST['positiondetail'] != "") {
|
69
|
$array['positiondetail'] = $_POST['positiondetail'];
|
70
|
$whereQuery .= " w.positiondetail = :positiondetail AND";
|
71
|
}
|
72
|
if (array_key_exists("finished", $_POST) && $_POST['finished'] != "") {
|
73
|
$array['finished'] = $_POST['finished'];
|
74
|
$whereQuery .= " w.finished = :finished AND";
|
75
|
}
|
76
|
if (array_key_exists("manuscript", $_POST) && $_POST['manuscript'] != "") {
|
77
|
$array['manuscript'] = Array();
|
78
|
$nums = explode(",", $_POST['manuscript']);
|
79
|
$whereQuery .= " m.manuscript in (";
|
80
|
for ($x = 0; $x < count($nums); $x += 1) {
|
81
|
$array['manuscript'][$x] = $nums[$x];
|
82
|
$whereQuery .= ":manuscript".$x.",";
|
83
|
}
|
84
|
$whereQuery = substr_replace($whereQuery, "", -1, 1);
|
85
|
$whereQuery .= ") AND";
|
86
|
}
|
87
|
$tag = "____________%";
|
88
|
if (array_key_exists("tag_pos", $_POST) && $_POST['tag_pos'] != "") {
|
89
|
$tag = substr_replace($tag, $_POST['tag_pos'], 0, 1);
|
90
|
}
|
91
|
if (array_key_exists("tag_case", $_POST) && $_POST['tag_case'] != "") {
|
92
|
$tag = substr_replace($tag, $_POST['tag_case'], 1, 1);
|
93
|
}
|
94
|
if (array_key_exists("tag_number", $_POST) && $_POST['tag_number'] != "") {
|
95
|
$tag = substr_replace($tag, $_POST['tag_number'], 2, 1);
|
96
|
}
|
97
|
if (array_key_exists("tag_gender", $_POST) && $_POST['tag_gender'] != "") {
|
98
|
$tag = substr_replace($tag, $_POST['tag_gender'], 3, 1);
|
99
|
}
|
100
|
if (array_key_exists("tag_degree", $_POST) && $_POST['tag_degree'] != "") {
|
101
|
$tag = substr_replace($tag, $_POST['tag_degree'], 4, 1);
|
102
|
}
|
103
|
if (array_key_exists("tag_shape", $_POST) && $_POST['tag_shape'] != "") {
|
104
|
$tag = substr_replace($tag, $_POST['tag_shape'], 5, 1);
|
105
|
}
|
106
|
if (array_key_exists("tag_num", $_POST) && $_POST['tag_num'] != "") {
|
107
|
$tag = substr_replace($tag, $_POST['tag_num'], 6, 1);
|
108
|
}
|
109
|
if (array_key_exists("tag_sentence", $_POST) && $_POST['tag_sentence'] != "") {
|
110
|
$tag = substr_replace($tag, $_POST['tag_sentence'], 7, 1);
|
111
|
}
|
112
|
if (array_key_exists("tag_verb_person", $_POST) && $_POST['tag_verb_person'] != "") {
|
113
|
$tag = substr_replace($tag, $_POST['tag_verb_person'], 8, 1);
|
114
|
}
|
115
|
if (array_key_exists("tag_verb_time", $_POST) && $_POST['tag_verb_time'] != "") {
|
116
|
$tag = substr_replace($tag, $_POST['tag_verb_time'], 9, 1);
|
117
|
}
|
118
|
if (array_key_exists("tag_verb_degree", $_POST) && $_POST['tag_verb_degree'] != "") {
|
119
|
$tag = substr_replace($tag, $_POST['tag_verb_degree'], 10, 1);
|
120
|
}
|
121
|
if (array_key_exists("tag_verb_aspect", $_POST) && $_POST['tag_verb_aspect'] != "") {
|
122
|
$tag = substr_replace($tag, $_POST['tag_verb_aspect'], 11, 1);
|
123
|
}
|
124
|
$array['tag'] = $tag;
|
125
|
$whereQuery .= " upper(t.tag) LIKE upper(:tag)";
|
126
|
return $whereQuery;
|
127
|
}
|