-
Notifications
You must be signed in to change notification settings - Fork 1
/
routepoetry.php
128 lines (102 loc) · 3.59 KB
/
routepoetry.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
<?php
function randomdisplay($data,$num) {
if($num==NULL){
$poetry=$data->query("select * from poetries order by rand( ) limit 1;")->fetchAll();
echo $poetry[0]['title'];
echo '</br>';
echo $poetry[0]['content'];
}else{
$poetries=$data->query("select * from poetries order by rand( ) limit ".$num.";")->fetchAll();
foreach ($poetries as $poetry){
echo $poetry['title'];
echo '</br>';
echo $poetry['content'];
}
}
}
function randomhandlewithjson($data,$num){
if($num==NULL){
$poetry=$data->query("select * from poetries order by rand( ) limit 1;")->fetchAll();
echo Flight::json($poetry);
}else{
$poetries=$data->query("select * from poetries order by rand( ) limit ".$num.";")->fetchAll();
echo Flight::json($poetries);
}
}
Flight::route('/poetry/random(/@num:[0-9]{1,99})(/@display)',function($num,$display){
$data=Flight::get('database');
if($display!=NULL)
randomdisplay($data,$num);
else
randomhandlewithjson($data,$num);
});
function namedisplay($data,$name){
$poetries=$data->select("poetries",["title","content"],["title[~]"=>$name]);
foreach ($poetries as $poetry){
echo $poetry['title'];
echo '</br>';
echo $poetry['content'];
}
}
function namehandlewithjson($data,$name){
$poetries=$data->select("poetries","*",["title[~]"=>$name]);
echo Flight::json($poetries);
}
Flight::route('/poetry/name/@name(/@display)',function($name,$display){
$data=Flight::get('database');
if($display!=NULL)
namedisplay($data,$name);
else
namehandlewithjson($data,$name);
});
function authorhandlewithjson($data,$author){
/**
echo 'test start';
$table='poetries';
$columns=["poetries.title","poetries.content"];
$join=[ "[>]poets"=>["poet_id"=>"id"] ];
$where=["LIMIT" => 50];
**/
$query="select poetries.* from poetries left join poets on poetries.poet_id=poets.id where poets.name=:name";
$poetries=$data->query($query,["name"=>$author])->fetchAll();
Flight::json($poetries);
}
function authordisplay($data,$author){
$query="select poetries.* from poetries left join poets on poetries.poet_id=poets.id where poets.name=:name";
$poetries=$data->query($query,["name"=>$author])->fetchAll();
foreach($poetries as $poetry){
echo $poetry['title'];
echo '</br>';
echo $poetry['content'];
echo '</br>';
}
}
Flight::route('/poetry/author/@author(/@display)',function($author,$display){
$data=Flight::get('database');
if($display!=NULL)
authordisplay($data,$author);
else
authorhandlewithjson($data,$author);
});
function authorbynamehandlewithjson($data,$author,$name){
$query="select poetries.* from poetries left join poets on poetries.poet_id=poets.id where poets.name=:name and poetries.title like :title";
$poetries=$data->query($query,["name"=>$author,"title"=>"%".$name."%"])->fetchAll();
Flight::json($poetries);
}
function authorbynamedisplay($data,$author,$name){
$query="select poetries.* from poetries left join poets on poetries.poet_id=poets.id where poets.name=:name and poetries.title like :title";
$poetries=$data->query($query,["name"=>$author,"title"=>"%".$name."%"])->fetchAll();
foreach($poetries as $poetry){
echo $poetry['title'];
echo '</br>';
echo $poetry['content'];
echo '</br>';
}
}
Flight::route('/poetry/author/@author/name/@name(/@display)',function($author,$name,$display){
$data=Flight::get('database');
if($display!=NULL)
authorbynamedisplay($data,$author,$name);
else
authorbynamehandlewithjson($data,$author,$name);
});