Advertisement
Ruslan_Rayanov

block_land_customlist_items_get

Dec 18th, 2024
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
T-SQL 3.29 KB | None | 0 0
  1. CREATE PROCEDURE [dbo].[block_land_customlist_items_get]
  2.     @code nvarchar(128),
  3.     @itemID nvarchar(256),
  4.     @parameters ExtendedDictionaryParameter readonly,  -- langID, username...
  5.     @res nvarchar(max) output
  6. AS
  7. BEGIN
  8.     declare @catalogPageCode nvarchar(max) = 'customlist'
  9.     declare @url nvarchar(max) = (select value2 from @parameters where [key]='itemID')
  10.  
  11.     declare @pageSize int = 10
  12.    
  13.     declare @filters table(name nvarchar(max), value nvarchar(max))
  14.     insert into @filters (name, value)
  15.     select dbo.str_splitpart(value, '=', 1) name, dbo.str_splitpart(value, '=', 2) value
  16.     from dbo.split(@url, '--') where len(value)>0
  17.    
  18.     --declare @fsValues nvarchar(max) = ''
  19.     -- select @fsValues = @fsValues +  Value + ' ' from @filters where len(value)>0
  20.     declare @s1  nvarchar(max)= isnull((select top 1  value from @filters where name = 's1'), '')
  21.     declare @s2 int= isnull((select top 1 try_cast( value as int) from @filters where name = 's2'), 0)
  22.     declare @s3  bit = isnull((select top 1  try_cast(value as bit) from @filters where name = 's3'), 0)
  23.     declare @page  int = isnull((select top 1  try_cast(value as int) from @filters where name = 'page'), 1)
  24.    
  25.     declare @ids table (id int primary key)
  26.     insert into @ids(id)
  27.     select id
  28.     from tst_categories
  29.     where ( @s1='' or name like '%'+@s1+'%')
  30.         and (@s2=0 or parentID = @s2)
  31.         and (@s3=0 or selected = 1)
  32.     declare @total int = (select count(*) from @ids)
  33.     declare @title nvarchar(max) = 'Каталог элементов (найдено '+cast(@total as nvarchar)+') '
  34.         + iif(@s1<>'', 'Поиск по '+ @s1, '' )
  35.         + iif(@s2>0, 'В категории  '+ isnull((select name from tst_categories where id = @s2), ''), '' )
  36.         + iif(@s3=1, '(только ключевые)', '' )
  37.    
  38.     declare @text nvarchar(max) = ''
  39.     select @text = @text + '
  40.    <div class="col-12 col-md-3">
  41.         <div class="as-panel">
  42.             <h3>'+isnull(name, '')+'</h3>
  43.             <div>'+isnull([code], '')+'</div>        
  44.        </div>
  45.    </div>'
  46.     from tst_categories
  47.     where id in (select id from @ids)
  48.     order by id
  49.     OFFSET @PageSize * (@Page - 1) ROWS
  50.     FETCH NEXT @PageSize ROWS ONLY;
  51.    
  52.     if(@total = 0) set @text = '<div class="col-12"><div class="mx-auto text-center alert alert-secondary w-50" >Ничего не найдено по запросу</div></div>'
  53.    
  54.     -- определяем пагинацию
  55.     declare @pg nvarchar(max) = ''
  56.     declare @i int = 1
  57.     declare @clearUrl nvarchar(max) = replace(@url, '--page='+ cast(@page as nvarchar), '')
  58.     while (@i <= round(@total / cast(@pageSize as float), 0)) begin
  59.         set @pg = @pg +
  60.             '<li class="page-item '+iif(@page=@i, 'active', '')+'"><a class="page-link"
  61.                 href="/'+@catalogPageCode+'/'+@clearUrl+iif(@i =1, '','--page='+cast(@i as nvarchar))+'">'+
  62.                     cast(@i as nvarchar)+'</a>
  63.             </li>'
  64.         set @i = @i + 1
  65.     end
  66.     declare @pagination nvarchar(max) = iif(@pg<>'',  '<nav><ul class="pagination">'+isnull(@pg,'')+'</ul></nav>', '')
  67.      
  68.     set @res = '
  69.    <div class="mb-5">
  70.         <h1 class="h3">'+isnull(@title, '')+'</h1>
  71.         <div class="row">
  72.             '+isnull(@text, '')+'
  73.         </div>
  74.        '+ isnull(@pagination, '')+ '
  75.    </div>'
  76. END
  77.  
  78.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement