Fix user invitation, fix query

pull/3768/head
Julio Montoya 5 years ago
parent a8a4ae762f
commit f8d39d2d49
  1. 3
      public/main/inc/ajax/message.ajax.php
  2. 113
      public/main/inc/lib/social.lib.php
  3. 3
      public/main/social/invitations.php
  4. 2
      src/CoreBundle/Repository/Node/UserRepository.php

@ -142,7 +142,8 @@ switch ($action) {
$subject = isset($_REQUEST['subject']) ? trim($_REQUEST['subject']) : null;
$invitationContent = isset($_REQUEST['content']) ? trim($_REQUEST['content']) : null;
SocialManager::sendInvitationToUser($_REQUEST['user_id'], $subject, $invitationContent);
$result = SocialManager::sendInvitationToUser($_REQUEST['user_id'], $subject, $invitationContent);
echo $result ? 1 : 0;
break;
case 'find_users':
if (api_is_anonymous()) {

@ -273,9 +273,7 @@ class SocialManager extends UserManager
//Just in case we replace the and \n and \n\r while saving in the DB
$message_content = str_replace(["\n", "\n\r"], '<br />', $message_content);
$clean_message_content = Database::escape_string($message_content);
$now = api_get_utc_datetime();
$sql = 'SELECT COUNT(*) AS count FROM '.$tbl_message.'
WHERE
user_sender_id='.$user_id.' AND
@ -284,31 +282,32 @@ class SocialManager extends UserManager
';
$res_exist = Database::query($sql);
$row_exist = Database::fetch_array($res_exist, 'ASSOC');
if (0 == $row_exist['count']) {
$params = [
'user_sender_id' => $user_id,
'user_receiver_id' => $friend_id,
'msg_status' => MESSAGE_STATUS_INVITATION_PENDING,
'send_date' => $now,
'title' => $message_title,
'content' => $message_content,
'group_id' => 0,
'parent_id' => 0,
'update_date' => $now,
];
$messageId = Database::insert($tbl_message, $params);
$senderInfo = api_get_user_info($user_id);
$notification = new Notification();
$notification->saveNotification(
$messageId,
Notification::NOTIFICATION_TYPE_INVITATION,
[$friend_id],
$message_title,
$message_content,
$senderInfo
);
if (0 === (int) $row_exist['count']) {
$em = Database::getManager();
$message = new Message();
$message
->setUserSender(api_get_user_entity($user_id))
->setUserReceiver(api_get_user_entity($friend_id))
->setMsgStatus(MESSAGE_STATUS_INVITATION_PENDING)
->setTitle($message_title)
->setContent($message_content)
->setGroupId(0)
;
$em->persist($message);
$em->flush();
$messageId = $message->getId();
if ($messageId) {
$senderInfo = api_get_user_info($user_id);
$notification = new Notification();
$notification->saveNotification(
$messageId,
Notification::NOTIFICATION_TYPE_INVITATION,
[$friend_id],
$message_title,
$message_content,
$senderInfo
);
}
return true;
} else {
@ -330,10 +329,10 @@ class SocialManager extends UserManager
Database::query($sql);
return true;
} else {
return false;
}
}
return false;
}
/**
@ -668,7 +667,7 @@ class SocialManager extends UserManager
$success = get_lang('The message has been sent to');
$success .= ' : '.api_get_person_name($user_info['firstName'], $user_info['lastName']);
if (isset($subject) && isset($content) && isset($userId)) {
if (!empty($subject) && !empty($content) && !empty($userId)) {
$result = MessageManager::send_message($userId, $subject, $content);
if ($result) {
@ -677,37 +676,39 @@ class SocialManager extends UserManager
);
} else {
Display::addFlash(
Display::return_message(get_lang('There was an error while trying to send the message.'), 'error', false)
Display::return_message(
get_lang('There was an error while trying to send the message.'),
'error',
false
)
);
}
return false;
} elseif (isset($userId) && !isset($subject)) {
if (isset($userId) && $userId > 0) {
$count = self::send_invitation_friend(
api_get_user_id(),
$userId,
get_lang('Invitation'),
$content
);
} elseif (!empty($userId) && empty($subject)) {
$count = self::send_invitation_friend(
api_get_user_id(),
$userId,
get_lang('Invitation'),
$content
);
if ($count) {
Display::addFlash(
Display::return_message(
api_htmlentities(get_lang('The invitation has been sent')),
'normal',
false
)
);
} else {
Display::addFlash(
Display::return_message(
api_htmlentities(get_lang('You already sent an invitation')),
'warning',
false
)
);
}
if ($count) {
Display::addFlash(
Display::return_message(
api_htmlentities(get_lang('The invitation has been sent')),
'normal',
false
)
);
} else {
Display::addFlash(
Display::return_message(
api_htmlentities(get_lang('You already sent an invitation')),
'warning',
false
)
);
}
}
}

@ -1,4 +1,5 @@
<?php
/* For licensing terms, see /license.txt */
/**
@ -79,7 +80,7 @@ if (is_array($_GET) && count($_GET) > 0) {
}
}
$content = null;
$content = '';
// Block Menu Social
$social_menu_block = SocialManager::show_social_menu('invitations');

@ -585,7 +585,7 @@ class UserRepository extends ResourceRepository implements UserLoaderInterface,
U.active = 1 AND
U.status != 6 AND
UF.relationType NOT IN('.USER_RELATION_TYPE_DELETED.', '.USER_RELATION_TYPE_RRHH.") AND
UF.userId = $currentUserId AND
UF.user = $currentUserId AND
UF.friendUserId != $currentUserId AND
U = R.user AND
R.url = $accessUrlId";

Loading…
Cancel
Save