private function updateDirectoryMapping($deleteMapping) { $es = $this->getContainer()->get('es_client'); // Elastic Search client // Do it for the course mapping $params = array(); $params['index'] = $this->getContainer()->getParameter('es_index_name'); $params['type'] = 'course'; if ($deleteMapping) { $es->indices()->deleteMapping($params); } // Get the mapping $cDoc = new CourseDocumentType(new Course(), $this->getContainer()); $mapping = array('_source' => array('enabled' => true), 'properties' => $cDoc->getMapping()); $params['body']['course'] = $mapping; $es->indices()->putMapping($params); // Credential Mapping $params = array(); $params['index'] = $this->getContainer()->getParameter('es_index_name'); $params['type'] = 'credential'; $credentialDoc = new CredentialDocumentType(new \ClassCentral\CredentialBundle\Entity\Credential(), $this->getContainer()); if ($deleteMapping) { $es->indices()->deleteMapping($params); } $mapping = array('_source' => array('enabled' => true), 'properties' => $credentialDoc->getMapping()); $params['body']['credential'] = $mapping; $es->indices()->putMapping($params); // Suggest Document mapping $params = array(); $params['index'] = $this->getContainer()->getParameter('es_index_name'); $params['type'] = 'suggest'; if ($deleteMapping) { $es->indices()->deleteMapping($params); } // Get the mapping $sDoc = new SuggestDocumentType(new Course(), $this->getContainer()); $mapping = array('_source' => array('enabled' => true), 'properties' => $sDoc->getMapping()); $params['body']['suggest'] = $mapping; $es->indices()->putMapping($params); }
/** * Index the particular entity * @param $entity */ public function index($entity, $indexName = null) { $this->esClient = $this->container->get('es_client'); // Index the course if ($entity instanceof Course) { $cDoc = new CourseDocumentType($entity, $this->container); $doc = $cDoc->getDocument($this->getIndexName('es_index_name')); $this->esClient->index($doc); // Add the course to the Suggest documents if ($entity->getStatus() < 100) { $csDoc = new SuggestDocumentType($entity, $this->container); $doc = $csDoc->getDocument($this->getIndexName('es_index_name')); $this->esClient->index($doc); } } // Index the Credential if ($entity instanceof Credential) { $cDoc = new CredentialDocumentType($entity, $this->container); $doc = $cDoc->getDocument($this->getIndexName('es_index_name')); $this->esClient->index($doc); if ($entity->getStatus() < 100) { $csDoc = new SuggestDocumentType($entity, $this->container); $doc = $csDoc->getDocument($this->getIndexName('es_index_name')); $this->esClient->index($doc); } } // Index the institution if ($entity instanceof Institution) { // Add the institution to document suggestions $isDoc = new SuggestDocumentType($entity, $this->container); $doc = $isDoc->getDocument($this->getIndexName('es_index_name')); $this->esClient->index($doc); } // Index the Language if ($entity instanceof Language) { // Add Language to document suggestions $isDoc = new SuggestDocumentType($entity, $this->container); $doc = $isDoc->getDocument($this->getIndexName('es_index_name')); $this->esClient->index($doc); } if ($entity instanceof Stream) { $sDoc = new SubjectDocumentType($entity, $this->container); $doc = $sDoc->getDocument($this->getIndexName('es_index_name')); $this->esClient->index($doc); // Add the subject to document suggestions $ssDoc = new SuggestDocumentType($entity, $this->container); $doc = $ssDoc->getDocument($this->getIndexName('es_index_name')); $this->esClient->index($doc); } if ($entity instanceof Initiative) { $ssDoc = new SuggestDocumentType($entity, $this->container); $doc = $ssDoc->getDocument($this->getIndexName('es_index_name')); $this->esClient->index($doc); } if ($entity instanceof ESJob) { $jobDoc = new ESJobDocumentType($entity, $this->container); $doc = $jobDoc->getDocument($this->getIndexName('es_scheduler_index_name')); $this->esClient->index($doc); } if ($entity instanceof ESJobLog) { $jobLogDoc = new ESJobLogDocumentType($entity, $this->container); $doc = $jobLogDoc->getDocument($this->getIndexName('es_scheduler_index_name')); $this->esClient->index($doc); } }
public function getBody() { $body = array(); $credentialService = $this->container->get('credential'); $c = $this->entity; // Alias for entity $formatter = $c->getFormatter(); $body['name'] = $c->getName(); $body['id'] = $c->getId(); $body['slug'] = $c->getSlug(); $body['oneLiner'] = $c->getOneLiner(); $body['subTitle'] = $c->getSubTitle(); $body['price'] = $c->getPrice(); $body['pricePeriod'] = $c->getPricePeriod(); $body['displayPrice'] = $formatter->getPrice(); $body['durationMin'] = $c->getDurationMin(); $body['durationMax'] = $c->getDurationMax(); $body['displayDuration'] = $formatter->getDuration(); $body['workloadMin'] = $c->getWorkloadMin(); $body['workloadMax'] = $c->getDurationMax(); $body['workloadType'] = $c->getWorkloadType(); $body['displayWorkload'] = $formatter->getWorkload(); $body['url'] = $c->getUrl(); $body['description'] = $c->getDescription(); $body['status'] = $c->getStatus(); $body['image'] = $credentialService->getImage($c); $body['cardImage'] = $credentialService->getCardImage($c); $body['subjectSlug'] = null; $body['subject'] = null; if ($c->getSubject()) { $body['subjectSlug'] = $c->getSubject(); $body['subject'] = Credential::$SUBJECTS[$c->getSubject()]; } $orgs = array(); // Array of names of organizations who are involved in creating the credential // Provider $body['provider'] = array(); if ($c->getInitiative()) { $provider = $c->getInitiative(); $body['certificateName'] = $formatter->getCertificateName(); $body['certificateSlug'] = $formatter->getCertificateSlug(); $bulletOrg = "{$formatter->getCertificateName()} via "; $orgs[] = $provider->getName(); // Populate the organization list } else { // create an independent provider $provider = new Initiative(); $provider->setName('Independent'); $provider->setCode('independent'); } $pDoc = new ProviderDocumentType($provider, $this->container); $body['provider'] = $pDoc->getBody(); // Institutions $body['institutions'] = array(); $institutions = array(); foreach ($c->getInstitutions() as $ins) { $iDoc = new InstitutionDocumentType($ins, $this->container); $body['institutions'][] = $iDoc->getBody(); $orgs[] = $ins->getName(); // Populate the organization list } // Get the ratings $rating = $credentialService->calculateAverageRating($this->entity); $body['rating'] = $rating['rating']; $body['formattedRating'] = ReviewUtility::formatRating($rating['rating']); // Rounds the rating to the nearest 0.5 $body['numRatings'] = $rating['numRatings']; $courses = array(); foreach ($this->entity->getCourses() as $course) { $cDoc = new CourseDocumentType($course, $this->container); $courses[] = $cDoc->getBody(); } $body['courses'] = $courses; $body['isSponsered'] = $c->isSponsored(); // Build the bullet points in the array $bulletPoints = array(); $bulletPoints[] = $bulletOrg . UniversalHelper::commaSeparateList($orgs); // Bullet Price and Duration $bulletPriceAndDuration = $formatter->getPrice(); $displayDuration = $formatter->getDuration(); if ($displayDuration) { $bulletPriceAndDuration .= ' for ' . $displayDuration; } $bulletPoints[] = $bulletPriceAndDuration; // Bullet effort $effort = $formatter->getWorkload(); if ($effort) { $bulletPoints[] = $effort . ' of effort'; } if ($provider->getName() == 'Coursera') { $bulletPoints[] = count($body['courses']) - 1 . ' courses + capstone project '; } elseif ($provider->getName() == 'HBX') { $bulletPoints[] = '3 courses and a final exam. Application Required'; } if ($formatter->getEnrollment()) { $bulletPoints[] = $formatter->getEnrollment(); } $body['bulletPoints'] = $bulletPoints; return $body; }