<commit_before># Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/
module Ticket::HistoryLog

=begin

create log activity for this ticket

  ticket = Ticket.find(123)
  result = ticket.history_create('created', user_id)

returns

  result = true # false

=end

  def history_log (type, user_id, data = {})
    data[:o_id]                   = self['id']
    data[:history_type]           = type
    data[:history_object]         = self.class.name
    data[:related_o_id]           = nil
    data[:related_history_object] = nil
    data[:created_by_id]          = user_id
    data[:updated_at]             = updated_at
    data[:created_at]             = updated_at
    History.add(data)
  end

=begin

get log activity for this ticket

  ticket = Ticket.find(123)
  result = ticket.history_get()

returns

  result = [
    {
      :type          => 'created',
      :object        => 'Ticket',
      :created_by_id => 3,
      :created_at    => "2013-08-19 20:41:33",
    },
    {
      :type          => 'updated',
      :object        => 'Ticket',
      :attribute     => 'priority',
      :o_id          => 1,
      :id_to         => 3,
      :id_from       => 2,
      :value_from    => "low",
      :value_to      => "high",
      :created_by_id => 3,
      :created_at    => "2013-08-19 20:41:33",
    },
  ]

=end

  def history_get(fulldata = false)
    list = History.list( self.class.name, self['id'], 'Ticket::Article' )
    return list if !fulldata

    # get related objects
    assets = {}
    list.each {|item|
      record = Kernel.const_get( item['object'] ).find( item['o_id'] )
      assets = record.assets(assets)

      if item['related_object']
        record = Kernel.const_get( item['related_object'] ).find( item['related_o_id'] )
        assets = record.assets(assets)
      end
    }
    {
      history: list,
      assets: assets,
    }
  end
end<commit_msg>improved doc.<commit_after># Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/
module Ticket::HistoryLog

=begin

create log activity for this ticket

  ticket = Ticket.find(123)
  result = ticket.history_create('created', user_id)

returns

  result = true # false

=end

  def history_log (type, user_id, data = {})
    data[:o_id]                   = self['id']
    data[:history_type]           = type
    data[:history_object]         = self.class.name
    data[:related_o_id]           = nil
    data[:related_history_object] = nil
    data[:created_by_id]          = user_id
    data[:updated_at]             = updated_at
    data[:created_at]             = updated_at
    History.add(data)
  end

=begin

get log activity for this ticket

  ticket = Ticket.find(123)
  result = ticket.history_get()

returns

  result = [
    {
      type: 'created',
      object: 'Ticket',
      created_by_id: 3,
      created_at: "2013-08-19 20:41:33",
    },
    {
      type: 'updated',
      object: 'Ticket',
      attribute: 'priority',
      o_id: 1,
      id_to: 3,
      id_from: 2,
      value_from: "low",
      value_to: "high",
      created_by_id: 3,
      created_at: "2013-08-19 20:41:33",
    },
  ]

=end

  def history_get(fulldata = false)
    list = History.list(self.class.name, self['id'], 'Ticket::Article')
    return list if !fulldata

    # get related objects
    assets = {}
    list.each {|item|
      record = Kernel.const_get(item['object']).find(item['o_id'])
      assets = record.assets(assets)

      if item['related_object']
        record = Kernel.const_get(item['related_object']).find( item['related_o_id'])
        assets = record.assets(assets)
      end
    }
    {
      history: list,
      assets: assets,
    }
  end
end
{'fraction_non_alphanumeric': 0.13183540877097996, 'fraction_numerical': 0.025446670276123445, 'mean_word_length': 2.210251954821894, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '341294', 'n_tokens_mistral': 1313, 'n_tokens_neox': 1221, 'n_words': 262}