
################
StandardTemplate
################


****
NAME
****


Kernel::System::StandardTemplate - standard template lib


***********
DESCRIPTION
***********


All standard template functions. E. g. to add standard template or other functions.


****************
PUBLIC INTERFACE
****************


new()
=====


create an object


.. code-block:: perl

     my $StandardTemplateObject = $Kernel::OM->Get('Kernel::System::StandardTemplate');



StandardTemplateAdd()
=====================


add new standard template


.. code-block:: perl

     my $ID = $StandardTemplateObject->StandardTemplateAdd(
         Name         => 'New Standard Template',
         Template     => 'Thank you for your email.',
         ContentType  => 'text/plain; charset=utf-8',
         TemplateType => 'Answer,Forward',
         ValidID      => 1,
         UserID       => 123,
     );



StandardTemplateGet()
=====================


get standard template attributes


.. code-block:: perl

     my %StandardTemplate = $StandardTemplateObject->StandardTemplateGet(
         ID => 123,
     );


Returns:


.. code-block:: perl

     %StandardTemplate = (
         ID                  => '123',
         Name                => 'Simple remplate',
         Comment             => 'Some comment',
         Template            => 'Template content',
         ContentType         => 'text/plain',
         TemplateType        => 'Answer,Forward',
         ValidID             => '1',
         CreateTime          => '2010-04-07 15:41:15',
         CreateBy            => '321',
         ChangeTime          => '2010-04-07 15:59:45',
         ChangeBy            => '223',
     );



StandardTemplateDelete()
========================


delete a standard template


.. code-block:: perl

     $StandardTemplateObject->StandardTemplateDelete(
         ID => 123,
     );



StandardTemplateUpdate()
========================


update standard template attributes


.. code-block:: perl

     $StandardTemplateObject->StandardTemplateUpdate(
         ID           => 123,
         Name         => 'New Standard Template',
         Template     => 'Thank you for your email.',
         ContentType  => 'text/plain; charset=utf-8',
         TemplateType => 'Answer,Forward',
         ValidID      => 1,
         UserID       => 123,
     );



StandardTemplateLookup()
========================


return the name or the standard template id


.. code-block:: perl

     my $StandardTemplateName = $StandardTemplateObject->StandardTemplateLookup(
         StandardTemplateID => 123,
     );
 
     or
 
     my $StandardTemplateID = $StandardTemplateObject->StandardTemplateLookup(
         StandardTemplate => 'Std Template Name',
     );



StandardTemplateExport()
========================


export a standard template


.. code-block:: perl

     my $ExportData = $StandardTemplateObject->StandardTemplateExport(
         # required either ID or ExportAll
         ID                       => $StandardTemplateID,
         ExportAll                => 0,               # possible: 0, 1
 
         UserID                   => 1,               # required
     }


returns Standard Template hashes in an array with data:


.. code-block:: perl

     my $ExportData =
     [
         {
             'ValidID' => 1,
             'Template' => '<p>some-content</p>',
             'CreateBy' => 1,
             'Name' => 'create1',
             'TemplateType' => 'Create',
             'Comment' => '',
             'Queues' => {},
             'ChangeBy' => 1,
             'ID' => '24',
             'Attachments' => {
                 '1' => 'attachment1',
                 '2' => 'attachment2'
             },
             'CreateTime' => '2024-07-24 09:47:28',
             'ContentType' => 'text/html',
             'ChangeTime' => '2024-07-24 09:53:25'
         },
     ];



StandardTemplateImport()
========================


import a standard template via YAML content


.. code-block:: perl

     my $ImportResult = $StandardTemplateObject->StandardTemplateImport(
         Content                    => $YAMLContent, # mandatory, YAML format
         OverwriteExistingTemplates => 0,            # optional, possible: 0, 1
         UserID                     => 1,            # mandatory
     );


Returns:


.. code-block:: perl

     $Result = {
         Success          => 1,                                      # 1 if success or undef if operation could not
                                                                     # be performed
         Message          => 'The Message to show.',                 # error message
         Added            => 'StandardTemplate1, StandardTemplate2', # string of StandardTemplates correctly added
         Updated          => 'StandardTemplate3, StandardTemplate4', # string of StandardTemplates correctly updated
         NotUpdated       => 'StandardTemplate5, StandardTemplate6', # string of StandardTemplates not updated due to existing entity
                                                                     # with the same name
         Errors           => 'StandardTemplate5',                    # string of StandardTemplates that could not be added or updated
         AdditionalErrors => ['Some error occured!', 'Error2!'],     # list of additional error not necessarily related to specified StandardTemplate
     };



StandardTemplateCopy()
======================


copy a standard template without linking it to any queue/attachment


.. code-block:: perl

     my $NewStandardTemplateID = $StandardTemplateObject->StandardTemplateCopy(
         ID     => 1, # mandatory
         UserID => 1, # mandatory
     );



StandardTemplateExportDataGet()
===============================


get data to export standard template


.. code-block:: perl

     my %StandardTemplateData = $StandardTemplateObject->StandardTemplateExportDataGet(
         ID => 1, # mandatory
     );


Returns:


.. code-block:: perl

     my %StandardTemplateData = (
         {
            'ValidID' => 1,
            'CreateBy' => 1,
            'Template' => '<p>some-content</p>',
            'Name' => 'create1',
            'TemplateType' => 'Create',
            'Queues' => {},
            'ChangeBy' => 1,
            'ID' => '24',
            'Comment' => '',
            'Attachments' => {
                 '1' => 'attachment1',
                 '2' => 'attachment2'
             },
             'CreateTime' => '2024-07-24 09:47:28',
             'ChangeTime' => '2024-07-24 09:53:25',
             'ContentType' => 'text/html'
         };
     );



StandardTemplateExportFilenameGet()
===================================


get export file name based on standard template name


.. code-block:: perl

     my $Filename = $StandardTemplateObject->StandardTemplateExportFilenameGet(
         Name => 'StandardTemplate_1',
         Format => 'YAML',
     );



StandardTemplateQueuesList()
============================


get a list of the queues that have been linked to standard template


.. code-block:: perl

     my %StandardTemplateQueues = $StandardTemplateObject->StandardTemplateQueuesList(
         ID => 1, # mandatory
     );


Returns:


.. code-block:: perl

     my %StandardTemplateQueues = (
         1 => 'queue1',
         2 => 'queue2',
     )



StandardTemplateAttachmentsList()
=================================


get a list of attachments that have been linked to standard template


.. code-block:: perl

     my %StandardTemplateAttachments = $StandardTemplateObject->StandardTemplateAttachmentsList(
         ID => 1, # mandatory
     );


Returns:


.. code-block:: perl

     my %StandardTemplateAttachments = (
         1 => 'attachment1',
         2 => 'attachment2',
     )



StandardTemplateQueueLinkByTemplate()
=====================================


assign a list of queues to a template


.. code-block:: perl

     my $Success = $StandardTemplateObject->StandardTemplateQueueLinkByTemplate(
         QueueIDs => [1,2,3],
         ID       => 1,
         UserID   => 1,
     );



StandardTemplateAttachmentLinkByTemplate()
==========================================


assign a list of attachments to a template


.. code-block:: perl

     my $Success = $StandardTemplateObject->StandardTemplateAttachmentLinkByTemplate(
         AttachmentIDs => [1,2,3],
         ID            => 1,
         UserID        => 1,
     );



StandardTemplateList()
======================


get all valid standard templates


.. code-block:: perl

     my %StandardTemplates = $StandardTemplateObject->StandardTemplateList();


Returns:


.. code-block:: perl

     %StandardTemplates = (
         1 => 'Some Name',
         2 => 'Some Name2',
         3 => 'Some Name3',
     );


get all standard templates


.. code-block:: perl

     my %StandardTemplates = $StandardTemplateObject->StandardTemplateList(
         Valid => 0,
     );


Returns:


.. code-block:: perl

     %StandardTemplates = (
         1 => 'Some Name',
         2 => 'Some Name2',
     );


get standard templates of a single type


.. code-block:: perl

     my %StandardTemplates = $StandardTemplateObject->StandardTemplateList(
         Valid => 0,
         Type  => 'Answer',
     );


Returns:


.. code-block:: perl

     %StandardTemplates = (
         1 => 'Some Name',
     );


get standard templates for multiple types


.. code-block:: perl

     my %StandardTemplates = $StandardTemplateObject->StandardTemplateList(
         Valid => 0,
         Type  => 'Answer,Forward',
     );


Returns:


.. code-block:: perl

     %StandardTemplates = (
         'Answer' => {
             '1' => 'Some Name',
             '4' => 'AW FWD',
         },
         'Forward' => {
             '3' => 'Some Name3',
             '4' => 'AW FWD',
         }
     );



NameExistsCheck()
=================



.. code-block:: perl

     return 1 if another standard template with this name already exists
 
         $Exist = $StandardTemplateObject->NameExistsCheck(
             Name => 'Some::Template',
             ID   => 1,                  # optional
         );





