/** * @param array $types * @param \App\Model\Entities\Vote $vote * @return Form */ public function create($types, $vote = NULL) { $form = $this->baseFormFactory->create(); $form->addText('question', 'system.voteQuestion')->setRequired($form->getTranslator()->translate('system.requiredItem', ['label' => '%label'])); $form->addSelect('type', 'system.voteType')->setItems($types)->setPrompt('Zvolte typ dotazu')->setRequired($form->getTranslator()->translate('system.requiredItem', ['label' => '%label'])); $form->addText('expiration', 'system.voteExpiration')->setType('datetime-local')->setAttribute('placeholder', 'd. m. Y, H:i (den. měsíc. rok, hodina:minuta'); $options = $form->addDynamic('options', function (Container $option) { $option->addText('option', 'system.voteOption'); $option->addSubmit('remove', 'system.delete')->addRemoveOnClick(); }, 1); $options->addSubmit('add', 'system.new')->setValidationScope(FALSE)->addCreateOnClick(); $form->addSubmit('send', 'system.save'); $form->addHidden('id'); if ($vote) { $defaults = $this->getDefaults($vote); $form->setDefaults($defaults); $options->setValues($defaults['options']); } else { $today = new DateTime(); $today->modify('+6 month'); $default = ['expiration' => $today->format(self::$dateMask)]; $form->setDefaults($default); } $form->onValidate[] = [$this, 'validateForm']; $form->onSuccess[] = [$this, 'formSucceeded']; return $form; }
/** * * @return string|boolean */ public function getOpeningAtWarning() { $timeModified = new DateTime($this->time); $timeModified->modify($this->warningOpeningDiff); $status = $this->getStatus(); if ($status instanceof StatusModel\Closed && $this->isOpenedByTime($timeModified)) { return $this->openingAtByWeekDay($timeModified->format('w')); } return FALSE; }
public function createComponentExampleOneForm() { $form = new Form(); $form->addText('name', "Name:"); $form->addPassword('password', "Password:"******"Textarea"); $form->addSelect('select', "Select", ['Option 1', 'Option 2']); $form->addUpload('upload', 'Upload'); $form->addCheckbox('checkbox', 'Checkbox'); $form->addRadioList('radioList', 'Radio list', ['Item A', 'Item B']); $form->addCheckboxList('checkboxList', 'Checkbox list,', ['Item A', 'Item B']); $form->addText('date', 'Date:')->getControlPrototype()->class('b-date-input'); $form->addText('datetime', 'Date time:')->getControlPrototype()->class('b-date-input b-date-input--datetime'); $now = new DateTime(); $now->modify('+1 day'); $now->modify('+3 hour'); $form->setDefaults(['date' => $now, 'datetime' => $now]); $form->addSubmit('actionSend', 'Save'); $form->onSuccess[] = array($this, 'exampleOneFormSubmitted'); return $form; }
/** * @param string|null $key * @param DateTime|null $date * @param boolean|null $active */ public function __construct($key = NULL, DateTime $date = NULL, $active = NULL) { if (NULL === $key) { $this->key = Random::generate(self::KEY_LENGHT); } else { $this->key = $key; } if (NULL === $date) { $date = new DateTime(); $date->modify('+5 minutes'); $this->expiration = $date; } else { $this->expiration = $date; } if (NULL === $active) { $this->active = TRUE; } else { $this->active = $active; } }
/** * Auto removes email file when expired. * @param string * @return bool */ private function removeExpired($path) { if ($this->autoremove) { $now = new DateTime(); $file_date = new DateTime('@' . filemtime($path)); $file_date->setTimezone($now->getTimezone()); $remove_date = $now->modify($this->autoremove); if ($file_date < $remove_date) { unlink($path); return TRUE; } } return FALSE; }
/** * Vraci nahodne clanky * @param int $count * @param DateTime|NULL $period * @return Entities\Article[] */ public function getRandArticles($count = 1, $period = NULL) { if ($period === NULL) { $now = new DateTime(); $period = $now->modify("-6 month"); } $cacheId = 'rand-' . $count; $countAllArticles = (int) $this->countAllArticles(); $query = "SELECT a FROM \\App\\Model\\Entities\\Article a WHERE a.published = true " . "AND a.publishDate >= :date "; $randArticles = $this->em->createQuery($query)->setParameter('date', $period)->setMaxResults($count)->setFirstResult(mt_rand(0, $countAllArticles - 1))->useResultCache(TRUE, 600, $cacheId)->getResult(); return $randArticles; }