Fix matt's code and add it to filters

This commit is contained in:
Christophe Vilayphiou committed 2012-05-19 03:19:55 +08:00
1 parent dc4116bc3d
commit 815e6a8361
2 files changed
+24 -14

No files matched your search

+23 -7
View File
@@ -32,13 +32,7 @@ class OrbitBackendController< ApplicationController
end
def get_sorted_and_filtered(object_class, query=nil)
object_class = object_class.classify.constantize
if query
objects = object_class.all.where(query)
else
objects = object_class.all
end
objects = get_objects(object_class, query)
if !params[:sort].blank?
options = params[:sort_options]
options = [options] if !options.class.eql?(Array)
@@ -157,5 +151,27 @@ class OrbitBackendController< ApplicationController
a = params[:direction].eql?('asc') ? (sorted_tmp + sorted_objects) : (sorted_objects + sorted_tmp)
a.flatten
end
def get_viewable(object_class)
objects = get_objects(object_class)
Kaminari.paginate_array(objects).page(params[:page]).per(10)
end
def get_objects(object_class, query=nil)
object_class = object_class.classify.constantize
if query
objects = object_class.all.where(query).entries
else
objects = object_class.all.entries
end
if(!is_admin? || !is_manager?)
objects.delete_if{ |object|
(object.is_pending == true) && ((!object.send("#{object.class.to_s.underscore}_category").authed_users('fact_check').include?(current_user) rescue nil) || object.create_user_id!=current_user.id)
}
end
objects
end
end