DocSpace-buildtools/products/ASC.CRM/Server/Classes/CRMCalendar.cs

134 lines
5.2 KiB
C#
Raw Normal View History

2020-04-16 19:41:37 +00:00
/*
*
* (c) Copyright Ascensio System Limited 2010-2018
*
* This program is freeware. You can redistribute it and/or modify it under the terms of the GNU
* General Public License (GPL) version 3 as published by the Free Software Foundation (https://www.gnu.org/copyleft/gpl.html).
* In accordance with Section 7(a) of the GNU GPL its Section 15 shall be amended to the effect that
* Ascensio System SIA expressly excludes the warranty of non-infringement of any third-party rights.
*
* THIS PROGRAM IS DISTRIBUTED WITHOUT ANY WARRANTY; WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR
* FITNESS FOR A PARTICULAR PURPOSE. For more details, see GNU GPL at https://www.gnu.org/copyleft/gpl.html
*
* You can contact Ascensio System SIA by email at sales@onlyoffice.com
*
* The interactive user interfaces in modified source and object code versions of ONLYOFFICE must display
* Appropriate Legal Notices, as required under Section 5 of the GNU GPL version 3.
*
* Pursuant to Section 7 § 3(b) of the GNU GPL you must retain the original ONLYOFFICE logo which contains
* relevant author attributions when distributing the software. If the display of the logo in its graphic
* form is not reasonably feasible for technical reasons, you must include the words "Powered by ONLYOFFICE"
* in every copy of the program you distribute.
* Pursuant to Section 7 § 3(e) we decline to grant you any rights under trademark law for use of our trademarks.
*
*/
2021-03-19 16:56:26 +00:00
using System;
using System.Collections.Generic;
using System.Globalization;
2020-04-18 17:49:09 +00:00
using ASC.Common;
using ASC.Common.Utils;
2020-04-16 19:41:37 +00:00
using ASC.Core;
2020-04-18 17:49:09 +00:00
using ASC.Core.Tenants;
2020-04-16 19:41:37 +00:00
using ASC.CRM.Core.Dao;
using ASC.CRM.Core.Enums;
2020-04-18 17:49:09 +00:00
using ASC.CRM.Resources;
using ASC.Web.Core;
using ASC.Web.Core.Calendars;
2021-03-02 16:29:07 +00:00
2021-03-10 15:38:56 +00:00
namespace ASC.CRM.Api
2020-04-16 19:41:37 +00:00
{
[Scope]
2021-05-05 14:09:05 +00:00
public sealed class CrmCalendar : BaseCalendar
2020-04-16 19:41:37 +00:00
{
2021-03-02 16:29:07 +00:00
[AllDayLongUTC]
2020-04-16 19:41:37 +00:00
private class Event : BaseEvent
{
}
2021-05-28 17:20:12 +00:00
private WebItemSecurity _webItemSecurity;
private DaoFactory _daoFactory;
private TenantManager _tenantManager;
private TenantUtil _tenantUtil;
2020-04-16 19:41:37 +00:00
2021-05-05 14:09:05 +00:00
public CrmCalendar(WebItemSecurity webItemSecurity,
2020-04-18 17:49:09 +00:00
DaoFactory daoFactory,
AuthContext authContext,
TimeZoneConverter timeZoneConverter,
TenantManager tenantManager,
TenantUtil tenantUtil
) : base(authContext, timeZoneConverter)
2020-04-16 19:41:37 +00:00
{
2021-05-28 17:20:12 +00:00
_tenantUtil = tenantUtil;
_tenantManager = tenantManager;
_webItemSecurity = webItemSecurity;
_daoFactory = daoFactory;
2020-04-18 17:49:09 +00:00
2020-04-16 19:41:37 +00:00
Context.HtmlBackgroundColor = "";
Context.HtmlTextColor = "";
Context.CanChangeAlertType = false;
Context.CanChangeTimeZone = false;
Context.GetGroupMethod = () => CRMCommonResource.ProductName;
Id = "crm_calendar";
EventAlertType = EventAlertType.Never;
Name = CRMCommonResource.ProductName;
Description = "";
SharingOptions = new SharingOptions();
2021-03-02 16:29:07 +00:00
// SharingOptions.PublicItems.Add(new SharingOptions.PublicItem { Id = userId, IsGroup = false });
2020-04-16 19:41:37 +00:00
}
public override List<IEvent> LoadEvents(Guid userId, DateTime startDate, DateTime endDate)
{
2020-04-18 17:49:09 +00:00
var events = new List<IEvent>();
if (
2021-05-28 17:20:12 +00:00
!_webItemSecurity.IsAvailableForMe(WebItemManager.CRMProductID))
2020-04-16 19:41:37 +00:00
{
2020-04-18 17:49:09 +00:00
return events;
}
2020-04-16 19:41:37 +00:00
2021-05-28 17:20:12 +00:00
var tasks = _daoFactory.GetTaskDao().GetTasks(String.Empty, userId, 0, false, DateTime.MinValue,
2020-04-18 17:49:09 +00:00
DateTime.MinValue, EntityType.Any, 0, 0, 0, null);
foreach (var t in tasks)
{
if (t.DeadLine == DateTime.MinValue) continue;
2020-04-16 19:41:37 +00:00
2020-04-18 17:49:09 +00:00
var allDayEvent = t.DeadLine.Hour == 0 && t.DeadLine.Minute == 0;
2021-05-28 17:20:12 +00:00
var utcDate = allDayEvent ? t.DeadLine.Date : _tenantUtil.DateTimeToUtc(t.DeadLine);
2020-04-16 19:41:37 +00:00
2020-04-18 17:49:09 +00:00
var e = new Event
2020-04-16 19:41:37 +00:00
{
2020-04-18 17:49:09 +00:00
AlertType = EventAlertType.Never,
AllDayLong = allDayEvent,
CalendarId = Id,
UtcStartDate = utcDate,
UtcEndDate = utcDate,
Id = "crm_task_" + t.ID.ToString(CultureInfo.InvariantCulture),
Name = CRMCommonResource.ProductName + ": " + t.Title,
Description = t.Description
};
2020-04-16 19:41:37 +00:00
2020-04-18 17:49:09 +00:00
if (IsVisibleEvent(startDate, endDate, e.UtcStartDate, e.UtcEndDate))
events.Add(e);
2020-04-16 19:41:37 +00:00
}
2020-04-18 17:49:09 +00:00
return events;
2020-04-16 19:41:37 +00:00
}
public override TimeZoneInfo TimeZone
{
2021-05-28 17:20:12 +00:00
get { return TimeZoneInfo.FindSystemTimeZoneById(_tenantManager.GetCurrentTenant().TimeZone); }
2020-04-16 19:41:37 +00:00
}
private bool IsVisibleEvent(DateTime startDate, DateTime endDate, DateTime eventStartDate, DateTime eventEndDate)
{
return (startDate <= eventStartDate && eventStartDate <= endDate) ||
(startDate <= eventEndDate && eventEndDate <= endDate) ||
(eventStartDate < startDate && eventEndDate > endDate);
}
}
}