Users Management
Managing your domain users.

Add User

Adding a new user to MQTT chat is done in two steps: first define user basic informations in post array. Then add him to your domain users using add function.
PHP
1
require_once vendor/autoload.php;
2
$users=new telifoun\mqttchat\users();
3
$post_array=array("userid"=>1,
4
"name"=>"foulen",
5
"surname"=>"ben foulen",
6
"profile_link"=>"",
7
"avatar_link"=>"",
8
"gender"=>telifoun\mqttchat\users::MALE);
9
$result=$users->add($post_array);
10
Copied!
1
{
2
"ok": true,
3
"data": {
4
"userid": 1
5
}
6
}
Copied!

Update User Informations

To edit existing user information’s, you should define the userid , informations to update then call update function.
PHP
1
require_once vendor/autoload.php;
2
$users=new telifoun\mqttchat\users();
3
$userid=1;
4
$post_array=array("name"=>"new name");
5
$result=$users->update($userid,$post_array);
Copied!
1
{
2
"ok": true,
3
"data": {
4
"name": "new name"
5
}
6
}
Copied!

Get User Informations

To verify that user information’s are changed, you can use get function. Do not forget to specify userid.
PHP
1
require_once vendor/autoload.php;
2
$users=new telifoun\mqttchat\users();
3
$userid=1;
4
$result=$users->get($userid);
Copied!
1
{
2
"ok": true,
3
"data": {
4
"userid": 1,
5
"name": "new name",
6
"surname": "ben foulen",
7
"gender": 0,
8
"avatar_link": "",
9
"profile_link": "",
10
"status": "offline",
11
"timestamp": 1607866409
12
}
13
}
Copied!

Delete user

If you want to delete a user, the delete function is made for that.
PHP
1
require_once vendor/autoload.php;
2
$users=new telifoun\mqttchat\users();
3
$userid=1;
4
$result=$users->delete($userid);
Copied!
1
{
2
"ok": true,
3
"data": {
4
"userid": 1
5
}
6
}
Copied!

Get All Users

You can get all users of your domain in groups of 100 users max. You can also filter them by presence status and/or by gender.
PHP
1
require_once vendor/autoload.php;
2
$users=new telifoun\mqttchat\users();
3
$after_userid=1; //get users having userid > 1
4
$limit=20; //number of results to return (max 100)
5
$online=1; // get only users having status online
6
$gender=1; // get only womens
7
$result=$users->getByPage($after_userid,$limit,$online,$gender);
Copied!
1
{
2
"ok": true,
3
"data": {
4
"query": {
5
"after_userid": 1,
6
"limit": 1
7
},
8
"users": [
9
{
10
"userid": 2,
11
"name": "Gaddour",
12
"surname": "Mohamed",
13
"profile_link": "",
14
"avatar_link": "",
15
"gender": 0,
16
"status": "offline",
17
"timestamp": 1607858164
18
}
19
]
20
}
21
}
Copied!

Delete All Users

deleteAll() function will delete all users of your domain, absolutely all.
🧐
Be careful using this function.
🧐
PHP
1
require_once vendor/autoload.php;
2
$users=new telifoun\mqttchat\users();
3
$result=$users->deleteAll();
Copied!
1
{
2
"ok": true,
3
"data": 3
4
}
Copied!
Last modified 8mo ago