I try to migrate the following condition without success:
[globalVar = GP:tx_news_pi1|news > 0] || [globalVar = GP:tx_news_pi1|news_preview > 0] && [PIDinRootline = 123, 456]
I tried something like this, but none of my attempts seem to work:
[traverse(request.getQueryParams(), 'tx_news_pi1/news') > 0 || traverse(request.getQueryParams(), 'tx_news_pi1/news_preview') > 0] && [123 in tree.rootLineIds || 456 in tree.rootLineIds]
How do i have to write such complex conditions in Symfony Expression Language/TypoScript?
I think you need to write the complete condition into one square brackets expression:
[traverse(request.getQueryParams(), 'tx_news_pi1/news') > 0 || traverse(request.getQueryParams(), 'tx_news_pi1/news_preview') > 0] && (123 in tree.rootLineIds || 456 in tree.rootLineIds)]
Related
Assuming that A = True, B = False and C = True.
Give the results of the following Boolean operations
AB + BC’ (A + B’C) + B
(b) ABC’ + (B + AC’)B + A’
in boolean multiply operation is AND (&&) operation
and plus + operation is OR(||) operation
and ' operator measn NOT(!)
so,
AB + BC’ (A + B’C) + B
can be written as
(A && B) || [(B && (!C)) && (A || ((!B) && C))] || B
PUTTING THE VALUE IN THE ABOVE EQUATION
= (1 && 0) || [(0 && (!0)) && (1 || ((!1) && 1))] || 1
= 0 || [(0 && 1 )&& (1 || (0 && 1)] ||1
= 0 || [(0 && 1) && (1 || 0)] ||1
= 0 || [0 && 1] ||1
= 0 || 0 || 1
= 1
I KNOW IT IS HARD TO FOLLOW BUT THE ANSWER WILL BE 1
AND FOLLOWING THE SAME LOGIC THE ANSWER TO THE 2ND STATEMENT WILL ALSO BE 1
IF YOU WANT TO UNDERSTAND HOW THIS WORKS PLEASE READ THE DOCS
I would like to build query Range, where
ActiveTo < today || ActiveFrom > today.
Is it possible, I tried something like that but it's not working.
qbdsDimAttrValue = ds.addDataSource(tableNum(DimensionAttributeValue));
qbrMainAccountActiveFrom = qbdsDimAttrValue.addRange(fieldnum(DimensionAttributeValue,ActiveFrom));
qbrMainAccountActiveFrom.value(strFmt('(((%1.%2 != 0) || (%1.%3 != 0)) && ((%1.%2 > %4) || (%1.%3 < %4)))',
qbdsDimAttrValue.name(),
fieldStr(DimensionAttributeValue,ActiveFrom),
fieldStr(DimensionAttributeValue,ActiveTo),
today(),
));
I write 0, because in table DimensionAttributeValue if field ActiveFrom, ActiveTo is null it has value 0, not dateNull(), dateMax()
Date values used in such queries must be in the dd\MM\yyyy format - you can use function date2StrXpp() for this purpose.
Try using the following range:
qbrMainAccountActiveFrom.value(
strFmt('((%1.%2 > %4) || ((%1.%3 < %4) && (%1.%3 != %5)))',
qbdsDimAttrValue.name(),
fieldStr(DimensionAttributeValue, ActiveFrom),
fieldStr(DimensionAttributeValue, ActiveTo),
date2StrXpp(systemDateGet()),
date2StrXpp(dateNull())
));
If you check Global::dateNull() you will see that it returns '01\01\1900', also you can see that database doesn't store 0 in these fields:
Yo can find more details here
So you can simplify your extended range as follows
qbrMainAccountActiveFrom.value(strFmt('((%1.%2 > %4) || (%1.%3 < %4))',
qbds.name(),
fieldStr(DimensionAttributeValue, ActiveFrom),
fieldStr(DimensionAttributeValue, ActiveTo),
today()
));
I need such a condition in ts:
([treeLevel = 0] && [globalVar = GP:R > 0]) || [PIDinRootline = {$pages.2018}]
I wanna show block if page has treelevel=0 and the get var R > 0, or if page id = $pages.2018
It looks like the similar code in php:
if(($treeLevel == 0 && $r > 0) || (pid == number))
The all expression in first brackets should be right, or in second.
Is it exist the method to group it like the previous record or I can only use userfunc?
There is no grouping in TS conditions, but if you need this particular condition from your post I think it is not needed because brackets around && are useless in this case.
(p && q) || r
is exactly the same as
p && q || r
Did you tested it?
I write an algorithm that checks the stability of the closed system of the Nyquist criterion (http://en.wikipedia.org/wiki/Nyquist_stability_criterion)
function answear=stability(re,im)
%% Function check stability of system
%re is real part of transmitation
%im is imagine part of transmitation
%% Check number of vectors elements
re(end +1:5) = 0;
im(end +1:5) = 0;
if( length(re) > length(im))
root = length(re);
else
root = length(im);
end
for w=1:root
tran(w) = re(1) + re(2)*w.^1 + re(3)*w.^2 + re(4)*w.^3 + re(5)*w.^4 +1i*(...
im(1) + im(2)*w.^1 + im(3)*w.^2 + im(4)*w.^3 +im(5)*w.^4);
end
%% Algorithm
switch root
case 0
exist('Write nonzero numbers', 'var')
case 1
for w=1:length(w)
if( real(tran(w)) > 0 && imag(tran(w)) > 0)
answear=1;
else
answear=0;
end
end
case 2
for w=1:length(w)
if( real(tran(w)) > 0 && imag(tran(w)) > 0)
if( real(tran(w)) < 0 && imag(tran(w)) > 0)
answear=1;
else
answear=0;
end
end
end
case 3
for w=1:length(w)
if( real(tran(w)) > 0 && imag(tran(w)) > 0)
if( real(tran(w)) < 0 && imag(tran(w)) > 0)
if( real(tran(w)) < 0 && imag(tran(w)) < 0)
answear=1;
else
answear=0;
end
end
end
end
case 4
for w=1:length(w)
if( real(tran(w)) > 0 && imag(tran(w)) > 0)
if( real(tran(w)) < 0 && imag(tran(w)) > 0)
if( real(tran(w)) < 0 && imag(tran(w)) < 0)
if( real(tran(w)) > 0 && imag(tran(w)) < 0)
answear=1;
else
answear=0;
end
end
end
end
end
end
%% Answear
if answear==1
disp('System unstable')
else
disp('System stable')
end
plot(real(tran),imag(tran))
grid on
end
Function returns
Undefined function or variable "answear".
Error in stability (line 87) if answear==1
So the algorithm is badly written?
Your code could use a lot of cleanup:
Instead of an if-statement such as this one:
if( real(tran(w)) > 0 && imag(tran(w)) > 0)
answear=1;
else
answear=0;
end
you could write a boolean assignment:
answear = real(tran(w)) > 0 & imag(tran(w)) > 0);
Why do you have three (almost) identical nested if-statements at all?
if( real(tran(w)) > 0 && imag(tran(w)) > 0)
if( real(tran(w)) < 0 && imag(tran(w)) > 0)
if( real(tran(w)) < 0 && imag(tran(w)) < 0)
First of all, you could replace everything with one if-statement. But what are you actually testing with this? It seems that those nested if statements are never executed. For instance, real(tran(w)) cannot be both positive and negative at the same time (unless it is a vector you are working on, in which case you shouldn't be using the operator &&).
Also, this is probably your code triggers the error regarding variable answear. Accessing it is impossible since it hasn't been assigned a value (none of the if-statements have been executed).
What is tran, and what is w? Are they global variables? If they are, pass them as input parameters. Your function is probably poorly designed if it relies on external states and variables.
I haven't actually run your code, but these suggestions should make it easier for you to debug it.
P.S:
Please fix the annoying spelling error (it is "answer" and not "answear") :)
If I have a function with 2 inputs, is there a way to test both its range other than nested if functions?
For example...
if input1 > 0 && input1 <10 && input2 > 0 && input2 <10
this doesn't work so I'm forced to write
if input1 > 0 && input1 <10
if input2 > 0 && input2 <10
'%something
end
end
Are there easier ways to test range of multiple inputs?
I don't know of a way to avoid nested if functions, but you can avoid repetition:
In JavaScript:
function test(argument1,argument2) {
check = 0;
for (i=0;i<arguments.length;i++){
if (arguments[i] > 0 && (arguments[i] < 10)) {
check++;
if (check === arguments.length) {
//do something
}
}
}
}
test(1,2);
Try this in Matlab:
find((input1==1:20),1) & find((input2==50:100),1)