sigd/app/Models/ActivityGpcOutput.php

66 lines
2.4 KiB
PHP

<?php
namespace App\Models;
class ActivityGpcOutput extends SigdModel
{
protected $table = 'gpc_output';
protected $fillable = [
'id', 'inventory_year', 'activity_year', 'population', 'area', 'gdp',
'i_1_1', 'i_1_2', 'i_1_3', 'i_2_1', 'i_2_2', 'i_2_3', 'i_3_1', 'i_3_2', 'i_3_3', 'i_4_1',
'i_4_2', 'i_4_3', 'i_4_4', 'i_5_1', 'i_5_2', 'i_5_3', 'i_6_1', 'i_6_2', 'i_6_3', 'i_7_1', 'i_8_1',
'ii_1_1', 'ii_1_2', 'ii_1_3', 'ii_2_1', 'ii_2_2', 'ii_2_3', 'ii_3_1',
'ii_3_2', 'ii_3_3', 'ii_4_1', 'ii_4_2', 'ii_4_3', 'ii_5_1', 'ii_5_2', 'ii_5_3',
'iii_1_1', 'iii_1_2', 'iii_1_3', 'iii_2_1', 'iii_2_2', 'iii_2_3', 'iii_3_1', 'iii_3_2', 'iii_3_3',
'iii_4_1', 'iii_4_2', 'iii_4_3', 'iv_1', 'iv_2', 'v_1', 'v_2', 'v_3', 'vi_1',
'credits_i', 'credits_ii', 'credits_iii', 'credits_iv', 'credits_v', 'credits_vi', 'gpc_basic',
'row_status', 'created_by', 'updated_by',
];
private $columnRefs = [
'i_1_1', 'i_1_2', 'i_1_3', 'i_2_1', 'i_2_2', 'i_2_3', 'i_3_1', 'i_3_2', 'i_3_3', 'i_4_1',
'i_4_2', 'i_4_3', 'i_4_4', 'i_5_1', 'i_5_2', 'i_5_3', 'i_6_1', 'i_6_2', 'i_6_3', 'i_7_1', 'i_8_1',
'ii_1_1', 'ii_1_2', 'ii_1_3', 'ii_2_1', 'ii_2_2', 'ii_2_3', 'ii_3_1',
'ii_3_2', 'ii_3_3', 'ii_4_1', 'ii_4_2', 'ii_4_3', 'ii_5_1', 'ii_5_2', 'ii_5_3',
'iii_1_1', 'iii_1_2', 'iii_1_3', 'iii_2_1', 'iii_2_2', 'iii_2_3', 'iii_3_1', 'iii_3_2', 'iii_3_3',
'iii_4_1', 'iii_4_2', 'iii_4_3', 'iv_1', 'iv_2', 'v_1', 'v_2', 'v_3', 'vi_1',
];
public function getColumnValueOrReference($columnName)
{
$value = $this->$columnName;
if ($columnName == 'created_by' || $columnName == 'updated_by') {
return $value;
}
if (is_null($value)) {
$gpcCode = str_replace('_', '.', strtoupper($columnName));
$reference = ReferenceGpc::where('gpc_code', $gpcCode)->first();
if ($reference) {
return $reference->notation_key;
}
}
if ($value == 0) {
return 'NE';
}
return $value;
}
public function getAllColumnsWithReference()
{
$columns = array_intersect($this->getFillable(), $this->columnRefs);
// $columns = $this->getFillable();
$data = [];
foreach ($columns as $column) {
$data[$column] = $this->getColumnValueOrReference($column);
}
return $data;
}
}