class RegistrationDatatable include ActionView::Helpers::TagHelper include DmEvent::RegistrationsHelper include DmUtilities::DateHelper include DmCore::ApplicationHelper delegate :params, :link_to, :image_tag, :number_to_currency, :time_ago_in_words, to: :@view delegate :url_helpers, to: 'DmEvent::Engine.routes' #------------------------------------------------------------------------------ def initialize(view, user, permissions) @view = view @user = user @permissions = permissions end #------------------------------------------------------------------------------ def as_json(options = {}) { sEcho: params[:sEcho].to_i, iTotalDisplayRecords: registrations.total_entries, iTotalRecords: @workshop.registrations.count, aaData: data } end private #------------------------------------------------------------------------------ def data registrations.map do |registration| [ registration_actions(registration), "#{registration.receipt_code}", name_and_avatar(registration), present(registration).balance_or_paid, "#{format_date(registration.created_at)}", "#{(registration.user_profile.user ? present(registration.user_profile.user).last_access : colored_label('no user', :gray))}" ] end end #------------------------------------------------------------------------------ def registrations @registrations ||= fetch_registrations end #------------------------------------------------------------------------------ def name_and_avatar(registration) # image_tag(registration.user_profile.public_avatar_url(:sq35), width: 25, height: 25) + link_to(registration.full_name, url_helpers.edit_admin_registration_path(I18n.locale, registration)) if @permissions[:manage_event_registrations] link_to(registration.full_name, url_helpers.edit_admin_registration_path(I18n.locale, registration)) else registration.full_name end end #------------------------------------------------------------------------------ def fetch_registrations @workshop = Workshop.find_by_slug(params[:id]) registrations = @workshop.registrations.includes(:workshop_price, :user_profile => [:user => :current_site_profile]).references(:user_profiles).order("#{sort_column} #{sort_direction}") if !@permissions[:manage_event_registrations] && !@permissions[:manage_event_finances] # limit to your own registration if can only edit the workshop registrations = registrations.where(user_profile_id: @user.user_profile.id) end if params[:duplicates].present? #--- grab only registrations that have duplicates (based on the user_profile_id) grouped = registrations.group(:user_profile_id) dups = grouped.count.reject {|x, y| y == 1}.collect {|x, y| x} registrations = registrations.where(user_profile_id: dups) end registrations = registrations.page(page).per_page(per_page) if params[:sSearch].present? registrations = registrations.where("LOWER(user_profiles.first_name) like :search OR LOWER(user_profiles.last_name) like :search OR LOWER(user_profiles.email) like :search OR receipt_code like :search", search: "%#{params[:sSearch]}%".downcase) end registrations end #------------------------------------------------------------------------------ def registration_actions(registration) actions = '' actions += '