View Single Post
  #2  
Old 11-12-2014, 05:06 AM
IntoRain's Avatar
IntoRain IntoRain is offline
Moderator
 
Join Date: Jul 2013
Location: Portugal
Posts: 461
Gender: Female
Credits: 19,353
IntoRain is on a distinguished road
Default

Interesting! I will try to answer what I can!

Quote:
Originally Posted by Kyttias View Post
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.
The 'where' part of that query goes to the last argument of mysidia's query function, you can do it like this:

PHP Code:
$timestamp='2014-09-17';
$now = new DateTime(); 
$today $now->format('Y-m-d');
$total_interacts $mysidia->db->select("vote_voters", array(), "date between '{$timestamp}' and '{$today}'")->rowCount(); 
Quote:
Originally Posted by Kyttias View Post
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?
If you want them to disappear after 24 hours from their creation, you have to store the date and the time when the effect turned on, not just the date

PHP Code:
$now = new DateTime();  
$effect_turned_on_at $now->format('Y-m-d H:i:s');//date + time                 
//add 24 hours: http://php.net/manual/en/dateinterval.construct.php        
$now->add(new DateInterval('PT24H'));  
$expires_at $now->format('Y-m-d H:i:s'); 
Quote:
Originally Posted by Kyttias View Post
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.
Since you store if the effect is on or off, you can select the value from the database in those pages and use it to apply your desired effect. For example, the boost to money yield and clicks:

levelup.php - click()

PHP Code:
/* Conditions for boosts below */

$bonus_clicks 0;
$bonus_money 0;
$effect $mysidia->db->select("levels_settings", array("value"), "name = 'ts'")->fetchColumn();
        
if(
$effect == 'on'){
    
$bonus_clicks 3;
    
$bonus_money 500;
}
/* Conditions for boosts above */

//these lines already exist in the function:
$newClicks $this->adopt->getTotalClicks() + $bonus_clicks
(...)
$reward $mysidia->user->clickreward($this->settings->reward) + $bonus_money
Quote:
Originally Posted by Kyttias View Post
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.
I think it looks fine. Regarding giant functions:
Since this will take a few lines, I'd move the code you already have in assignTemplateVars() to a separate private function but in the same file and call that function somewhere inside assignTemplateVars(). This is just for organization though, separating big functions into smaller ones makes the code more readable (Code Refactoring - Method Extraction)

I'd also use && instead of 'and' xD

Number 5, you can create a new settings page just for those or add those settings to an existing page too. Add the fields you want (range of days? bonuses?) to a form then after submiting it update the database with those values
If it gets to a point where you want to define many different bonuses (money, clicks, discounts...), maybe create a new table just for those bonuses?

Number 6, I can't really help with sorry :/
__________________


asp.net stole my soul.

Last edited by IntoRain; 11-12-2014 at 05:11 AM.
Reply With Quote