function test_getAnimals()
 {
     //Arrange
     $type = "dog";
     $id = null;
     $test_animal_type = new AnimalType($type, $id);
     $test_animal_type->save();
     $test_type_id = $test_animal_type->getId();
     $name = 'Sparky';
     $gender = 'Male';
     $breed = 'Pug';
     $admit_date = '2015-08-18';
     $test_animal = new Animal($name, $gender, $breed, $admit_date, $test_type_id);
     $test_animal->save();
     $name2 = 'Senna';
     $gender2 = 'Male';
     $breed2 = 'Domestic Shorthair';
     $admit_date2 = '2015-07-28';
     $test_animal2 = new Animal($name, $gender, $breed, $admit_date, $test_type_id);
     $test_animal2->save();
     //Act
     $result = $test_animal_type->getAnimals();
     //Assert
     $this->assertEquals([$test_animal, $test_animal2], $result);
 }
Example #2
0
 public function perigo(Animal $p)
 {
     $p->emitirSom();
     $p->dormir();
     //$p->brincar(); Nao vale para todos
     //os animais.
 }
Example #3
0
 function getListCountryCityCountryLanguage($condicion = null, $parametros = array())
 {
     if ($condicion === null) {
         $condicion = "";
     } else {
         $condicion = "where {$condicion}";
     }
     $sql = " select co.*, ci.*, cl.*\r\n                    from country co\r\n                    left join city ci\r\n                    on co.Code = ci.CountryCode\r\n                    left join countrylanguage cl \r\n                    on co.Code =  cl.CountryCode {$condicion}";
     $this->bd->send($sql, $parametros);
     $r = array();
     $contador = 0;
     while ($fila = $this->bd->getRow()) {
         $country = new Cuidador();
         $country->set($fila);
         $city = new Animal();
         $city->set($fila, 15);
         //el numero es a partir del ultimo campo de country, para que coja los de city
         //$countrylanguage = new CountryLanguage();
         //$countrylanguage->set($fila, 20);
         $r[$contador]["country"] = $country;
         $r[$contador]["city"] = $city;
         //$r[$contador]["countrylanguage"]=$countrylanguage;
         $contador++;
     }
     return $r;
 }
Example #4
0
 public function removeAnimal(Animal $animal)
 {
     foreach ($this->_group as $key => $current) {
         if ($current->getAnimalName() == $animal->getAnimalName()) {
             unset($this->_group[$key]);
         }
     }
 }
 public function enqueue(Animal $animal)
 {
     $animal->setIndex($this->index++);
     if ($animal instanceof Dog) {
         $this->dogs->add($animal);
     } else {
         if ($animal instanceof Cat) {
             $this->cats->add($animal);
         } else {
             throw new InvalidArgumentException('Unknown animal type: ' + get_class($animal));
         }
     }
 }
Example #6
0
 public function register($aid, $name, $gender, $age, $type, $u_name, $u_gender, $u_city, $inviter)
 {
     $user = new User();
     $user->name = $u_name;
     $user->gender = $u_gender;
     $user->city = $u_city;
     $user->code = $this->createInviteCode();
     $user->inviter = $inviter;
     $user->gold = 500;
     $reward_items = array(1101 => 3, 1102 => 3, 1103 => 3, 1104 => 3, 1105 => 3, 1106 => 3, 1107 => 3, 1201 => 2, 1202 => 2, 1203 => 2, 1204 => 2, 1205 => 2, 1206 => 2, 1207 => 2, 1301 => 1, 1302 => 1, 1303 => 1, 1304 => 1, 1305 => 1, 2101 => 3, 2102 => 3, 2103 => 3, 2104 => 3);
     $user->items = serialize($reward_items);
     $user->save();
     if (!isset($aid)) {
         $animal = new Animal();
         $animal->name = $name;
         $animal->gender = $gender;
         $animal->age = $age;
         $animal->type = $type;
         $animal->from = substr($type, 0, 1);
         $animal->master_id = $user->usr_id;
         $animal->save();
         $aid = $animal->aid;
         $circle = new Circle();
         $circle->aid = $aid;
         $circle->usr_id = $user->usr_id;
         $circle->rank = 0;
         $circle->save();
     } else {
         $circle = new Circle();
         $circle->aid = $aid;
         $circle->usr_id = $user->usr_id;
         $circle->save();
     }
     $f = new Follow();
     $f->usr_id = $user->usr_id;
     $f->aid = $aid;
     $f->create_time = time();
     $f->save();
     $user->aid = $aid;
     $user->saveAttributes(array('aid'));
     $user->initialize();
     $user->rewardInviter();
     //$this->onRegister = array($user, 'initialize');
     //$this->onRegister = array($user, 'rewardInviter');
     $this->owner->usr_id = $user->usr_id;
     $this->owner->saveAttributes(array('usr_id'));
     $this->onRegister(new CEvent());
     return $user;
 }
Example #7
0
 public function describe()
 {
     $parentValue = parent::describe();
     //$parentValue .= $this->ssn;
     return $parentValue . ' but I am really a dog';
     //return parent::describe();
 }
 public function __construct($name, $address)
 {
     // Call the parent constructor to save time
     parent::__construct($name);
     // Assign an additional value
     $this->address = $address;
 }
 public function mostra()
 {
     #Chamando função da classe pai.
     parent::mostra();
     echo "Alimento: " . $this->alimento . "</br>";
     echo "Som: " . $this->som . "</br>";
 }
Example #10
0
 function getList($pagina = 1, $orden = "", $nrpp = Constant::NRPP)
 {
     $ordenPredeterminado = "{$orden}, NombreAnimal, ZonaCode, IDAnimal";
     if ($orden === "" || $orden === null) {
         $ordenPredeterminado = "NombreAnimal, ZonaCode, IDAnimal";
     }
     $registroInicial = ($pagina - 1) * $nrpp;
     $this->bd->select($this->tabla, "*", "1=1", array(), $ordenPredeterminado, "{$registroInicial}, {$nrpp}");
     $r = array();
     while ($fila = $this->bd->getRow()) {
         $animal = new Animal();
         $animal->set($fila);
         $r[] = $animal;
     }
     return $r;
 }
Example #11
0
 public function come($comida)
 {
     if ($comida == "carne" || $comida == "insecto") {
         parent::come($comida);
     } else {
         echo "A mí no me gusta ese tipo de comida";
     }
 }
Example #12
0
 public function come($comida)
 {
     if ($comida == "carne") {
         parent::come($comida);
     } else {
         echo "A mí no me gusta este tipo de comida. Quiero carne";
     }
 }
 public static function deleteAnimal($ìd)
 {
     try {
         Animal::delete($id);
         echo 'Animal excluído';
     } catch (PDOException $e) {
         echo 'Houve um erro: ' . $e;
     }
 }
 function getListCountryCityCountryLanguage($condicion = null, $parametros = array())
 {
     if ($condicion === null) {
         $condicion = "";
     } else {
         $condicion = "where {$condicion}";
     }
     $sql = " select co.*, ci.*, cl.*\r\n                    from country co\r\n                    left join city ci\r\n                    on co.Code = ci.CountryCode\r\n                    left join countrylanguage cl \r\n                    on co.Code =  cl.CountryCode {$condicion}";
     $this->bd->send($sql, $parametros);
     $r = array();
     while ($fila = $this->bd->getRow()) {
         $country = new Cuidador();
         $country->set($fila);
         $city = new Animal();
         $city->set($fila, 15);
         $countrylanguage = new CountryLanguage();
         $countrylanguage->set($fila, 20);
         $r[] = new CountryCityCountryLanguage($country, $city, $countrylanguage);
     }
     return $r;
 }
 /**
  *
  */
 public function testBatchWrite_NestedObjects_ObjectsExist()
 {
     $dogs = array();
     for ($i = 0; $i < 100; $i++) {
         $dog = new Dog();
         $dog->Name = 'Bob ' . $i;
         $dog->Country = 'Africa ' . $i;
         $dog->Type = 'Woof Dog ' . $i;
         $dog->Color = 'Brown #' . $i;
         $dogs[] = $dog;
     }
     $batch = new \Batch();
     $batch->write($dogs);
     for ($i = 0; $i < 100; $i++) {
         $this->assertTrue($dogs[$i]->exists());
         $id = $dogs[$i]->ID;
         $this->assertEquals($i + 1, $id);
     }
     $this->assertEquals(100, Dog::get()->count());
     foreach (Animal::get() as $i => $dog) {
         $this->assertEquals('Bob ' . $i, $dog->Name);
         $this->assertEquals('Brown #' . $i, $dog->Color);
     }
 }
Example #16
0
 /**
  * @return la liste des animaux à l'adoption
  */
 public static function getHomelessAnimals()
 {
     $db = DbManager::getPDO();
     $query = "SELECT * FROM Animal WHERE idState='" . self::$STATE_ADOPTION . "';";
     $res = $db->query($query)->fetchAll();
     for ($i = 0; $i < count($res); $i++) {
         $animal = Animal::getAnimalArrayFromFetch($res[$i]);
         $listAnimals[$animal['idAnimal']] = $animal;
     }
     return $listAnimals;
 }
Example #17
0
 /**
  * 
  * @param self $record
  * @param array $row
  */
 public static function populateRecord($record, $row)
 {
     parent::populateRecord($record, $row);
     $record->does = 'bark';
 }
<?php

function __autoload($className)
{
    require_once $className . '-class.php';
}
// ANIMAL CLASS
$kikker = new Animal('Kermit', 'male', 100);
$kat = new Animal('Dikkie', 'male', 100);
$kat->changeHealth(-10);
$dolfijn = new Animal('Flipper', 'female', 80);
?>


<!DOCTYPE html>
<html>
<head>
	<title>Oplossing PHPoefening 040</title>
</head>
	<body>
	

		<h1>Oplossing PHPoefening 040</h1>
		
		
		<p><?php 
echo $kikker->getName();
?>
 is van het geslacht <?php 
echo $kikker->getSex();
?>
Example #19
0
 public function Comer()
 {
     return parent::Comer() . " lo que me has dado ";
 }
Example #20
0
 public function __construct($name)
 {
     parent::__construct($name);
 }
<?php

/*   Load in classes     */
function __autoload($className)
{
    require 'classes/' . $className . '.php';
}
/*   Create instance of class Animal: $cat = new Animal("Name", "Gender","health");   */
$cat = new Animal("Buttons", "Male", 50);
$hippo = new Animal("Ms Hippo", "Female", 1000);
$flamingo = new Animal("Firenze", "Male", 200);
$hippo->changeHealth(-200);
/*  Create instance of class lion & zebra  */
$Lionel = new Lion("Lionel", "Male", 500, "Cool lion");
$Lionesse = new Lion("Lionesse", "Female", 400, "Awesome lion");
$Zebradude = new Zebra("Zebradude", "Male", 500, "Fast zebra");
$Zebradudette = new Zebra("Zebradudette", "Female", 300, "Good looking zebra");
?>

<!doctype html>
<html>
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <title>Opdracht classes: extends</title>
        <link rel="stylesheet" href="http://web-backend.local/css/global.css">
        <link rel="stylesheet" href="http://web-backend.local/css/facade.css">
        <link rel="stylesheet" href="http://web-backend.local/css/directory.css">
    </head>
    <body class="web-backend-opdracht">
        
<?php

function __autoload($className)
{
    include "classes/" . $className . ".php";
}
/*
__autoload("Animal");
__autoload("Lion");*/
$lion = new Animal("johan", "man", 10);
$cat = new Animal("bert", "vrouw", 50);
$dog = new Animal("Gerrit", "man", 24);
$simba = new Lion("lion", "Simba", "vrouw", 12);
$scar = new Lion("mountain lion", "scar", "man", 150);
$zeke = new Zebra("Leke", "man", 57421, "zebra");
$Brian = new Zebra("Bian", "vrouw", 5742, "zebra");
$lion->changeHealth(20);
?>

<!doctype html>
<html>
	<head>
		<title>Opdracht classes-extends</title>

	</head>

<body>

	<h1>Instanties van de classe Animal</h1>

	<p><?php 
 public function __construct($name, $gender, $health, $species)
 {
     parent::__construct($name, $gender, $health);
     $this->species = $species;
 }
<!doctype html>

<?php 
function __autoload($className)
{
    require_once 'classes/' . $className . '.php';
}
// ANIMAL CLASS
$rat = new Animal('Lou', 'male', 100);
$kat = new Animal('Dik', 'female', 100);
$koe = new Animal('Mia', 'female', 80);
$kat->changeHealth(-10);
$koe->changeHealth(+5);
// LION CLASS
$simba = new lion('Simba', 'male', 100, 'Congo lion');
$scar = new lion('Scar', 'female', 100, 'Kenia lion');
// ZEBRA CLASS
$zeke = new zebra('Zeke', 'male', 120, 'Quagga');
$zana = new zebra('Zana', 'female', 100, 'Selous');
?>

<html>
<head>
<meta charset="utf-8">
<title>Naamloos document</title>
</head>

<body>

<h1>Opdracht classes extends</h1>
Example #25
0
 public function treat(Animal $animal)
 {
     echo 'The vet has treated ' . $animal->getName();
 }
Example #26
0
 public function __construct($name, $sex, $health, $lionSpecies)
 {
     parent::__construct($name, $sex, $health);
     $this->lionSpecies = $lionSpecies;
 }
Example #27
0
            unlink(DBDIR . "animals/{$args['0']}");
        } else {
            throw new ERR_NOT_FOUND("Sorry, the barn does not contain {$args['0']}.");
        }
        $resp->status()->add_message("{$args['0']} is now dead. Good job!");
        return Worker::WORKER_SUCCESS;
    }
    function do_work($id, $resp)
    {
        $animal = $this->get_animal($id);
        if ($animal['species'] == 'Araneus cavaticus') {
            $this->spin_web($animal['name'], $resp);
        } else {
            $resp->status()->add_message($animal['name'] . " is happily rolling around in the mud!");
        }
    }
    function spin_web($name, $resp)
    {
        $resp->status()->progress(10);
        $resp->status()->add_message("{$name} is beginning to spin a web.");
        sleep(30);
        $resp->status()->progress(50);
        $resp->status()->add_message("{$name} is still spinning...");
        sleep(30);
        $messages = array('SOME PIG', 'TERRIFIC', 'RADIANT', 'HUMBLE');
        $message = $messages[array_rand($messages)];
        $resp->status()->add_message("{$name}'s web is complete! It says: '{$message}'");
    }
}
$worker = new Animal($argv[1]);
$worker->run();
 public function __construct($name, $address)
 {
     parent::__construct($name);
     //If there's no $name, it will use parent's $name
     $this->address = $address;
 }
Example #29
0
 public function actionModifyInfoApi($aid, $name, $gender, $age, $type)
 {
     $pattern = '/^[a-zA-Z0-9\\x{30A0}-\\x{30FF}\\x{3040}-\\x{309F}\\x{4E00}-\\x{9FBF}]+$/u';
     //$namelen = (strlen($name)+mb_strlen($name,"UTF8"))/2;
     $namelen = mb_strlen($name, "UTF8");
     if ($namelen > 8) {
         throw new PException('宠物昵称超过最大长度');
     }
     if (!preg_match($pattern, $name)) {
         throw new PException('宠物昵称含有特殊字符');
     }
     $transaction = Yii::app()->db->beginTransaction();
     try {
         $animal = Animal::model()->findByPk($aid);
         $animal->name = $name;
         $animal->age = $age;
         $animal->type = $type;
         $animal->gender = $gender;
         $animal->saveAttributes(array('name', 'age', 'type', 'gender'));
         $transaction->commit();
         $this->echoJsonData(array('isSuccess' => true));
     } catch (Exception $e) {
         $transaction->rollback();
         throw $e;
     }
 }
Example #30
0
            }
            function somAnimalFaz()
            {
                return 'O animal ' . $this->animal . ' faz o seguinte som:  ' . $this->som . '.<br/>';
            }
        };
    }
    function exibeMenagemSomAnimal()
    {
        return $this->name->somAnimalFaz();
    }
}
$meuPetA = new Animal("Gato", "Mia");
echo $meuPetA->exibeMenagemSomAnimal();
$meuPetB = new Animal("Cachorro", "Late");
echo $meuPetB->exibeMenagemSomAnimal();
$meuPetC = new Animal("Tico Francisco", "Canta");
echo $meuPetC->exibeMenagemSomAnimal();
?>

            </div>

            <div class="footer">
                <?php 
include 'views/partials/footer.php';
?>
            </div>
        </div>
    </body>