Skip to content

Commit

Permalink
REST API to change visibility
Browse files Browse the repository at this point in the history
  • Loading branch information
remdex committed Oct 2, 2016
1 parent 9a8b9a2 commit 77f5149
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<?php include_once(erLhcoreClassDesign::designtpl('lhchat/user_settings_sound.tpl.php'));?>

<?php if ($canChangeVisibilityMode == true) : ?>
<li><a href="#"><i class="material-icons" title="<?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('chat/user_settings','Change my visibility to visible/invisible');?>" onclick="return lhinst.changeVisibility($(this))"><?php $UserData->invisible_mode == 1 ? print 'visibility_off' : print 'visibility'?></i></a></li>
<li><a href="#"><i id="vi-in-user" class="material-icons" title="<?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('chat/user_settings','Change my visibility to visible/invisible');?>" onclick="return lhinst.changeVisibility($(this))"><?php $UserData->invisible_mode == 1 ? print 'visibility_off' : print 'visibility'?></i></a></li>
<?php endif;?>

<?php if ($canChangeOnlineStatus == true) : ?>
Expand Down
4 changes: 4 additions & 0 deletions lhc_web/modules/lhrestapi/module.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@
'params' => array()
);

$ViewList['setvisibilitystatus'] = array(
'params' => array()
);

$ViewList['isonline'] = array(
'params' => array()
);
Expand Down
54 changes: 54 additions & 0 deletions lhc_web/modules/lhrestapi/setvisibilitystatus.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept');
header('Content-Type: application/json');

try {
erLhcoreClassRestAPIHandler::validateRequest();

if (isset($_GET['user_id']) && is_numeric($_GET['user_id'])) {
$userData = erLhcoreClassModelUser::fetch((int) $_GET['user_id']);
} elseif (isset($_GET['username']) && ! empty($_GET['username'])) {
$userData = erLhcoreClassModelUser::findOne(array(
'filter' => array(
'username' => $_GET['username']
)
));
} elseif (isset($_GET['email']) && ! empty($_GET['email'])) {
$userData = erLhcoreClassModelUser::findOne(array(
'filter' => array(
'email' => $_GET['email']
)
));
}

if (! ($userData instanceof erLhcoreClassModelUser)) {
throw new Exception('User could not be found!');
}

if ($_GET['status'] == 'false') {
$userData->invisible_mode = 0;
$text = 'visibility_on';
} else {
$text = 'visibility_off';
$userData->invisible_mode = 1;
}

$userData->operation_admin .= "$('#vi-in-user').text('" . $text . "');";

erLhcoreClassUser::getSession()->update($userData);

erLhcoreClassRestAPIHandler::outputResponse(array(
'invisible' => $userData->invisible_mode
));

erLhcoreClassChatEventDispatcher::getInstance()->dispatch('chat.operator_visibility_changed',array('user' => & $userData, 'reason' => 'rest_api'));

} catch (Exception $e) {
echo json_encode(array(
'error' => true,
'result' => $e->getMessage()
));
}

exit();
10 changes: 6 additions & 4 deletions lhc_web/modules/lhuser/setinvisible.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
<?php

$currentUser = erLhcoreClassUser::instance();
$UserData = $currentUser->getUserData(true);
$userData = $currentUser->getUserData(true);

if ($Params['user_parameters']['status'] == 'false') {
$UserData->invisible_mode = 0;
$userData->invisible_mode = 0;
} else {
$UserData->invisible_mode = 1;
$userData->invisible_mode = 1;
}

erLhcoreClassUser::getSession()->update($UserData);
erLhcoreClassChatEventDispatcher::getInstance()->dispatch('chat.operator_visibility_changed',array('user' => & $userData, 'reason' => 'user_action'));

erLhcoreClassUser::getSession()->update($userData);
exit;

?>

0 comments on commit 77f5149

Please sign in to comment.