Mysidia Adoptables Support Forum

Mysidia Adoptables Support Forum (http://www.mysidiaadoptables.com/forum/index.php)
-   Mys v1.3.x Mods (http://www.mysidiaadoptables.com/forum/forumdisplay.php?f=42)
-   -   Mys v1.3.4 Pet Sorting (http://www.mysidiaadoptables.com/forum/showthread.php?t=5466)

Dinocanid 06-13-2017 10:28 AM

Pet Sorting
 
Pet Sorting mod (Mys 1.3.4)
Description: A non-invasive and minimal mod that allows users to sort their pets according to total clicks, gender, level, and name; without the use of javascript or ajax. This can easily be extended on to allow more sorting options as well (like species).


-Step 1-
Go into phpMyAdmin and add a new column in users_options:
http://www.clipular.com/c/5606370570...lPiHD09hlImMV0

-Step 2-
Open up myadopts.php and replace the entire public function index with this:
PHP Code:

    public function index(){
        
$mysidia Registry::get("mysidia");
        
$total $mysidia->db->select("owned_adoptables", array("aid"), "owner = '{$mysidia->user->username}'")->rowCount();
        
$pagination = new Pagination($total10"myadopts");
        
$pagination->setPage($mysidia->input->get("page"));    
        
        
//Attempting to sort!
        
$sort $mysidia->db->select("users_options", array("petsort"), "username = '{$mysidia->user->username}'")->fetchColumn();
            switch (
$sort){
    case 
'clicks'
        
$stmt $mysidia->db->select("owned_adoptables", array("aid"), "owner = '{$mysidia->user->username}' ORDER BY totalclicks LIMIT {$pagination->getLimit()},{$pagination->getRowsperPage()}");
        break;
    case 
'gender'
        
$stmt $mysidia->db->select("owned_adoptables", array("aid"), "owner = '{$mysidia->user->username}' ORDER BY gender LIMIT {$pagination->getLimit()},{$pagination->getRowsperPage()}"); 
        break;
    case 
'level'
        
$stmt $mysidia->db->select("owned_adoptables", array("aid"), "owner = '{$mysidia->user->username}' ORDER BY currentlevel LIMIT {$pagination->getLimit()},{$pagination->getRowsperPage()}");
        break;
    case 
'name'
        
$stmt $mysidia->db->select("owned_adoptables", array("aid"), "owner = '{$mysidia->user->username}' ORDER BY name LIMIT {$pagination->getLimit()},{$pagination->getRowsperPage()}");
        break;
}
        
        
//Sorting ends here!
        
$this->setField("pagination"$pagination);
        
$this->setField("stmt", new DatabaseStatement($stmt));
    } 

-Step 3-
Finally, open myadoptsview.php and place this wherever you want the dropdown to be (I placed it above the table for adopts)
PHP Code:

//This is for sorting!
         
if($mysidia->input->post("sortpets")){
$choice $mysidia->input->post("sortlist");
$mysidia->db->update("users_options", array("petsort" => $choice), "username = '{$mysidia->user->username}'");
$document->add(new Comment("<meta http-equiv='refresh' content='0;url=/myadopts' />")); 
}
         
        
$sortForm = new Form("sortform""""post");
        
$sort_list = new DropdownList("sortlist");
        
$sort_list->add(new Option("Clicks""clicks"));
        
$sort_list->add(new Option("Gender""gender"));
        
$sort_list->add(new Option("Level""level"));
        
$sort_list->add(new Option("Name""name"));
        
$sortForm->add(new Comment("<b>Sort by:</b>"FALSE));
        
$sortForm->add($sort_list);
        
$sortForm->add(new Button("Sort Pets""sortpets""submit"));
        
$document->add($sortForm);
        
        
//Sorting ends here!!! 

  Spoiler: Different codes for refreshing 

It is also possible to refresh the page with:
PHP Code:

header("Location: $root/myadopts");
 
exit; 

Or:
PHP Code:

header("Location: /myadopts");
 
exit; 

But this might not work for everyone


(Also if anyone knows how to safely place the button next to the dropdown box that would be great!)

parayna 06-13-2017 10:55 AM

Yay mod XD I also added a new option to mine at the top that says 'Select an option...' and instead of making it throw an error I made it set the users sort to the default (clicks). That way it's like a reset button and is basically a blank option XD Purely for aesthetic reasons lol If it resets what they had before then they were probably trying to change it anyway, so.. XD

Abronsyth 06-13-2017 11:44 AM

This is splendid, easy to edit, and simple to set up!!

Thank you very much for sharing, it is definitely a feature users appreciate!

draugluin 08-09-2018 05:15 AM

Ah.. this is GREAT !! thank you Dinocanid ! :smile::smile::smile:

Missy Master 07-19-2020 06:03 PM

Late to the game but very nice Mod, have it installed and working, thank you!!


All times are GMT -5. The time now is 03:18 PM.

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