class Project

Public Class Methods

projects_for_user(user_id) click to toggle source
# File app/models/project.rb, line 142
def self.projects_for_user(user_id)
        projects = Array.new
        groups = ProjectGroup.where("user_id = ?", user_id)
        unless groups.nil? then
                groups.each do |group|
                        unless group.project.nil? then
                                projects << group.project
                        end
                end
        end
        return projects
end

Public Instance Methods

administerable_by(user_id) click to toggle source
# File app/models/project.rb, line 115
def administerable_by(user_id)
        user = project_groups.find_by_user_id(user_id)
        if (! user.nil?) && user.project_administrator then
                return true
        else
                return false
        end
end
assign_administrator(user_id) click to toggle source
# File app/models/project.rb, line 111
def assign_administrator(user_id)
        add_user(user_id, true, true)
end
assign_creator(user_id) click to toggle source
# File app/models/project.rb, line 99
def assign_creator(user_id)
        add_user(user_id, true, true, true)
end
assign_editor(user_id) click to toggle source
# File app/models/project.rb, line 103
def assign_editor(user_id)
        add_user(user_id, true)
end
assign_reader(user_id) click to toggle source
# File app/models/project.rb, line 107
def assign_reader(user_id)
        add_user(user_id)
end
created_by(user_id) click to toggle source
# File app/models/project.rb, line 155
def created_by(user_id)
        user = project_groups.find_by_user_id(user_id)
        if (! user.nil?) && user.project_creator then
                return true
        else
                return false
        end
end
editable_by(user_id) click to toggle source
# File app/models/project.rb, line 124
def editable_by(user_id)
        user = project_groups.find_by_user_id(user_id)
        if (! user.nil?) && user.project_editor then
                return true
        else
                return false
        end
end
funder() click to toggle source
# File app/models/project.rb, line 39
def funder
        if dmptemplate.nil? then
                return nil
        end
        template_org = dmptemplate.organisation
        if template_org.organisation_type.name == I18n.t('helpers.org_type.funder').downcase
                return template_org
        else
                return nil
        end
end
funder_id() click to toggle source
# File app/models/project.rb, line 27
def funder_id
        if dmptemplate.nil? then
                return nil
        end
        template_org = dmptemplate.organisation
        if template_org.organisation_type.name == I18n.t('helpers.org_type.funder').downcase
                return template_org.id
        else
                return nil
        end
end
funder_id=(new_funder_id) click to toggle source
# File app/models/project.rb, line 18
def funder_id=(new_funder_id)
        if new_funder_id != "" then
                new_funder = Organisation.find(new_funder_id);
                if new_funder.dmptemplates.count == 1 then
                        dmptemplate = new_funder.dmptemplates.first
                end
        end
end
funder_name() click to toggle source
# File app/models/project.rb, line 51
def funder_name
        if self.funder.nil?
                return read_attribute(:funder_name)
        else
                return self.funder.name
        end
end
funder_name=(new_funder_name) click to toggle source
# File app/models/project.rb, line 59
def funder_name=(new_funder_name)
        write_attribute(:funder_name, new_funder_name)
        org_table = Organisation.arel_table
        existing_org = Organisation.where(org_table[:name].matches(new_funder_name))
        if existing_org.nil?
                existing_org = Organisation.where(org_table[:abbreviation].matches(new_funder_name))
        end
        unless existing_org.empty?
                self.funder_id=existing_org.id
        end
end
institution_id() click to toggle source
# File app/models/project.rb, line 77
def institution_id
        if organisation.nil?
                return nil
        else
                return organisation.root.id
        end
end
institution_id=(new_institution_id) click to toggle source
# File app/models/project.rb, line 71
def institution_id=(new_institution_id)
        if organisation.nil? then
                self.organisation_id = new_institution_id
        end
end
last_edited() click to toggle source
# File app/models/project.rb, line 183
def last_edited
        self.latest_update.to_date
end
latest_update() click to toggle source
# File app/models/project.rb, line 164
def latest_update
        latest_update = updated_at
        plans.each do |plan|
                if plan.latest_update > latest_update then
                        latest_update = plan.latest_update
                end
        end
        return latest_update
end
name() click to toggle source

Getters to match 'My plans' columns

# File app/models/project.rb, line 175
def name
        self.title
end
owner() click to toggle source
# File app/models/project.rb, line 179
def owner
        self.project_groups.find_by_project_creator(true).try(:user)
end
readable_by(user_id) click to toggle source
# File app/models/project.rb, line 133
def readable_by(user_id)
        user = project_groups.find_by_user_id(user_id)
        if (! user.nil?) then
                return true
        else
                return false
        end
end
shared() click to toggle source
Alias for: shared?
shared?() click to toggle source
# File app/models/project.rb, line 187
def shared?
        self.project_groups.count > 1
end
Also aliased as: shared
template_owner() click to toggle source
# File app/models/project.rb, line 193
def template_owner
        self.dmptemplate.try(:organisation).try(:abbreviation)
end
unit_id() click to toggle source
# File app/models/project.rb, line 91
def unit_id
        if organisation.nil? || organisation.parent_id.nil?
                return nil
        else
                return organisation_id
        end
end
unit_id=(new_unit_id) click to toggle source
# File app/models/project.rb, line 85
def unit_id=(new_unit_id)
        unless new_unit_id.nil? ||new_unit_id == ""
                self.organisation_id = new_unit_id
        end
end

Private Instance Methods

add_user(user_id, is_editor = false, is_administrator = false, is_creator = false) click to toggle source
# File app/models/project.rb, line 199
def add_user(user_id, is_editor = false, is_administrator = false, is_creator = false)
        group = ProjectGroup.new
        group.user_id = user_id
        group.project_creator = is_creator
        group.project_editor = is_editor
        group.project_administrator = is_administrator
        project_groups << group
end
create_plans() click to toggle source
# File app/models/project.rb, line 208
def create_plans
        dmptemplate.phases.each do |phase|
                latest_published_version = phase.latest_published_version
                unless latest_published_version.nil?
                        new_plan = Plan.new
                        new_plan.version = latest_published_version
                        plans << new_plan
                end
        end
end