Class: MonthlyAllocation

Inherits:
Object
  • Object
show all
Includes:
DataMapper::Resource
Defined in:
models/monthlyallocation.rb

Overview

Allocation of time spent on apps for a given month and given User. Set by users to represent commitments. At the beginning of each month, AllocationPreset runs and sets a default MonthlyAllocation with wasAutoSet set to true. This default is zero if no previous allocation exists, or equal to the last month's allocation for that User if one exists.

Class Method Summary (collapse)

Instance Method Summary (collapse)

Methods included from DataMapper::Resource

#make_dirty

Class Method Details

+ (Integer) allocation(repository = nil)

Returns Allocation percentage (0-100)

Returns:

  • (Integer)

    Allocation percentage (0-100)



19
# File 'models/monthlyallocation.rb', line 19

property :allocation,	Integer

+ (MonthlyAllocation) allocationForUser(uid, month = nil, year = nil)

Get MonthlyAllocation for a given [User] and given month and year. If no month/year specified, return current month's allocation

Returns:

  • (MonthlyAllocation)

    Monthly allocation, or nil if none exists for given User/Month/Year combo



31
32
33
34
35
36
# File 'models/monthlyallocation.rb', line 31

def self.allocationForUser(uid, month=nil, year=nil)
	month = DateTime.now.month if(month.nil?)
	year = DateTime.now.year if(year.nil?)

	return first(:uid => uid, :month => month, :year => year, :order => [:id.desc])
end

+ (MonthlyAllocation) autoSetAllocationForUser(uid, allocation, month = nil, year = nil)

Automatically set a MonthlyAllocation for a User/month/year combo. This method will NOT override an already-created MonthlyAllocation for that combo.

Parameters:

  • uid (Integer)

    ID of User to create an auto-set MonthlyAllocation for

  • allocation (Integer)

    % allocation (0-100)

  • month (Integer) (defaults to: nil)

    Month to create an auto-set allocation for

  • year (Integer) (defaults to: nil)

    Year to create an auto-set allocation for

Returns:



75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'models/monthlyallocation.rb', line 75

def self.autoSetAllocationForUser(uid, allocation, month=nil, year=nil)
	month = DateTime.now.month if(month.nil?)
	year = DateTime.now.year if(year.nil?)

	row = first(:uid => uid, :month => month, :year => year, :order => [:id.desc])
	if(row.nil?)
		row = create(:uid => uid, :allocation => allocation, :month => month, :year => year, :wasAutoSet => true)
	else
		#dont overwrite with an autoset
		return nil
	end

	return row
end

+ (DateTime) created_at(repository = nil)

Returns Date/Time MonthlyAllocation created (DM Handled)

Returns:

  • (DateTime)

    Date/Time MonthlyAllocation created (DM Handled)



21
# File 'models/monthlyallocation.rb', line 21

property :created_at, 	DateTime

+ (Integer) id(repository = nil)

Returns Primary Key

Returns:

  • (Integer)

    Primary Key



15
# File 'models/monthlyallocation.rb', line 15

property :id,			Serial

+ (MonthlyAllocation) lastAllocationForUser(uid)

Get the most recent MonthlyAllocation set by a User. This will NOT return an auto-set allocation.

Parameters:

  • uid (Integer)

    ID of the User to get allocation for

Returns:

  • (MonthlyAllocation)

    Most recent explicitly set or confirmed MonthlyAllocation for given User



42
43
44
# File 'models/monthlyallocation.rb', line 42

def self.lastAllocationForUser(uid)
	return first(:uid => uid, :wasAutoSet => false, :order => [:id.desc])
end

+ (Integer) month(repository = nil)

Returns Month this Allocation is for (1-12)

Returns:

  • (Integer)

    Month this Allocation is for (1-12)



17
# File 'models/monthlyallocation.rb', line 17

property :month,		Integer

+ (MonthlyAllocation) setAllocationForUser(uid, allocation, month = nil, year = nil)

Set or update Monthly allocation for a given User/month/year combo

Parameters:

  • uid (Integer)

    ID of User to set or update MonthlyAllocation for

  • allocation (Integer)

    % allocation (0-100)

  • month (Integer) (defaults to: nil)

    Month to set/update allocation for

  • year (Integer) (defaults to: nil)

    Year to set/update allocation for

Returns:



53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'models/monthlyallocation.rb', line 53

def self.setAllocationForUser(uid, allocation, month=nil, year=nil)
	month = DateTime.now.month if(month.nil?)
	year = DateTime.now.year if(year.nil?)

	row = first(:uid => uid, :month => month, :year => year, :order => [:id.desc])
	if(row.nil?)
		row = create(:uid => uid, :allocation => allocation, :month => month, :year => year, :wasAutoSet => false)
	else
		row.update(:allocation => allocation, :wasAutoSet => false)
	end

	return row
end

+ (Integer) uid(repository = nil)

Returns ID of User this Allocation is for

Returns:

  • (Integer)

    ID of User this Allocation is for



16
# File 'models/monthlyallocation.rb', line 16

property :uid,			Integer

+ (DateTime) updated_at(repository = nil)

Returns Date/Time MonthlyAllocation last updated (DM Handled)

Returns:

  • (DateTime)

    Date/Time MonthlyAllocation last updated (DM Handled)



22
# File 'models/monthlyallocation.rb', line 22

property :updated_at, 	DateTime

+ (Boolean) wasAutoSet(repository = nil)

Returns True if this allocation was auto-set at beginning of month

Returns:

  • (Boolean)

    True if this allocation was auto-set at beginning of month



20
# File 'models/monthlyallocation.rb', line 20

property :wasAutoSet,	Boolean, :default => false

+ (Integer) year(repository = nil)

Returns Year this Allocation is for (4 digit year)

Returns:

  • (Integer)

    Year this Allocation is for (4 digit year)



18
# File 'models/monthlyallocation.rb', line 18

property :year,			Integer

Instance Method Details

- (Integer) allocation

Returns Allocation percentage (0-100)

Returns:

  • (Integer)

    Allocation percentage (0-100)



19
# File 'models/monthlyallocation.rb', line 19

property :allocation,	Integer

- (Integer) allocation=(value)

Returns Allocation percentage (0-100)

Returns:

  • (Integer)

    Allocation percentage (0-100)



19
# File 'models/monthlyallocation.rb', line 19

property :allocation,	Integer

- (DateTime) created_at

Returns Date/Time MonthlyAllocation created (DM Handled)

Returns:

  • (DateTime)

    Date/Time MonthlyAllocation created (DM Handled)



21
# File 'models/monthlyallocation.rb', line 21

property :created_at, 	DateTime

- (DateTime) created_at=(value)

Returns Date/Time MonthlyAllocation created (DM Handled)

Returns:

  • (DateTime)

    Date/Time MonthlyAllocation created (DM Handled)



21
# File 'models/monthlyallocation.rb', line 21

property :created_at, 	DateTime

- (Integer) id

Returns Primary Key

Returns:

  • (Integer)

    Primary Key



15
# File 'models/monthlyallocation.rb', line 15

property :id,			Serial

- (Integer) id=(value)

Returns Primary Key

Returns:

  • (Integer)

    Primary Key



15
# File 'models/monthlyallocation.rb', line 15

property :id,			Serial

- (Integer) month

Returns Month this Allocation is for (1-12)

Returns:

  • (Integer)

    Month this Allocation is for (1-12)



17
# File 'models/monthlyallocation.rb', line 17

property :month,		Integer

- (Integer) month=(value)

Returns Month this Allocation is for (1-12)

Returns:

  • (Integer)

    Month this Allocation is for (1-12)



17
# File 'models/monthlyallocation.rb', line 17

property :month,		Integer

- (Integer) uid

Returns ID of User this Allocation is for

Returns:

  • (Integer)

    ID of User this Allocation is for



16
# File 'models/monthlyallocation.rb', line 16

property :uid,			Integer

- (Integer) uid=(value)

Returns ID of User this Allocation is for

Returns:

  • (Integer)

    ID of User this Allocation is for



16
# File 'models/monthlyallocation.rb', line 16

property :uid,			Integer

- (DateTime) updated_at

Returns Date/Time MonthlyAllocation last updated (DM Handled)

Returns:

  • (DateTime)

    Date/Time MonthlyAllocation last updated (DM Handled)



22
# File 'models/monthlyallocation.rb', line 22

property :updated_at, 	DateTime

- (DateTime) updated_at=(value)

Returns Date/Time MonthlyAllocation last updated (DM Handled)

Returns:

  • (DateTime)

    Date/Time MonthlyAllocation last updated (DM Handled)



22
# File 'models/monthlyallocation.rb', line 22

property :updated_at, 	DateTime

- (Boolean) wasAutoSet

Returns True if this allocation was auto-set at beginning of month

Returns:

  • (Boolean)

    True if this allocation was auto-set at beginning of month



20
# File 'models/monthlyallocation.rb', line 20

property :wasAutoSet,	Boolean, :default => false

- (Boolean) wasAutoSet=(value)

Returns True if this allocation was auto-set at beginning of month

Returns:

  • (Boolean)

    True if this allocation was auto-set at beginning of month



20
# File 'models/monthlyallocation.rb', line 20

property :wasAutoSet,	Boolean, :default => false

- (Integer) year

Returns Year this Allocation is for (4 digit year)

Returns:

  • (Integer)

    Year this Allocation is for (4 digit year)



18
# File 'models/monthlyallocation.rb', line 18

property :year,			Integer

- (Integer) year=(value)

Returns Year this Allocation is for (4 digit year)

Returns:

  • (Integer)

    Year this Allocation is for (4 digit year)



18
# File 'models/monthlyallocation.rb', line 18

property :year,			Integer