Class: Orange::TestimonialsResource

Inherits:
ModelResource show all
Defined in:
lib/orange-more/testimonials/resources/testimonials_resource.rb

Instance Attribute Summary

Attributes inherited from ModelResource

#model_class

Instance Method Summary collapse

Methods inherited from ModelResource

#afterDelete, #afterSave, #beforeDelete, #beforeNew, #beforeSave, #create, #delete, #do_list_view, #do_view, #edit, #find_list, #find_one, #index, #list, #new, new, #onDelete, #onNew, #onSave, #save, #show, #table_row, use, #view, #view_opts

Methods inherited from RoutableResource

#routable, #route

Methods inherited from Resource

#afterLoad, call_me, #do_view, #find_extras, #init, #initialize, #options, #orange, #orange_name, #routable, #set_orange, set_orange, #view, #view_opts

Methods included from ClassInheritableAttributes

#cattr_accessor, #cattr_reader, #cattr_writer, eval_in_accessor_module, fetch_value, store_value

Constructor Details

This class inherits a constructor from Orange::Resource

Instance Method Details

#afterNew(packet, obj, params = {}) ⇒ Object



23
24
25
# File 'lib/orange-more/testimonials/resources/testimonials_resource.rb', line 23

def afterNew(packet, obj, params = {})
  obj.orange_site = packet['subsite'].blank? ? packet['site'] : packet['subsite']
end

#for_site(packet, opts = {}) ⇒ Object



27
28
29
30
31
32
33
34
35
# File 'lib/orange-more/testimonials/resources/testimonials_resource.rb', line 27

def for_site(packet, opts = {})
  site_filtered = model_class.all(:orange_site => packet['subsite'].blank? ? packet['site'] : packet['subsite'])
  if site_filtered.count > 0
    site_filtered
  else
    # Return unfiltered if no site-specific ones
    model_class.all
  end
end

#stack_initObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/orange-more/testimonials/resources/testimonials_resource.rb', line 5

def stack_init
  orange[:admin, true].add_link("Content", :resource => @my_orange_name, :text => 'Testimonials')
  orange[:radius].define_tag "testimonials" do |tag|
    packet = tag.locals.packet
 	  if tag.attr["tag"] && for_site(packet).with_tag(tag.attr["tag"]).count >0
      m = for_site(packet).with_tag(tag.attr["tag"]).first(:offset => rand(for_site(packet).with_tag(tag.attr["tag"]).count)) #selects testimonial based on tag
   elsif for_site(packet).count > 0 && !tag.attr.include?("tag")
  	  m = for_site(packet).first(:offset => rand(for_site(packet).count)) #selects a random testimonial
   end
    unless m.nil?
      template = tag.attr["template"] || "testimonials"
      orange[:testimonials].testimonial(packet, {:model => m, :template => template})
    else
      ""
    end
  end
end

#testimonial(packet, opts = {}) ⇒ Object



37
38
39
40
# File 'lib/orange-more/testimonials/resources/testimonials_resource.rb', line 37

def testimonial(packet, opts = {})
  template = opts[:template].to_sym || :testimonials
  do_view(packet, template, opts)
end