Class: XPlanner::Person

Inherits:
ModelHelper show all
Extended by:
AttrAccessorWithDirtyBit
Defined in:
lib/models/person.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from AttrAccessorWithDirtyBit

dirty_accessor

Methods inherited from ModelHelper

base_url, base_url=, check_client_initialised, #check_client_initialised, #create_payload, fetch_from_remote, #hashify, parse_date, remote_delete, #remote_update, soap_client, soap_client=

Constructor Details

#initialize(p) ⇒ Person

Returns a new instance of Person.



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/models/person.rb', line 13

def initialize( p )
    @dirty_bit = false

    @id                = p[:id]
    @name              = p[:name]
    @last_update_time  = Person.parse_date p[:last_update_time]
    @initials          = p[:initials]
    @phone             = p[:phone]
    @user_id           = p[:user_id]
    @email             = p[:email]
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



10
11
12
# File 'lib/models/person.rb', line 10

def id
  @id
end

#last_update_timeObject (readonly)

Returns the value of attribute last_update_time.



10
11
12
# File 'lib/models/person.rb', line 10

def last_update_time
  @last_update_time
end

Class Method Details

.allObject



25
26
27
28
29
30
31
# File 'lib/models/person.rb', line 25

def self.all
    rpc = :get_people
    path = [:get_people_response, :get_people_return, :get_people_return]
    p = fetch_from_remote( rpc, {}, path, Person )
    p = [p] if p.class == Person
    p
end

.create(name, email, user_id, initials = '', phone = '') ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/models/person.rb', line 40

def self.create( name, email, user_id, initials = '', phone = '' )
    rpc = :add_person
    payload = { :personData => {
        :name => name, 
        :email => email, 
        :user_id => user_id,
        :initials => initials,
        :phone => phone
    } }
    path = [:add_person_response, :add_person_return]
    fetch_from_remote( rpc, payload, path, Person )
end

.delete(id) ⇒ Object



53
54
55
56
57
# File 'lib/models/person.rb', line 53

def self.delete( id )
    rpc = :remove_person
    payload = { :id => id }
    remote_delete( rpc, payload )
end

.get_userid_from_username(username) ⇒ Object



69
70
71
72
# File 'lib/models/person.rb', line 69

def self.get_userid_from_username( username )
    Person.all.each { |u| return Integer(u.id) if u.user_id == username }
    return nil
end

.retrieve(id) ⇒ Object



33
34
35
36
37
38
# File 'lib/models/person.rb', line 33

def self.retrieve( id )
    rpc = :get_person
    payload = { :id => id }
    path = [:get_person_response, :get_person_return]
    fetch_from_remote( rpc, payload, path, Person )
end

Instance Method Details

#deleteObject



59
60
61
# File 'lib/models/person.rb', line 59

def delete
    Person.delete @id
end

#saveObject



63
64
65
66
67
# File 'lib/models/person.rb', line 63

def save
    rpc = :update
    payload = { :personData => create_payload }
    remote_update( rpc, payload )
end