ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Limiting member gallery entries per day (a PHP input / output / shake it all about problem)

December 18, 2007 8:34pm

Subscribe [2]
  • #1 / Dec 18, 2007 8:34pm

    Simon Rudkin

    51 posts

    Hi -

    I’m trying to limit members to making one gallery entry per day (using the Solspace Gallery Extended Module). Here’s my (il)logic: -

    Get the current logged-in member: -

    <?php
    global $SESS;
    $user_id = $SESS->userdata['member_id'];
    ?>

    Get the most recent gallery entry from that member: -

    {exp:query sql="SELECT * FROM exp_gallery_entries WHERE author_id = '<?php echo $user_id;?>' ORDER BY entry_date DESC LIMIT 1"}

    Compare the entry date of the most recent gallery entry plus a day to the current time: -

    <?php if ('{entry_date format="%U"}+86400' > time ()) { echo "This entry is less than one day old, you can't post another" ; } ?>
    {/exp:query}

    Problem is, it’s not working. I’m guessing this is because I’ve got PHP on input to get the current logged-in member, and the date comparison code needs to be on output. But how to set this up in terms of PHP input/output and embeds is blowing my already frazzled pre-Christmas brain…

    ...anybody want to be the star on top of my tree?

  • #2 / Dec 19, 2007 10:02am

    Simon Rudkin

    51 posts

    A good night’s sleep fixed my frazzled brain; going pure PHP sorted out my problem: -

    <?php
    global $SESS;
    $user_id = $SESS->userdata['member_id'];
    
    global $DB;
    $query = $DB->query("SELECT entry_date, author_id FROM exp_gallery_entries WHERE author_id  = '$user_id' ORDER BY entry_date DESC LIMIT 1");
    $myDate = $query->row['entry_date'];
    ?>
    
    <?php
        if (time() - $myDate < 86400) {
            echo "This entry is less than one day old.";
        }
    ?>

    Guess I’m going to be sitting on top of my own Christmas tree, so to speak!

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases