public function indexAction() { parent::indexAction(); $viewmodel = new ViewModel(); $return = array(); if ($this->flashMessenger()->hasErrorMessages()) { $return['error'] = $this->flashMessenger()->getErrorMessages(); } if ($this->flashMessenger()->hasSuccessMessages()) { $return['success'] = $this->flashMessenger()->getSuccessMessages(); } $this->flashMessenger()->clearMessages(); $objectManager = $this->getServiceLocator()->get('Doctrine\\ORM\\EntityManager'); $tabid = $this->params()->fromQuery('tabid', null); if ($tabid) { $tab = $objectManager->getRepository('Application\\Entity\\Tab')->find($tabid); if ($tab) { $categories = $tab->getCategories(); $cats = array(); foreach ($categories as $cat) { $cats[] = $cat->getId(); } $viewmodel->setVariable('onlyroot', $tab->isOnlyroot()); $viewmodel->setVariable('cats', $cats); $viewmodel->setVariable('tabid', $tabid); } else { $return['error'][] = "Impossible de trouver l'onglet correspondant. Contactez votre administrateur."; } } else { $return['error'][] = "Aucun onglet défini. Contactez votre administrateur."; } $viewmodel->setVariables(array('messages' => $return)); return $viewmodel; }
/** * Prepare view renderer * * @param array $variables * @param \Contentinum\Options\PageOptions $pageOptions * @return \Zend\View\Model\ViewModel */ public function buildView($variables, $pageOptions) { $view = new ViewModel($variables); $msg = false; $msgType = false; if (true === $this->flashMessenger()->setNamespace('mcwork')->hasCurrentErrorMessages()) { $msg = $this->flashMessenger()->setNamespace('mcwork')->getErrorMessages(); $msgType = 'error'; } elseif (true === $this->flashMessenger()->setNamespace('mcwork')->hasCurrentSuccessMessages()) { $msg = $this->flashMessenger()->setNamespace('mcwork')->getSuccessMessages(); $msgType = 'success'; } elseif (true === $this->flashMessenger()->setNamespace('mcwork')->hasCurrentWarningMessages()) { $msg = $this->flashMessenger()->setNamespace('mcwork')->getWarningMessages(); $msgType = 'warning'; } $view->setVariable('messages', $msg); $view->setVariable('msgtype', $msgType); if (1 === $pageOptions->getToolbar()) { $view->setVariable('toolbarcontent', $this->getServiceLocator()->get('mcwork_toolbar')); } if (1 === $pageOptions->getTableedit()) { $view->setVariable('tableeditcontent', $this->getServiceLocator()->get('mcwork_tableedit')); } if (null !== $pageOptions->getTemplate()) { $view->setTemplate($pageOptions->getTemplate()); } return $view; }
/** * @return array|ViewModel */ public function indexAction() { $this->view->setTerminal(true); $this->view->setVariable('languages', $this->serviceLocator->get('config')['languages']); $this->view->setVariable('location', $this->location->getLocationCode()); return $this->view; }
public function editAction() { $action = $this->params('action'); $form = new CustomVocabForm($this->getServiceLocator()); $response = $this->api()->read('custom_vocabs', $this->params('id')); $vocab = $response->getContent(); $form->setData($vocab->jsonSerialize()); if ($this->getRequest()->isPost()) { $form->setData($this->params()->fromPost()); if ($form->isValid()) { $formData = $form->getData(); $response = $this->api()->update('custom_vocabs', $vocab->id(), $formData); if ($response->isError()) { $form->setMessages($response->getErrors()); } else { $this->messenger()->addSuccess('Custom vocab updated.'); return $this->redirect()->toRoute('admin/custom-vocab'); } } else { $this->messenger()->addError('There was an error during validation'); } } $view = new ViewModel(); $view->setVariable('form', $form); $view->setVariable('vocab', $vocab); return $view; }
/** * Outputs message depending on flag * * @return string */ public function render() { // get messages $allMessages = ['danger' => array_unique(array_merge($this->flashMessenger->getErrorMessages(), $this->flashMessenger->getCurrentErrorMessages())), 'success' => array_unique(array_merge($this->flashMessenger->getSuccessMessages(), $this->flashMessenger->getCurrentSuccessMessages())), 'warning' => array_unique(array_merge($this->flashMessenger->getWarningMessages(), $this->flashMessenger->getCurrentWarningMessages())), 'info' => array_unique(array_merge($this->flashMessenger->getInfoMessages(), $this->flashMessenger->getCurrentInfoMessages())), 'default' => array_unique(array_merge($this->flashMessenger->getMessages(), $this->flashMessenger->getCurrentMessages()))]; // clear messages $this->flashMessenger->clearMessagesFromContainer(); $this->flashMessenger->clearCurrentMessagesFromContainer(); // initialize output $output = ''; // loop through messages foreach ($allMessages as $groupKey => $groupMessages) { foreach ($groupMessages as $message) { $addClass = $groupKey == 'default' ? '' : 'alert-' . $groupKey; // setup view model $viewModel = new ViewModel(); $viewModel->setVariable('alertClass', $addClass); $viewModel->setVariable('alertMessage', $message); $viewModel->setTemplate('zf2rapid-library/widget/bootstrap-alert'); // add rendered output $output .= $this->getView()->render($viewModel); } } // return output return $output . "\n"; }
/** * @param MvcEvent $e * @return mixed|void */ public function onDispatch(MvcEvent $e) { $viewModel = new ViewModel(); $valid = $this->collageData->isValid(); $data = $this->authenticationService->getAuthData(); $viewModel->setVariable('validInputs', $this->collageData->getValidInput()); $viewModel->setVariable('user', $data->user); if (!$valid) { $viewModel->setTemplate('frontend/gallery/error'); $viewModel->setVariable('messages', $this->collageData->getMessages()); return $e->setResult($viewModel); } $uniqueId = md5(serialize($this->collageData->getValues())); if ($this->sessionContainer->valuesHash != $uniqueId) { $collectionService = $this->collectionFactory->createCollection($this->collageData); $images = $collectionService->getImages($this->collageData); } else { $images = $this->sessionContainer->images; } $collageHttpPath = $this->collageService->create($images, $uniqueId, $this->collageData->getWidth(), $this->collageData->getHeight(), $this->collageData->getLimit()); if ($collageHttpPath !== false) { $viewModel->setVariable('collageHttpPath', $collageHttpPath); } $viewModel->setTemplate('frontend/gallery/index'); return $e->setResult($viewModel); }
/** * @return array|ViewModel */ public function indexAction() { $this->view->setVariable('menu', $this->navigation->getMenuItems()); $this->view->setVariable('main', $this->navigation->getMainItems()); $this->view->setTerminal(true); return $this->view; }
public function editProductAction() { if (!$this->getAuthenticationService()->hasIdentity()) { $this->redirect()->toRoute('admin_login'); } $request = $this->getRequest(); $viewModel = new ViewModel(); $product = null; $productId = $this->params()->fromRoute('id'); $form = $this->getAdminCatalogService()->getCatalogProductForm(); if (null != $productId) { $product = $this->getObjectManager()->find('Catalog\\Entity\\Product', $productId); } $fprg = $this->fileprg($form, $this->url()->fromRoute('admin_product_edit', ['id' => $productId]), true); if ($fprg instanceof \Zend\Http\PhpEnvironment\Response) { return $fprg; } elseif ($fprg === false) { $form->bind($product); $viewModel->setVariable('form', $form); return $viewModel; } if ($form->isValid()) { $product = $form->getObject(); $this->getAdminCatalogService()->saveProduct($product); $viewModel->setVariable('success', true); } else { $viewModel->setVariable('success', false); } $viewModel->setVariable('form', $form); return $viewModel; }
public function resetAction() { $viewModel = new ViewModel(); $this->getUserService(); $email = $this->params()->fromPost("email", false); if ($email) { $viewModel->setTemplate("chatter/account/reset"); $this->userService->sendPasswordEmail($email); $viewModel->setVariable($submitted, true); } else { $uuid = $this->params()->fromPost("uuid", false); $password = $this->params()->fromPost("password", false); if ($uuid && $password) { $viewModel->setTemplate("chatter/account/savedpass"); $this->userService->resetPassword($uuid, $password); } else { $uuid = $this->params()->fromQuery("uuid", false); if ($uuid) { $viewModel->setVariable("uuid", $uuid); $viewModel->setTemplate("chatter/account/newpass"); } else { $viewModel->setTemplate("chatter/account/reset"); } } } return $viewModel; }
public function editAction() { $this->setAccess('frontend/squads/create'); $squadID = (int) $this->params('id', null); $squadRepo = $this->getEntityManager()->getRepository('Frontend\\Squads\\Entity\\Squad'); $squadEntity = $squadRepo->findOneBy(array('user' => $this->identity(), 'id' => $squadID)); if (!$squadEntity) { $this->flashMessenger()->addErrorMessage('Squad not found'); return $this->redirect()->toRoute('frontend/user/squads'); } $form = new Member(); $form->setEntityManager($this->getEntityManager()); $form->init($squadEntity); if ($this->getRequest()->isPost()) { // zf bug workaround - deleting all members $postedData = (array) $this->getRequest()->getPost(); if (!isset($postedData['members'])) { $postedData['members'] = array(); } $form->setData($postedData); if ($form->isValid()) { $this->getEntityManager()->flush(); $this->flashMessenger()->addSuccessMessage('Members successfully edited!'); return $this->redirect()->refresh(); } else { $form->populateValues($this->getRequest()->getPost()); } } $viewModel = new ViewModel(); $viewModel->setTemplate('/squads/member/edit.phtml'); $viewModel->setVariable('form', $form); $viewModel->setVariable('squad', $squadEntity); return $viewModel; }
public function prepareNotFoundViewModel(MvcEvent $e) { $vars = $e->getResult(); if ($vars instanceof Response) { // Already have a response as the result return; } $response = $e->getResponse(); if ($response->getStatusCode() != 404) { // Only handle 404 responses return; } if (!$vars instanceof ViewModel) { $model = new ViewModel(); if (is_string($vars)) { $model->setVariable('message', $vars); } else { $model->setVariable('message', 'Page not found.'); } } else { $model = $vars; if ($model->getVariable('message') === null) { $model->setVariable('message', 'Page not found.'); } } // If displaying reasons, inject the reason $this->injectNotFoundReason($model, $e); // If displaying exceptions, inject $this->injectException($model, $e); // Inject controller if we're displaying either the reason or the exception $this->injectController($model, $e); ob_clean(); throw new \Exception($model->getVariable('message') . ' ' . $model->getVariable('reason')); }
public function editAction() { $this->getPostService(); $viewModel = new ViewModel(); $postId = $this->params()->fromPost('id', false); $userId = $this->zfcUserAuthentication()->hasIdentity() ? $this->zfcUserAuthentication()->getIdentity()->getId() : false; if (!$postId) { $postId = $this->params()->fromQuery('id', false); $post = $this->postService->getPost($postId); if ($post['user_id'] != $userId) { $this->redirect()->toUrl("/forum"); } else { $viewModel->setVariable('postId', $post['id']); $viewModel->setVariable('postContent', $post['content']); $viewModel->setTemplate("chatter/post/edit"); } } else { $content = $this->params()->fromPost('message', false); if ($postId && $content) { $this->postService->updatePost($postId, $content); } $post = $this->postService->getPost($postId); $this->redirect()->toUrl("/forum/thread?id=" . $post['thread_id']); } return $viewModel; }
public function deleteAction() { $viewModel = new ViewModel(); $id = (int) $this->params()->fromRoute('id', 0); if (!$id) { return $this->redirect()->toRoute('admin/list_price'); } $request = $this->getRequest(); if ($request->isPost()) { $del = $request->getPost('del', 'No'); if ($del == 'Si') { $id = (int) $request->getPost('id'); $result = $this->getListPriceTable()->delete($id); if (isset($result) && $result) { return $this->redirect()->toRoute('admin/list_price'); } else { $viewModel->setVariable("error", true); } } else { return $this->redirect()->toRoute('admin/list_price'); } } $viewModel->setVariable(array('id' => $id, 'listPrice' => $this->getListPriceTable()->get($id), 'config' => $this->config)); return $viewModel; }
/** * Update pays * @return ViewModel */ public function paysUpdateAction() { $view = new ViewModel(); $form = new Pays(); $code = $this->params('code'); if ($code) { $paysTable = $this->getServiceLocator()->get('pays-table'); $paysArray = $paysTable->getPaysAdmin($code); if (isset($paysArray["error"])) { return $this->redirect()->toRoute('api_admin'); } $form->bind($paysArray[0]); if ($this->request->isPost()) { $post = $this->request->getPost(); $form->setData($post); if (false === $form->isValid()) { return $view; } $cleanedData = $form->getData(); $this->savePays($cleanedData); } $view->setVariable("form", $form); $view->setVariable("code", $code); } return $view; }
/** * check if user is correctly login * * @return \Zend\Http\Response |ViewModel | redirect */ public function processAction() { $data = $this->params()->fromPost(); $form = new LoginForm(); $form->setData($data); $viewModel = new ViewModel(["form" => $form]); $viewModel->setTemplate('user/login/index'); if ($form->isValid()) { $this->authService = $this->getAuth(); $adapter = $this->authService->getAdapter(); $adapter->setIdentityValue($data['email']); $adapter->setCredentialValue($data['password']); $authResult = $this->authService->authenticate(); if ($authResult->isValid()) { $identity = $authResult->getIdentity(); $this->authService->getStorage()->write($identity); //TODO move bellow logic to specific service update last login time return $this->redirect()->toRoute('board'); } else { $viewModel->setVariable("isLoginError", true); } } else { $viewModel->setVariable("isFormError", true); } return $viewModel; }
public function getDebugTemplate($data, $e) { $model = new ViewModel(); $model->setVariable('exception', $e); $model->setVariable('data', $data); $model->setTemplate('debug-template'); return $this->_renderer->render($model); }
/** * @param array $data * @return string */ public function getBody(array $data = []) { $viewContent = new ViewModel($data); $viewContent->setTemplate($this->template); $content = $this->renderer->render($viewContent); $this->layout->setVariable('content', $content); return $this->renderer->render($this->layout); }
public function loginAction() { $authenticationService = new AuthenticationService(); if ($authenticationService->hasIdentity()) { return $this->redirect()->toRoute('dashboard'); } $form = new LoginForm(); $viewModel = new ViewModel(); $this->layout("layout/login"); $viewModel->setVariable("form", $form); $viewModel->setVariable("config", $this->config); $request = $this->getRequest(); if ($request->isPost()) { $login = new Login(); $login->getInputFilter()->get('captcha')->setRequired(false); $form->setInputFilter($login->getInputFilter()); $form->setData($request->getPost()); if ($form->isValid()) { $username = $form->get('username')->getValue(); $password = $form->get('password')->getValue(); $authSessionAdapter = $this->getAuthSessionAdapter(); if ($authSessionAdapter->authenticate($username, $password)) { $userObject = $authenticationService->getStorage()->read(); $rol = $userObject->rol; $acl = new Acl(); $acl->addResource(new Resource("dashboard")); $acl->addResource(new Resource("note")); if ($rol == 1) { $resources = $this->config['resources']; foreach ($resources as $module => $resource) { foreach ($resource as $resourceValue) { $acl->addResource(new Resource($resourceValue)); } } } else { $acl->addRole(new Role($rol)); $modules = $this->getModuleRolTable()->fetchAll($rol); foreach ($modules as $module) { $acl->addResource(new Resource($module)); } } $userObject->acl = serialize($acl); return $this->redirect()->toRoute('dashboard'); } else { $form->get('username')->setValue(""); $form->get('password')->setValue(""); if ($authSessionAdapter->getCode() == -5) { $form->get("username")->setMessages(array('username' => $this->config['authentication_codes'][$authSessionAdapter->getCode()])); } else { $form->get("username")->setMessages(array('username' => $this->config['authentication_codes'][-6])); } } } else { $form->get("username")->setMessages(array('username' => $this->config['authentication_codes'][-6])); } } return $viewModel; }
/** * @param MvcEvent $e * @return mixed|void */ public function onDispatch(MvcEvent $e) { $viewModel = new ViewModel(); $data = $this->authenticationService->getAuthData(); $viewModel->setVariable('user', $data->user); $viewModel->setVariable('configure', true); $viewModel->setTemplate('frontend/gallery/index'); $e->setResult($viewModel); }
/** * @return array|ViewModel */ public function indexAction() { $view = new ViewModel; $view->setTerminal(true); $view->setVariable('languages', $this->serviceLocator->get('config')['languages']); $view->setVariable('location', 'en_US'); $view->setVariable('version', AppInterface::VERSION); return $view; }
/** * @return array|ViewModel */ public function menuAction() { $view = new ViewModel(); $view->setTemplate('/magento/setup/navigation/menu.phtml'); $view->setTerminal(true); $view->setVariable('menu', $this->navigation->getMenuItems()); $view->setVariable('main', $this->navigation->getMainItems()); return $view; }
/** * @return array|ViewModel */ public function indexAction() { $view = new ViewModel(); $view->setTerminal(true); $view->setVariable('languages', $this->serviceLocator->get('config')['languages']); $view->setVariable('location', 'en_US'); $view->setVariable('version', $this->composerJson['version']); return $view; }
public function standaloneAction() { $test = $this->params()->fromQuery('test'); $viewModel = new ViewModel(); $viewModel->setVariable('test', $test); $viewModel->setVariable('filters', $this->getClassMethodsFromFile($test)); $viewModel->setVariable('allGetParameters', (array) $this->params()->fromQuery()); $viewModel->setVariable('filter', $this->params()->fromQuery('filter')); $viewModel->setVariable('testResults', $this->getTestResults($test, $this->params()->fromQuery('filter'))); return $viewModel; }
public function orderAction() { $id = (int) $this->params()->fromRoute('id', -1); if ($id > 0) { $_SESSION["lastUrl"] = "/order/" . $id; } $vm = new ViewModel(); $vm->setVariable("order", $this->persistenceService->getOrder($id)); $vm->setVariable("orderLines", $this->persistenceService->getOrderLines($id)); return $vm; }
public function showAction() { $site = $this->getSite(); $response = $this->api()->read('items', $this->params('id')); $item = $response->getContent(); $view = new ViewModel(); $view->setVariable('site', $site); $view->setVariable('item', $item); $view->setVariable('resource', $item); return $view; }
public function process() { $model = new ViewModel(array('form' => $this->form)); try { $this->productMapper->insert($this->form->getData()); $model->setVariable('success', true); } catch (\Exception $e) { $model->setVariable('insertError', true); } return $model; }
/** * @return array|ViewModel */ public function headerBarAction() { if ($this->navigation->getType() === NavModel::NAV_UPDATER) { if ($this->status->isUpdateError() || $this->status->isUpdateInProgress()) { $this->view->setVariable('redirect', '../' . Environment::UPDATER_DIR . '/index.php'); } } $this->view->setTemplate('/magento/setup/navigation/header-bar.phtml'); $this->view->setTerminal(true); return $this->view; }
/** * Displays license * * @return ViewModel */ public function indexAction() { $contents = $this->license->getContents(); $view = new ViewModel(); if ($contents === false) { $view->setTemplate('error/404'); $view->setVariable('message', 'Cannot find license file.'); } else { $view->setVariable('license', $contents); } return $view; }
public function showAction() { $site = $this->getSite(); $siteId = $site->id(); $pageResponse = $this->api()->read('site_pages', ['slug' => $this->params('page-slug'), 'site' => $siteId]); $page = $pageResponse->getContent(); $this->getServiceLocator()->get('ViewHelperManager')->get('sitePagePagination')->setPage($page); $view = new ViewModel(); $view->setVariable('site', $site); $view->setVariable('page', $page); return $view; }
public function __invoke(MvcEvent $event) { $model = $event->getResult(); if (!$model instanceof ViewModel) { return; } if (strpos($model->getTemplate(), 'error') === false) { return; } $result = $event->getResult(); $error = $event->getError(); $layout = new ViewModel(); $layout->setTemplate('layout/layout'); $content = new ViewModel(); if ($error == 'error-exception') { $content->setVariable('reason', 'The site seems to be experiencing problems, please try again later'); $content->setTemplate('error/knc-exception'); } else { $content->setVariable('reason', 'The site cannot find the url in the address bar'); $content->setTemplate('error/knc-error'); } $layout->addChild($content); $layout->setTerminal(true); $event->setViewModel($layout); $event->setResult($layout); return false; }