Welcome, Guest
Username: Password: Remember me

TOPIC: Line Breaks in Report (as Equation)

Line Breaks in Report (as Equation) 2 years 5 months ago #76037

  • tacman1123
  • tacman1123's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 125
  • Karma: 1
I need to generate a report based on the answers of a survey. It's pretty much "If they answered this way, say this". For example, health recommendations --

{if (num_drinks_per_day > 6), 'Have you tried AA?<br />', ''}
{if (exercise_per_week < 30), 'Join a Gym or Walk more!<br />', ''}

The problem is (besides the unhelpful recommendations) is that <br /> isn't the best way to add line breaks. But what is? How can I add line breaks so it comes out as a list of recommendations?

Tac
The administrator has disabled public write access.

Re: Line Breaks in Report (as Equation) 2 years 5 months ago #76039

  • TMSWhite
  • TMSWhite's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 759
  • Thank you received: 82
  • Karma: 36
Tac-

It used to be that you could put <br /> and other HTML into Expression output. However, that posted a potential security hole, so any embedded HTML is processed through htmlspecialchars(). Thus, <br /> becomes <br />, which will not render line breaks.

Perhaps the easiest solution might be to augment the list() function which is effectively implode(', ', ...) where ... is a list of variables. You could easily create a list()-like function that generates an ordered or list. A reasonable syntax might be:

htmllist(type, class, var_list), where type is 'ol' or 'ul'; class is a CSS class to use for the list (so you can do custom styling), and var_list is the list of variables. The function would then generate the proper HTML if there is at least one variable that is non-null.

Then, you would create one Equation question type per message, and pass the full list of those variables to htmllist()

/Tom
The administrator has disabled public write access.

Re: Line Breaks in Report (as Equation) 2 years 5 months ago #76073

  • tacman1123
  • tacman1123's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 125
  • Karma: 1
Create a new EM function you mean? Hmm.

What would the syntax of that be, using the above example? Have some sort of add_to_list function first? I'm not familiar with how the list function would work.

Tac
The administrator has disabled public write access.

Re: Line Breaks in Report (as Equation) 2 years 5 months ago #76564

  • tacman1123
  • tacman1123's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 125
  • Karma: 1
Can you point me to the documentation or an example for how I'd do that?
The administrator has disabled public write access.

Re: Line Breaks in Report (as Equation) 2 years 5 months ago #76586

  • TMSWhite
  • TMSWhite's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 759
  • Thank you received: 82
  • Karma: 36
Tac-

In retrospect, it should be possible to simply use the existing nl2br() function and put line returns (\n) in your strings. However, I discovered that there is a bug in the tokenizer such that it doesn't properly handle \n yet - I'm working on that.

Perhaps a more generic solution would be to have a function that parses a string as if it were wiki syntax and outputs proper HTML. That way you could have complex markup (like the lists of recommendations you want), but not risk broken HTML. Know of any good wiki syntax parsers that work in PHP and JavaScript?

If you don't find any, I can provide more details on how to build the custom function you want.

-Tom
The administrator has disabled public write access.

Re: Line Breaks in Report (as Equation) 2 years 5 months ago #76588

  • tacman1123
  • tacman1123's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 125
  • Karma: 1
Not for js, but I recently used github.com/lahdekorpi/Wiky.php for a project. It doesn't support nesting, but other than that it was fine for simple markup to HTML.

I'm still trying to figure out how to display this report without having to navigate through the 10 groups. Is there a way I can go to a question by putting its code in the url?

Thanks,

Tac
The administrator has disabled public write access.

Re: Line Breaks in Report (as Equation) 2 years 5 months ago #76594

  • TMSWhite
  • TMSWhite's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 759
  • Thank you received: 82
  • Karma: 36
tacman1123 wrote:
Not for js, but I recently used github.com/lahdekorpi/Wiky.php for a project. It doesn't support nesting, but other than that it was fine for simple markup to HTML.

Looks like wiky.php is an adaptation of wiky.js - which is encouraging. How stable has it been for you?
tacman1123 wrote:
I'm still trying to figure out how to display this report without having to navigate through the 10 groups. Is there a way I can go to a question by putting its code in the url?

Not exactly sure what you mean. However, if you use the "Show Logic" screen, it shows all of the questions and their variable names. If you want to edit any of those questions, simply click on the variable name in any of the syntax-highlighted strings and it opens a question edit window in a new tab.
The administrator has disabled public write access.

Re: Line Breaks in Report (as Equation) 2 years 5 months ago #76598

  • tacman1123
  • tacman1123's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 125
  • Karma: 1
Let's say the questions are Do you smoke? How often do you exercise? How many alcoholic drinks do you have per week?

The idea is that the user may like a self-assessment at the end "Here are some tips for improving your health, based on your answers...", and that Dr. Tom may want to log on, look at the patient results, then click on a single link that takes him to that same report, which he can cut and paste into a Word Document with nice letterhead, make a few personalized comments and send it off as a letter to the patient.

That's the exact scenario I want, except that it's not medical records.

I'm just stuck on how to do that. I can sort of generate a report at the end by generating text as the last "question". It's sloppy, because the user still has to click to continue to finalize the survey, and at the moment it's an editable piece of text.

But I do that so that when the "doctor" comes into send the printed report, they can simply go to "Data Entry", go to the last question, and cut and paste the recommendations.

So that's the long(er) answer of what I'm trying to do.

Thx,

Tac
The administrator has disabled public write access.

Re: Line Breaks in Report (as Equation) 2 years 5 months ago #76601

  • TMSWhite
  • TMSWhite's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 759
  • Thank you received: 82
  • Karma: 36
Tac-

You could create the report as a hidden Equation at the end of the survey. That way it is available through data entry, but the user doesn't see it (and the users see the Submit button so their surveys are finalized).

The newest 1.92+ stable release fixes a bug in the Equation question type that kept it from processing reports in Equations correctly if the equations are generated on the same page as some variables on which it depends.

In general, what I've done in the past is to simply create a nicely formatted table as one question on the penultimate page, and asked users to print it out. Then, I incentivize them to click submit by saying they'll be redirected to a relevant web page. However, knowing that not everyone will click Submit, my analyzes of whether they completed the survey are based upon whether they got to that final report page.

/Tom
The administrator has disabled public write access.
Moderators: ITEd
Time to create page: 0.138 seconds
Donation Image