public function indexAction() { $request = $this->getRequest(); $logContent = ''; // initialize when no submit anymore $data = []; $data['logmessage'] = $this->form->get('logmessage')->getValue(); if ($request->isPost()) { $this->form->setData($request->getPost()); if ($this->form->isValid()) { $data = $this->form->getData(); $this->loggerPriority = $data['logpriority']; if ($data['logformat'] !== 'simple') { $this->loggerConfig['writers'][0]['options']['formatter']['name'] = $data['logformat']; unset($this->loggerConfig['writers'][0]['options']['formatter']['options']); } } } $logger = new Logger($this->loggerConfig); // save log data to buffer and make it variable ob_start(); $logger->log((int) $this->loggerPriority, $data['logmessage']); $logContent = ob_get_clean(); return new ViewModel(['form' => $this->form, 'logContent' => $logContent]); }
public function createAction() { $this->contactForm->get('avatar')->setValue('building'); if ($this->getRequest()->isPost()) { $this->contactForm->setData($this->getRequest()->getPost()); if ($this->contactForm->isValid()) { $person = $this->contactService->createCompany($this->contactForm->getData()); return $this->redirect()->toRoute('contacts/view', ['type' => ContactEntry::TYPE_COMPANY, 'id' => $person->getId()->toString()]); } } return new ViewModel(['contactForm' => $this->contactForm]); }
/** * Renders the error messages. * @param \Zend\Form\FormInterface $oForm * @return string */ public function render(\Zend\Form\FormInterface $oForm, $sMessage, $bDismissable = false) { $errorHtml = sprintf($this->messageOpenFormat, $sMessage); $sMessagesArray = array(); foreach ($oForm->getMessages() as $fieldName => $sMessages) { foreach ($sMessages as $sMessage) { if ($oForm->get($fieldName)->getAttribute('id')) { $sMessagesArray[] = sprintf('<a href="#%s">%s</a>', $oForm->get($fieldName)->getAttribute('id'), $oForm->get($fieldName)->getLabel() . ': ' . $sMessage); } else { $sMessagesArray[] = $oForm->get($fieldName)->getLabel() . ': ' . $sMessage; } } } return $this->dangerAlert($errorHtml . implode($this->messageSeparatorString, $sMessagesArray) . $this->messageCloseString, $bDismissable); }
public function resetPasswordAction() { $code = $this->params('code'); if ($code) { $this->resetPasswordForm->get('code')->setValue($code); } if ($this->getRequest()->isPost()) { $this->resetPasswordForm->setData($this->getRequest()->getPost()); if ($this->resetPasswordForm->isValid()) { $data = $this->resetPasswordForm->getData(); $this->passwordChanger->resetAccountPassword($data['code'], $data['credential']); return $this->redirect()->toRoute('login'); } } return new ViewModel(['resetPasswordForm' => $this->resetPasswordForm, 'code' => $code]); }
public function changesAction() { $siteId = $this->services->getUtilityService()->getSiteId(); $site = $this->services->getSiteService()->find($siteId); $fromControl = $this->dateIntervalForm->get(DateIntervalForm::FROM_DATE_NAME); $toControl = $this->dateIntervalForm->get(DateIntervalForm::TO_DATE_NAME); $lastDate = $site->getLastUpdate(); $lastDate->setTime(23, 59, 59); $fromControl->setAttribute('max', $lastDate->format('Y-m-d')); $toControl->setAttribute('max', $lastDate->format('Y-m-d')); $from = clone $lastDate; $from->sub(new \DateInterval('P1M')); $to = $lastDate; $fromControl->setValue($from->format('Y-m-d')); $toControl->setValue($to->format('Y-m-d')); $request = $this->getRequest(); if ($request->isPost()) { $this->dateIntervalForm->setData($request->getPost()); if ($this->dateIntervalForm->isValid()) { $from = \DateTime::createFromFormat('Y-m-d', $fromControl->getValue()); $to = \DateTime::createFromFormat('Y-m-d', $toControl->getValue()); } } $from->setTime(0, 0, 0); $to->setTime(23, 59, 59); $result = array('intervalForm' => $this->dateIntervalForm, 'site' => $site, 'members' => $this->getMembersData($siteId, $from, $to), 'pages' => $this->getPagesData($siteId, $from, $to), 'revisions' => $this->getRevisionsData($siteId, $from, $to), 'votes' => $this->getVotesData($siteId, $from, $to)); return new ViewModel($result); }
/** * @param string $content * @param array $attribs * @param ElementInterface $element * @param FormInterface $form * @return string */ public function render($content, array $attribs = [], ElementInterface $element = null, FormInterface $form = null) { if ($form && $form->hasAttribute('class')) { $class = $form->getAttribute('class'); if (strpos($class, 'form-inline') !== false) { return $content; } if (strpos($class, 'form-horizontal') !== false && empty($attribs['class']) && $form->has('submit') && $form->has('reset')) { if ($form->get('submit') === $element) { $attribs['class'] = 'col-xs-12 col-sm-8'; } elseif ($form->get('reset') === $element) { $attribs['class'] = 'col-xs-12 col-sm-4'; } } } return parent::render($content, $attribs); }
public function renderAdditional(FormInterface $form, $type) { $result = ''; foreach ($this->contactTypes[$type] as $fieldName => $fieldOptions) { $result .= $this->renderElement($form->get($fieldName), $fieldOptions, true); } return $result; }
public function editAction() { $project = $this->projectRepository->find($this->params('projectId')); if ($project === null) { $this->getResponse()->setStatusCode(404); return; } $this->projectForm->get('client')->setValue($project->getClient()->getName()); $this->projectForm->bind($project); if ($this->getRequest()->isPost()) { $this->projectForm->setData($this->getRequest()->getPost()); if ($this->projectForm->isValid()) { $this->projectService->persist($this->projectForm->getData()); $this->redirect()->toRoute('clients/show', ['clientId' => $project->getClient()->getId()], ['fragment' => 'project-table']); } } return new ViewModel(['form' => $this->projectForm]); }
/** * @param $name * @return Element */ public function row($name) { if (isset($this->cache[$name])) { return $this->cache[$name]; } $elem = $this->form->get($name); if ($elem instanceof ZendElement) { $return = new Element($elem, $this->renderer); $this->cache[$name] = $return; return $return; } throw new \DomainException('Invalid form element object.'); }