Class: TimeEntry
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- TimeEntry
- Defined in:
- app/models/time_entry.rb
Overview
redMine - project management software Copyright (C) 2006-2008 Jean-Philippe Lang
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Class Method Summary
Instance Method Summary
- - (Object) after_initialize
- - (Object) before_validation
-
- (Boolean) editable_by?(usr)
Returns true if the time entry can be edited by usr, otherwise false.
- - (Object) hours(h)
-
- (Object) spent_on(date)
tyear, tmonth, tweek assigned where setting spent_on attributes these attributes make time aggregations easier.
- - (Object) validate
Methods inherited from ActiveRecord::Base
Class Method Details
+ (Object) visible_by(usr)
79 80 81 82 83 |
# File 'app/models/time_entry.rb', line 79 def self.visible_by(usr) with_scope(:find => { :conditions => Project.allowed_to_condition(usr, :view_time_entries) }) do yield end end |
Instance Method Details
- (Object) after_initialize
42 43 44 45 46 47 48 49 |
# File 'app/models/time_entry.rb', line 42 def after_initialize if new_record? && self.activity.nil? if default_activity = TimeEntryActivity.default self.activity_id = default_activity.id end self.hours = nil if hours == 0 end end |
- (Object) before_validation
51 52 53 |
# File 'app/models/time_entry.rb', line 51 def before_validation self.project = issue.project if issue && project.nil? end |
- (Boolean) editable_by?(usr)
Returns true if the time entry can be edited by usr, otherwise false
75 76 77 |
# File 'app/models/time_entry.rb', line 75 def editable_by?(usr) (usr == user && usr.allowed_to?(:edit_own_time_entries, project)) || usr.allowed_to?(:edit_time_entries, project) end |
- (Object) hours=(h)
61 62 63 |
# File 'app/models/time_entry.rb', line 61 def hours=(h) write_attribute :hours, (h.is_a?(String) ? (h.to_hours || h) : h) end |
- (Object) spent_on=(date)
tyear, tmonth, tweek assigned where setting spent_on attributes these attributes make time aggregations easier
67 68 69 70 71 72 |
# File 'app/models/time_entry.rb', line 67 def spent_on=(date) super self.tyear = spent_on ? spent_on.year : nil self.tmonth = spent_on ? spent_on.month : nil self.tweek = spent_on ? Date.civil(spent_on.year, spent_on.month, spent_on.day).cweek : nil end |
- (Object) validate
55 56 57 58 59 |
# File 'app/models/time_entry.rb', line 55 def validate errors.add :hours, :invalid if hours && (hours < 0 || hours >= 1000) errors.add :project_id, :invalid if project.nil? errors.add :issue_id, :invalid if (issue_id && !issue) || (issue && project!=issue.project) end |