b2evolution PHP Cross Reference Blogging Systems

Source: /inc/sessions/views/_goal_hitsummary.view.php - 189 lines - 4869 bytes - Summary - Text - Print

Description: This file implements the UI view for the Goal Hit list. b2evolution - {@link http://b2evolution.net/} Released under GNU GPL License - {@link http://b2evolution.net/about/license.html}

   1  <?php
   2  /**
   3   * This file implements the UI view for the Goal Hit list.
   4   *
   5   * b2evolution - {@link http://b2evolution.net/}
   6   * Released under GNU GPL License - {@link http://b2evolution.net/about/license.html}
   7   *
   8   * @copyright (c)2003-2014 by Francois Planque - {@link http://fplanque.com/}
   9   *
  10   * @package admin
  11   *
  12   * @version $Id: _goal_hitsummary.view.php 6136 2014-03-08 07:59:48Z manuel $
  13   */
  14  if( !defined('EVO_MAIN_INIT') ) die( 'Please, do not access this page directly.' );
  15  
  16  
  17  $final = param( 'final', 'integer', 0, true );
  18  $goal_name = param( 'goal_name', 'string', NULL, true );
  19  
  20  // Get all goal hits:
  21  $sql = 'SELECT DATE_FORMAT( hit_datetime, "%Y-%m-%d" ) as day, ghit_goal_ID, COUNT(ghit_ID) as count
  22                      FROM T_track__goalhit INNER JOIN T_hitlog ON ghit_hit_ID = hit_ID
  23                   GROUP BY day DESC, ghit_goal_ID';
  24  $hitgroup_rows = $DB->get_results( $sql, OBJECT, 'Get hits by day and goal' );
  25  
  26  $hitgroup_array = array();
  27  foreach( $hitgroup_rows as $hitgroup_row )
  28  {
  29      $hitgroup_array[$hitgroup_row->day][$hitgroup_row->ghit_goal_ID] = $hitgroup_row->count;
  30  }
  31  
  32  
  33  // Get list of all goals
  34  $SQL = new SQL();
  35  $SQL->SELECT( 'goal_ID, goal_name' );
  36  $SQL->FROM( 'T_track__goal' );
  37  if( !empty($final) )
  38  {    // We want to filter on final goals only:
  39      $SQL->WHERE_and( 'goal_redir_url IS NULL' );
  40  }
  41  if( !empty($goal_name) ) // TODO: allow combine
  42  { // We want to filter on the goal name:
  43      $SQL->WHERE_and( 'goal_name LIKE '.$DB->quote($goal_name.'%') );
  44  }
  45  $SQL->ORDER_BY( 'goal_name' );
  46  $goal_rows = $DB->get_results( $SQL->get(), OBJECT, 'Get list of all goals' );
  47  
  48  
  49  $Table = new Table( NULL, 'ghs_' );
  50  
  51  $Table->title = T_('Goal hit summary').get_manual_link( 'goal-stats' );
  52  
  53  $Table->cols = array(
  54      array( 'th' => T_('Date') )
  55  );
  56  foreach( $goal_rows as $goal_row )
  57  { // For each named goal, display name:
  58  $Table->cols[] = array(
  59          'th' => $goal_row->goal_name,
  60          'td_class' => 'right',
  61      );
  62  }
  63  $Table->cols[] = array(
  64          'th' => T_('Total'),
  65          'td_class' => 'right',
  66      );
  67  
  68  
  69  
  70  
  71  /**
  72   * Callback to add filters on top of the result set
  73   *
  74   * @param Form
  75   */
  76  function filter_goal_hitsummary( & $Form )
  77  {
  78      $Form->checkbox_basic_input( 'final', get_param('final'), T_('Final') );
  79      $Form->text_input( 'goal_name', get_param('goal_name'), 20, T_('Goal names starting with'), '', array( 'maxlength'=>50 ) );
  80  }
  81  $Table->filter_area = array(
  82      'callback' => 'filter_goal_hitsummary',
  83      'url_ignore' => 'final,goal_name',
  84      'presets' => array(
  85          'all' => array( T_('All'), '?ctrl=goals&amp;tab3=stats' ),
  86          'final' => array( T_('Final'), '?ctrl=goals&amp;tab3=stats&amp;final=1' ),
  87          )
  88      );
  89  
  90  
  91  echo '<div class="results">';;
  92  
  93  $Table->display_init();
  94  
  95  // TITLE / COLUMN HEADERS:
  96  $Table->display_head();
  97  
  98  // START OF LIST/TABLE:
  99  $Table->display_list_start();
 100  
 101  if( empty( $hitgroup_array ) )
 102  { // No records
 103      $Table->total_pages = 0;
 104  }
 105  else
 106  { // Display table
 107  
 108  // DISPLAY COLUMN HEADERS:
 109  $Table->display_col_headers();
 110  
 111  // BODY START:
 112  $Table->display_body_start();
 113  
 114  $goal_total = array();
 115  foreach( $hitgroup_array as $day => $hitday_array )
 116  {
 117      $Table->display_line_start();
 118  
 119      $Table->display_col_start();
 120      echo $day;
 121      $Table->display_col_end();
 122  
 123      $line_total = 0;
 124      foreach( $goal_rows as $goal_row )
 125      { // For each named goal, display count:
 126          if( ! isset( $goal_total[ $goal_row->goal_ID ] ) )
 127          {
 128              $goal_total[ $goal_row->goal_ID ] = 0;
 129          }
 130          $Table->display_col_start();
 131          if( isset( $hitday_array[$goal_row->goal_ID] ) )
 132          {
 133              echo '<a href="?blog=0&amp;ctrl=stats&amp;tab=goals&amp;tab3=hits&amp;goal_name='.rawurlencode($goal_row->goal_name).'">'.$hitday_array[$goal_row->goal_ID].'</a>';
 134              $line_total += $hitday_array[$goal_row->goal_ID];
 135              $goal_total[ $goal_row->goal_ID ] += $hitday_array[$goal_row->goal_ID];
 136          }
 137          else
 138          {
 139              echo '&nbsp;';
 140          }
 141          $Table->display_col_end();
 142      }
 143  
 144      $Table->display_col_start();
 145      echo $line_total;
 146      $Table->display_col_end();
 147  
 148      $Table->display_line_end();
 149  }
 150  
 151  // Totals row:
 152  echo $Table->params['total_line_start'];
 153  
 154  echo str_replace( '$class$', '', $Table->params['total_col_start_first'] );
 155  echo T_('Total');
 156  echo $Table->params['total_col_end'];
 157  
 158  $all_total = 0;
 159  foreach( $goal_rows as $goal_row )
 160  { // For each named goal, display total of count:
 161      echo str_replace( '$class_attrib$', 'class="right"', $Table->params['total_col_start'] );
 162      if( ! empty( $goal_total[ $goal_row->goal_ID ] ) )
 163      {
 164          echo '<a href="?blog=0&amp;ctrl=stats&amp;tab=goals&amp;tab3=hits&amp;goal_name='.rawurlencode( $goal_row->goal_name ).'">'.$goal_total[ $goal_row->goal_ID ].'</a>';
 165          $all_total += $goal_total[ $goal_row->goal_ID ];
 166      }
 167      else
 168      {
 169          echo '&nbsp;';
 170      }
 171      echo $Table->params['total_col_end'];
 172  }
 173  
 174  echo str_replace( '$class$', 'right', $Table->params['total_col_start_last'] );
 175  echo $all_total;
 176  echo $Table->params['total_col_end'];
 177  
 178  echo $this->params['total_line_end'];
 179  
 180  // BODY END:
 181  $Table->display_body_end();
 182  
 183  }
 184  
 185  $Table->display_list_end();
 186  
 187  echo '</div>';
 188  
 189  ?>

title

Description

title

Description

title

Description

title

title

Body