Mysidia Adoptables Support Forum

Mysidia Adoptables Support Forum (http://www.mysidiaadoptables.com/forum/index.php)
-   Questions and Supports (http://www.mysidiaadoptables.com/forum/forumdisplay.php?f=18)
-   -   Add Favorite Adopt to sidebar? (http://www.mysidiaadoptables.com/forum/showthread.php?t=5419)

KatFennec 04-25-2017 03:10 AM

What would I use to create a variable to pull from the owned adoptables table in the SQL database?

KatFennec 04-25-2017 04:10 AM

Ok, so I got it working. Cludged a little of the code from here together with some of Kyttias' code.

PHP Code:

$profile $mysidia->user->getprofile();
$owned = new OwnedAdoptable($profile->getFavpetID());
$profile->getFavpetID();
$Name $owned->getName();
$Type $owned->getType();
$texta = new Paragraph;
$texta->add(new Comment(

<br> 
<img src='
{$owned->getImage()}'> 
<br> 
{$Name} the {$Type} 
<br> 
<a href='
{$mysidia->path->getAbsolute()}myadopts/manage/{$owned->getAdoptID()}'>View</a> | <a href='{$mysidia->path->getAbsolute()}account/activepet'>Change</a> 
"
)); 
$moduleContainer->add($texta); 


aquapyrofan 04-25-2017 04:52 PM

The reason the above code works is because we could get it working as a module in the ACP, which won't accept if else statements. Don't know if that's the case with coding it in the file, but it's likely.

Abronsyth 04-25-2017 05:43 PM

That is certainly curious, I have the favpet in my sidebar (and elsewhere on my site) using Kyttias's code without any issues.

Did you make sure to leave the code sections in the widget blank? The widget only exists for you to actually place within the sidebar, but no code goes into it via the ACP.

aquapyrofan 04-25-2017 07:43 PM

Quote:

Originally Posted by Abronsyth (Post 36202)
That is certainly curious, I have the favpet in my sidebar (and elsewhere on my site) using Kyttias's code without any issues.

Did you make sure to leave the code sections in the widget blank? The widget only exists for you to actually place within the sidebar, but no code goes into it via the ACP.

We tried that and it showed absolutely nothing when the pet was set and broke the site when it wasn't. On a mod-free install of Mysidia as well. Kat was able to get it working with the code she posted plus an "if else" statement in the ACP, but the site still throws a 500 error if no pet is set.

KatFennec 04-25-2017 07:48 PM

Quote:

Originally Posted by Abronsyth (Post 36202)
That is certainly curious, I have the favpet in my sidebar (and elsewhere on my site) using Kyttias's code without any issues.

Did you make sure to leave the code sections in the widget blank? The widget only exists for you to actually place within the sidebar, but no code goes into it via the ACP.

Yes, I did. I copied the code that Kyttias provided, pasted it into class_sidebar.php as per the instructions, then created a blank module, with the name FavPetSB, exactly as per instructions.

As it stands, I have the following code, emplaced within the PHP box of a new module. However, it seems that the if statement is causing some manner of issue - it works flawlessly if the user HAS set a favourite pet, but the entire site returns a 500 error if not, and they are logged in.
PHP Code:

$profile $mysidia->user->getprofile();
$owned = new OwnedAdoptable($profile->getFavpetID());


if(
$profile->getFavpetID() == 0){
$texta = new Paragraph;
$texta->add(new Comment(
<br>
Unfortunately, you don't seem to have a favourite pet set.
"
));
}
else {
$Name $owned->getName();
$Type $owned->getType();
$texta = new Paragraph;
$texta->add(new Comment(

<br> 
<img src='
{$owned->getImage()}'> 
<br> 
{$Name} the {$Type} 
<br> 
<a href='
{$mysidia->path->getAbsolute()}myadopts/manage/{$owned->getAdoptID()}'>View</a> | <a href='{$mysidia->path->getAbsolute()}account/profile'>Change</a> 
"
)); 
}
$moduleContainer->add($texta); 

EDIT: I should mention we have Mysidia installed in a subdomain, and on x10hosting, on the offhand chance either of those are contributing factors

Abronsyth 04-25-2017 08:30 PM

I have the function in classes/class_siderbar as this;
PHP Code:

    public function getFavPetSB(){
        return 
$this->FavPetSB;
    }

    protected function 
setFavPetSB(){
        
$mysidia Registry::get("mysidia");
        
$profile $mysidia->user->getprofile();   
        
        
/* IF THE USER DOES *NOT* HAVE A FAVPET: */
        
if ($profile->getFavpetID() == "0"){
            
$this->FavPetSB = new Paragraph
            
$this->FavPetSB->add(new Comment("<a href='LINK TO CHOOSE PAGE'>Choose Companion</a>"));
        }

        
/* IF THE USER *DOES* HAVE A FAVPET: */
        
if ($profile->getFavpetID() != "0"){
            
$favpet = new OwnedAdoptable($profile->getFavpetID());
            
$this->FavPetSB = new Paragraph
            
$this->FavPetSB->add(new Comment("<center><b>Companion</b><br><a href='/myadopts/manage/{$profile->getFavpetID()}'><img src='{$favpet->getImage()}' style='max-width:80px;' rel='tooltip' title=\"{$favpet->name}\"></a><br></center>"));


        }        
        
$this->setDivision($this->FavPetSB);
    } 

That makes it so if a user doesn't have it set then they'll just get a link to set it. I don't know how much I changed it from Kyttias's version, but maybe it'll work for you?

KatFennec 04-25-2017 08:43 PM

OK, so I think I've narrowed down the problem - it looks like getFavpetID() is NOT returning a 0 when there is no favourite pet assigned. Which is particularly strange, seeing as I poked through the databases, and it most certainly SHOULD be returning a zero.

KatFennec 04-25-2017 08:52 PM

In an attempt to confirm my findings, I attempted to create a module to return the FavPetID.
PHP Code:

$profile $mysidia->user->getprofile();
$owned = new OwnedAdoptable($profile->getFavpetID());
$profile->getFavpetID();
$uniqueidforpet $profile->getFavpetID();
$texta = new Paragraph;
$texta->add(new Comment("
<br>
ID: 
{$profile->getFavpetID()}
"
));
$moduleContainer->add($texta); 

Placed in a module, it correctly returned my favourite pet, but when I set it to none caused the site to return a 500 error

aquapyrofan 04-25-2017 09:02 PM

I fixed it, by suggesting that the part defining the owned adoptable class be moved to where it definitively exists after the install in WAMP threw an error that told me what the problem was. Oops.


All times are GMT -5. The time now is 02:50 PM.

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