public function findByName($name, QueryOptionBag $options = null)
 {
     if (!$options) {
         $options = new QueryOptionBag();
     }
     $qb = $this->getEntityManager()->createQueryBuilder();
     $qb->select('a')->from('TermBundle:Term', 'a')->where('a.name LIKE :name')->setParameter('name', '%' . $name . '%');
     if ($options->has(QueryOption::LIMIT)) {
         $qb->setMaxResults($options->get(QueryOption::LIMIT));
     }
     $qb->orderBy('a.name', 'ASC');
     return $qb->getQuery()->getResult();
 }
 public function getAvailableGlobalAwardsOfInstitutionMedicalCenter(InstitutionMedicalCenter $institutionMedicalCenter, QueryOptionBag $options)
 {
     $globalAwardPropertyType = $this->getEntityManager()->getRepository('InstitutionBundle:InstitutionPropertyType')->findOneBy(array('name' => InstitutionPropertyType::TYPE_GLOBAL_AWARD));
     $sql = "SELECT a.value  FROM institution_medical_center_properties a WHERE a.institution_property_type_id = :propertyType AND a.institution_medical_center_id = :institutionMedicalCenterId";
     $statement = $this->getEntityManager()->getConnection()->prepare($sql);
     $statement->execute(array('propertyType' => $globalAwardPropertyType->getId(), 'institutionMedicalCenterId' => $institutionMedicalCenter->getId()));
     $result = array();
     $ids = array();
     if ($statement->rowCount() > 0) {
         while ($row = $statement->fetch(Query::HYDRATE_ARRAY)) {
             $ids[] = $row['value'];
         }
     }
     $qb = $this->getEntityManager()->createQueryBuilder()->select('a,b')->from('HelperBundle:GlobalAward', 'a')->innerJoin('a.awardingBody', 'b')->where('a.status = :globalAwardActiveStatus')->setParameter('globalAwardActiveStatus', GlobalAward::STATUS_ACTIVE)->orderBy('a.name', 'ASC');
     if ($options->has('globalAward.name')) {
         $qb->andWhere('a.name LIKE :globalAwardName')->setParameter('globalAwardName', '%' . $options->get('globalAward.name') . '%');
     }
     if ($options->has('globalAward.type')) {
         $qb->andWhere('a.type = :globalAwardType')->setParameter('globalAwardType', $options->get('globalAward.type'));
     }
     if (\count($ids)) {
         $qb->andWhere($qb->expr()->notIn('a.id', ':globalAwardIds'))->setParameter('globalAwardIds', $ids);
     }
     //echo $qb->getQuery()->getSQL(); exit;
     return $qb->getQuery()->getResult();
 }