Skip to content

Commit

Permalink
[WR-1605] add ssotFormat function to handle NULL/0, use ssotFormat fu…
Browse files Browse the repository at this point in the history
…nction for… (#380)

* add ssotFormat function to handle NULL/0, use ssotFormat function for Industry Employment by Region table

* fix variable name

* rename ssotFormatNA() function, start using ssotFormatNA function
  • Loading branch information
rjkuyvenhoven authored Jun 30, 2023
1 parent d68493f commit 716c19a
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 78 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,52 +47,38 @@ public function viewElements(ContentEntityInterface $entity) {
if (!empty($entity->ssot_data) && isset($entity->ssot_data['career_regional'])) {
$region = array();
$region['name'] = t(REGION_CARIBOO);
$value = $entity->ssot_data['career_regional']['cariboo_expected_number_of_job_openings_10y'];
$region['openings'] = ($value===0||$value) ? ssotFormatNumber(floatval($value),0) : WORKBC_EXTRA_FIELDS_NOT_AVAILABLE;
$value = $entity->ssot_data['career_regional']['cariboo_average_annual_employment_growth_10y_pct'];
$region['growth'] = ($value===0||$value) ? ssotFormatNumber($value,1) . "%" : WORKBC_EXTRA_FIELDS_NOT_AVAILABLE;
$region['openings'] = ssotFormatNA($entity->ssot_data['career_regional']['cariboo_expected_number_of_job_openings_10y'], 0);
$region['growth'] = ssotFormatNA($entity->ssot_data['career_regional']['cariboo_average_annual_employment_growth_10y_pct'], 1, "%");
$regions[] = $region;
$region = array();
$region['name'] = t(REGION_KOOTENAY);
$value = $entity->ssot_data['career_regional']['kootenay_expected_number_of_job_openings_10y'];
$region['openings'] = ($value===0||$value) ? ssotFormatNumber(floatval($value),0) : WORKBC_EXTRA_FIELDS_NOT_AVAILABLE;
$value = $entity->ssot_data['career_regional']['kootenay_average_annual_employment_growth_10y_pct'];
$region['growth'] = ($value===0||$value) ? ssotFormatNumber($value,1) . "%" : WORKBC_EXTRA_FIELDS_NOT_AVAILABLE;
$region['openings'] = ssotFormatNA($entity->ssot_data['career_regional']['kootenay_expected_number_of_job_openings_10y'], 0);
$region['growth'] = ssotFormatNA($entity->ssot_data['career_regional']['kootenay_average_annual_employment_growth_10y_pct'], 1, "%");
$regions[] = $region;
$region = array();
$region['name'] = t(REGION_MAINLAND_SOUTHWEST);
$value = $entity->ssot_data['career_regional']['mainland_southwest_expected_number_of_job_openings_10y'];
$region['openings'] = ($value===0||$value) ? ssotFormatNumber(floatval($value),0) : WORKBC_EXTRA_FIELDS_NOT_AVAILABLE;
$value = $entity->ssot_data['career_regional']['mainland_southwest_annual_employment_growth_10y_pct'];
$region['growth'] = ($value===0||$value) ? ssotFormatNumber($value,1) . "%" : WORKBC_EXTRA_FIELDS_NOT_AVAILABLE;
$region['openings'] = ssotFormatNA($entity->ssot_data['career_regional']['mainland_southwest_expected_number_of_job_openings_10y'], 0);
$region['growth'] = ssotFormatNA($entity->ssot_data['career_regional']['mainland_southwest_annual_employment_growth_10y_pct'], 1, "%");
$regions[] = $region;
$region = array();
$region['name'] = t(REGION_NORTH_COAST_NECHAKO);
$value = $entity->ssot_data['career_regional']['north_coast_nechako_expected_number_of_job_openings_10y'];
$region['openings'] = ($value===0||$value) ? ssotFormatNumber(floatval($value),0) : WORKBC_EXTRA_FIELDS_NOT_AVAILABLE;
$value = $entity->ssot_data['career_regional']['north_coast_nechako_annual_employment_growth_10y_pct'];
$region['growth'] = ($value===0||$value) ? ssotFormatNumber($value,1) . "%" : WORKBC_EXTRA_FIELDS_NOT_AVAILABLE;
$region['openings'] = ssotFormatNA($entity->ssot_data['career_regional']['north_coast_nechako_expected_number_of_job_openings_10y'], 0);
$region['growth'] = ssotFormatNA($entity->ssot_data['career_regional']['north_coast_nechako_annual_employment_growth_10y_pct'], 1, "%");
$regions[] = $region;
$region = array();
$region['name'] = t(REGION_NORTHEAST);
$value = $entity->ssot_data['career_regional']['northeast_expected_number_of_job_openings_10y'];
$region['openings'] = ($value===0||$value) ? ssotFormatNumber(floatval($value),0) : WORKBC_EXTRA_FIELDS_NOT_AVAILABLE;
$value = $entity->ssot_data['career_regional']['northeast_annual_employment_growth_10y_pct'];
$region['growth'] = ($value===0||$value) ? ssotFormatNumber($value,1) . "%" : WORKBC_EXTRA_FIELDS_NOT_AVAILABLE;
$region['openings'] = ssotFormatNA($entity->ssot_data['career_regional']['northeast_expected_number_of_job_openings_10y'], 0);
$region['growth'] = ssotFormatNA($entity->ssot_data['career_regional']['northeast_annual_employment_growth_10y_pct'], 1, "%");
$regions[] = $region;
$region = array();
$region['name'] = t(REGION_THOMPSON_OKANAGAN);
$value = $entity->ssot_data['career_regional']['thompson_okanagan_expected_number_of_job_openings_10y'];
$region['openings'] = ($value===0||$value) ? ssotFormatNumber(floatval($value),0) : WORKBC_EXTRA_FIELDS_NOT_AVAILABLE;
$value = $entity->ssot_data['career_regional']['thompson_okanagan_annual_employment_growth_10y_pct'];
$region['growth'] = ($value===0||$value) ? ssotFormatNumber($value,1) . "%" : WORKBC_EXTRA_FIELDS_NOT_AVAILABLE;
$region['openings'] = ssotFormatNA($entity->ssot_data['career_regional']['thompson_okanagan_expected_number_of_job_openings_10y'], 0);
$region['growth'] = ssotFormatNA($entity->ssot_data['career_regional']['thompson_okanagan_annual_employment_growth_10y_pct'], 1, "%");
$regions[] = $region;
$region = array();
$region['name'] = t(REGION_VANCOUVER_ISLAND_COAST);
$rvalue = $entity->ssot_data['career_regional']['vancouver_island_coast_expected_number_of_job_openings_10y'];
$region['openings'] = ($value===0||$value) ? ssotFormatNumber(floatval($value),0) : WORKBC_EXTRA_FIELDS_NOT_AVAILABLE;
$value = $entity->ssot_data['career_regional']['vancouver_island_coast_annual_employment_growth_10y_pct'];
$region['growth'] = ($value===0||$value) ? ssotFormatNumber($value,1) . "%" : WORKBC_EXTRA_FIELDS_NOT_AVAILABLE;
$region['openings'] = ssotFormatNA($entity->ssot_data['career_regional']['vancouver_island_coast_expected_number_of_job_openings_10y'], 0);
$region['growth'] = ssotFormatNA($entity->ssot_data['career_regional']['vancouver_island_coast_annual_employment_growth_10y_pct'], 1, "%");
$regions[] = $region;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,53 +45,32 @@ public function viewElements(ContentEntityInterface $entity) {
$regions = [];
if (!empty($entity->ssot_data) && isset($entity->ssot_data['career_regional'])) {
$region = array();
$region['name'] = t(REGION_CARIBOO);
$value = $entity->ssot_data['career_regional']['cariboo_expected_number_of_job_openings_10y'];
$region['openings'] = ($value===0||$value) ? ssotFormatNumber(floatval($value),0) : WORKBC_EXTRA_FIELDS_NOT_AVAILABLE;
$value = $entity->ssot_data['career_regional']['cariboo_average_annual_employment_growth_10y_pct'];
$region['growth'] = ($value===0||$value) ? ssotFormatNumber($value,1) . "%" : WORKBC_EXTRA_FIELDS_NOT_AVAILABLE;
$region['openings'] = $entity->ssot_data['career_regional']['cariboo_expected_number_of_job_openings_10y'];
$region['growth'] = $entity->ssot_data['career_regional']['cariboo_average_annual_employment_growth_10y_pct'];
$regions[] = $region;
$region = array();
$region['name'] = t(REGION_KOOTENAY);
$value = $entity->ssot_data['career_regional']['kootenay_expected_number_of_job_openings_10y'];
$region['openings'] = ($value===0||$value) ? ssotFormatNumber(floatval($value),0) : WORKBC_EXTRA_FIELDS_NOT_AVAILABLE;
$value = $entity->ssot_data['career_regional']['kootenay_average_annual_employment_growth_10y_pct'];
$region['growth'] = ($value===0||$value) ? ssotFormatNumber($value,1) . "%" : WORKBC_EXTRA_FIELDS_NOT_AVAILABLE;
$region['openings'] = $entity->ssot_data['career_regional']['kootenay_expected_number_of_job_openings_10y'];
$region['growth'] = $entity->ssot_data['career_regional']['kootenay_average_annual_employment_growth_10y_pct'];
$regions[] = $region;
$region = array();
$region['name'] = t(REGION_MAINLAND_SOUTHWEST);
$value = $entity->ssot_data['career_regional']['mainland_southwest_expected_number_of_job_openings_10y'];
$region['openings'] = ($value===0||$value) ? ssotFormatNumber(floatval($value),0) : WORKBC_EXTRA_FIELDS_NOT_AVAILABLE;
$value = $entity->ssot_data['career_regional']['mainland_southwest_annual_employment_growth_10y_pct'];
$region['growth'] = ($value===0||$value) ? ssotFormatNumber($value,1) . "%" : WORKBC_EXTRA_FIELDS_NOT_AVAILABLE;
$region['openings'] = $entity->ssot_data['career_regional']['mainland_southwest_expected_number_of_job_openings_10y'];
$region['growth'] = $entity->ssot_data['career_regional']['mainland_southwest_annual_employment_growth_10y_pct'];
$regions[] = $region;
$region = array();
$region['name'] = t(REGION_NORTH_COAST_NECHAKO);
$value = $entity->ssot_data['career_regional']['north_coast_nechako_expected_number_of_job_openings_10y'];
$region['openings'] = ($value===0||$value) ? ssotFormatNumber(floatval($value),0) : WORKBC_EXTRA_FIELDS_NOT_AVAILABLE;
$value = $entity->ssot_data['career_regional']['north_coast_nechako_annual_employment_growth_10y_pct'];
$region['growth'] = ($value===0||$value) ? ssotFormatNumber($value,1) . "%" : WORKBC_EXTRA_FIELDS_NOT_AVAILABLE;
$region['openings'] = $entity->ssot_data['career_regional']['north_coast_nechako_expected_number_of_job_openings_10y'];
$region['growth'] = $entity->ssot_data['career_regional']['north_coast_nechako_annual_employment_growth_10y_pct'];
$regions[] = $region;
$region = array();
$region['name'] = t(REGION_NORTHEAST);
$value = $entity->ssot_data['career_regional']['northeast_expected_number_of_job_openings_10y'];
$region['openings'] = ($value===0||$value) ? ssotFormatNumber(floatval($value),0) : WORKBC_EXTRA_FIELDS_NOT_AVAILABLE;
$value = $entity->ssot_data['career_regional']['northeast_annual_employment_growth_10y_pct'];
$region['growth'] = ($value===0||$value) ? ssotFormatNumber($value,1) . "%" : WORKBC_EXTRA_FIELDS_NOT_AVAILABLE;
$region['openings'] = $entity->ssot_data['career_regional']['northeast_expected_number_of_job_openings_10y'];
$region['growth'] = $entity->ssot_data['career_regional']['northeast_annual_employment_growth_10y_pct'];
$regions[] = $region;
$region = array();
$region['name'] = t(REGION_THOMPSON_OKANAGAN);
$value = $entity->ssot_data['career_regional']['thompson_okanagan_expected_number_of_job_openings_10y'];
$region['openings'] = ($value===0||$value) ? ssotFormatNumber(floatval($value),0) : WORKBC_EXTRA_FIELDS_NOT_AVAILABLE;
$value = $entity->ssot_data['career_regional']['thompson_okanagan_annual_employment_growth_10y_pct'];
$region['growth'] = ($value===0||$value) ? ssotFormatNumber($value,1) . "%" : WORKBC_EXTRA_FIELDS_NOT_AVAILABLE;
$region['openings'] = $entity->ssot_data['career_regional']['thompson_okanagan_expected_number_of_job_openings_10y'];
$region['growth'] = $entity->ssot_data['career_regional']['thompson_okanagan_annual_employment_growth_10y_pct'];
$regions[] = $region;
$region = array();
$region['name'] = t(REGION_VANCOUVER_ISLAND_COAST);
$rvalue = $entity->ssot_data['career_regional']['vancouver_island_coast_expected_number_of_job_openings_10y'];
$region['openings'] = ($value===0||$value) ? ssotFormatNumber(floatval($value),0) : WORKBC_EXTRA_FIELDS_NOT_AVAILABLE;
$value = $entity->ssot_data['career_regional']['vancouver_island_coast_annual_employment_growth_10y_pct'];
$region['growth'] = ($value===0||$value) ? ssotFormatNumber($value,1) . "%" : WORKBC_EXTRA_FIELDS_NOT_AVAILABLE;
$region['openings'] = $entity->ssot_data['career_regional']['vancouver_island_coast_expected_number_of_job_openings_10y'];
$region['growth'] = $entity->ssot_data['career_regional']['vancouver_island_coast_annual_employment_growth_10y_pct'];
$regions[] = $region;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,46 +47,46 @@ public function viewElements(ContentEntityInterface $entity) {
if (!empty($entity->ssot_data) && isset($entity->ssot_data['labour_force_survey_industry'])) {
$region = array();
$region['name'] = t(REGION_CARIBOO);
$region['industry'] = floatval($entity->ssot_data['labour_force_survey_industry']['location_cariboo_employment_this_industry_pct']);
$region['all'] = floatval($entity->ssot_data['labour_force_survey_industry']['location_cariboo_employment_all_industries_pct']);
$region['industry'] = ssotFormatNA($entity->ssot_data['labour_force_survey_industry']['location_cariboo_employment_this_industry_pct'], 1, "%");
$region['all'] = ssotFormatNA($entity->ssot_data['labour_force_survey_industry']['location_cariboo_employment_all_industries_pct'], 1, "%");
$regions[] = $region;
$region = array();
$region['name'] = t(REGION_KOOTENAY);
$region['industry'] = floatval($entity->ssot_data['labour_force_survey_industry']['location_kootenay_employment_this_industry_pct']);
$region['all'] = floatval($entity->ssot_data['labour_force_survey_industry']['location_kootenay_employment_all_industries_pct']);
$region['industry'] = ssotFormatNA($entity->ssot_data['labour_force_survey_industry']['location_kootenay_employment_this_industry_pct'], 1, "%");
$region['all'] = ssotFormatNA($entity->ssot_data['labour_force_survey_industry']['location_kootenay_employment_all_industries_pct'], 1, "%");
$regions[] = $region;
$region = array();
$region['name'] = t(REGION_MAINLAND_SOUTHWEST);
$region['industry'] = floatval($entity->ssot_data['labour_force_survey_industry']['location_mainland_southwest_employment_this_industry_pct']);
$region['all'] = floatval($entity->ssot_data['labour_force_survey_industry']['location_mainland_southwest_employment_all_industries_pct']);
$region['industry'] = ssotFormatNA($entity->ssot_data['labour_force_survey_industry']['location_mainland_southwest_employment_this_industry_pct'], 1, "%");
$region['all'] = ssotFormatNA($entity->ssot_data['labour_force_survey_industry']['location_mainland_southwest_employment_all_industries_pct'], 1, "%");
$regions[] = $region;
$region = array();
$region['name'] = t(REGION_NORTH_COAST_NECHAKO);
$region['industry'] = floatval($entity->ssot_data['labour_force_survey_industry']['location_north_coast_nechako_employment_this_industry_pct']);
$region['all'] = floatval($entity->ssot_data['labour_force_survey_industry']['location_north_coast_nechako_employment_all_industries_pct']);
$region['industry'] = ssotFormatNA($entity->ssot_data['labour_force_survey_industry']['location_north_coast_nechako_employment_this_industry_pct'], 1, "%");
$region['all'] = ssotFormatNA($entity->ssot_data['labour_force_survey_industry']['location_north_coast_nechako_employment_all_industries_pct'], 1, "%");
$regions[] = $region;
$region = array();
$region['name'] = t(REGION_NORTHEAST);
$region['industry'] = floatval($entity->ssot_data['labour_force_survey_industry']['location_northeast_employment_this_industry_pct']);
$region['all'] = floatval($entity->ssot_data['labour_force_survey_industry']['location_northeast_employment_all_industries_pct']);
$region['industry'] = ssotFormatNA($entity->ssot_data['labour_force_survey_industry']['location_northeast_employment_this_industry_pct'], 1, "%");
$region['all'] = ssotFormatNA($entity->ssot_data['labour_force_survey_industry']['location_northeast_employment_all_industries_pct'], 1, "%");
$regions[] = $region;
$region = array();
$region['name'] = t(REGION_THOMPSON_OKANAGAN);
$region['industry'] = floatval($entity->ssot_data['labour_force_survey_industry']['location_thompson_okanagan_employment_this_industry_pct']);
$region['all'] = floatval($entity->ssot_data['labour_force_survey_industry']['location_thompson_okanagan_employment_all_industries_pct']);
$region['industry'] = ssotFormatNA($entity->ssot_data['labour_force_survey_industry']['location_thompson_okanagan_employment_this_industry_pct'], 1, "%");
$region['all'] = ssotFormatNA($entity->ssot_data['labour_force_survey_industry']['location_thompson_okanagan_employment_all_industries_pct'], 1, "%");
$regions[] = $region;
$region = array();
$region['name'] = t(REGION_VANCOUVER_ISLAND_COAST);
$region['industry'] = floatval($entity->ssot_data['labour_force_survey_industry']['location_vancouver_island_coast_employment_this_industry_pct']);
$region['all'] = floatval($entity->ssot_data['labour_force_survey_industry']['location_vancouver_island_coast_employment_all_industries_pct']);
$region['industry'] = ssotFormatNA($entity->ssot_data['labour_force_survey_industry']['location_vancouver_island_coast_employment_this_industry_pct'], 1, "%");
$region['all'] = ssotFormatNA($entity->ssot_data['labour_force_survey_industry']['location_vancouver_island_coast_employment_all_industries_pct'], 1, "%");
$regions[] = $region;
}


$content = "<table>";
$content .= "<tr><th>Region</th><th>% Employment this Industry</th><th>% Employment All Industries</th></tr>";
foreach ($regions as $region) {
$content .= "<tr><td>" . $region['name'] . "</td><td>" . ssotFormatNumber($region['industry'], 1) . "%</td><td>" . ssotFormatNumber($region['all'],1) . "%</td></tr>";
$content .= "<tr><td>" . $region['name'] . "</td><td>" . $region['industry'] . "</td><td>" . $region['all'] . "</td></tr>";
}
$content .= "</table>";
$output = $content;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,17 @@ function ssotIndustryName($machine_name) {
return isset($industries[$machine_name]) ? $industries[$machine_name] : "";
}

function ssotFormatNA($number, $decimals = 0, $suffix = "") {

if ($number===0||$number) {
$result = ssotFormatNumber(floatval($number), $decimals) . $suffix;
}
else {
$result = WORKBC_EXTRA_FIELDS_NOT_AVAILABLE;
}
return $result;
}


/*
custom number format function to add '+' if required
Expand Down

0 comments on commit 716c19a

Please sign in to comment.