﻿<?xml version="1.0"?>
<AlvaoApplication xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ModelVersion="1">
  <Applications>
    <Application id="36">
      <Name>TicketKnowledgeBase</Name>
      <Description>Custom request tab for the solver team with a list of relevant knowledge base articles (assigned to the request service).</Description>
      <Scripts>
        <Script id="97">
          <Name>Settings</Name>
          <Code>public static class Settings
{
    /*
     * Knowledge base tab will be displayed for configured supported services.
     * Example values:
     *
     * public static int[] SupportedServices = null;           - tab is displayed in all services
     * public static int[] SupportedServices = { };            - tab is not displayed
     * public static int[] SupportedServices = { 1, 2, 3 };    - tab is displayed in services with ID 1, 2, 3
     *
     */

    public static readonly int[] SupportedServices = null;

    // The text displayed on the tab
    public const string TabName = "Knowledge Base";
}
</Code>
          <IsLibCode>true</IsLibCode>
        </Script>
        <Script id="98">
          <Name>SectionKnowledges</Name>
          <Code>using System;
using Alvao.API.Common;
using Alvao.API.Common.Model.CustomApps;
using Alvao.Apps.API;

public class SectionKnowledges : IEntityTab
{
    public string Id {get; set;}
    public Entity Entity {get; set;}

    public SectionKnowledges() 
    {
        Id = Settings.TabName.GetHashCode().ToString();
        Entity = Entity.Request;
    }

    public EntityTabShowResult Show(int entityId, int personId)
    {      
        bool show = false;
        string name = Settings.TabName;
        string url = string.Empty;

        try
        {
            var ticket = Alvao.API.SD.Ticket.GetById(entityId);
            if (ticket == null)
            {
                return new EntityTabShowResult(show, name, url);
            }

            //Check if the request service is in the service list 
            int sectionId = ticket.liHdTicketHdSectionId;
            if (Settings.SupportedServices != null &amp;&amp; Array.IndexOf(Settings.SupportedServices, sectionId) == -1)
            {
                return new EntityTabShowResult(show, name, url);
            }

            var teamRoles = PersonRights.TicketRoles.SectionManager | PersonRights.TicketRoles.SectionMainSolver | PersonRights.TicketRoles.SectionSolver;
            show = PersonRights.HaveTicketRole(personId, entityId, sectionId, teamRoles, true);


            //Show only to members of the Service team
            if (show)
            {
                string webAppUrl = DbProperty.WebAppUrl;
                if (!string.IsNullOrEmpty(webAppUrl))
                {
                    //Address of tab with articles from knowledge base
                    url = webAppUrl + "/KnowledgeBase?id=" + sectionId;
                }
            }
        }
        catch
        {
            return new EntityTabShowResult(show, name, url);
        }

        return new EntityTabShowResult(show, name, url);
    }
}</Code>
          <IsLibCode>false</IsLibCode>
        </Script>
      </Scripts>
    </Application>
  </Applications>
</AlvaoApplication>