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.1 Group sort (http://www.mysidiaadoptables.com/forum/showthread.php?t=3672)

SilverDragonTears 01-16-2017 11:38 AM

Ah makes sense :)

parayna 06-11-2017 05:52 PM

Has anyone made any progress with this..? :3 It's a feature I've been trying to implement but have been failing badly at... XD

Dinocanid 12-16-2017 08:59 PM

I managed to convert the main part of the script, which involves creating groups and sorting pets on the myadopts index.
http://www.clipular.com/c/5136285479...3wLqmwuS_9ZWD0
That's the table setup for adopts_pet_groups. You need new column in owned_adoptables called "pet_group". (Not "group! "group" is a reserved name in phpMyAdmin.) Also make sure that "default as defined" is set to 0.
I did the entire thing in blank.php/blankview.php for testing purposes, so that's why it looks the way it does.
PHP Code:

<?php
class BlankView 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($total10"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   
    
}
    
    public function 
creategroup(){
    
$mysidia Registry::get("mysidia");
    
$document $this->document;
    
$username $mysidia->user->username;
    
$uid $mysidia->user->uid;    
    
//$document->setTitle("<center>Sort Testing!</center>");
                  
$groupCount $mysidia->db->select("pet_groups", array("uid"), "uid = '{$mysidia->user->uid}'")->rowCount();
                if(
$groupCount >= 5) {
                    
$document->setTitle("<center>Sorry!</center>");
                    
$document->add(new Comment("You can only have 5 groups. <br><br> <a href='myadopts'>Go back?</a>"));
                }
                else{
                 
$document->setTitle("<center>Create a new group</center>");
                 
$document->add(new Comment("
                     <form method='post' action='creategroup'>
                        <b>Group Name:</b> <br>
                        Max length is 15.<br>
                        <input type='text' name='groupname' id='groupname' maxlength='15' /><br>
                        <input type='submit' name='submit'>
                    </form>
                    <a href='/blank'>Go back</a>"
));
            }
            if (
$_SERVER['REQUEST_METHOD'] == 'POST') {
                
$groupCount $mysidia->db->select("pet_groups", array("uid"), "uid = '{$mysidia->user->uid}'")->rowCount();
                    if(
$groupCount >= 5) {
                        
$document->setTitle("<center>Sorry!</center>");
                        
$document->add(new Comment("You can only have 5 groups. <br><br> <a href='myadopts'>Go back?</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("
                         You created a new group called '
{$groupname}'.<br><br>
                        <a href='/blank'>Go back</a>"
));
                    }
            }
    }
    
    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("<center>Sort Testing!</center>");
                  
$groupCount $mysidia->db->select("pet_groups", array("uid"), "uid = '{$mysidia->user->uid}'")->rowCount();
                if(
$groupCount 0) {
                    
$document->setTitle("<center>Sorry!</center>");
                    
$document->add(new Comment("You don't have any groups. <br><br> <a href='/blank'>Go back?</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>
                        <input type='submit' value='Go'>
                        </form>
                        <a href='/blank'>Go back</a>"
));
            }
            
            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("
                         '
{$group_info->name}' has been deleted. All pets organized under it are now ''ungrouped''.<br><br>
                        <a href='/blank'>Go back</a>"
));
                    
$mysidia->db->update("owned_adoptables", array("pet_group" => 0), "pet_group = '{$group}'");
                           
$mysidia->db->delete("pet_groups""uid='{$uid}' AND id = '{$group}'");    
            }
    }
    
}
?>

PHP Code:

<?php

class BlankController extends AppController{

    
    public function 
index(){        
    
$mysidia Registry::get("mysidia");
    
    }
    
    public function 
creategroup(){        
    
$mysidia Registry::get("mysidia");
    
    }
    
    public function 
deletegroup(){        
    
$mysidia Registry::get("mysidia");
    
    }
}
?>

This version doesn't use AJAX, but it basically works the same. It just handles the variables internally instead of passing it to the URL.

Pear 12-17-2017 02:07 PM

YAAAAS! :D Thanks Dinocanid! :D Makes me want to make a new site now that people can group their pets...I've wanted this kind of feature for sooo long! x'3

parayna 12-17-2017 02:51 PM

I'll definitely be adding it to my site too! Thank you! It'll make it so much easier to sort pets. I might now replace the faulty sort option with groups because then people can custom group all their pets together! :D

Dinocanid 12-17-2017 03:51 PM

Yeah, the sort mod didn't work out so well ^^; hopefully a fix is found soon. This one works better imo though. I didn't include a function to actually add pets to those groups yet, but I'm planning to. It's also possible to do it yourself in the meantime with a form that updates the pet's group to whatever the user selected.

draugluin 08-31-2018 09:38 AM

and here come's the part, which allows you, to assign a group (from the existing groups) to your adopt.

I hope, it works indeed for all :wutno:

in myadopts.php ... after the closing tag ( } ) for the freeze-function


PHP Code:

public function changegroup(){        
    
$mysidia Registry::get("mysidia");
    
$this->setField("adopt"$this->adopt);  
    } 

and in myadoptsview.php after the closing tag ( } ) for the freeze-function

PHP Code:

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("
                <b>Choose a group:</b><br>
                 
                 <form method='post' action=''>
                        <select name='groups' id='groups'>
                        ^<option value='0'>choose</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>  
                        <input type='submit' value='go'>
                    </form>
                      
                    "
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_groups" => $new), "aid ='{$adopt->getAdoptID()} ' and owner='{$mysidia->user->username}'");  
             
$document->add(new Comment("  Your adopt is now grouped to :{$new} <br>
                        <a href='/myadopts/manage/
{$adopt->getAdoptID()}'>back to the adopt</a>   ")); 
          }        
                    
        
          
    } 

and somewhere by the list of name, type etc.

PHP Code:

 <a href='/myadopts/changegroup/{$aid}'>(changegroup)</a


have fun :wutno:

Abronsyth 09-04-2018 03:08 PM

@draugluin, so what I'm getting (from looking at that briefly) is that it allows you to assign your pet to a group via that pet's manage page? That is very handy!

EDIT:
Made some fixes to it so that it works properly, just replace the database update line with;
PHP Code:

$mysidia->db->update("owned_adoptables", array("pet_group" => $wahl), "aid ='{$adopt->getAdoptID()} ' and owner='{$mysidia->user->username}'"); 


draugluin 09-10-2018 04:01 AM

@ Abronsyth

right... it should be the continuation of Dinocanids script.

but ... $wahl is just the id-number of the pet-groups ... $new is the name.

edit:

http://wolves.16mb.com/w33.jpg

Abronsyth 09-10-2018 10:03 AM

Aye, the pet-group's ID is what needs to be added to the database for the pet to be "assigned" to it, though, hence replacing with $wahl :)


All times are GMT -5. The time now is 08:46 AM.

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