getJmeno() . " " . $this->getPrijmeni(); } public function getCursesToString() { $args = $this->getActiveCourses($this->getId()); $str = ""; return $str; } public function archivate($level) { // Whiski - dělalo problémy //foreach($this->Dochazka_list as $dochazka){ // $dochazka->archivate($level); //} foreach ($this->Rozpocet_list as $dochazka) { $dochazka->archivate($level); } foreach ($this->Pracovnik_kurz_list as $pracovnik_kurz) { $pracovnik_kurz->archivate($level); } $this->archive($level); } public function getCursesRozpocetToString() { $args = $this->getActiveCourses($this->getId()); $str = ""; foreach ($args as $arg) { $str .= ""; } $str .= "
" . $this->getRozpocet($arg->getId(), $this->getId(), 'getRozpocet') . "
"; return $str; } public function getCursesRozpocetZbyvaWarToString() { $pomocnik = Doctrine::getTable('Pomocnici_personalisty')->createQuery('u')->where("u.zakaznik_id = " . $this->getZakaznikId())->execute(); $args = $this->getActiveCourses($this->getId()); $str = ""; foreach ($args as $arg) { $class = ""; $value = 0; $count = 0; $cerpano = $this->getRozpocet($arg->getId(), $this->getId(), 'getCerpano'); $rozpocet = $this->getRozpocet($arg->getId(), $this->getId(), 'getRozpocet'); $rozdil = $rozpocet - $cerpano; if ($rozpocet > 0) { if ($rozdil <= 0) $class = "background-color:red;"; if ($rozdil > 0 && $rozdil != $rozpocet) { $count = (100 - (($cerpano / $rozpocet) * 100)); if ($count < $pomocnik[0]->getMinHranice()) $class = "background-color:red;"; } } $str .=""; } $str .= "
" . ($this->getRozpocet($arg->getId(), $this->getId(), 'getRozpocet') - $this->getRozpocet($arg->getId(), $this->getId(), 'getCerpano')) . "
"; return $str; } public function getWarning() { $pomocnik = Doctrine::getTable('Pomocnici_personalisty')->createQuery('u')->where("u.zakaznik_id = " . $this->getZakaznikId())->execute(); $args = $this->getActiveCourses($this->getId()); $error = false; foreach ($args as $arg) { $value = 0; $count = 0; $cerpano = $this->getRozpocet($arg->getId(), $this->getId(), 'getCerpano'); $rozpocet = $this->getRozpocet($arg->getId(), $this->getId(), 'getRozpocet'); $rozdil = $rozpocet - $cerpano; if ($rozpocet > 0 && $cerpano > 0) { if ($rozdil <= 0) $error = true; if ($rozdil > 0 && $rozdil != $rozpocet) { $count = (100 - (($cerpano / $rozpocet) * 100)); if ($count < $pomocnik[0]->getMinHranice()) $error = true; } } } return $error; } public function getWarningIcon() { $error = false; $pomocnik = Doctrine::getTable('Pomocnici_personalisty')->createQuery('u')->where("u.zakaznik_id = " . $this->getZakaznikId())->execute(); $rozpocet_a = $pomocnik[0]->getMinHraniceA(); $dochazka_a = $pomocnik[0]->getMinDochazkaA(); $rozpocet_date = ""; $dochazka_date = ""; $rozpocet_date_from = ""; $rozpocet_date_to = ""; $r = $pomocnik[0]->getMinHraniceDate(); $d = $pomocnik[0]->getMinDochazkaDate(); if (!empty($r)) $rozpocet_date = explode(" - ", $pomocnik[0]->getMinHraniceDate()); if (!empty($d)) $dochazka_date = explode(" - ", $pomocnik[0]->getMinDochazkaDate()); if (!empty($rozpocet_date[0]) && !empty($rozpocet_date[1])) { $rozpocet_date_from = strtotime($rozpocet_date[0]); $rozpocet_date_to = strtotime($rozpocet_date[1]); } if (!empty($dochazka_date[0]) && !empty($dochazka_date[1])) { $dochazka_date_from = strtotime($dochazka_date[0]); $dochazka_date_to = strtotime($dochazka_date[1]); } $pracovnici = Doctrine::getTable('Pracovnik')->createQuery('u')->where("u.zakaznik_id = " . $this->getZakaznikId())->execute(); if (empty($rozpocet_a)) { if (empty($r) || ($rozpocet_date_from > time() && $rozpocet_date_to < time() )) { foreach ($pracovnici as $pracovnik) { $args = $this->getActiveCourses($pracovnik->getId()); foreach ($args as $arg) { $value = 0; $count = 0; $cerpano = $this->getRozpocet($arg->getId(), $pracovnik->getId(), 'getCerpano'); $rozpocet = $this->getRozpocet($arg->getId(), $pracovnik->getId(), 'getRozpocet'); $rozdil = $rozpocet - $cerpano; if ($rozpocet > 0 && $cerpano > 0) { if ($rozdil <= 0) $error = true; if ($rozdil > 0 && $rozdil != $rozpocet) { $count = (100 - (($cerpano / $rozpocet) * 100)); if ($count < $pomocnik[0]->getMinHranice()) $error = true; } } } } } } if (count($this->getErrorPracovniciDochazka($this->getZakaznikId())) != 0 && empty($dochazka_a)) { if (empty($d) || ($dochazka_date_from > time() && $dochazka_date_to < time() )) $error = true; } return $error; } public function getCursesRozpocetZbyvaToString() { $args = $this->getActiveCourses($this->getId()); $str = ""; foreach ($args as $arg) { $str .= ""; } $str .= "
" . $this->getRozpocet($arg->getId(), $this->getId(), 'getRozpocet') - $this->getRozpocet($arg->getId(), $this->getId(), 'getCerpano') . "
"; return $str; } public function getCursesDochazkaToString() { $arg = $this->getActiveCourses($this->getId()); } public function getTostringPracovnikSpecifikace() { $specifikace = $this->getSpecifikacePracovnik(); $str = ''; if (!empty($specifikace)) { $wheres = explode("|", $specifikace); $argSpec = array(); foreach ($wheres as $spec): if (!empty($spec)) $argSpec[] = 'a.id = ' . $spec; endforeach; $speci = Doctrine::getTable('Specifikace_pracovnik') ->createQuery('a') ->andWhere(implode(" OR ", $argSpec)) ->orderBy("pozice ASC") ->execute(); foreach ($speci as $spec): $str .= $spec->getHodnota() . "
"; endforeach; } return $str; } public function getSelectedTrue($str, $strCheck) { if (stristr($str, $strCheck)) return 'checked="checked"'; return ""; } public function getDochazkaForm($pracovnik, $id) { $pracDoch = Doctrine::getTable('Kurz_dochazka')->getCurrentDochazkaWithPracovnik($pracovnik, $id)->execute(); return $pracDoch[0]->getStav(); } public function getActiveCourses($id) { $str = ""; $kurzy = array(); $qs = Doctrine::getTable('Pracovnik_kurz')->getCurrentKurzOfPracovnik($id)->execute(); foreach ($qs as $q) { $kurzy[] = $q->Kurz; } return $kurzy; } /** * * @deprecated - nepoužívat tydle šílenosti */ public function getActivesCourse() { $str = array(); $id = ""; $kurzy = Doctrine::getTable('Pracovnik_kurz') ->createQuery("a") ->where("a.pracovnik_id = " . $this->id) ->execute(); foreach ($kurzy as $kurz) { $id = $kurz->Kurz->getBehKurzuId(); if (!empty($id)) $str[] = " id =" . $kurz->getId(); $id = ""; } if (!empty($str)) return Doctrine::getTable('Pracovnik_kurz')->createQuery("a")->where(implode(" OR ", $str))->execute(); return ""; } /** * * @param string $from * @param string $to * @return Doctrine_Query */ public function getActiveCourseQuery($from = null, $to = null) { if (is_null($from)) { $from = date("Y-m-d"); } if (is_null($to)) { $to = date("Y-m-d"); } return Doctrine::getTable('Kurz')->createQuery('kurz') ->innerJoin('kurz.Pracovnik_kurz_list as pk') ->innerJoin('kurz.Kurz_beh_list as kb') ->addWhere('pk.pracovnik_id = ?', $this->getId()) ->addWhere('(kb.beh_od >= ? AND kb.beh_do <= ?) OR (kb.beh_od >= ? AND kb.beh_od <= ?) OR (kb.beh_do >= ? AND kb.beh_do <= ?) OR (kb.beh_od <= ? AND kb.beh_do >= ?)', array($from, $to, $from, $to, $from, $to, $from, $to)); } /** * * @deprecated - nepoužívat tydle šílenosti */ public function getNonActivesCourse() { $strT = array(); $id = ""; $kurzy = Doctrine::getTable('Pracovnik_kurz')->createQuery("a")->where("a.pracovnik_id = " . $this->id)->execute(); foreach ($kurzy as $kurz) { $id = $kurz->Kurz->getBehKurzuId(); if (empty($id)) $strT[] = " id =" . $kurz->getId(); $id = ""; } if (!empty($strT)) return Doctrine::getTable('Pracovnik_kurz')->createQuery("a")->where(implode(" OR ", $strT))->execute(); return ""; } /** * * @param string $from * @param string $to * @return Doctrine_Query */ public function getDeactiveCourseQuery($from = null, $to = null) { if (is_null($from)) { $from = date("Y-m-d"); } if (is_null($to)) { $to = date("Y-m-d"); } return Doctrine::getTable('Kurz')->createQuery('kurz') ->innerJoin('kurz.Pracovnik_kurz_list as pk') ->innerJoin('kurz.Kurz_beh_list as kb') ->addWhere('pk.pracovnik_id = ?', $this->getId()) ->addWhere('kb.beh_do < ? OR kb.beh_od > ?', array($from, $to)); } /** * Vrátí query se všemi kurzy, kterých se pracovník zúčastnil. * * @param date $from * @param date $to * @return Doctrine_Query */ public function getParticipateCoursesQuery($from = null, $to = null) { $query = Doctrine::getTable('Kurz')->createQuery('kurz') ->innerJoin('kurz.Kurz_beh_list beh') ->innerJoin('beh.Kurz_hodina_list hodina') ->innerJoin('hodina.Dochazka_list dochazka') ->addWhere('dochazka.pracovnik_id = ?', $this->getId()); if (!is_null($from) && !is_null($to)) { $query->addWhere('(beh.beh_od >= ? AND beh.beh_do <= ?) OR (beh.beh_od <= ? AND beh.beh_do >= ?) OR (beh.beh_od <= ? AND beh.beh_do >= ?)', array($from, $to, $from, $from, $to, $to)); } return $query; } public function getKurzHodina($id) { $arg = array(); $qs = Doctrine::getTable('Pracovnik_kurz')->getCurrentKurzOfPracovnik($id)->execute(); foreach ($qs as $q) { } } public function getRozpocet($id, $id_pracovnik, $type) { $sum = 0; if (!empty($id)) { $beh = Doctrine::getTable('Kurz_beh')->getBehFromKurz($id)->execute(); $rozpocet = Doctrine::getTable('Pracovnik_rozpocet')->getCurrentRozpocet($id_pracovnik, $beh[0]->getId())->execute(); if (count($rozpocet) == 1 && $rozpocet[0]->$type() > 0) $sum = $rozpocet[0]->$type(); } return $sum; } public function cerpaneProstredky(Kurz_beh $beh, $od = null, $do = null) { $query = Doctrine::getTable('Kurz_dochazka')->createQuery('dochazka') ->innerJoin('dochazka.Kurz_hodina hodina') ->innerJoin('hodina.Kurz_beh beh') ->select('sum(dochazka.cena) as sum') ->addWhere('beh.id = ?', $beh->getId()) ->addWhere('hodina.zruseno = ? OR hodina.zruseno = ?', array('ne', 'pozde')) ->addWhere('dochazka.pracovnik_id = ?', $this->getId()); if (!is_null($od)) { $query->addWhere('hodina.datum >= ?', $od); } if (!is_null($do)) { $query->addWhere('hodina.datum <= ?', $do); } $dochazky = $query->fetchArray(); return isset($dochazky[0]['sum']) ? round($dochazky[0]['sum']) : 0; } public function getDatumPrvniNavstevyBehu($beh_id) { $q = Doctrine::getTable('Kurz_dochazka') ->createQuery('d') ->select('d.id, h.datum') ->leftJoin('d.Kurz_hodina h') ->where('h.kurz_beh_id = ?', $beh_id) ->andWhere('d.pracovnik_id = ?', $this->id) ->orderBy('h.datum') ->limit(1); $q = $q->execute(); foreach ($q AS $d) { $datum = $d->datum; }; return "kokot"; } // public function getDochazka($id_kurz){ // $id = $this->getId(); // $sum = 0; // $sumAll = 0; // $sumaA = 0; // $beh = Doctrine::getTable('Kurz_beh')->getBehFromKurz($id_kurz)->execute(); // if(count($beh) >0){ // $hodiny = Doctrine::getTable('Kurz_hodina')->getHodina($beh[0]->getId())->where("kurz_beh_id = ".$beh[0]->getId())->execute(); // // if(count($hodiny) >0){ // foreach($hodiny as $hodina){ // $sumAll++; // $sumaA += count(Doctrine::getTable('Kurz_dochazka')->getHodinaByBeh($id,$hodina->getId())->where("kurz_hodina_id = ".$hodina->getId())->andWhere("stav = 'A'")->andWhere('pracovnik_id='.$id)->execute()); // // } // } // } // // wtf???? // if($sumAll != 0 || $sumaA!=0) return number_format(($sumaA/$sumAll)*100, 0)."%"; // return number_format($sum, 0)."%"; // } /** * Vrátí procentuální docházku do konkrétního běhu. * * @param Kurz_beh $beh * @return integer */ public function procentualniDochazka(Kurz_beh $beh, $od = null, $do = null) { $hodiny = $this->fakturovanychHodin($beh, $od, $do); if ($hodiny == 0) { return 0; } $dochazky = $this->absolvovanychHodin($beh, $od, $do); if ($dochazky == 0) { return 0; } return round(($dochazky / $hodiny) * 100); } /** * Vrátí počet absolvovaných hodin konkrétního běhu. * * @param Kurz_beh $beh * @return integer */ public function absolvovanychHodin(Kurz_beh $beh, $od = null, $do = null) { $query = Doctrine::getTable('Kurz_dochazka')->createQuery('dochazka') ->innerJoin('dochazka.Kurz_hodina hodina') ->innerJoin('hodina.Kurz_beh beh') ->addWhere('beh.id = ?', $beh->getId()) ->addWhere('dochazka.stav = ?', 'A') ->addWhere('dochazka.pracovnik_id = ?', $this->getId()); if (!is_null($od)) { $query->addWhere('hodina.datum >= ?', $od); } if (!is_null($do)) { $query->addWhere('hodina.datum <= ?', $do); } return $query->count(); } /** * Vrátí počet fakturovaných hodin konkrétního běhu. * * @param Kurz_beh $beh * @return integer */ public function fakturovanychHodin(Kurz_beh $beh, $od = null, $do = null) { $query = Doctrine::getTable('Kurz_dochazka')->createQuery('dochazka') ->innerJoin('dochazka.Kurz_hodina hodina') ->innerJoin('hodina.Kurz_beh beh') ->addWhere('beh.id = ?', $beh->getId()) ->addWhere('dochazka.stav = ? OR dochazka.stav = ? OR dochazka.stav = ?', array('A', 'N', 'ZP')) ->addWhere('dochazka.pracovnik_id = ?', $this->getId()); if (!is_null($od)) { $query->addWhere('hodina.datum >= ?', $od); } if (!is_null($do)) { $query->addWhere('hodina.datum <= ?', $do); } return $query->count(); } public function getHodinaReportBehu($beh_id, $datum_od = null, $datum_do = null) { $q = Doctrine::getTable('Kurz_dochazka') ->createQuery('d') ->select('d.stav, d.cena, h.zruseno') ->leftJoin('d.Kurz_hodina h') ->where('h.kurz_beh_id = ?', $beh_id) ->andWhere('d.pracovnik_id = ?', $this->id); if (!empty($datum_od)) $q->andWhere('h.datum >= ?', $datum_od); if (!empty($datum_do)) $q->andWhere('h.datum <= ?', $datum_do); $q = $q->execute(); $report = array('A' => 0, 'N' => 0, 'ZP' => 0, 'cena' => 0, 'cena_ZP' => 0); foreach ($q AS $d) { if ($d->stav == 'A') ++$report['A']; if ($d->stav == 'N') ++$report['N']; if ($d->stav == 'ZP') { ++$report['N']; ++$report['ZP']; $report['cena_ZP'] += $d->cena; } if ($d->stav != 'ZV') // Zrušeno včas { $report['cena'] += $d->cena; } $report['cena_ZP'] = round($report['cena_ZP']); } $report['cena'] = round($report['cena']); return $report; } public function getDochazkaLastMountPerson() { $max = 0; $count = 0; $pracovnik_kurzy = Doctrine::getTable("Pracovnik_kurz")->createQuery("a")->where("a.pracovnik_id = " . $this->getId())->execute(); $yearFrom = date("Y"); $mountFrom = date("m") - 1; $yearTo = date("Y"); $mountTo = date("m"); if (date("m") == 1) { $yearTo = date("Y") - 1; $mountTo = "01"; } $dateFrom = $yearFrom . "-" . $mountFrom . "-01"; $dateTo = $yearTo . "-" . $mountTo . "-01"; foreach ($pracovnik_kurzy as $pracovnik_kurz) { $kurz_beh = Doctrine::getTable("Kurz_beh")->getBehFromKurz($pracovnik_kurz->getKurzId())->execute(); $kurz_hodiny = Doctrine::getTable("Kurz_hodina")->createQuery("a")->where("a.kurz_beh_id = " . $kurz_beh[0]->getId()) ->andWhere("a.datum >= '" . $dateFrom . "'") ->andWhere("a.datum < '" . $dateTo . "'")->execute(); foreach ($kurz_hodiny as $kurz_hodina) { $dochazka = Doctrine::getTable("Kurz_dochazka")->createQuery("a")->where("a.kurz_hodina_id = " . $kurz_hodina->getId())->execute(); $max++; if (stristr($dochazka[0]->getStav(), "A")) $count++; } } if ($max > 0 && $count > 0) { return number_format(($count / $max) * 100, 0) . "%"; } return "0 %"; } public function getDochazkaLastMount($id_kurz) { $id = $this->getId(); $beh = Doctrine::getTable('Kurz_beh')->getBehFromKurz($id_kurz)->execute(); $id_beh = $beh[0]->getId(); $sum = 0; $sumAll = 0; $sumaA = 0; $yearFrom = date("Y"); $mountFrom = date("m") - 1; $yearTo = date("Y"); $mountTo = date("m"); if (date("m") == 1) { $yearTo = date("Y") - 1; $mountTo = "01"; } $dateFrom = $yearFrom . "-" . $mountFrom . "-01"; $dateTo = $yearTo . "-" . $mountTo . "-01"; $beh = Doctrine::getTable('Kurz_beh')->find($id_beh); $hodiny = Doctrine::getTable("Kurz_hodina")->createQuery("a")->where("a.kurz_beh_id = " . $beh->getId()) ->andWhere("a.datum >= '" . $dateFrom . "'") ->andWhere("a.datum < '" . $dateTo . "'")->execute(); if (count($hodiny) > 0) { foreach ($hodiny as $hodina) { $sumAll++; $sumaA += count(Doctrine::getTable('Kurz_dochazka')->getHodinaByBeh($id, $hodina->getId())->where("kurz_hodina_id = " . $hodina->getId())->andWhere("stav = 'A'")->andWhere('pracovnik_id=' . $id)->execute()); } } if ($sumAll != 0 || $sumaA != 0) return (($sumaA / $sumAll) * 100) . " %"; return $sum . " %"; } public function getAbsPrize($count, $id_beh) { $beh = Doctrine::getTable('Kurz_beh')->createQuery('u')->where("u.id = " . $id_beh)->execute(); return $count > 0 ? ($beh[0]->getFjCena() / $count) : 0; } public function getDochazkaStyle($dochazka, $celkem) { if (sfContext::getInstance()->getUser()->checkRight(get_class($this), "getDochazkaPersonalistaDetail")) { $pomocnik = Doctrine::getTable('Pomocnici_personalisty')->createQuery('u')->where("u.zakaznik_id = " . $this->getZakaznikId())->execute(); $count = 0; if ($celkem > 0) $count = ($dochazka / $celkem) * 100; if ($count < $pomocnik[0]->getMinDochazka()) return "style='background-color:red;'"; } return ""; } public function getRozpocetStyle($cerpano, $celkem) { if (sfContext::getInstance()->getUser()->checkRight(get_class($this), "getRozpocet")) { $pomocnik = Doctrine::getTable('Pomocnici_personalisty')->createQuery('u')->where("u.zakaznik_id = " . $this->getZakaznikId())->execute(); $count = 0; if ($celkem > 0) $count = ($cerpano / $celkem) * 100; if ($count < $pomocnik[0]->getMinHranice()) return "style='background-color:red;'"; } return ""; } public function getDochazkaPracovnik() { $dochazkaA = Doctrine::getTable('Kurz_dochazka')->createQuery("u")->where("u.pracovnik_id = " . $this->getId())->andWhere("u.stav = 'A'")->execute(); $dochazkaMax = Doctrine::getTable('Kurz_dochazka')->createQuery("u")->where("u.pracovnik_id = " . $this->getId())->execute(); if (count($dochazkaMax) > 0 && count($dochazkaA) > 0) { return number_format(((count($dochazkaA) / count($dochazkaMax)) * 100), 0) . " %"; } return "0 %"; } public function getErrorPracovniciRozpocet($id_zakaznik) { $pomocnik = Doctrine::getTable('Pomocnici_personalisty')->createQuery('u')->where("u.zakaznik_id = " . $id_zakaznik)->execute(); $pracovnici = Doctrine::getTable('Pracovnik')->createQuery('u')->where("u.zakaznik_id = " . $id_zakaznik)->execute(); $error = array(); foreach ($pracovnici as $pracovnik) { $args = $this->getActiveCourses($pracovnik->getId()); foreach ($args as $arg) { $value = 0; $count = 0; $cerpano = $this->getRozpocet($arg->getId(), $pracovnik->getId(), 'getCerpano'); $rozpocet = $this->getRozpocet($arg->getId(), $pracovnik->getId(), 'getRozpocet'); $rozdil = $rozpocet - $cerpano; if (!empty($rozpocet) && $rozpocet > 0) { $beh = Doctrine::getTable('Kurz_beh')->getBehFromKurz($arg->getId())->execute(); $err = Doctrine::getTable('Pracovnik_rozpocet')->createQuery("u")->where("u.pracovnik_id = " . $pracovnik->getId())->andWhere("u.kurz_beh_id=" . $beh[0]->getId())->execute(); if ($rozdil > 0 && $rozdil != $rozpocet) { $count = (100 - (($cerpano / $rozpocet) * 100)); if ($count < $pomocnik[0]->getMinHranice()) $error[] = "u.id=" . $err[0]->getId(); } if ($rozdil <= 0) $error[] = "u.id=" . $err[0]->getId(); } } } $pracovnik_rozpocet = array(); if (!empty($error) && count($error) > 0) $pracovnik_rozpocet = Doctrine::getTable('Pracovnik_rozpocet')->createQuery("u")->where(implode(" OR ", $error))->execute(); return $pracovnik_rozpocet; } public function getErrorPracovniciDochazka($id_zakaznik) { $pomocnik = Doctrine::getTable('Pomocnici_personalisty')->createQuery('u')->where("u.zakaznik_id = " . $id_zakaznik)->execute(); $prumer = 0; $kurzy = Doctrine::getTable('Kurz')->createQuery("u")->where("u.zakaznik_id = " . $id_zakaznik)->execute(); $arg = array(); if (count($pomocnik) != 0) { foreach ($kurzy as $kurz) { $pracovnik_kurzy = Doctrine::getTable('Pracovnik_kurz')->createQuery("u")->where("u.kurz_id = " . $kurz->getId())->execute(); foreach ($pracovnik_kurzy as $pracovnik_kurz) { $max = count(Doctrine::getTable('Kurz_dochazka')->getDochazkaFromPracovnik($pracovnik_kurz->getPracovnikId())->execute()); $count = count(Doctrine::getTable('Kurz_dochazka')->getDochazkaFromPracovnikA($pracovnik_kurz->getPracovnikId())->execute()); if ($count > 0 && $max > 0) $prumer = ($count / $max) * 100; if ($prumer < $pomocnik[0]->getMinDochazka() && $prumer != 0) { $arg[] = array("pracovnik" => $pracovnik_kurz->Pracovnik->getPrijmeni() . " " . $pracovnik_kurz->Pracovnik->getJmeno(), "kurz" => $kurz->getNazev(), "prumer" => $prumer); } } } } return $arg; } public function getError($type, $id) { $args = $this->$type($id); if (count($args) > 0) return $args; return ""; } public function getName() { return $this->getJmeno() . ' ' . $this->getPrijmeni(); } public function fullDelete() { Doctrine::getTable('Pracovnik_rozpocet')->setOption('ignore_archive', true); foreach ($this->getRozpocet_list() as $rozpocet) { $rozpocet->delete(); } Doctrine::getTable('Pracovnik_kurz')->setOption('ignore_archive', true); foreach ($this->getPracovnik_kurz_list() as $pk) { $pk->delete(); } foreach ($this->getPracovnik_kurz_hodnoceni_list() as $pkh) { $pkh->delete(); } Doctrine::getTable('Kurz_dochazka')->setOption('ignore_archive', true); foreach ($this->getDochazka_list() as $d) { $d->delete(); } foreach ($this->getDotaznik_pracovnik_list() as $dp) { $dp->delete(); } foreach ($this->getUchazec_list() as $u) { $u->delete(); } foreach ($this->getDotaznik_pracovnik_odpoved_list() as $o) { $o->delete(); } $this->delete(); } public function hasPermission(Zakaznik $zakaznik) { return $this->getZakaznikId() == $zakaznik->getId(); } public function getAppendDirChoices($is_agentura = false) { $choices = array('' => ''); foreach ($this->getRootDocuments($is_agentura) as $document) { if ($document->isDir()) { $choices[$document->getId()] = $document->getName(); $choices = $choices + $document->getDirChoices('-', $is_agentura); } } return $choices; } public function getRootDocuments($is_agentura = false) { $query = Doctrine::getTable('Document')->createQuery() ->addWhere('zakaznik_id = ?', $this->getZakaznikId()) ->addWhere('((pracovnik_id = ? AND parent_id IS NULL) OR (pracovnik_id IS NOT NULL AND is_global = ?)) AND !(kurz_id = ? AND parent_id IS NOT NULL AND is_global = ?)', array($this->getId(), true, $this->getId(), true)) ->orderBy('is_global DESC'); if ($is_agentura) { $query->addWhere('agentura_read = ?', true); } return $query->execute(); } public function navstevujeKurz(Kurz $kurz) { return Doctrine::getTable('Pracovnik_kurz')->createQuery('pk') ->where('pk.kurz_id = ? AND pk.pracovnik_id = ?', array($kurz->getId(), $this->getId())) ->count() > 0; } public function datumPrvniDochazky(Kurz $kurz) { $dochazka = Doctrine::getTable('Kurz_dochazka')->createQuery('kd') ->select('kh.datum as datum') ->innerJoin('kd.Kurz_hodina kh') ->innerJoin('kh.Kurz_beh kb') ->addWhere('kb.kurz_id = ?', $kurz->getId()) ->addWhere('kd.pracovnik_id = ?', $this->getId()) ->orderBy('kh.datum ASC') ->limit(1) ->execute(array(), Doctrine::HYDRATE_ARRAY); return isset($dochazka[0]['datum']) ? $dochazka[0]['datum'] : false; } public function datumPosledniDochazky(Kurz $kurz) { $dochazka = Doctrine::getTable('Kurz_dochazka')->createQuery('kd') ->select('kh.datum as datum') ->innerJoin('kd.Kurz_hodina kh') ->innerJoin('kh.Kurz_beh kb') ->addWhere('kb.kurz_id = ?', $kurz->getId()) ->addWhere('kd.pracovnik_id = ?', $this->getId()) ->orderBy('kh.datum DESC') ->limit(1) ->execute(array(), Doctrine::HYDRATE_ARRAY); return isset($dochazka[0]['datum']) ? $dochazka[0]['datum'] : false; } public function getPlanIds() { $ids = Doctrine::getTable('PlanPracovnik')->createQuery('pr') ->select('pr.plan_id') ->addWhere('pr.pracovnik_id = ?', $this->getId()) ->fetchArray(); $result = array(); foreach ($ids as $id) { $result[] = $id['plan_id']; } return $result; } /** * * @param Plan $plan * @return boolean */ public function hasPlannedPlan(Plan $plan) { return ($plan->getPrafovnikRelation($this) instanceof PlanPracovnik); } public function getVidiKurzyIds() { $result = array(); foreach ($this->getVidiKurzy() as $kurz) { $result[] = $kurz->getId(); } return $result; } public function zrusitViditelnostKurzu(Kurz $kurz) { Doctrine::getTable('PracovnikVidiKurz')->createQuery() ->addWhere('pracovnik_id = ?', $this->getId()) ->addWhere('kurz_id = ?', $kurz->getId()) ->execute() ->delete(); } public function vidiKurzId($kurz_id) { return Doctrine::getTable('PracovnikVidiKurz')->createQuery() ->addWhere('pracovnik_id = ?', $this->getId()) ->addWhere('kurz_id = ?', $kurz_id) ->count() > 0; } public function getKurzyDlePrava() { // kurzy, ke kterým má pracant právo na základě střediska $kurzy = Doctrine::getTable('Kurz')->createQuery('k') ->WhereIn('k.nakladove_stredisko', $this->getVidiStrediskaArray()) ->andWhere('k.zakaznik_id=?', $this->getZakaznikId()) ->execute(); // kurzy, ke kterým má právo výčtem $kurzy->merge($this->getVidiKurzy()); // kurzy, které pracant navštěvuje foreach ($this->getPracovnik_kurz_list() as $pk) { $kurzy->add($pk->Kurz); } return $kurzy; } public function getRozvrhyProKurzyDlePrava() { $ids = $this->getVidiKurzyIds(); foreach ($this->getPracovnik_kurz_list() as $pk) { $ids[] = $pk->getKurzId(); } $krs = Doctrine::getTable('Kurz_rozvrh')->createQuery('kr') ->innerJoin('kr.Kurz as k') ->innerJoin('k.Kurz_beh_list as b') ->andWhereIn('kr.kurz_id', $ids) ->orWhereIn('k.nakladove_stredisko', $this->getVidiStrediskaArray()) ->addWhere('k.zakaznik_id = ?', $this->getZakaznikId()) ->addWhere('b.beh_od <= NOW()') ->addWhere('b.beh_do >= NOW()') ->orderBy('kr.den_v_tydnu') ->addOrderBy('kr.od') ->execute(); return $krs; } public function getDochazkaByHodina(Kurz_hodina $hodina) { return Doctrine::getTable('Kurz_dochazka')->createQuery() ->addWhere('pracovnik_id = ?', $this->getId()) ->addWhere('kurz_hodina_id = ?', $hodina->getId()) ->fetchOne(); } public function getVidiStrediskaArray() { $result = array(); foreach(explode(',', $this->getVidiStrediska()) as $s) { $result[] = trim($s); } return $result; } }