-
Notifications
You must be signed in to change notification settings - Fork 0
/
tagRelationResist.php
256 lines (247 loc) · 7.18 KB
/
tagRelationResist.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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Tag search relarion resister</title>
</head>
<body>
<?php
ini_set( 'display_errors', 1 );
require_once("cmn/debug.php");
require_once("cmn/utils.php");
require_once("cmn/specialTagIDList.php");
$addTagName = $_REQUEST['addTagName'];//追加するタグ名
$targetTagIDFrom = $_REQUEST['targetTagIDFrom'];//親になるタグのID
$targetArticleIDTo = $_REQUEST['targetArticleIDTo'];//タグを関連付ける記事I
$pdo = db_open();
//サジェスト親子関係存在確認
$sql = "SELECT `Tag`.* , `userP`.`name` AS userProfile FROM `Tag` AS userP ,`User_TBL` INNER JOIN `Tag` ON `User_TBL` . `profileID` = `Tag` . `owner` WHERE `Tag` .`name` LIKE '$addTagName' AND `userP`.`ID` = `User_TBL` . `profileID`";
$tagIDfinding = $pdo->query($sql);//既存のタグを探す一層の並列関係のみ
$i = 0;
while ($row = $tagIDfinding->fetch()) {
$name = htmlspecialchars($row['name']);
$ID = htmlspecialchars($row['ID']);
$owner = htmlspecialchars($row['owner']);
$userProfile = htmlspecialchars($row['userProfile']);
$Tag = array(
'name' => $name,
'ID' => $ID,
'ownerID' => $owner,
'userProfile' => $userProfile
);
$tagA[$i] = $Tag;
$i++;
}
print_r ($tagA);//ここに複数のタグを入れる
if ($tagA == null) {
echo "タグを登録してください";
} else {
echo "親子関係を調査します";
foreach ($tagA as $eachTag){
echo "<br>当該タグID";
print_r ($eachTag[ID]);//既存のタグのID
$childTagID = $eachTag[ID];
$sql = "SELECT `tagLink`.`LFrom` AS TLFROM, `Tag` . * FROM `LINK` INNER JOIN `LINK` AS tagLink ON `LINK`.`ID` = `tagLink`.`LTo`, `Tag` WHERE `LINK`.`LFrom` =$targetTagIDFrom AND `tagLink`.`LFrom` =$tagSSugID AND `Tag` . `ID` = `LINK` . `LTo` AND `LINK`.`LTo` = $childTagID;"; //親タグと当該タグのリンク重複を調べる
$relationSQL = $pdo->query($sql);
$h = 0;
while ($row = $relationSQL->fetch()) {
$replyName = htmlspecialchars($row['name']);
$replyID = htmlspecialchars($row['ID']);
$ownerID = htmlspecialchars($row['owner']);
$CreatedTime = htmlspecialchars($row['Created_time']);
$relationA = array(
'name' => $replyName,
'owner' => $ownerID,
'CreatedTime' => $CreatedTime,
'ID' => $replyID
);
$relation[$h] = $relationA;
$h++;
}
print_r ($relation);
if ($relation == null){ //既存のタグと重複していなかったら
echo "親子関係が存在していません";
//親タグと子供タグのリンクを作成
$pdo->beginTransaction();
$sql = "INSERT INTO `db0tagplus`.`LINK` (
`ID` ,
`LFrom` ,
`LTo` ,
`quant` ,
`owner`
)
VALUES (
NULL , '$targetTagIDFrom', '$childTagID', '$ownerID', '1'
);";
$pdo->exec($sql);
$lastAIID = $pdo->lastInsertId('ID');
$pdo->commit();
$pdo->beginTransaction();//元記事-返信リンクと返信タグリンクを作成
$sql = "INSERT INTO `db0tagplus`.`LINK` (
`ID` ,
`LFrom` ,
`LTo` ,
`quant` ,
`owner`,
`Created_time`
)
VALUES (
NULL , '$tagSSugID', '$lastAIID', '1', '$ownerID', NOW( )
);";
$pdo->exec($sql);
$pdo->commit();
} else {
echo "親子関係がすでに存在します";
}
}
}
/*
//検索関係が子供である場合重複していないか確かめる
$sql = "SELECT `Tag`.* , `userP`.`name` AS userProfile FROM `Tag` AS userP ,`User_TBL` INNER JOIN `Tag` ON `User_TBL` . `profileID` = `Tag` . `owner` WHERE `Tag` .`name` LIKE '$addTagName' AND `userP`.`ID` = `User_TBL` . `profileID`";
$tagIDfinding = $pdo->query($sql);//既存のタグを探す一層の並列関係のみ
$i = 0;
while ($row = $tagIDfinding->fetch()) {
$name = htmlspecialchars($row['name']);
$ID = htmlspecialchars($row['ID']);
$owner = htmlspecialchars($row['owner']);
$userProfile = htmlspecialchars($row['userProfile']);
$Tag = array(
'name' => $name,
'ID' => $ID,
'ownerID' => $owner,
'userProfile' => $userProfile
);
$tagA[$i] = $Tag;
$i++;
}
print_r ($tagA);//ここに複数のタグを入れる
if ($tagA == null) {//既存のタグが存在しなかったら、新規追加
echo "新規追加";
//タグを追加する
$pdo->beginTransaction();
$sql = "INSERT INTO `db0tagplus`.`Tag` (
`ID` ,
`name` ,
`owner`
)
VALUES (
NULL , '$addTagName', '1'
);";
$pdo->exec($sql);
$lastAIID = $pdo->lastInsertId('ID');//新規に追加したタグIDを
$pdo->commit();
print_r ($lastAIID);
$pdo->beginTransaction();//既存の記事とタグのリンク作成
$sql = "INSERT INTO `db0tagplus`.`LINK` (
`ID` ,
`LFrom` ,
`LTo` ,
`quant` ,
`owner`
)
VALUES (
NULL , '$lastAIID', '$targetArticleIDTo', '1', '1'
);";
$pdo->exec($sql); $pdo->commit();
//親タグと子供タグのリンクを作成
$pdo->beginTransaction();
$sql = "INSERT INTO `db0tagplus`.`LINK` (
`ID` ,
`LFrom` ,
`LTo` ,
`quant` ,
`owner`
)
VALUES (
NULL , '$targetTagIDFrom', '$lastAIID', '1', '1'
);";
$pdo->exec($sql);
$lastAIID = $pdo->lastInsertId('ID');
$pdo->commit();
$pdo->beginTransaction();//元記事-返信リンクと返信タグリンクを作成
$sql = "INSERT INTO `db0tagplus`.`LINK` (
`ID` ,
`LFrom` ,
`LTo` ,
`quant` ,
`owner`,
`Created_time`
)
VALUES (
NULL , '$tagSSugID', '$lastAIID', '1', '$ownerID', NOW( )
);";
$pdo->exec($sql);
$pdo->commit();
} else {
echo "関係追加";
//既存のタグがすでに当該記事にリンク付されているのか調べる
foreach ($tagA as $eachTag){
echo "<br>当該タグID";
print_r ($eachTag[ID]);//既存のタグのID
$From = $eachTag[ID];
$sql = "SELECT `LINK` . `ID` From `LINK` WHERE `LINK` .`LFrom` = $eachTag[ID] AND `LINK` .`LTo` = $targetArticleIDTo;"; //当該記事と当該タグのリンクを調べる
$existingLink = $pdo->query($sql);
$i = 0;
while ($row = $existingLink->fetch()) {
$linkID = htmlspecialchars($row['ID']);
$Link = array(
'ID' => $linkID
);
$LinkA[$i] = $Link;
$i++;
}
print_r ($LinkA);
if ($LinkA == null){ //既存のタグと重複していなかったら
echo "重複していない";
echo "リンクFrom追加 $From";
$pdo->beginTransaction();
$sql = "INSERT INTO `db0tagplus`.`LINK` (
`ID` ,
`LFrom` ,
`LTo` ,
`quant` ,
`owner`
)
VALUES (
NULL , '$From', '$targetArticleIDTo', '1', '1'
);";
$pdo->exec($sql);
$lastAIID = $pdo->lastInsertId('ID');
$pdo->commit();
//親タグと子供タグのリンクを作成
$pdo->beginTransaction();
$sql = "INSERT INTO `db0tagplus`.`LINK` (
`ID` ,
`LFrom` ,
`LTo` ,
`quant` ,
`owner`
)
VALUES (
NULL , '$targetTagIDFrom', '$lastAIID', '1', '1'
);";
$pdo->exec($sql);
$lastAIID = $pdo->lastInsertId('ID');
$pdo->commit();
$pdo->beginTransaction();//元記事-返信リンクと返信タグリンクを作成
$sql = "INSERT INTO `db0tagplus`.`LINK` (
`ID` ,
`LFrom` ,
`LTo` ,
`quant` ,
`owner`,
`Created_time`
)
VALUES (
NULL , '$tagSSugID', '$lastAIID', '1', '$ownerID', NOW( )
);";
$pdo->exec($sql);
$pdo->commit();
} else {
//タグ付けが重複している場合親子関係だけを追加
}
}
}
*/
?>
</body>
/*</html>