module OrbitControllerLib
    module DivisionForDisable
      # def get_disable_object_by_user(object_class)
      #   if is_admin? or is_manager?
      #     object_class.admin_manager_all
      #   else
      #     object_class.all
      #   end
      # end


      def get_categories_for_index(object_class,id = nil)
        class_ref = object_class.constantize
        ivar_name = "@#{object_class.to_s.underscore.pluralize}"
        instance_variable_set(ivar_name, [])
        if(is_manager? || is_admin?)
          instance_variable_set(ivar_name,  (id ? class_ref.admin_manager_all.find(id).to_a : class_ref.admin_manager_all))
        elsif is_sub_manager?
          instance_variable_set(ivar_name,  (class_ref.all))
        end
        instance_variable_get(ivar_name)
      end

      def get_categorys(object_class,id = nil,func_authed_for_sub_manager = 'submit')
        class_ref = object_class.constantize
        # ivar_name = "@#{object_class.to_s.underscore.pluralize}"
        ivar_name = "@#{object_class.to_s.underscore}s"
        instance_variable_set(ivar_name, [])
        @bulletin_categorys = []
        if(is_manager? || is_admin?)
         #instance_variable_set(ivar_name,  (id ? class_ref.admin_manager_all.find(id).to_a : class_ref.admin_manager_all))
         instance_variable_set(ivar_name,  (id ? class_ref.all.find(id).to_a : class_ref.all))
       elsif is_sub_manager?
          instance_variable_set(ivar_name, class_ref.all.authed_for_user(current_user,func_authed_for_sub_manager))
        end
        if instance_variable_get(ivar_name).empty? && params[:action] != "index"
            flash[:alert] = t("announcement.error.no_avilb_cate_for_posting")
            redirect_to :action => :index
        end
      end
  

    end
end
