Class: Employee

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
ExtensibleObjectHelper, HasCredentialModelHelper, IsActiveModelHelper
Defined in:
app/models/employee.rb

Defined Under Namespace

Classes: Slimtimer

Instance Method Summary collapse

Methods included from HasCredentialModelHelper

append_features, #credential_after_save, #validate_credential_fields

Methods included from IsActiveModelHelper

append_features, #initialize

Methods included from ExtensibleObjectHelper

append_features

Instance Method Details

#authorized_for?(options) ⇒ Boolean

Returns:

  • (Boolean)


39
40
41
42
43
44
45
46
# File 'app/models/employee.rb', line 39

def authorized_for?(options)
  case options[:action]
    when :destroy
      ( Activity::Labor.count( :all, :conditions => ['employee_id = ?', id] ) > 0 ) ? false : true
    else
      true
  end
end

#ensure_not_referenced_on_destroyObject



35
36
37
# File 'app/models/employee.rb', line 35

def ensure_not_referenced_on_destroy
  ( errors.add_to_base "Can't destroy a referenced employee" and return false ) unless authorized_for? :action => :destroy
end

#nameObject



17
18
19
20
21
22
23
24
25
# File 'app/models/employee.rb', line 17

def name
  ret = String.new
  
  ret += first_name if !first_name.nil? and first_name.length > 0
  
  ret += (ret.length > 0) ? " #{last_name}" : last_name if !last_name.nil? and last_name.length > 0
  
  ret
end

#short_nameObject



27
28
29
30
31
32
33
# File 'app/models/employee.rb', line 27

def short_name
  if first_name.length > 0 and last_name.length > 0
    (first_name[0...1] + last_name).downcase
  else
    (first_name.length > 0) ? first_name.downcase : last_name.downcase
  end
end