app/controllers/groups_controller.rb in radiant-reader-extension-3.0.0 vs app/controllers/groups_controller.rb in radiant-reader-extension-3.0.1
- old
+ new
@@ -11,14 +11,14 @@
def show
@readers = @group.readers.uniq
respond_to do |format|
format.html
format.csv {
- send_data generate_csv(@readers), :type => 'text/csv; charset=utf-8; header=present', :filename => "#{@group.filename}.csv"
+ send_data Reader.csv_for(@readers), :type => 'text/csv; charset=utf-8; header=present', :filename => "#{@group.filename}.csv"
}
format.vcard {
- send_data generate_vcard(@readers), :filename => "#{@group.filename}.vcf"
+ send_data Reader.vcards_for(@readers), :filename => "everyone.vcf"
}
end
end
private
@@ -30,8 +30,20 @@
def require_group_visibility
if @group && !@group.visible_to?(current_reader) # nb. @groups is a smaller set
raise ReaderError::AccessDenied, "That group is not public and you are not in it."
end
+ end
+
+ def generate_csv(readers=[])
+ columns = %w{forename surname email phone mobile postal_address}
+ table = FasterCSV.generate do |csv|
+ csv << columns.map { |f| t("activerecord.attributes.reader.#{f}") }
+ readers.each { |r| csv << columns.map{ |f| r.send(f.to_sym) } }
+ end
+ end
+
+ def generate_vcard(readers=[])
+ readers.map(&:vcard).join("\n")
end
end