Class: Knjappserver::Log

Inherits:
Knj::Datarow
  • Object
show all
Defined in:
lib/include/class_log.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.add(d) ⇒ Object



52
53
54
# File 'lib/include/class_log.rb', line 52

def self.add(d)
	d.data[:date_saved] = Time.now if !d.data.key?(:date_saved)
end

.list(d, &block) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/include/class_log.rb', line 6

def self.list(d, &block)
	sql = "SELECT #{table}.* FROM #{table}"
	
	if d.args["object_lookup"]
     data_val = d.ob.get_by(:Log_data_value, {"value" => d.args["object_lookup"].class.name})
     return [] if !data_val #if this data-value cannot be found, nothing has been logged for the object. So just return empty array here and skip the rest.
     
		sql << "
			LEFT JOIN Log_link ON
				Log_link.log_id = #{table}.id AND
				Log_link.object_class_value_id = '#{d.db.esc(data_val.id)}' AND
				Log_link.object_id = '#{d.db.esc(d.args["object_lookup"].id)}'
		"
	end
	
	return_sql = false
	sql << " WHERE 1=1"
	
	ret = list_helper(d)
	d.args.each do |key, val|
		case key
			when "object_lookup"
         sql << " AND Log_link.id IS NOT NULL"
       when "return_sql"
         return_sql = true
       when "tag"
         data_val = d.ob.get_by(:Log_data_value, {"value" => val})
         if !data_val
           sql << " AND false"
         else
           sql << " AND Log.tag_data_id = '#{d.db.esc(data_val.id)}'"
         end
			else
				raise "Invalid key: #{key}."
			end
	end
	
	sql << ret[:sql_where]
	sql << ret[:sql_order]
	sql << ret[:sql_limit]
	
	return sql if return_sql
	
	return d.ob.list_bysql(:Log, sql, &block)
end

Instance Method Details

#commentObject



60
61
62
63
64
65
# File 'lib/include/class_log.rb', line 60

def comment
   return "" if self[:comment_data_id].to_i == 0
   log_data = ob.get(:Log_data_value, self[:comment_data_id])
   return "" if !log_data
   return log_data[:value]
end


82
83
84
# File 'lib/include/class_log.rb', line 82

def cookie
  ob.args[:knjappserver].log_data_hash(self[:cookie_keys_data_id], self[:cookie_values_data_id])
end

#first_lineObject



102
103
104
# File 'lib/include/class_log.rb', line 102

def first_line
	lines = self.text.to_s.split("\n").first.to_s
end

#getObject



74
75
76
# File 'lib/include/class_log.rb', line 74

def get
	ob.args[:knjappserver].log_data_hash(self[:get_keys_data_id], self[:get_values_data_id])
end

#ipObject



94
95
96
97
98
99
100
# File 'lib/include/class_log.rb', line 94

def ip
  meta_d = self.meta
  
  return meta_d[:HTTP_X_FORWARDED_FOR] if meta_d.has_key?(:HTTP_X_FORWARDED_FOR)
  return meta_d[:REMOTE_ADDR] if meta_d.has_key?(:REMOTE_ADDR)
  return "[no ip logged]"
end

#metaObject



86
87
88
# File 'lib/include/class_log.rb', line 86

def meta
  ob.args[:knjappserver].log_data_hash(self[:meta_keys_data_id], self[:meta_values_data_id])
end

#objects_html(ob_use) ⇒ Object



106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/include/class_log.rb', line 106

def objects_html(ob_use)
	html = ""
	first = true
	
	self.links.each do |link|
		obj = link.object(ob_use)
		
		html << ", " if !first
		first = false if first
		
		if obj.respond_to?(:html)
			html << obj.html
		else
			html << "#{obj.class.name}{#{obj.id}}"
		end
	end
	
	return html
end

#postObject



78
79
80
# File 'lib/include/class_log.rb', line 78

def post
	ob.args[:knjappserver].log_data_hash(self[:post_keys_data_id], self[:post_values_data_id])
end

#sessionObject



90
91
92
# File 'lib/include/class_log.rb', line 90

def session
  ob.args[:knjappserver].log_data_hash(self[:session_keys_data_id], self[:session_values_data_id])
end

#tagObject



67
68
69
70
71
72
# File 'lib/include/class_log.rb', line 67

def tag
   return "" if self[:tag_data_id].to_i == 0
   log_data = ob.get(:Log_data_value, self[:tag_data_id])
   return "" if !log_data
   return log_data[:value]
end

#textObject



56
57
58
# File 'lib/include/class_log.rb', line 56

def text
	return ob.get(:Log_data_value, self[:text_value_id])[:value]
end