Revize d9606f0d
Přidáno uživatelem Tomáš Pašek před asi 4 roky(ů)
application/controller/TableController.php | ||
---|---|---|
1 | 1 |
<?php |
2 | 2 |
require "../model/DB.php"; |
3 |
require "../model/Tag.php"; |
|
4 |
require "../model/Word.php"; |
|
5 |
require "../model/Lemma.php"; |
|
3 | 6 |
$DB = new DB(); |
4 | 7 |
|
5 |
// (B) SEARCH FOR USERS |
|
8 |
$parArray = Array(); |
|
9 |
$whereQuery = createWhereQuery($parArray); |
|
10 |
|
|
6 | 11 |
$results = $DB->select( |
7 |
"SELECT * FROM dd_wordform limit 10" |
|
8 |
); |
|
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 |
$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 |
|
|
9 | 45 |
|
10 |
// (C) OUTPUT RESULTS |
|
11 |
$result = json_encode(count($results)==0 ? null : $results); |
|
12 |
echo $result; |
|
46 |
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 |
} |
application/model/DB.php | ||
---|---|---|
23 | 23 |
} |
24 | 24 |
|
25 | 25 |
// (C) RUN A SELECT QUERY |
26 |
function select($sql, $cond=null){
|
|
26 |
function select($sql, $params){
|
|
27 | 27 |
$result = false; |
28 | 28 |
try { |
29 | 29 |
$this->stmt = $this->pdo->prepare($sql); |
30 |
$this->stmt->execute($cond); |
|
30 |
if (array_key_exists("lemma", $params)) { |
|
31 |
$this->stmt->bindParam(':lemma',$params['lemma'], PDO::PARAM_STR); |
|
32 |
} |
|
33 |
if (array_key_exists("word", $params)) { |
|
34 |
$this->stmt->bindParam(':word',$params['word'], PDO::PARAM_STR); |
|
35 |
} |
|
36 |
if (array_key_exists("position1", $params)) { |
|
37 |
$this->stmt->bindParam(':position1',$params['position1'], PDO::PARAM_INT); |
|
38 |
} |
|
39 |
if (array_key_exists("position2", $params)) { |
|
40 |
$this->stmt->bindParam(':position2',$params['position2'], PDO::PARAM_INT); |
|
41 |
} |
|
42 |
if (array_key_exists("positiondetail", $params)) { |
|
43 |
$this->stmt->bindParam(':positiondetail',$params['positiondetail'], PDO::PARAM_INT); |
|
44 |
} |
|
45 |
if (array_key_exists("tag", $params)) { |
|
46 |
$this->stmt->bindParam(':tag',$params['tag'], PDO::PARAM_STR); |
|
47 |
} |
|
48 |
if (array_key_exists("tag", $params)) { |
|
49 |
$this->stmt->bindParam(':tag',$params['tag'], PDO::PARAM_STR); |
|
50 |
} |
|
51 |
if (array_key_exists("finished", $params)) { |
|
52 |
$this->stmt->bindParam(':finished',$params['finished']); |
|
53 |
} |
|
54 |
if (array_key_exists("manuscript", $params)) { |
|
55 |
for ($x = 0; $x < count($params["manuscript"]); $x += 1) { |
|
56 |
$this->stmt->bindParam(':manuscript'.$x,$params["manuscript"][$x], PDO::PARAM_INT); |
|
57 |
} |
|
58 |
} |
|
59 |
$this->stmt->execute(); |
|
31 | 60 |
$result = $this->stmt->fetchAll(); |
32 | 61 |
return $result; |
33 | 62 |
} catch (Exception $ex) { |
... | ... | |
39 | 68 |
|
40 | 69 |
// (D) DATABASE SETTINGS - CHANGE TO YOUR OWN! |
41 | 70 |
define('DB_HOST', 'localhost'); |
42 |
define('DB_NAME', 'dalimil1');
|
|
71 |
define('DB_NAME', 'dalimil2');
|
|
43 | 72 |
define('DB_CHARSET', 'utf8'); |
44 | 73 |
define('DB_USER', 'postgres'); |
45 | 74 |
define('DB_PASSWORD', 'a'); |
application/model/Lemma.php | ||
---|---|---|
1 |
<?php |
|
2 |
|
|
3 |
class Lemma { |
|
4 |
public $id; |
|
5 |
public $lemma; |
|
6 |
public $pos; |
|
7 |
|
|
8 |
public function __construct($id, $lemma, $pos) |
|
9 |
{ |
|
10 |
$this->id = $id; |
|
11 |
$this->lemma = $lemma; |
|
12 |
$this->pos = $pos; |
|
13 |
} |
|
14 |
} |
application/model/Tag.php | ||
---|---|---|
1 |
<?php |
|
2 |
|
|
3 |
class Tag { |
|
4 |
public $id; |
|
5 |
public $tag; |
|
6 |
|
|
7 |
function __construct($id, $tag) |
|
8 |
{ |
|
9 |
$this->id = $id; |
|
10 |
$this->tag = $tag; |
|
11 |
} |
|
12 |
} |
application/model/Word.php | ||
---|---|---|
1 |
<?php |
|
2 |
class Word { |
|
3 |
public $id; |
|
4 |
public $context; |
|
5 |
public $date; |
|
6 |
public $description; |
|
7 |
public $description2; |
|
8 |
public $description3; |
|
9 |
public $ending; |
|
10 |
public $finished; |
|
11 |
public $namedentity; |
|
12 |
public $position1; |
|
13 |
public $position2; |
|
14 |
public $positiondetail; |
|
15 |
public $word; |
|
16 |
public $lemma; |
|
17 |
public $tag; |
|
18 |
public $manuscript = Array(); |
|
19 |
|
|
20 |
function __construct($id, $context, $date, $description, $description2, $description3, $ending, $finished, $namedentity, $position1, $position2, $positiondetail, $word, $lemma, $tag) |
|
21 |
{ |
|
22 |
$this->id = $id; |
|
23 |
$this->context = $context; |
|
24 |
$this->date = $date; |
|
25 |
$this->description = $description; |
|
26 |
$this->description2 = $description2; |
|
27 |
$this->description3 = $description3; |
|
28 |
$this->ending = $ending; |
|
29 |
$this->finished = $finished; |
|
30 |
$this->namedentity = $namedentity; |
|
31 |
$this->position1 = $position1; |
|
32 |
$this->position2 = $position2; |
|
33 |
$this->positiondetail = $positiondetail; |
|
34 |
$this->word = $word; |
|
35 |
$this->lemma = $lemma; |
|
36 |
$this->tag = $tag; |
|
37 |
} |
|
38 |
} |
application/view/Index.php | ||
---|---|---|
6 | 6 |
function doSearch () { |
7 | 7 |
// (A1) GET SEARCH TERM |
8 | 8 |
var data = new FormData(); |
9 |
|
|
10 |
// (A2) AJAX - USE HTTP:// NOT FILE:// |
|
9 |
//data.append("manuscript", "0,3"); //příklad pro filtraci manuscriptů, asi se ještě uprav |
|
10 |
data.append("page", "0"); |
|
11 |
data.append("items_per_page", "50"); |
|
12 |
//data.append("finished", "false"); |
|
13 |
// data.append("tag_pos", "V"); |
|
14 |
// data.append("tag_verb_aspect", "P"); |
|
15 |
// data.append("tag_number", "S"); |
|
16 |
// data.append("word", "okáza"); |
|
11 | 17 |
var xhr = new XMLHttpRequest(); |
12 | 18 |
xhr.open("POST", "../controller/TableController.php"); |
13 | 19 |
xhr.onload = function(){ |
14 | 20 |
let results = document.getElementById("results"), |
15 |
search = this.response;
|
|
21 |
search = JSON.parse(this.response);
|
|
16 | 22 |
results.innerHTML = ""; |
17 | 23 |
console.log(search); |
18 |
let parsedJSON = JSON.parse(search); |
|
19 |
console.log(parsedJSON); |
|
20 |
if (parsedJSON != null) { for (let s of parsedJSON) { |
|
21 |
results.innerHTML += "<div>" + s.id + "</div>"; |
|
22 |
}} |
|
23 | 24 |
}; |
24 | 25 |
xhr.send(data); |
25 | 26 |
return false; |
Také k dispozici: Unified diff
Feature #8345 Implementce filterů dat - Server