Mysidia Adoptables Support Forum  

Home Community Mys-Script Creative Off-Topic
Go Back   Mysidia Adoptables Support Forum > Mysidia Adoptables > Addons and Modifications > Mys v1.3.x Mods

Notices

Reply
 
Thread Tools Display Modes
  #1  
Old 12-10-2016, 01:02 PM
Dinocanid's Avatar
Dinocanid Dinocanid is offline
Member
 
Join Date: Aug 2016
Location: Maryland, USA
Posts: 516
Gender: Unknown/Other
Credits: 63,679
Dinocanid is on a distinguished road
Default Bank Mod

-Before we start--
If you have a fresh install of the mysidia script or you have unmodified files, you may download the attachments at the bottom. (You still must follow step 0) If you would rather install it manually, follow the instructions below.

-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();
        
$cash $mysidia->user->getcash();
        
        if (
$balance <= 0){
        
$document->add(new Comment("<h2>Current Balance: $0</h2>"));
        }
        else 
$document->add(new Comment("<h2>Current Balance: $ {$balance}</h2>"FALSE));
        
$document->add(new paragraph);

if(
$mysidia->input->post("deposit")){
$amount $mysidia->input->post("amount");
$balance $mysidia->db->select("users", array("bank"))->fetchColumn();
if(
$amount $cash){$document->add(new Comment("You don't have that much to deposit!")); return TRUE;}
$mysidia->user->changecash(-$amount);
$mysidia->user->changebank(+$amount);
$document->add(new Comment("<h2>You deposited $ {$amount} 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();
if(
$amount $balance){$document->add(new Comment("You don't have that much to withdraw!")); return TRUE;}
else{
$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.

-Attachment-
The bank.php file goes in your root/public_html folder while bankview.php goes in your view folder. Please do not use the attachments if you have heavily modified files as it can cause errors! Follow the manual tutorial instead.
Attached Files
File Type: zip 1.3.4 Mysidia Bank Mod.zip (4.9 KB, 9 views)
__________________

Last edited by Dinocanid; 12-10-2016 at 09:53 PM.
Reply With Quote
  #2  
Old 12-10-2016, 02:15 PM
parayna's Avatar
parayna parayna is offline
Member
 
Join Date: May 2013
Location: Devon, UK
Posts: 342
Gender: Female
Credits: 16,096
parayna is on a distinguished road
Default

OK, I tinkered with it a bit and made it so that the deposit and withdraw are two separate things for my site... that way the deposit and withdraw parts are hidden when doing one or the other! I basically did it by creating bank_deposit and bank_withdraw.php files as well as their view files. And they work, woo! XD This also let me use the Admin CP to create my bank page as I could just link to those pages from a custom page but I am going to create a PHP one so that it is linked under {url}bank instead of {url}pages/view/bank XD

There was probably an easier way of hiding them so I didn't have to create these files but I'm happy with doing this as then I can add images to each available page and not worry about them showing up wrong. If the text and code isn't in one file, there is no chance of it showing the wrong text/code unless I mess up! XD

Thanks for the code ^_^
Reply With Quote
  #3  
Old 12-10-2016, 09:54 PM
Dinocanid's Avatar
Dinocanid Dinocanid is offline
Member
 
Join Date: Aug 2016
Location: Maryland, USA
Posts: 516
Gender: Unknown/Other
Credits: 63,679
Dinocanid is on a distinguished road
Default

Added a pretty important update so users can no longer withdraw more money than they have in the bank and deposit money they don't have.
__________________
Reply With Quote
  #4  
Old 01-15-2017, 10:16 AM
ffsharriet ffsharriet is offline
Member
 
Join Date: Jan 2017
Posts: 22
Gender: Female
Credits: 4,130
ffsharriet is on a distinguished road
Default

I can't find where to add a new column?

Name: bank
Type: int
Length/Values: 11
Default: As defined 0
check the null box

I have no where to add this. Could you provide a screen shot to where I can find it please?
Reply With Quote
  #5  
Old 01-15-2017, 10:32 AM
Dinocanid's Avatar
Dinocanid Dinocanid is offline
Member
 
Join Date: Aug 2016
Location: Maryland, USA
Posts: 516
Gender: Unknown/Other
Credits: 63,679
Dinocanid is on a distinguished road
Default

You go to phpMyAdmin, find and select adopts_users, and then add a new column under the structure tab with the given information:
__________________
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 06:36 PM.

Currently Active Users: 447 (0 members and 447 guests)
Threads: 4,080, Posts: 32,024, 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