Hi,

I have been stuck with this issue for past several weeks.

The php field only returns Webforms sid instead of the value itself.

I tried $data->field_field as well but it returns empty. I guess for webform components it should be something else.
I have this:
$row->value_5: TimeIn
$row->value_6: TimeOut
in my available variables.

Please help.
Thanks

Comments

dev16.addweb’s picture

Please perform below steps to return value of webform components using view php:

1. Create webform content view.
2. Add 'Content:Nid' field in field section and check 'Exclude from display'.
3. Add 'Content: Webform submission' field in Relationship section.
4. Add ' Webform submissions: Sid' field in field section and check 'Exclude from display'.
5. Now add 'Globle:PHP' field and return follwing code in Value code.

 return $row->nid;
        return $row->nid;

6. And return follwing code in Output code.

        <?php
                include_once drupal_get_path('module','webform') . '/includes/webform.submissions.inc';
                $submission = webform_get_submission($row->nid, $row->sid);
                $data = $submission->data;
                $node = node_load($row->nid);
                $components = $node->webform['components'];
                $labels = array();
                foreach ($components as $key => $component) {
                  $labels[$key] = $component['form_key'];
                }
                $fields = array();
                foreach ($data as $key => $values) {
                  $fields[$labels[$key]] = $values[$key];
                }
                foreach ($fields as $key => $value) {
                  print $key .':'.$value;
                }
        ?>

Hope this helps you.

Thanks!

maryam.naji68@gmail.com’s picture

Hi Tejal,

Thank you for your complete response. Very very interesting way of thinking.
But when I do the steps I get this:

date:please_let_us_know_how_your_day_was_with_the_client:
date:please_let_us_know_how_your_day_was_with_the_client:
date:please_let_us_know_how_your_day_was_with_the_client:
date:please_let_us_know_how_your_day_was_with_the_client:was_a_prn_given_today:if_prn_was_given_today_when_was_it_given
date:please_let_us_know_how_your_day_was_with_the_client:was_a_prn_given_today:if_prn_was_given_today_when_was_it_given
date:please_let_us_know_how_your_day_was_with_the_client:was_a_prn_given_today:if_prn_was_given_today_when_was_it_given

Which are the field keys of all components of all webforms!
It doesn't return any value and I think we need another relationship to specify the very webform node we want the submissions from. But I don't know how?!

dev16.addweb’s picture

Oh yes! Apologies! One correction into the code for 6th point. Please find the updated code below:

6. And return following code in Output code.

        <?php
                include_once drupal_get_path('module','webform') . '/includes/webform.submissions.inc';
                $submission = webform_get_submission($row->nid, $row->sid);
                $data = $submission->data;
                $node = node_load($row->nid);
                $components = $node->webform['components'];
                $labels = array();
                foreach ($components as $key => $component) {
                  $labels[$key] = $component['form_key'];
                }
                $fields = array();
                foreach ($data as $key => $values) {
                  $fields[$labels[$key]] = $values[0];
                }
                foreach ($fields as $key => $value) {
                  print $key .':'.$value;
                }
        ?>

Hope this helps.

Thanks!

maryam.naji68@gmail.com’s picture

Worked Great, Thanks sooooo much!

You open so many new doors for me and my husband :D

I added a part to output the duration for me which is:

$time1= strtotime($fields["time_in"]);
$time2= strtotime($fields["time_out"]);
$duration=($time2-$time1)/3600;
print $duration;

Thanks

maryam.naji68@gmail.com’s picture

Status: Active » Fixed
dev16.addweb’s picture

My Pleasure! Good to hear this. Feel free to contact me in future for any Drupal related work. Always ready to help :)

Thanks
Tejal

maryam.naji68@gmail.com’s picture

Hi Tejal,
Now I need to get a percentage of each submission out of all.
So as you helped me I ended up with this code to calculate time duration for each submission:

 include_once drupal_get_path('module','webform') . '/includes/webform.submissions.inc';
                $submission = webform_get_submission($row->nid, $row->sid);
                $data = $submission->data;
                $node = node_load($row->nid);
                $components = $node->webform['components'];
                $labels = array();
                foreach ($components as $key => $component) {
                  $labels[$key] = $component['form_key'];
                }
                $fields = array();
                foreach ($data as $key => $values) {
                  $fields[$labels[$key]] = $values[0];
                }
                foreach ($fields as $key => $value) {
                                 }
 $time1= strtotime($fields["time_in"]);
$time2= strtotime($fields["time_out"]);

if ($time2 < $time1 ) {
	$time3= strtotime("+1 day", $time2);
	$duration=($time3 - $time1) / 3600;
          print     round($duration, 2);
     }

else {
	$duration= ($time2-$time1) / 3600;
	        print     round($duration, 2);
}

Now I need to calculate a percentage like this:
$percentage=$duration/$total * 100;
But I dont know how to calculate $total and where to put the foreach loop!
I tried so hard to find it out myself but it didn't work.

I so much appreciate your help, thanks

maryam.naji68@gmail.com’s picture

Credit provided to tejal.patel for providing my solution.

Many thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.