Merge pull request #4097 from AngelFQC/BT19391

Calendar: Allow create event from message - refs BT#19391
pull/4102/head
Angel Fernando Quiroz Campos 4 years ago committed by GitHub
commit e41c4ee9ab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 18
      main/calendar/agenda.php
  2. BIN
      main/img/icons/22/new_event.png
  3. 90
      main/inc/lib/message.lib.php
  4. 4
      main/messages/new_message.php
  5. 7
      src/Chamilo/CoreBundle/Component/Editor/CkEditor/Toolbar/Messages.php

@ -35,6 +35,20 @@ $group_id = api_get_group_id();
$groupInfo = GroupManager::get_group_properties($group_id);
$eventId = isset($_REQUEST['id']) ? $_REQUEST['id'] : null;
$type = $event_type = isset($_GET['type']) ? $_GET['type'] : null;
$messageId = (int) ($_GET['m'] ?? 0);
$messageInfo = [];
$currentUserId = api_get_user_id();
if ($messageId) {
$event_type = 'personal';
$messageInfo = MessageManager::get_message_by_id($messageId);
if (!in_array($currentUserId, [$messageInfo['user_receiver_id'], $messageInfo['user_sender_id']])) {
api_not_allowed(true);
}
}
$htmlHeadXtra[] = "<script>
function plus_repeated_event() {
@ -172,6 +186,10 @@ if ($allowToEdit) {
header("Location: $agendaUrl");
exit;
} else {
if (!empty($messageInfo)) {
MessageManager::setDefaultValuesInFormFromMessageInfo($messageInfo, $form);
}
$content = $form->returnForm();
}
break;

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

@ -1496,10 +1496,16 @@ class MessageManager
$social_link = 'f=social';
}
$eventLink = Display::url(
Display::return_icon('new_event.png', get_lang('New event')),
api_get_path(WEB_CODE_PATH).'calendar/agenda.php?action=add&type=personal&m='.$messageId
).PHP_EOL;
switch ($type) {
case self::MESSAGE_TYPE_OUTBOX:
$message_content .= '<a href="outbox.php?'.$social_link.'">'.
Display::return_icon('back.png', get_lang('ReturnToOutbox')).'</a> &nbsp';
$message_content .= $eventLink;
$message_content .= '<a href="outbox.php?action=deleteone&id='.$messageId.'&'.$social_link.'" >'.
Display::return_icon('delete.png', get_lang('DeleteMessage')).'</a>&nbsp';
break;
@ -1508,6 +1514,7 @@ class MessageManager
Display::return_icon('icons/22/arrow_up.png', get_lang('ReturnToInbox')).'</a>&nbsp;';
$message_content .= '<a href="new_message.php?re_id='.$messageId.'&'.$social_link.'">'.
Display::return_icon('message_reply.png', get_lang('ReplyToMessage')).'</a>&nbsp;';
$message_content .= $eventLink;
$message_content .= '<a href="inbox.php?action=deleteone&id='.$messageId.'&'.$social_link.'" >'.
Display::return_icon('delete.png', get_lang('DeleteMessage')).'</a>&nbsp;';
if ($idPrevMessage != 0) {
@ -1519,10 +1526,7 @@ class MessageManager
break;
}
$message_content .= '</div></td>
<td width="10"></td>
</tr>
</table>';
$message_content .= '</div>';
return $message_content;
}
@ -3193,4 +3197,82 @@ class MessageManager
return [];
}
/**
* @throws Exception
*/
public static function setDefaultValuesInFormFromMessageInfo(array $messageInfo, FormValidator $form)
{
$currentUserId = api_get_user_id();
$contentMatch = [];
preg_match('/<body>(.*?)<\/body>/s', $messageInfo['content'], $contentMatch);
$defaults = [
'title' => $messageInfo['title'],
];
if (empty($contentMatch[1])) {
$defaults['content'] = strip_tags_blacklist(
$messageInfo['content'],
['link', 'script', 'title', 'head', 'body']
);
$defaults['content'] = preg_replace('#(<link(.*?)>)#msi', '', $defaults['content']);
} else {
$defaults['content'] = $contentMatch[1];
}
if (api_get_configuration_value('agenda_collective_invitations')) {
$defaults['invitees'] = [];
if ($currentUserId != $messageInfo['user_sender_id']) {
$senderInfo = api_get_user_info($messageInfo['user_sender_id']);
$form->getElement('invitees')->addOption(
$senderInfo['complete_name_with_username'],
$senderInfo['id']
);
$defaults['invitees'][] = $senderInfo['id'];
}
$messageCopies = MessageManager::getCopiesFromMessageInfo($messageInfo);
foreach ($messageCopies as $messageCopy) {
if ($currentUserId == $messageCopy->getUserReceiverId()) {
continue;
}
$receiverInfo = api_get_user_info($messageCopy->getUserReceiverId());
$form->getElement('invitees')->addOption(
$receiverInfo['complete_name_with_username'],
$receiverInfo['id']
);
$defaults['invitees'][] = $receiverInfo['id'];
}
}
$form->setDefaults($defaults);
}
/**
* @throws Exception
*
* @return array<Message>
*/
public static function getCopiesFromMessageInfo(array $messageInfo): array
{
$em = Database::getManager();
$messageRepo = $em->getRepository('ChamiloCoreBundle:Message');
return $messageRepo->findBy(
[
'userSenderId' => $messageInfo['user_sender_id'],
'msgStatus' => MESSAGE_STATUS_OUTBOX,
'sendDate' => new DateTime($messageInfo['send_date'], new DateTimeZone('UTC')),
'title' => $messageInfo['title'],
'content' => $messageInfo['content'],
'groupId' => $messageInfo['group_id'],
'parentId' => $messageInfo['parent_id'],
]
);
}
}

@ -202,8 +202,8 @@ function manageForm($default, $select_from_user_list = null, $sent_to = '', $tpl
'content',
get_lang('Message'),
false,
false,
['ToolbarSet' => 'Messages', 'Width' => '100%', 'Height' => '250', 'style' => true]
true,
['ToolbarSet' => 'Messages']
);
if (isset($_GET['re_id'])) {

@ -17,6 +17,8 @@ class Messages extends Basic
*/
public function getConfig()
{
$config = [];
if (api_get_setting('more_buttons_maximized_mode') != 'true') {
$config['toolbar'] = $this->getNormalToolbar();
} else {
@ -24,9 +26,6 @@ class Messages extends Basic
$config['toolbar_maxToolbar'] = $this->getMaximizedToolbar();
}
$config['fullPage'] = true;
//$config['height'] = '200';
return $config;
}
@ -104,7 +103,7 @@ class Messages extends Basic
['Link', 'Image', 'Video', 'Flash', 'Audio', 'Table', 'Asciimath', 'Asciisvg'],
['BulletedList', 'NumberedList', 'HorizontalRule'],
['JustifyLeft', 'JustifyCenter', 'JustifyRight'],
['Format', 'Font', 'Bold', 'Italic', 'Underline', 'TextColor', 'BGColor'],
['Styles', 'Format', 'Font', 'Bold', 'Italic', 'Underline', 'TextColor', 'BGColor'],
api_get_setting('enabled_wiris') === 'true' ? ['ckeditor_wiris_formulaEditor', 'ckeditor_wiris_formulaEditorChemistry'] : [''],
['Toolbarswitch'],
];

Loading…
Cancel
Save