@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | namespace ChatApp; |
4 | -require_once (dirname(__DIR__) . '/vendor/autoload.php'); |
|
4 | +require_once (dirname(__DIR__).'/vendor/autoload.php'); |
|
5 | 5 | use ChatApp\Time; |
6 | 6 | use Dotenv\Dotenv; |
7 | 7 | $dotenv = new Dotenv(dirname(__DIR__)); |
@@ -34,20 +34,20 @@ discard block |
||
34 | 34 | $userId = $suggestion->userId; |
35 | 35 | $suggestion = trim($suggestion->value); |
36 | 36 | $flag = 0; |
37 | - if(!empty($userId) && !empty($suggestion)) |
|
37 | + if (!empty($userId) && !empty($suggestion)) |
|
38 | 38 | { |
39 | 39 | $query = "SELECT * FROM login where login_id != '$userId' and name like '$suggestion%' ORDER BY name DESC"; |
40 | - if($result = $this->connect->query($query)) |
|
40 | + if ($result = $this->connect->query($query)) |
|
41 | 41 | { |
42 | - if($result->num_rows > 0) |
|
42 | + if ($result->num_rows > 0) |
|
43 | 43 | { |
44 | - while($row = $result->fetch_assoc()) |
|
44 | + while ($row = $result->fetch_assoc()) |
|
45 | 45 | { |
46 | 46 | $check_id = $row["login_id"]; |
47 | 47 | $query = "SELECT * from total_message where (user1 = '$check_id' and user2 = '$userId') or (user2 = '$check_id' and user1 = '$userId')"; |
48 | - if($result1 = $this->connect->query($query)) |
|
48 | + if ($result1 = $this->connect->query($query)) |
|
49 | 49 | { |
50 | - if($result1->num_rows > 0) |
|
50 | + if ($result1->num_rows > 0) |
|
51 | 51 | { |
52 | 52 | $fetch = $result1->fetch_assoc(); |
53 | 53 | $fetch['time'] = $this->obTime->timeConversion($fetch['time']); |
@@ -59,7 +59,7 @@ discard block |
||
59 | 59 | } |
60 | 60 | } |
61 | 61 | } |
62 | - if($flag != 0) |
|
62 | + if ($flag != 0) |
|
63 | 63 | { |
64 | 64 | $this->array = array_merge([], ["Search" => $this->array]); |
65 | 65 | return json_encode($this->array); |
@@ -36,13 +36,13 @@ discard block |
||
36 | 36 | |
37 | 37 | public function onMessage(ConnectionInterface $from, $msg) |
38 | 38 | { |
39 | - $msg = (object) json_decode($msg); |
|
40 | - if($msg->type == 'OpenChat initiated..!') |
|
39 | + $msg = (object)json_decode($msg); |
|
40 | + if ($msg->type == 'OpenChat initiated..!') |
|
41 | 41 | { |
42 | - $initial = (object) array(); |
|
42 | + $initial = (object)array(); |
|
43 | 43 | $initial->initial = json_decode($this->onSidebar($from->userId)); |
44 | 44 | |
45 | - if($initial->initial != null) |
|
45 | + if ($initial->initial != null) |
|
46 | 46 | { |
47 | 47 | $initial->conversation = json_decode( |
48 | 48 | $this->onConversation( |
@@ -58,14 +58,14 @@ discard block |
||
58 | 58 | } |
59 | 59 | elseif ($msg->type == 'Load Sidebar') |
60 | 60 | { |
61 | - $sidebar = (object) array(); |
|
61 | + $sidebar = (object)array(); |
|
62 | 62 | $sidebar->sidebar = json_decode($this->onSidebar($from->userId)); |
63 | 63 | $from->send(json_encode($sidebar)); |
64 | 64 | } |
65 | 65 | elseif ($msg->type == 'Initiated') |
66 | 66 | { |
67 | 67 | $msg->userId = $from->userId; |
68 | - $result = (object) array(); |
|
68 | + $result = (object)array(); |
|
69 | 69 | $result->conversation = json_decode($this->onConversation(json_encode($msg), False)); |
70 | 70 | $from->send(json_encode($result)); |
71 | 71 | } |
@@ -87,8 +87,8 @@ discard block |
||
87 | 87 | $getReturn = $this->onReply($msg); |
88 | 88 | echo $getReturn; |
89 | 89 | |
90 | - $receiveResult = (object) array(); |
|
91 | - $sentResult = (object) array(); |
|
90 | + $receiveResult = (object)array(); |
|
91 | + $sentResult = (object)array(); |
|
92 | 92 | foreach ($this->clients as $client) |
93 | 93 | { |
94 | 94 | if ($client->userId == $msg->name) |
@@ -107,7 +107,7 @@ discard block |
||
107 | 107 | |
108 | 108 | $client->send(json_encode($receiveResult)); |
109 | 109 | } |
110 | - elseif($client == $from) |
|
110 | + elseif ($client == $from) |
|
111 | 111 | { |
112 | 112 | $sentResult->sidebar = json_decode($this->onSidebar($client->userId)); |
113 | 113 |
@@ -55,33 +55,28 @@ discard block |
||
55 | 55 | ); |
56 | 56 | } |
57 | 57 | $from->send(json_encode($initial)); |
58 | - } |
|
59 | - elseif ($msg->type == 'Load Sidebar') |
|
58 | + } elseif ($msg->type == 'Load Sidebar') |
|
60 | 59 | { |
61 | 60 | $sidebar = (object) array(); |
62 | 61 | $sidebar->sidebar = json_decode($this->onSidebar($from->userId)); |
63 | 62 | $from->send(json_encode($sidebar)); |
64 | - } |
|
65 | - elseif ($msg->type == 'Initiated') |
|
63 | + } elseif ($msg->type == 'Initiated') |
|
66 | 64 | { |
67 | 65 | $msg->userId = $from->userId; |
68 | 66 | $result = (object) array(); |
69 | 67 | $result->conversation = json_decode($this->onConversation(json_encode($msg), False)); |
70 | 68 | $from->send(json_encode($result)); |
71 | - } |
|
72 | - elseif ($msg->type == 'Search') |
|
69 | + } elseif ($msg->type == 'Search') |
|
73 | 70 | { |
74 | 71 | $msg->userId = $from->userId; |
75 | 72 | $searchResult = $this->onSearch($msg); |
76 | 73 | $from->send($searchResult); |
77 | - } |
|
78 | - elseif ($msg->type == 'Compose') |
|
74 | + } elseif ($msg->type == 'Compose') |
|
79 | 75 | { |
80 | 76 | $msg->userId = $from->userId; |
81 | 77 | $composeResult = $this->onCompose($msg); |
82 | 78 | $from->send($composeResult); |
83 | - } |
|
84 | - else |
|
79 | + } else |
|
85 | 80 | { |
86 | 81 | $msg->userId = $from->userId; |
87 | 82 | $getReturn = $this->onReply($msg); |
@@ -106,8 +101,7 @@ discard block |
||
106 | 101 | ); |
107 | 102 | |
108 | 103 | $client->send(json_encode($receiveResult)); |
109 | - } |
|
110 | - elseif($client == $from) |
|
104 | + } elseif($client == $from) |
|
111 | 105 | { |
112 | 106 | $sentResult->sidebar = json_decode($this->onSidebar($client->userId)); |
113 | 107 |