/
showTweet.php
62 lines (47 loc) · 1.47 KB
/
showTweet.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
<?php
require_once("./src/connections.php");
if (isset($_SESSION['userId']) !== TRUE) {
header("Location: login.php");
}
if (isset($_GET['id'])) {
$id = $_GET['id'];
}
$tweetToShow = Tweet::LoadTweetById($id);
$userId = (int)($tweetToShow->getUserId());
$user = User::GetUserById($userId);
echo("<h1> {$user->getName()}</h1>");
echo($tweetToShow->getTweetText() . "<br>");
echo($tweetToShow->getTweetDate() . "<br />");
$coms = count($tweetToShow->getAllComments());
if($_SESSION['userId'] == $userId){
echo("<a href='editTweet.php?id=$id'> Edytuj</a>");
echo("<a href='removeTweet.php?id=$id'> Usuń</a>");
}
echo("<br>Liczba komentarzy: $coms ");
echo("<hr />");
echo("
<form method='post'>
<label>
<input type='text' name='comment' placeholder='wpisz swój komentarz'>
</label>
<input type='submit'>
</form>
");
foreach ($tweetToShow->getAllComments() as $comment) {
$idOfCommentingUser = $comment->getUserId();
$commentingUser = User::GetUserById($idOfCommentingUser);
echo("<h3>{$commentingUser->getName()}</h3>");
echo($comment->getCommentText() . "<br>");
echo($comment->getCommentDate() . "<br>");
echo("<hr />");
}
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
if (strlen($_POST['comment']) > 0) {
$commentText = $_POST['comment'];
$comment = Comment::CreateComment(($_GET['id']), $commentText);
header("Location: showTweet.php?id=$id");
return $comment;
}
return false;
}
?>