Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Try Vanilla Forums Cloud product

Nice Module!

This discussion is related to the Birthday Module addon.
R_JR_J Cheerleader & TroubleshooterMunich Moderator

I like the idea very much and - don't ask me why - have taken a look at the code (always eager to learn).

At first I didn't understood what's happening at Gdn::Set and Gdn:Get but then I understood that you are using the cache to store todays birthdays, which is a great idea, so that the db doesn't need to be queried all the time. Hopefully I can use that in one of my plugins B)

I was surprised you've not used the query builder. I would have filtered out the system user already in the sql like that (and inserted a Today var)

    protected function GetBirthdays() {
        $Birthdays = json_decode(Gdn::Get('BirthdayModule.Birthdays'));
        $Today = date('Y-m-d');
        if ($Birthdays && $Birthdays[0] == $Today) {
            return $Birthdays[1];
        }
        $Birthdays = Gdn::SQL()
            ->Select('UserID')
            ->From('User')
            ->Where('UserID <>', Gdn::UserModel()->GetSystemUserID())
            ->Where('DateOfBirth', $Today)
            ->Get()
            ->Result(DATASET_TYPE_ARRAY);
        $Birthdays = ConsolidateArrayValuesByKey($Birthdays, 'UserID');
        Gdn::Set('BirthdayModule.Birthdays', json_encode(array($Today, $Birthdays)));
        return $Birthdays;
    }

Actually, that's lie: I would have forgotten the system user ;)

YougeenBleistivt

Comments

  • R_JR_J Cheerleader & Troubleshooter Munich Moderator

    By the way: if you really think another plugin is needed (ProfileExtender in this case) you can add 'RequiredPlugins' => array('ProfileExtender' => '3.0'), to your PluginInfo array. But I guess you already knew that and I think it is better to not use it in this context, because DateOfBirth is a standard column and ProfileExtender is only one way to fill that column.

    And another "By the way": since I'm hanging around here, I've been wondering why there are no new developers/active community members/plugin contributors joining this community. Glad you are here at last :D

  • Thanks for the suggestions!

    I used a "raw" query as I needed DATE_FORMAT to filter out the year (otherwise it will only work on the actual date of birth ;) )
    But I could use Where() with the third and fourth parameter to prevent escaping, so it was probably just lazyness.
    Will use the query builder in the next revision.

    Another thing I would like to incorporate is birthdays on the 29.2.

    Right now it shows the birthdays in GMT, which is not really a problem for my community, as the users are all based in GMT+1, but in other timezones it can be up to 12 hours off.

    I thought about using Garden.GuestTimeZone, but that might not be set on every vanilla installation.
    It would be ideal to use the Houroffset to calculate the birthday for every user individually, but that would make the query overly complex :/

    My themes: pure | minusbaseline - My plugins: CSSedit | HTMLedit | InfiniteScroll | BirthdayModule | [all] - PM me about customizations

    R_J
  • R_JR_J Cheerleader & Troubleshooter Munich Moderator

    @Bleistivt said:
    I used a "raw" query as I needed DATE_FORMAT to filter out the year (otherwise it will only work on the actual date of birth ;) )

    Doh! And I thought my solution was elegant :lol:

    I also spent a few moments on thinking about different time zones, but you would have to cache each query by timezone which might simply be to much work for a simple module.

  • hgtonighthgtonight ∞ · New Moderator

    I am wondering why you put the birthday cache on the controller rather than in the module itself.

    Setting it in the data portion of the controller makes it visible in the json/xml view. Something to consider. That is my only concern.

    Nice idea and implemented pretty cleanly. :)

    Search first

    Check out the Documentation! We are always looking for new content and pull requests.

    Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.

    BleistivtShadowdare
  • vrijvlindervrijvlinder Papillon-Sauvage MVP

    Would be nice to have something like that here... no one said happy b day to me last time.. :(

  • whu606whu606 I'm not a SuperHero; I just like wearing tights... Moderator

    @vrijvlinder‌

    Are you Yaya Toure in disguise? ;)

    vrijvlinder
  • vrijvlindervrijvlinder Papillon-Sauvage MVP
Sign In or Register to comment.