• Hello Fabrik Community

    Fabrik is now in the hands of the development team that brought you Fabrik for Joomla 4. We have recently transitioned the Fabrik site over to a new server and are busy trying to clean it up. We have upgraded the site to Joomla 4 and are running the latest version of Fabrik 4. We have also upgraded the Xenforo forum software to the latest version. Many of the widgets you might have been used to on the forum are no longer operational, many abandoned by the developers. We hope to bring back some of the important ones as we have time.

    Exciting times to be sure.

    The Fabrik 4.0 Official release is now available. In addition, the Fabrik codebase is now available in a public repository. See the notices about these in the announcements section

    We wish to shout out a very big Thank You to all of you who have made donations. They have really helped. But we can always use more...wink..wink..

    Also a big Thank You to those of you who have been assisting others in the forum. This takes a very big burden off of us as we work on bugs, the website and the future of Fabrik.

Int number displayed as HH:mm:ss

Status
Not open for further replies.

jo-ka

Member
Hello,
I've a List that is linked to a database table not from Fabrik, which stores the time consumed for an operation in seconds as an integer type.

Is there any way to display this seconds, perhaps on a field element, as HH:mm:ss?

I've tried with Sprintf option, but with no avail.

Thank's in advance.
 
I can't think of a way to do it in-place, no. You'll probably need to add a calc element, which renders it in the format you want ...

Code:
$dtF = new \DateTime('@0');
$dtT = new \DateTime("@{yourtable___timestamp}");
return $dtF->diff($dtT)->format('%a days, %h hours, %i minutes and %s seconds');

Replace yourtable___timestamp with your full element name.

If you can't add a new element to do that, you'll probably have to do it with a form plugin. Do you edit this data? So would you need to convert it back to seconds on submit? Or is this just for display purposes?

-- hugh
 
I can't think of a way to do it in-place, no. You'll probably need to add a calc element, which renders it in the format you want ...

Code:
$dtF = new \DateTime('@0');
$dtT = new \DateTime("@{yourtable___timestamp}");
return $dtF->diff($dtT)->format('%a days, %h hours, %i minutes and %s seconds');

Replace yourtable___timestamp with your full element name.

If you can't add a new element to do that, you'll probably have to do it with a form plugin. Do you edit this data? So would you need to convert it back to seconds on submit? Or is this just for display purposes?

-- hugh

Well, this is really part of a Quiz Module for Joomla, so I don't edit this data, I use it just for display purposes...
Is there a way to add an element to a table but which is not stored on the database? I believe not... So I could use a calc element, but for display only.
 
Well, this is really part of a Quiz Module for Joomla, so I don't edit this data, I use it just for display purposes...
Is there a way to add an element to a table but which is not stored on the database? I believe not... So I could use a calc element, but for display only.
You can try setting "save to db" to No on a Calc element. I haven't true it, but worth a go.

Sent from my HTC6545LVW using Tapatalk
 
You can try setting "save to db" to No on a Calc element. I haven't true it, but worth a go.

Sent from my HTC6545LVW using Tapatalk
Yes, but this will create a new field on the table, even though it doesn't have any value, right?

If the module owner make some changes on the database, it can go away later, or not?
 
Maybe a bit overkill, but you could

create a list dummycalc, elements id, calc (no save to db), dummyFK (field element)
join your quiz table.id to dummycalc.dummyFK
edit (unlink) the new quiz calc element

Such a dummylist could be used by several other lists.

Is it for list view, details view or both?
Other possibilities:
custom templates
form php onLoad
I assume it should be also possible to change the display with JS...
 
As it's for display purposes only, the onLoad PHP would probably be the easiest, which is available in list and form plugins.

-- hugh
 
As it's for display purposes only, the onLoad PHP would probably be the easiest, which is available in list and form plugins.

-- hugh

OnLoad PHP?

I was looking for this on my plugins list, and couldn't find it, even searching for nonactivated plugins. I've tried with PHP list plugin (don't know if this is the plugin, but I believe not) with the code you've suggested, but with no avail.

I was looking for the plugin in Fabrik's downloads area, but the downloads are empty!

Where can I find this plugin?
 
OK, I've now found the list plugin, PHP_events. Sorry for this.

Then, I've copied the code to the onLoadData and got this error:

DateTime::__construct(): Failed to parse time string (@{vbcko_quiz_r_student_quiz___c_total_time}) at position 0 (@): Unexpected character

What can possibly be wrong?

Thanks in advance
 
Nope, you can't use placeholders in that plugin. Did you look at the wiki?

http://fabrikar.com/forums/index.php?wiki/php-events-list-plugin/

You have to loop around the data yourself, and access the array directly.

So it'll be something like this:

Code:
$data = $model->getData();
$dtF = new \DateTime('@0');

foreach($data as $group) {
   foreach($group as $row) {
      $timestamp = $row->vbcko_quiz_r_student_quiz___c_total_time_raw;
      if (!empty($timestamp) && is_numeric($timestamp)) {
         $dtT = new \DateTime("@" . $timestamp);
         $row->vbcko_quiz_r_student_quiz___c_total_time = $dtF->diff($dtT)->format('%h:%i:%s');
      }
   }
}

-- hugh
 
Last edited:
Man, you're GREAT!
Thanks Hugh...
Just a slight correction, for a typo on your code:
...
$timestamp = $row=>vbcko_quiz_r_student_quiz___c_total_time_raw;
...

should be -> and not =>.

All the rest is perfect.

Thanks once again.
 
Status
Not open for further replies.
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top