View Single Post
  #7  
Old 11-19-2014, 01:46 PM
IntoRain's Avatar
IntoRain IntoRain is offline
Moderator
 
Join Date: Jul 2013
Location: Portugal
Posts: 461
Gender: Female
Credits: 19,260
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