public function __invoke(JobEvent $event) { $job = $event->getJobEntity(); $invoiceAddressDraft = $this->draftRepository->findByJobId($job->getId()); $invoiceAddress = $invoiceAddressDraft->getInvoiceAddress(); $snapshotBuilder = new Builder(); $snapshot = $snapshotBuilder->build($job); $products = new ArrayCollection(); foreach ($job->getPortals() as $key) { $product = new Product(); $channel = $this->providerOptions->getChannel($key); $product->setName($channel->getLabel())->setProductNumber($channel->getExternalKey())->setQuantity(1); $products->add($product); } $data = ['type' => OrderInterface::TYPE_JOB, 'taxRate' => $this->options->getTaxRate(), 'price' => $this->priceFilter->filter($job->getPortals()), 'invoiceAddress' => $invoiceAddress, 'currency' => $this->options->getCurrency(), 'currencySymbol' => $this->options->getCurrencySymbol(), 'entity' => $snapshot, 'products' => $products]; $order = $this->orderRepository->create($data); $this->orderRepository->store($order); $this->draftRepository->remove($invoiceAddressDraft); }
/** * allows an event attachment just by class * @param JobEvent $e */ public function restPost(JobEvent $e) { $response = new JobResponse($this->name, JobResponse::RESPONSE_NOTIMPLEMENTED); $serviceManager = $this->getServiceManager(); if ($serviceManager->has('Jobs/RestClient')) { try { $restClient = $serviceManager->get('Jobs/RestClient'); $provider = $serviceManager->get('Jobs/Options/Provider'); $entity = $e->getJobEntity(); // all this is very alpha and will be due to several changes // needed by now are (naming according to the Provider): // applyId = to identify the job back in the provider // company = name of the company // title = // description = // location = zip and town-name // datePublishStart = in a comprehensibly format for \DateTime // channels = array of externalIds $data = array('applyId' => $entity->applyId, 'company' => $entity->organization->name, 'title' => $entity->title, 'description' => $entity->description, 'location' => $entity->location, 'datePublishStart' => $entity->datePublishStart, 'channels' => array()); //$hydrator = $serviceManager->get('Jobs/JobsEntityHydrator'); //$data = $hydrator->extract($entity); foreach ($entity->portals as $portalName => $portal) { if (array_key_exists($portal, $provider->channels)) { $data['channels'][] = $provider->channels[$portal]->externalkey; } } $dataJson = json_encode($data); $restClient->setRawBody($dataJson); $response = $restClient->send(); // @TODO: statusCode is not stored, there is simply no mechanism to track external communication. $StatusCode = $response->getStatusCode(); $e->stopPropagation(true); $response = new JobResponse($this->name, JobResponse::RESPONSE_OKANDSTOP); } catch (\Exception $e) { $response = new JobResponse($this->name, JobResponse::RESPONSE_FAIL); } } return $response; }
/** * Callback for the job rejected event * * @param JobEvent $e */ public function onJobRejected(JobEvent $e) { $this->sendMail($e->getJobEntity(), 'mail/job-rejected', 'Your job has been rejected'); }
/** * allows an event attachment just by class * * @param JobEvent $e * * @return JobResponse */ public function restPost(JobEvent $e) { $response = new JobResponse($this->name, JobResponse::RESPONSE_NOTIMPLEMENTED); $serviceManager = $this->getServiceManager(); if ($serviceManager->has('Jobs/RestClient')) { try { $log = $serviceManager->get('Core/Log'); $restClient = $serviceManager->get('Jobs/RestClient'); $provider = $serviceManager->get('Jobs/Options/Provider'); $entity = $e->getJobEntity(); $render = $serviceManager->get('ViewPhpRendererStrategy')->getRenderer(); $viewModel = $serviceManager->get('Jobs/ViewModelTemplateFilter')->__invoke($entity); $html = $render->render($viewModel); $absUrlFilter = $serviceManager->get('filterManager')->get('Core/HtmlAbsPathFilter'); $html = $absUrlFilter->filter($html); $host = $restClient->getHost(); if (!isset($host)) { throw new \RuntimeException('no host found for Provider'); } $externalIdPublisher = null; $referencePublisher = null; $publisher = $entity->getPublisher($host); if (isset($publisher)) { $externalIdPublisher = $publisher->externalId; $referencePublisher = $publisher->reference; } if (empty($externalIdPublisher)) { $externalIdPublisher = $entity->applyId; } if (empty($referencePublisher)) { $referencePublisher = $entity->reference; } // all this is very alpha and will be due to several changes // needed by now are (naming according to the Provider): // applyId = to identify the job back in the provider // company = name of the company // title = // description = // location = zip and town-name // datePublishStart = in a comprehensibly format for \DateTime // channels = array of externalIds $data = array('referenceId' => $externalIdPublisher, 'applyId' => $externalIdPublisher, 'reference' => $referencePublisher, 'company' => $entity->organization->name, 'title' => $entity->title, 'description' => $html, 'location' => $entity->location, 'datePublishStart' => $entity->datePublishStart, 'channels' => array(), 'templateName' => $entity->template, 'contactEmail' => $entity->contactEmail); //$hydrator = $serviceManager->get('Jobs/JobsEntityHydrator'); //$data = $hydrator->extract($entity); foreach ($entity->portals as $portalName => $portal) { if (array_key_exists($portal, $provider->channels)) { $data['channels'][] = $provider->channels[$portal]->externalkey; } } $dataJson = json_encode($data); $restClient->setRawBody($dataJson); $response = $restClient->send(); $StatusCode = $response->getStatusCode(); $body = $response->getBody(); $decodedBody = json_decode($body); $jsonLastError = json_last_error(); if (json_last_error() != JSON_ERROR_NONE) { // not able to decode json $log->info('RestCall Response not Json [errorCode: ' . $jsonLastError . ']: ' . var_export($body, true)); } else { // does the provider want to have an own ID for Identification ? $response_referenceUpdate = $decodedBody->referenceUpdate; $response_externalIdUpdate = $decodedBody->applyIdUpdate; if ($publisher->externalId != $response_externalIdUpdate || $publisher->reference != $response_referenceUpdate) { $log->info('RestCall changed externalID [' . var_export($publisher->externalId, true) . ' => ' . var_export($response_externalIdUpdate, true) . '], reference [' . var_export($publisher->reference, true) . ' => ' . var_export($response_referenceUpdate, true) . ']'); $publisher->reference = $response_referenceUpdate; $publisher->externalId = $response_externalIdUpdate; $serviceManager->get('repositories')->store($entity); } } $e->stopPropagation(true); $response = new JobResponse($this->name, JobResponse::RESPONSE_OKANDSTOP); } catch (\Exception $e) { $response = new JobResponse($this->name, JobResponse::RESPONSE_FAIL); } } return $response; }