fid = $fid;
$datarow = $kdb->getCalculationProgress($fid);
$this->setProgress($datarow);
$this->setFootprint($datarow['footprint']);
$this->setFootprintPP($datarow['footprint_pp']);
$this->setShared($datarow['shared']);
$this->setComment($datarow['comment']);
$this->setCreated($datarow['created']);
$this->setUID($datarow['userid']);
$this->setCalculation(unserialize($datarow['calculation']));
$this->setIsOrg($kdb->getIsOrgByUserId($this->getUID()));
}
public function getCID() {
return $this->fid;
}
public function getProgress() {
return $this->progress;
}
public function setProgress($dt) {
$this->progress = $dt;
}
public function getCalculation() {
return $this->calculation;
}
public function setCalculation($dt) {
$this->calculation = $dt;
}
public function getFootprint() {
return $this->footprint;
}
public function setFootprint($dt) {
$this->footprint = $dt;
}
public function getFootprintPP() {
return $this->footprint_pp;
}
public function setFootprintPP($dt) {
$this->footprint_pp = $dt;
}
public function getShared() {
return $this->shared;
}
public function setShared($dt) {
$this->shared = $dt;
}
public function getComment() {
return $this->comment;
}
public function setComment($dt) {
$this->comment = $dt;
}
public function getUID() {
return $this->uid;
}
public function setUID($dt) {
$this->uid = $dt;
}
public function getCreated() {
return $this->created;
}
public function setCreated($dt) {
$this->created = $dt;
}
public function getIsOrg() {
return $this->org;
}
public function setIsOrg($dt) {
$this->org = $dt;
}
public function getFootprintTitle() {
global $user;
$uo = $user->getUserById($this->getUID());
if ($uo['org']) {
$org = $uo['organization'];
if ($org){
return $org;
}
}
$name = $uo['firstname']." ".$uo['lastname'];
if ($name) {
return $name;
}
return $uo['uname'];
}
public function getTitles() {
$titles = array('Elektrienergia'=>array('Põlevkivi'=>'fifth',
'Roheline energia'=>'sixth'),
'Soojusenergia'=>array('Kivisüsi'=>'fifth',
'Nafta'=>'seventh',
'Maagaas'=>'ninth',
'Tuuleenergia'=>'eighth',
'Päikeseenergia'=>'soojus',
'Biomass'=>'sixth',
'Hüdroenergia'=>'third'),
'Vesi'=>array('Vesi'=>'eighth'),
'Inimeste transport'=>array('Autotransport'=>'seventh',
'Takso'=>'soojus',
'Bussitransport'=>'fifth',
'Rongitransport'=>'sixth',
'Laevatransport'=>'third',
'Lennutransport'=>'eighth'),
'Jäätmed'=>array('Taaskasutusse suunatud paber ja papp'=>'sixth',
'Taaskasutusse suunatud pakendid'=>'fifth',
'Taaskasutusse suunatud klaasijäätmed'=>'eighth',
'Taaskasutusse suunatud plastijäätmed'=>'soojus',
'Taaskasutusse suunatud metall'=>'ninth',
'Olmeprügi (prügilasse)'=>'second'),
'Kaupade transport'=>array('Maanteetransport'=>'seventh',
'Laevatransport'=>'third',
'Rongitransport'=>'sixth',
'Lennutransport'=>'eighth')
);
if (!$this->getIsOrg()) {
array_pop($titles);
}
return $titles;
}
public function getPercents() {
$fpt = $this->getFootprint();
$calc = $this->getCalculation();
$percs = array();
$width = 440;
$lwidth = 186;
$po = 0;
$cal = 0;
$total_perc = 0;
$total_percs = array();
if ($fpt && $calc) {
foreach ($calc as $ca) {
$pr = 0;
$lpr = 0;
$pro = 0;
$pos = 0;
$cal = $ca['calc'];
if ($cal) {
$pro = $cal/$fpt*100;
$pr = round($pro)*$width/100;
$lpr = round($pro)*$lwidth/100;
if ($pro<1) {
$pro = "alla 1";
} else {
$pro = round($pro);
}
}
if ($pr > 0) {
if ($pr<10){
$pr = 10;
$pos = $po;
} else {
$pos = $po + ($pr/2)-5;
}
if ($lpr<4){
$lpr = 4;
}
}
$po = $po + $pr;
$cfpt = 0;
$cprs = array();
$total_c_perc = 0;
foreach ($ca['data'] as $cd) {
$cfpt = $cd['fpt'];
$pros = 0;
$cpr = 0;
if ($cfpt) {
$pros = $cfpt/$cal*100;
$cpr = $pros*$width/100;
if ($pros<1) {
$pros = "alla 1";
} else if ($pros>99 && $pros<99.999) {
$pros = "üle 99";
} else {
$pros = round($pros);
}
if ($cpr<5 && $cpr!=0){
$cpr = 5;
}
}
$total_c_perc = $total_c_perc + $cpr;
$cprs []= array('val'=>$cpr, 'pros'=>$pros);
}
$total_perc = $total_perc + $pr;
$total_percs []= round($total_c_perc);
$percs []= array('perc'=>$pr, 'lperc'=>$lpr, 'pos'=>$pos, 'cperc'=>$cprs, 'val'=>$ca['val'], 'pros'=>$pro);
}
if (!$this->getIsOrg()) {
array_pop($percs);
}
if ($total_perc!=$width && $total_perc>0) {
$p_index = 0;
$cut_off_perc = $width/$total_perc;
foreach ($percs as $p_cut) {
$new_perc = $cut_off_perc*$p_cut['perc'];
$new_pos = $cut_off_perc*$p_cut['pos'];
$percs[$p_index]['perc'] = $new_perc;
$percs[$p_index]['pos'] = $new_pos;
$p_index++;
}
}
$p_index = 0;
foreach ($total_percs as $t_perc) {
if ($t_perc!=$width && $t_perc>0) {
$cut_off_perc = $width/$t_perc;
$pc_index = 0;
$check_it = 0;
foreach ($percs[$p_index]['cperc'] as $cperc) {
$new_perc = $cut_off_perc*$cperc['val'];
$check_it = $check_it + round($new_perc);
$percs[$p_index]['cperc'][$pc_index]['val'] = $new_perc;
$pc_index++;
}
if ($check_it<$width) {
$percs[$p_index]['cperc'][0]['val'] = $percs[$p_index]['cperc'][0]['val'] + $width-$check_it;
}
}
$p_index++;
}
return $percs;
}
return false;
}
}
?>