Displaying JobAdder XML

Last week I learnt something new! How to build a page from an XML. A client has a JobAdder account and wanted to display the jobs on there website.

JobAdder simply uploads a XML to a folder which I then can grab with the following:

if (fclose(fopen("https://edventureco.com/jobadder/jobadder.xml", "r"))) {
$xml = simplexml_load_file('https://edventureco.com/jobadder/jobadder.xml');
<?php } else {
echo 'Error message here';
}
?>

Using a fclose to check if it exists and if not display a simple message.

The page uses mixitup to filter the courses, the filters all come from the categories, locations, and work-types that are set in the xml. Essentially I just traverse the xml pulling the fields I want then using a foreach go through each element within each field and display them how I want.

<?php
foreach ($xml->Fields->Field as $filtervalue) { ?>

<?php $filtername = $filtervalue['name']; ?>
<h4><?php echo $filtername; ?></h4>

<?php /* Category */ ?>
<?php if ((string) $filtervalue['name'] == 'Category') {

?>
<div class="controlsection">
<?php foreach ($filtervalue->Values->Value as $listitems) { 
$listhere = $listitems['name'];
$locationone = strtolower($listhere);
$locationtwo = preg_replace('/\s+/', '', $locationone);
$locationresult = preg_replace("/[^a-zA-Z0-9]+/", "", $locationtwo);
?>
<button type="button" class="control" data-toggle=".<?php echo $locationresult; ?>"><?php echo $listhere; ?></button>
<?php   
} ?></div>
<?php } ?>


<?php /* Location */ ?>
<?php if ((string) $filtervalue['name'] == 'Location') {

?>
<div class="controlsection">
<?php foreach ($filtervalue->Values->Value as $listitems) { 
$listhere = $listitems['name'];
$locationone = strtolower($listhere);
$locationtwo = preg_replace('/\s+/', '', $locationone);
$locationresult = preg_replace("/[^a-zA-Z0-9]+/", "", $locationtwo);
?>
<button type="button" class="control" data-toggle=".<?php echo $locationresult; ?>"><?php echo $listhere; ?></button>
<?php   
} ?></div>
<?php } ?>

<?php /* Work Type */ ?>
<?php if ((string) $filtervalue['name'] == 'Work Type') {

?>
<div class="controlsection">
<?php foreach ($filtervalue->Values->Value as $listitems) { 
$listhere = $listitems['name'];
$locationone = strtolower($listhere);
$locationtwo = preg_replace('/\s+/', '', $locationone);
$locationresult = preg_replace("/[^a-zA-Z0-9]+/", "", $locationtwo);
?>
<button type="button" class="control" data-toggle=".<?php echo $locationresult; ?>"><?php echo $listhere; ?></button>
<?php   
} ?></div>
<?php } 
}
?>

Then its about displaying each job in the xml. Going through each job parameter that I want and assigning variables that I can then use within my html.

<?php

foreach ($xml->Job as $job) {

/* job main */
$jobID = $job['jid'];
$jobtitle = $job->Title;
$jobSum = $job->Summary;
$jobDesc = $job->Description;
/* job meta */
$jobApply = $job->Apply->Url; 
$jobDate = $job['datePosted'];
$date = new DateTime($jobDate);	
/* job url */
$job_link = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
?>
<div id="<?php echo $jobID; ?>" class="mix job <?php foreach($job->Classifications->Classification as $classlist) { 
$filterLoc = $classlist;
$filterLower = strtolower($filterLoc);
$stringfilter = preg_replace('/\s+/', '', $filterLower);
$resultfilter = preg_replace("/[^a-zA-Z0-9]+/", "", $stringfilter);
?><?php echo ' ' . $resultfilter; ?><?php } ?>">			  
<h3><a href="<?php echo $job_link; ?>?jobid=<?php echo $jobID; ?>"><?php echo $jobtitle; ?></a></h3>
<div class="jobdaterow"><i class="fas fa-calendar-alt"></i> <strong>Date Posted:</strong> <?php echo $date->format("d F 'y"); ?></div>
<p><?php echo $jobSum; ?></p>

<div class="jobdesc">
<p><?php echo $jobDesc; ?></p>
<ul>
<?php 
foreach($job->BulletPoints->BulletPoint as $bullet)
{ 
$bulletitem = $bullet;
?>
<li><?php echo $bulletitem; ?></li>
<?php   
}
?>
</ul>
</div>
<div class="jobbuttons">
<a href="<?php echo $job_link; ?>?jobid=<?php echo $jobID; ?>" class="joblink"><i class="fas fa-link"></i></a>
<span class="jobmore">More Info</span>
<a href="<?php echo $jobApply; ?>" target="_blank" class="button">Apply Now</a>
</div>    
<div class="jobmeta">
<?php 
foreach($job->Classifications->Classification as $classlist)
{ 
$jobCatName = $classlist[name];
$jobLoc = $classlist; 						   
?>
<div class="jobmetarows"><strong><?php echo $jobCatName; ?>:</strong><br /><?php echo $jobLoc; ?></div>
<?php   
}
?>
</div>               
</div>
<?php	} ?>

Finally instead of creating a page for each job, I just use the same page, and use the job ID that each job has as a url parameter. Then in the template I check if the url parameter exists, if so it outputs a simpler version of the above (with the filters replaced by a link back to view all jobs) using the full job description instead of the summary.

<?php
if( isset($_GET['jobid']) ): 
$jobidfromurl = $_GET["jobid"]; 
/* single job here */
else:
/* full job list here + filters */
endif; 
?>