Projekt

Obecné

Profil

Stáhnout (5.8 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
session_start();
8

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

    
12
$results = $DB->select(
13
        "SELECT DISTINCT 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 l.lemma", $parArray);
16

    
17
$output = Array();
18
$output["data"] = Array();
19
$temp_value = null;
20
foreach ($results as $res) {
21
    if ($temp_value != null && $res["id"] != $temp_value->id) {
22
        array_push($output["data"], $temp_value);
23
        $temp_value = null;
24
    }
25
    if ($temp_value == null) {
26
        $tag = new Tag($res["tag_id"], $res["tag"]);
27
        $lemma = new Lemma($res["lemma_id"], $res["lemma"], $res["pos"]);
28
        $word = new Word($res["id"],  $res["context"], $res["date"], $res["description"], $res["description2"], $res["description3"], $res["ending"],
29
            $res["finished"], $res["namedentity"], $res["position1"], $res["position2"], $res["positiondetail"], $res["word"], $lemma, $tag);
30
        if (array_key_exists("manuscript", $res)) {
31
            array_push($word->manuscript, $res["manuscript"]);
32
        }
33
        $temp_value = $word;
34
    } else {
35
        array_push($temp_value->manuscript, $res["manuscript"]);
36
    }
37
}
38

    
39
if ($temp_value != null) {
40
    array_push($output["data"], $temp_value);
41
}
42
$output["count"] = count($output["data"]);
43
if (array_key_exists("page", $_POST) && array_key_exists("items_per_page", $_POST)) {
44
    $output["data"] = array_slice($output["data"], $_POST['page'] * $_POST['items_per_page'], $_POST['items_per_page']);
45
} else {
46
    $output["data"] = array_slice($output["data"], 0, 50);
47
}
48
echo json_encode(count($output)==0 ? null : $output);
49

    
50

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