Show image on table based on date element

Status
Not open for further replies.

confis

Member
Hi,
I would like to show in my table different image based on another data element on the same table.


means
if the date on the data element was past today date the image on the table will be change to red.
if the date is smaller then today the image on the table will be green.
Etc,

see attach

please advice how to do it

Regards,
Yaniv
 

Attachments

  • 1.png
    1.png
    94.2 KB · Views: 332
Use a calc element.

The PHP would be something like this:

PHP:
$img_src = '/path/to/your/icons/folder';
$row_completed = '{youtable___completed}';
if ($row_completed = '1') {
    $img_icon = 'completed.png';
    $img_alt = 'Completed';
}
else {
    $row_date = strtotime('{yourtable___yourdate}');
    $img_icon = 'on_time.png';
    $img_alt = "On Time";
    if ($row_date < time()) {
        $img_icon = 'late.png';
        $img_alt = "Late"
    }
}
return "<img src='" . $img_path . "/" . $img_icon . "' alt='" . $img_alt . "' />";

Obviously your element names, and the folder and icon names, will be different, and your 'completed' value will depend on what element type that is, etc.

But that should give you an idea of how to proceed. Basically you use {tablename___elementname} placeholders to grab you element values, and set up your icon according to various tests on those values.

-- hugh
 
Thanks,
How to install the calc element in Fabrik 3 the instructions on github are quite confusing
 
Grab the latest github ZIP:

https://github.com/Fabrik/fabrik/zipball/master

Unzip it, and upload everything to your server, overwriting your existing files.

Go to J! extensions manager, purge cache and "discover".

Install any new plugins you want.

As of the next main release of Fabrik (3.0.6) we should be providing installable ZIP's for the non-core plugins, so hopefully this will be the only time you have to do this.

-- hugh
 
Thanks,

I managed to installed it

the code you help me with, not working for me
i use simple code to check it and its seams that its not working

I always get the red image even when my $row_completed = '1' is not '1'

http://my-flowers.com.sg/axiom/index.php/reports

please help

----------------------
$img_path = '/axiom/images/status/';
$row_completed =('{fab_myflower_reports___analysis_status_raw}');
if ($row_completed = '1')
{
$img_icon = 'Red.png';
}
else
{
$img_icon = 'Green.png';
}
return "<img src='" . $img_path . "/" . $img_icon . "' />";
-------------------------
 
its works,
the correct syntax is double == not one =

$img_path = '/axiom/images/status/';
$row_completed =('{fab_myflower_reports___analysis_status_raw}');
if ($row_completed == '1')
{
$img_icon = 'Red.png';
}
else
{
$img_icon = 'Green.png';
}
return "<img src='" . $img_path . "/" . $img_icon . "' />";
 
Hi,

I manage to work with the image change based on status

but the date is not working

the scenario is
if the date is smaller than today the the image need to be red (not working)

$img_path = '/axiom/images/status/';
$row_completed =('{fab_myflower_reports___analysis_status_raw}');
$row_date = strtotime('{fab_myflower_reports___Required_Date_raw}');
if ($row_completed == '1')
{
$img_icon = 'Blue.png';
}
elseif ($row_completed == '2')
{
$img_icon = 'Orange.png';
}
elseif ($row_completed == '3')
{
$img_icon = 'Green.png';
}
elseif ($row_completed == '4')
{
$img_icon ='Red.png';
}
elseif ($row_date < 'date()')
{
$img_icon = 'Red.png';
}
return "<img src='" . $img_path . "/" . $img_icon . "' />";

Please advice
Regards,
Yaniv
 
Try
elseif ($row_date < time())

'date()' is just the litterally string, date() needs a format and would return a formatted date string
 
Tried
Same the image not change to red :(

$img_path = '/axiom/images/status/';
$row_completed =('{fab_myflower_reports___analysis_status_raw}');
$row_date = strtotime('{fab_myflower_reports___delivery_date}');
if ($row_completed == '1')
{
$img_icon = 'Blue.png';
}
elseif ($row_completed == '2')
{
$img_icon = 'Orange.png';
}
elseif ($row_completed == '3')
{
$img_icon = 'Green.png';
}
elseif ($row_completed == '4')
{
$img_icon ='Red.png';
}
elseif ($row_date < time())
{
$img_icon = 'Red.png';
}
return "<img src='" . $img_path . "/" . $img_icon . "' />";
 
Make sure the date is in a format strtotime() can understand. Easiest way to do this is include that placeholder in the text you return from the calc, so you can see it on the list:

PHP:
return "{fab_myflower_reports___delivery_date} <img src='" . $img_path . "/" . $img_icon . "' />";

... and made sure it is something sensible, like YYYY/MM/DD HH:MM:SS or whatever.

But ... I suspect the issue is a logic problem. In the case where you want to show red because the date is late, what is the $row_completed going to be?

Remember that a daisy chained if / elseif is going to act on the first condition that is true. So if your $row_completed is any of 1, 2, 3 or 4, then it's never going to get as far as testing for the date.

So if you want to show red if date is less than today, regardless of $row_completed value, you need to put the date test first.

-- hugh
 
Hi,

Thank for your answer

Its working :D, the issue was as you said a logic problem.

this is the working code
-----------------
$img_path = '/axiom/images/status/';
$row_completed =('{fab_myflower_reports___analysis_status_raw}');
$row_date = strtotime('{fab_myflower_reports___delivery_date}');
if ($row_completed == '1')
{
$img_icon = 'Blue.png';
}
elseif ($row_date < time())
{
$img_icon = 'Red.png';
}
elseif ($row_completed == '2')
{
$img_icon = 'Orange.png';
}
elseif ($row_completed == '3')
{
$img_icon = 'Green.png';
}

elseif ($row_completed == '4')
{
$img_icon ='Red.png';
}
return "<img src='" . $img_path . "/" . $img_icon . "' />";
-----------------
Thank you very much
Regards,
Yaniv
 
Status
Not open for further replies.
We are in need of some funding.
More details.

Thank you.

Members online

No members online now.
Back
Top