Projekt

Obecné

Profil

« Předchozí | Další » 

Revize b9ed6a80

Přidáno uživatelem Tomáš Pašek před více než 3 roky(ů)

Feature #8345 Implementce filterů dat - Server

vytvořené objekty databáze, posílání json objektu klientu

Zobrazit rozdíly:

application/controller/TableController.php
1 1
<?php
2 2
require "../model/DB.php";
3
require "../model/Tag.php";
4
require "../model/Word.php";
3 5
$DB = new DB();
4 6

  
5 7
// (B) SEARCH FOR USERS
6 8
$results = $DB->select(
7
    "SELECT * FROM dd_wordform limit 10"
9
    "SELECT w.id, w.context, w.date, w.description, w.description2, w.description3, w.ending, w.finished,
10
w.namedentity, w.position1, w.position2, w.positiondetail, w.word, w.tag_id, w.lemma_id, t.tag, l.lemma, 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 order by w.id LIMIT 100"
8 11
);
9 12

  
10
// (C) OUTPUT RESULTS
11
$result = json_encode(count($results)==0 ? null : $results);
13
var_dump($results);
14

  
15
$output = Array();
16
foreach ($results as $res) {
17
    $tag = new Tag($res["tag_id"], $res["tag"]);
18
    $lemma = new Lemma($res["lemma_id"], $res["lemma"], $res["pos"]);
19
    $word = new Word($res["id"],  $res["context"], $res["date"], $res["description"], $res["description2"], $res["description3"], $res["ending"],
20
        $res["finished"], $res["namedentity"], $res["position1"], $res["position2"], $res["positiondetail"], $res["word"], $lemma, $tag);
21
    array_push($output, $word);
22
}
23

  
24
$result = json_encode(count($output)==0 ? null : $output);
12 25
echo $result;
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

  
19
    function __construct($id, $context, $date, $description, $description2, $description3, $ending, $finished, $namedentity, $position1, $position2, $positiondetail, $word, $lemma, $tag)
20
    {
21
        $this->id = $id;
22
        $this->context = $context;
23
        $this->date = $date;
24
        $this->description = $description;
25
        $this->description2 = $description2;
26
        $this->description3 = $description3;
27
        $this->ending = $ending;
28
        $this->finished = $finished;
29
        $this->namedentity = $namedentity;
30
        $this->position1 = $position1;
31
        $this->position2 = $position2;
32
        $this->positiondetail = $positiondetail;
33
        $this->word = $word;
34
        $this->lemma = $lemma;
35
        $this->tag = $tag;
36
    }
37
}
application/view/Index.php
6 6
    function doSearch () {
7 7
        // (A1) GET SEARCH TERM
8 8
        var data = new FormData();
9

  
10 9
        // (A2) AJAX - USE HTTP:// NOT FILE://
11 10
        var xhr = new XMLHttpRequest();
12 11
        xhr.open("POST", "../controller/TableController.php");

Také k dispozici: Unified diff