Guest User

Untitled

a guest
Feb 21st, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. Sq::ScheduledContent.all.each do |sc|
  2. present_count = 0
  3. un_present_count = 0
  4. sc.groups.each do |g|
  5. g.learners.each do |u|
  6. if sc.content_type.present?
  7. d = "User#{sc.content_type.sub('Sq::', '')}"
  8. user_con = "#{sc.content_type}::#{d}".constantize.where(scheduled_content_id: sc.id, user_profile_id: u.id).first
  9. if user_con.nil?
  10. con = sc.content_type.sub('Sq::', '').underscore.downcase
  11. if (sc.featured_on > Time.now) || (sc.featured_on < Time.now && sc.expires_on > Time.now)
  12. "#{sc.content_type}::#{d}".constantize.collection.insert_one(scheduled_content_id: sc.id, user_profile_id: u.id, status: 'featured', "#{con}_id": sc.content_id)
  13. elsif (sc.featured_on < Time.now && sc.expires_on < Time.now)
  14. "#{sc.content_type}::#{d}".constantize.collection.insert_one(scheduled_content_id: sc.id, user_profile_id: u.id, status: 'pending', "#{con}_id": sc.content_id)
  15. end
  16. elsif user_con.present?
  17. "#{sc.content_type}::#{d}".constantize.skip_callback(:save, :before, :update_timestamp)
  18. if (sc.content.expires_on < Time.now)
  19. user_con.update_attributes(status: "pending_archieved")
  20. elsif (user_con.started_archieved == "started")
  21. user_con.update_attributes(status: "started_archieved")
  22. end
  23. "#{sc.content_type}::#{d}".constantize.set_callback(:save, :before, :update_timestamp)
  24. end
  25. end
  26. end
  27. end
  28. end
Add Comment
Please, Sign In to add comment