Current Path : /data/web/virtuals/51568/virtual/www/subdom/pomucky.1/temp/ |
Current File : /data/web/virtuals/51568/virtual/www/subdom/pomucky.1/temp/objedTridy.php.bak2 |
<?php namespace app\models; use app\Model; use app\Application; class ObjedTridy extends Model { public $id; public $idpredmet; public $idpomucka; public $kusu = 0; public function rules(): array { $this->specialErrorMessages['kusu'][self::RULE_MINNUM] = 'nejméně {minnum}'; $this->specialErrorMessages['kusu'][self::RULE_MAXNUM] = 'nejvýše {maxnum}'; return [ 'id' => [], 'idpredmet' => [], 'idpomucka' => [], 'kusu' => [[self::RULE_MINNUM, 'minnum' => 0], [self::RULE_MAXNUM, 'maxnum' => 999]], ]; } public function types(): array { return [ 'id' => self::FIELD_INPUT, 'idpredmet' => self::FIELD_INPUT, 'idpomucka' => self::FIELD_INPUT, 'kusu' => self::FIELD_INPUT ]; } public function getTridy() { $sql = "SELECT `id`, `nazev` FROM `tridy` ORDER BY `nazev`"; $tridy = Application::$app->db->fetchAll($sql); $select = []; foreach($tridy as $trida){ $select[] = ['label' => $trida->nazev, 'value' => $trida->id]; } return $select; } public function objedTridyZobraz($data) { $sql = "SELECT `id`, `nazev`, `zaku`, `ucitel` FROM `tridy` WHERE `id`=:id"; $trida = Application::$app->db->fetchOne($sql, $data->id); $rocnik = explode('.', $trida->nazev)[0]; $stupen = ($rocnik < 6) ? 'stupen1' : 'stupen2'; $sql = "SELECT `id`, `nazev` FROM `pm_predmety` WHERE $stupen='1' ORDER BY `nazev`"; $predmety = Application::$app->db->fetchAll($sql); $predmetyArray = []; $predmetyCount = 0; foreach($predmety as $predmet) { $predmetyArray[] = $predmet->id; $predmetyCount++; } $sql = "SELECT `id`, `nazev`, `prodejni_cena` FROM `pm_pomucky` order by `poradi`"; $pomucky = Application::$app->db->fetchAll($sql); $pomuckyArray = []; $pomuckyZak = []; foreach($pomucky as $pomucka) { $pomuckyArray[$pomucka->id] = $pomucka->prodejni_cena; $pomuckyZak[$pomucka->id] = 0; } $sql = "SELECT `id`, `idpomucka`, `idpredmet`, `kusu` FROM `pm_objednavky` WHERE `idtrida` = :id"; $objednavky = Application::$app->db->fetchAll($sql, $data->id); $objednavkyArray = []; foreach($objednavky as $objednavka) { $objednavkyArray[$objednavka->idpomucka . "#" . $objednavka->idpredmet] = $objednavka->id . "#" . $objednavka->kusu; $pomuckyZak[$objednavka->idpomucka] += $objednavka->kusu; } $pomuckyTrida = []; foreach ($pomuckyArray as $keyPomucka => $pomucka) { foreach($predmetyArray as $keyPredmet => $predmet) { $value = (array_key_exists($keyPomucka . "#" . $keyPredmet, $objednavkyArray)) ? $objednavkyArray[$keyPomucka . "#" . $keyPredmet] : "0#"; $pomuckyTrida[$keyPomucka][$keyPredmet] = $keyPomucka . "#" . $keyPredmet . "#" . $value; } } var_dump($pomuckyTrida); return [$trida, $predmety, $pomucky, $pomuckyTrida, $predmetyCount, $pomuckyZak]; } }