src/Resolver/InterestFieldResolver.php line 20

Open in your IDE?
  1. <?php
  2. namespace App\Resolver;
  3. use Overblog\GraphQLBundle\Definition\Resolver\QueryInterface;
  4. use Doctrine\ORM\EntityManagerInterface;
  5. use App\BackendBundle\Model\DataTransfer\InterestFieldCount;
  6. use App\BackendBundle\Model\GraphQL\InterestField;
  7. use App\Entity\InterestField as InterestFieldBr;
  8. class InterestFieldResolver implements QueryInterface {
  9.     private EntityManagerInterface $em;
  10.     public function __construct(EntityManagerInterface $em) {
  11.         $this->em $em;
  12.     }
  13.     public function getFields() {
  14.         $interestFields $this->em->getRepository(InterestFieldBr::class)->findBy(array(), array('interestName' => 'ASC'));
  15.         $ifJobMapping $this->getInterestFieldJobMappings();
  16.         $interstFieldCount $this->getInterestFieldMappings();
  17.         $fields = array();
  18.         /* @var $interestFieldBr InterestFieldBr */
  19.         foreach ($interestFields as $interestFieldBr) {
  20.             $interestField = new InterestField();
  21.             $interestFieldID $interestFieldBr->getId();
  22.             $interestField->setId($interestFieldID);
  23.             $interestField->setInterestName($interestFieldBr->getInterestName());
  24.             $interestField->setSubHeading($interestFieldBr->getSubHeading());
  25.             if (array_key_exists($interestFieldID$ifJobMapping)) {
  26.                 $interestField->setCountJobs($ifJobMapping[$interestFieldID]);
  27.             }
  28.             $count $interstFieldCount->getCountByID($interestFieldID);
  29.             $interestField->setCountProviders($count);
  30.             $fields[] = $interestField;
  31.         }
  32.         return $fields;
  33.     }
  34.     private function getInterestFieldJobMappings() {
  35.         $connection $this->em->getConnection();
  36.         $sql "SELECT interest_field_id as id, count(*) as num "
  37.                 "FROM job_interest_field_mapping as jifm "
  38.                 "GROUP BY interest_field_id";
  39.         /* @var $stmt Statement */
  40.         $stmt $connection->prepare($sql);
  41.         $stmtResult $stmt->executeQuery();
  42.         $entries $stmtResult->fetchAllAssociative();
  43.         $result = array();
  44.         foreach ($entries as $data) {
  45.             $id $data['id'];
  46.             $count $data['num'];
  47.             $result[$id] = $count;
  48.         }
  49.         return $result;
  50.     }
  51.     private function getInterestFieldMappings() {
  52.         $interestFieldCount = new InterestFieldCount();
  53.         $this->getInterestFieldCompanyMappings($interestFieldCount);
  54.         $this->getInterestFieldSchoolMappings($interestFieldCount);
  55.         return $interestFieldCount;
  56.     }
  57.     private function getInterestFieldCompanyMappings(InterestFieldCount $interstFieldCount) {
  58.         $connection $this->em->getConnection();
  59.         $sql "SELECT interest_field_id as id, count(*) as num "
  60.                 "FROM company_profile_interest_field_mapping as cpifm "
  61.                 "LEFT JOIN company_profile as cp ON cpifm.company_profile_id=cp.id "
  62.                 "WHERE cp.is_visible=1 "
  63.                 "GROUP BY interest_field_id";
  64.         /* @var $stmt Statement */
  65.         $stmt $connection->prepare($sql);
  66.         $stmtResult $stmt->executeQuery();
  67.         $entries $stmtResult->fetchAllAssociative();
  68.         foreach ($entries as $data) {
  69.             $id $data['id'];
  70.             $count $data['num'];
  71.             $interstFieldCount->addCount($id$count);
  72.         }
  73.     }
  74.     private function getInterestFieldSchoolMappings(InterestFieldCount $interstFieldCount) {
  75.         $connection $this->em->getConnection();
  76.         $sql "SELECT interest_field_id as id, count(*) as num "
  77.                 "FROM school_interest_field_mapping as sifm "
  78.                 "LEFT JOIN school as sch ON sifm.school_id=sch.id "
  79.                 "LEFT JOIN school_profile as sp ON sp.school_id=sch.id "
  80.                 "WHERE sp.is_visible=1 "
  81.                 "GROUP BY interest_field_id";
  82.         /* @var $stmt Statement */
  83.         $stmt $connection->prepare($sql);
  84.         $stmtResult $stmt->executeQuery();
  85.         $entries $stmtResult->fetchAllAssociative();
  86.         foreach ($entries as $data) {
  87.             $id $data['id'];
  88.             $count $data['num'];
  89.             $interstFieldCount->addCount($id$count);
  90.         }
  91.     }
  92. }