public function findByName($name, $limit = null)
 {
     $queryOptions = new QueryOptionBag();
     if ($limit) {
         $queryOptions->add(QueryOption::LIMIT, $limit);
     }
     return $this->doctrine->getRepository('TermBundle:Term')->findByName($name, $queryOptions);
 }
 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();
 }
 /**
  * Load available global awards of an institution. Used in autocomplete fields
  *
  * @param Request $request
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function ajaxMedicalCenterGlobalAwardSourceAction(Request $request)
 {
     $term = \trim($request->get('term', ''));
     $type = $request->get('type', null);
     $types = \array_flip(GlobalAwardTypes::getTypeKeys());
     $type = \array_key_exists($type, $types) ? $types[$type] : 0;
     $output = array();
     $options = new QueryOptionBag();
     $options->add('globalAward.name', $term);
     if ($type) {
         $options->add('globalAward.type', $type);
     }
     $awards = $this->getDoctrine()->getRepository('InstitutionBundle:InstitutionMedicalCenterProperty')->getAvailableGlobalAwardsOfInstitutionMedicalCenter($this->institutionMedicalCenter, $options);
     foreach ($awards as $_award) {
         $output[] = array('id' => $_award->getId(), 'label' => $_award->getName(), 'awardingBody' => $_award->getAwardingBody()->getName());
     }
     return new Response(\json_encode($output), 200, array('content-type' => 'application/json'));
 }
 public function getRecentlyAddedMedicalCenters(Institution $institution, QueryOptionBag $options = null)
 {
     $qb = $this->doctrine->getEntityManager()->createQueryBuilder();
     $qb->select('i')->from('InstitutionBundle:InstitutionMedicalCenter', 'i')->where('i.institution = :institutionId')->orderBy('i.dateCreated', 'desc')->setParameter('institutionId', $institution->getId());
     if ($limit = $options->get(QueryOption::LIMIT, null)) {
         $qb->setMaxResults($limit);
     }
     return $qb->getQuery()->getResult();
 }