/** * Handle submission of the edit form. This primarily exists (rather * than using the stock Edit->process()) for the password hashing. * * @todo Find a better way to handle the password hashing. * * @param ResponseHelper $responseHelper * @return void */ public function process(ResponseHelper $responseHelper) { if ($this->request->isPost()) { $this->invalidSubmission = !$this->rowEditor->isValid($this->request->getPost()); if (!$this->invalidSubmission) { $title = strtolower($this->model->getSingularTitle()); /* @var $row \Dewdrop\Auth\Db\UserRowGateway */ $row = $this->rowEditor->getRow($this->model->getTableName()); if ($this->isNew) { $row->hashPassword($this->request->getPost('password')); $responseHelper->setSuccessMessage("Successfully saved new {$title}"); } else { $responseHelper->setSuccessMessage("Successfully saved changes to {$title}"); } $row->save(); if (!$this->request->isAjax()) { $responseHelper->redirectToAdminPage('index'); } else { header('Content-Type: application/json'); echo json_encode(['result' => 'success', 'id' => $this->component->getListing()->getPrimaryKey()->getValue()]); exit; } } } }
/** * On POST requests, save the new settings to the filter, set a success * message and redirect back to the component's listing. * * @param ResponseHelper $responseHelper */ public function process(ResponseHelper $responseHelper) { if ($this->request->isPost()) { $responseHelper->run('save', function () { $this->filter->save(json_decode($this->request->getPost('sorted_fields'), true)); }); $responseHelper->setSuccessMessage("Successfully sorted and grouped {$this->component->getTitle()} fields")->redirectToAdminPage('index'); } }
/** * Grab the selected visible columns from POST and save them back to * the visibility filter. * * @param ResponseHelper $responseHelper */ public function process(ResponseHelper $responseHelper) { $this->component->getPermissions()->haltIfNotAllowed('adjust-columns'); $selections = $this->request->getPost('visible_columns'); $applyToAllUsers = (bool) $this->request->getPost('apply_to_all_users', false); if (is_array($selections)) { /* @var $filter VisibilityFilter */ $filter = $this->component->getVisibilityFilter(); $filter->save($this->component->getFields(), $selections, $applyToAllUsers); } $responseHelper->redirectToAdminPage('index'); }
public function process(ResponseHelper $helper) { if ($this->request->isPost()) { $inputFilter = ImportInputFilterFactory::createInstance(); $inputFilter->setData($_FILES); if (!$inputFilter->isValid() || !is_uploaded_file($_FILES['file']['tmp_name'])) { $this->validationMessages = $inputFilter->getMessages(); } else { $file = ImportFile::fromUploadedFile($_FILES['file'], $this->getUploadPath(), $this->request->getPost('first_row_is_headers')); $gateway = new DbGateway(); $id = $gateway->insert(['component' => $this->component->getFullyQualifiedName(), 'full_path' => $file->getFullPath(), 'first_row_is_headers' => (int) $this->request->getPost('first_row_is_headers')]); $helper->setSuccessMessage('Import file successfully uploaded.')->redirectToAdminPage('import-map-fields', ['id' => $id]); } } }
/** * Perform any processing or data manipulation needed before render. * * A response helper object will be passed to this method to allow you to * easily add success messages or redirects. This helper should be used * to handle these kinds of actions so that you can easily test your * page's code. * * @param ResponseHelper $responseHelper * @return ResponseHelper|null */ public function process(ResponseHelper $responseHelper) { $isCurrentUser = $this->row->get('user_id') === Pimple::getResource('user')->get('user_id'); if (!$this->component->getPermissions()->can('edit') && !$isCurrentUser) { return $responseHelper->redirectToUrl('/admin'); } if ($this->request->isPost()) { $this->inputFilter->setData($this->request->getPost()); if ($this->inputFilter->isValid()) { $this->row->hashPassword($this->request->getPost('password'))->save(); if ($isCurrentUser) { return $responseHelper->redirectToUrl('/admin'); } else { return $responseHelper->redirectToAdminPage('index'); } } } }
public function process(ResponseHelper $helper) { if ($this->request->isPost()) { $importRows = $this->importFile->getData(); $inputRows = []; $fields = $this->getFields()->getEditableFields(); foreach ($importRows as $row) { $data = []; foreach ($fields as $field) { $id = $field->getId(); $modeId = $id . ':mode'; $mode = $this->request->getPost($modeId); $data[$id] = $this->getFieldValue($id, $mode, $row); } $inputRows[] = $data; } if ($this->isValid($fields, $importRows, $inputRows)) { $this->save($inputRows); $count = count($importRows); $helper->setSuccessMessage("Successfully imported {$count} {$this->getPluralTitle()}.")->redirectToAdminPage('index'); } } }
/** * If our component is a BulkActionProcessorInterface implementer, then * process those here, handling the result and associated message. * * @param ResponseHelper $responseHelper */ public function process(ResponseHelper $responseHelper) { if ($this->component instanceof BulkActionProcessorInterface) { $result = $this->component->getBulkActions()->process(); if ($result) { if (!$result->isSuccess()) { $this->bulkActionFailureMessage = $result->getMessage(); } else { $index = $this->component->getListingQueryParamsSessionName(); $params = isset($this->session[$index]) ? $this->session[$index] : []; $responseHelper->setSuccessMessage($result->getMessage())->redirectToAdminPage('Index', $params); } } } }
protected function redirect(ResponseHelper $responseHelper) { $session = new Session(); $index = $this->component->getListingQueryParamsSessionName(); $params = isset($session[$index]) ? $session[$index] : []; $responseHelper->redirectToAdminPage('index', $params); }
protected function redirect(ResponseHelper $responseHelper) { $session = new Session(Pimple::getInstance()); $index = $this->component->getListingQueryParamsSessionName(); $params = isset($session[$index]) ? $session[$index] : []; if (!is_array($params)) { $params = (array) $params; } $responseHelper->redirectToAdminPage('index', $params); }