Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
SondagesPro-LimeSurvey-plugin
recomputeExpression
Commits
40b4f279
Commit
40b4f279
authored
Mar 01, 2019
by
Denis Chenu
Browse files
[fix] Question attribute 'equation' is not used
[fix] Unable to use it in 2.6 with 'urlFormat' => 'get',
parent
0fc8e4b8
Changes
2
Hide whitespace changes
Inline
Side-by-side
js/recompute.js
View file @
40b4f279
...
...
@@ -20,7 +20,7 @@
$
(
function
()
{
if
(
typeof
recomputeVar
!=
'
undefined
'
){
addUpdateResponse
();
addUpdateResponse
();
}
});
...
...
@@ -29,17 +29,11 @@ function addUpdateResponse()
var
docUrl
=
document
.
URL
;
var
jsonUrl
=
recomputeVar
.
jsonurl
;
var
aUrl
=
docUrl
.
split
(
'
/
'
);
var
surveyid
=
aUrl
[
aUrl
.
indexOf
(
"
surveyid
"
)
+
1
];
if
(
aUrl
.
indexOf
(
"
admin
"
)
>
0
){
var
controller
=
aUrl
[
aUrl
.
indexOf
(
"
admin
"
)
+
1
];
}
else
{
var
controller
=
aUrl
[
aUrl
.
indexOf
(
"
?r=admin
"
)
+
1
];
}
var
surveyid
=
recomputeVar
.
surveyId
;
var
responseId
=
recomputeVar
.
responseId
;
if
(
$
(
'
table.detailbrowsetable
'
).
length
>
0
)
// Browse one response
if
(
responseId
&&
$
(
'
table.detailbrowsetable
'
).
length
>
0
)
// Browse one response
{
// Find the response id
var
responseId
=
aUrl
[
aUrl
.
indexOf
(
"
id
"
)
+
1
];
// OR var responseId= aUrl.pop();
$
(
'
.menubar
'
).
eq
(
1
).
find
(
'
.menubar-main
'
).
find
(
"
.menubar-left:last
"
).
append
(
"
<a class='btn btn-small updateanswer' data-responseid='
"
+
responseId
+
"
'><i class='icon-refresh'></i>Update This Answer</a>
"
);
$
(
'
.updateanswer
'
).
click
(
function
(){
...
...
@@ -83,7 +77,7 @@ function addUpdateResponse()
});
});
}
if
(
controller
==
'
responses
'
){
if
(
surveyid
){
$
(
'
.menubar
'
).
eq
(
0
).
find
(
'
.menubar-main
'
).
find
(
"
.menubar-left:last
"
).
append
(
"
<a class='btn btn-small updateanswers'><i class='icon-refresh'></i>Update all submitted answers</a>
"
);
$
(
"
.updateanswers
"
).
click
(
function
(){
var
jsonurl
=
$
(
this
).
attr
(
'
rel
'
);
...
...
recomputeExpression.php
View file @
40b4f279
...
...
@@ -62,9 +62,13 @@
public
function
afterPluginLoad
()
{
if
(
strpos
(
Yii
::
app
()
->
request
->
getRequestUri
(),
'admin/responses'
)){
// Hack to register only on browse response
$surveyid
=
Yii
::
app
()
->
request
->
getparam
(
'surveyid'
);
$responseid
=
Yii
::
app
()
->
request
->
getparam
(
'id'
);
$aRecomputeVar
=
array
(
'jsonurl'
=>
$this
->
api
->
createUrl
(
'plugins/direct'
,
array
(
'plugin'
=>
'recomputeExpression'
,
'function'
=>
'recompute'
))
);
'jsonurl'
=>
$this
->
api
->
createUrl
(
'plugins/direct'
,
array
(
'plugin'
=>
'recomputeExpression'
,
'function'
=>
'recompute'
)),
'surveyId'
=>
$surveyid
,
'responseId'
=>
$responseid
,
);
Yii
::
app
()
->
getClientScript
()
->
registerScript
(
'aRecomputeVar'
,
'recomputeVar='
.
json_encode
(
$aRecomputeVar
),
CClientScript
::
POS_BEGIN
);
Yii
::
app
()
->
getClientScript
()
->
registerScriptFile
(
Yii
::
app
()
->
getConfig
(
'publicurl'
)
.
"plugins/recomputeExpression/js/recompute.js"
);
}
...
...
@@ -146,7 +150,7 @@
{
$iResponseId
=
$oResponse
->
id
;
$aOldAnswers
=
$oResponse
->
attributes
;
// Not needed but keep it
if
(
isset
(
$oResponse
->
token
)
&&
$oResponse
->
token
)
$sToken
=
$oResponse
->
token
;
// Fill $_SESSION['survey_'.$iSurveyId]
...
...
@@ -231,7 +235,12 @@
{
//($string, $questionNum=NULL, $replacementFields=array(), $debug=false, $numRecursionLevels=1, $whichPrettyPrintIteration=1, $noReplacements=false, $timeit=true, $staticReplacement=false)
$oldVal
=
$oResponse
->
$column
;
$newVal
=
$oResponse
->
$column
=
LimeExpressionManager
::
ProcessString
(
$aFieldMap
[
$column
][
'question'
],
null
,
array
(),
false
,
1
,
0
,
false
,
false
,
true
);
$equation
=
$aFieldMap
[
$column
][
'question'
];
$equationAttribute
=
QuestionAttribute
::
model
()
->
find
(
"qid = :qid and attribute = :attribute"
,
array
(
":qid"
=>
$aFieldMap
[
$column
][
'qid'
],
":attribute"
=>
'equation'
));
if
(
!
empty
(
$equationAttribute
)
&&
!
empty
(
$equationAttribute
->
value
))
{
$equation
=
$equationAttribute
->
value
;
}
$newVal
=
$oResponse
->
$column
=
LimeExpressionManager
::
ProcessString
(
$equation
,
null
,
array
(),
false
,
1
,
0
,
false
,
false
,
true
);
if
(
$oldVal
!=
$newVal
&&
(
$oldVal
&&
$newVal
))
{
$updatedValues
[
'old'
][
$sColumnName
]
=
$oldVal
;
...
...
@@ -285,4 +294,4 @@
die
();
}
}
?>
\ No newline at end of file
?>
Denis Chenu
@Shnoulle
mentioned in issue
#2 (closed)
·
Mar 01, 2019
mentioned in issue
#2 (closed)
mentioned in issue #2
Toggle commit list
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment