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);
        }
Esempio n. 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 IEnumerable <string> RenderComponentsForPage(Survey survey, SurveyUser user, TemplateContext context, int pageNbr)
        {
            graph.Survey.Current = survey;
            var activeComponents   = graph.Details.Select().FirstTableItems.Where(det => det.Active == true);
            var selectedComponents = SurveyUtils.SelectPages(activeComponents, pageNbr);
            var firstOfSelected    = selectedComponents.FirstOrDefault();
            var renderedComponents = new List <string>();

            if (firstOfSelected == null)
            {
                return(renderedComponents);
            }
            var selectedPageNbr = firstOfSelected?.PageNbr.Value ?? 99999;
            var nextComponents  = SurveyUtils.SelectPages(activeComponents, ++selectedPageNbr);

            FillPageInfoLookAhead(context, activeComponents, nextComponents);
            var url = GetUrl(context, firstOfSelected.PageNbr.Value);

            context.SetValue(new ScriptVariableGlobal(URL), url);
            foreach (var detail in selectedComponents)
            {
                var component = SurveyComponent.PK.Find(graph, detail.ComponentID);
                var template  = Template.Parse(component.Body);
                AddDetailContext(context, detail, component);
                FillPageInfo(context, activeComponents, detail);
                var rendered = template.Render(context);
                renderedComponents.Add(rendered);
            }
            // TODO Handle nothing rendered
            return(renderedComponents);
        }
Esempio n. 4
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);
            }
        }
Esempio n. 5
0
        public virtual IEnumerable addUsers(PXAdapter adapter)
        {
            var users = UsersForAddition.Select().Where(a => a.GetItem <Contact>().Selected == true).ToList();

            foreach (var user in users)
            {
                var surveyUser = new SurveyUser();
                surveyUser.Active    = true;
                surveyUser.SurveyID  = SurveyCurrent.Current.SurveyID;
                surveyUser.ContactID = user.GetItem <Contact>().ContactID;
                surveyUser           = SurveyUsers.Insert(surveyUser);
            }

            return(adapter.Get());
        }
Esempio n. 6
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 TemplateContext GetSurveyContext(Survey survey, SurveyUser user, string token)
        {
            var setup   = graph.SurveySetup.Current;
            var context = new TemplateContext();

            context.MemberRenamer = MyMemberRenamerDelegate;
            context.MemberFilter  = MyMemberFilterDelegate;
            var url       = GetUrl(survey, token, null);
            var container = new ScriptObject {
                { survey.GetType().Name, survey },
                { setup.GetType().Name, setup },
                { user.GetType().Name, user },
                { IS_SINGLE_PAGE, survey.Layout == SurveyLayout.SinglePage },
                { TOKEN, token },
                { URL, url },
            };

            //container.SetValue(AcuFunctions.PREFIX, new AcuFunctions(), true);
            //container.SetValue(JsonFunctions.PREFIX, new JsonFunctions(), true);
            context.PushGlobal(container);
            return(context);
        }