title="Статистика"; $this->params['breadcrumbs'][] = ['label' => 'Статистика', 'url' => ['index']]; $this->params['breadcrumbs'][] = $this->title; $y = date("Y")*1; if (Yii::$app->request->isGet){ if($m = Yii::$app->request->get('m')){ if( $m == -1 ){ $b_date = date(($y-1)."-12-01 00:00:00"); $e_date = date(($y-1)."-12-31 23:59:59"); $m = 12; }else{ $d = cal_days_in_month(CAL_GREGORIAN, $m, $y); $m = $m<10?"0$m":$m; $d = $d<10?"0$d":$d; $b_date = date("Y-".$m."-01 00:00:00"); $e_date = date("Y-".$m."-".$d." 23:59:59"); } }else{ $b_date = date("Y-m-01 00:00:00"); $e_date = date("Y-m-d H:i:s"); $m = date("m"); } $authorname = Yii::$app->request->get('author'); $date = Yii::$app->request->get('date'); }else{ $b_date = date("Y-m-01 00:00:00"); $e_date = date("Y-m-d H:i:s"); $m = date("m"); } $AuthorsA = Authors::find()->all(); $aut = []; foreach( $AuthorsA as $author ){ $aut[str_replace( ['ё','Ё'], 'е',$author->name)] = ['name'=>str_replace( ['ё','Ё'], 'е',$author->name),'id'=>$author->id]; } // var_dump($aut); // echo "
";
//	var_dump($AuthorsA);
//exit;
	/*
$newsDataProvidera = new \yii\data\ActiveDataProvider(
    [
        "query"=>\app\models\base\News::find()->select(["SUBSTRING_INDEX(`editors`,',',1) as e"])->andwhere(['between', 'dt_pub',  $b_date , $e_date])->andwhere(['active'=>'Y'])->groupBy(["e"]),
            "pagination" =>false
    ]
);
$cnt = $newsDataProvidera->getCount();

$newsDataProviderau = new \yii\data\ActiveDataProvider(
    [
        "query"=>\app\models\base\News::find()->select('count(author)')->andwhere(['between', 'dt_pub',  $b_date , $e_date])->andwhere(['active'=>'Y'])->andwhere(['<>', 'author', '5']),
            "pagination" =>false
    ]
);
$cnt2 = $newsDataProviderau->getCount();

$newsDataProvideras = new \yii\data\ActiveDataProvider(
    [
        "query"=>\app\models\base\News::find()->select('count(*)')->andwhere(['between', 'dt_pub',  $b_date , $e_date])->andwhere(['<>', 'author', '5'])->andwhere(['active'=>'Y'])->andWhere(['show_author'=>'Y']),
            "pagination" =>false
    ]
);
$cnt3 = $newsDataProvideras->getCount();
*/

$authors = Yii::$app->db->createCommand("select e, count(e) as c from (SELECT SUBSTRING_INDEX(`editors`,',',1) as e FROM `news` WHERE `dt_pub` BETWEEN '".$b_date."' AND '".$e_date."' and active = 'Y') t where 1 group by e")->queryAll();

$newsDataProviderau = new \yii\data\ActiveDataProvider(
    [
        "query"=>\app\models\base\News::find()->andwhere(['between', 'dt_pub',  $b_date , $e_date])->andwhere(['active'=>'Y']),
            "pagination" =>false
    ]
);
$cntall = $newsDataProviderau->getCount();
/*
$sql = "select e, count(e) as c, name from (SELECT SUBSTRING_INDEX(`editors`,',',1) as e, `authors`.name as name FROM `news` LEFT JOIN `authors` ON( news.author = authors.id and authors.id <> 5 ) WHERE `dt_pub` BETWEEN '".$b_date."' AND '".$e_date."' and `news`.active = 'Y' ) t where 1 group by e, `name`";
$authorsfix = Yii::$app->db->createCommand( $sql )->queryAll();
echo $sql;
*/
$authord = [];
if( $authorname ){
	$sql = "select count(*) as c, DATE_FORMAT(dt_pub, '%d') e from `news` WHERE `dt_pub` BETWEEN '".$b_date."' AND '".$e_date."' and `news`.active = 'Y' and editors like '$authorname%'  group by e";
	$authord = Yii::$app->db->createCommand( $sql )->queryAll();
}

$authornews = [];
if( $date ){
	$bb_date = date("Y-m-d 00:00:00", strtotime($date));
	$eb_date = date("Y-m-d 23:59:59",strtotime($date));
	$sql = "select * from `news` WHERE `dt_pub` BETWEEN '".$bb_date."' AND '".$eb_date."' and `news`.active = 'Y' and editors like '$authorname%'  order by dt_pub";
	$authornews = Yii::$app->db->createCommand( $sql )->queryAll();
}


$a = array();
foreach( $authors as $author ){
	$a[str_replace( ['ё','Ё'], 'е', $author['e'])] = $author['c'];
}
//print_r($a);
/*
foreach( $authorsfix as $author ){
	if( $author['name'] ){

		$name = str_replace( ['ё','Ё'], 'е', $author['name'] );
		$authorn = str_replace( ['ё','Ё'], 'е', $author['e'] );
		if( $name != $authorn ){
			if( !isset( $a[$name] ) ) $a[$name] = 0;
			$a[$name] += $author['c'];
			$a[$authorn] -= $author['c'];
		}
	}
}
*/
$sum = 0;
$max = 0;
foreach( $a as $key => $item ){
	$sum += $item;
	if( $item == 0 ){
		unset($a[$key]);
	}
	$max = ( $item > $max )?$item:$max;
}
/*
$aj = [];
foreach( $AuthorsA as $author ){
	$searchedValue = $author->name;
	if( $author->active == 'Y' ){
	$ajs= array_filter(
		$a,
		function ($key, $e) use (&$searchedValue) {
			$name = str_replace( ['ё','Ё'], 'е', $searchedValue );
			return ( $name == $e );
		}, ARRAY_FILTER_USE_BOTH
	);
	if( count($ajs ) ) $aj += $ajs;
	}
}
//print_r();
$a = $aj;
*/
//$authors = $newsDataProvidera->query->createCommand()->queryAll();
$months = array( 1 => 'Январь' , 'Февраль' , 'Март' , 'Апрель' , 'Май' , 'Июнь' , 'Июль' , 'Август' , 'Сентябрь' , 'Октябрь' , 'Ноябрь' , 'Декабрь' );
?>
Note:
Даты расчёта с

Авторы

$c ){ ?>
Автор Материалов

Автор:

День Материалов
">--

Автор:

Дата Материал