public function getClusterData($idName, $cluster) { // we first build the json object from the cluster ids, then pass it to the builder $oject = ''; $oject_table = ''; if (CostbenefitprojectionHelper::isJson($cluster) && CostbenefitprojectionHelper::checkString($idName)) { $array = json_decode($cluster, true); // get te set intervention data $interventions = array(); if (CostbenefitprojectionHelper::checkArray($array)) { foreach ($array as $intervention) { $interventions[$intervention] = CostbenefitprojectionHelper::getVar('intervention', $intervention, 'id', 'intervention'); } } // sort the data $bucket = array(); if (CostbenefitprojectionHelper::checkArray($interventions)) { foreach ($interventions as $inter => $set) { if (CostbenefitprojectionHelper::isJson($set)) { $set = json_decode($set, true); if (CostbenefitprojectionHelper::checkArray($set)) { foreach ($set as $option => $values) { foreach ($values as $nr => $value) { $bucket[$inter][$nr][$option] = $value; } } } } } } // combine the data $combine = array(); if (CostbenefitprojectionHelper::checkArray($bucket)) { foreach ($bucket as $pool) { if (CostbenefitprojectionHelper::checkArray($pool)) { foreach ($pool as $headers) { if (CostbenefitprojectionHelper::checkArray($headers)) { // check if this cause is already targeted if (isset($combine[$headers['causerisk']])) { // combine $temp = $combine[$headers['causerisk']]; $temp['cpe'] = $this->combineValues($temp['cpe'], $headers['cpe']); $temp['mbr'] = $this->combineValues($temp['mbr'], $headers['mbr']); $temp['mtr'] = $this->combineValues($temp['mtr'], $headers['mtr']); // update the data $combine[$headers['causerisk']] = $temp; } else { // set for first time $combine[$headers['causerisk']] = array('cpe' => $headers['cpe'], 'mbr' => $headers['mbr'], 'mtr' => $headers['mtr']); } } } } } } // setup the object if (CostbenefitprojectionHelper::checkArray($combine)) { $oject = array(); foreach ($combine as $causerisk => $vals) { if (CostbenefitprojectionHelper::checkArray($vals)) { $oject['causerisk'][] = $causerisk; foreach ($vals as $header => $v) { // set placeholder $oject[$header][] = $v; } } } // done at last $oject = json_encode($oject); } } // return the table and values return array('table' => $this->getInterventionBuildTable($idName, $oject, 'ja'), 'values' => $oject); }
public function setCompany() { if (CostbenefitprojectionHelper::checkObject($this->company)) { // main switch $usecountry = false; // public switch if (isset($this->company->public)) { $usecountry = true; $cKey = 'id'; } else { $cKey = 'country'; } // set array of json objects to convert to array $jsonObjects = array('percentmale', 'percentfemale', 'country_percentmale', 'country_percentfemale', 'country_maledeath', 'country_femaledeath', 'country_maleyld', 'country_femaleyld'); $removeArray = array('asset_id', 'not_required', 'published', 'created_by', 'country_created_by', 'country_created', 'country_version', 'country_hits', 'country_ordering', 'modified_by', 'country_asset_id', 'created', 'modified', 'version', 'hits', 'ordering', 'country_published', 'country_modified_by', 'country_modified', 'country_maledeath', 'country_femaledeath', 'country_maleyld', 'country_femaleyld', 'idCompanyScaling_factorC', $cKey . 'CountryHealth_dataB', $cKey . 'CountryHealth_dataBB', 'causesrisksIdCauseriskG', 'causesrisksIdCauseriskGG', 'idCompanyInterventionD', 'countryCountryInterventionDD', 'idCountryInterventionDD'); foreach ($jsonObjects as $jsonObject) { if (isset($this->company->{$jsonObject}) && CostbenefitprojectionHelper::isJson($this->company->{$jsonObject})) { // convert to array $array = json_decode($this->company->{$jsonObject}, true); if (CostbenefitprojectionHelper::checkArray($array)) { $this->company->{$jsonObject} = array(); foreach ($array as $option => $values) { if (CostbenefitprojectionHelper::checkArray($values)) { foreach ($values as $nr => $value) { $this->company->{$jsonObject}[$nr][$option] = $value; } } } } } } // if company has not causerisks selected fall back on country if ($usecountry || isset($this->company->causesrisks) && !CostbenefitprojectionHelper::checkArray($this->company->causesrisks) || $this->company->department == 1) { $this->company->causesrisks = $this->company->country_causesrisks; $this->company->medical_turnovers_males = $this->company->males * ($this->company->country_medical_turnovers / 100000); $this->company->medical_turnovers_females = $this->company->females * ($this->company->country_medical_turnovers / 100000); $this->company->sick_leave_males = $this->company->males * $this->company->country_sick_leave; $this->company->sick_leave_females = $this->company->females * $this->company->country_sick_leave; $this->company->datayear = $this->company->country_datayear; $this->company->total_healthcare = $this->company->country_healthcare / 100 * $this->company->total_salary; $this->company->working_days = $this->company->country_working_days; $this->company->productivity_losses = $this->company->country_productivity_losses; $usecountry = true; } // percent sorting $percentSort = array('percentmale', 'percentfemale', 'country_percentmale', 'country_percentfemale'); foreach ($percentSort as $sort) { $point = $sort; if (isset($this->company->{$sort}) && !CostbenefitprojectionHelper::checkArray($this->company->{$sort}) && strpos($sort, 'country') === false) { $sort = 'country_' . $sort; } if (isset($this->company->{$sort}) && CostbenefitprojectionHelper::checkArray($this->company->{$sort})) { $bucket = array(); foreach ($this->company->{$sort} as $value) { $bucket[$value['age']] = (int) $value['percent']; } $this->company->{$point} = $bucket; } } // country totals sorting $countrySort = array('country_maledeath' => array('gender' => 'male', 'type' => 'death'), 'country_femaledeath' => array('gender' => 'female', 'type' => 'death'), 'country_maleyld' => array('gender' => 'male', 'type' => 'yld'), 'country_femaleyld' => array('gender' => 'female', 'type' => 'yld')); $this->company->country_yld = 0; $this->company->country_death = 0; foreach ($countrySort as $sort => $tar) { if (isset($this->company->{$sort}) && CostbenefitprojectionHelper::checkArray($this->company->{$sort})) { foreach ($this->company->{$sort} as $value) { if ($this->company->datayear == $value['year']) { $this->company->{'country_' . $tar['type']} += $value['number']; } } } } // country health totals sorting $specialSort = array('maledeath', 'maleyld', 'femaledeath', 'femaleyld'); $keepData = array(); if (isset($this->company->{$cKey . 'CountryHealth_dataB'}) && CostbenefitprojectionHelper::checkArray($this->company->{$cKey . 'CountryHealth_dataB'}) && !$usecountry) { $healthBucket = array(); foreach ($this->company->{$cKey . 'CountryHealth_dataB'} as $healthData) { $healthBucket[$healthData->causerisk] = new stdClass(); foreach ($specialSort as $sort) { if (isset($healthData->{$sort}) && CostbenefitprojectionHelper::isJson($healthData->{$sort})) { // convert to array $array = json_decode($healthData->{$sort}, true); if (CostbenefitprojectionHelper::checkArray($array)) { foreach ($array as $option => $values) { if (CostbenefitprojectionHelper::checkArray($values)) { foreach ($values as $nr => $value) { $healthBucket[$healthData->causerisk]->{$sort}[$nr][$option] = $value; } } } } } } // number sorting foreach ($specialSort as $sort) { if (isset($healthBucket[$healthData->causerisk]->{$sort}) && CostbenefitprojectionHelper::checkArray($healthBucket[$healthData->causerisk]->{$sort})) { $bucket = array(); foreach ($healthBucket[$healthData->causerisk]->{$sort} as $value) { if (CostbenefitprojectionHelper::checkArray($value)) { $buket[$value['age']] = $value['number']; } } $healthBucket[$healthData->causerisk]->{$sort} = $buket; } } // check if we should keep any other data if (CostbenefitprojectionHelper::checkArray($keepData)) { // set data to keep foreach ($keepData as $keep) { $healthBucket[$healthData->causerisk]->{$keep} = $healthData->{$keep}; } } } } elseif (isset($this->company->{$cKey . 'CountryHealth_dataBB'}) && CostbenefitprojectionHelper::checkArray($this->company->{$cKey . 'CountryHealth_dataBB'}) && $usecountry) { $healthBucket = array(); foreach ($this->company->{$cKey . 'CountryHealth_dataBB'} as $healthData) { $healthBucket[$healthData->causerisk] = new stdClass(); foreach ($specialSort as $sort) { if (isset($healthData->{$sort}) && CostbenefitprojectionHelper::isJson($healthData->{$sort})) { // convert to array $array = json_decode($healthData->{$sort}, true); if (CostbenefitprojectionHelper::checkArray($array)) { foreach ($array as $option => $values) { if (CostbenefitprojectionHelper::checkArray($values)) { foreach ($values as $nr => $value) { $healthBucket[$healthData->causerisk]->{$sort}[$nr][$option] = $value; } } } } } } // number sorting foreach ($specialSort as $sort) { if (isset($healthBucket[$healthData->causerisk]->{$sort}) && CostbenefitprojectionHelper::checkArray($healthBucket[$healthData->causerisk]->{$sort})) { $bucket = array(); foreach ($healthBucket[$healthData->causerisk]->{$sort} as $value) { if (CostbenefitprojectionHelper::checkArray($value)) { $buket[$value['age']] = $value['number']; } } $healthBucket[$healthData->causerisk]->{$sort} = $buket; } } // check if we should keep any other data if (CostbenefitprojectionHelper::checkArray($keepData)) { // set data to keep foreach ($keepData as $keep) { $healthBucket[$healthData->causerisk]->{$keep} = $healthData->{$keep}; } } } } // set health data $this->company->healthData = $healthBucket; unset($healthBucket); // set company scaling $keepData = array('yld_scaling_factor_males', 'yld_scaling_factor_females', 'mortality_scaling_factor_males', 'mortality_scaling_factor_females', 'presenteeism_scaling_factor_males', 'presenteeism_scaling_factor_females', 'health_scaling_factor'); $scalingBucket = array(); if (isset($this->company->idCompanyScaling_factorC) && CostbenefitprojectionHelper::checkArray($this->company->idCompanyScaling_factorC)) { // use the compony set values foreach ($this->company->idCompanyScaling_factorC as $scalingFactor) { $scalingBucket[$scalingFactor->causerisk] = new stdClass(); foreach ($keepData as $keep) { $scalingBucket[$scalingFactor->causerisk]->{$keep} = $scalingFactor->{$keep}; } } } else { // set defaults foreach ($this->company->causesrisks as $scalingFactor) { $scalingBucket[$scalingFactor] = new stdClass(); foreach ($keepData as $keep) { $scalingBucket[$scalingFactor]->{$keep} = 1; } } } // set scaling factors $this->company->scalingFactors = $scalingBucket; unset($scalingBucket); // set Cause/Risk Details $keepData = array('id', 'ref', 'name', 'alias', 'category', 'description'); if (isset($this->company->causesrisksIdCauseriskG) && CostbenefitprojectionHelper::checkArray($this->company->causesrisksIdCauseriskG) && !$usecountry) { foreach ($this->company->causesrisksIdCauseriskG as $causesrisks) { $this->items[$causesrisks->id] = new stdClass(); $this->items[$causesrisks->id]->details = new stdClass(); foreach ($keepData as $keep) { $this->items[$causesrisks->id]->details->{$keep} = $causesrisks->{$keep}; } } } elseif (isset($this->company->causesrisksIdCauseriskGG) && CostbenefitprojectionHelper::checkArray($this->company->causesrisksIdCauseriskGG) && $usecountry) { foreach ($this->company->causesrisksIdCauseriskGG as $causesrisks) { $this->items[$causesrisks->id] = new stdClass(); $this->items[$causesrisks->id]->details = new stdClass(); foreach ($keepData as $keep) { $this->items[$causesrisks->id]->details->{$keep} = $causesrisks->{$keep}; } } } // set company insterventions $keepData = array('id', 'name', 'coverage', 'duration', 'description', 'reference', 'share', 'type'); $insterventionBucket = array(); if (isset($this->company->idCompanyInterventionD) && CostbenefitprojectionHelper::checkArray($this->company->idCompanyInterventionD)) { foreach ($this->company->idCompanyInterventionD as $key => $intervention) { $insterventionBucket[$key] = new stdClass(); foreach ($keepData as $keep) { $insterventionBucket[$key]->{$keep} = $intervention->{$keep}; } // load the most important part, the actual intervention data $array = json_decode($intervention->intervention, true); if (CostbenefitprojectionHelper::checkArray($array)) { $insterventionBucket[$key]->data = array(); foreach ($array as $option => $values) { if (CostbenefitprojectionHelper::checkArray($values)) { foreach ($values as $nr => $value) { if ('causerisk' == $option) { $insterventionBucket[$key]->data[$nr]['id'] = $value; $insterventionBucket[$key]->data[$nr]['allias'] = CostbenefitprojectionHelper::getVar('causerisk', $value, 'id', 'alias'); } else { // set values $insterventionBucket[$key]->data[$nr][$option] = $value; } } } } } } } elseif ($usecountry || isset($this->company->{$cKey . 'CountryInterventionDD'}) && CostbenefitprojectionHelper::checkArray($this->company->{$cKey . 'CountryInterventionDD'})) { foreach ($this->company->{$cKey . 'CountryInterventionDD'} as $key => $intervention) { $insterventionBucket[$key] = new stdClass(); foreach ($keepData as $keep) { $insterventionBucket[$key]->{$keep} = $intervention->{$keep}; } // load the most important part, the actual intervention data $array = json_decode($intervention->intervention, true); if (CostbenefitprojectionHelper::checkArray($array)) { $insterventionBucket[$key]->data = array(); foreach ($array as $option => $values) { if (CostbenefitprojectionHelper::checkArray($values)) { foreach ($values as $nr => $value) { if ('causerisk' == $option) { $insterventionBucket[$key]->data[$nr]['id'] = $value; $insterventionBucket[$key]->data[$nr]['allias'] = CostbenefitprojectionHelper::getVar('causerisk', $value, 'id', 'alias'); } else { // set values $insterventionBucket[$key]->data[$nr][$option] = $value; } } } } } } } // set intervention to company data $this->company->interventions = $insterventionBucket; unset($insterventionBucket); // remove undeeded values if (CostbenefitprojectionHelper::checkArray($removeArray)) { foreach ($removeArray as $remove) { // remove value if set if (isset($this->company->{$remove})) { unset($this->company->{$remove}); } } } return true; } return false; }
function setIntervention($item) { if (CostbenefitprojectionHelper::isJson($item->intervention)) { $bucket = array(); $bucketsmall = array(); $interventions = json_decode($item->intervention); foreach ($interventions as $name => $values) { if (CostbenefitprojectionHelper::checkArray($values)) { foreach ($values as $pointer => $value) { if (!isset($bucket[$pointer])) { $bucket[$pointer] = ''; $bucketsmall[$pointer] = ''; } switch ($name) { case 'causerisk': $causeName = CostbenefitprojectionHelper::getVar('causerisk', $value, 'id', 'name'); $bucket[$pointer] .= '<td>' . $causeName . "</td>"; $bucketsmall[$pointer] .= $causeName . ': '; break; case 'cpe': $bucket[$pointer] .= '<td class="uk-text-center"><span class="uk-badge uk-badge-notification uk-badge-success">' . $value . '</span></td>'; $bucketsmall[$pointer] .= '<span class="uk-badge uk-badge-success">' . $name . ' ' . $value . '</span> '; break; case 'mbr': $bucket[$pointer] .= '<td class="uk-text-center"><span class="uk-badge uk-badge-notification uk-badge-success">' . $value . '</span></td>'; $bucketsmall[$pointer] .= '<span class="uk-badge uk-badge-success">' . $name . ' ' . $value . '</span> '; break; case 'mtr': $bucket[$pointer] .= '<td class="uk-text-center"><span class="uk-badge uk-badge-notification uk-badge-success">' . $value . '</span></td>'; $bucketsmall[$pointer] .= '<span class="uk-badge uk-badge-success">' . $name . ' ' . $value . '</span>'; break; } } } } } return '<td><table class="uk-table uk-table-hover uk-table-striped uk-table-condensed uk-hidden-small"><thead><tr><th>' . JText::_('COM_COSTBENEFITPROJECTION_CAUSERISK') . '</th><th>' . JText::_('COM_COSTBENEFITPROJECTION_COST_PER_EMPLOYEE') . '</th><th>' . JText::_('COM_COSTBENEFITPROJECTION_MORBIDITY_REDUCTION') . '</th><th>' . JText::_('COM_COSTBENEFITPROJECTION_MORTALITY_REDUCTION') . '</th></tr></thead><tbody><tr>' . implode('</tr><tr>', $bucket) . '</tr></tbody></table><div class="uk-visible-small">' . implode('<br />', $bucketsmall) . '</div></td>'; }