Mysidia Adoptables Support Forum  

Home Community Mys-Script Creative Off-Topic
Go Back   Mysidia Adoptables Support Forum > Mysidia Adoptables > Questions and Supports

Reply
 
Thread Tools Display Modes
  #1  
Old 11-11-2014, 11:19 PM
Kyttias's Avatar
Kyttias Kyttias is offline
Premium Member
 
Join Date: Jan 2014
Posts: 840
Gender: Unknown/Other
Credits: 35,653
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. I cannot offer tech support on any coding I've done prior to 2018.

Last edited by Kyttias; 11-11-2014 at 11:29 PM.
Reply With Quote
  #2  
Old 11-12-2014, 06:06 AM
IntoRain's Avatar
IntoRain IntoRain is offline
Moderator
 
Join Date: Jul 2013
Location: Portugal
Posts: 461
Gender: Female
Credits: 14,413
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 06:11 AM.
Reply With Quote
  #3  
Old 11-12-2014, 03:03 PM
Kyttias's Avatar
Kyttias Kyttias is offline
Premium Member
 
Join Date: Jan 2014
Posts: 840
Gender: Unknown/Other
Credits: 35,653
Kyttias is on a distinguished road
Default

*high fives* Beautiful teamwork, IntoRain! Thanks again~

I want to test out a few more things, get those additions added in, and then once that's done I'll write up a cleaner post here... and once I get the adminCP version working, I'll release it as an actual mod in a thread in the proper area.

I actually wrote up quite a fun list of features I want last night, since it all seems within my grasp now. There's a lot of new data I'd like to be collecting from user activities, so I may in fact be making my own table afterall.

:: plans of more data to track ::
total sitewide interactions (pet visits) (weekly)
total individual user interactions (pet visit) (daily, each day, weekly)
total number of pound rescues by individual user (ever)
total amount of currency spent by all users (weekly)
total amount of currency spent by individual user (ever)
total owned adoptables (user and sitewide, ever)
most owned (popular) adoptable (user and sitewide, currently)

Part of it's just displaying fun facts so the admin has a view of their site's progression (as in, these would be great stats to show on the opening page of the adminCP, especially if totals are tracked daily! could make a cute chart~), but these things can also be put to real use in regards to rewarding the community for being active (in a way extremely similar to my opening post - timestamping!).
__________________
Please do not contact me. I cannot offer tech support on any coding I've done prior to 2018.

Last edited by Kyttias; 11-12-2014 at 03:05 PM.
Reply With Quote
  #4  
Old 11-12-2014, 10:07 PM
IntoRain's Avatar
IntoRain IntoRain is offline
Moderator
 
Join Date: Jul 2013
Location: Portugal
Posts: 461
Gender: Female
Credits: 14,413
IntoRain is on a distinguished road
Default

Happy to help! :D good luck with the rest of the mod, it looks very interesting!
__________________


asp.net stole my soul.
Reply With Quote
  #5  
Old 11-15-2014, 02:39 PM
Hall of Famer's Avatar
Hall of Famer Hall of Famer is online now
Administrator, Lead Coder
 
Join Date: Dec 2008
Location: Somerville
Posts: 4,388
Gender: Male
Credits: 126,221
Hall of Famer is on a distinguished road
Default

So how does this one go now? Are you encountering some issues?
__________________


Mysidia Adoptables, a free and ever-improving script for aspiring adoptables/pets site.
Reply With Quote
  #6  
Old 11-17-2014, 11:24 PM
Kyttias's Avatar
Kyttias Kyttias is offline
Premium Member
 
Join Date: Jan 2014
Posts: 840
Gender: Unknown/Other
Credits: 35,653
Kyttias is on a distinguished road
Default

Well I got some work done re-factoring the code. I've made the timestamps down to the hour:min:sec, created a table just for bonus data, and made it an independent function/method.

-

New instructions (so far) are as follows:

Open phpMyAdmin to access your MySQL database. Open up the database for Mysidia. On the left hand side there should be a long list of tables for Mysidia, with the prefix that you put in during your initial install. The default prefix is adopts_. If your prefix is different, you will want to change it in two places in the code below.

Now, look to right side, at the top. The second tab, between Structure and Search, should be SQL. Open this up, and paste in the following code to run, then press "Go".
Code:
CREATE TABLE IF NOT EXISTS `adopts_kyt_bonuses` (
  `id` int(10) unsigned NOT NULL,
  `bonus_name` varchar(20) NOT NULL,
  `bonus_type` varchar(20) NOT NULL,
  `status` varchar(5) NOT NULL,
  `amount` varchar(20) NOT NULL,
  `timestamp` varchar(20) NOT NULL,
  `expiration` varchar(20) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

INSERT INTO `adopts_kyt_bonuses` (`id`, `bonus_name`, `bonus_type`, `status`, `amount`, `timestamp`, `expiration`) VALUES (1, 'Bonus1', 'Type1', 'off', '2', '2014-11-17 16:33:07', '2014-11-18 17:06:41');

INSERT INTO `adopts_kyt_bonuses` (`id`, `bonus_name`, `bonus_type`, `status`, `amount`, `timestamp`, `expiration`) VALUES (2, 'Bonus2', 'Type2', 'off', '6', '2014-11-17 21:49:59', '2014-11-18 22:23:33')
This created two example bonuses, one for each type. Type1 is based on the total site interactions made today. For example, if there's been a total of at least 5 interactions, the bonus kicks in. Type2 is based on interactions made since the last timestamp was marked down. For example, when the community has made at least 100 interactions, regardless of how long it took them, a bonus kicks in. Bonuses last for 24 hours.

You will now be able to find the table we created, adopts_kyt_bonuses, in the list on the left. If you open it up, you should see a table that looks like this:



*Disclaimer: Sometimes I'll be calling things functions, other times I'll be referring to things as methods. However, methods are just functions found inside a class. *thumbs up*

Onward! Open up ~/classes/class_template.php. We're going to be creating a new method called checkCommunityBonuses(). To start, we'll add it to the method used to construct the template, that way it knows to run. If you haven't modified this file, in version 1.3.4, you'll find public function __construct(Path $path) at around line 62. Inside this method that constructs the template, after the list of other functions it knows it needs to run, add in:
PHP Code:
$this->checkCommunityBonuses(Bonus1);
$this->checkCommunityBonuses(Bonus2); 
Next, we'll be creating our method properly. After the closing bracket for the construction method, you can paste in the following code:
PHP Code:
    public function checkCommunityBonuses($bonus_name){
        
$mysidia Registry::get("mysidia");
        
$now = new DateTime(); 
        
$today $now->format('Y-m-d H:i:s');

        
# The name of the bonus.
        
$bonus_name $bonus_name;
        
# This is the amount of interactions needed for the effect to kick in.
        
$amount $mysidia->db->select("kyt_bonuses", array("amount"), "bonus_name = '$bonus_name'")->fetchColumn();
        
# This is the type of bonus that this is.
        
$bonus_type $mysidia->db->select("kyt_bonuses", array("bonus_type"), "bonus_name = '$bonus_name'")->fetchColumn();
        
# Moving on, let's get the status... is the effect on or off?
        
$effect_status $mysidia->db->select("kyt_bonuses", array("status"), "bonus_name = '$bonus_name'")->fetchColumn();

        
# Inside kyt_bonuses, fetch the value in the timestamp column where the bonus_name column holds of a value of '$bonus_name'.
        
$timestamp $mysidia->db->select("kyt_bonuses", array("timestamp"), "bonus_name = '$bonus_name'")->fetchColumn();
        
# Convert this to a timestamp PHP can play with.
        
$time date("Y-m-d H:i:s"strtotime($timestamp));
        
# This is so we can find out what day is tomorrow.
        
$oneday strtotime('+1 day');
        
# And now we math...
        
$new_expiration date("Y-m-d H:i:s"$time $oneday);
        
# So, has the timestamp expired? We better check.
        
$timestamp_expiration $mysidia->db->select("kyt_bonuses", array("expiration"), "bonus_name = '$bonus_name'")->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 in the 'status' column to 'off'
            
$mysidia->db->update("kyt_bonuses", array("status" => 'off'), "bonus_name = '$bonus_name'");
            
#Let's reset the timestamp.
            
$mysidia->db->update("kyt_bonuses", array("timestamp" => $today), "bonus_name = '$bonus_name'");
        }

        
# Inside vote_voters, count how many rows have {$today} in their date column.
        
$interactions_today $mysidia->db->select("vote_voters", array(), "date = '{$now->format('Y-m-d')}'")->rowCount();
        
# Now count how many interactions have happened since the timestamp went into effect.
        
$ts date("Y-m-d"strtotime($timestamp)); // This is regathering the timestamp in a form the vote_voters can understand.
        
$interactions_since_timestamp $mysidia->db->select("vote_voters", array(), "date between '{$ts}' and '{$today}'")->rowCount();  

        
/*** BONUS TYPE 1 ***/
        
if ($bonus_type == "Type1"){ //Type1 is based on interactions made today.
           # So, if the effect is on, should it be?
            
if ($effect_status == 'on'){ 
                if (
$interactions_today $amount){ // No
                    # Why is this even on? turn it off!
                    
$mysidia->db->update("kyt_bonuses", array("status" => 'off'), "bonus_name = '$bonus_name'");     
                }
                if (
$interactions_today >= $amount){ // Yes
                    // 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?
            
if ($effect_status == 'off') {
                if (
$interactions_today $amount){ // No
                    # Great, stay off.
                    
$mysidia->db->update("kyt_bonuses", array("status" => 'off'), "bonus_name = '$bonus_name'"); 
                }
                if (
$interactions_today >= $amount) {  // Yes
                    # Great, turn it on.
                    
$mysidia->db->update("kyt_bonuses", array("status" => 'on'), "bonus_name = '$bonus_name'");
                    
#Let's reset the timestamp.
                    
$mysidia->db->update("kyt_bonuses", array("timestamp" => $today), "bonus_name = '$bonus_name'");
                    
# And make sure the timestamp knows when it should expire!
                    
$mysidia->db->update("kyt_bonuses", array("expiration" => $new_expiration), "bonus_name = '$bonus_name'");
                }
            }
          
        } 
// end type1

        /*** BONUS TYPE 2 ***/
        
if ($bonus_type == "Type2"){ //Type2 is based on interactions since the timestamp last rolled over.
            # So, if the effect is on, should it be?
            
if ($effect_status == 'on'){
                if (
$interactions_since_timestamp $amount){ // No
                    # Why is this even on? Turn it off!
                    
$mysidia->db->update("kyt_bonuses", array("status" => 'off'), "bonus_name = '$bonus_name'"); 
                }
                if (
$interactions_since_timestamp >= $amount){ // Yes
                    // 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?
            
if ($effect_status == 'off'){
                if (
$interactions_since_timestamp $amount){ // No
                    # Great, stay off.
                    
$mysidia->db->update("kyt_bonuses", array("status" => 'off'), "bonus_name = '$bonus_name'"); 
                }
                if (
$interactions_since_timestamp >= $amount){ // Yes
                    # Great, turn it on.
                    
$mysidia->db->update("kyt_bonuses", array("status" => 'on'), "bonus_name = '$bonus_name'");
                    
#Let's reset the timestamp.
                    
$mysidia->db->update("kyt_bonuses", array("timestamp" => $today), "bonus_name = '$bonus_name'");
                    
# And make sure the timestamp knows when it should expire!
                    
$mysidia->db->update("kyt_bonuses", array("expiration" => $new_expiration), "bonus_name = '$bonus_name'"); 
                }
            }

        } 
// end type2

        # And let's get an update on the effect status, time stamp, and expiration...
        
$effect_status $mysidia->db->select("kyt_bonuses", array("status"), "bonus_name = '$bonus_name'")->fetchColumn();
        
$timestamp $mysidia->db->select("kyt_bonuses", array("timestamp"), "bonus_name = '$bonus_name'")->fetchColumn();
        
$timestamp_expiration $mysidia->db->select("kyt_bonuses", array("expiration"), "bonus_name = '$bonus_name'")->fetchColumn(); 

        
# This is a smarty variable of {$timestamp_data}, for a visual read out of the data, and can be placed any where in the main theme template file.
        
$this->assign("timestamp_data","Bonus Effect: {$bonus_name}</br> Effect Status: {$effect_status} <br/> Current Timestamp: {$timestamp} <br/> Expiration On: {$timestamp_expiration} <br/> Interactions Today: {$interactions_today} <br/> Interactions Since Timestamp: {$interactions_since_timestamp}");
        
# This is a smarty variable of {$interactionstoday} that will just show how many interactions have happened today.
        
$this->assign("interactionstoday","Interactions Today: {$interactions_today}");

    } 
// end community bonus check 
Now is find a place in your theme's template.tpl to store {$timestamp_data}, just like you would the {$sidebar} or {$footer}, to see it working. To display just the total amount of interactions made today somewhere, you can use {$interactionstoday}.

Assuming IntoRain's modification to levelup.php mentioned in a post above works out just fine (replacing of course the line linking to the effect in the database), we'll be doing something similar to that. Exact instructions for this part aren't written up yet, aha.

-

Things I need help with now:

1 - You'll see that in the construct method for the template I'm calling the checkCommunityBonuses() function I made with a parameter holding the bonus name. Obviously not ideal at this point! I need to make another function that pulls from the database the number of bonuses that exist, loop through them, and then call checkCommunityBonuses() for each of them. ( And it's much too late tonight for my brain to want to do that.)

2 - H-how do I make Smarty variables with a variable in the name? *nervous laugh* I left the code in there from last time (give or take a few tweaks) but it'll only pull up data from the last bonus it came across, I'm sure. I want to make an admin panel here, so telling users they have to go in and make these variables by hand is... not ideal. Obviously, they'll want to be able to customize the contents of these -- rather than reading off hard data they could put in an image and a tooltip to represent the bonus being on or off.

3 - So. New settings to add the AdminCP... Man, would I appreciate some pointers here. I'll figure it out later given enough time, but I don't have any specific questions right now because I haven't even begun to peer down that rabbit hole. This is on my to-do list...

4 - The modifications to levelup.php - so, what if we've got multiple bonuses going on? And, what if I create room in the database for the bonus clicks and currency so users can do that in the adminCP? I don't know how many bonuses a site owner might create, but I would know their settings for bonus clicks and currency, then.

5 - Eh, should I just forgo the adminCP business, since there's going to be so much to do by hand, anyway?
__________________
Please do not contact me. I cannot offer tech support on any coding I've done prior to 2018.
Reply With Quote
  #7  
Old 11-19-2014, 02:46 PM
IntoRain's Avatar
IntoRain IntoRain is offline
Moderator
 
Join Date: Jul 2013
Location: Portugal
Posts: 461
Gender: Female
Credits: 14,413
IntoRain is on a distinguished road
Default

Sorry, I've been busy lately and couldn't reply earlier x.x

When creating a table, you can set your ID to be a primary key and auto_increment. That way you don't need to add an id manually when inserting a new row, it will increment the ID's for you

Quote:
Originally Posted by Kyttias View Post
Things I need help with now:

1 - You'll see that in the construct method for the template I'm calling the checkCommunityBonuses() function I made with a parameter holding the bonus name. Obviously not ideal at this point! I need to make another function that pulls from the database the number of bonuses that exist, loop through them, and then call checkCommunityBonuses() for each of them. ( And it's much too late tonight for my brain to want to do that.)
You might want to reduce the number of times you query your database. Since you need all columns anyway, instead of doing a select() for each columns, you can just get the full row instead with a single query.


So, basically you can call your function like this:

PHP Code:
        //obtain all rows
        
$all_bonuses $mysidia->db->select("kyt_bonuses", array(), "");

    
//for each row    
    
while($bonus $all_bonuses->fetchObject()){
                
//run this function
        
$this->checkCommunityBonuses($bonus);
    } 
Then inside the function you can do it like this:

PHP Code:
    private function checkCommunityBonuses($bonus){
            
//bonus_name, amount, etc... are what the columns are called in the database
        
$bonus_name $bonus->bonus_name;
        
$amount $bonus->amount;
        
$bonus_type $bonus->bonus_type;
        
$effect_status $bonus->status;
        
$timestamp $bonus->timestamp;
        
$timestamp_expiration $bonus->expiration;
(...)
    } 

Quote:
Originally Posted by Kyttias View Post
2 - H-how do I make Smarty variables with a variable in the name? *nervous laugh* I left the code in there from last time (give or take a few tweaks) but it'll only pull up data from the last bonus it came across, I'm sure. I want to make an admin panel here, so telling users they have to go in and make these variables by hand is... not ideal. Obviously, they'll want to be able to customize the contents of these -- rather than reading off hard data they could put in an image and a tooltip to represent the bonus being on or off.
You want to pass all bonuses into a Smarty variable? You can pass arrays too and go through each element (in this case, it would be all_bonuses instead of this->messages). Here's an example I did some time ago, to display the 3 latest unread messages:

assigning:

PHP Code:
$this->messages $mysidia->db->select("messages", array(), "touser='{$mysidia->user->username}' and status='unread' ORDER BY id DESC LIMIT 3")->fetchAll();

//I'm assigning an array with at most 3 messages (3 rows)
$mysidia->template->assign("messages",$this->messages); 
template.tpl:

PHP Code:
<!-- Iterate through the messages array -->
                {foreach 
from=$messages item=message}
                <
li class="message-preview">
                  <
a href="/messages/read/{$message.id}">
                    <
span class="name">{$message.fromuser}:</span>
                    <
span class="message">{$message.messagetitle}</span>
                    <
span class="time"><class="fa fa-clock-o"></i> {$message.datesent}</span>
                  </
a>
                </
li>
                <
li class="divider"></li>
                {/foreach} 
Quote:
Originally Posted by Kyttias View Post
3 - So. New settings to add the AdminCP... Man, would I appreciate some pointers here. I'll figure it out later given enough time, but I don't have any specific questions right now because I haven't even begun to peer down that rabbit hole. This is on my to-do list...
The AdminCP works like the normal pages: It has a controller and a view, which you need to create to make a new page. In the controller you do the checking and database access, in the view you do the display. Basically, you display a form to edit whatever you need from the database and a button to submit. In the controller, after submiting, you get the values filled by the user and do a database update.
I can be more specific when you go into making the admincp pages ^^

Quote:
Originally Posted by Kyttias View Post
4 - The modifications to levelup.php - so, what if we've got multiple bonuses going on? And, what if I create room in the database for the bonus clicks and currency so users can do that in the adminCP? I don't know how many bonuses a site owner might create, but I would know their settings for bonus clicks and currency, then.
It might be better to define specific types of bonuses, instead of letting the users create the bonuses themselves. Instead, you can let the user "activate" the bonuses they want to use and the amounts. Because there are bonuses like click and currency that go into levelup.php, and other bonuses that go in other pages, depending on what they change. This way, in each page that might suffer changes from bonuses, you just need to check if the site admin is using that bonus and if they are, do the normal checking.

Quote:
Originally Posted by Kyttias View Post
5 - Eh, should I just forgo the adminCP business, since there's going to be so much to do by hand, anyway?
I advise just finishing the feature itself and worrying about the admincp after you have everything finished. As long as the values are in the database, it should be simple to find a way to change them ^^
__________________


asp.net stole my soul.
Reply With Quote
  #8  
Old 12-29-2016, 10:05 PM
parayna's Avatar
parayna parayna is offline
Member
 
Join Date: May 2013
Location: Devon, UK
Posts: 312
Gender: Female
Credits: 8,746
parayna is on a distinguished road
Default

Wow.. I know this is 2 years late but this seems like an absolutely brilliant way of rewarding users... was it ever finished, or progressed further than this? It would be amazing if a mod like this came out sometime!
Reply With Quote
Reply

Tags
bonus, clicks, community, interaction, mod

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
The community here is brilliant! CallumCharlton Newcomer Center 3 03-11-2015 10:29 AM
Opinions on Progress RoconzaArt Art Gallery 9 01-20-2011 11:38 PM
Which is best open source community software? chriskrich878 Other Chat 3 11-23-2010 10:06 PM
Still a work in Progress MyBBSkinz Adoptables Sites Showcase 7 08-31-2008 08:13 AM
Urm Yeah mybb community forums Ajof Other Chat 5 06-29-2008 04:12 PM


All times are GMT -5. The time now is 11:47 PM.

Currently Active Users: 214 (1 members and 213 guests)
Threads: 3,942, Posts: 31,405, Members: 15,530
Welcome to our newest members, ancrsbys01.
BER





What's New?

What's Hot?

What's Popular?


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2018, vBulletin Solutions Inc.
vBCommerce I v2.0.0 Gold ©2010, PixelFX Studios
vBCredits I v2.0.0 Gold ©2010, PixelFX Studios
Emoticons by darkmoon3636