authorsd.php 9.1 KB

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