authors.php 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. <?php
  2. $this->title="Статистика";
  3. $this->params['breadcrumbs'][] = ['label' => 'Статистика', 'url' => ['index']];
  4. $this->params['breadcrumbs'][] = $this->title;
  5. $y = date("Y")*1;
  6. if (Yii::$app->request->isGet && $m = Yii::$app->request->get('m')){
  7. if( $m == -1 ){
  8. $b_date = date(($y-1)."-12-01 00:00:00");
  9. $e_date = date(($y-1)."-12-31 23:59:59");
  10. $m = 12;
  11. }else{
  12. $d = cal_days_in_month(CAL_GREGORIAN, $m, $y);
  13. $m = $m<10?"0$m":$m;
  14. $d = $d<10?"0$d":$d;
  15. $b_date = date("Y-".$m."-01 00:00:00");
  16. $e_date = date("Y-".$m."-".$d." 23:59:59");
  17. }
  18. }else{
  19. $b_date = date("Y-m-01 00:00:00");
  20. $e_date = date("Y-m-d H:i:s");
  21. $m = date("m");
  22. }
  23. $newsDataProvidera = new \yii\data\ActiveDataProvider(
  24. [
  25. "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"]),
  26. "pagination" =>false
  27. ]
  28. );
  29. $cnt = $newsDataProvidera->getCount();
  30. $newsDataProviderau = new \yii\data\ActiveDataProvider(
  31. [
  32. "query"=>\app\models\base\News::find()->select('count(author)')->andwhere(['between', 'dt_pub', $b_date , $e_date])->andwhere(['active'=>'Y'])->andwhere(['<>', 'author', '5']),
  33. "pagination" =>false
  34. ]
  35. );
  36. $cnt2 = $newsDataProviderau->getCount();
  37. $newsDataProvideras = new \yii\data\ActiveDataProvider(
  38. [
  39. "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']),
  40. "pagination" =>false
  41. ]
  42. );
  43. $cnt3 = $newsDataProvideras->getCount();
  44. $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();
  45. $newsDataProviderau = new \yii\data\ActiveDataProvider(
  46. [
  47. "query"=>\app\models\base\News::find()->andwhere(['between', 'dt_pub', $b_date , $e_date])->andwhere(['active'=>'Y']),
  48. "pagination" =>false
  49. ]
  50. );
  51. $cntall = $newsDataProviderau->getCount();
  52. $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`";
  53. $authorsfix = Yii::$app->db->createCommand( $sql )->queryAll();
  54. $a = array();
  55. foreach( $authors as $author ){
  56. $a[str_replace( ['ё','Ё'], 'е', $author['e'])] = $author['c'];
  57. }
  58. //print_r($a);
  59. foreach( $authorsfix as $author ){
  60. if( $author['name'] ){
  61. $name = str_replace( ['ё','Ё'], 'е', $author['name'] );
  62. $authorn = str_replace( ['ё','Ё'], 'е', $author['e'] );
  63. if( $name != $authorn ){
  64. if( !isset( $a[$name] ) ) $a[$name] = 0;
  65. $a[$name] += $author['c'];
  66. $a[$authorn] -= $author['c'];
  67. }
  68. }
  69. }
  70. $sum = 0;
  71. $max = 0;
  72. foreach( $a as $key => $item ){
  73. $sum += $item;
  74. if( $item == 0 ){
  75. unset($a[$key]);
  76. }
  77. $max = ( $item > $max )?$item:$max;
  78. }
  79. //$authors = $newsDataProvidera->query->createCommand()->queryAll();
  80. $months = array( 1 => 'Январь' , 'Февраль' , 'Март' , 'Апрель' , 'Май' , 'Июнь' , 'Июль' , 'Август' , 'Сентябрь' , 'Октябрь' , 'Ноябрь' , 'Декабрь' );
  81. ?>
  82. <section class="content">
  83. <div class="container-fluid">
  84. <div class="callout callout-info">
  85. <h5><i class="fas fa-info"></i> Note:</h5>
  86. <h6>Даты расчёта <strong class="page-month"><?=$months[$m*1]?></strong> с <?="$b_date по $e_date"?></h6>
  87. </div>
  88. <ul class="pagination pagination-month justify-content-center">
  89. <li class="page-item">
  90. <a class="page-link" href="?m=-1">
  91. <p class="page-month">Декабрь</p>
  92. <p class="page-year"><?=$y-1?></p>
  93. </a>
  94. </li>
  95. <?
  96. foreach( $months as $key => $m ){
  97. ?>
  98. <li class="page-item<?=($key==date("m"))?' active':''?>">
  99. <a class="page-link" href="?m=<?=$key?>">
  100. <p class="page-month"><?=$m?></p>
  101. <p class="page-year"><?=$y?></p>
  102. </a>
  103. </li>
  104. <?}?>
  105. </ul>
  106. <div class="row">
  107. <div class="info-box col-3 m-3">
  108. <span class="info-box-icon bg-info"><i class="far fa-copy"></i></span>
  109. <div class="info-box-content">
  110. <span class="info-box-text">Всего материалов</span>
  111. <span class="info-box-number"><?=$cntall?></span>
  112. </div>
  113. </div>
  114. <div class="info-box col-3 m-3">
  115. <span class="info-box-icon bg-success"><i class="far fa-flag"></i></span>
  116. <div class="info-box-content">
  117. <span class="info-box-text">Авторов на ленте</span>
  118. <span class="info-box-number"><?=$cnt?></span>
  119. <span class="info-box-number">
  120. <?=$cnt2?> Указаны авторы
  121. </span>
  122. </div>
  123. </div>
  124. <div class="info-box col-3 m-3">
  125. <span class="info-box-icon bg-danger"><i class="far fa-star"></i></span>
  126. <div class="info-box-content">
  127. <span class="info-box-text">Подписаных материалов</span>
  128. <span class="info-box-number"><?=$cnt3?></span>
  129. </div>
  130. </div>
  131. </div>
  132. </div>
  133. <div class="row">
  134. <div class="col-md-6">
  135. <div class="card direct-chat direct-chat-warning">
  136. <div class="card-header">
  137. <h3 class="card-title">Авторы по материалам</h3>
  138. <div class="card-tools">
  139. <span title="<?=$cntall?> New Messages" class="badge badge-warning"><?=$cntall?></span>
  140. <button type="button" class="btn btn-tool" data-card-widget="collapse">
  141. <i class="fas fa-minus"></i>
  142. </button>
  143. <button type="button" class="btn btn-tool" data-card-widget="remove">
  144. <i class="fas fa-times"></i>
  145. </button>
  146. </div>
  147. </div>
  148. <div class="card-body">
  149. <table class="table m-0">
  150. <thead>
  151. <tr>
  152. <th>Автор</th>
  153. <th>Материалов</th>
  154. </tr>
  155. </thead>
  156. <tbody>
  157. <?
  158. foreach( $authors as $author ){
  159. ?>
  160. <tr>
  161. <td><?=$author['e']?></td><td><?=$author['c']?></td>
  162. </tr>
  163. <?}?>
  164. <tbody>
  165. </table>
  166. <div class="card-footer">
  167. По данным редакторов
  168. </div>
  169. </div>
  170. </div>
  171. </div>
  172. <div class="col-md-6">
  173. <div class="card direct-chat direct-chat-warning">
  174. <div class="card-header">
  175. <h3 class="card-title">Авторы по материалам диаграмма</h3>
  176. <div class="card-tools">
  177. <button type="button" class="btn btn-tool" data-card-widget="collapse">
  178. <i class="fas fa-minus"></i>
  179. </button>
  180. <button type="button" class="btn btn-tool" data-card-widget="remove">
  181. <i class="fas fa-times"></i>
  182. </button>
  183. </div>
  184. </div>
  185. <div class="card-body mx-2">
  186. <?
  187. foreach( $authors as $author ){
  188. ?>
  189. <div class="progress-group">
  190. <?=$author['e']?>
  191. <span class="float-right"><b><?=$author['c']?></b>/<?=$cntall?></span>
  192. <div class="progress progress-sm">
  193. <div class="progress-bar bg-danger" style="width: <?=round($author['c']*100/$max)?>%"></div>
  194. </div>
  195. </div>
  196. <?}?>
  197. <div class="card-footer">
  198. По данным редакторов
  199. </div>
  200. </div>
  201. </div>
  202. </div>
  203. </div>
  204. <div class="row">
  205. <div class="col-md-6">
  206. <div class="card direct-chat direct-chat-warning">
  207. <div class="card-header">
  208. <h3 class="card-title">Авторы по материалам (пересчёт)</h3>
  209. <div class="card-tools">
  210. <span title="<?=$sum?> New Messages" class="badge badge-warning"><?=$sum?></span>
  211. <button type="button" class="btn btn-tool" data-card-widget="collapse">
  212. <i class="fas fa-minus"></i>
  213. </button>
  214. <button type="button" class="btn btn-tool" data-card-widget="remove">
  215. <i class="fas fa-times"></i>
  216. </button>
  217. </div>
  218. </div>
  219. <div class="card-body">
  220. <table class="table m-0">
  221. <thead>
  222. <tr>
  223. <th>Автор</th>
  224. <th>Материалов</th>
  225. </tr>
  226. </thead>
  227. <tbody>
  228. <?
  229. foreach( $a as $author => $c){
  230. ?>
  231. <tr>
  232. <td><?=$author?></td><td><?=$c?></td>
  233. </tr>
  234. <?}?>
  235. <tbody>
  236. </table>
  237. <div class="card-footer">
  238. Уточнённый данные по указанным авторам
  239. </div>
  240. </div>
  241. </div>
  242. </div>
  243. <div class="col-md-6">
  244. <div class="card direct-chat direct-chat-warning">
  245. <div class="card-header">
  246. <h3 class="card-title">Авторы по материалам диаграмма</h3>
  247. <div class="card-tools">
  248. <button type="button" class="btn btn-tool" data-card-widget="collapse">
  249. <i class="fas fa-minus"></i>
  250. </button>
  251. <button type="button" class="btn btn-tool" data-card-widget="remove">
  252. <i class="fas fa-times"></i>
  253. </button>
  254. </div>
  255. </div>
  256. <div class="card-body mx-2">
  257. <?
  258. foreach( $a as $author => $c ){
  259. ?>
  260. <div class="progress-group">
  261. <?=$author?>
  262. <span class="float-right"><b><?=$c?></b>/<?=$sum?></span>
  263. <div class="progress progress-sm">
  264. <div class="progress-bar bg-danger" style="width: <?=round($c*100/$max)?>%"></div>
  265. </div>
  266. </div>
  267. <?}?>
  268. <div class="card-footer">
  269. Уточнённый данные по указанным авторам
  270. </div>
  271. </div>
  272. </div>
  273. </div>
  274. </div>
  275. </section>