class WorkPacket

File

work_packet.rb

(C)

Hipposoft 2007

Purpose

Describe the behaviour of WorkPacket objects. See below for more details.


24-Dec-2007 (ADH): Created.

Public Class Methods

find_earliest_by_tasks( task_ids = [] ) click to toggle source

Return the earliest (first by date) work packet, either across all tasks (pass nothing) or for the given tasks specified as an array of task IDs. The work packet may be in either a not committed or committed timesheet.

# File app/models/work_packet.rb, line 53
def self.find_earliest_by_tasks( task_ids = [] )
  return WorkPacket.find_first_by_tasks_and_order( task_ids, 'date ASC' )
end
find_first_by_tasks_and_order( task_ids, order ) click to toggle source

Support ::find_earliest_by_tasks and find_latest_by_tasks. Pass an array of task IDs and a sort order (SQL fragment, e.g. “date ASC”).

# File app/models/work_packet.rb, line 68
def self.find_first_by_tasks_and_order( task_ids, order )
  if ( task_ids.count.zero? )
    return WorkPacket.significant.order( order ).first

  else
    joins      = :timesheet_row
    conditions = { :timesheet_rows => { :task_id => task_ids } }
    return WorkPacket.significant.joins( joins ).where( conditions ).order( order ).first

  end
end
find_latest_by_tasks( task_ids = [] ) click to toggle source

Return the latest (last by date) work packet, either across all tasks (pass nothing) or for the given tasks specified as an array of task IDs. The work packet may be in either a not committed or committed timesheet.

# File app/models/work_packet.rb, line 61
def self.find_latest_by_tasks( task_ids = [] )
  return WorkPacket.find_first_by_tasks_and_order( task_ids, 'date DESC' )
end