filters.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. use yii\web\View;
  3. use \app\models\base\Tags;
  4. use \app\models\Tagsfilter;
  5. if( YII_ENV_DEV )
  6. {
  7. $tmodel = new Tags();
  8. $session = Yii::$app->session;
  9. $x =$session->get('filterx');
  10. $items = Yii::$app->cache->getOrSet("tagsmenu",function () use($tmodel){
  11. return $tmodel->find()->rightJoin(['m'=>Tagsfilter::find()], 'm.id = tags.id')->orderBy('sort')->All();
  12. });
  13. ?>
  14. <div class="header-bottom__button">
  15. <span style="background-color: #eee;padding: 4px;cursor: pointer;border-radius: 7px;fill: #ff8813;" onclick="toggletFiltersModal();return false;">
  16. <span class="button__icon"><i class="fa-solid fa-filter"></i>
  17. <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" style="width: 17px;height: 14px;" class="icon icon-tg"><title>фильтры материалов</title><path d="M3.9 54.9C10.5 40.9 24.5 32 40 32H472c15.5 0 29.5 8.9 36.1 22.9s4.6 30.5-5.2 42.5L320 320.9V448c0 12.1-6.8 23.2-17.7 28.6s-23.8 4.3-33.5-3l-64-48c-8.1-6-12.8-15.5-12.8-25.6V320.9L9 97.3C-.7 85.4-2.8 68.8 3.9 54.9z"/></svg>
  18. </span>
  19. </span>
  20. </div>
  21. <div id="tfilters-modal" class="mymodal hidden shadow p-3 mb-5 bg-white rounded">
  22. <div class="modal-header">
  23. <h5 class="modal-title">Читать только</h5>
  24. <button type="button" class="close" data-dismiss="modal" aria-label="Close" onclick="$('#tfilters-modal').addClass('hidden');">
  25. <span aria-hidden="true">&times;</span>
  26. </button>
  27. </div>
  28. <div class="form-group w-100 ml-4">
  29. <?
  30. foreach( $items as $item ){
  31. ?>
  32. <div class="form-check checkbox-lg">
  33. <input class="form-check-input exttag" type="checkbox" value="<?=$item->id?>" id="flexCheck<?=$item->id?>" name="ExtTag[<?=$item->id?>]"<?=($x && in_array($item->id,$x))?' checked':''?>>
  34. <label class="form-check-label" for="flexCheck<?=$item->id?>"><?=$item->title?></label><br>
  35. </div>
  36. <?}?>
  37. </div>
  38. <span class="btn btn-gray" onclick="SendTfilter();">Применить фильтр</span>
  39. </div>
  40. <?php
  41. $filterurl = \yii\helpers\Url::base('https')."/setfilters";
  42. $this->registerJs(
  43. <<<JS
  44. function toggletFiltersModal(){
  45. $("#tfilters-modal").toggleClass("hidden");
  46. }
  47. function SendTfilter(){
  48. $("#tfilters-modal").toggleClass("hidden");
  49. var selectElement = document.querySelectorAll('.exttag');
  50. var a = [];
  51. selectElement.forEach((el) => {
  52. if( el.checked ) a.push(el.value);
  53. });
  54. if( a.length == 0 ) a.push(0);
  55. $.getJSON( "$filterurl", { 'filters': a }, function( data ) {
  56. if( data.status == 'ok' ){
  57. document.location.reload();
  58. }
  59. });
  60. }
  61. JS
  62. ,
  63. View::POS_END,
  64. 'fmodal'
  65. );
  66. }