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)

aquapyrofan 04-24-2017 01:37 PM

Add Favorite Adopt to sidebar?
 
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?

Abronsyth 04-24-2017 02:32 PM

You'll want to check out this thread;
http://mysidiaadoptables.com/forum/s...favpet+sidebar

aquapyrofan 04-24-2017 08:04 PM

Quote:

Originally Posted by Abronsyth (Post 36183)
You'll want to check out this thread;
http://mysidiaadoptables.com/forum/s...favpet+sidebar

That didn't actually help because I don't actually want anything in there aside from the name, species, image, and links to view or change the active, and I still don't know how to fetch and display that information (or in the case of the links, how to do them at all in there).

Kyttias 04-24-2017 09:03 PM

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):
http://fc03.deviantart.net/fs71/f/20...as-d8dr0j8.png

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

PHP Code:

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

aquapyrofan 04-24-2017 09:31 PM

Quote:

Originally Posted by Kyttias (Post 36189)
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):
http://fc03.deviantart.net/fs71/f/20...as-d8dr0j8.png

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

PHP Code:

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.

Kyttias 04-24-2017 09:46 PM

Here, replace your entire classes/class_sidebar.php file with this one:
PHP Code:

<?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/"FALSEFALSE);
            
$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);    
    }
}
?>


aquapyrofan 04-24-2017 09:55 PM

Quote:

Originally Posted by Kyttias (Post 36192)
Here, replace your entire classes/class_sidebar.php file with this one:
PHP Code:

<?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/"FALSEFALSE);
            
$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.

Kyttias 04-24-2017 10:19 PM

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?

aquapyrofan 04-24-2017 10:30 PM

Quote:

Originally Posted by Kyttias (Post 36194)
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.

KatFennec 04-25-2017 02:24 AM

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


All times are GMT -5. The time now is 11:24 PM.

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