Projet

Général

Profil

Révision 7b2d1845

Ajouté par Assos Assos il y a presque 4 ans

Weekly update of contrib modules

Voir les différences:

drupal7/sites/all/modules/webform/includes/webform.report.inc
265 265
/**
266 266
 * Theme the results table displaying all the submissions for a particular node.
267 267
 *
268
 * @param $node
269
 *   The node whose results are being displayed.
270
 * @param $components
271
 *   An associative array of the components for this webform.
272
 * @param $submissions
273
 *   An array of all submissions for this webform.
274
 * @param $total_count
275
 *   The total number of submissions to this webform.
276
 * @param $pager_count
277
 *   The number of results to be shown per page.
268
 * @param array $variables
269
 *   An array with keys:
270
 *    - node: The node whose results are being displayed.
271
 *    - components: An associative array of the components for this webform.
272
 *    - submissions: An array of all submissions for this webform.
273
 *    - total_count: The total number of submissions to this webform.
274
 *    - pager_count: The number of results to be shown per page.
278 275
 *
279 276
 * @return string
280 277
 *   HTML string with result data.
281 278
 */
282
function theme_webform_results_table($variables) {
279
function theme_webform_results_table(array $variables) {
283 280
  drupal_add_library('webform', 'admin');
284 281

  
285 282
  $node = $variables['node'];
283
  $components = $variables['components'];
286 284
  $submissions = $variables['submissions'];
287 285
  $total_count = $variables['total_count'];
288 286
  $pager_count = $variables['pager_count'];
......
304 302
    $component_headers = array();
305 303

  
306 304
    // Generate a cell for each component.
307
    foreach ($node->webform['components'] as $component) {
305
    foreach ($components as $component) {
308 306
      $data = isset($submission->data[$component['cid']]) ? $submission->data[$component['cid']] : NULL;
309 307
      $submission_output = webform_component_invoke($component['type'], 'table', $component, $data);
310 308
      if ($submission_output !== NULL) {
......
738 736
  $element['#webform_download_info']['serial'] = $last_download ? $last_download['serial'] : NULL;
739 737
  $element['#webform_download_info']['requested'] = $last_download ? $last_download['requested'] : $node->created;
740 738
  $element['#webform_download_info']['total'] = webform_get_submission_count($node->nid, NULL, NULL);
741
  $element['#webform_download_info']['new'] = webform_download_sids_count($node->nid, array('range_type' => 'new'));
739
  $element['#webform_download_info']['new'] = webform_download_sids_count($node->nid, array('range_type' => 'new', 'completion_type' => 'finished'));
740
  if ($node->webform['allow_draft'] || $node->webform['auto_save']) {
741
    $element['#webform_download_info']['new_draft'] = webform_download_sids_count($node->nid, array('range_type' => 'new', 'completion_type' => 'draft'));
742
  }
742 743

  
743 744
  return $element;
744 745
}
......
760 761
  $format = webform_date_format('short');
761 762
  $requested_date = format_date($download_info['requested'], 'custom', $format);
762 763
  $element['range_type']['new']['#theme_wrappers'] = array('webform_inline_radio');
763
  $element['range_type']['new']['#title'] .= ' (' . t('@count new since @date', array('@count' => $download_info['new'], '@date' => $requested_date)) . ')';
764
  if (isset($download_info['new_draft'])) {
765
    $args = array(
766
      '@new_draft' => $download_info['new_draft'],
767
      '@new' => $download_info['new'],
768
      '@date' => $requested_date,
769
    );
770
    $element['range_type']['new']['#title'] .= ' (' . t('@new_draft new drafts, @new new finished since @date', $args) . ')';
771
    $total_count = $download_info['new_draft'] + $download_info['new'];
772
  }
773
  else {
774
    $args = array(
775
      '@count' => $download_info['new'],
776
      '@date' => $requested_date,
777
    );
778
    $element['range_type']['new']['#title'] .= ' (' . t('@count new since @date', $args) . ')';
779
    $total_count = $download_info['new'];
780
  }
764 781

  
765 782
  // Disable option if there are no new submissions.
766
  if ($download_info['new'] == 0) {
783
  if ($total_count == 0) {
767 784
    $element['range_type']['new']['#attributes']['disabled'] = 'disabled';
768 785
  }
769 786

  
......
1071 1088
/**
1072 1089
 * Returns rows of downloadable webform data.
1073 1090
 *
1074
 * @deprecated in webform:7.x-4.8 and is removed from webform:7.x-5.0. See
1075
 * webform_results_download_rows_process().
1076
 * @see https://www.drupal.org/project/webform/issues/2465291
1077
 *
1078 1091
 * @param $node
1079 1092
 *   The webform node on which to generate the analysis.
1080 1093
 * @param array $options
......
1089 1102
 *   An array of rows built according to the provided $serial_start and
1090 1103
 *   $pager_count variables. Note that the current page number is determined
1091 1104
 *   by the super-global $_GET['page'] variable.
1105
 *
1106
 * @deprecated in webform:7.x-4.8 and is removed from webform:7.x-5.0. See
1107
 * webform_results_download_rows_process().
1108
 * @see https://www.drupal.org/project/webform/issues/2465291
1092 1109
 */
1093 1110
function webform_results_download_rows($node, array $options, $serial_start = 0, &$last_sid = NULL) {
1094 1111
  // Get all the required submissions for the download.
......
1354 1371
 */
1355 1372
function webform_results_export_success($node, $export_info) {
1356 1373
  if (!in_array($export_info['options']['range']['range_type'], array('range', 'range_serial', 'range_date')) && !empty($export_info['last_sid'])) {
1357
    // Insert a new record or update an existing record.
1358
    db_merge('webform_last_download')
1359
      ->key(array(
1360
        'nid' => $node->nid,
1361
        'uid' => $GLOBALS['user']->uid,
1362
      ))
1363
      ->fields(array(
1364
        'sid' => $export_info['last_sid'],
1365
        'requested' => REQUEST_TIME,
1366
      ))
1367
      ->execute();
1374
    webform_update_webform_last_download($node, $GLOBALS['user']->uid, $export_info['last_sid'], REQUEST_TIME);
1368 1375
  }
1369 1376
}
1370 1377

  
1378
/**
1379
 * Insert or update a download record in table {webform_last_download}.
1380
 *
1381
 * @param object $node
1382
 *   The Webform node of the record to update.
1383
 * @param int $uid
1384
 *   The user ID of the record to update.
1385
 * @param int $sid
1386
 *   The last downloaded submission number.
1387
 * @param int $requested
1388
 *   Timestamp of last download request.
1389
 *
1390
 * @return int
1391
 *   MergeQuery::STATUS_INSERT or ::STATUS_UPDATE.
1392
 */
1393
function webform_update_webform_last_download(stdClass $node, $uid, $sid, $requested) {
1394
  return db_merge('webform_last_download')
1395
    ->key(array(
1396
      'nid' => $node->nid,
1397
      'uid' => $uid,
1398
    ))
1399
    ->fields(array(
1400
      'sid' => $sid,
1401
      'requested' => $requested,
1402
    ))
1403
    ->execute();
1404
}
1405

  
1371 1406
/**
1372 1407
 * Menu callback; Download an exported file.
1373 1408
 *
......
1831 1866
 */
1832 1867
function webform_analysis_components_form_submit($form, $form_state) {
1833 1868
  $node = $form['#node'];
1869
  // Get a fresh copy of the node so that we are only saving these changes.
1870
  // Otherwise, changes to the Webform on another tab will be overwritten.
1871
  $node = node_load($node->nid, NULL, TRUE);
1834 1872
  foreach ($form_state['values']['components'] as $cid => $enabled) {
1835 1873
    $node->webform['components'][$cid]['extra']['analysis'] = (bool) $enabled;
1836 1874
  }
......
1880 1918
/**
1881 1919
 * Given a set of range options, retrieve a set of SIDs for a webform node.
1882 1920
 *
1883
 * @deprecated in webform:7.x-4.8 and is removed from webform:7.x-5.0. Use
1884
 * webform_download_sids_query().
1885
 * @see https://www.drupal.org/project/webform/issues/2465291
1921
 * @param int $nid
1922
 *   The node id of the webform.
1923
 * @param array $range_options
1924
 *   Associate array of range options.
1925
 * @param int $uid
1926
 *   The user id of the user whose last download information should be used,
1927
 *   or the current user if NULL. This is unrelated to which user submitted
1928
 *   the submissions.
1929
 *
1930
 * @return array
1931
 *   An array of submission IDs.
1886 1932
 */
1887
function webform_download_sids($nid, $range_options, $uid = NULL) {
1933
function webform_download_sids($nid, array $range_options, $uid = NULL) {
1888 1934
  return webform_download_sids_query($nid, $range_options, $uid)
1889 1935
    ->fields('ws', array('sid'))
1890 1936
    ->execute()
......
1893 1939

  
1894 1940
/**
1895 1941
 * Retrieves a count the number of matching submissions.
1942
 *
1943
 * @return int
1944
 *   The number number of matching submissions.
1896 1945
 */
1897 1946
function webform_download_sids_count($nid, $range_options, $uid = NULL) {
1898
  return webform_download_sids_query($nid, $range_options, $uid)
1947
  return (int) webform_download_sids_query($nid, $range_options, $uid)
1899 1948
    ->countQuery()
1900 1949
    ->execute()
1901 1950
    ->fetchField();
......
1930 1979
      $query->orderBy('ws.sid', 'ASC');
1931 1980
      break;
1932 1981

  
1933
    case 'new':
1934
      // All Since Last Download.
1935
      $download_info = webform_download_last_download_info($nid, $uid);
1936
      $last_sid = $download_info ? $download_info['sid'] : 0;
1937
      $query
1938
        ->condition('ws.sid', $last_sid, '>')
1939
        ->orderBy('ws.sid', 'ASC');
1940
      break;
1941

  
1942 1982
    case 'latest':
1943 1983
      // Last x Submissions.
1944 1984
      $start_sid = webform_download_latest_start_sid($nid, $range_options['latest'], $range_options['completion_type']);
......
1963 2003
      $query->orderBy('ws.serial', 'ASC');
1964 2004
      break;
1965 2005

  
2006
    case 'new':
2007
      // All since last download. This is the same as 'range_date' except that
2008
      // the start date is the date of the last download.
2009
      $download_info = webform_download_last_download_info($nid, $uid);
2010
      $start_date = (int) $download_info ? $download_info['requested'] : 0;
2011
      $end_time = NULL;
2012
      // Fall through.
1966 2013
    case 'range_date':
1967
      $date_field = $range_options['completion_type'] == 'finished' ? 'ws.completed' : 'ws.submitted';
1968
      $format = webform_date_format('short');
1969
      $start_date = DateTime::createFromFormat($format, $range_options['start_date']);
1970
      $start_date->setTime(0, 0, 0);
1971
      $query->condition($date_field, $start_date->getTimestamp(), '>=');
1972
      $end_time = DateTime::createFromFormat($format, $range_options['end_date']);
1973
      if ($range_options['end_date'] != '' && ($end_time !== FALSE)) {
2014
      // If the submission is completed, use the completed date, otherwise, the
2015
      // submitted date.
2016
      $date_field = 'COALESCE(NULLIF(ws.completed, 0), ws.submitted)';
2017
      // This is required because SQLite uses dynamic typing.
2018
      if (db_driver() === 'sqlite') {
2019
        $date_field = 'CAST(' . $date_field . ' AS INTEGER)';
2020
      }
2021

  
2022
      if (!isset($start_date)) {
2023
        $format = webform_date_format('short');
2024
        $start_date = DateTime::createFromFormat($format, $range_options['start_date']);
2025
        $start_date->setTime(0, 0, 0);
2026
        $start_date = $start_date->getTimestamp();
2027

  
2028
        $end_time = DateTime::createFromFormat($format, $range_options['end_date']);
2029
      }
2030
      $query->where($date_field . ' >= :start_date', array(':start_date' => $start_date));
2031

  
2032
      if ($end_time) {
1974 2033
        // Check for the full day's submissions.
1975 2034
        $end_time->setTime(23, 59, 59);
1976
        $query->condition($date_field, $end_time->getTimestamp(), '<=');
2035
        $end_time = $end_time->getTimestamp();
2036
        $query->where($date_field . ' <= :end_time', array(':end_time' => $end_time));
1977 2037
      }
2038

  
1978 2039
      $query->orderBy($date_field, 'ASC');
1979 2040
      break;
1980 2041
  }

Formats disponibles : Unified diff