Mys 1.3.5 Pet Group Sorting Mod 1.3.5

Forum
Last Post
Threads / Messages

GeneticAlpha

Loving Mysidia!
Member
Joined
May 24, 2020
Messages
287
Points
18
Age
31
Location
Tennessee
Mysidian Dollar
13,377
So this mod is one I got working thanks to reading posts by: Dinocanid, draugluin, and Abronsyth on an old post here: 1.3.1 Group Sorting Mod

This mod will work for 1.3.4, 1.3.5, and with tweaking it might work for 1.3.6 but I'm not sure.
It works by placing a sorting drop-down on your myadopts page and you can go through the groups that you made and hit "Go" to go to that specified group you selected in the drop-down. You can also create a group or delete a group from the myadopts page. To assign your pets to a group you have created you need to go to their manage page. You can also set how many groups a user can make, I have mine set to 8 but the original was 5.

So let's set up the database since it's the easiest.

You want to make a new database table called: adopts_pet_groups and include this info:

id INT 11 Auto Increment
name VARCHAR 15
username VARCHAR 20
uid INT 11


and it's done after you hit submit. Then you want to go to adopts_owned_adopts table and add a new structure with this info:

pet_group INT 11 As Defined 0

then submit. We're done with the database now.

__________________________________________

So the easier files to make is what we'll start with. We need to make two new PHP pages, a regular and a view.

First let's create: petgroup.php in your root folder where all the regular php pages are and inside paste this:
<?php

class PetgroupController extends AppController{

public function __construct(){
parent::__construct("member");
}

public function index(){
$mysidia = Registry::get("mysidia");

}

public function creategroup(){
$mysidia = Registry::get("mysidia");

}

public function deletegroup(){
$mysidia = Registry::get("mysidia");

}

}
?>​


Then it's done. Next, we'll need to go to the view files in the root folder and create: petgroupview.php and inside paste this:
<?php
class PetgroupView extends View{


public function index(){
$mysidia = Registry::get("mysidia");
$document = $this->document;
$document->setTitle("<center>Sort Testing!</center>");

//pet group variables? I think?
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$group = $_REQUEST["group"];
}
//var end

//convenient vars
$username = $mysidia->user->username;
$uid = $mysidia->user->uid;
//var end


//Pet sorting!
if(!$group == ""){
if(!is_numeric($group)){
$document->setTitle("No group");
$document->add(new Comment("Group does not exist."));
return;
}
else{
$row = $mysidia->db->select("pet_groups", array(), "uid='{$uid}' and id='{$group}'")->fetchObject();
if($row->id == $group and $row->uid == $uid){
$groupquery = "AND pet_group = '{$group}'";
}
else{ // Invalid group
$article_title = "No group";
$article_content = "Group does not exist.";
}
}
}
else{
$groupquery = "AND pet_group = '0'";
}

// We need to get all of the user's adoptables from the database and display them...
$rowsperpage = 10;
//$pagination = new Pagination($adopts, $query, $rowsperpage, "http://".constant("DOMAIN").constant("SCRIPTPATH")."/stable.php?group={$group}");
//$pagination->setPage($_GET[page]);
$pagination = new Pagination($total, 10, "myadopts");
$pagination->setPage($mysidia->input->get("page"));
//$stmt = $mysidia->db->query($query);
$stmt = $mysidia->db->select("owned_adoptables", array("aid"), "owner = '{$mysidia->user->username}' {$groupquery} ORDER BY totalclicks LIMIT {$pagination->getLimit()},{$rowsperpage}");
$groups = ""; // Get groups
$stmt2 = $mysidia->db->select("pet_groups", array(), "uid='{$uid}'");

$document->add(new Comment("
<b>Group:</b><br>
<form method='post' action='petgroup'>
<select name='group' id='group'>
<option value='0'>Ungrouped</option>"));

while($row = $stmt2->fetchObject()) {
$id = $row->id;
$name = $row->name;
$document->add(new Comment("<option value='{$id}'>{$name}</option>"));
}
$document->add(new Comment("
</select><br>
<input type='submit' value='Go'>
</form>
<a href='petgroup/creategroup'>Create a new group</a> | <a href='petgroup/deletegroup'>Delete a group</a>
<br><br>
<table class='table table-bordered table-dark'>
<thead>
<tr>
<th>Image</th>
<th>Info</th>
<th>Action</th>
</tr>
</thead>
<tbody>", FALSE));
while($row = $stmt->fetchObject()){
$adopt = new OwnedAdoptable($row->aid);
$image = $adopt->getImage();
$document->add(new Comment("
<tr>
<td><img src='{$adopt->getImage()}'></td>
<td><b><em>{$adopt->getName()}</b></em><br></br> Level {$adopt->getCurrentLevel()}<br></br> {$Gender}</td>
<td><a href='/myadopts/manage/{$row->aid}' class='btn btn-primary' style='width:200px; height:auto;'>Manage</a></td>
</tr>
", FALSE));
}
$document->add(new Comment("</table><br /><br />{$pagination->showPage()}"));
//Sorting end
}

public function creategroup(){
$mysidia = Registry::get("mysidia");
$document = $this->document;
$username = $mysidia->user->username;
$uid = $mysidia->user->uid;
$document->setTitle("Group Sorting");
$groupCount = $mysidia->db->select("pet_groups", array("uid"), "uid = '{$mysidia->user->uid}'")->rowCount();
if($groupCount >= 5) {
$document->setTitle("Sorry!");
$document->add(new Comment("You can only have 5 groups. <br><br> <a href='myadopts'>Go back?</a>"));
}
else{
$document->setTitle("Create a new group");
$document->add(new Comment("
<form method='post' action='creategroup'>
Here is where you can create a group type for your dinosaurs or pets.
<br><br>Recommended groups are:
<br>
<br><b>Dinosaurs
<br>Canines
<br>Felines
<br>Fowl
<br>Equine
<br>Bovine
<br>Fish</b>
<br>____________________<br>
<br><b>Group Name:</b><br>
<b>Note:</b> <i>Max length is 15 characters and you can have a total of 8 groups.</i>
<br><br>
<input type='text' name='groupname' id='groupname' maxlength='15' /><br><br>
<input id='sortbutton' type='submit' name='submit'>
</form>
<a href='https://dinotracks.mysidiahost.com/myadopts'>Go back to View Pets & Dinosaurs</a>
<style>
input#sortbutton {
font-size: 14px;
padding: 0px 0px;
width: 70px;
}
input#sortbutton {
font-size: 14px;
border-radius: 30px;
box-shadow: 0px 2px #828282;
background-color: #31c458;
cursor: pointer;
display: inline-block;
}
input#sortbutton:hover {
background-color: #000000;
color: #ffffff;
transform: translateY(1px);
}
</style>"));
}
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$groupCount = $mysidia->db->select("pet_groups", array("uid"), "uid = '{$mysidia->user->uid}'")->rowCount();
if($groupCount >= 5) {
$document->setTitle("Sorry!");
$document->add(new Comment("You can only have 8 groups. <br><br> <a href='https://dinotracks.mysidiahost.com/myadopts'>Go back to View Pets & Dinosaurs</a>"));
}
else{
$groupname = $_REQUEST["groupname"];
$mysidia->db->insert("pet_groups", array("username" => $username, "uid" => $uid, "name" => $groupname));
$group = $mysidia->db->select("pet_groups", array(), "name='{$groupname}' and uid='{$uid}'")->fetchObject();
$id = $group->id;
$document->setTitle("Created group ''{$groupname}''");
$document->add(new Comment("<br><b>
You created a new group called '{$groupname}'.</b><br><br>"));
}
}
}

public function deletegroup(){
$mysidia = Registry::get("mysidia");
$document = $this->document;
$username = $mysidia->user->username;
$uid = $mysidia->user->uid;
$stmt2 = $mysidia->db->select("pet_groups", array(), "uid='{$uid}'");
$document->setTitle("Delete a Group");
$groupCount = $mysidia->db->select("pet_groups", array("uid"), "uid = '{$mysidia->user->uid}'")->rowCount();
if($groupCount = 0) {
$document->setTitle("Sorry!");
$document->add(new Comment("You don't have any groups. <br><br> <a href='https://dinotracks.mysidiahost.com/myadopts'>Go back to View Pets & Dinosaurs</a>"));
}
else{
$document->setTitle("<center>Delete a group</center>");
$document->add(new Comment("
<b>Group:</b><br>
<form method='post' action='deletegroup'>
<select name='group' id='group'>
<option value='0' {$selected}>Ungrouped</option>"));

while($row = $stmt2->fetchObject()) {
$id = $row->id;
$name = $row->name;
$document->add(new Comment("<option value='{$id}'>{$name}</option>"));
}
$document->add(new Comment("
</select><br><br>
<input id='sortbutton' type='submit' value='Go'>
</form>
<a href='https://dinotracks.mysidiahost.com/myadopts'>Go back to View Pets & Dinosaurs</a>

<style>
input#sortbutton {
font-size: 14px;
padding: 0px 0px;
width: 70px;
}
input#sortbutton {
font-size: 14px;
border-radius: 30px;
box-shadow: 0px 2px #828282;
background-color: #31c458;
cursor: pointer;
display: inline-block;
}
input#sortbutton:hover {
background-color: #000000;
color: #ffffff;
transform: translateY(1px);
}
</style>"));
}

if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$group = $_REQUEST["group"];
$group_info = $mysidia->db->select("pet_groups", array(), "id='{$group}' and uid='{$uid}'")->fetchObject();
$document->setTitle("Deleted ''{$group_info->name}''");
$document->add(new Comment("<br><b>
'{$group_info->name}' has been deleted. All pets and dinosaurs that were in this group are now organized under: ''ungrouped''.</b><br><br>"));
$mysidia->db->update("owned_adoptables", array("pet_group" => 0), "pet_group = '{$group}'");
$mysidia->db->delete("pet_groups", "uid='{$uid}' AND id = '{$group}'");
}
}

}
?>​
 

Now is the trickier part, because the next files we need to add things into is the myadopts files. We'll be messing with the regular PHP page and the view. So you'll need to edit both files. We'll work with the myadopts.php first since it's easiest.

You want to paste this code at the closing tag of the freeze function:
public function changegroup(){
$mysidia = Registry::get("mysidia");
$this->setField("adopt", $this->adopt);
}​


and it's done. :) So worst for last lol. The myadoptsview.php file.

I pasted this code above the freeze function:
public function changegroup(){
$mysidia = Registry::get("mysidia");
$document = $this->document;
$document->setTitle(" Change group ");
$adopt = $this->getField("adopt");
$username = $mysidia->user->username;
$uid = $mysidia->user->uid;


$stmt20 = $mysidia->db->select("pet_groups", array(), "uid='{$uid}'");

$document->add(new Comment("Here is where you can assign <b>{$adopt->name}</b> to a group.<br><br>
<b>Choose a group:</b><br>

<form method='post' action=''>
<select name='groups' id='groups'>
^<option value='0'>Ungroup</option>"));

while($row = $stmt20->fetchObject()) {
$id = $row->id;
$name = $row->name;
$document->add(new Comment("
<option value='{$id}'>{$name}</option>"));
}
$document->add(new Comment("
</select> <br><br>
<input id='sortbutton' type='submit' value='Go'>
</form>

<a href='https://dinotracks.mysidiahost.com/myadopts'>Go back to View Pets & Dinosaurs</a>

<style>
input#sortbutton {
font-size: 14px;
padding: 0px 0px;
width: 70px;
}
input#sortbutton {
font-size: 14px;
border-radius: 30px;
box-shadow: 0px 2px #828282;
background-color: #31c458;
cursor: pointer;
display: inline-block;
}
input#sortbutton:hover {
background-color: #000000;
color: #ffffff;
transform: translateY(1px);
}
</style>
", FALSE));

if($mysidia->input->post("groups")){
$wahl = $mysidia->input->post("groups");
$new = $mysidia->db->select("pet_groups", array("name"), "id='{$wahl}'")->fetchcolumn();
$mysidia->db->update("owned_adoptables", array("pet_group" => $wahl), "aid ='{$adopt->getAdoptID()} ' and owner='{$mysidia->user->username}'");
$document->add(new Comment(" <br><br><b>Your adopt is now grouped to group: {$new} <br></b>
<br><a href='https://dinotracks.mysidiahost.com/myadopts/manage/{$adopt->getAdoptID()}'>Go back to manage {$adopt->name}</a>"));
}

}​


Next you'll want to add this code to your Manage function somewhere:
<a href='https://dinotracks.mysidiahost.com/petgroup/change/{$aid}'> Change {$name}'s Group</a>​


and last is the trickier one because it's been modified so much. But this is my public function chunk of code:
public function index(){
$mysidia = Registry::get("mysidia");
$document = $this->document;
$document->setTitle($this->lang->title);

$pagination = $this->getField("pagination");
$stmt = $this->getField("stmt")->get();
if($stmt->rowCount() == 0){
$document->addLangvar($this->lang->empty);
return;
}
//pet group variables? I think?
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$group = $_REQUEST["group"];
}
//var end

//convenient vars
$username = $mysidia->user->username;
$uid = $mysidia->user->uid;
//var end


//Pet sorting!
if(!$group == ""){
if(!is_numeric($group)){
$document->setTitle("No group");
$document->add(new Comment("Group does not exist."));
return;
}
else{
$row = $mysidia->db->select("pet_groups", array(), "uid='{$uid}' and id='{$group}'")->fetchObject();
if($row->id == $group and $row->uid == $uid){
$groupquery = "AND pet_group = '{$group}'";
}
else{ // Invalid group
$article_title = "No group";
$article_content = "Group does not exist.";
}
}
}
else{
$groupquery = "AND pet_group = '0'";
}

// We need to get all of the user's adoptables from the database and display them...
$rowsperpage = 10;
//$pagination = new Pagination($adopts, $query, $rowsperpage, "http://".constant("DOMAIN").constant("SCRIPTPATH")."/stable.php?group={$group}");
//$pagination->setPage($_GET[page]);
$pagination = new Pagination($total, 10, "myadopts");
$pagination->setPage($mysidia->input->get("page"));
//$stmt = $mysidia->db->query($query);
$stmt = $mysidia->db->select("owned_adoptables", array("aid"), "owner = '{$mysidia->user->username}' {$groupquery} ORDER BY totalclicks LIMIT {$pagination->getLimit()},{$rowsperpage}");
$groups = ""; // Get groups
$stmt2 = $mysidia->db->select("pet_groups", array(), "uid='{$uid}'");

$document->add(new Comment("
<b>Group:</b><br>
<form method='post' action='myadopts'>
<select name='group' id='group'>
<option value='0'>Ungrouped</option>"));

while($row = $stmt2->fetchObject()) {
$id = $row->id;
$name = $row->name;
$document->add(new Comment("<option value='{$id}'>{$name}</option>"));
}
$document->add(new Comment("
</select><br><br>
<input id='sortbutton' type='submit' value='Go'>
</form>
<a href='https://dinotracks.mysidiahost.com/petgroup/creategroup'>Create a New Group</a> | <a href='https://dinotracks.mysidiahost.com/petgroup/deletegroup'>Delete a Group</a>
<br><br>
<table class='table table-bordered table-dark'>
<thead>
<tr>
<th>Picture</th>
<th>Information</th>
<th>Type</th>
<th>Action</th>
</tr>
</thead>
<tbody>

<style>

#menu {
display: none;
}

input#sortbutton {
font-size: 14px;
padding: 0px 0px;
width: 70px;
}
input#sortbutton {
font-size: 14px;
border-radius: 30px;
box-shadow: 0px 2px #828282;
background-color: #31c458;
cursor: pointer;
display: inline-block;
}
input#sortbutton:hover {
background-color: #000000;
color: #ffffff;
transform: translateY(1px);
}
#footer {
display: none;
}

th {
border: 2px solid #000;
}
</style>", FALSE));
while($row = $stmt->fetchObject()){
$adopt = new OwnedAdoptable($row->aid);
$image = $adopt->getImage();
$document->add(new Comment("
<tr>
<td><img src='{$adopt->getImage()}'></td>
<td><center><b><em>{$adopt->getName()}</b></em><br></br> {$adopt->age}<br></br> {$adopt->sex}</center></td>
<td>{$adopt->getType()}
</td>
<td><center><a href='https://dinotracks.mysidiahost.com/myadopts/manage/{$row->aid}' class='btn btn-primary' style='width:200px; height:auto;'>Manage</a></center></td>", FALSE));
if ($adopt->hasVoter($mysidia->user, $date)){$document->add(new Comment("<td><p style='font-size:14px;color:green;'>Already Fed</p>
</td>
</tr>
", FALSE));
}
$document->add(new Comment("</table><br /><br />{$pagination->showPage()}"));
//Sorting end

}}​


you'll need to REMEMBER to go to all the https:// areas in these files (petgroupview.php, myadoptsview.php) and change my website URL to your own and if my public function code is too modified you can try this one and tweak it to fit you. It was one posted by Dinocanid:
public function index(){
$mysidia = Registry::get("mysidia");
$document = $this->document;
$document->setTitle("<center>Sort Testing!</center>");

//pet group variables? I think?
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$group = $_REQUEST["group"];
}
//var end

//convenient vars
$username = $mysidia->user->username;
$uid = $mysidia->user->uid;
//var end


//Pet sorting!
if(!$group == ""){
if(!is_numeric($group)){
$document->setTitle("No group");
$document->add(new Comment("Group does not exist."));
return;
}
else{
$row = $mysidia->db->select("pet_groups", array(), "uid='{$uid}' and id='{$group}'")->fetchObject();
if($row->id == $group and $row->uid == $uid){
$groupquery = "AND pet_group = '{$group}'";
}
else{ // Invalid group
$article_title = "No group";
$article_content = "Group does not exist.";
}
}
}
else{
$groupquery = "AND pet_group = '0'";
}

// We need to get all of the user's adoptables from the database and display them...
$rowsperpage = 10;
//$pagination = new Pagination($adopts, $query, $rowsperpage, "http://".constant("DOMAIN").constant("SCRIPTPATH")."/stable.php?group={$group}");
//$pagination->setPage($_GET[page]);
$pagination = new Pagination($total, 10, "myadopts");
$pagination->setPage($mysidia->input->get("page"));
//$stmt = $mysidia->db->query($query);
$stmt = $mysidia->db->select("owned_adoptables", array("aid"), "owner = '{$mysidia->user->username}' {$groupquery} ORDER BY totalclicks LIMIT {$pagination->getLimit()},{$rowsperpage}");
$groups = ""; // Get groups
$stmt2 = $mysidia->db->select("pet_groups", array(), "uid='{$uid}'");

$document->add(new Comment("
<b>Group:</b><br>
<form method='post' action='blank'>
<select name='group' id='group'>
<option value='0'>Ungrouped</option>"));

while($row = $stmt2->fetchObject()) {
$id = $row->id;
$name = $row->name;
$document->add(new Comment("<option value='{$id}'>{$name}</option>"));
}
$document->add(new Comment("
</select><br>
<input type='submit' value='Go'>
</form>
<a href='blank/creategroup'>Create a new group</a> | <a href='blank/deletegroup'>Delete a group</a>
<br><br>
<table class='table table-bordered table-dark'>
<thead>
<tr>
<th>Image</th>
<th>Info</th>
<th>Action</th>
</tr>
</thead>
<tbody>", FALSE));
while($row = $stmt->fetchObject()){
$adopt = new OwnedAdoptable($row->aid);
$image = $adopt->getImage();
$document->add(new Comment("
<tr>
<td><img src='{$adopt->getImage()}'></td>
<td><b><em>{$adopt->getName()}</b></em><br></br> Level {$adopt->getCurrentLevel()}<br></br> {$Gender}</td>
<td><a href='/myadopts/manage/{$row->aid}' class='btn btn-primary' style='width:200px; height:auto;'>Manage</a></td>
</tr>
", FALSE));
}
$document->add(new Comment("</table><br /><br />{$pagination->showPage()}"));
//Sorting end
}​


 
Looking great, I am sure this will help a lot of users since if I recall correctly, Group Sort was a very popular and demanded mod in its days. Maybe can convert it to Mys v.1.3.6 too.
 
Looking great, I am sure this will help a lot of users since if I recall correctly, Group Sort was a very popular and demanded mod in its days. Maybe can convert it to Mys v.1.3.6 too.
I'll definitely try to convert it later to work for 1.3.6 :) as well as other mods I made.
 
I got a problem. When I try to change the group of an pet, I get the following error message:
You specified an invalid action that cannot be completed.
 
I got a problem. When I try to change the group of an pet, I get the following error message:
You specified an invalid action that cannot be completed.
What version are you on? If you're using 1.3.6 there might be extra steps that have to be taken that I'm unaware of since I did the mod for 1.3.5. If you are on 1.3.5 it could be as simple as a bracket being off somewhere, or possibly a missed https area that you need to change to match your site's URL. The database can be finicky too like if you have a capital letter somewhere.
 
im having a little bit of trouble with where to put the codes into the myadopts.php and myadoptsview.php files. Ive tried putting them in the areas you said (before/after the freeze code) but it ended up not working! Im unsure if im doing something wrong. I made sure that all the URL links are correct, and the database as well. i think its maybe just an issue on my part of where im placing the code?
 
im having a little bit of trouble with where to put the codes into the myadopts.php and myadoptsview.php files. Ive tried putting them in the areas you said (before/after the freeze code) but it ended up not working! Im unsure if im doing something wrong. I made sure that all the URL links are correct, and the database as well. i think its maybe just an issue on my part of where im placing the code?
You may wait to install this one and wait until I can edit the tutorial because I discovered this mod I got functional from the mod I referenced from, it breaks pagination with viewing adopts.
 
You may wait to install this one and wait until I can edit the tutorial because I discovered this mod I got functional from the mod I referenced from, it breaks pagination with viewing adopts.
ah that makes sense, i think that’s what was happening for me, thanks for letting me know!! i’ll be sure to hold off on this mod for now then
 

Similar threads

Users who are viewing this thread

  • Forum Contains New Posts
  • Forum Contains No New Posts

Forum statistics

Threads
4,274
Messages
33,113
Members
1,602
Latest member
BerrieMilk
BETA

Latest Threads

Latest Posts

Top