Message: Allow filter by tags - refs BT#19396

pull/4119/head
Angel Fernando Quiroz Campos 4 years ago
parent e0f6063641
commit 6f17f0cdcf
  1. 9
      app/Resources/public/css/base.css
  2. 102
      main/inc/lib/message.lib.php
  3. 6
      main/messages/inbox.php
  4. 7
      main/messages/outbox.php
  5. 36
      src/Chamilo/CoreBundle/Entity/Repository/ExtraFieldRelTagRepository.php

@ -5258,6 +5258,15 @@ i.size-32.icon-new-work {
width: 300px;
}
.actions .form-inline .bootstrap-select.inbox-search-tags .dropdown-toggle .filter-option-inner-inner {
margin-right: 15px;
overflow: hidden;
min-width: 150px;
text-overflow: ellipsis;
width: 300px;
}
ul.holder {
list-style: none;
margin: 0;

@ -62,8 +62,19 @@ class MessageManager
$table = Database::get_main_table(TABLE_MESSAGE);
$conditions = self::getWhereConditions($params);
$sql = "SELECT COUNT(id) as number_messages
FROM $table
$sql = "SELECT COUNT(DISTINCT m.id) as number_messages
FROM $table m";
if (true === api_get_configuration_value('enable_message_tags')) {
$tblExtraFielRelTag = Database::get_main_table(TABLE_MAIN_EXTRA_FIELD_REL_TAG);
$tblExtraField = Database::get_main_table(TABLE_EXTRA_FIELD);
$sql .= "
LEFT JOIN $tblExtraFielRelTag efrt ON efrt.item_id = m.id
LEFT JOIN $tblExtraField ef ON ef.id = efrt.field_id AND ef.variable = 'tags'";
}
$sql .= "
WHERE
$conditions
";
@ -88,6 +99,7 @@ class MessageManager
$keyword = isset($extraParams['keyword']) && !empty($extraParams['keyword']) ? $extraParams['keyword'] : '';
$type = isset($extraParams['type']) && !empty($extraParams['type']) ? $extraParams['type'] : '';
$tags = $extraParams['tags'] ?? [];
if (empty($type)) {
return '';
@ -96,15 +108,15 @@ class MessageManager
switch ($type) {
case self::MESSAGE_TYPE_INBOX:
$statusList = [MESSAGE_STATUS_NEW, MESSAGE_STATUS_UNREAD];
$userCondition = " user_receiver_id = $userId AND";
$userCondition = " m.user_receiver_id = $userId AND";
break;
case self::MESSAGE_TYPE_OUTBOX:
$statusList = [MESSAGE_STATUS_OUTBOX];
$userCondition = " user_sender_id = $userId AND";
$userCondition = " m.user_sender_id = $userId AND";
break;
case self::MESSAGE_TYPE_PROMOTED:
$statusList = [MESSAGE_STATUS_PROMOTED];
$userCondition = " user_receiver_id = $userId AND";
$userCondition = " m.user_receiver_id = $userId AND";
break;
}
@ -115,13 +127,20 @@ class MessageManager
$keywordCondition = '';
if (!empty($keyword)) {
$keyword = Database::escape_string($keyword);
$keywordCondition = " AND (title like '%$keyword%' OR content LIKE '%$keyword%') ";
$keywordCondition = " AND (m.title like '%$keyword%' OR m.content LIKE '%$keyword%') ";
}
$messageStatusCondition = implode("','", $statusList);
$tagsCondition = '';
if (true === api_get_configuration_value('enable_message_tags') && !empty($tags)) {
$tagsCondition = ' AND efrt.tag_id IN ('.implode(', ', $tags).") ";
}
return " $userCondition
msg_status IN ('$messageStatusCondition')
$keywordCondition";
m.msg_status IN ('$messageStatusCondition')
$keywordCondition
$tagsCondition";
}
/**
@ -184,14 +203,25 @@ class MessageManager
}
$table = Database::get_main_table(TABLE_MESSAGE);
$sql = "SELECT
id as col0,
title as col1,
send_date as col2,
msg_status as col3,
user_sender_id,
user_receiver_id
FROM $table
$sql = "SELECT DISTINCT
m.id as col0,
m.title as col1,
m.send_date as col2,
m.msg_status as col3,
m.user_sender_id,
m.user_receiver_id
FROM $table m";
if (true === api_get_configuration_value('enable_message_tags')) {
$tblExtraFielRelTag = Database::get_main_table(TABLE_MAIN_EXTRA_FIELD_REL_TAG);
$tblExtraField = Database::get_main_table(TABLE_EXTRA_FIELD);
$sql .= "
LEFT JOIN $tblExtraFielRelTag efrt ON efrt.item_id = m.id
LEFT JOIN $tblExtraField ef ON ef.id = efrt.field_id AND ef.variable = 'tags'";
}
$sql .= "
WHERE
$whereConditions
ORDER BY col$column $direction
@ -2224,7 +2254,7 @@ class MessageManager
*
* @return string
*/
public static function getMessageGrid($type, $keyword, $actions = [])
public static function getMessageGrid($type, $keyword, $actions = [], array $searchTags = [])
{
$html = '';
// display sortable table with messages of the current user
@ -2237,7 +2267,7 @@ class MessageManager
'DESC'
);
$table->setDataFunctionParams(
['keyword' => $keyword, 'type' => $type, 'actions' => $actions]
['keyword' => $keyword, 'type' => $type, 'actions' => $actions, 'tags' => $searchTags]
);
$table->set_header(0, '', false, ['style' => 'width:15px;']);
$table->set_header(1, get_lang('Messages'), false);
@ -2277,7 +2307,7 @@ class MessageManager
*
* @return string
*/
public static function inboxDisplay($keyword = '')
public static function inboxDisplay($keyword = '', array $searchTags = [])
{
$success = get_lang('SelectedMessagesDeleted');
$success_read = get_lang('SelectedMessagesRead');
@ -2347,7 +2377,7 @@ class MessageManager
$actions = ['reply', 'mark_as_unread', 'mark_as_read', 'forward', 'delete'];
$html = self::getMessageGrid(self::MESSAGE_TYPE_INBOX, $keyword, $actions);
$html = self::getMessageGrid(self::MESSAGE_TYPE_INBOX, $keyword, $actions, $searchTags);
$html .= self::addTagsFormToInbox();
return $html;
@ -2400,7 +2430,7 @@ class MessageManager
*
* @return string
*/
public static function outBoxDisplay($keyword)
public static function outBoxDisplay($keyword, array $searchTags = [])
{
$actions = ['delete'];
@ -2433,7 +2463,7 @@ class MessageManager
exit;
}
$html = self::getMessageGrid(self::MESSAGE_TYPE_OUTBOX, $keyword, $actions);
$html = self::getMessageGrid(self::MESSAGE_TYPE_OUTBOX, $keyword, $actions, $searchTags);
$html .= self::addTagsFormToInbox();
return $html;
@ -2715,6 +2745,8 @@ class MessageManager
FormValidator::LAYOUT_INLINE
);
self::addTagsFormToSearch($form);
$form->addElement(
'text',
'keyword',
@ -3361,4 +3393,30 @@ class MessageManager
return $messageContent;
}
private static function addTagsFormToSearch(FormValidator $form)
{
if (false === api_get_configuration_value('enable_message_tags')) {
return;
}
$userId = api_get_user_id();
$em = Database::getManager();
$tags = $em
->getRepository('ChamiloCoreBundle:ExtraFieldRelTag')
->getTagsByUserMessages($userId)
;
$tagsOptions = [];
foreach ($tags as $tag) {
$tagsOptions[$tag->getId()] = $tag->getTag();
}
$form
->addSelect('tags', get_lang('Tags'), $tagsOptions, ['class' => 'inbox-search-tags'])
->setMultiple(true)
;
}
}

@ -62,6 +62,7 @@ if ($allowSocial) {
// Right content
$social_right_content = '';
$keyword = '';
$searchTags = [];
if ($allowSocial) {
$actionsLeft = '<a href="'.api_get_path(WEB_PATH).'main/messages/new_message.php">'.
Display::return_icon('new-message.png', get_lang('ComposeMessage'), [], 32).'</a>';
@ -72,12 +73,13 @@ if ($allowSocial) {
if ($form->validate()) {
$values = $form->getSubmitValues();
$keyword = $values['keyword'];
$searchTags = $values['tags'] ?? [];
}
$actionsRight = $form->returnForm();
$social_right_content .= Display::toolbarAction('toolbar', [$actionsLeft, $actionsRight]);
$social_right_content .= Display::toolbarAction('toolbar', [$actionsLeft, $actionsRight], [2, 10]);
}
$social_right_content .= MessageManager::inboxDisplay($keyword);
$social_right_content .= MessageManager::inboxDisplay($keyword, $searchTags);
$tpl = new Template(null);

@ -55,6 +55,7 @@ if ($allowMessage) {
$keyword = '';
$social_right_content = '';
$searchTags = [];
if ($allowSocial) {
// Block Social Menu
$social_menu_block = SocialManager::show_social_menu('messages');
@ -65,15 +66,17 @@ if ($allowSocial) {
if ($form->validate()) {
$values = $form->getSubmitValues();
$keyword = $values['keyword'];
$searchTags = $values['tags'] ?? [];
}
$actionsRight = $form->returnForm();
$social_right_content .= Display::toolbarAction(
'toolbar',
[$actionsLeft, $actionsRight]
[$actionsLeft, $actionsRight],
[2, 10]
);
}
$social_right_content .= MessageManager::outBoxDisplay($keyword);
$social_right_content .= MessageManager::outBoxDisplay($keyword, $searchTags);
$tpl = new Template(get_lang('Outbox'));
// Block Social Avatar

@ -44,4 +44,40 @@ class ExtraFieldRelTagRepository extends EntityRepository
return $queryBuilder->getQuery()->getResult();
}
public function getTagsByUserMessages(int $userId)
{
$qb = $this->createQueryBuilder('eft');
$qb
->select('t')
->distinct(true)
->innerJoin('ChamiloCoreBundle:Tag', 't', Join::WITH, 'eft.tagId = t.id AND eft.fieldId = t.fieldId')
->innerJoin('ChamiloCoreBundle:ExtraField', 'ef', Join::WITH, 'eft.fieldId = ef.id')
->innerJoin('ChamiloCoreBundle:Message', 'm', Join::WITH, 'eft.itemId = m.id')
->where($qb->expr()->eq('ef.variable', ':variable'))
->andWhere($qb->expr()->eq('ef.extraFieldType', ':extraFieldType'))
->andWhere(
$qb->expr()->orX(
$qb->expr()->andX(
$qb->expr()->eq('m.userReceiverId', ':userId'),
$qb->expr()->in('m.msgStatus', [MESSAGE_STATUS_NEW, MESSAGE_STATUS_UNREAD])
),
$qb->expr()->andX(
$qb->expr()->eq('m.userSenderId', ':userId'),
$qb->expr()->in('m.msgStatus', [MESSAGE_STATUS_OUTBOX])
)
)
)
->orderBy('t.tag', 'ASC')
->setParameters(
[
'variable' => 'tags',
'extraFieldType' => ExtraField::MESSAGE_TYPE,
'userId' => $userId,
]
)
;
return $qb->getQuery()->getResult();
}
}

Loading…
Cancel
Save