0

I have a text field on a node type, which the user fills out with a video duration in ISO format (no validation or anything). So, '4:33' or '04:33' would be likely values for this field.

The client now needs a View which shows all these videos' titles and durations, and adds up the durations. I've looked at solutions like Views Calc and have had no real success. I've also have bad luck formatting the duration as a datestamp and trying to manipulate it that way. I need a way to show something like this:

+----------+--------------+
|TITLE     | Duration     |
+----------+--------------+
|Swimming  | 4:33         |
|Diving    | 2:42         |
|Running   | 1:27         |
+----------+--------------+
|TOTAL     | 8:42         |
+----------+--------------+

2
  • What do you need the totals for? Will you be using them for filtering, ordering, or as an argument? Or is it just the case that when you display the times, you also want to display the total?
    – Andy
    Aug 1, 2012 at 12:13
  • Just display, at least for now.
    – beth
    Aug 1, 2012 at 14:26

2 Answers 2

1

Imho your two best bets would be to either create a custom formatter, or to use hook_field_attach_view_alter() to modify the display (this answer might help if you go down that road). I'd be happy to expand on either of those methods.

Is there any reason you're using a text field? I would've thought a dedicated duration field would've been the way to go. I've never used any myself, but Google suggests: HMS Field, Time Period. Have you had a look at them? They might already have a formatter that supports what you want (a longshot, perhaps!).

2
  • The text field is already there, so changing it would involve losing information from at least 200 records.
    – beth
    Aug 1, 2012 at 18:03
  • 1
    Didn't realise it would require migration. It's not necessarily worth it, but in these situations in the past I've found a quick custom action coupled with Views Bulk Operations can be a surprisingly easy way to migrate data from one field type to another. YMMV
    – Andy
    Aug 2, 2012 at 9:33
0

you have to create a custom view tpl in your theme . To add time using php may be this link will help

5
  • That's not the hard part. The $row variable contains only already-rendered HTML. So how do I get all the values of the fields to do the math on?
    – beth
    Aug 1, 2012 at 14:26
  • something like this $i = 0; foreach($rows as $row){ $i = $row[XXXXX] + $i; }
    – Serjas
    Aug 3, 2012 at 4:42
  • That would work great if $row didn't contain one huge string that is the whole view as HTML already rendered.
    – beth
    Aug 3, 2012 at 13:45
  • you can use strip_tags :) strip_tags($row)
    – Serjas
    Aug 4, 2012 at 8:55
  • But it doesn't just contain tags, the whole content of the View is in there, tags, text, and all. For more than one row of data.
    – beth
    Aug 4, 2012 at 11:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.