/** * Executes this finisher * @see AbstractFinisher::execute() * * @return void * @throws \TYPO3\Flow\Mvc\Exception\StopActionException(); */ protected function executeInternal() { /** @var \TYPO3\Form\Core\Runtime\FormRuntime $formRuntime */ $formRuntime = $this->finisherContext->getFormRuntime(); $formValueArray = $formRuntime->getFormState()->getFormValues(); /** @var \GIB\GradingTool\Domain\Model\Project $project */ $project = $this->projectRepository->findByIdentifier($formRuntime->getRequest()->getParentRequest()->getArgument('project')); // store changes to project $project->setProjectData($formValueArray); $this->projectRepository->update($project); // add a flash message $message = new \TYPO3\Flow\Error\Message('The project data for "%s" was successfully edited.', \TYPO3\Flow\Error\Message::SEVERITY_OK, array($project->getProjectTitle())); $this->flashMessageContainer->addMessage($message); $this->persistenceManager->persistAll(); // redirect to dashboard $formRuntime = $this->finisherContext->getFormRuntime(); $request = $formRuntime->getRequest()->getMainRequest(); $uriBuilder = new \TYPO3\Flow\Mvc\Routing\UriBuilder(); $uriBuilder->setRequest($request); $uriBuilder->reset(); $uri = $uriBuilder->uriFor('index', NULL, 'Admin'); $response = $formRuntime->getResponse(); $mainResponse = $response; while ($response = $response->getParentResponse()) { $mainResponse = $response; } $mainResponse->setStatus(303); $mainResponse->setHeader('Location', (string) $uri); throw new \TYPO3\Flow\Mvc\Exception\StopActionException(); }
/** * @param array $demand */ public function listAction($demand = NULL) { if (is_array($demand)) { $demand = Arrays::removeEmptyElementsRecursively($demand); $projects = $this->projectRepository->findByDemand($demand); //\TYPO3\Flow\var_dump($demand, 'demand'); // return not only the country code, but also the country name for filter display if (isset($demand['filter']['country'])) { $isoCode = $demand['filter']['country']; unset($demand['filter']['country']); $demand['filter']['country']['name'] = $this->cldrService->getTerritoryNameForIsoCode($isoCode); $demand['filter']['country']['isoCode'] = $isoCode; } // return not only the regions requested, but also their names if (isset($demand['filter']['regions']) && is_array($demand['filter']['regions'])) { $regionsRequested = $demand['filter']['regions']; unset($demand['filter']['regions']); foreach ($regionsRequested as $region) { $demand['filter']['regions'][$region]['key'] = $region; $demand['filter']['regions'][$region]['name'] = $this->cldrService->getTerritoryNameForIsoCode($region); } } // return not only the stages requested, but also their names if (isset($demand['filter']['stages']) && is_array($demand['filter']['stages'])) { $stagesRequested = $demand['filter']['stages']; unset($demand['filter']['stages']); $stagesSettings = $this->settings['projectDatabase']['filters']['stage']; foreach ($stagesRequested as $stage) { $demand['filter']['stages'][$stage]['key'] = $stage; $demand['filter']['stages'][$stage]['name'] = $stagesSettings[$stage]['_value']; } } // return not only the budget bracket keys, but also the minimum and maximum value if (isset($demand['filter']['budgetBrackets']) && is_array($demand['filter']['budgetBrackets'])) { $bracketsRequested = $demand['filter']['budgetBrackets']; unset($demand['filter']['budgetBrackets']); $bracketSettings = $this->settings['projectDatabase']['filters']['budget']['brackets']; foreach ($bracketsRequested as $bracket) { $demand['filter']['budgetBrackets'][$bracket]['key'] = $bracket; $demand['filter']['budgetBrackets'][$bracket]['minimum'] = $bracketSettings[$bracket]['minimum']; $demand['filter']['budgetBrackets'][$bracket]['maximum'] = $bracketSettings[$bracket]['maximum']; } } // return not only the required investment bracket keys, but also the minimum and maximum value if (isset($demand['filter']['requiredInvestmentBrackets']) && is_array($demand['filter']['requiredInvestmentBrackets'])) { $bracketsRequested = $demand['filter']['requiredInvestmentBrackets']; unset($demand['filter']['requiredInvestmentBrackets']); $bracketSettings = $this->settings['projectDatabase']['filters']['budget']['brackets']; foreach ($bracketsRequested as $bracket) { $demand['filter']['requiredInvestmentBrackets'][$bracket]['key'] = $bracket; $demand['filter']['requiredInvestmentBrackets'][$bracket]['minimum'] = $bracketSettings[$bracket]['minimum']; $demand['filter']['requiredInvestmentBrackets'][$bracket]['maximum'] = $bracketSettings[$bracket]['maximum']; } } } else { $projects = $this->projectRepository->findVisible(); } $this->view->assignMultiple(array('projects' => $projects, 'demand' => $demand)); }
/** * Executes this finisher * @see AbstractFinisher::execute() * * @return void * @throws \TYPO3\Flow\Mvc\Exception\StopActionException(); */ protected function executeInternal() { /** @var \TYPO3\Form\Core\Runtime\FormRuntime $formRuntime */ $formRuntime = $this->finisherContext->getFormRuntime(); // The corresponding project $projectIdentifier = $formRuntime->getRequest()->getParentRequest()->getArgument('project'); /** @var \GIB\GradingTool\Domain\Model\Project $project */ $project = $this->projectRepository->findByIdentifier($projectIdentifier); $sendGradingToProjectManager = FALSE; if (is_null($project->getSubmissionLastUpdated())) { $sendGradingToProjectManager = TRUE; } // update the project with the data from the form $formValueArray = $formRuntime->getFormState()->getFormValues(); $project->setSubmissionContent(serialize($formValueArray)); $project->setSubmissionLastUpdated(new \TYPO3\Flow\Utility\Now()); $this->projectRepository->update($project); $this->persistenceManager->persistAll(); // add a flash message $message = new \TYPO3\Flow\Error\Message('Thank you for submitting the data for your project "%s".', \TYPO3\Flow\Error\Message::SEVERITY_OK, array($project->getProjectTitle())); $this->flashMessageContainer->addMessage($message); // send notification mail $templateIdentifierOverlay = $this->templateService->getTemplateIdentifierOverlay('newSubmissionNotification', $project); $this->notificationMailService->sendNotificationMail($templateIdentifierOverlay, $project, $project->getProjectManager()); if ($sendGradingToProjectManager) { // The grading was completed for the first time, so we send the grading to the project manager $this->submissionService->sendGradingToProjectManager($project); } // redirect to dashboard $formRuntime = $this->finisherContext->getFormRuntime(); $request = $formRuntime->getRequest()->getMainRequest(); $uriBuilder = new \TYPO3\Flow\Mvc\Routing\UriBuilder(); $uriBuilder->setRequest($request); $uriBuilder->reset(); $uri = $uriBuilder->uriFor('index', NULL, 'Standard'); $response = $formRuntime->getResponse(); $mainResponse = $response; while ($response = $response->getParentResponse()) { $mainResponse = $response; } $mainResponse->setStatus(303); $mainResponse->setHeader('Location', (string) $uri); throw new \TYPO3\Flow\Mvc\Exception\StopActionException(); }
/** * Migrate Primary Sector * * Migrates the dataSheet field "singleselectdropdown1" in the serialized dataSheetContent field of a project. * Changes field name to "primarySector" and field values to speaking values. * * @param boolean $simulate If set, this command will only tell what it would do instead of doing it right away * @return void */ public function migratePrimarySectorCommand($simulate = FALSE) { $affectedProjects = $this->projectRepository->findByDataSheetFormIdentifier('dataSheetFormV2'); foreach ($affectedProjects as $project) { /** @var $project \GIB\GradingTool\Domain\Model\Project */ $dataSheetContentArray = $project->getDataSheetContentArray(); if (array_key_exists('singleselectdropdown1', $dataSheetContentArray)) { $value = $dataSheetContentArray['singleselectdropdown1']; $newValue = ''; switch ($value) { case 'transport': $newValue = 'Transportation (Railway, Road, BRT, etc.)'; break; case 'energy': $newValue = 'Energy generation and distribution'; break; case 'water': $newValue = 'Water and waste processing'; break; case 'social': $newValue = 'Social Infrastructure (schools, hospitals, state housing)'; break; case 'telecom': $newValue = 'ICT'; break; default: break; } unset($dataSheetContentArray['singleselectdropdown1']); $dataSheetContentArray['primarySector'] = $newValue; $project->setDataSheetContent($dataSheetContentArray); $status = '[SIMULATE] '; if (!$simulate) { $this->projectRepository->update($project); $this->persistenceManager->persistAll(); $status = ''; } $message = $status . 'Project "' . $project->getProjectTitle() . '": Changed singleselectdropdown "' . $value . '" to primarySector "' . $newValue . '".'; $this->outputLine($message); } } $this->quit(); }
/** * Send the grading of a project to its project manager if the submission is complete * * @param string $submissionFormIdentifier * @param boolean $testMode */ public function sendGradingToProjectManagerAction($submissionFormIdentifier, $testMode = TRUE) { $this->checkAdministratorAndDenyIfNeeded(); $projects = $this->projectRepository->findBySubmissionFormIdentifier($submissionFormIdentifier); foreach ($projects as $project) { /** @var \GIB\GradingTool\Domain\Model\Project $project */ if (!is_null($project->getSubmissionLastUpdated()) && !empty($project->getSubmissionContent())) { $message = 'Send Grading for Project ' . $project->getProjectTitle() . ' to ' . $project->getProjectManager()->getPrimaryElectronicAddress()->getIdentifier() . '.'; if (!$testMode) { $this->submissionService->sendGradingToProjectManager($project); print '[!!!] ' . $message . PHP_EOL; } else { print '[TEST] ' . $message . PHP_EOL; } } } die; }
/** * Executes this finisher * @see AbstractFinisher::execute() * * @return void * @throws \TYPO3\Flow\Mvc\Exception\StopActionException(); */ protected function executeInternal() { /** @var \TYPO3\Form\Core\Runtime\FormRuntime $formRuntime */ $formRuntime = $this->finisherContext->getFormRuntime(); $formValueArray = $formRuntime->getFormState()->getFormValues(); if ($formRuntime->getRequest()->getParentRequest()->getControllerActionName() == 'editDataSheet') { // we need to update the data sheet, we assume that the person is authenticated because a data sheet can only be edited by a authenticated user /** @var \GIB\GradingTool\Domain\Model\Project $project */ $project = $this->projectRepository->findByIdentifier($formRuntime->getRequest()->getParentRequest()->getArgument('project')); // make a HTML representation of a diff of the old and new data $diffContent = DiffUtility::arrayDiffRecursive($project->getDataSheetContentArray(), $formValueArray); // store changes to project $project->setDataSheetContent($formValueArray); $project->setLastUpdated(new \TYPO3\Flow\Utility\Now()); // update e-mail address (could have changed in the data sheet) $projectManagerElectronicAddress = new \TYPO3\Party\Domain\Model\ElectronicAddress(); $projectManagerElectronicAddress->setIdentifier($formValueArray['projectManagerEmail']); $projectManagerElectronicAddress->setType(\TYPO3\Party\Domain\Model\ElectronicAddress::TYPE_EMAIL); $project->getProjectManager()->setPrimaryElectronicAddress($projectManagerElectronicAddress); $this->partyRepository->update($project->getProjectManager()); $this->projectRepository->update($project); $this->persistenceManager->persistAll(); // send a notification mail to the Administrator containing the changes $templateIdentifierOverlay = $this->templateService->getTemplateIdentifierOverlay('editDataSheetNotification', $project); $this->notificationMailService->sendNotificationMail($templateIdentifierOverlay, $project, NULL, '', '', $diffContent); // add a flash message $message = new \TYPO3\Flow\Error\Message('Your data sheet for project "%s" was successfully edited.', \TYPO3\Flow\Error\Message::SEVERITY_OK, array($project->getProjectTitle())); $this->flashMessageContainer->addMessage($message); } else { // we need to add a new data sheet /** @var \GIB\GradingTool\Domain\Model\Project $project */ $project = new \GIB\GradingTool\Domain\Model\Project(); $project->setProjectTitle($formValueArray['projectTitle']); $project->setDataSheetFormIdentifier($this->settings['forms']['dataSheet']['default']); $project->setSubmissionFormIdentifier($this->settings['forms']['submission']['default']); // store identifier=userName and password for later usage $identifier = $formValueArray['userName']; $password = $formValueArray['password']; // remove userName and password from data array so it doesn't get saved unencrypted unset($formValueArray['userName']); unset($formValueArray['password']); $project->setDataSheetContent($formValueArray); $project->setCreated(new \TYPO3\Flow\Utility\Now()); $this->projectRepository->add($project); // add a flash message $message = new \TYPO3\Flow\Error\Message('Your data sheet for project "%s" was successfully submitted.', \TYPO3\Flow\Error\Message::SEVERITY_OK, array($formValueArray['projectTitle'])); $this->flashMessageContainer->addMessage($message); if (!$this->authenticationManager->isAuthenticated() || $this->authenticationManager->isAuthenticated() && $this->authenticationManager->getSecurityContext()->hasRole('GIB.GradingTool:Administrator')) { // the product manager (supposedly) doesn't have an account yet, so we create one $projectManager = new \GIB\GradingTool\Domain\Model\ProjectManager(); $projectManagerName = new \TYPO3\Party\Domain\Model\PersonName('', $formValueArray['projectManagerFirstName'], '', $formValueArray['projectManagerLastName']); $projectManager->setName($projectManagerName); $projectManagerElectronicAddress = new \TYPO3\Party\Domain\Model\ElectronicAddress(); $projectManagerElectronicAddress->setIdentifier($formValueArray['projectManagerEmail']); $projectManagerElectronicAddress->setType(\TYPO3\Party\Domain\Model\ElectronicAddress::TYPE_EMAIL); $projectManager->addElectronicAddress($projectManagerElectronicAddress); $projectManager->setPrimaryElectronicAddress($projectManagerElectronicAddress); // add account $roles = array('GIB.GradingTool:ProjectManager'); $authenticationProviderName = 'DefaultProvider'; $account = $this->accountFactory->createAccountWithPassword($identifier, $password, $roles, $authenticationProviderName); $this->accountRepository->add($account); // add account to ProjectManager $projectManager->addAccount($account); // add project to ProjectManager $projectManager->addProject($project); // finally add the complete ProjectManager $this->partyRepository->add($projectManager); if (!$this->authenticationManager->getSecurityContext()->hasRole('GIB.GradingTool:Administrator')) { // authenticate user if no Administrator is authenticated $authenticationTokens = $this->securityContext->getAuthenticationTokensOfType('TYPO3\\Flow\\Security\\Authentication\\Token\\UsernamePassword'); if (count($authenticationTokens) === 1) { $authenticationTokens[0]->setAccount($account); $authenticationTokens[0]->setAuthenticationStatus(\TYPO3\Flow\Security\Authentication\TokenInterface::AUTHENTICATION_SUCCESSFUL); } // add a flash message $message = new \TYPO3\Flow\Error\Message('The account "%s" was created and you were successfully logged in.', \TYPO3\Flow\Error\Message::SEVERITY_OK, array($identifier)); $this->flashMessageContainer->addMessage($message); } } elseif ($this->authenticationManager->isAuthenticated() && $this->authenticationManager->getSecurityContext()->hasRole('GIB.GradingTool:ProjectManager')) { // a productManager is adding a new project to his account /** @var \GIB\GradingTool\Domain\Model\ProjectManager $projectManager */ $projectManager = $this->authenticationManager->getSecurityContext()->getParty(); $projectManager->addProject($project); $this->partyRepository->update($projectManager); } $this->persistenceManager->persistAll(); // send notification mail to project manager (bcc to team) $templateIdentifierOverlay = $this->templateService->getTemplateIdentifierOverlay('newDataSheetProjectManagerNotification', $project); $this->notificationMailService->sendNotificationMail($templateIdentifierOverlay, $project, $projectManager, $formValueArray['projectManagerFirstName'] . ' ' . $formValueArray['projectManagerLastName'], $formValueArray['projectManagerEmail']); // send notification mail to the GIB team $templateIdentifierOverlay = $this->templateService->getTemplateIdentifierOverlay('newDataSheetTeamNotification', $project); $dataSheetArray = $this->dataSheetService->getProcessedDataSheet($project); $this->notificationMailService->sendNotificationMail($templateIdentifierOverlay, $project, $projectManager, '', '', $dataSheetArray); } $this->persistenceManager->persistAll(); // redirect to dashboard $formRuntime = $this->finisherContext->getFormRuntime(); $request = $formRuntime->getRequest()->getMainRequest(); $uriBuilder = new \TYPO3\Flow\Mvc\Routing\UriBuilder(); $uriBuilder->setRequest($request); $uriBuilder->reset(); $uri = $uriBuilder->uriFor('editDatasheet', array('project' => $project), 'Project'); $response = $formRuntime->getResponse(); $mainResponse = $response; while ($response = $response->getParentResponse()) { $mainResponse = $response; } $mainResponse->setStatus(303); $mainResponse->setHeader('Location', (string) $uri); throw new \TYPO3\Flow\Mvc\Exception\StopActionException(); }