private void FillEntityInfo(Survey survey, SurveyUser user, SurveyCollector collector, SurveyMaint graph, TemplateContext context)
        {
            // This collector might be an anonymous collector without the RefNoteID, let's find the real collector
            if (collector.RefNoteID == null && survey.KeepAnswersAnonymous == true)
            {
                collector = SurveyCollector.UK.ByToken.Find(graph, collector.Token);//?? collector;
            }
            if (collector.RefNoteID == null)
            {
                return;
            }
            var noteID    = collector.RefNoteID;
            var eh        = new EntityHelper(graph);
            var entityRow = eh.GetEntityRow(noteID);

            // Due to Acumatica
            if (entityRow == null)
            {
                return;
            }
            var entityType = entityRow.GetType();
            var entityName = eh.GetFriendlyEntityName(noteID);
            var fvp        = eh.GetFieldValuePairs(entityRow, entityType);
            var desc       = eh.GetEntityDescription(noteID, entityType);

            context.SetValue(new ScriptVariableGlobal(ENTITY_ROW), entityRow);
            context.SetValue(new ScriptVariableGlobal(ENTITY_TYPE), entityType);
            context.SetValue(new ScriptVariableGlobal(ENTITY_NAME), entityName);
            context.SetValue(new ScriptVariableGlobal(ENTITY_DESC), desc);
            context.SetValue(new ScriptVariableGlobal(ENTITY_FIELDS), fvp);
        }
Exemple #2
0
        private void SendMailNotification(Survey survey, SurveyUser surveyUser, SurveyCollector collector, int?notificationID)
        {
            Notification notification = PXSelect <Notification, Where <Notification.notificationID, Equal <Required <Notification.notificationID> > > > .Select(this, notificationID);

            /*
             * notification.RefNoteID = collector.NoteID.ToString();
             */
            //var sent = false;
            var emailGenerator = TemplateNotificationGenerator.Create(collector, notification);

            emailGenerator.LinkToEntity = true;
            emailGenerator.To           = surveyUser.Email;
            emailGenerator.ContactID    = surveyUser.ContactID;
            var generator = new SurveyGenerator();
            var url       = generator.GetUrl(survey, collector.Token, null);

            emailGenerator.Body = emailGenerator.Body.Replace("((Collector.URL))", url);
            //sender.MailAccountId = notification.NFrom ?? MailAccountManager.DefaultMailAccountID;
            emailGenerator.RefNoteID = collector.NoteID;
            //sender.Subject =
            //bool asAttachment = false;
            //if (asAttachment) {
            //if (!string.IsNullOrEmpty(message)) {
            //    sender.AddAttachment("HeaderContent.json", Encoding.UTF8.GetBytes(message));
            //}
            //} else {
            //sender.Body = message;
            //sender.BodyFormat = PX.Objects.CS.NotificationFormat.Html;
            //}
            //foreach (Guid? attachment in (IEnumerable<Guid?>)attachments) {
            //    if (attachment.HasValue)
            //        notificationGenerator.AddAttachmentLink(attachment.Value);
            //}
            var emails = emailGenerator.Send();
        }
        private static SurveyCollectorData FindCollectorData(SurveyMaint graph, SurveyCollector collector, int?pageNbr)
        {
            SurveyCollectorData collData = PXSelect <SurveyCollectorData,
                                                     Where <SurveyCollectorData.token, Equal <Required <SurveyCollectorData.token> >,
                                                            And <SurveyCollectorData.pageNbr, Equal <Required <SurveyCollectorData.pageNbr> > > > > .Select(graph, collector.Token, pageNbr);

            return(collData);
        }
Exemple #4
0
        public void DoSendNewNotification(SurveyCollector collector)
        {
            Collector.Current = collector;
            Survey survey = FindSurvey.Select(collector.SurveyID);

            DoSendNotification(collector, survey, survey.NotificationID);
            collector.SentOn  = PXTimeZoneInfo.Now;
            collector.Status  = CollectorStatus.Sent;
            collector.Message = null;
            Collector.Update(collector);
            Actions.PressSave();
        }
Exemple #5
0
        public void DoSendNotification(SurveyCollector collector, Survey survey, int?notificationID)
        {
            SurveyUser surveyUser = FindUser.Select(collector.SurveyID, collector.UserLineNbr);

            if (surveyUser.UsingMobileApp == true)
            {
                SendPushNotification(survey, surveyUser, collector);
            }
            else
            {
                SendMailNotification(survey, surveyUser, collector, notificationID);
            }
        }
        public static (Survey survey, SurveyUser user, SurveyCollector answerCollector, SurveyCollector userCollector) GetSurveyAndUser(SurveyMaint graph, string token)
        {
            SurveyCollector answerCollector;
            SurveyCollector userCollector = null;
            Survey          survey;
            SurveyUser      user;

            token = token?.Trim();
            if (token.Length <= 15)
            {
                // Anonymous survey, token is SurveyID
                survey = Survey.PK.Find(graph, token);
                if (survey == null)
                {
                    throw new PXException("Cannot find a survey with token {0}", token);
                }
                (user, answerCollector) = InsertAnonymous(graph, survey, null, true, false);
                token = answerCollector.Token;
            }
            else
            {
                answerCollector = SurveyCollector.UK.ByToken.Find(graph, token);
                survey          = Survey.PK.Find(graph, answerCollector.SurveyID);
                // If answers must be kept anonymous, then retrieve the anonymous collector of the user collector
                if (survey.KeepAnswersAnonymous == true && answerCollector.Anonymous != true)
                {
                    userCollector   = answerCollector;
                    answerCollector = GetAnonymousCollector(graph, survey, userCollector);
                }
                user = SurveyUser.PK.Find(graph, survey.SurveyID, answerCollector.UserLineNbr);
            }
            if (answerCollector == null)
            {
                throw new PXException(Messages.TokenNoFound, token);
            }
            if (survey == null)
            {
                throw new PXException(Messages.TokenNoSurvey, token);
            }
            if (user == null)
            {
                throw new PXException(Messages.TokenNoUser, token);
            }
            if (userCollector == null)
            {
                userCollector = answerCollector;
            }
            return(survey, user, answerCollector, userCollector);
        }
Exemple #7
0
        public void DoSendReminder(SurveyCollector collector, int?delay)
        {
            Collector.Current = collector;
            Survey survey = FindSurvey.Select(collector.SurveyID);

            DoSendNotification(collector, survey, survey.RemindNotificationID);
            collector.SentOn  = PXTimeZoneInfo.Now;
            collector.Status  = CollectorStatus.Reminded;
            collector.Message = null;
            if (delay > 0)
            {
                collector.ExpirationDate = DateTime.UtcNow.AddMinutes(delay.Value);
            }
            Collector.Update(collector);
            Actions.PressSave();
        }
Exemple #8
0
        private void SendPushNotification(Survey survey, SurveyUser surveyUser, SurveyCollector surveyCollector)
        {
            string sScreenID = PXSiteMap.Provider
                               .FindSiteMapNodeByGraphType(typeof(SurveyCollectorMaint).FullName).ScreenID;
            Guid noteID = surveyCollector.NoteID.GetValueOrDefault();

            if (surveyUser.UserID != null)
            {
                List <Guid> userIds = new List <Guid> {
                    surveyUser.UserID.GetValueOrDefault()
                };
                pushNotificationSender.SendNotificationAsync(
                    userIds: userIds,
                    title: Messages.PushNotificationTitleSurvey,
                    text: $"{Messages.PushNotificationMessageBodySurvey} # {survey.Title}.",
                    link: (sScreenID, noteID),
                    cancellation: CancellationToken.None);
            }
        }
        private static SurveyCollector GetAnonymousCollector(SurveyMaint graph, Survey survey, SurveyCollector userCollector)
        {
            var coll = SurveyCollector.PK.Find(graph, userCollector.AnonCollectorID);

            if (coll == null)
            {
                // Rare case where AnonCollectorID points to a deleted Collector, should have been cleared.
                var(_, anon) = InsertAnonymous(graph, survey, null, true, false);
                userCollector.AnonCollectorID = anon?.CollectorID;
                graph.Collectors.Update(userCollector);
                graph.Actions.PressSave();
                coll = anon;
            }
            return(coll);
        }