/** * 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'); } }
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]); } } }
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); } } } }
/** * On a POST request, validate the user's input. If valid, save using the * RowEditor, set a success message and then redirect. Should also behave * reasonably well when used as an endpoint for an XHR by returning a success * message and the new primary key value. * * @param ResponseHelper $responseHelper */ 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()); if (!$this->request->isAjax()) { if ($this->isNew) { $responseHelper->setSuccessMessage("Successfully saved new {$title}."); } else { $responseHelper->setSuccessMessage("Successfully saved changes to {$title}."); } } $this->rowEditor->save(); $this->logActivity(); if (!$this->request->isAjax()) { $this->redirect($responseHelper); } } } }