filters.php 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. use yii\web\View;
  3. use \app\models\base\Tags;
  4. use \app\models\Tagsfilter;
  5. if( YII_ENV_DEV || 1 )
  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="fill: #ff8813;" onclick="toggletFiltersModalSel();return false;" class="button button_grey">
  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. &nbsp;Ваша лента
  20. </span>
  21. </div>
  22. <?php $this->beginBlock('FilterModal'); ?>
  23. <div id="tfilters-modal" class="mymodal hidden shadow p-3 mb-5 bg-white rounded modal-sm">
  24. <div class="modal-header">
  25. <h5 class="modal-title">Показать в ленте:</h5>
  26. <button type="button" class="close" data-dismiss="modal" aria-label="Close" onclick="$('#tfilters-modal').addClass('hidden');">
  27. <span aria-hidden="true">&times;</span>
  28. </button>
  29. </div>
  30. <div class="form-group w-100 ml-4">
  31. <?
  32. foreach( $items as $item ){
  33. ?>
  34. <div class="form-check checkbox-lg">
  35. <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':''?>>
  36. <label class="form-check-label" for="flexCheck<?=$item->id?>"><?=$item->title?></label><br>
  37. </div>
  38. <?}?>
  39. </div>
  40. <span class="btn btn-gray" onclick="SendTfilter();">Применить фильтр</span>
  41. </div>
  42. <?php $this->endBlock(); ?>
  43. <?php
  44. $filterurl = \yii\helpers\Url::base('https')."/setfilters";
  45. $this->registerJs(
  46. <<<JS
  47. function toggletFiltersModalSel(){
  48. $("#tfilters-modal").toggleClass("hidden");
  49. }
  50. function delete_cookie( name, path, domain ) {
  51. if( get_cookie( name ) ) {
  52. document.cookie = name + "=" +
  53. ((path) ? ";path="+path:"")+
  54. ((domain)?";domain="+domain:"") +
  55. ";expires=Thu, 01 Jan 1970 00:00:01 GMT";
  56. }
  57. }
  58. function get_cookie(name){
  59. return document.cookie.split(';').some(c => {
  60. return c.trim().startsWith(name + '=');
  61. });
  62. }
  63. function SendTfilter(){
  64. $("#tfilters-modal").toggleClass("hidden");
  65. var selectElement = document.querySelectorAll('.exttag');
  66. var a = [];
  67. selectElement.forEach((el) => {
  68. if( el.checked ) a.push(el.value);
  69. });
  70. if( a.length == 0 ) a.push(0);
  71. $.getJSON( "$filterurl", { 'filters': a }, function( data ) {
  72. if( data.status == 'ok' ){
  73. delete_cookie('filterq','','/');
  74. document.location.reload();
  75. }
  76. });
  77. }
  78. JS
  79. ,
  80. View::POS_END,
  81. 'fmodal'
  82. );
  83. }