add sort of datas by view in DateRangeAnalytic
This commit is contained in:
parent
0739f683c7
commit
5810e09a45
|
@ -7,11 +7,11 @@ use App\Core\Repository\Analytic\RefererRepositoryQuery;
|
|||
use App\Core\Repository\Analytic\ViewRepositoryQuery;
|
||||
|
||||
/**
|
||||
* class RangeAnalytic.
|
||||
* class DateRangeAnalytic.
|
||||
*
|
||||
* @author Simon Vieille <simon@deblan.fr>
|
||||
*/
|
||||
class RangeAnalytic
|
||||
class DateRangeAnalytic
|
||||
{
|
||||
protected ViewRepositoryQuery $viewQuery;
|
||||
protected RefererRepositoryQuery $refererQuery;
|
||||
|
@ -57,6 +57,8 @@ class RangeAnalytic
|
|||
$datas[$index] += $entity->getViews();
|
||||
}
|
||||
|
||||
arsort($datas, SORT_NUMERIC);
|
||||
|
||||
return $datas;
|
||||
}
|
||||
|
||||
|
@ -77,6 +79,8 @@ class RangeAnalytic
|
|||
$datas[$index] += $entity->getViews();
|
||||
}
|
||||
|
||||
arsort($datas, SORT_NUMERIC);
|
||||
|
||||
return $datas;
|
||||
}
|
||||
|
||||
|
@ -108,6 +112,18 @@ class RangeAnalytic
|
|||
$datas[$index]['uris'][$path] += $entity->getViews();
|
||||
}
|
||||
|
||||
uasort($datas, function($a, $b) {
|
||||
if ($a['views'] > $b['views']) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ($a['views'] < $b['views']) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
});
|
||||
|
||||
return $datas;
|
||||
}
|
||||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
namespace App\Core\Controller\Analytic;
|
||||
|
||||
use App\Core\Analytic\RangeAnalytic;
|
||||
use App\Core\Analytic\DateRangeAnalytic;
|
||||
use App\Core\Entity\Site\Node;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
@ -16,22 +16,22 @@ class AnalyticController extends AbstractController
|
|||
/**
|
||||
* @Route("/stats/{node}/{range}", name="admin_analytic_stats")
|
||||
*/
|
||||
public function stats(Node $node, RangeAnalytic $rangeAnalytic, string $range = '7days'): Response
|
||||
public function stats(Node $node, DateRangeAnalytic $analytic, string $range = '7days'): Response
|
||||
{
|
||||
if (!in_array($range, ['7days', '30days', '90days', '1year'])) {
|
||||
throw $this->createNotFoundException();
|
||||
}
|
||||
|
||||
$rangeAnalytic
|
||||
$analytic
|
||||
->setDateRange(new \DateTime('now - '.$range), new \DateTime())
|
||||
->setNode($node)
|
||||
;
|
||||
|
||||
return $this->render('@Core/analytic/stats.html.twig', [
|
||||
'range' => $range,
|
||||
'views' => $rangeAnalytic->getViews(),
|
||||
'pathViews' => $rangeAnalytic->getPathViews(),
|
||||
'referers' => $rangeAnalytic->getReferers(),
|
||||
'views' => $analytic->getViews(),
|
||||
'pathViews' => $analytic->getPathViews(),
|
||||
'referers' => $analytic->getReferers(),
|
||||
'node' => $node,
|
||||
]);
|
||||
}
|
||||
|
|
|
@ -99,6 +99,16 @@ class AnalyticListener
|
|||
return;
|
||||
}
|
||||
|
||||
$referer = $this->request->headers->get('referer');
|
||||
|
||||
if (!filter_var($referer, FILTER_VALIDATE_URL) || parse_url($url, PHP_URL_SCHEME)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!in_array(parse_url($url, PHP_URL_SCHEME), ['http', 'https'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
$entity = $this->refererRepositoryQuery->create()
|
||||
->filterByRequest($this->request)
|
||||
->andWhere('.date=CURRENT_DATE()')
|
||||
|
@ -106,7 +116,7 @@ class AnalyticListener
|
|||
;
|
||||
|
||||
if (!$entity) {
|
||||
$entity = $this->refererFactory->create($this->node, $this->request->headers->get('referer'));
|
||||
$entity = $this->refererFactory->create($this->node, $referer);
|
||||
}
|
||||
|
||||
$entity->addView();
|
||||
|
|
Loading…
Reference in a new issue