class Dmptemplate

Public Class Methods

funders_and_own_templates(org_id) click to toggle source

returns an array with all funders and own institutional templates

# File app/models/dmptemplate.rb, line 63
def self.funders_and_own_templates(org_id)
        funders_templates = self.funders_templates

#verify if org type is not a funder

current_org = Organisation.find(org_id)
if current_org.organisation_type.name != I18n.t("helpers.org_type.funder") then 
    own_institutional_templates = self.own_institutional_templates(org_id)
        else
    own_institutional_templates = []
end    
    
        templates_list = Array.new
        templates_list += own_institutional_templates
        templates_list += funders_templates
        templates_list = templates_list.sort_by { |f| f['title'].downcase }
                        
        return templates_list
end
funders_templates() click to toggle source

returns all funders templates

# File app/models/dmptemplate.rb, line 44
    def self.funders_templates
            new_org_obejcts = OrganisationType.find_by_name(I18n.t("helpers.org_type.funder")).organisations
      org_templates = Array.new
    
    new_org_obejcts.each do |neworg|
    org_templates += neworg.dmptemplates
end

return org_templates        
    end
own_institutional_templates(org_id) click to toggle source

returns all institutional templates bellowing to the current user's org

# File app/models/dmptemplate.rb, line 57
def self.own_institutional_templates(org_id)
        new_templates = self.where("organisation_id = ?", org_id)
        return new_templates
end
templates_org_type(ot) click to toggle source
# File app/models/dmptemplate.rb, line 32
def self.templates_org_type(ot)
  new_org_obejcts = OrganisationType.find_by_name(ot).organisations
  
  org_templates = Array.new
  new_org_obejcts.each do |neworg|
     org_templates += neworg.dmptemplates.where("published = ?", true)
  end
  
  return org_templates
end

Public Instance Methods

has_customisations?(org_id, temp) click to toggle source

verify if a template has customisation by current user's org

# File app/models/dmptemplate.rb, line 88
def has_customisations?(org_id, temp)
        if temp.organisation_id != org_id then
                temp.phases.each do |phase|
                        phase.versions.each do |version|
                                version.sections.each do |section|
                                        return true if section.organisation_id == org_id 
                                                                                
                                end        
                        end
                        return false 
                end
        else
                return false         
        end   
end
has_published_versions?() click to toggle source

verify if there are any publish version for the template

# File app/models/dmptemplate.rb, line 106
def has_published_versions?
        phases.each do |phase|
                return true if !phase.latest_published_version.nil?
        end
        return false 
end
org_type() click to toggle source
# File app/models/dmptemplate.rb, line 82
def org_type
        org_type = organisation.organisation_type.name
        return org_type
end
to_s() click to toggle source
# File app/models/dmptemplate.rb, line 28
def to_s
  "#{title}"
end