public function kontrolaDatumu(NastavitDatumCasForm $form) { $values = $form->getValues(); $datum = $values[$this->prefix . 'datum']; if (preg_match('~([0-9]{1,2}).([0-9]{1,2}).([0-9]{4})~', $datum, $matches)) { $rok = $matches[3]; $den = str_pad($matches[1], 2, '0', STR_PAD_LEFT); $mesic = str_pad($matches[2], 2, '0', STR_PAD_LEFT); } elseif (preg_match('~(.*)-(.*)-(.*)~', $datum, $matches)) { $rok = $matches[1]; $mesic = $matches[2]; $den = $matches[3]; } else { $form->addError('Chybný tvar datumu. Zadávejte datum ve tvaru 1.1.2000'); return FALSE; } if (!checkdate($mesic, $den, $rok)) { $form->addError('Neplatné datum'); return FALSE; } else { return TRUE; } }
public function nastavitDatumDoFormSubmitted(NastavitDatumCasForm $form) { $values = $form->getValues(); $clanek = new Clanek($this->id_clanku); if ($this->redakce->findClanekById($this->id_clanku)->top == 'A' && strtotime(PrevodnikDatumu::prevestDatumNaAnglicke($values->zobrazit_do_datum) . ' ' . $values->zobrazit_do_cas) < time()) { $form->addError('Článek je top. Datum nelze nastavit.'); } else { $clanek->setUdaje($values); $this->redakce->ulozitClanek($clanek); $this->logg('clanku ' . $this->id_clanku . ' nastaven konec zobrazeni: ' . $values->zobrazit_do_datum . ' ' . $values->zobrazit_do_cas); $this->flashMessage('Změny byly uloženy.'); $this->restoreRequest($this->backlink); $this->redirect('default'); } }