1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Receiver Class Doc Comment |
4
|
|
|
* |
5
|
|
|
* PHP version 5 |
6
|
|
|
* |
7
|
|
|
* @category PHP |
8
|
|
|
* @package OpenChat |
9
|
|
|
* @author Ankit Jain <[email protected]> |
10
|
|
|
* @license The MIT License (MIT) |
11
|
|
|
* @link https://github.com/ankitjain28may/openchat |
12
|
|
|
*/ |
13
|
|
|
namespace ChatApp; |
14
|
|
|
|
15
|
|
|
require_once dirname(__DIR__).'/vendor/autoload.php'; |
16
|
|
|
use ChatApp\User; |
17
|
|
|
use ChatApp\Conversation; |
18
|
|
|
use mysqli; |
19
|
|
|
use Dotenv\Dotenv; |
20
|
|
|
$dotenv = new Dotenv(dirname(__DIR__)); |
21
|
|
|
$dotenv->load(); |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Send message to other user |
25
|
|
|
* |
26
|
|
|
* @category PHP |
27
|
|
|
* @package OpenChat |
28
|
|
|
* @author Ankit Jain <[email protected]> |
29
|
|
|
* @license The MIT License (MIT) |
30
|
|
|
* @link https://github.com/ankitjain28may/openchat |
31
|
|
|
*/ |
32
|
|
|
class Receiver |
33
|
|
|
{ |
34
|
|
|
/* |
35
|
|
|
|-------------------------------------------------------------------------- |
36
|
|
|
| Receiver Class |
37
|
|
|
|-------------------------------------------------------------------------- |
38
|
|
|
| |
39
|
|
|
| Send message to other user. |
40
|
|
|
| |
41
|
|
|
*/ |
42
|
|
|
|
43
|
|
|
protected $obUser; |
44
|
|
|
protected $conversation; |
45
|
|
|
protected $messages; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Create a new class instance. |
49
|
|
|
* |
50
|
|
|
* @return void |
|
|
|
|
51
|
|
|
*/ |
52
|
|
|
public function __construct() |
53
|
|
|
{ |
54
|
|
|
$this->obUser = new User(); |
55
|
|
|
$this->conversation = new Conversation(); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Swaping value of conversation class to modify them for receiver |
60
|
|
|
* |
61
|
|
|
* @param string $msg To store message |
62
|
|
|
* @param boolean $para To store True/False |
63
|
|
|
* |
64
|
|
|
* @return string |
65
|
|
|
*/ |
66
|
|
|
public function receiverLoad($msg, $para) |
67
|
|
|
{ |
68
|
|
|
$msg = json_decode($msg); |
69
|
|
|
$id2 = $msg->userId; |
70
|
|
|
$this->messages = $this->obUser->userDetails($id2, $para); |
|
|
|
|
71
|
|
|
$username = $this->messages['username']; |
72
|
|
|
$name = $this->messages['name']; |
73
|
|
|
$id1 = $msg->details; |
74
|
|
|
$msg->details = bin2hex(convert_uuencode($msg->details)); |
75
|
|
|
$msg = json_encode($msg); |
76
|
|
|
$this->messages = json_decode( |
77
|
|
|
$this->conversation->conversationLoad($msg, $para) |
78
|
|
|
); |
79
|
|
|
// $id1 = json_decode($msg)->details; |
80
|
|
|
for ($i = 1; $i < count($this->messages); $i++) { |
|
|
|
|
81
|
|
|
$this->messages[$i]->start = $id1; |
82
|
|
|
} |
83
|
|
|
$id2 = bin2hex(convert_uuencode($id2)); |
84
|
|
|
|
85
|
|
|
$this->messages[0]->username = $username; |
86
|
|
|
$this->messages[0]->name = $name; |
87
|
|
|
$this->messages[0]->id = $id2; |
88
|
|
|
return json_encode($this->messages); |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
|
Adding a
@return
annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.