View Single Post
  #5  
Old 04-24-2017, 09:31 PM
aquapyrofan aquapyrofan is offline
Member
 
Join Date: Apr 2017
Posts: 48
Gender: Unknown/Other
Credits: 10,831
aquapyrofan is on a distinguished road
Default

Quote:
Originally Posted by Kyttias View Post
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):


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.
Reply With Quote