View Single Post
  #5  
Old 09-02-2013, 02:17 PM
RandomFrog RandomFrog is offline
Member
 
Join Date: Aug 2013
Posts: 13
Gender: Female
Credits: 1,665
RandomFrog is on a distinguished road
Default

Okay, here is the code:

PHP Code:
<?php

class BreedingController extends AppController{

    private 
$view;
    private 
$subController;

    public function 
__construct(){
        
parent::__construct("member");
        
$mysidia Registry::get("mysidia");        
        
$userStatus $mysidia->user->getstatus();
        if(
$userStatus->canbreed == "no") throw new NoPermissionException("It appears that you have been banned for breeding.");        
    }
    
    public function 
index(){
        
$mysidia Registry::get("mysidia");
        
$document $mysidia->frame->getDocument();
        
$settings = new BreedingSetting($mysidia->db);
        if(
$settings->system != "enabled") throw new InvalidActionException($mysidia->lang->system);
        
        if(
$mysidia->input->post("submit")){
            if(
$mysidia->input->post("female") == "none" or $mysidia->input->post("male") == "none"){
                  throw new 
InvalidIDException("You haven't selected a male or female adoptable.");
            }
            
            try{
                
$female = new OwnedAdoptable($mysidia->input->post("female"), $mysidia->user->username);
                
$male = new OwnedAdoptable($mysidia->input->post("male"), $mysidia->user->username);
                
$breeding = new Breeding($female$male$settings); 
                
$validator $breeding->getValidator("all");
                
$validator->validate();
            }
            catch(
AdoptNotfoundException $ane){
                throw new 
InvalidIDException("There is no adoptable that has that ID!");
            }
            catch(
BreedingException $bre){                
                
$status $bre->getmessage();
                
$validator->setStatus($status);
                throw new 
InvalidActionException($mysidia->lang->{$status});
            }
            
            if(
$settings->method == "advanced"$species $breeding->getBabySpecies();
            
$breeding->getBabyAdopts($species);
            
$breeding->breed($adopts);
            
$num $breeding->countOffsprings();

            if(
$num 0){
                
$document->setTitle("Breeding is Successful!");
                
$document->add(new Comment("Congratulations! Breeding is successful, you have acquired {$breeding->countOffsprings()} baby adoptables from the breeding center."));
                
$document->add(new Comment("Click on one of the links to see them!"));
                
$offsprings $breeding->getOffsprings();
                
$offspringID $mysidia->db->select("owned_adoptables", array("aid"), "1 ORDER BY aid DESC LIMIT 1")->fetchColumn() - $num 1;
                foreach(
$offsprings as $offspring){
                    
$image $offspring->getEggImage("gui");
                    
$link = new Link("myadopts/manage/{$offspringID}"$image);
                    
$document->add($link);
                    
$offspringID++;
                }
            }
            else{
                
$document->setTitle("Breeding has failed...");
                
$document->addLangvar(It did not workMaybe you can try again!");
            }            
            return;
        }
        
        
$document->setTitle($mysidia->lang->title);
        
$document->addLangvar($mysidia->lang->default.$mysidia->lang->money);
        
$document->addLangvar("{$settings->cost} {$mysidia->settings->cost}");
        
$document->addLangvar($mysidia->lang->warning.$mysidia->lang->select);
        
$breedingForm = new Form("breedingform", "breeding", "post");
        
$current = new DateTime;
        
$lasttime = $current->getTimestamp() - (($settings->interval) * 24 * 60 * 60);
        
        
$stmt = $mysidia->db->select("owned_adoptables", array("aid"), "owner '{$mysidia->user->username}' AND gender 'f' AND currentlevel >= {$settings->level} AND lastbred <= '{$lasttime}'");
        if(
$stmt->rowcount() == 0) $document->addLangvar($mysidia->lang->female);
        else{ 
            
$female = new DropdownList("female");
            
$femaleIDs = $stmt->fetchAll(PDO::FETCH_COLUMN);    
            
$femaleNames = $mysidia->db->select("owned_adoptables", array("name"), "owner '{$mysidia->user->username}' AND gender 'f' AND currentlevel >= {$settings->level} AND lastbred <= '{$lasttime}'")->fetchAll(PDO::FETCH_COLUMN);
            
$female->add(new Option("None Selected", "none"));
            
$female->fill($femaleNames$femaleIDs);
            
$breedingForm->add(new Comment("Female", FALSE));
            
$breedingForm->add($female);
        }    
  
        
$stmt = $mysidia->db->select("owned_adoptables", array(), "owner '{$mysidia->user->username}' AND gender 'm' AND currentlevel >= {$settings->level} AND lastbred <= '{$lasttime}'");
        if(
$stmt->rowcount() == 0) $document->addLangvar($mysidia->lang->male);
        else{
            
$male = new DropdownList("male");
            
$maleIDs = $stmt->fetchAll(PDO::FETCH_COLUMN);    
            
$maleNames = $mysidia->db->select("owned_adoptables", array("name"), "owner '{$mysidia->user->username}' AND gender 'm' AND currentlevel >= {$settings->level} AND lastbred <= '{$lasttime}'")->fetchAll(PDO::FETCH_COLUMN);
            
$male->add(new Option("None Selected", "none"));
            
$male->fill($maleNames$maleIDs);
            
$breedingForm->add(new Comment("Male", FALSE));
            
$breedingForm->add($male);
        }
        
        
$breedingForm->add(new PasswordField("hidden", "breed", "yes"));
        
$breedingForm->add(new Button("Let's breed!", "submit", "submit"));
        $document->add($breedingForm);    
    }
}
?>
It also WAS working when I installed it.
Reply With Quote