LimeSurvey issue tracker
Registration

View Issue Details Jump to Notes ] Related Changesets ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
07236Bug reports[All Projects] Expression Managerpublic2013-01-27 14:312013-02-09 17:34
ReporterDenisChenu 
Assigned ToDenisChenu 
PrioritynormalSeverityminor 
StatusclosedResolutionfixed 
Product Version2.00+ 
Target VersionFixed in Version2.00+ 
Summary07236: Unable to concatenate number : + don't work and join is undefined
DescriptionEM don't offer possibility to concatenate number
Steps To ReproduceTry to have : 10€ or $10 with EM

You can import included survey to see the problem.
Additional InformationIn EM:
with +:
If the 2 var are string then concatenate : seems OK
If the 2 var can be number : do sum : Think it's not godd, need to test if the 2 var are real number (difference between 10+10 and "10"+"10")
If the 2 var are "different" send NAN ... easy to replace by a concatenate, but still the "10"+"10" issue.

Trying to use {join("A","B")} => show undefined function
I will donate to the project if issue is resolved within 48 hrsNo
LimeSurvey build number OR git commit ID130127
Browsernot relevant
Database & DB-Versionnot relevant
Operating System (Server)debian/linux
Webserver software & versionapache
PHP VersionPHP Version 5.3
Attached Files? file icon limesurvey_survey_concatenate.lss [^] (12,273 bytes) 2013-01-27 14:31
? file icon limesurvey_survey_concatenate_samegroup.lss [^] (15,248 bytes) 2013-01-31 21:13

- Relationships

-  Notes
User avatar (23831)
DenisChenu (developer)
2013-01-27 14:34

And for number format, we can using it with another format too.
For example :

number_format ( QCODE , 2 , ',' , ' ' )
User avatar (23839)
c_schmitz (administrator)
2013-01-28 11:06

Documentation says to use join(arg1,arg2) for concatenation. Funny enough this function is not in the function list.
User avatar (23842)
DenisChenu (developer)
2013-01-28 11:10

Then move to documentation.

Thanks
User avatar (23843)
DenisChenu (developer)
2013-01-28 11:14

Problem:
join => undefined function.
User avatar (23844)
DenisChenu (developer)
2013-01-28 11:15

Bug updated
User avatar (23847)
c_schmitz (administrator)
2013-01-28 12:06

Thomas, any idea on this?
User avatar (23849)
TMSWhite (reporter)
2013-01-28 18:32

the missing join() function is an oversight. There is an implode() function that can be used instead.

The root problem is a (perhaps misguided) effort to get + to work identically in PHP and JavaScript. For the equation "a + b", JavaScript treats + as concat() if a is of type String (even if it is numeric). So, ExpressionManager (one of the RDP_xxx() functions) tries to emulate that behavior in PHP.

In retrospect, this may cause more problems than not, so I'd be happy to have + always mean "add" and force users to use join(), or implode() to do concatenation.

So, recommendations are:
(1) Add join() function to EM (or change documentation to have them use implode())
(2) Make "+" always mean add (and never concatenate), and let it throw a NaN exception as needed.

/Tom
User avatar (23852)
DenisChenu (developer)
2013-01-28 19:41
edited on: 2013-01-28 19:42

Think implode are made for array, not to concatenate string.

1st: join(2 var) , see after for 3.... and more

User avatar (23853)
TMSWhite (reporter)
2013-01-28 19:50

The EM implode() function does work for contatenating strings (e.g. the function takes an unlimited number of arguments), even if the original PHP implode() function was meant for arrays.
User avatar (23856)
DenisChenu (developer)
2013-01-28 23:07

Think some user use + only for addition, sometimes with "10"+"10", then you break their survey.

Maybe:
If $bNumerci : +
else concatenate

And adding join
User avatar (23857)
DenisChenu (developer)
2013-01-28 23:10

em_core_helper:
            case '+':
                if ($bBothNumeric) {
                    $result = array(($arg1[0] + $arg2[0]),$token[1],'NUMBER');
                }
                else{
                    $result = array($arg1[0] . $arg2[0],$token[1],'STRING');
                }
User avatar (23858)
TMSWhite (reporter)
2013-01-28 23:25

1.92 and 2.0 both already have this code for RDP_EvaluateBinary()

case '+':
  if ($bBothNumeric) {
    $result = array(($arg1[0] + $arg2[0]),$token[1],'NUMBER');
  }
  else if ($bBothString) {
    $result = array($arg1[0] . $arg2[0],$token[1],'STRING');
  } else {
    $result = array(NAN,$token[1],'NUMBER');
  }
  break;

So the problem is likely in em_javascript.js or GetJavaScriptEquivalentOfExpression()
User avatar (23867)
DenisChenu (developer)
2013-01-29 08:03

I propose to remove the if ($bBothString) test.

Then if both can be numeric Adding else concatenate.
Don't look at javascript now.
User avatar (23894)
Mazi (developer)
2013-01-29 23:57

From what I can tell from the forums and from other Limesurvey users I have been working with, "+" is used a lot to concatenate strings/messages and you never know how many users make use of it without us ever having noticed them.

Thus, I really wish to not change the way that function is currently used. It might break dozens or hundreds of running surveys.
Instead, better find a code-wise workaround by using some try-catch statements or the like to handle the special cases we are talking about while keeping the current functionality available for our existing users.

Of course, updating the manual and giving some examples when which functions should best be used, does no harm :-)
User avatar (23896)
DenisChenu (developer)
2013-01-30 11:11
edited on: 2013-01-30 11:11

Mazi:
For starting: it's this OK:

{"10"+"10"} : 20
{"$"+"10"} : "$10"
{"A"+"B"} : "AB"

Actually we have
{"10"+"10"} : 20
{"$"+"10"} : NAN
{"A"+"B"} : "AB"

(Adding join function in php and js after)

User avatar (23927)
DenisChenu (developer)
2013-01-31 21:14

The second file show behaviour with same group:
No NAN: but is both can be numeric : sum
If not concatenate.
User avatar (23928)
DenisChenu (developer)
2013-01-31 21:20

Fix committed to master branch: http://bugs.limesurvey.org/plugin.php?page=Source/view&id=11547 [^]
User avatar (23931)
DenisChenu (developer)
2013-02-01 10:37

Fix committed to master branch: http://bugs.limesurvey.org/plugin.php?page=Source/view&id=11549 [^]
User avatar (23963)
c_schmitz (administrator)
2013-02-07 10:52

New version 2.00 build 120206 released.
User avatar (24017)
DenisChenu (developer)
2013-02-09 17:21

Fix committed to 2.1 branch: http://bugs.limesurvey.org/plugin.php?page=Source/view&id=11608 [^]
User avatar (24018)
DenisChenu (developer)
2013-02-09 17:34

Fix committed to 2.1 branch: http://bugs.limesurvey.org/plugin.php?page=Source/view&id=11609 [^]

- Related Changesets
LimeSurvey: master 911185fb
Timestamp: 2013-01-31 20:17:29
Author: DenisChenu
Committer: Denis Chenu
Details ] Diff ]
Fixed issue 07236: Different behaviour of + in EM in same group or next group
Dev: Just fix partially, have to add join function to concatenate 2 number
mod - application/helpers/expressions/em_core_helper.php Diff ] File ]
LimeSurvey: master 8167e5ae
Timestamp: 2013-02-01 09:34:12
Author: DenisChenu
Committer: Denis Chenu
Details ] Diff ]
Fixed issue 07236: Unable to concatenate number : join is undefined
Dev: adding join($arg), alias of implode("",$arg)
mod - application/helpers/expressions/em_core_helper.php Diff ] File ]
mod - scripts/expressions/em_javascript.js Diff ] File ]
LimeSurvey: 2.1 586d0ecc
Timestamp: 2013-02-09 16:18:28
Author: DenisChenu
Committer: Denis Chenu
Details ] Diff ]
Fixed issue 07236: Different behaviour of + in EM in same group or next group
Dev: Just fix partially, have to add join function to concatenate 2 number
mod - application/helpers/expressions/em_core_helper.php Diff ] File ]
LimeSurvey: 2.1 ac112709
Timestamp: 2013-02-09 16:31:06
Author: DenisChenu
Committer: Denis Chenu
Details ] Diff ]
Fixed issue 07236: Unable to concatenate number : join is undefined
Dev: adding join($arg), alias of implode("",$arg)
mod - application/helpers/expressions/em_core_helper.php Diff ] File ]
mod - scripts/expressions/em_javascript.js Diff ] File ]

- Issue History
Date Modified Username Field Change
2013-01-27 14:31 DenisChenu New Issue
2013-01-27 14:31 DenisChenu File Added: limesurvey_survey_concatenate.lss
2013-01-27 14:34 DenisChenu Note Added: 23831
2013-01-28 11:06 c_schmitz Note Added: 23839
2013-01-28 11:10 DenisChenu Note Added: 23842
2013-01-28 11:10 DenisChenu Assigned To => DenisChenu
2013-01-28 11:10 DenisChenu Status new => assigned
2013-01-28 11:10 DenisChenu Category Expression Manager => Documentation
2013-01-28 11:14 DenisChenu Note Added: 23843
2013-01-28 11:14 DenisChenu Assigned To DenisChenu =>
2013-01-28 11:14 DenisChenu Status assigned => new
2013-01-28 11:14 DenisChenu Category Documentation => Expression Manager
2013-01-28 11:14 DenisChenu Summary Unable to concatenate number => Unable to concatenate number : + don't work and join is undefined
2013-01-28 11:15 DenisChenu Note Added: 23844
2013-01-28 11:16 DenisChenu Additional Information Updated View Revisions
2013-01-28 12:06 c_schmitz Note Added: 23847
2013-01-28 18:32 TMSWhite Note Added: 23849
2013-01-28 19:41 DenisChenu Note Added: 23852
2013-01-28 19:42 DenisChenu Note Edited: 23852 View Revisions
2013-01-28 19:50 TMSWhite Note Added: 23853
2013-01-28 23:07 DenisChenu Note Added: 23856
2013-01-28 23:10 DenisChenu Note Added: 23857
2013-01-28 23:25 TMSWhite Note Added: 23858
2013-01-29 08:03 DenisChenu Note Added: 23867
2013-01-29 23:57 Mazi Note Added: 23894
2013-01-30 11:11 DenisChenu Note Added: 23896
2013-01-30 11:11 DenisChenu Note Edited: 23896 View Revisions
2013-01-30 11:12 DenisChenu Assigned To => DenisChenu
2013-01-30 11:12 DenisChenu Status new => assigned
2013-01-31 21:13 DenisChenu File Added: limesurvey_survey_concatenate_samegroup.lss
2013-01-31 21:14 DenisChenu Note Added: 23927
2013-01-31 21:20 DenisChenu Changeset attached => LimeSurvey master 911185fb
2013-01-31 21:20 DenisChenu Note Added: 23928
2013-01-31 21:20 DenisChenu Resolution open => fixed
2013-02-01 10:37 DenisChenu Changeset attached => LimeSurvey master 8167e5ae
2013-02-01 10:37 DenisChenu Note Added: 23931
2013-02-01 10:37 DenisChenu Status assigned => resolved
2013-02-01 10:37 DenisChenu Fixed in Version => 2.00+
2013-02-07 10:52 c_schmitz Note Added: 23963
2013-02-07 10:52 c_schmitz Status resolved => closed
2013-02-09 17:21 DenisChenu Changeset attached => LimeSurvey 2.1 586d0ecc
2013-02-09 17:21 DenisChenu Note Added: 24017
2013-02-09 17:34 DenisChenu Changeset attached => LimeSurvey 2.1 ac112709
2013-02-09 17:34 DenisChenu Note Added: 24018


Copyright © 2000 - 2014 MantisBT Team
Powered by Mantis Bugtracker