123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309 |
- <?php
- use app\models\Authors;
- $this->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 "<pre>";
- // 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 => 'Январь' , 'Февраль' , 'Март' , 'Апрель' , 'Май' , 'Июнь' , 'Июль' , 'Август' , 'Сентябрь' , 'Октябрь' , 'Ноябрь' , 'Декабрь' );
- ?>
- <section class="content">
- <div class="container-fluid">
- <div class="callout callout-info">
- <h5><i class="fas fa-info"></i> Note:</h5>
- <h6>Даты расчёта <strong class="page-month"><?=$months[$m*1]?></strong> с <?="$b_date по $e_date"?></h6>
- </div>
- <ul class="pagination pagination-month justify-content-center">
- <li class="page-item">
- <a class="page-link" href="?m=-1">
- <p class="page-month">Декабрь</p>
- <p class="page-year"><?=$y-1?></p>
- </a>
- </li>
- <?
- foreach( $months as $key => $m1 ){
- ?>
- <li class="page-item<?=($key==$m)?' active':''?>">
- <a class="page-link" href="?m=<?=$key?>">
- <p class="page-month"><?=$m1?></p>
- <p class="page-year"><?=$y?></p>
- </a>
- </li>
- <?}?>
- </ul>
- </div>
- <div class="row">
- <div class="col-md-3">
- <div class="card direct-chat direct-chat-warning">
- <div class="card-header">
- <h3 class="card-title">Авторы</h3>
- <div class="card-tools">
- <span title="<?=$cntall?> New Messages" class="badge badge-warning"><?=$cntall?></span>
- <button type="button" class="btn btn-tool" data-card-widget="collapse">
- <i class="fas fa-minus"></i>
- </button>
- <button type="button" class="btn btn-tool" data-card-widget="remove">
- <i class="fas fa-times"></i>
- </button>
- </div>
- </div>
- <div class="card-body">
- <table class="table m-0">
- <thead>
- <tr>
- <th>Автор</th>
- <th>Материалов</th>
- </tr>
- </thead>
- <tbody>
- <?
- foreach( $a as $author => $c ){
- ?>
- <tr>
- <td><a href="?m=<?=$m*1?>&author=<?=$author?>"><?=$author?></a></td><td><?=$c?></td>
- </tr>
- <?}?>
- <tbody>
- </table>
- <div class="card-footer">
- По данным редакторов
- </div>
- </div>
- </div>
- </div>
- <?
- $sum = 0;
- foreach( $authord as $item ){
- $sum += $item['c'];
- }
- ?>
- <div class="col-md-3">
- <div class="card direct-chat direct-chat-warning">
- <div class="card-header">
- <h3 class="card-title">Автор: <b class="nowrap"><?=$authorname?></b></h3>
- <div class="card-tools">
- <a href="/manager/stats/csv?m=<?=$m*1?>&author=<?=$authorname?>" class="btn btn-tool btn-sm" download>
- <i class="fas fa-download"></i>
- </a>
- <span title="<?=$sum?> New Messages" class="badge badge-warning"><?=$sum?></span>
- <button type="button" class="btn btn-tool" data-card-widget="collapse">
- <i class="fas fa-minus"></i>
- </button>
- <button type="button" class="btn btn-tool" data-card-widget="remove">
- <i class="fas fa-times"></i>
- </button>
- </div>
- </div>
- <div class="card-body">
- <table class="table m-0">
- <thead>
- <tr>
- <th>День</th>
- <th>Материалов</th>
- </tr>
- </thead>
- <tbody>
- <?
- foreach( $authord as $author ){
- ?>
- <tr>
- <td><a href="?m=<?=$m*1?>&author=<?=$authorname?>&date=<?=$author['e']?>-<?=$m*1?>-<?=date("Y")?>"><?=$author['e']?>-<?=$months[$m*1]?>-<?=date("Y")?></a></td><td><?=$author['c']?></td>
- </tr>
- <?}?>
- <tbody>
- </table>
- <div class="card-footer">
- По данным редактирования
- </div>
- </div>
- </div>
- </div>
- <div class="col-md-6">
- <div class="card direct-chat direct-chat-warning">
- <div class="card-header">
- <h3 class="card-title">Автор: <b><?=$authorname?></b></h3>
- <div class="card-tools">
- <span title="<?=count($authornews)?> New Messages" class="badge badge-warning"><?=count($authornews)?></span>
- <button type="button" class="btn btn-tool" data-card-widget="collapse">
- <i class="fas fa-minus"></i>
- </button>
- <button type="button" class="btn btn-tool" data-card-widget="remove">
- <i class="fas fa-times"></i>
- </button>
- </div>
- </div>
- <div class="card-body">
- <table class="table m-0">
- <thead>
- <tr>
- <th>Дата</th>
- <th>Материал</th>
- </tr>
- </thead>
- <tbody>
- <?
- foreach( $authornews as $author ){
- ?>
- <tr>
- <td><?=date("d-m-Y h:i", strtotime($author['dt_pub']))?></td><td class="direct-chat-msg"><img class="direct-chat-img" src="/images/news/news/<?=$author['id']?>.jpg"><a href="/news/<?=$author['id']?>" target="_blank"><div class="direct-chat-text"><?=$author['title']?></a></a></td>
- </tr>
- <?}?>
- <tbody>
- </table>
- <div class="card-footer">
- По данным редактирования
- </div>
- </div>
- </div>
- </div>
- </div>
- </section>
|