Gc\User\Visitor::getReferers PHP Method

getReferers() public method

Return all referers
public getReferers ( string $sort, integer $limit = 20 ) : array
$sort string Sort by HOUR, DAY, MONTH, YEAR
$limit integer Optional limit, default: 20
return array
    public function getReferers($sort, $limit = 20)
    {
        $sort = $this->checkSort($sort);
        $select = new Select();
        $select->from(array('lu' => 'log_url'))->columns(array('date' => new Expression(sprintf('EXTRACT(%s FROM MAX(lu.visit_at))', $sort))))->join(array('lui' => 'log_url_info'), 'lui.id = lu.log_url_info_id', array('url' => 'referer', 'nb' => new Expression('COUNT(lui.id)')))->where('lui.referer IS NOT null')->order('nb DESC')->group(array('lui.referer'));
        $this->groupByDate($sort, $select);
        $select->limit($limit);
        return $this->fetchAll($select);
    }

Usage Example

Example #1
0
 /**
  * Display statistics for visitors
  *
  * @return \Zend\View\Model\ViewModel
  */
 public function indexAction()
 {
     $visitorModel = new Visitor();
     $settings = array('back_colour' => '#FFFFFF', 'stroke_colour' => '#C2C2C2', 'back_stroke_width' => 0, 'back_stroke_colour' => '#C2C2C2', 'axis_colour' => '#333', 'axis_overlap' => 1, 'axis_font' => 'Verdana', 'axis_font_size' => 10, 'grid_colour' => '#888888', 'label_colour' => '#555555', 'pad_right' => 10, 'pad_left' => 10, 'project_angle' => 45, 'minimum_grid_spacing' => 40);
     $graph = new SVGGraph(600, 400, $settings);
     $graph->colours = array(array('#855D10', '#855D10'));
     $data = array();
     $array = array('hours' => 'HOUR', 'days' => 'DAY', 'months' => 'MONTH', 'years' => 'YEAR');
     foreach ($array as $type => $sqlValue) {
         $label = '';
         switch ($type) {
             case 'hours':
                 $label = 'This day';
                 break;
             case 'days':
                 $label = 'This month';
                 break;
             case 'months':
                 $label = 'This year';
                 break;
             case 'years':
                 $label = 'All the time';
                 break;
         }
         $data[$type] = array('label' => $label, 'labels' => array('visitors' => 'Visitors', 'pagesviews' => 'Pages views', 'urlsviews' => 'Most urls views', 'referers' => 'Referers'), 'values' => array('visitors' => $visitorModel->getNbVisitors($sqlValue), 'pagesviews' => $visitorModel->getNbPagesViews($sqlValue), 'urlsviews' => $visitorModel->getUrlsViews($sqlValue), 'referers' => $visitorModel->getReferers($sqlValue)));
     }
     return array('graph' => $graph, 'groups' => $data);
 }