コード例 #1
0
 public function search(Survivor $survivor)
 {
     $queryBuilder = $this->createQueryBuilder('s');
     $queryBuilder->leftJoin('s.camp', 'c')->addSelect('c')->where('s.firstname = :firstname')->setParameter('firstname', ucfirst($survivor->getFirstname()))->andWhere('s.lastname = :lastname')->setParameter('lastname', ucfirst($survivor->getLastname()));
     if (!empty($survivor->getBirthday())) {
         $queryBuilder->andWhere('s.birthday = :birthday')->setParameter('birthday', $survivor->getBirthday());
     }
     if (!empty($survivor->getEyesColor())) {
         $queryBuilder->andWhere('s.eyesColor = :eyescolor')->setParameter('eyescolor', $survivor->getEyesColor());
     }
     if (!empty($survivor->getWeight())) {
         //Convert weight if necessary
         if ($survivor->getWeightUnit() == "kg") {
             $converter = new Converter();
             $weight = $converter->fromKgToLb($survivor->getWeight());
             $survivor->setWeight($weight);
         }
         $queryBuilder->andWhere($queryBuilder->expr()->between(':weight', 's.weight - 5', 's.weight + 5'))->setParameter('weight', $survivor->getWeight());
     }
     if (!empty($survivor->getHeight())) {
         //Convert height if necessary
         if ($survivor->getHeightUnit() == "cm") {
             $converter = new Converter();
             $height = $converter->fromCmToInch($survivor->getHeight());
             $survivor->setHeight($height);
         }
         $queryBuilder->andWhere($queryBuilder->expr()->between(':height', 's.height - 5', 's.height + 5'))->setParameter('height', $survivor->getHeight());
     }
     if (!empty($survivor->getHairColor())) {
         $queryBuilder->andWhere('s.hairColor = :haircolor')->setParameter('haircolor', $survivor->getHairColor());
     }
     return $queryBuilder->getQuery()->getResult();
 }
コード例 #2
0
 /**
  * Convert weight and height if necessary
  * 
  * @param \Xali\Bundle\SurvivorBundle\Entity\Survivor $survivor
  * @param \Xali\Bundle\SurvivorBundle\Converter\Converter $converter
  * @author Anthony Bocci <*****@*****.**>
  */
 private function convertWeightAndHeight($survivor, $converter)
 {
     //If weight unit is kilogrammes
     if ($survivor->getWeightUnit() == "kg") {
         $survivor->setWeight($converter->fromKgToLb($survivor->getWeight()));
     }
     //If height unit is centimeters
     if ($survivor->getHeightUnit() == "cm") {
         $survivor->setHeight($converter->fromCmToInch($survivor->getHeight()));
     }
 }
コード例 #3
0
ファイル: ConverterTest.php プロジェクト: anthonybocci/Xali
 /**
  * Test if 1 inch equals to 2.54 centimeters
  */
 public function testfromInchToCm()
 {
     $converter = new Converter();
     $result = $converter->fromInchToCm(1);
     $this->assertEquals(2.54, $result);
 }