# -*- coding: utf-8 -*-

class NewsMailer < ActionMailer::Base
  default from: "salzamt@fet.at"
  helper :plugins

  def neuigkeit_mail(email, neuigkeit_id)
    @neuigkeit= Neuigkeit.find(neuigkeit_id)
    @user=User.first
    @ability=Ability.new(@user)
    subject =  @neuigkeit.title
    subject = subject.to_s + " email: " + email.to_s if Rails.env=="development"
    email = "andis@fet.at" if Rails.env=="development"
    email="andis@fet.at"
    mail(to: email, subject: subject)
    render locals: {current_user: User.first}
  end
  def daily_newsletter(user_id)
    user=User.find(user_id)
    self.message.perform_deliveries = false unless user.flag_getemails
    ability= Ability.new(user)
    
    @neuigkeiten=Neuigkeit.accessible_by(ability).published_scope.where("cache_order<2")
  end

  def daily_reminder(user_id)
    user=User.find(user_id)
    @user=user
    self.message.perform_deliveries = false unless user.flag_getemails
    @ability = Ability.new(user)
    @calentries = Calentry.of_month(Date.today).limit(100)
#    @neuigkeiten=Neuigkeit.accessiblße_by(ability).published_scope.where("cache_order<2")
    mail(to: user.email,      content_type: "text/html", subject: "sdf")
    render locals: {c_user: user}
 end
private
include CanCan::ControllerAdditions
  def current_user
    @user
  end
  def current_ability
    @ability
  end 
end
