View Single Post
  #1  
Old 11-11-2014, 10:19 PM
Kyttias's Avatar
Kyttias Kyttias is offline
Premium Member
 
Join Date: Jan 2014
Posts: 857
Gender: Unknown/Other
Credits: 88,080
Kyttias is on a distinguished road
Arrow Mod In Progress - Community Interaction Bonuses

And by interactions, I mean visiting/clicking adoptables. To encourage user participation and interest in others, of course! When site-wide a grand total of x interactions has been in a day, everyone will reap the benefits!

Bare with me on my rambling... this is just a feature I want, and I'm a ways off from fully implementing it, so I'm using this space to jot down some pseudo-code. It's all hypothetical at this point, but with some feedback, this will become a rather nice mod.

Please don't attempt to follow my instructions unless you've read through them and somewhat understand what you're doing. Only people who think they grasp what's going on and think they can attempt to help should continue. This is not a mod yet, and not production ready!

First, we set up space in the database (I'll be using the levels_settings table) to store timestamp and expiration date columns. (Feel free to replace the default with whatever today's date is. The format will be Y-m-d, for example, 2014-11-14.)
Code:
ALTER TABLE `adopts_levels_settings` ADD `timestamp` DATE NOT NULL DEFAULT '0000-00-00' ;
ALTER TABLE `adopts_levels_settings` ADD `expires` DATE NOT NULL DEFAULT '0000-00-00' ;
Now we'll add a row. As a test, my first one will have lsid of '8', since its the next id not taken, name of 'ts' and a value that says 'off'. You can fill the 'timestamp' and 'expire' dates with whatever today's date is. We'll make sure PHP can recognize it's associated timestamps as dates. I'll connect this to a PHP variable, $ts.

Using the following code, the day's total interactions made by all users will be tallied, and effect will turn on if this total is above a certain threshold (currently >=2). The effect will expire at midnight the day its timestamp turns on, and the effects (not currently supplied) will turn off. Again, currently, there is no actual effect taking place, just a placeholder, ready to take on some code to launch. But I do supply a way of rendering a quick check as to whether the system is working.

Conditions to activate and de-activate bonus effects will be checked on every page load. The code I'll supply below can go into class_template.php - since it will always run one each page. I've placed at the bottom of the inside of private function assignTemplateVars(). I'm sure there's better placement for all this, but... it's where I tend to test my code, ahaha.

PHP Code:
// Experimental
$now = new DateTime(); 
$today $now->format('Y-m-d');

# Inside levels_settings, fetch the value in the value column where the name is 'ts'.
$ts $mysidia->db->select("levels_settings", array("timestamp"), "name = 'ts'")->fetchColumn();
# Convert this to a timestamp PHP can play with.
$timestamp date("Y-m-d"strtotime($ts));
# This is so we can find out what day is tomorrow.
$oneday strtotime('+1 day');
# And now we math...
$expires date("Y-m-d"$timestamp $oneday);

# So, has the timestamp expired? We better check.
$timestamp_expiration $mysidia->db->select("levels_settings", array("expires"), "name = 'ts'")->fetchColumn();
# If the expiration date is greater than or equal to day, then yes, it's expired
if ($timestamp_expiration >= $today) { 
    
# Because the effect should expire now, we will turn it's value to 'off'
    
$mysidia->db->update("levels_settings", array("value" => 'off'), "name = 'ts'");
}

# Moving on, let's get the current effect status...
$effect_status $mysidia->db->select("levels_settings", array("value"), "name = 'ts'")->fetchColumn();
# If it's current on, let's do this~!
if ($effect_status == 'on'){
// Nothing yet, but we'll put in a function here - the true magic of the effect!
}

# Well, if the effect is off, are there are enough interactions for the effect to be turned on?
else if (($effect_status == 'off') and ($interactions_today >= 2)) { 
    
# Great, turn it on.
    
$mysidia->db->update("levels_settings", array("value" => 'on'), "name = 'ts'");
    
# Set the timestamp.
    
$mysidia->db->update("levels_settings", array("timestamp" => $today), "name = 'ts'");
    
# And make sure the timestamp knows when it should expire!
    
$mysidia->db->update("levels_settings", array("expires" => $expires), "name = 'ts'");
    
# Let's get an update on the effect status, time stamp, and expiration...
    
$effect_status $mysidia->db->select("levels_settings", array("value"), "name = 'ts'")->fetchColumn();
    
$ts $mysidia->db->select("levels_settings", array("timestamp"), "name = 'ts'")->fetchColumn();
    
$timestamp_expiration $mysidia->db->select("levels_settings", array("expires"), "name = 'ts'")->fetchColumn();
}

# This is a smarty variable, for a visual read out of the data, and can be placed any where in the main theme template file as {$timestamp_data}.
$this->assign("timestamp_data","Effect Status: {$effect_status} <br/> Current Timestamp: {$timestamp} <br/> Expires On: {$timestamp_expiration}"); 
All you have to do now is find a place in your template to store {$timestamp_data}, just like you would the {$sidebar} or {$footer} to see it working. It currently activates after 2 interactions have been made. Obviously that's just a silly low testing number.

Things I need help with now:

1 - I want more complicated requirements than just hitting a daily threshold that expires at midnight. I need to find the total number of interactions in a range of dates, between $timestamp and $today, for an effect that builds over several days worth of interactions until a threshold is finally met. Help constructing a database query that's a Mysidia equivalent to this query format would be nice.

2 - I also want effects to dismiss themselves if it is past exactly 24 hours from their creation, not just if it is the next day/past midnight. So I will need to change how I am storing the date format. Would anyone be willing to test this out for me?

3 - No function actually takes place, currently, but the possibilities could include temporary boosts such as increased currency yield from visiting adoptables, and for adoptables have an increased click (exp) rate from visits. More complex implementations might feature shop discounts or everyone receiving a bit of additional currency/an item. I would love some direction on how to make these happen, to speed this along into becoming an actual mod.

4 - I would love some general feedback on how to improve and optimize my existing code. Where it's stored, if it should all be in a giant function, and other tips and such.

5 - This sort of thing is best fine tuned to cater to the exact size of your site. If you expect a lot of interactions, you may want to set the bar high. If you're a new site, you'll want it to be quite low. Therefore, help implementing it into a feature that can be controlled from the admin panel would be amazing.

6 - I also need to know what versions of Mysidia this will/won't work with. I don't know just much has changed between versions, ahaha...
__________________
Please do not contact me directly outside of Mysidia.
I also cannot troubleshoot code more than two years old - I legit don't remember it.

Last edited by Kyttias; 11-11-2014 at 10:29 PM.
Reply With Quote