original_string: public static function getSelectsFromRangedColumn($column, $ranges, $table, $selectColumnPrefix, $restrictToReturningVisitors = false)
      {
          $selects = array();
          $extraCondition = '';
  
          if ($restrictToReturningVisitors) {
              // extra condition for the SQL SELECT that makes sure only returning visits are counted
              // when creating the 'days since last visit' report
              $extraCondition = 'and log_visit.visitor_returning = 1';
              $extraSelect    = "sum(case when log_visit.visitor_returning = 0 then 1 else 0 end) "
                              . " as `" . $selectColumnPrefix . 'General_NewVisits' . "`";
              $selects[] = $extraSelect;
          }
  
          foreach ($ranges as $gap) {
              if (count($gap) == 2) {
                  $lowerBound = $gap[0];
                  $upperBound = $gap[1];
  
                  $selectAs = "$selectColumnPrefix$lowerBound-$upperBound";
  
                  $selects[] = "sum(case when $table.$column between $lowerBound and $upperBound $extraCondition" .
                               " then 1 else 0 end) as `$selectAs`";
              } else {
                  $lowerBound = $gap[0];
  
                  $selectAs  = $selectColumnPrefix . ($lowerBound + 1) . urlencode('+');
                  $selects[] = "sum(case when $table.$column > $lowerBound $extraCondition then 1 else 0 end) as `$selectAs`";
              }
          }
  
          return $selects;
      }
code: public static function getSelectsFromRangedColumn($column, $ranges, $table, $selectColumnPrefix, $restrictToReturningVisitors = false)
      {
          $selects = array();
          $extraCondition = '';
  
          if ($restrictToReturningVisitors) {
              // extra condition for the SQL SELECT that makes sure only returning visits are counted
              // when creating the 'days since last visit' report
              $extraCondition = 'and log_visit.visitor_returning = 1';
              $extraSelect    = "sum(case when log_visit.visitor_returning = 0 then 1 else 0 end) "
                              . " as `" . $selectColumnPrefix . 'General_NewVisits' . "`";
              $selects[] = $extraSelect;
          }
  
          foreach ($ranges as $gap) {
              if (count($gap) == 2) {
                  $lowerBound = $gap[0];
                  $upperBound = $gap[1];
  
                  $selectAs = "$selectColumnPrefix$lowerBound-$upperBound";
  
                  $selects[] = "sum(case when $table.$column between $lowerBound and $upperBound $extraCondition" .
                               " then 1 else 0 end) as `$selectAs`";
              } else {
                  $lowerBound = $gap[0];
  
                  $selectAs  = $selectColumnPrefix . ($lowerBound + 1) . urlencode('+');
                  $selects[] = "sum(case when $table.$column > $lowerBound $extraCondition then 1 else 0 end) as `$selectAs`";
              }
          }
  
          return $selects;
      }
code_tokens: public static function getSelectsFromRangedColumn ( $ column , $ ranges , $ table , $ selectColumnPrefix , $ restrictToReturningVisitors = false ) { $ selects = array ( ) ; $ extraCondition = '' ; if ( $ restrictToReturningVisitors ) { // extra condition for the SQL SELECT that makes sure only returning visits are counted // when creating the 'days since last visit' report $ extraCondition = 'and log_visit.visitor_returning = 1' ; $ extraSelect = "sum(case when log_visit.visitor_returning = 0 then 1 else 0 end) " . " as `" . $ selectColumnPrefix . 'General_NewVisits' . "`" ; $ selects [ ] = $ extraSelect ; } foreach ( $ ranges as $ gap ) { if ( count ( $ gap ) == 2 ) { $ lowerBound = $ gap [ 0 ] ; $ upperBound = $ gap [ 1 ] ; $ selectAs = "$selectColumnPrefix$lowerBound-$upperBound" ; $ selects [ ] = "sum(case when $table.$column between $lowerBound and $upperBound $extraCondition" . " then 1 else 0 end) as `$selectAs`" ; } else { $ lowerBound = $ gap [ 0 ] ; $ selectAs = $ selectColumnPrefix . ( $ lowerBound + 1 ) . urlencode ( '+' ) ; $ selects [ ] = "sum(case when $table.$column > $lowerBound $extraCondition then 1 else 0 end) as `$selectAs`" ; } } return $ selects ; }
docstring: Creates and returns an array of SQL `SELECT` expressions that will each count how
  many rows have a column whose value is within a certain range.
  
  **Note:** The result of this function is meant for use in the `$additionalSelects` parameter
  in one of the query... methods (for example {@link queryVisitsByDimension()}).
  
  **Example**
  
  // summarize one column
  $visitTotalActionsRanges = array(
  array(1, 1),
  array(2, 10),
  array(10)
  );
  $selects = LogAggregator::getSelectsFromRangedColumn('visit_total_actions', $visitTotalActionsRanges, 'log_visit', 'vta');
  
  // summarize another column in the same request
  $visitCountVisitsRanges = array(
  array(1, 1),
  array(2, 20),
  array(20)
  );
  $selects = array_merge(
  $selects,
  LogAggregator::getSelectsFromRangedColumn('visitor_count_visits', $visitCountVisitsRanges, 'log_visit', 'vcv')
  );
  
  // perform the query
  $logAggregator = // get the LogAggregator somehow
  $query = $logAggregator->queryVisitsByDimension($dimensions = array(), $where = false, $selects);
  $tableSummary = $query->fetch();
  
  $numberOfVisitsWithOneAction = $tableSummary['vta0'];
  $numberOfVisitsBetweenTwoAnd10 = $tableSummary['vta1'];
  
  $numberOfVisitsWithVisitCountOfOne = $tableSummary['vcv0'];
  
  @param string $column The name of a column in `$table` that will be summarized.
  @param array $ranges The array of ranges over which the data in the table
  will be summarized. For example,
  ```
  array(
  array(1, 1),
  array(2, 2),
  array(3, 8),
  array(8) // everything over 8
  )
  ```
  @param string $table The unprefixed name of the table whose rows will be summarized.
  @param string $selectColumnPrefix The prefix to prepend to each SELECT expression. This
  prefix is used to differentiate different sets of
  range summarization SELECTs. You can supply different
  values to this argument to summarize several columns
  in one query (see above for an example).
  @param bool $restrictToReturningVisitors Whether to only summarize rows that belong to
  visits of returning visitors or not. If this
  argument is true, then the SELECT expressions
  returned can only be used with the
  {@link queryVisitsByDimension()} method.
  @return array An array of SQL SELECT expressions, for example,
  ```
  array(
  'sum(case when log_visit.visit_total_actions between 0 and 2 then 1 else 0 end) as vta0',
  'sum(case when log_visit.visit_total_actions > 2 then 1 else 0 end) as vta1'
  )
  ```
  @api
docstring_tokens: Creates and returns an array of SQL SELECT expressions that will each count how many rows have a column whose value is within a certain range .