public function validateAddArticleForm(Form $form) { $values = (object) $form->getHttpData(); if ($values->publishedAt == "later") { $later = DateTimeUtils::createDbDatetimeFormatFromDateParts($values->year, $values->month, $values->day, $values->hour, $values->minute, "0"); $valid = DateTimeUtils::createDateTime(DateTimeUtils::DB_DATETIME_FORMAT, $later); if (!$valid) { $form->addError("Zadej prosím platné datum"); } } if ($values->photoId == 0) { $form->addError("Vyber prosím fotografii ke článku."); } if (!isset($values->tagList)) { $tagList = null; $form->addError("Zadej prosím alespoň jeden tag ke článku."); } else { $tagList = new TagCollection(); foreach ($values->tagList as $tag) { $tagList->addItem(TagService::create($tag)); } } $articleId = $form->getPresenter()->getParameter("articleId"); if (count($form->getErrors()) > 0) { if ($articleId) { $form->getPresenter()->actionEdit(null, $tagList, $values->photoId); } else { $form->getPresenter()->actionAdd($tagList, $values->photoId); } } }
public function setPublishedAt($publishedAt) { if ($publishedAt == "now") { $this->publishedAt = DateTimeUtils::getNow(); } else { $this->setDatetime("publishedAt", $publishedAt); } }
protected function setDatetime($property, $value, $format = DateTimeUtils::DB_DATETIME_FORMAT) { $datetime = DateTimeUtils::createDateTime($format, $value); if (!$datetime) { throw new InvalidDateTimeException(); } $this->{$property} = $datetime; }
public function setLastModifiedAt($lastModifiedAt) { if ($lastModifiedAt == "null") { $this->lastModifiedAt = null; } elseif ($lastModifiedAt == "now") { $this->lastModifiedAt = DateTimeUtils::getNow(); } else { $this->setDatetime("lastModifiedAt", $lastModifiedAt); } }
private function formValuesToEntity(Form $form, $values) { $user = UserService::loadFromSession($form->getPresenter()->getUser()); $values->releaseDate = DateTimeUtils::createDbDatetimeFormatFromDateParts($values->year, $values->month, $values->day, "0", "0", "0"); if ($values->reservationId == 0) { return ReservationService::create($values, $user); } else { return ReservationService::loadForUpdate($values); } }
public function create() { $form = new Form(); $form->setRenderer(new BootstrapInlineRenderer()); $form->addSelect("month")->setItems(DateTimeUtils::getMonths())->setDefaultValue(date("n")); $form->addSelect("year")->setItems(DateTimeUtils::getYears())->setDefaultValue(date("Y")); $form->addSubmit("send", "Vygenerovat")->setAttribute("class", "btn btn-default"); $form->onSuccess[] = $this->generateStatsFormSucceeded; return $form; }
private function storePhotos($values) { $now = DateTimeUtils::getNow(); $filepath = Strings::webalize(Passwords::hash($now->format(DateTimeUtils::DB_DATETIME_FORMAT))) . $values->filepath->name; $photo = Image::fromFile($values->filepath); $photo->resize(748, 490, Image::STRETCH); $photo->save("img/articles/" . $filepath); $photo->resize(359, 235, Image::STRETCH); $photo->save("img/articles/midiatures/" . $filepath); $photo->resize(130, 130, Image::STRETCH); $photo->save("img/articles/miniatures/" . $filepath); return $filepath; }
public function create($defaultMonth, $defaultYear, $userId) { $form = new Form(); $form->setRenderer(new BootstrapInlineRenderer()); $form->addSelect("month")->setItems(DateTimeUtils::getMonths())->setDefaultValue($defaultMonth); $form->addSelect("year")->setItems(DateTimeUtils::getYears())->setDefaultValue($defaultYear); if ($this->user->isAllowed("UserFilter")) { $form->addSelect("user")->setItems($this->users)->setDefaultValue($userId); } $form->addSubmit("send", "Filtrovat")->setAttribute("class", "btn btn-default"); $form->onSuccess[] = $this->monthFilterFormSucceeded; return $form; }
public function sendStatsFormSucceeded(Form $form, $values) { $month = $form->getPresenter()->month; $year = $form->getPresenter()->year; try { $stats = $this->statisticFacade->findAll($month, $year); } catch (EntitiesNotFoundException $ex) { \Tracy\Debugger::log($ex); $stats = null; } $monthInWords = DateTimeUtils::getMonthByIndex($month); $this->mailSender->send("*****@*****.**", $values->email, "Statistiky za {$monthInWords} {$year}", $this->createSendStatisticTemplate($form, $stats, $monthInWords, $year)); $form->getPresenter()->flashMessage("Statistiky za {$monthInWords} {$year} byly úspěšně odeslány.", "alert-success"); $form->getPresenter()->redirect("this"); }
public static function loadForUpdate($articleId, $editedArticle, $user, $photo, $tags, $categories) { $instance = new Article(); $instance->setId($articleId); $instance->setTitle($editedArticle->title); $instance->setContent($editedArticle->content); if ($editedArticle->publishedAt == "later") { $publishedAt = DateTimeUtils::createDbDatetimeFormatFromDateParts($editedArticle->year, $editedArticle->month, $editedArticle->day, $editedArticle->hour, $editedArticle->minute, "0"); $instance->setPublishedAt($publishedAt); } $instance->setLastModifiedAt("now"); $instance->setUser($user); $instance->setPhoto($photo); $instance->setTags($tags); $instance->setCategories($categories); return $instance; }
public function actionDefault() { if ($this->firstLoad) { $this->template->stats = null; $this->template->firstLoad = true; } else { try { $this->template->stats = $this->statisticFacade->findAll($this->month, $this->year); } catch (EntitiesNotFoundException $ex) { \Tracy\Debugger::log($ex); $this->template->stats = null; } finally { $this["generateStatsForm"]->setDefaults(array("month" => $this->month, "year" => $this->year)); $this->template->firstLoad = false; $this->template->month = DateTimeUtils::getMonthByIndex($this->month); $this->template->year = $this->year; } } }
public function renderDefault() { try { $this->template->articles = $this->articleFacade->findByArticlesFilter($this->month, $this->year, $this->userId); } catch (EntityNotFoundException $ex) { \Tracy\Debugger::log($ex); $this->template->articles = false; } finally { $this->template->month = DateTimeUtils::getMonthByIndex($this->month); $this->template->year = $this->year; if ($this->userId > 0) { $this->template->filterUser = $this->userFacade->findOneById($this->userId); } else { $this->template->filterUser = false; } } }
public function setValidity($validity) { if ($validity == "now") { $this->validity = DateTimeUtils::getNow()->modify("+12 hour"); } else { $this->setDatetime("validity", $validity); } }
public function findOneByValidToken($email, $token) { return $this->db->table(self::TABLE_NAME)->where(self::COLUMN_EMAIL, $email)->where(self::COLUMN_TOKEN, $token)->where(self::COLUMN_VALIDITY . " >= ?", \Utils\DateTimeUtils::getNow())->fetch(); }
public function getByTagCount($tagId) { return $this->db->table(self::TABLE_NAME)->where(self::COLUMN_VISIBLE, true)->where(self::COLUMN_DELETED, false)->where(self::COLUMN_PUBLISHED_AT . " <= ?", DateTimeUtils::getNow())->where(self::COLUMN_ID, $this->db->table("article_tag")->select("DISTINCT article_id")->where("tag_id", $tagId))->count("*"); }