Hello to all.
β
I am trying to implement following code somewhere in the CCv6 Connection:
β
$today = date("d.m.Y");
$polTerm = $this->data['polTerm'];
if ($polTerm < $today) {
echo '<td style="color: red;">$polTerm </td>';
}
where date saved in DB Column 'polTerm' and Read in the CCv6 Table column turns red if it is earlier than today,
but did not succeed because of several possible reasons:
β
1. Code is completely wrong π ;
2. Place in CCv6 where this code is executed is completely wrongπ
β
I tried two ways:
1. implement this code with Read Data function in Where conditions , but got the following error: Unknown column 'Submission.<td style="color' in 'where clause';
2. Create PHP function and then call it in index before Table view.
β
None is working.
β
I would be very happy if someone helped me with this.
β
In addition, what would be code if I wanted to create filter with this conditon?
β
Thank you in advance -
Elita
β
I am trying to implement following code somewhere in the CCv6 Connection:
β
$today = date("d.m.Y");
$polTerm = $this->data['polTerm'];
if ($polTerm < $today) {
echo '<td style="color: red;">$polTerm </td>';
}
where date saved in DB Column 'polTerm' and Read in the CCv6 Table column turns red if it is earlier than today,
but did not succeed because of several possible reasons:
β
1. Code is completely wrong π ;
2. Place in CCv6 where this code is executed is completely wrongπ
β
I tried two ways:
1. implement this code with Read Data function in Where conditions , but got the following error: Unknown column 'Submission.<td style="color' in 'where clause';
2. Create PHP function and then call it in index before Table view.
β
None is working.
β
I would be very happy if someone helped me with this.
β
In addition, what would be code if I wanted to create filter with this conditon?
β
Thank you in advance -
Elita
Hi Elita,
β
Assuming your PHP function name is php, you can call {fn:php} in the table columns views, and use this code in the PHP function:
β
Assuming your PHP function name is php, you can call {fn:php} in the table columns views, and use this code in the PHP function:
$today = date("m.d.Y");Best regards
$polTerm = $this->data['polTerm'];
if ($polTerm < $today) {
echo '<div style="color: red;">'.$polTerm.'</div>';
}else{
echo $polTerm;
}
Hello, Max, thank you for your help; The good thing - I got this code executedπ The bad thing - it got parse error:
β
β
Got this code passed php code syntax check for php-7.1.4:
β
β
Parse error: syntax error, unexpected (T_STRING) in your code on line 2:Could you tell whats wrong here - I'm bad with php, sorry.
$polTerm = $this->data['polTerm'];
β
Got this code passed php code syntax check for php-7.1.4:
β
$polterm = $this->get('submissions_list.row.Submission.polTerm');but it still generates an error in CCv6: 0syntax error, unexpected '<' - do you have an idea why, Max?
$today = $date = JFactory::getDate();
if($today > $polterm){
<div style="color: red;"><?php echo $polterm ?></div>
}else{
echo $polterm;
}
Hi Elita,
β
The 2nd piece of code is wrong, the 4th line should be like this:
β
Best regards
β
The 2nd piece of code is wrong, the 4th line should be like this:
echo '<div style="color: red;">'.$polterm.'</div>';The first code, where is line 2 ?
β
Best regards
This was line 2
β
This was the previous code version that gave that parse error:
$polTerm = $this->data['polTerm'];So I tried to rewrite it and found somewhere this:
$polterm = $this->get('submissions_list.row.Submission.polTerm');Do not know if this is right though.
β
This was the previous code version that gave that parse error:
$today = date("d.m.Y");
$polTerm = $this->data['polTerm'];
if ($polTerm < $today) {
echo '<div style="color: red;">'.$polTerm.'</div>';}
else{
echo $polTerm;}
Tried this code below and got 0 syntax error, unexpected '' (T_STRING), (php-7.1.4)
$polterm = $this->get('submissions_list.row.Submission.polTerm');
$today = $date = JFactory::getDate();
if($today > $polterm){
echo '<div style="color: red;">'.$polterm.'</div>';
}else{
echo $polterm;
}
Hi Elita,
β
Pay attention not to copy the code from the forum here as there are some hidden characters which cause a PHP error, try the write the code yourself until I can fix this problem here.
β
Best regards
β
Pay attention not to copy the code from the forum here as there are some hidden characters which cause a PHP error, try the write the code yourself until I can fix this problem here.
β
Best regards
Function is working, however one problem appeared:
[polTerm] field contains data that is saved with CF6 calendar and formatted as follows:
β

β
And it seems not to be the correct date format. Question is - how to convert the field data so it could be properly compared to today date?
[polTerm] field contains data that is saved with CF6 calendar and formatted as follows:
β

β
And it seems not to be the correct date format. Question is - how to convert the field data so it could be properly compared to today date?
Hi Elita,
β
The "Real format" is the format under which the date value is saved and it should match the format of the read date value, under which format you store your date ? if it does not match the "real format" then you will need to change it using PHP before the "Display section" action.
β
Best regards
β
The "Real format" is the format under which the date value is saved and it should match the format of the read date value, under which format you store your date ? if it does not match the "real format" then you will need to change it using PHP before the "Display section" action.
β
Best regards
What confusing me Max, (sorry im just learning PHP), is that DD.MM.YYYY does not to seem to be right format PHP would understand -
So probably this DD.MM.YYYY has to be somehow formatted for PHP to read that properly as Date?
the numbers that are stored in the DB field are as following example: 02.01.2018
So probably this DD.MM.YYYY has to be somehow formatted for PHP to read that properly as Date?
the numbers that are stored in the DB field are as following example: 02.01.2018
Hi Elita,
β
If the dates are stored in the database as 02.0.1.2018 and your "Real format" is DD.MM.YYYY then no formatting should be made, you can get the timestamp of this date using the PHP function "strtotime", then do the comparison to today's date in PHP too: strtotime(date("d.m.y"))
β
Best regards
β
If the dates are stored in the database as 02.0.1.2018 and your "Real format" is DD.MM.YYYY then no formatting should be made, you can get the timestamp of this date using the PHP function "strtotime", then do the comparison to today's date in PHP too: strtotime(date("d.m.y"))
β
Best regards
I got this code working:
β
1. Create php function with the similar code written above;
2. Add this function to Table Columns views:
$polterm = $this->get('submissions_list.row.Submission.polTerm');To resume, for everybody who wants to format table cells based on Current date, do following:
$endDate = new DateTime($polterm);
$curdate = new DateTime(date('d.m.Y'));
if($curdate > $endDate){
echo '<div style="color: red;">'.$polterm.'</div>';
}else{
echo $polterm;
}
β
1. Create php function with the similar code written above;
2. Add this function to Table Columns views:
Model.fieldname:{fn:php_function}
This topic is locked and no more replies can be posted.