Add Favorite Adopt to sidebar?

Forum
Last Post
Threads / Messages

aquapyrofan

Member
Member
Joined
Apr 22, 2017
Messages
48
Points
0
Mysidian Dollar
5,119
I'm wanting to add the user's favorite adopt to a sidebar module with the following structure:

(Image)
Name the Species
View | Change

The view link would go to either their profile (if I can set that up) or to their "manage" page, while the "change" link would go to change the "active pet." Potentially with icons, most likely not.

How would I go about this?
 
I know that thread is a lot to follow through, but I helped them with the basics before moving on. Here it is with just what you wanted:

To make a favpet display in the sidebar, first in the AdminCP you'll create a module (surprisingly not a widget):
sc_by_kyttias-d8dr0j8.png


Then in classes/class_sidebar.php you'll need to add these functions:

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

protected function setFavPetSB(){
    $mysidia = Registry::get("mysidia");
    $profile = $mysidia->user->getprofile();
    
    if ($profile->getFavpetID() == "0"){ // In case the user's fav pet isn't set...
        $this->FavPetSB = new Paragraph; 
        $this->FavPetSB->add(new Comment("

        	<br>
        	<b>No Favorite Pet!</b>
        	<br>
        	<a href='{$mysidia->path->getAbsolute()}account/activepet'>Choose Favorite Pet?</a>

        "));
    } else { // It must be set, so let's pull information from it.
        $favpet = new OwnedAdoptable($profile->getFavpetID());
        $this->FavPetSB = new Paragraph;
	        $this->FavPetSB->add(new Comment("

			<br>	
			<img src='{$favpet->getImage()}'>
			<br>
			{$favpet->getName()} the {$favpet->getType()}
			<br>
			<a href='{$mysidia->path->getAbsolute()}myadopts/manage/{$favpet->getAdoptID()}'>View</a> | <a href='{$mysidia->path->getAbsolute()}account/activepet'>Change</a>

		"));
	}
}

Try that and let me know how it goes? For some clarification, if it helps--

$mysidia = Registry::get("mysidia"); // $mysidia is like god

$profile = $mysidia->user->getprofile(); // $mysidia->user is an instance of the member class, so the function getprofile() is actually being called from class_member.php -- and what getprofile() does is create a new instance of the class_userprofile, which basically pulls information about (the current) user from the database

$profile->getFavpetID() // so now our variable $profile is calling getFavpetID() from, you guessed it, class_userprofile.php, to get the id of the favorite pet (from here we check whether or not its set to anything past the default value of 0 and then move on)

$favpet = new OwnedAdoptable($profile->getFavpetID()); // now we're creating $favpet as a new instance of the class "OwnedAdoptable" so we can call up functions from class_ownedadoptable.php and use them - but create a new instance of this class requires a parameter, and in this case, what it wants is the adoptable's ID number, so, that's exactly what we feed it

$favpet->getImage() and $favpet->getName() and $favpet->getType() // these are all functions found in class_ownedadoptable.php -- so definitely check out that file to see what other kind of information you can dig up -- in addition, 'public' variables set at the top are also immediately accessible without a function call

$mysidia->path->getAbsolute() // this one's really handy - $mysidia knows exactly what the root of your url is from when you installed, so you never have to worry if you change hosts or whatever - here we're using it to make sure our links definitely go to the right place every single time
 
Last edited:
I know that thread is a lot to follow through, but I helped them with the basics before moving on. Here it is with just what you wanted:

To make a favpet display in the sidebar, first in the AdminCP you'll create a module (surprisingly not a widget):
sc_by_kyttias-d8dr0j8.png


Then in classes/class_sidebar.php you'll need to add these functions:

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

protected function setFavPetSB(){
    $mysidia = Registry::get("mysidia");
    $profile = $mysidia->user->getprofile();
    
    if ($profile->getFavpetID() == "0"){ // In case the user's fav pet isn't set...
        $this->FavPetSB = new Paragraph; 
        $this->FavPetSB->add(new Comment("

        	<br>
        	<b>No Favorite Pet!</b>
        	<br>
        	<a href='{$mysidia->path->getAbsolute()}account/activepet'>Choose Favorite Pet?</a>

        "));
    } else { // It must be set, so let's pull information from it.
        $favpet = new OwnedAdoptable($profile->getFavpetID());

		$this->FavPetSB->add(new Comment("

			<br>	
			<img src='{$favpet->getImage()}'>
			<br>
			{$favpet->getName()} the {$favpet->getType()}
			<br>
			<a href='{$mysidia->path->getAbsolute()}myadopts/manage/{$favpet->getAdoptID()}'>View</a> | <a href='{$mysidia->path->getAbsolute()}account/activepet'>Change</a>

		"));
	}
}

Try that and let me know how it goes? For some clarification, if it helps--

$mysidia = Registry::get("mysidia"); // $mysidia is like god

$profile = $mysidia->user->getprofile(); // $mysidia->user is an instance of the member class, so the function getprofile() is actually being called from class_member.php -- and what getprofile() does is create a new instance of the class_userprofile, which basically pulls information about (the current) user from the database

$profile->getFavpetID() // so now our variable $profile is calling getFavpetID() from, you guessed it, class_userprofile.php, to get the id of the favorite pet (from here we check whether or not its set to anything past the default value of 0 and then move on)

$favpet = new OwnedAdoptable($profile->getFavpetID()); // now we're creating $favpet as a new instance of the class "OwnedAdoptable" so we can call up functions from class_ownedadoptable.php and use them - but create a new instance of this class requires a parameter, and in this case, what it wants is the adoptable's ID number, so, that's exactly what we feed it

$favpet->getImage() and $favpet->getName() and $favpet->getType() // these are all functions found in class_ownedadoptable.php -- so definitely check out that file to see what other kind of information you can dig up -- in addition, 'public' variables set at the top are also immediately accessible without a function call

$mysidia->path->getAbsolute() // this one's really handy - $mysidia knows exactly what the root of your url is from when you installed, so you never have to worry if you change hosts or whatever - here we're using it to make sure our links definitely go to the right place every single time

Where exactly am I supposed to put that? I get a HTTP ERROR 500 so I know something isn't right.
 
Here, replace your entire classes/class_sidebar.php file with this one:
PHP:
<?php

/**
 * The Sidebar Class, defines a standard HTML Sidebar component.
 * It extends from the Widget class, while adding its own implementation.
 * @category Resource
 * @package Widget
 * @author Hall of Famer 
 * @copyright Mysidia Adoptables Script
 * @link http://www.mysidiaadoptables.com
 * @since 1.3.3
 * @todo Not much at this point.
 *
 */

class Sidebar extends Widget{

    /**
     * The moneyBar property, specifies the money/donation bar for members.
     * @access protected
     * @var Paragraph
    */
    protected $moneyBar;
    
    /**
     * The linksBar property, stores all useful links for members.
     * @access protected
     * @var Paragraph
    */
    protected $linksBar;
    
    /**
     * The wolBar property, determines the who's online url in the sidebar.
     * @access protected
     * @var Link
    */
    protected $wolBar;
    
    /**
     * The loginBar property, specifies the loginBar for guests.
     * @access protected
     * @var FormBuilder
    */
    protected $loginBar;

    /**
     * Constructor of Sidebar Class, it initializes basic sidebar properties     
     * @access public
     * @return Void
     */
    public function __construct(){
        parent::__construct(4, "sidebar");
    }
    
    /**
     * The setDivision method, setter method for property $division.
     * It is set internally upon object instantiation, cannot be accessed in client code.
     * @param GUIComponent  $module
     * @access protected
     * @return Void
     */
    protected function setDivision(GUIComponent $module){
        if(!$this->division){
            $this->division = new Division;
            $this->division->setClass("sidebar");
        }   
        $this->division->add($module);
    }


    
    //////////////////////////////////////////////////////////////////////////////////
    //////////////////////////////////////////////////////////////////////////////////
    /// From: http://www.mysidiaadoptables.com/forum/showthread.php?t=5419
    /// 
    public function getFavPetSB(){
        return $this->FavPetSB;
    }

    protected function setFavPetSB(){
        $mysidia = Registry::get("mysidia");
        $profile = $mysidia->user->getprofile();
        
        if ($profile->getFavpetID() == "0"){ // In case the user's fav pet isn't set...
            $this->FavPetSB = new Paragraph; 
            $this->FavPetSB->add(new Comment("

                <br>
                <b>No Favorite Pet!</b>
                <br>
                <a href='{$mysidia->path->getAbsolute()}account/activepet'>Choose Favorite Pet?</a>

            "));
        } else { // It must be set, so let's pull information from it.
            $favpet = new OwnedAdoptable($profile->getFavpetID());
            $this->FavPetSB = new Paragraph;
            $this->FavPetSB->add(new Comment("

                <br>    
                <img src='{$favpet->getImage()}'>
                <br>
                {$favpet->getName()} the {$favpet->getType()}
                <br>
                <a href='{$mysidia->path->getAbsolute()}myadopts/manage/{$favpet->getAdoptID()}'>View</a> | <a href='{$mysidia->path->getAbsolute()}account/activepet'>Change</a>

            "));
        }
    }  
    ///
    ///
    //////////////////////////////////////////////////////////////////////////////////
    //////////////////////////////////////////////////////////////////////////////////
    
    
    /**
     * The getMoneyBar method, getter method for property $moneyBar.
     * @access public
     * @return Paragraph
     */
    public function getMoneyBar(){
        return $this->moneyBar;
    }

    
    /**
     * The setMoneyBar method, setter method for property $moneyBar.
     * It is set internally upon object instantiation, cannot be accessed in client code.
     * @access protected
     * @return Void
     */
    protected function setMoneyBar(){
        $mysidia = Registry::get("mysidia");
        $this->moneyBar = new Paragraph;
        $this->moneyBar->add(new Comment("You have {$mysidia->user->money} {$mysidia->settings->cost}."));
        
        $donate = new Link("donate");
        $donate->setText("Donate Money to Friends");
        $this->moneyBar->add($donate);
        $this->setDivision($this->moneyBar);        
    }

    /**
     * The getLinksBar method, getter method for property $linksBar.
     * @access public
     * @return Paragraph
     */
    public function getLinksBar(){
        return $this->linksBar;
    }
    
    /**
     * The setLinksBar method, setter method for property $linksBar.
     * It is set internally upon object instantiation, cannot be accessed in client code.
     * @access protected
     * @return Void
     */
    protected function setLinksBar(){
        $mysidia = Registry::get("mysidia");
        $this->linksBar = new Paragraph;
        $linkTitle = new Comment("{$mysidia->user->username}'s Links:");
        $linkTitle->setBold();
        $this->linksBar->add($linkTitle);
        
        $linksList = new LinksList("ul");
        $this->setLinks($linksList);
        
        $this->linksBar->add($linksList);
        $this->setDivision($this->linksBar);    
    }

    /**
     * The setLinks method, append all links to the LinksBar.
     * It is set internally upon object instantiation, cannot be accessed in client code.
     * @access protected
     * @return Void
     */
    protected function setLinks(LinksList $linksList){
        $mysidia = Registry::get("mysidia");
        $stmt = $mysidia->db->select("links", array("id", "linktext", "linkurl"), "linktype = 'sidelink' ORDER BY linkorder");
        if($stmt->rowCount() == 0) Throw new Exception("There is an error with sidebar links, please contact the admin immediately for help.");
        
        while($sideLink = $stmt->fetchObject()){
            $link = new Link($sideLink->linkurl);
            $link->setText($sideLink->linktext);
            if($sideLink->linkurl == "messages"){
                $num = $mysidia->db->select("messages", array("touser"), "touser='{$mysidia->user->username}' and status='unread'")->rowCount();
                if($num > 0) $link->setText("<b>{$link->getText()} ({$num})</b>");
            }
            $link->setListed(TRUE);
            $linksList->add($link);   
        }
        
        if($mysidia->user instanceof Admin){
            $adminCP = new Link("admincp/", FALSE, FALSE);
            $adminCP->setText("Admin Control Panel");
            $adminCP->setListed(TRUE);  
            $linksList->add($adminCP);          
        }
    }
    
    /**
     * The getWolBar method, getter method for property $wolBar.
     * @access public
     * @return LinksList
     */
    public function getWolBar(){
        return $this->wolBar;
    }
    
    /**
     * The setWolBar method, setter method for property $wolBar.
     * It is set internally upon object instantiation, cannot be accessed in client code.
     * @access protected
     * @return Void
     */
    protected function setWolBar(){
        $mysidia = Registry::get("mysidia");
        $this->wolBar = new Link("online");
        $online = $mysidia->db->select("online", array(), "username != 'Visitor'")->rowCount();
        $offline = $mysidia->db->select("online", array(), "username = 'Visitor'")->rowCount();
        $this->wolBar->setText("This site has {$online} members and {$offline} guests online.");
        $this->setDivision($this->wolBar);      
    }
    
    /**
     * The getLoginBar method, getter method for property $loginBar.
     * @access public
     * @return FormBuilder
     */
    public function getLoginBar(){
        return $this->loginBar;
    }
    
    /**
     * The setLoginBar method, setter method for property $loginBar.
     * It is set internally upon object instantiation, cannot be accessed in client code.
     * @access protected
     * @return Void
     */
    protected function setLoginBar(){
        $this->loginBar = new FormBuilder("login", "login", "post");
        $loginTitle = new Comment("Member Login:");
        $loginTitle->setBold();
        $loginTitle->setUnderlined();
        $this->loginBar->add($loginTitle);

        $this->loginBar->buildComment("username: ", FALSE)
                       ->buildTextField("username")
                       ->buildComment("password: ", FALSE)
                       ->buildPasswordField("password", "password", "", TRUE)   
                       ->buildButton("Log In", "submit", "submit")
                       ->buildComment("Don't have an account?"); 
                       
        $register = new Link("register");
        $register->setText("Register New Account");
        $register->setLineBreak(TRUE);
        $forgot = new Link("forgotpass");
        $forgot->setText("Forgot Password?");
        
        $this->loginBar->add($register);
        $this->loginBar->add($forgot);
        $this->setDivision($this->loginBar);    
    }
}
?>
 
Here, replace your entire classes/class_sidebar.php file with this one:
PHP:
<?php

/**
 * The Sidebar Class, defines a standard HTML Sidebar component.
 * It extends from the Widget class, while adding its own implementation.
 * @category Resource
 * @package Widget
 * @author Hall of Famer 
 * @copyright Mysidia Adoptables Script
 * @link http://www.mysidiaadoptables.com
 * @since 1.3.3
 * @todo Not much at this point.
 *
 */

class Sidebar extends Widget{

    /**
     * The moneyBar property, specifies the money/donation bar for members.
     * @access protected
     * @var Paragraph
    */
    protected $moneyBar;
    
    /**
     * The linksBar property, stores all useful links for members.
     * @access protected
     * @var Paragraph
    */
    protected $linksBar;
    
    /**
     * The wolBar property, determines the who's online url in the sidebar.
     * @access protected
     * @var Link
    */
    protected $wolBar;
    
    /**
     * The loginBar property, specifies the loginBar for guests.
     * @access protected
     * @var FormBuilder
    */
    protected $loginBar;

    /**
     * Constructor of Sidebar Class, it initializes basic sidebar properties     
     * @access public
     * @return Void
     */
    public function __construct(){
        parent::__construct(4, "sidebar");
    }
    
    /**
     * The setDivision method, setter method for property $division.
     * It is set internally upon object instantiation, cannot be accessed in client code.
     * @param GUIComponent  $module
     * @access protected
     * @return Void
     */
    protected function setDivision(GUIComponent $module){
        if(!$this->division){
            $this->division = new Division;
            $this->division->setClass("sidebar");
        }   
        $this->division->add($module);
    }


    
    //////////////////////////////////////////////////////////////////////////////////
    //////////////////////////////////////////////////////////////////////////////////
    /// From: http://www.mysidiaadoptables.com/forum/showthread.php?t=5419
    /// 
    public function getFavPetSB(){
        return $this->FavPetSB;
    }

    protected function setFavPetSB(){
        $mysidia = Registry::get("mysidia");
        $profile = $mysidia->user->getprofile();
        
        if ($profile->getFavpetID() == "0"){ // In case the user's fav pet isn't set...
            $this->FavPetSB = new Paragraph; 
            $this->FavPetSB->add(new Comment("

                <br>
                <b>No Favorite Pet!</b>
                <br>
                <a href='{$mysidia->path->getAbsolute()}account/activepet'>Choose Favorite Pet?</a>

            "));
        } else { // It must be set, so let's pull information from it.
            $favpet = new OwnedAdoptable($profile->getFavpetID());
            $this->FavPetSB = new Paragraph;
            $this->FavPetSB->add(new Comment("

                <br>    
                <img src='{$favpet->getImage()}'>
                <br>
                {$favpet->getName()} the {$favpet->getType()}
                <br>
                <a href='{$mysidia->path->getAbsolute()}myadopts/manage/{$favpet->getAdoptID()}'>View</a> | <a href='{$mysidia->path->getAbsolute()}account/activepet'>Change</a>

            "));
        }
    }  
    ///
    ///
    //////////////////////////////////////////////////////////////////////////////////
    //////////////////////////////////////////////////////////////////////////////////
    
    
    /**
     * The getMoneyBar method, getter method for property $moneyBar.
     * @access public
     * @return Paragraph
     */
    public function getMoneyBar(){
        return $this->moneyBar;
    }

    
    /**
     * The setMoneyBar method, setter method for property $moneyBar.
     * It is set internally upon object instantiation, cannot be accessed in client code.
     * @access protected
     * @return Void
     */
    protected function setMoneyBar(){
        $mysidia = Registry::get("mysidia");
        $this->moneyBar = new Paragraph;
        $this->moneyBar->add(new Comment("You have {$mysidia->user->money} {$mysidia->settings->cost}."));
        
        $donate = new Link("donate");
        $donate->setText("Donate Money to Friends");
        $this->moneyBar->add($donate);
        $this->setDivision($this->moneyBar);        
    }

    /**
     * The getLinksBar method, getter method for property $linksBar.
     * @access public
     * @return Paragraph
     */
    public function getLinksBar(){
        return $this->linksBar;
    }
    
    /**
     * The setLinksBar method, setter method for property $linksBar.
     * It is set internally upon object instantiation, cannot be accessed in client code.
     * @access protected
     * @return Void
     */
    protected function setLinksBar(){
        $mysidia = Registry::get("mysidia");
        $this->linksBar = new Paragraph;
        $linkTitle = new Comment("{$mysidia->user->username}'s Links:");
        $linkTitle->setBold();
        $this->linksBar->add($linkTitle);
        
        $linksList = new LinksList("ul");
        $this->setLinks($linksList);
        
        $this->linksBar->add($linksList);
        $this->setDivision($this->linksBar);    
    }

    /**
     * The setLinks method, append all links to the LinksBar.
     * It is set internally upon object instantiation, cannot be accessed in client code.
     * @access protected
     * @return Void
     */
    protected function setLinks(LinksList $linksList){
        $mysidia = Registry::get("mysidia");
        $stmt = $mysidia->db->select("links", array("id", "linktext", "linkurl"), "linktype = 'sidelink' ORDER BY linkorder");
        if($stmt->rowCount() == 0) Throw new Exception("There is an error with sidebar links, please contact the admin immediately for help.");
        
        while($sideLink = $stmt->fetchObject()){
            $link = new Link($sideLink->linkurl);
            $link->setText($sideLink->linktext);
            if($sideLink->linkurl == "messages"){
                $num = $mysidia->db->select("messages", array("touser"), "touser='{$mysidia->user->username}' and status='unread'")->rowCount();
                if($num > 0) $link->setText("<b>{$link->getText()} ({$num})</b>");
            }
            $link->setListed(TRUE);
            $linksList->add($link);   
        }
        
        if($mysidia->user instanceof Admin){
            $adminCP = new Link("admincp/", FALSE, FALSE);
            $adminCP->setText("Admin Control Panel");
            $adminCP->setListed(TRUE);  
            $linksList->add($adminCP);          
        }
    }
    
    /**
     * The getWolBar method, getter method for property $wolBar.
     * @access public
     * @return LinksList
     */
    public function getWolBar(){
        return $this->wolBar;
    }
    
    /**
     * The setWolBar method, setter method for property $wolBar.
     * It is set internally upon object instantiation, cannot be accessed in client code.
     * @access protected
     * @return Void
     */
    protected function setWolBar(){
        $mysidia = Registry::get("mysidia");
        $this->wolBar = new Link("online");
        $online = $mysidia->db->select("online", array(), "username != 'Visitor'")->rowCount();
        $offline = $mysidia->db->select("online", array(), "username = 'Visitor'")->rowCount();
        $this->wolBar->setText("This site has {$online} members and {$offline} guests online.");
        $this->setDivision($this->wolBar);      
    }
    
    /**
     * The getLoginBar method, getter method for property $loginBar.
     * @access public
     * @return FormBuilder
     */
    public function getLoginBar(){
        return $this->loginBar;
    }
    
    /**
     * The setLoginBar method, setter method for property $loginBar.
     * It is set internally upon object instantiation, cannot be accessed in client code.
     * @access protected
     * @return Void
     */
    protected function setLoginBar(){
        $this->loginBar = new FormBuilder("login", "login", "post");
        $loginTitle = new Comment("Member Login:");
        $loginTitle->setBold();
        $loginTitle->setUnderlined();
        $this->loginBar->add($loginTitle);

        $this->loginBar->buildComment("username: ", FALSE)
                       ->buildTextField("username")
                       ->buildComment("password: ", FALSE)
                       ->buildPasswordField("password", "password", "", TRUE)   
                       ->buildButton("Log In", "submit", "submit")
                       ->buildComment("Don't have an account?"); 
                       
        $register = new Link("register");
        $register->setText("Register New Account");
        $register->setLineBreak(TRUE);
        $forgot = new Link("forgotpass");
        $forgot->setText("Forgot Password?");
        
        $this->loginBar->add($register);
        $this->loginBar->add($forgot);
        $this->setDivision($this->loginBar);    
    }
}
?>
Well, it's not throwing an error this time, but nothing's showing up in the sidebar.
 
I tested this exact version of the file on my own site and it works just fine? Are you sure you created the module in the Admin CP exactly how the image shows?
 
I tested this exact version of the file on my own site and it works just fine? Are you sure you created the module in the Admin CP exactly how the image shows?

I just checked, it's exactly the same. I have no idea.
 
Aquapyrofan and I are working together on this, so I've got a couple questions, since I'm having trouble getting this working as well. We've tried to set it exactly as you said, but it's still not working. As such, I was wondering whether the alchemy or item drop mods, or the fact that it was not installed at the domain's root, would be issues?

EDIT: tested on a clean install under WAMP, it still doesn't work
 
Last edited:
What would I use to create a variable to pull from the owned adoptables table in the SQL database?
 
Ok, so I got it working. Cludged a little of the code from here together with some of Kyttias' code.

PHP:
$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);
 
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.
 
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.
 
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.
 
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:
$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
 
Last edited:
I have the function in classes/class_siderbar as this;
PHP:
    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?
 
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.
 
In an attempt to confirm my findings, I attempted to create a module to return the FavPetID.
PHP:
$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
 
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.
 

Similar threads

Users who are viewing this thread

  • Forum Contains New Posts
  • Forum Contains No New Posts

Forum statistics

Threads
4,277
Messages
33,118
Members
1,602
Latest member
BerrieMilk
BETA

Latest Threads

Latest Posts

Top