list.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. <?php
  2. use \app\models\News;
  3. use \app\models\base\Kd;
  4. use app\models\base\Image;
  5. global $dcount;
  6. $dcount = 7; //новотей в КД
  7. $a1 = [];
  8. $this->title='Главная "картина дня" без НЧ';
  9. $newsDataProvider = new \yii\data\ActiveDataProvider(
  10. [
  11. "query"=>$model->find()->orderBy(["order"=>SORT_ASC])->limit($dcount),
  12. "pagination" => false
  13. ]
  14. );
  15. $nh = new \yii\data\ActiveDataProvider(
  16. [
  17. "query"=>News::find()->andWhere(['active'=>'Y', 'NH'=>'Y'])->orderBy(["dt_pub"=>SORT_DESC])->andWhere(['between', 'dt_pub', date("Y-m-d H:i:00",time()-2678400*2 ) , date("Y-m-d H:i:00")])->limit(10),
  18. "pagination" => false
  19. ]
  20. );
  21. $kd = new \yii\data\ActiveDataProvider(
  22. [
  23. "query"=>News::find()->andWhere(['active'=>'Y', 'top'=>'Y', 'NH'=>'N'])->andWhere(['between', 'dt_pub', date("Y-m-d H:i:00",time()-2678400*2 ) , date("Y-m-d H:i:00")])->orderBy(["dt_pub"=>SORT_DESC])->limit(15),
  24. "pagination" => false
  25. ]
  26. );
  27. $auto_news = Yii::$app->cache->get('main_auto_news');
  28. ?>
  29. <div class="alert alert-<?=$auto_news?'success':'warning'?>" role="alert">
  30. Включён режим <?=$auto_news?'автоматической':'ручной'?> ленты</div>
  31. <a href="/manager/kd/togleauto" class="btn btn-<?=$auto_news?'success':'warning'?>">Переключить на <?=$auto_news?'ручной':'автоматический'?> режим</a><br><br>
  32. <div class="">
  33. <div class="row">
  34. <div class="table-responsive-sm custom-range-badge col-8">
  35. <ul class="" id="sort">
  36. <li class="ui-state-default ui-state-disabled center htitle">
  37. <span class="stitle lft">Блок на главной <i class="icon-share"></i></span>
  38. </li>
  39. <?
  40. foreach( $sort = $newsDataProvider->getModels() as $item ){
  41. $a1[$item->id] = $item->id;
  42. draw($item);
  43. }
  44. if($sort == false){
  45. ?>
  46. <li class="ui-state-default center">
  47. <span class="stitle lft">блок 0<i class="icon-share"></i></span>
  48. </li>
  49. <?
  50. }
  51. ?>
  52. <li class="ui-state-default ui-state-disabled center htitle">
  53. <span class="stitle lft">Новости часа в очереди <i class="icon-share"></i></span>
  54. </li>
  55. <?
  56. foreach( $sort1 = $nh->getModels() as $item ){
  57. if(!isset($a1[$item->id])){
  58. draw($item);
  59. $a1[$item->id] = $item->id;
  60. }
  61. }
  62. if($sort1 == false){
  63. ?>
  64. <li class="ui-state-default center">
  65. <span class="stitle lft">блок 0<i class="icon-share"></i></span>
  66. </li>
  67. <?
  68. }
  69. ?>
  70. <li class="ui-state-default ui-state-disabled center htitle">
  71. <span class="stitle lft">КД новости в очереди <i class="icon-share"></i></span>
  72. </li>
  73. <?
  74. foreach( $sort2 = $kd->getModels() as $item ){
  75. if(!isset($a1[$item->id])){
  76. draw($item);
  77. $a1[$item->id] = $item->id;
  78. }
  79. }
  80. if($sort2 == false){
  81. ?>
  82. <li class="ui-state-default center">
  83. <span class="stitle lft">блок 0<i class="icon-share"></i></span>
  84. </li>
  85. <?
  86. }
  87. ?>
  88. </ul>
  89. </div>
  90. <style>
  91. .center { text-align:center;}
  92. .lft { text-align:left;}
  93. .act { text-align:left;width:220px}
  94. .stitle{display: inline-block;width:100%;}
  95. .htitle{color:#000;font-weight:700;opacity:1;}
  96. #sort { list-style-type: none; margin: 0; padding: 0; zoom: 1; }
  97. #sort li { margin: 0 5px 5px 5px; padding: 3px; width: 100%; }
  98. .actives{ background-color:#79d9ff;}
  99. .asorty{ background-color:#79ffc2;}
  100. </style>
  101. <script>
  102. $(function() {
  103. $( "#sort" ).sortable({
  104. items: "li:not(.ui-state-disabled)",
  105. update: function( event, ui ) {
  106. var order = $(this).sortable('serialize');
  107. $.getJSON( "/manager/kd/sort", order, function( data ) {
  108. if( data.status != 'ok' ){
  109. // $( "#sort" ).sortable( "refresh" );
  110. alert("Не записано!!");
  111. }else{
  112. $('#main-view-container').load( "/manager/kd/preview" );
  113. $( "#sort" ).sortable( "toArray" ).forEach(function(item, i, arr) {
  114. console.log($('#d'+item));
  115. if( i < <?=$dcount?> ){
  116. $('#d'+item).removeClass( "asorty" ).addClass( "actives" );
  117. }else{
  118. if( i == <?=$dcount?> ){
  119. $('#d'+item).addClass( "asorty" );
  120. }
  121. $('#d'+item).removeClass( "actives" );
  122. }
  123. });
  124. }
  125. });
  126. }
  127. }).disableSelection();
  128. $('#main-view-container').load( "/manager/kd/preview" );
  129. });
  130. </script>
  131. <?php
  132. function draw($item){
  133. global $dcount;
  134. static $i = 0;
  135. $strbage = '';
  136. $news = News::findOne($item->id);
  137. if( $news ){
  138. $title = $news->title;
  139. }else{
  140. $strbage .= '<span class="badge badge-danger">Дохлый элемент</span><br>';
  141. }
  142. $mark = '';
  143. if( $news->active == 'N' ){
  144. $mark = ' class="table-dark"';
  145. $strbage .= '<span class="badge badge-dark">Спрятано</span><br>';
  146. }
  147. ?>
  148. <li class="ui-state-default lft" id="item_<?=$item->id?>">
  149. <div class="stitle lft <?=($i < $dcount)?'actives':'asorty'?>" id="ditem_<?=$item->id?>"><?=date( "m.d h:i", strtotime($news->dt_pub))?> <?=$title?><small><?=$mark?></small></div>
  150. </li>
  151. <?
  152. $i++;
  153. }
  154. ?>
  155. <div class="col-4" style="transform:scale(0.6);margin-left: -95px;margin-top: -200px;">
  156. <div class="" id="main-view-container" style="width:800px;">
  157. </div>
  158. </div>
  159. <?
  160. echo \yii\helpers\Html::endTag("div");
  161. echo \yii\helpers\Html::endTag("div");
  162. echo \yii\helpers\Html::endTag("div");