If condition in mediawiki not working so that please help me - mediawiki

i want to display image when hideDiploma field is not 1. i will try for that but not working
the code as follow:
{{
#if:{{{hideDiploma|}}}|<div class="image" style="display:none;">|<div class="image">
}}

when hideDiploma field is not 1
Note that you are only checking if the parameter was actually set to anything. If you want to check for equality with 1, you could do it like this:
{{ #ifeq: {{{hideDiploma|}}} | 1
| <div class="image" style="display:none;">
| <div class="image">
}}
Or if you want to allow multiple values, e.g. yes and y, you could use a switch:
{{ #switch: {{{hideDiploma|}}}
| 1 | yes | y = <div class="image" style="display:none;">
| #default = <div class="image">
}}

Related

Getting max from a string list in jinja2

I would like to get a max value from a list. I have a homeassistant configuration that I would like to work, but for some reason list is considered as string value, and I get ] character as max value:
{% set value = ['nema','niska','nema'] %}
{% set list = value | replace("nema", 0 ) | replace("niska", 1 | int) | replace("visoka", 2) | replace("vrlovisoka", 3) %}
{{ list | max }}
If I use {{ list | map('int') | max }} like other posts suggest, I just get an error ValueError: Template error: int got invalid input '[' when rendering template
How can I make this work?

what does # symbol do in this [#][] ansible code?

I would like to know what # symbol does in this line of code and [#][] do? This is being used in Ansible. Thank you.
json_query("response.result.job | [#][]")
The whole code:
- name: task1
<removed for simplicity>
cmd: 'show jobs all'
register: all_jobs
until: |
all_jobs is not failed
and (all_jobs.stdout | from_json | json_query("response.result.job|[#][]") | default([], true) | length > 0)
and (all_jobs.stdout | from_json | json_query("response.result.job|[#][]")
| json_query("[?status != 'FIN']") | length == 0)
retries: 60
delay: 30
For those who are curious, I think I found the answer. It is all about jmespath. # is the current node. [] will flat a list. [][] will flat nested lists. [#][] will flat second level list. To understand this please go to this link below. There are examples there.
https://jmespath.org/tutorial.html

Table padding in td

its very weird that i have padding in my td but it was 0 padding at all in my inspect element i see padding when i hover in my td? any idea of this?
its very weird lol.
here's my html
table.md-table border="1"
tr.md-table-content-row ng-repeat="(payroll_type, taxes) in ctrl.table_taxes | groupBy:'payroll_type'"
td.md-table-content.tax_table
div.pay-type layout="row" layout-align="center center" style="height:20px;"
| {{ payroll_type | capitalize }}
md-button.md-mini.md-primary.md-icon-button.md-mr-0.md-pd-0 ng-show="taxtableform.$visible" ng-click="ctrl.addTaxStatus(taxes)"
md-icon.material-icons.md-fnt-sz-20 add_circle_outline
md-tooltip Add Tax Status
hr
div.md-ta-c style="height:20px;"
| Exemption
hr
div.md-ta-c style="height:20px;"
| Status
hr
span ng-repeat="(status_name, taxes4) in taxes | groupBy:'payroll_type'"
div.md-ta-c ng-repeat="tax in taxes4 | unique:'status_name'| orderBy: 'status_name'" style="height:20px;"
hr
| {{ tax.status_name }}
td.md-table-content.tax_table.md-ta-r ng-repeat="(column_no, taxes2) in taxes | groupBy:'column_no'"
div.md-ta-c.md-mr-t-1 layout="row" layout-align="center center" style="height:20px;"
span
| {{ column_no }}
md-button.md-mini.md-primary.md-icon-button.md-mr-0.md-pd-0 ng-show="taxtableform.$visible" ng-click="ctrl.removeColumn(taxes2)"
md-icon.material-icons.md-fnt-sz-20 delete
md-tooltip Delete Column
hr
span ng-repeat="(exemption, taxes3) in taxes2 | groupBy:'exemption'"
div.item-wrapper style="height:20px;"
span ng-hide="taxtableform.$visible" e-style="width:50px;" editable-text="exemption" e-form="taxtableform" onbeforesave="ctrl.exemptionChecker($data, exemption, taxes2)"
| {{ exemption | number: 2 }}
hr
span ng-repeat="(over_percentage, taxes3) in taxes2 | groupBy:'over_percentage'"
div.item-wrapper style="height:20px;"
span ng-hide="taxtableform.$visible" e-style="width:50px;" editable-text="over_percentage" e-form="taxtableform" onbeforesave="ctrl.percentageChecker($data, over_percentage, taxes3)"
| {{ over_percentage | number: 2 }}
hr
span ng-repeat="tax in taxes2 | orderBy:'status_name'"
hr
div.item-wrapper style="height:20px;"
span ng-hide="taxtableform.$visible" e-style="width:50px;" editable-text="tax.amount" e-form="taxtableform" onbeforesave="ctrl.taxAmountChecker($data, tax)"
| {{ tax.amount }}
can u try to add this style at table
border-collapse: collapse;

Computing a Weighted Average with Liquid Template Filters

I'm using Jekyll with its Liquid Templates hosted on Github Pages and I'd like to compute a weighted average, but I don't see a way to deal with order of operations using Liquid math filters.
For example I'd like to compute something like:
{{ (page.x | times:.4) | plus:(page.y | times:.6) }}
--> (x * .4) + (y * .6)
But it seems the parenthesis are ignored an I'm effectively getting:
{{ page.x | times:.4 | plus:page.y | times:.6 }}
--> (((x * .4) + y) * .6)
Liquid filters are applied one at a time in the order they appear, using the former value. You cannot change precedence with parenthesis (you can only do this with if conditionals).
Here you have to split you operation like this :
{% assign a = x | times:.4 %}
{% assign b = y | times:.6 %}
{% assign c = a | plus: b %}

Save an excel/cvs file from mysql using PHP [run via a cron job]

I have some results from a mysql table that I would like to export, I am currently able to click a download link and download an xls but I would like to be able to run this via a cron job and have the weekly results email to me.
I have looked at doing this from Mysql and save it out as a csv directly.
However I am struggling with the SQL, the table format is as follows
btFormQuestions (some columns ommitted)
+-------+---------------+----------+-----------+
| msqID | questionSetId | Question | InputType |
|-------+---------------+----------+-----------+
| 1 | 123456 | Name | field |
| 2 | 123456 | Telephone| field |
| 3 | 123456 | Email | email |
| 4 | 123456 | Enquiry | test |
btFormAnswers
+-----+------+-------+-----------------+
| aID | asID | msqID | answer |
+-----+------+-------+-----------------+
| 1 | 1 | 1 | Sean |
| 2 | 1 | 2 | 0800 0 |
| 3 | 1 | 3 | se#te.com |
| 4 | 1 | 4 | Asking Question |
btFormAnswersSet
+------+---------------+---------------------+
| asID | questionSetId | created |
+------+---------------+---------------------+
| 1 | 123456 | 2013-04-30 11:07:55 |
The sql queries, I am currently using to get the information into PHP and into an array is as follows:
//get answers sets
$sql='SELECT * FROM btFormAnswerSet AS aSet '.
'WHERE aSet.questionSetId='.$questionSet.' ORDER BY created DESC LIMIT 0, 100;
$answerSetsRS=$db->query($sql);
//load answers into a nicer multi-dimensional array
$answerSets=array();
$answerSetIds=array(0);
while( $answer = $answerSetsRS->fetchRow() ){
//answer set id - question id
$answerSets[$answer['asID']]=$answer;
$answerSetIds[]=$answer['asID'];
}
//get answers
$sql='SELECT * FROM btFormAnswers AS a WHERE a.asID IN ('.join(',',$answerSetIds).')';
$answersRS=$db->query($sql);
//load answers into a nicer multi-dimensional array
while( $answer = $answersRS->fetchRow() ){
//answer set id - question id
$answerSets[$answer['asID']]['answers'][$answer['msqID']]=$answer;
}
return $answerSets;
I would like to be able to do one of the following
A.) Move all of this into one query to be able to get the following sort of result
+---------------+------+-----------+-----------+-----------------+
| QuestionSetID | Name | Telephone | Email | Enquiry |
+---------------+------+-----------+-----------+-----------------+
| 123456 | Sean | 0800 0 | se#te.com | Asking Question |
(I did try this with various joins but could not get them quite right)
If I could get this to work I would not mind saving as a CSV
B.) Output the returned array as excel file that can be saved to a location on the server,
The current code creates a html table from the array
The code is a little long so I am only pasting the top and bottom bits here
//fwrite($handle, $excelHead);
//fwrite($handle, $row);
//fflush($handle);
ob_start();
header("Content-Type: application/vnd.ms-excel");
echo "<table>\r\n";
//Question headers go here
foreach($answerSets as $answerSetId=>$answerSet){
$questionNumber=0;
$numQuestionsToShow=2;
echo "\t<tr>\r\n";
echo "\t\t<td>". $dateHelper->getSystemDateTime($answerSet['created'])."</td>\r\n";
foreach($questions as $questionId=>$question){
$questionNumber++;
if ($question['inputType'] == 'checkboxlist'){
$options = explode('%%', $question['options']);
$subanswers = explode(',', $answerSet['answers'][$questionId]['answer']);
for ($i = 1; $i <= count($options); $i++)
{
echo "\t\t<td align='center'>\r\n";
if (in_array(trim($options[$i-1]), $subanswers)) {
// echo "\t\t\t".$options[$i-1]."\r\n";
echo "x";
} else {
echo "\t\t\t \r\n";
}
echo "\t\t</td>\r\n";
//fwrite($handle, $node);
//fflush($handle);
}
}elseif($question['inputType']=='fileupload'){
echo "\t\t<td>\r\n";
$fID=intval($answerSet['answers'][$questionId]['answer']);
$file=File::getByID($fID);
if($fID && $file){
$fileVersion=$file->getApprovedVersion();
echo "\t\t\t".''.$fileVersion->getFileName().''."\r\n";
}else{
echo "\t\t\t".t('File not found')."\r\n";
}
echo "\t\t</td>\r\n";
}else{
echo "\t\t<td>\r\n";
echo "\t\t\t".$answerSet['answers'][$questionId]['answer'].$answerSet['answers'][$questionId]['answerLong']."\r\n";
echo "\t\t</td>\r\n";
}
//fwrite($handle, $node);
//fflush($handle);
}
echo "\t</tr>\r\n";
//fwrite($handle, $row);
//fflush($handle);
}
echo "</table>\r\n";
//fwrite($handle, $excelFoot);
//fflush($handle);
//fclose($handle);
file_put_contents($filePath, ob_get_clean());
I can get the file to save to the directory but I am having issues setting it as an Excel file, I have also tried, playing with Fwrite (instead of the buffer) with the similar results
can anyone help, or point me in the right location.
Thank you,
Sean
I would do this from within concrete5. That way you get all the form-results-related models, plus the various helpers (like email).
For more info about jobs, see http://www.concrete5.org/documentation/developers/system/jobs/ . To run from a cron job, see http://www.concrete5.org/documentation/how-tos/developers/how-to-run-certain-jobs-via-cron/ .
It looks like you've got the code to generate the answers, and put it into an array, but you might want to look at something like https://github.com/concrete5/concrete5/blob/master/web/concrete/core/controllers/blocks/form_statistics.php#L32 . I'm not positive that's exactly what you need, but I do know that the dashboard page builds that answers table for you, so the code clearly exists somewhere.
Finally, to create an excel file, elsewhere c5 uses the "put it into a table and call it .xls" method, which works with excel and open office. I'm not sure exactly what you mean by "having issues setting it as Excel", but it sounds like this is your issue at the moment. If something is getting saved to the file, then you should post the file contents and you/we can work backwards as to what is causing the issue. It's probably just misformatted HTML or something.
Finally, to send the email, you can use the Mail Helper, but that doesn't currently allow for attachments (there's a pull request in github that does, and that you could use to override the mail helper with). Typically, the "best practice" would be to send it as a link.