avanrossum

Livestream Recipe SPROC

Mar 16th, 2020
123
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. USE [MinistryPlatform]
  2. GO
  3.  
  4. SET ANSI_NULLS ON
  5. GO
  6. SET QUOTED_IDENTIFIER ON
  7. GO
  8.  
  9. /*=================================
  10. == Displays Livestream link
  11. == based on time/day
  12. == Version 1.0
  13. == --------------------------------
  14. == alex@pocketplatform.io
  15. == --------------------------------
  16. =================================*/
  17.  
  18. IF NOT EXISTS (
  19.   SELECT *
  20.   FROM sys.objects
  21.   WHERE type = 'P'
  22.   AND OBJECT_ID = OBJECT_ID('dbo.api_PocketPlatform_GetLivestream_SunWed')
  23. )
  24. BEGIN
  25.    EXEC('CREATE PROC [dbo].[api_PocketPlatform_GetLivestream_SunWed] AS BEGIN SET NOCOUNT ON; END')
  26. END
  27. GO
  28.  
  29. ALTER PROCEDURE [dbo].[api_PocketPlatform_GetLivestream_SunWed]
  30.   @ID NVARCHAR(75)
  31.   ,@Title NVARCHAR(75)
  32.   ,@DomainID INT
  33.   ,@DayNumber INT
  34.   ,@Dayhour INT
  35.   ,@DayMin INT
  36.   ,@DayTime DATETIME
  37. AS
  38. BEGIN
  39.  
  40.   SET DATEFIRST 7;
  41.  
  42.  
  43.   -- #ATT Please build a new configuration entry for the Livestream URL.
  44.   -- #ATT The required key is POCKETPLATFORM > LiveStreamURL
  45.   DECLARE @LiveStreamURL nvarchar(MAX) = (SELECT Value FROM dp_Configuration_Settings WHERE Application_Code = 'POCKETPLATFORM' AND Key_Name='LiveStreamURL')
  46.  
  47.  
  48.  
  49.   /* -- == TEST DATA
  50.    */
  51.   -- SET @dayNumber = 4;
  52.   -- SET @dayTime = '11:50:01';
  53.  
  54.   DECLARE @Items TABLE (
  55.     ID NVARCHAR(50)
  56.     ,Parent_ID NVARCHAR(50)
  57.     ,[Type] NVARCHAR(50)
  58.     ,Data NTEXT
  59.     ,URL NVARCHAR(255)
  60.   );
  61.  
  62.  
  63.   IF ( @LiveStreamURL IS NOT NULL )
  64.   BEGIN
  65.     IF ( @dayNumber = 1 AND ( (@dayTime > '07:00:00' AND @dayTime < '13:30:00' ) ) )
  66.     BEGIN
  67.       INSERT INTO @Items (ID, Parent_ID, [Type], Data, URL) VALUES
  68.       (@ID, NULL, 'card', NULL, @LivestreamURL),
  69.       (@ID + 'arrow', @ID, 'arrow-action', NULL, NULL),
  70.       (@ID + 'heading', @ID + 'arrow', 'heading', @Title, NULL);
  71.     END
  72.   ELSE IF ( @dayNumber = 4 AND ( ( @dayTime > '17:00:00' AND @dayTime < '20:30:00' )  ) )
  73.   BEGIN
  74.     INSERT INTO @Items (ID, Parent_ID, [Type], Data, URL) VALUES
  75.       (@ID, NULL, 'card', NULL, @LivestreamURL),
  76.       (@ID + 'arrow', @ID, 'arrow-action', NULL, NULL),
  77.       (@ID + 'heading', @ID + 'arrow', 'heading', @Title, NULL);
  78.   END
  79.   --Enable the below block to send to archives if not streaming.
  80.   /*ELSE
  81.     BEGIN
  82.       INSERT INTO @Items (ID, Parent_ID, [Type], Data, URL) VALUES
  83.         (@ID, NULL, 'card', NULL, @LivestreamURL),
  84.         (@ID + 'arrow', @ID, 'arrow-action', NULL, NULL),
  85.         (@ID + 'heading', @ID + 'arrow', 'heading', 'Watch Archived Services' , NULL);
  86.     END*/
  87.   END
  88.  
  89.   DECLARE @OperationCount INT = ( SELECT COUNT(*) FROM @Items )
  90.   IF @OperationCount > 0
  91.     SELECT * FROM @Items;
  92.  
  93. END
RAW Paste Data