Skip to content

Commit

Permalink
wr-936-show-date-ranges
Browse files Browse the repository at this point in the history
commit 4167899d6bef238dc3112da7180abf3e57869ad7
Author: rjkuyvenhoven <[email protected]>
Date:   Mon Oct 31 14:17:57 2022 -0700

    add Trends dates extra field

commit 3b72828bc10a02cd31b563f24c844601c9bf92f3
Merge: 4cfec57a e95c532
Author: rjkuyvenhoven <[email protected]>
Date:   Mon Oct 31 14:14:57 2022 -0700

    Merge branch 'master' into wr-936-show-date-ranges

commit 4cfec57a2d104f0f7689d3cb2aa736767c6bf491
Author: rjkuyvenhoven <[email protected]>
Date:   Mon Oct 31 14:14:31 2022 -0700

    add Date info for Career & Industry profiles

commit b31b9702250198d4dba328c04e1e595059c0f4b0
Merge: b1af9e41 556fbd7
Author: rjkuyvenhoven <[email protected]>
Date:   Mon Oct 31 10:56:26 2022 -0700

    Merge branch 'master' into wr-936-show-date-ranges

commit b1af9e410eb4051e35638d215a62cec0ea573ef4
Merge: e66e9e00 b7ad0eb
Author: rjkuyvenhoven <[email protected]>
Date:   Mon Oct 31 09:23:32 2022 -0700

    Merge branch 'master' into wr-936-show-date-ranges

commit e66e9e00029b22b386694020d0f009ec355f4ddb
Author: rjkuyvenhoven <[email protected]>
Date:   Fri Oct 28 16:58:54 2022 -0700

    show date range wip
  • Loading branch information
rjkuyvenhoven committed Oct 31, 2022
1 parent e95c532 commit b66c8a5
Show file tree
Hide file tree
Showing 21 changed files with 163 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ third_party_settings:
- extra_field_industry_employment_types_industry
- extra_field_industry_employment_types_bc
- extra_field_industry_employment_types_source
- extra_field_industry_employment_trends_dates
- extra_field_industry_employment_latest_trends_total
- extra_field_industry_employment_latest_trends_percent
- extra_field_industry_employment_trends_source
Expand Down Expand Up @@ -210,6 +211,11 @@ content:
third_party_settings: { }
weight: 4
region: content
extra_field_industry_employment_trends_dates:
settings: { }
third_party_settings: { }
weight: 28
region: content
extra_field_industry_employment_trends_source:
settings: { }
third_party_settings: { }
Expand All @@ -228,7 +234,7 @@ content:
extra_field_industry_employment_types_source:
settings: { }
third_party_settings: { }
weight: 28
weight: 27
region: content
extra_field_industry_job_openings:
settings: { }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,40 +50,42 @@ public function viewElements(ContentEntityInterface $entity) {
if (!is_null($entity->ssot_data['openings_careers']['industry_1_percent'])) {
$industry = [];
$industry['name'] = $entity->ssot_data['openings_careers']['industry_1_name'];
$industry['openings_careers'] = $entity->ssot_data['openings_careers']['industry_1_percent'];
$industry['openings_careers'] = $entity->ssot_data['openings_careers']['industry_1_openings'];
$industries[] = $industry;
}
if (!is_null($entity->ssot_data['openings_careers']['industry_2_percent'])) {
$industry = [];
$industry['name'] = $entity->ssot_data['openings_careers']['industry_2_name'];
$industry['openings_careers'] = $entity->ssot_data['openings_careers']['industry_2_percent'];
$industry['openings_careers'] = $entity->ssot_data['openings_careers']['industry_2_openings'];
$industries[] = $industry;
}
if (!is_null($entity->ssot_data['openings_careers']['industry_3_percent'])) {
$industry = [];
$industry['name'] = $entity->ssot_data['openings_careers']['industry_3_name'];
$industry['openings_careers'] = $entity->ssot_data['openings_careers']['industry_3_percent'];
$industry['openings_careers'] = $entity->ssot_data['openings_careers']['industry_3_openings'];
$industries[] = $industry;
}
if (!is_null($entity->ssot_data['openings_careers']['industry_4_percent'])) {
$industry = [];
$industry['name'] = $entity->ssot_data['openings_careers']['industry_4_name'];
$industry['openings_careers'] = $entity->ssot_data['openings_careers']['industry_4_percent'];
$industry['openings_careers'] = $entity->ssot_data['openings_careers']['industry_4_openings'];
$industries[] = $industry;
}
if (!is_null($entity->ssot_data['openings_careers']['industry_5_percent'])) {
$industry = [];
$industry['name'] = $entity->ssot_data['openings_careers']['industry_5_name'];
$industry['openings_careers'] = $entity->ssot_data['openings_careers']['industry_5_percent'];
$industry['openings_careers'] = $entity->ssot_data['openings_careers']['industry_5_openings'];
$industries[] = $industry;
}
}

$datestr = ssotParseDateRange($this->getEntity()->ssot_data['schema'], 'openings_careers', 'industry_1_openings');

$text = "<div>";
$text = "<table>";
$text .= "<tr><th>Industry</th><th>Job Openings (2021-2031)</th></tr>";
$text .= "<tr><th>Industry</th><th>Job Openings (" . $datestr . ")</th></tr>";
foreach ($industries as $industry) {
$text .= "<tr><td>" . $industry['name'] . "</td><td>" . number_format($industry['openings_careers']) . "</td></tr>";
$text .= "<tr><td>" . $industry['name'] . "</td><td>" . ssotFormatNumber($industry['openings_careers']) . "</td></tr>";
}
$text .= "</table>";
$output = $text;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ class CareerProfileJobOpenings extends ExtraFieldDisplayFormattedBase {
* {@inheritdoc}
*/
public function getLabel() {

return $this->t('Job Openings');
$datestr = ssotParseDateRange($this->getEntity()->ssot_data['schema'], 'career_provincial', 'job_openings_first');
return $this->t('Job Openings (:datestr)', array(":datestr" => $datestr));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ class CareerProfileJobOpeningsByRegion extends ExtraFieldDisplayFormattedBase {
* {@inheritdoc}
*/
public function getLabel() {

return $this->t('Job Openings');
$datestr = ssotParseDateRange($this->getEntity()->ssot_data['schema'], 'career_regional', 'cariboo_expected_number_of_job_openings_10y');
return $this->t('Job Openings by Region (:datestr)', array(":datestr" => $datestr));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,54 +45,56 @@ public function viewElements(ContentEntityInterface $entity) {

$names = ["Cariboo", "Kootenay", "Mainland/Southwest", "Nort Coast & Nechako", "Northeast", "Thompson-Okanagan", "Vancouver Island-Coast"];
$regions = [];
if (!empty($entity->ssot_data) && isset($entity->ssot_data['career_regional'])) {
if (!empty($entity->ssot_data) && isset($entity->ssot_data['census']) && isset($entity->ssot_data['career_regional'])) {
$total = intval($entity->ssot_data['census']['workers_employed']);
$region = array();
$region['name'] = t(REGION_CARIBOO);
$region['percent'] = floatval($entity->ssot_data['census']['cariboo_employment_of_this_occupation']);
$region['employment'] = round($region['percent'] * $total / 100);
$region['employment'] = $entity->ssot_data['career_regional']['cariboo_employment_current'];
$regions[] = $region;
$region = array();
$region['name'] = t(REGION_KOOTENAY);
$region['percent'] = floatval($entity->ssot_data['census']['kootenay_employment_of_this_occupation']);
$region['employment'] = round($region['percent'] * $total / 100);
$region['employment'] = $entity->ssot_data['career_regional']['kootenay_employment_current'];
$regions[] = $region;
$region = array();
$region['name'] = t(REGION_MAINLAND_SOUTHWEST);
$region['percent'] = floatval($entity->ssot_data['census']['mainland_southwest_employment_of_this_occupation']);
$region['employment'] = round($region['percent'] * $total / 100);
$region['employment'] = $entity->ssot_data['career_regional']['mainland_southwest_employment_current'];
$regions[] = $region;
$region = array();
$region['name'] = t(REGION_NORTH_COAST_NECHAKO);
$region['percent'] = floatval($entity->ssot_data['census']['north_coast_nechako_employment_of_this_occupation']);
$region['employment'] = round($region['percent'] * $total / 100);
$region['employment'] = $entity->ssot_data['career_regional']['north_coast_and_nechako_employment_current'];
$regions[] = $region;
$region = array();
$region['name'] = t(REGION_NORTHEAST);
$region['percent'] = floatval($entity->ssot_data['census']['northeast_employment_of_this_occupation']);
$region['employment'] = round($region['percent'] * $total / 100);
$region['employment'] = $entity->ssot_data['career_regional']['northeast_employment_current'];
$regions[] = $region;
$region = array();
$region['name'] = t(REGION_THOMPSON_OKANAGAN);
$region['percent'] = floatval($entity->ssot_data['census']['thompson_okanagan_employment_of_this_occupation']);
$region['employment'] = round($region['percent'] * $total / 100);
$region['employment'] = $entity->ssot_data['career_regional']['thompson_okanagan_employment_current'];
$regions[] = $region;
$region = array();
$region['name'] = t(REGION_VANCOUVER_ISLAND_COAST);
$region['percent'] = floatval($entity->ssot_data['census']['vancouver_island_coast_employment_of_this_occupation']);
$region['employment'] = round($region['percent'] * $total / 100);
$region['employment'] = $entity->ssot_data['career_regional']['vancouver_island_coast_employment_current'];
$regions[] = $region;
}

$datestr = ssotParseDateRange($entity->ssot_data['schema'], 'career_regional', 'cariboo_employment_current');

$module_handler = \Drupal::service('module_handler');
$module_path = $module_handler->getModule('workbc_extra_fields')->getPath();

$text = '<div><img src="/' . $module_path . '/images/' . WORKBC_BC_MAP_WITH_LABELS . '"></div>';
$text .= "<div>";
$text .= "<table>";
$text .= "<tr><th>Region</th><th>Employment</th><th>% Employment</th></tr>";
$text .= "<tr><th>Region</th><th>Employment (" . $datestr . ")</th><th>% Employment</th></tr>";
foreach ($regions as $region) {
$text .= "<tr><td>" . $region['name'] . "</td><td>" . number_format($region['employment']) . "</td><td>" . number_format($region['percent'],1) . "%</td></tr>";
$text .= "<tr><td>" . $region['name'] . "</td><td>" . ssotFormatNumber($region['employment']) . "</td><td>" . ssotFormatNumber($region['percent'],1) . "%</td></tr>";
}
$text .= "</table>";
$text .= "</div>";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ class CareerProfileLabourMarketExpectedOpenings extends ExtraFieldDisplayFormatt
* {@inheritdoc}
*/
public function getLabel() {

return $this->t('Expected Job Openings');
$datestr = ssotParseDateRange($this->getEntity()->ssot_data['schema'], 'career_provincial', 'expected_job_openings_10y');
return $this->t('Expected Job Openings (:datestr)', array(":datestr" => $datestr));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ class IndustryAverageWage extends ExtraFieldDisplayFormattedBase {
* {@inheritdoc}
*/
public function getLabel() {

return $this->t('Industry Average Wage');
$datestr = ssotParseDateRange($this->getEntity()->ssot_data['schema'], 'labour_force_survey_industry', 'earnings_men');
return $this->t("Industry Average Wage (" . $datestr . ")");
}

/**
Expand All @@ -44,9 +44,9 @@ public function getLabelDisplay() {
public function viewElements(ContentEntityInterface $entity) {

if (!empty($entity->ssot_data) && isset($entity->ssot_data['labour_force_survey_industry'])) {
$avgMen = '$' . $entity->ssot_data['labour_force_survey_industry']['earnings_men'] . '/hr';
$avgWomen = '$' . $entity->ssot_data['labour_force_survey_industry']['earnings_women'] . '/hr';
$avgYouth = '$' . $entity->ssot_data['labour_force_survey_industry']['earnings_youth'] . '/hr';
$avgMen = '$' . ssotFormatNumber($entity->ssot_data['labour_force_survey_industry']['earnings_men'],2) . '/hr';
$avgWomen = '$' . ssotFormatNumber($entity->ssot_data['labour_force_survey_industry']['earnings_women'],2) . '/hr';
$avgYouth = '$' . ssotFormatNumber($entity->ssot_data['labour_force_survey_industry']['earnings_youth'],2) . '/hr';
}
else {
$avgMen = WORKBC_EXTRA_FIELDS_NOT_AVAILABLE;;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ class IndustryAverageWageBC extends ExtraFieldDisplayFormattedBase {
* {@inheritdoc}
*/
public function getLabel() {

return $this->t('BC Average Wage');
$datestr = ssotParseDateRange($this->getEntity()->ssot_data['schema'], 'labour_force_survey_industry', 'earnings_men_average');
return $this->t("BC Average Wage (" . $datestr . ")");
}

/**
Expand All @@ -44,9 +44,9 @@ public function getLabelDisplay() {
public function viewElements(ContentEntityInterface $entity) {

if (!empty($entity->ssot_data) && isset($entity->ssot_data['labour_force_survey_industry'])) {
$avgMen = '$' . $entity->ssot_data['labour_force_survey_industry']['earnings_men_average'] . '/hr';
$avgWomen = '$' . $entity->ssot_data['labour_force_survey_industry']['earnings_women_average'] . '/hr';
$avgYouth = '$' . $entity->ssot_data['labour_force_survey_industry']['earnings_youth_average'] . '/hr';
$avgMen = '$' . ssotFormatNumber($entity->ssot_data['labour_force_survey_industry']['earnings_men_average'],2) . '/hr';
$avgWomen = '$' . ssotFormatNumber($entity->ssot_data['labour_force_survey_industry']['earnings_women_average'],2) . '/hr';
$avgYouth = '$' . ssotFormatNumber($entity->ssot_data['labour_force_survey_industry']['earnings_youth_average'],2) . '/hr';
}
else {
$avgMen = WORKBC_EXTRA_FIELDS_NOT_AVAILABLE;;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ class IndustryBCAverageChart extends ExtraFieldDisplayFormattedBase {
* {@inheritdoc}
*/
public function getLabel() {

return $this->t('BC Average Chart');
$datestr = ssotParseDateRange($this->getEntity()->ssot_data['schema'], 'labour_force_survey_industry', 'workforce_provincial_average_pct_men');
return $this->t("BC Average (" . $datestr . ")");
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ class IndustryEmployment extends ExtraFieldDisplayFormattedBase {
* {@inheritdoc}
*/
public function getLabel() {

return $this->t('Employment');
$datestr = ssotParseDateRange($this->getEntity()->ssot_data['schema'], 'industry_outlook', 'employment_first');
return $this->t("Employment (" . $datestr . ")");
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public function getLabelDisplay() {
public function viewElements(ContentEntityInterface $entity) {

if (!empty($entity->ssot_data) && isset($entity->ssot_data['labour_force_survey_industry'])) {

$value = 100;
$value -= $entity->ssot_data['labour_force_survey_industry']['workforce_employment_under_25_pct_average'];
$value -= $entity->ssot_data['labour_force_survey_industry']['workforce_employment_over_55_pct_average'];
Expand All @@ -69,8 +70,11 @@ public function viewElements(ContentEntityInterface $entity) {
$industryAvgOver55 = WORKBC_EXTRA_FIELDS_NOT_AVAILABLE;
}

$datestr1 = ssotParseDateRange($entity->ssot_data['schema'], 'labour_force_survey_industry', 'workforce_employment_under_25_pct_average');
$datestr2 = ssotParseDateRange($entity->ssot_data['schema'], 'labour_force_survey_industry', 'workforce_employment_under_25_pct');

$content = '<table>';
$content .= '<tr><th>Age Group</th><th>Industry Average</th><th>B.C. Average</th></tr>';
$content .= "<tr><th>Age Group</th><th>Industry Average (" . $datestr1 . ")</th><th>B.C. Average (" . $datestr2 . ")</th></tr>";
$content .= '<tr><td>15 - 24 years</td><td>' . $industryAvgUnder25 . '</td><td>' . $bcAvgUnder25 . '</td></tr>';
$content .= '<tr><td>25 - 54 years</td><td>' . $industryAvg25thru55 . '</td><td>' . $bcAvg25thru55 . '</td></tr>';
$content .= '<tr><td>55+ years</td><td>' . $industryAvgOver55 . '</td><td>' . $bcAvgOver55 . '</td></tr>';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ class IndustryEmploymentBySex extends ExtraFieldDisplayFormattedBase {
* {@inheritdoc}
*/
public function getLabel() {

return $this->t('Employment by Sex');
$datestr = ssotParseDateRange($this->getEntity()->ssot_data['schema'], 'labour_force_survey_industry', 'workforce_employment_gender_pct_men');
return $this->t("Employment by Sex (" . $datestr . ")");
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ class IndustryEmploymentGrowth extends ExtraFieldDisplayFormattedBase {
*/
public function getLabel() {

return $this->t('Employment Growth');
$datestr = ssotParseDateRange($this->getEntity()->ssot_data['schema'], 'industry_outlook', 'annual_employment_growth_rate_pct_first5y');
return $this->t("Employment Growth (" . $datestr . ")");
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php

namespace Drupal\workbc_extra_fields\Plugin\ExtraField\Display\IndustryProfile;

use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\extra_field\Plugin\ExtraFieldDisplayFormattedBase;

/**
* Example Extra field with formatted output.
*
* @ExtraFieldDisplay(
* id = "industry_employment_trends_dates",
* label = @Translation("Latest Employment Trends Dates"),
* description = @Translation("An extra field to display industry latest employment trends dates."),
* bundles = {
* "node.industry_profile",
* }
* )
*/
class IndustryEmploymentLatestTrendsDates extends ExtraFieldDisplayFormattedBase {

use StringTranslationTrait;

/**
* {@inheritdoc}
*/
public function getLabel() {

return $this->t('Latest Employment Trends');
}

/**
* {@inheritdoc}
*/
public function getLabelDisplay() {

return 'above';
}

/**
* {@inheritdoc}
*/
public function viewElements(ContentEntityInterface $entity) {

if (!empty($entity->ssot_data) && isset($entity->ssot_data['monthly_labour_market_updates'])) {
$sourceData = $entity->ssot_data['monthly_labour_market_updates'];
$idx = ssotLatestMonthlyLabourMarketUpdate($entity->ssot_data['monthly_labour_market_updates']);
$date1 = strtotime($entity->ssot_data['monthly_labour_market_updates'][$idx]['year'] . "-" . $entity->ssot_data['monthly_labour_market_updates'][$idx]['month']. "-01", 10);
$date2 = strtotime("-1 month", $date1);
$output = date("M Y", $date1) . " vs. " . date("M Y", $date2);
}
else {
$output = WORKBC_EXTRA_FIELDS_NOT_AVAILABLE;
}
return [
['#markup' => $output],
];
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ public function viewElements(ContentEntityInterface $entity) {
if (!empty($entity->ssot_data) && isset($entity->ssot_data['monthly_labour_market_updates'])) {
$sourceData = $entity->ssot_data['monthly_labour_market_updates'];
$idx = ssotLatestMonthlyLabourMarketUpdate($entity->ssot_data['monthly_labour_market_updates']);
$output = ssotFormatNumber($entity->ssot_data['monthly_labour_market_updates'][$idx]['employment_change_pct_total_employment'], 1, true);
$output = "<div>(since last month)</div>";
$output .= ssotFormatNumber($entity->ssot_data['monthly_labour_market_updates'][$idx]['employment_change_pct_total_employment'], 1, true);
$output .= "%";
}
else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ class IndustryEmploymentLatestTrendsTotal extends ExtraFieldDisplayFormattedBase
* {@inheritdoc}
*/
public function getLabel() {

return $this->t('Latest Employment Trends Total');
return $this->t('Employment');
}

/**
Expand All @@ -46,7 +45,8 @@ public function viewElements(ContentEntityInterface $entity) {
if (!empty($entity->ssot_data) && isset($entity->ssot_data['monthly_labour_market_updates'])) {
$sourceData = $entity->ssot_data['monthly_labour_market_updates'];
$idx = ssotLatestMonthlyLabourMarketUpdate($entity->ssot_data['monthly_labour_market_updates']);
$output = ssotFormatNumber($entity->ssot_data['monthly_labour_market_updates'][$idx]['employment_change_abs_total_employment'], 0, true);
$output = "<div>(change since last month)</div>";
$output .= ssotFormatNumber($entity->ssot_data['monthly_labour_market_updates'][$idx]['employment_change_abs_total_employment'], 0, true);
}
else {
$output = WORKBC_EXTRA_FIELDS_NOT_AVAILABLE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ class IndustryEmploymentTypesBC extends ExtraFieldDisplayFormattedBase {
* {@inheritdoc}
*/
public function getLabel() {

return $this->t('Employment Types BC');
$datestr = ssotParseDateRange($this->getEntity()->ssot_data['schema'], 'labour_force_survey_industry', 'employment_part_time_pct_average');
return $this->t("Employment Types BC (" . $datestr . ")");
}

/**
Expand Down
Loading

0 comments on commit b66c8a5

Please sign in to comment.