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.
require_once vendor/autoload.php;$users=new telifoun\mqttchat\users();$post_array=array("userid"=>1,"name"=>"foulen","surname"=>"ben foulen","profile_link"=>"","avatar_link"=>"","gender"=>telifoun\mqttchat\users::MALE);$result=$users->add($post_array);
{"ok": true,"data": {"userid": 1}}
To edit existing user information’s, you should define the userid ,
informations to update then call update
function.
require_once vendor/autoload.php;$users=new telifoun\mqttchat\users();$userid=1;$post_array=array("name"=>"new name");$result=$users->update($userid,$post_array);
{"ok": true,"data": {"name": "new name"}}
To verify that user information’s are changed, you can use get
function. Do not forget to specify userid
.
require_once vendor/autoload.php;$users=new telifoun\mqttchat\users();$userid=1;$result=$users->get($userid);
{"ok": true,"data": {"userid": 1,"name": "new name","surname": "ben foulen","gender": 0,"avatar_link": "","profile_link": "","status": "offline","timestamp": 1607866409}}
If you want to delete a user, the delete
function is made for that.
require_once vendor/autoload.php;$users=new telifoun\mqttchat\users();$userid=1;$result=$users->delete($userid);
{"ok": true,"data": {"userid": 1}}
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.
require_once vendor/autoload.php;$users=new telifoun\mqttchat\users();$after_userid=1; //get users having userid > 1$limit=20; //number of results to return (max 100)$online=1; // get only users having status online$gender=1; // get only womens$result=$users->getByPage($after_userid,$limit,$online,$gender);
{"ok": true,"data": {"query": {"after_userid": 1,"limit": 1},"users": [{"userid": 2,"name": "Gaddour","surname": "Mohamed","profile_link": "","avatar_link": "","gender": 0,"status": "offline","timestamp": 1607858164}]}}
deleteAll()
function will delete all users of your domain, absolutely all. 🧐 Be careful using this function. 🧐
require_once vendor/autoload.php;$users=new telifoun\mqttchat\users();$result=$users->deleteAll();
{"ok": true,"data": 3}