We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Sponsors of the Day - Best practices for implementation?

Development and Programming

jay_turley's avatar
jay_turley
46 posts
10 years ago
jay_turley's avatar jay_turley

Requirement

The home page of a site needs to have three “sponsors of the day”. The sponsors of the day should be changed every 24 hours. Sponsors of the day are to be drawn from the “sponsors” channel at random. Every entry in the “sponsors” channel must be used as a sponsor of the day once before any entries can be re-used as sponsors of the day.

Plan

So, my plan is to do the following (pseudo code so don’t worry about names and values, please):

1) Add two “hidden” fields to the sponsors channel fields: “current_sotd”, and “was_sotd”,

2) Add one “hidden” field to the pages channel fields: “sotd_set_date”,

3) At every load of the home page, check to see if the sotd_set_date is more than 24 hours ago, and if so:

3a) Set sotd_set_date to the current datetime,
3b) Set all sponsors entries current_sotd to NO,
3c) Select 3 new sponsor entries, 1 at a time, that have was_sotd set to NO, and set each current_sotd to YES
3d) As each is selected, if 0 sponsor entries have was_sotd set to NO, reset all sponsor entries to was_sotd to NO

I realize this means enabling PHP on my home page template, and writing some custom PHP/SQL.

My question is: Is there in fact a better, more EE way to approach this requirement? Is there some feature or functionality of EE that I am not seeing or understanding due to my lack of experience?

       
jay_turley's avatar
jay_turley
46 posts
10 years ago
jay_turley's avatar jay_turley

Once again, I am happy to reply to my own post for posterity.

I plan to create an embedded template called “sponsors-of-the-day” and then cache it for 24 hours.

This means I only need the custom code to change these sponsors every 24 hours, which means only one extra “hidden” field on the sponsors channel to track if they have been used yet.

It seems like caching is more in the spirit of EE/CMS.

Still, if anyone has any further suggestions…

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.