public function executeNew(HTTPRequest $request) { $categories = $this->_categoriesManager->getListOf(); $departments = $this->_departmentsManager->getListOf(); $addresses = $this->_addressManager->getListOf($this->_user->id()); $profile = $this->_profileManager->getByUserId($this->_user->id()); $announce = new Announcement(); $announce->setStateId(AnnouncementStates::STATE_DRAFT); if ($request->postExists('title')) { $this->parseAnnounceForm($request, $announce); if ($this->isAnnounceValid($announce)) { $announce->setStateId(AnnouncementStates::STATE_DRAFT); $this->_announcementsManager->save($announce); $this->app->httpResponse()->redirect('/announcements/edit/photo/' . $announce->id()); exit; } else { $this->app->user()->setFlash('draft-incomplete'); $this->displayInfoMessage(); } } $this->page->smarty()->assign('announce', $announce); $this->page->smarty()->assign('categories', $categories); $this->page->smarty()->assign('addresses', $addresses); $this->page->smarty()->assign('profile', $profile); }
private function updateAnnouncementState(Announcement $announce) { $endPublicationDate = $announce->getEndPublicationDate(); $now = new DateTime(); $endDate = new DateTime($endPublicationDate); if ($endDate->getTimestamp() < $now->getTimestamp() && $announce->getStateId() == AnnouncementStates::STATE_VALIDATED) { $announce->setStateId(AnnouncementStates::STATE_ARCHIVED); } }