Mysidia Adoptables Support Forum

Mysidia Adoptables Support Forum (http://www.mysidiaadoptables.com/forum/index.php)
-   Tutorials and Tips (http://www.mysidiaadoptables.com/forum/forumdisplay.php?f=27)
-   -   Pet biographies! (http://www.mysidiaadoptables.com/forum/showthread.php?t=5227)

Dinocanid 10-21-2016 05:37 PM

Pet biographies!
 
This tutorial allows you to add biographies to your adopts. Let me know if you get any errors since I worked on this on and off and I might have forgotten to include a line of code somewhere.

Setup
This is the stuff you need to do in phpMyAdmin before you go edit anything else. I'm sure this tutorial won't work otherwise.
Find adopts_owned_adoptables and add 1 column under the structure tab with this info:
  Spoiler: What to add 
Name: petbio
Type: VARCHAR
Length/Values: 500
Default: NULL
Collation: latin1_swedish_ci
Check the box that says null

You can change the length to whatever you want the max number of characters allowed in an adoptable's bio to be. I put 500 since that seems reasonable.

Foundation
Now for the bulk of this tutorial: Editing. This part is for getting the under-the-hood stuff for the bio working so it actually saves after you type it. Let's work from the outside in.

Step 1
Go to myadopts.php and add this to it:
PHP Code:

public function changepetbio(){
        
$mysidia Registry::get("mysidia");        
        if(
$mysidia->input->post("submit")){
            
$poundsettings getpoundsettings();
            
$poundpet $mysidia->db->select("pounds", array(), "aid='{$this->adopt->getAdoptID()}'")->fetchObject();
            if(
$poundpet and $poundsettings->rename->active == "yes"){
                if(!empty(
$poundpet->firstowner) and $mysidia->user->username != $poundpet->firstowner){
                    
$this->setFlags("rename_error""rename_owner");
                    return;    
                }                
            }            
            
$this->adopt->setPetbio($mysidia->input->post("petbio"), "update");
        }
        
$this->setField("adopt"$this->adopt);        
    
$this->setField("image"$this->image);            
    } 

As you can probably see, I basically duplicated the rename function. Some of it can probably be cleaned up if you know how, but I don't.

Step 2
Go to classes>class_ownedadoptable.php and add this with all the other protected and public stuff (All that yellow stuff between "class OwnedAdoptable" and "public function_construct")
PHP Code:

public $petbio

Once you do that, add these lines with all the other functions. It can be towards the bottom or something.
PHP Code:

public function getPetbio(){
        return 
$this->petbio;
    }
    public function 
setPetbio($petbio$assignMode ""){
        if(
$assignMode == Model::UPDATE$this->save("petbio"$petbio);
        
$this->petbio $petbio;
    } 

Step 3
Go to lang>lang_myadopts.php and add these lines:
PHP Code:

$lang['changebio'] = "Change the bio of ";
$lang['changebio_default'] = "This page allows you to change the bio of ";
$lang['changebio_details'] = ". To change this adoptable's bio, simply type it in the box below.";
$lang['changebio_error'] = "Cannot change";
$lang['changebio_owner'] = "The site admin has specified that only original owners can change their adoptables' bios.";  
$lang['changebio_success_title'] = "Bio Change Successful";
$lang['changebio_success'] = "You have successfully changed the bio of "

Displaying and Using
We're halfway there, wow! This part is for adding the text areas, buttons, and links that will allow users to actually add bios to their adoptables; as well as displaying it on the adoptable's profile.

Step 1
Go to view>myadoptsview. After we're done, you can use the following line to display the bio wherever you want on a pet's profile. You can go ahead and add it now if you want so you can see it right after we finish.
PHP Code:

$bio stripslashes($adopt->getPetbio()); 
Bio: {$bio

You can also use this if your profile code is structured differently from mine:
PHP Code:

$bio stripslashes($adopt->getPetbio()); 
$document->add(new Comment(Bio: {$bio})); 

Step 2
Add this code with all the other functions. You can put it towards the bottom to keep things organized:
PHP Code:

public function changepetbio(){
        
$mysidia Registry::get("mysidia");
        
$adopt $this->getField("adopt");        
        
$image $this->getField("image");        
        
$document $this->document;
        
        if(
$mysidia->input->post("submit")){
            
$document->setTitle($this->lang->changebio_success_title);
            
$document->add($image);
            
$message "<br>{$this->lang->changebio_success}{$adopt->getName()}
                        You can now manage 
{$mysidia->input->post("adoptname")} on the";
            
$document->addLangvar($message);
            
$document->add(new Link("myadopts/manage/{$adopt->getAdoptID()}""My Adopts Page"));
            return;
        }
        
        
$document->setTitle($this->lang->changebio.$adopt->getName());
        
$document->add($image);
        
$document->addLangvar("<br />{$this->lang->changebio_default}{$adopt->getName()}{$this->lang->changebio_details}<br />");
        
        
$petbioForm = new FormBuilder("petbioform""""post");
        
$petbioForm->buildTextArea("petbio")->buildButton("Change Bio""submit""submit");
        
$document->add($petbioForm);           
    } 

Another rename replica :veeee:. This huge chunk basically works like the rename function and takes the user to a page that lets them edit the bio.

Step 3
Done? Good, now just scroll back up and add this with all the other links on your adoptable's profile. (Along with rename, trade status, freeze, etc.)
PHP Code:

$document->add(new Link("myadopts/changepetbio/{$aid}"" Change {$name}'s Bio"TRUE)); 

The End
Aaand...you're done! To test this, go to your pet's profile and click on the new link we added. This should take you to a screen where you can type in whatever you want for the bio. Once you hit the "Change Bio" button, it takes you back to the profile with your pet's new and shiny biography.

Bexasaurus 11-25-2016 01:24 AM

I'm receiving the following error: Database error 1054 - Unknown column 'petbio' in 'field list'

This is after I click on update for the pet's bio.

How can I fix this?

Dinocanid 11-25-2016 06:33 AM

That's usually caused by it not being in the database. Did you try the setup through step 2 again?

Bexasaurus 11-25-2016 11:17 AM

I'll try to redo all of the steps. Maybe I just missed something and don't know it.

Dinocanid 11-25-2016 01:51 PM

If it still isn't working after you try again, I'll look at my code since it might be missing a part.

Corsair 11-25-2016 02:35 PM

I just tried it and it works for me. I noticed it has a "/" in words like "I've" and "pet's".

Dinocanid 11-25-2016 02:40 PM

Mysidia has a problem with apostrophes in text, so it will add backslashes wherever they're used. The only way to get rid of them is to go to the bio in phpMyAdmin and manually remove the \'s, or avoid using apostrophes. I wish there was a way to prevent it though, they pop up everywhere on my site since I use them a lot :/

Bexasaurus 11-25-2016 02:55 PM

Ah, so it's just me then. I'll redo the steps as soon as I fix the inventory issue I have going on. :eye:

parayna 12-23-2016 05:38 PM

Dinocanid, you can use a stripslashes command to remove backslashes but I'm not too sure where you'd place them in yours XD I'm gonna have a go though, and will share if I get it..

EDIT: Done!

This isn't too elegant.. and I have sooo many places to put it >.> But it works!

Where you have your profile (bio, I suppose) placed you need to include this somewhere:

$bio = stripslashes($adopt->getPetbio());

That's what I have on my 'manage adopt' page, and it works! (I am using Kyttias' profile page method of displaying stuff so that might make it work? I'm not sure.)

Basically place that where you have biographies displayed :)

Oh, and remember to put {$bio} (or just $bio) instead of the full string, to those who might be confused :)

Dinocanid 12-23-2016 06:06 PM

Thanks for sharing! Those backslashes were so annoying lol.


All times are GMT -5. The time now is 01:15 PM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.