Skip to content

Commit

Permalink
feat: added google for jobs modification event (#114)
Browse files Browse the repository at this point in the history
* feat: added google for jobs event

* feat: added google for jobs modification event
  • Loading branch information
Benjamin Jasper authored Sep 13, 2023
1 parent 511afef commit 8b03410
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Added privacy protection to option to send email without personal data by @hmccloy (#92)
- Added list plugin option to set prefiltered locations (#68)
- Added a new event to modify google for jobs data

### Fixed

Expand Down
1 change: 0 additions & 1 deletion Classes/Controller/ApplicationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
use ITX\Jobapplications\Event\BeforeApplicationPersisted;
use ITX\Jobapplications\PageTitle\JobsPageTitleProvider;
use ITX\Jobapplications\Service\ApplicationFileService;
use ITX\Jobapplications\Utility\Mail\MailInterface;
use ITX\Jobapplications\Utility\Typo3VersionUtility;
use ITX\Jobapplications\Utility\UploadFileUtility;
use Psr\Http\Message\ResponseInterface;
Expand Down
12 changes: 8 additions & 4 deletions Classes/Controller/PostingController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use ITX\Jobapplications\Domain\Repository\LocationRepository;
use ITX\Jobapplications\Domain\Repository\PostingRepository;
use ITX\Jobapplications\Event\DisplayPostingEvent;
use ITX\Jobapplications\Event\ModifyGoogleForJobsDataEvent;
use ITX\Jobapplications\PageTitle\JobsPageTitleProvider;
use Psr\Http\Message\ResponseInterface;
use TYPO3\CMS\Core\Cache\CacheManager;
Expand Down Expand Up @@ -289,7 +290,7 @@ public function showAction(?Posting $posting = null): ResponseInterface

$titleProvider = GeneralUtility::makeInstance(JobsPageTitleProvider::class);

// Pagetitle Templating
// Page-title Templating
$title = $this->settings["pageTitle"];
if ($title !== "")
{
Expand All @@ -316,7 +317,7 @@ public function showAction(?Posting $posting = null): ResponseInterface

/**
* This function generates the Google Jobs structured on page data.
* This can be overriden if any field customizations are done.
* This can be overridden if any field customizations are done.
*
* @throws \JsonException
*/
Expand Down Expand Up @@ -397,7 +398,7 @@ protected function addGoogleJobsDataToPage(Posting $posting): void
$googleJobsJSON = [
"@context" => "http://schema.org",
"@type" => "JobPosting",
"datePosted" => $posting->getDatePosted()->format("c"),
"datePosted" => $posting->getDatePosted()?->format("c"),
"description" => $posting->getCompanyDescription()."<br>".$posting->getJobDescription()."<br>"
.$posting->getRoleDescription()."<br>".$posting->getSkillRequirements()
."<br>".$posting->getBenefits(),
Expand Down Expand Up @@ -436,12 +437,15 @@ protected function addGoogleJobsDataToPage(Posting $posting): void
];
}


if ($posting->getEndtime() instanceof \DateTime)
{
$googleJobsJSON["validThrough"] = $posting->getEndtime()->format("c");
}

/** @var ModifyGoogleForJobsDataEvent $event */
$event = $this->eventDispatcher->dispatch(new ModifyGoogleForJobsDataEvent($googleJobsJSON, $posting));
$googleJobsJSON = $event->getGoogleForJobsData();

$googleJobs = "<script type=\"application/ld+json\">".json_encode($googleJobsJSON, JSON_THROW_ON_ERROR)."</script>";

$this->pageRenderer->addHeaderData($googleJobs);
Expand Down
30 changes: 30 additions & 0 deletions Classes/Event/ModifyGoogleForJobsDataEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace ITX\Jobapplications\Event;

use ITX\Jobapplications\Domain\Model\Posting;

class ModifyGoogleForJobsDataEvent
{
protected array $googleForJobsData;
protected Posting $posting;
public function __construct(array $googleForJobsData, Posting $posting) {
$this->googleForJobsData = $googleForJobsData;
$this->posting = $posting;
}

public function getGoogleForJobsData(): array
{
return $this->googleForJobsData;
}

public function setGoogleForJobsData(array $googleForJobsData): void
{
$this->googleForJobsData = $googleForJobsData;
}

public function getPosting(): Posting
{
return $this->posting;
}
}

0 comments on commit 8b03410

Please sign in to comment.