public function onUserLogout($user) { if (\Session::has('kandyLiveChatUserInfo')) { \Session::pull('kandyLiveChatUserInfo'); } $kandyUser = KandyUsers::where('main_user_id', $user->id)->first(); //if login user is a chat agent if ($kandyUser) { $userLogin = KandyUserLogin::where('kandy_user_id', $kandyUser->user_id)->first(); if (!empty($userLogin) && $user->can('admin') == false) { $userLogin->status = Kandylaravel::USER_STATUS_OFFLINE; $userLogin->save(); } if (\Session::has('userAccessToken.' . $kandyUser->user_id)) { \Session::pull('userAccessToken.' . $kandyUser->user_id); } $kandyLaravel = new Kandylaravel(); $full_user_id = $kandyUser->main_user_id . '@' . $kandyUser->domain_name; $kandyLaravel->getLastSeen([$full_user_id]); } }
/** * Initialize data of widget * @param $data */ public function init($data) { if (!isset($data["id"])) { $data["id"] = "chat-" . rand(); } else { $this->id = $data["id"]; } if (!isset($data["class"])) { $data["class"] = $this->class; } else { $data["class"] = $this->class . " " . $data["class"]; $this->class = $data["class"]; } //init options $attributes = array("contact", "message", "user"); if (!isset($data["options"])) { $data["options"] = array(); } foreach ($attributes as $attr) { //callOut Area Init if (isset($data["options"][$attr])) { //params $comAttributes = $data["options"][$attr]; //default value $defaultComAttributes = $this->options[$attr]; foreach ($comAttributes as $comAttributeKey => $comAttribute) { if (!isset($data["options"][$attr][$comAttributeKey])) { $data["options"][$attr][$comAttributeKey] = $defaultComAttributes[$comAttributeKey]; } } } else { //use default value $data["options"][$attr] = $this->options[$attr]; } } //end init options if (!isset($data["htmlOptions"])) { $data['htmlOptions'] = $this->htmlOptions; } $htmlOptionsAttributes = ""; if (!empty($data['htmlOptions'])) { if (!isset($data["htmlOptions"]["style"])) { $data['htmlOptions']['style'] = $this->htmlOptions["style"]; } else { $this->htmlOptions = $data['htmlOptions']; } foreach ($data['htmlOptions'] as $key => $value) { if ($key != "id" && $key != "class" && $key != "style") { $htmlOptionsAttributes .= $key . "= '" . $value . "'"; } elseif ($key == "style") { $style = ""; foreach ($value as $k => $v) { $style .= $k . ":" . $v . ";"; } $htmlOptionsAttributes = $key . '=' . $style; } } } $data["htmlOptionsAttributes"] = $htmlOptionsAttributes; $kandylaravel = new Kandylaravel(); $kandy_user_id = $data["options"]['user']['name']; $data["displayName"] = $kandylaravel->getDisplayNameFromKandyUser($kandy_user_id); $data["kandyUser"] = $data["options"]['user']['kandyUser']; if ($kandy_user_id) { //check if user is now inactive, then active user if (KandyUsers::where('user_id', $kandy_user_id)->where('type', Kandylaravel::USER_TYPE_CHAT_AGENT)) { $userLogin = KandyUserLogin::where('kandy_user_id', $kandy_user_id)->where('status', Kandylaravel::USER_STATUS_OFFLINE)->first(); if ($userLogin) { $userLogin->status = Kandylaravel::USER_STATUS_ONLINE; $userLogin->save(); } } } $this->data = $data; }
/** * Get Kandy user by full user id * * @param $full_user_id * @return string */ public function getKandyUserByFullUserId($full_user_id) { $arrFullUserId = explode('@', $full_user_id); $userId = $arrFullUserId[0]; $domain = $arrFullUserId[1]; $user = KandyUsers::where('user_id', $userId)->where('domain_name', $domain)->first(); if (!empty($user)) { return $user; } return null; }