Mysidia Adoptables Support Forum  

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

Notices

Reply
 
Thread Tools Display Modes
  #1  
Old 12-05-2016, 10:25 PM
Dinocanid's Avatar
Dinocanid Dinocanid is offline
Member
 
Join Date: Aug 2016
Location: Maryland, USA
Posts: 516
Gender: Unknown/Other
Credits: 78,999
Dinocanid is on a distinguished road
Default (1.3.4) Banks

After over an hour of work and smashing the keyboard wondering why the forms weren't working correctly, I present to you:
banks!

-Step 0-
Go to phpMyAdmin, adopts_users, and create a new column with this info:
Code:
Name: bank
Type: int
Length/Values: 11
Default: As defined 0
check the null box
-Step 1-
Create a new page for your bank from scratch. If you don't know how to make pages from scratch go here. Do not create a new page from the admincp.
Create a file named bank.php in your root folder and add the following contents:
PHP Code:
<?php

class BankController extends AppController{

    public function 
__construct(){
        
parent::__construct("member");    
    }
    
    public function 
index(){
        
$mysidia Registry::get("mysidia");
    }
}
?>
Next, make a new file called bankview.php in your view folder with the following contents:
PHP Code:
 <?php
class BankView extends View{

    public function 
index(){
      
        
$mysidia Registry::get("mysidia");
        
$document $this->document;        
        
$document->setTitle("The Bank");  
        
$balance $mysidia->user->getbank();
        
        if (
$balance <= 0){
        
$document->add(new Comment("<h2>Current Balance: 0 CURRENCY</h2>"));
        }
        else 
$document->add(new Comment("<h2>Current Balance: {$balance} CURRENCY</h2>"FALSE));
        
$document->add(new paragraph);

if(
$mysidia->input->post("deposit")){
$amount $mysidia->input->post("amount");
$balance $mysidia->db->select("users", array("bank"))->fetchColumn();
$mysidia->user->changecash(-$amount);
$mysidia->user->changebank(+$amount);
$document->add(new Comment("<h2>You deposited {$amount} CURRENCY into your bank account</h2>"FALSE));
$document->add(new Comment("<br><a href='{$path}bank'>Return to Bank</a>  "FALSE));
return 
TRUE;}

$depositForm = new FormBuilder("depositForm""""post");
$depositForm->buildComment("Amount: "FALSE)
  ->
buildTextField("amount"FALSE)
  ->
buildButton("Deposit""deposit""submit");
        
$document->add($depositForm);
        
        
        
        
     if(
$mysidia->input->post("withdraw")){
$amount $mysidia->input->post("amount");
$balance $mysidia->db->select("users", array("bank"))->fetchColumn();
$mysidia->user->changecash(+$amount);
$mysidia->user->changebank(-$amount);
$document->add(new Comment("<h2>You withdrew $ {$amount} from your bank account</h2>"FALSE));
$document->add(new Comment("<br><a href='{$path}bank'>Return to Bank</a>  "FALSE));
return 
TRUE;}  

 
$withdrawForm = new FormBuilder("withdrawForm""""post");
$withdrawForm->buildComment("Amount: "FALSE)
  ->
buildTextField("amount"FALSE)
  ->
buildButton("Withdraw""withdraw""submit");
        
$document->add($withdrawForm);
    }
}
?>
-Step 2-
Now go to class_member.php and add this with the other public items:
PHP Code:
public $bank
Afterwards, add this with the rest of the functions:
PHP Code:
  public function changebank($amount){     
      
$mysidia Registry::get("mysidia");
      if(!
is_numeric($amount)) throw new Exception('Cannot change user money by a non-numeric value!');
      
      
$this->bank += $amount;    
      if(
$this->bank >= 0){ 
         
$mysidia->db->update("users", array("bank" => $this->bank), "username = '{$this->username}'");
         return 
TRUE;              
      }
      
///else throw new InvalidActionException("It seems that {$this->username} cannot afford this transaction.");
  

(The else function is commented out for now so the user avoids any errors. I'll clean it up when I find a way)

Next, go to class_user.php and add this with the other public things:
PHP Code:
public $bank
And this with the other functions:
PHP Code:
      public function getbank(){
     return 
$this->bank;

-End-
That should be it. Now users are able to add and withdraw from a bank account that holds their currency. As of right now, the user's money doesn't appear to go down until they go to another page and the balance doesn't appear to go up until they leave the page and come back. If anyone knows how to make it update right then and there, let me know!
Be sure to let your users know that if they refresh the bank page after depositing money then it will deposit the same amount again. The same goes for withdrawing money. A "confirm resubmission" popup appears on some browsers though (including chrome), which should help avoid accidents.
__________________

Last edited by Dinocanid; 12-07-2016 at 02:02 PM.
Reply With Quote
  #2  
Old 12-06-2016, 04:10 PM
Corsair's Avatar
Corsair Corsair is offline
Member
 
Join Date: Jan 2012
Posts: 128
Gender: Female
Credits: 13,304
Corsair is on a distinguished road
Default

Thank you for sharing! I tried it and it works perfectly.
Reply With Quote
  #3  
Old 12-06-2016, 06:02 PM
parayna's Avatar
parayna parayna is offline
Member
 
Join Date: May 2013
Location: Devon, UK
Posts: 342
Gender: Female
Credits: 22,577
parayna is on a distinguished road
Default

Ooh, this is interesting! Technically couldn't you make it so that after the withdraw or deposit it forwards you automatically to abother page that says a message? (Such as "Thank you for your deposit, we'll take good care of your *currency*!" Maybe a different page for withdrawing.) Then you'd see the currency update and also avoid refreshes. You could also include a "Return to bank" option so people can still do things in it. The button would just link you to the bank again instead of back a page. Just my thoughts ^_^ This would mean extra pages. .. but to avoid users potentially complaining I'd put up with that XD
Reply With Quote
  #4  
Old 12-06-2016, 06:18 PM
Dinocanid's Avatar
Dinocanid Dinocanid is offline
Member
 
Join Date: Aug 2016
Location: Maryland, USA
Posts: 516
Gender: Unknown/Other
Credits: 78,999
Dinocanid is on a distinguished road
Default

That does sound like it would cause less problems in the long run xD
It wouldn't take me very long to add either since I have much of the base done. I'll probably work on it tonight.
__________________
Reply With Quote
  #5  
Old 12-06-2016, 06:51 PM
parayna's Avatar
parayna parayna is offline
Member
 
Join Date: May 2013
Location: Devon, UK
Posts: 342
Gender: Female
Credits: 22,577
parayna is on a distinguished road
Default

Ok! ^_^ I have to say the bank will be such a great feature T-T Thanks XD So helpful to have XD
Reply With Quote
  #6  
Old 12-07-2016, 08:22 AM
Abronsyth's Avatar
Abronsyth Abronsyth is offline
A Headache Embodied
 
Join Date: Aug 2011
Location: NY
Posts: 1,011
Gender: Male
Credits: 133,206
Abronsyth is on a distinguished road
Default

You've actually set it up perfectly to add a little back button that will bring you back to the bank without refreshing. Just add this under comments for withdrawing and depositing:
PHP Code:
<br><a href='{$path}bank'>Return to Bank</a
Works splendidly, thank you for sharing!
__________________
My Mods Site (1.3.4, 2020 Mods)
Reply With Quote
  #7  
Old 12-07-2016, 09:15 AM
Hall of Famer's Avatar
Hall of Famer Hall of Famer is offline
Administrator, Lead Coder
 
Join Date: Dec 2008
Location: South Brunswick
Posts: 4,448
Gender: Male
Credits: 488,641
Hall of Famer is on a distinguished road
Default

Looks nice, congratulations. You may want to make this into a Mod/Plugin, if you can.
__________________


Mysidia Adoptables, a free and ever-improving script for aspiring adoptables/pets site.
Reply With Quote
  #8  
Old 12-07-2016, 01:15 PM
Dinocanid's Avatar
Dinocanid Dinocanid is offline
Member
 
Join Date: Aug 2016
Location: Maryland, USA
Posts: 516
Gender: Unknown/Other
Credits: 78,999
Dinocanid is on a distinguished road
Default

@HOF: Would I just post the updated version in the mods section? I'm not entirely sure how plugins work but I see a spot for it in the adminCP. Is it related to that?
@Abrosynth: It works perfectly, thanks! I'll add it in.
__________________
Reply With Quote
  #9  
Old 12-07-2016, 02:40 PM
Hall of Famer's Avatar
Hall of Famer Hall of Famer is offline
Administrator, Lead Coder
 
Join Date: Dec 2008
Location: South Brunswick
Posts: 4,448
Gender: Male
Credits: 488,641
Hall of Famer is on a distinguished road
Default

Yeah it will be good this way. If possible, upload modified files as attachment in your thread so users with fresh installation of Mysidia can just download/upload easily.
__________________


Mysidia Adoptables, a free and ever-improving script for aspiring adoptables/pets site.
Reply With Quote
  #10  
Old 12-09-2016, 09:13 PM
Ittermat's Avatar
Ittermat Ittermat is offline
The awesomesauce
 
Join Date: Feb 2016
Location: in front of my laptop
Posts: 272
Gender: Female
Credits: 38,526
Ittermat is on a distinguished road
Default

EDIT: NVM I was a ***** and forgot the table step...its been a long day



So I followed the instructions- but when I go to deposit money I get this error..

Fatal error: Uncaught exception 'Exception' with message 'Database error 1054 - Unknown column 'bank' in 'field list'' in /home/atrocity/public_html/classes/class_database.php:213 Stack trace: #0 /home/atrocity/public_html/classes/class_database.php(142): Database->_query('users', Array, 'select', NULL) #1 /home/atrocity/public_html/view/bankview.php(19): Database->select('users', Array) #2 /home/atrocity/public_html/classes/class_frontcontroller.php(100): BankView->index() #3 /home/atrocity/public_html/index.php(78): FrontController->render() #4 /home/atrocity/public_html/index.php(82): IndexController::main() #5 {main} thrown in /home/atrocity/public_html/classes/class_database.php on line 213

Last edited by Ittermat; 12-09-2016 at 09:20 PM.
Reply With Quote
Reply

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


All times are GMT -5. The time now is 12:59 PM.

Currently Active Users: 985 (0 members and 985 guests)
Threads: 4,081, Posts: 32,031, Members: 2,016
Welcome to our newest members, jolob.
BETA





What's New?

What's Hot?

What's Popular?


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