/** * * @param type $termsObj * @return type * * vystupni format osevniho postupu */ public function manage_terms($termsObj) { $sum_C = 0; $terms = []; for ($key = 0; $key < count($termsObj); $key++) { $prevKey = ($key + count($termsObj) - 1) % count($termsObj); if ($termsObj[$key]->poradi === 1) { $year = date("Y", strtotime($termsObj[$key]->terms['term_1'])); $month = date("m", strtotime($termsObj[$prevKey]->terms['term_4'])); $day = date("d", strtotime($termsObj[$prevKey]->terms['term_4'])); if (strtotime($year . $month . $day) >= strtotime($termsObj[$key]->terms['term_1'])) { $previousFazeEnd = $year - 1 . $month . $day; } else { $previousFazeEnd = $year . $month . $day; } } else { $previousFazeEnd = $termsObj[$prevKey]->terms['term_4']; } $termsObj[$key]->setFaze($previousFazeEnd); $previous_id_skupina_plodina = $termsObj[$prevKey]->plodina->getIdSkupinaPlodina(); $Ci = vypocetData::getCi($termsObj[$key]->plodina->getIdSkupinaPlodina(), $termsObj[$key]->agrotech->getId(), $previous_id_skupina_plodina, $termsObj[$key]->plodina->getMeziplodina()); $plodina_C[$key] = $this->solveC_new($termsObj[$key]->faze, $Ci); $terms[$key]["c"] = $plodina_C[$key]['c_plodina']; $terms[$key]["priprava"] = $termsObj[$key]->terms['term_1']; $terms[$key]["seti"] = $termsObj[$key]->terms['term_2']; $terms[$key]["sklizen"] = $termsObj[$key]->terms['term_3']; $terms[$key]["orba"] = $termsObj[$key]->terms['term_4']; $terms[$key]["faze_1_start"] = $termsObj[$key]->faze['faze_1']['start']; $terms[$key]["faze_1_end"] = $termsObj[$key]->faze['faze_1']['end']; $terms[$key]["faze_2_start"] = $termsObj[$key]->faze['faze_2']['start']; $terms[$key]["faze_2_end"] = $termsObj[$key]->faze['faze_2']['end']; $terms[$key]["faze_3_start"] = $termsObj[$key]->faze['faze_3']['start']; $terms[$key]["faze_3_end"] = $termsObj[$key]->faze['faze_3']['end']; $terms[$key]["faze_4_start"] = $termsObj[$key]->faze['faze_4']['start']; $terms[$key]["faze_4_end"] = $termsObj[$key]->faze['faze_4']['end']; $terms[$key]["faze_5_start"] = $termsObj[$key]->faze['faze_5']['start']; $terms[$key]["faze_5_end"] = $termsObj[$key]->faze['faze_5']['end']; $terms[$key]["poradi"] = $termsObj[$key]->poradi; $terms[$key]["plodina"] = $termsObj[$key]->plodina->getNazev(); $terms[$key]["id_plodina"] = $termsObj[$key]->plodina->getId(); $terms[$key]["agrotech"] = $termsObj[$key]->agrotech->getNazev(); $terms[$key]["id_agrotech"] = $termsObj[$key]->agrotech->getId(); $terms[$key]["meziplodina"] = $termsObj[$key]->plodina->getMeziplodina(); $plodina_C[$key]['plodina'] = $termsObj[$key]->plodina->getNazev(); $sum_C = $sum_C + $plodina_C[$key]['c_plodina']; } $first_date = strtotime($termsObj[0]->faze['faze_1']['start']); $second_date = strtotime($termsObj[count($termsObj) - 1]->faze['faze_5']['end']); $numYears = round(($second_date - $first_date) / (60 * 60 * 24) / 365); $sum_C = $sum_C / $numYears; return ['c_osev' => $sum_C, 'c_plodina' => $plodina_C, 'numYears' => $numYears, 'terms' => $terms]; }