add offers count, & minor fixes code standards
This commit is contained in:
@@ -2,6 +2,8 @@
|
||||
|
||||
namespace App\Repositories\Core;
|
||||
|
||||
use Carbon\Carbon;
|
||||
|
||||
class Stat
|
||||
{
|
||||
public static $is_debug = false;
|
||||
@@ -17,48 +19,38 @@ class Stat
|
||||
return $model->where('created_at', '<', $end)->count();
|
||||
}
|
||||
|
||||
/*
|
||||
fonctions de rendus
|
||||
*/
|
||||
|
||||
public static function renderStatsbyMultiVar($var, $var_option = '')
|
||||
{
|
||||
static::renderStatsJson(static::getStatsbyMultiVar($var, $var_option));
|
||||
self::renderStatsJson(self::getStatsbyMultiVar($var, $var_option));
|
||||
}
|
||||
|
||||
public static function renderStatsbyVar($var)
|
||||
{
|
||||
static::renderStatsJson(static::getStatsbyVar($var));
|
||||
self::renderStatsJson(self::getStatsbyVar($var));
|
||||
}
|
||||
|
||||
public static function renderStatsbyOptions($var, $var_option = '')
|
||||
{
|
||||
static::renderStatsJson(static::getStatsbyOptions($var, $var_option));
|
||||
self::renderStatsJson(self::getStatsbyOptions($var, $var_option));
|
||||
}
|
||||
|
||||
public static function renderStatsJson($data)
|
||||
{
|
||||
Response::headers()->set('Content-Type', 'application/json');
|
||||
Response::setBody(json_encode($data, JSON_NUMERIC_CHECK));
|
||||
return json_encode($data, JSON_NUMERIC_CHECK);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
Fonctions internes
|
||||
*/
|
||||
|
||||
public static function getStatsbyMultiVar($var, $var_option = '')
|
||||
{
|
||||
if (empty($var_option)) {
|
||||
$var_option = $var;
|
||||
}
|
||||
$options = self::getInstance()->controller->getOption($var_option);
|
||||
return self::getInstance()->getStatsbyMultiOptions($var, $options);
|
||||
$options = self::getOption($var_option);
|
||||
return self::getStatsbyMultiOptions($var, $options);
|
||||
}
|
||||
|
||||
public static function getCountByPeriod($var, $begin, $end)
|
||||
{
|
||||
$count = static::getModel()
|
||||
$count = self::getModel()
|
||||
->whereBetween($var, $begin, $end)
|
||||
->count();
|
||||
return $count;
|
||||
@@ -67,7 +59,7 @@ class Stat
|
||||
public static function getCountbyVar($var)
|
||||
{
|
||||
$db = self::getInstance()->app->db;
|
||||
$data = static::getModel()
|
||||
$data = self::getModel()
|
||||
->select($db::raw("count(id) as y, $var as name"))
|
||||
->groupBy($var)
|
||||
->get();
|
||||
@@ -82,7 +74,7 @@ class Stat
|
||||
$var_option = $var;
|
||||
}
|
||||
$options = self::getInstance()->controller->getOption($var_option);
|
||||
$nb = static::getCountbyOption($var);
|
||||
$nb = self::getCountbyOption($var);
|
||||
// var_Debug::message($nb);
|
||||
foreach ($options as $key => $value) {
|
||||
$y = (int) $nb[$key];
|
||||
@@ -95,7 +87,7 @@ class Stat
|
||||
public static function getCountbyOption($var)
|
||||
{
|
||||
$db = self::getInstance()->app->db;
|
||||
$data = static::getModel()
|
||||
$data = self::getModel()
|
||||
->select($db::raw('count(id) as nb'))
|
||||
->groupBy($var)
|
||||
->get();
|
||||
@@ -112,7 +104,7 @@ class Stat
|
||||
public static function getStatsbyMultiOptions($var, $options)
|
||||
{
|
||||
foreach ($options as $key => $value) {
|
||||
$nb = static::getCountbyBin($var, $key);
|
||||
$nb = self::getCountbyBin($var, $key);
|
||||
$data[] = ['y' => $nb, 'name' => $value];
|
||||
}
|
||||
return ($data);
|
||||
@@ -121,7 +113,7 @@ class Stat
|
||||
public static function getCountbyBin($var, $value)
|
||||
{
|
||||
$bit = pow(2, $value);
|
||||
$count = static::getModel()
|
||||
$count = self::getModel()
|
||||
->where($var, '&', $bit)
|
||||
->count();
|
||||
return $count;
|
||||
@@ -149,7 +141,7 @@ class Stat
|
||||
|
||||
public static function serializeValues($tab)
|
||||
{
|
||||
return static::serializeByVar($tab, 'count');
|
||||
return self::serializeByVar($tab, 'count');
|
||||
}
|
||||
|
||||
public static function serializeByVar($tab, $var, $n = 0)
|
||||
|
||||
Reference in New Issue
Block a user