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)
-   -   A way to exclude pets from daycare? (http://www.mysidiaadoptables.com/forum/showthread.php?t=4226)

Infernette 08-04-2013 06:00 PM

A way to exclude pets from daycare?
 
I was wondering if there was a way to exclude pets from the daycare once clicked for the day, I know there is ways to tell if the pet is clicked but I don't know how to exclude it from the query.

IntoRain 08-05-2013 12:41 AM

Maybe you have to add a "wasClicked" attribute to the tables? I did this little crappy code down here, I'm pretty sure it has bugs and maybe it's not the best solution (when I ask for a sizeof of the array it outputs 34 instead of 33, so it's doing extra stuff :D), but hey it's a start... right?

I don't know the documentation of this project, what the functions do etc... I'm pretty new xDWe have to try to find out where to restrict addition of adoptables to the daycare. That's the getConditions() function.
The basic idea was to take the IDs that have been clicked and compare the adoptable id to them. This condition is saved in the $conditions variable that will be used when selecting adoptables from owned_adoptables in the function above getConditions() (I believe it's getAdopts()).

In the class_daycare, getConditions(), before returning:

PHP Code:

      $date = new DateTime;
               
$datetime $date->format('Y-m-d');
                
$user $mysidia->user;
                
//take adoptable IDs that have been clicked by the user in today's date
        
$idsM $mysidia->db->select("vote_voters", array("adoptableid"), "date='{$datetime}' and username='{$user->username}'")->fetchAll(PDO::FETCH_COLUMN);
        
$adoptsIDs = new ArrayObject($idsM);
        
//append to the conditions string an aid restrictions (aid can't be equal to the IDs in idsM) - yes, for each adoptable it has to compare its ID to all of the IDs ._.
        
for($index 0$index sizeof($adoptsIDs); $index++)
        {
            
//echo $datetime;
            
$conditions .= " and aid != '{$adoptsIDs[$index]}'";
        } 

I only tested it twice with two different users... It seems to work with today's date, but when using writing down a specific date (yesterday's date) it returned 34 instead of 33, so I don't know what it's doing as an extra? This is not a good solution, but maybe it will help you somehow :/ edit: hm, I counted wrong... Apparently everything's fine(?), but still it's not an optimal solution (the amount of comparisons it has to do...) And it only works if you refresh the page, so it won't take out an egg from the daycare when it's clicked of course, it updates the array after refresh

I also tried to restrict their appearance (in levelup, in daycare() function) instead of restricting addition, but I don't really know how the page is set up so it was errors after errors.

Infernette 08-05-2013 10:05 AM

That works perfectly! Refeshing is what I meant, and it seems to flow nicely (I also have an upgraded server package so yeah, dunno how well it'd work for free hosters. XD)

IntoRain 08-05-2013 10:20 AM

I love your site so Glad I could help! I really don't know another way other than comparing IDs, but the increasing number of IDs worries me xD Constructing another table not_clicked and selecting from owned_adoptables MINUS selecting from vote_voters, but I really don't know how to work with the date there xD But if it works I'm glad I could help ^^


All times are GMT -5. The time now is 05:22 AM.

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