/**
  * @param \GIB\GradingTool\Domain\Model\Project $project
  * @return array
  */
 public function getProcessedProjectData(\GIB\GradingTool\Domain\Model\Project $project)
 {
     /** @var \TYPO3\Form\Core\Model\FormDefinition $formDefinition */
     $formDefinition = $this->formPersistenceManager->load($this->settings['forms']['projectData']);
     $fieldArray = $this->buildFieldArray($formDefinition['renderables'], $project->getProjectDataArray());
     return $fieldArray;
 }
 /**
  * Returns the templateIdentifier of a template in the laguage of a project if available,
  * fall back to default language if not available
  *
  * @param string $templateIdentifier
  * @param \GIB\GradingTool\Domain\Model\Project $project
  * @return string
  */
 public function getTemplateIdentifierOverlay($templateIdentifier, \GIB\GradingTool\Domain\Model\Project $project)
 {
     $availableLanguages = $this->settings['languages'];
     $defaultLangage = $this->settings['defaultLanguage'];
     $projectLanguage = $project->getLanguage();
     if ($projectLanguage === $defaultLangage) {
         // the language for the default template has no suffix, therefore return the unchanged templateIdentifier
         return $templateIdentifier;
     }
     if (array_key_exists($projectLanguage, $availableLanguages)) {
         // language is available, so we try to overlay
         if (count($this->templateRepository->findByTemplateIdentifier($templateIdentifier . ucfirst($projectLanguage)))) {
             // localized template was found, so we use it
             return $templateIdentifier . ucfirst($projectLanguage);
         } else {
             // localized template was not found, we fall back to default language
             return $templateIdentifier;
         }
     }
 }
 /**
  * @param $templateIdentifier
  * @param \GIB\GradingTool\Domain\Model\Project $project
  * @param \GIB\GradingTool\Domain\Model\ProjectManager $projectManager
  * @param string $recipientName
  * @param string $recipientEmail
  * @param string $additionalContent
  * @param array $attachements
  * @return bool|void
  */
 public function sendNotificationMail($templateIdentifier, \GIB\GradingTool\Domain\Model\Project $project, \GIB\GradingTool\Domain\Model\ProjectManager $projectManager = NULL, $recipientName = '', $recipientEmail = '', $additionalContent = '', $attachements = array())
 {
     if ($this->settings['email']['activateNotifications'] === FALSE) {
         return TRUE;
     }
     /** @var \GIB\GradingTool\Domain\Model\Template $template */
     $template = $this->templateRepository->findOneByTemplateIdentifier($templateIdentifier);
     $templateContentArray = unserialize($template->getContent());
     // some kind of wrapper of all e-mail templates containing the HTML structure and styles
     $beforeContent = Files::getFileContents($this->settings['email']['beforeContentTemplate']);
     $afterContent = Files::getFileContents($this->settings['email']['afterContentTemplate']);
     /** @var \TYPO3\Fluid\View\StandaloneView $emailView */
     $emailView = new \TYPO3\Fluid\View\StandaloneView();
     $emailView->setTemplateSource('<f:format.raw>' . $beforeContent . $templateContentArray['content'] . $afterContent . '</f:format.raw>');
     $emailView->setPartialRootPath(FLOW_PATH_PACKAGES . 'Application/GIB.GradingTool/Resources/Private/Partials');
     $emailView->setFormat('html');
     $emailView->assignMultiple(array('beforeContent' => $beforeContent, 'afterContent' => $afterContent, 'project' => $project, 'projectManager' => $projectManager, 'dataSheetContent' => $project->getDataSheetContentArray(), 'additionalContent' => $additionalContent));
     $emailBody = $emailView->render();
     /** @var \TYPO3\SwiftMailer\Message $email */
     $email = new Message();
     $email->setFrom(array($templateContentArray['senderEmail'] => $templateContentArray['senderName']));
     // the recipient e-mail can be overridden by method arguments
     if (!empty($recipientEmail)) {
         $email->setTo(array((string) $recipientEmail => (string) $recipientName));
         // in this case, send a bcc to the GIB team
         $email->setBcc(array($templateContentArray['senderEmail'] => $templateContentArray['senderName']));
     } else {
         $email->setTo(array($templateContentArray['recipientEmail'] => $templateContentArray['recipientName']));
     }
     if (!empty($attachements)) {
         foreach ($attachements as $attachement) {
             $email->attach(\Swift_Attachment::fromPath($attachement['source'])->setFilename($attachement['fileName']));
         }
     }
     $email->setSubject($templateContentArray['subject']);
     $email->setBody($emailBody, 'text/html');
     $email->send();
 }
 /**
  * Check if an administrator is logged in or the owner of a project and deny access if someone else is trying to access
  *
  * @param \GIB\GradingTool\Domain\Model\Project $project
  */
 public function checkOwnerOrAdministratorAndDenyIfNeeded(\GIB\GradingTool\Domain\Model\Project $project)
 {
     // check if the user has access to this project
     if ($this->securityContext->getParty() !== $project->getProjectManager() && !array_key_exists('GIB.GradingTool:Administrator', $this->securityContext->getRoles())) {
         // add a flash message
         $message = new \TYPO3\Flow\Error\Message('Access denied.', \TYPO3\Flow\Error\Message::SEVERITY_ERROR);
         $this->flashMessageContainer->addMessage($message);
         $this->redirect('index', 'Standard');
     }
 }
 /**
  * Get score basis data
  *
  * @param Project $project
  * @return array
  */
 public function getScoreData(Project $project = NULL)
 {
     $form = $project instanceof Project ? $project->getSubmissionFormIdentifier() : $this->settings['forms']['submission']['default'];
     $submissionFormDefinition = $this->formPersistenceManager->load($form);
     $scoreData = array();
     foreach ($submissionFormDefinition['renderables'] as $key => $page) {
         // a form page
         foreach ($page['renderables'] as $section) {
             $scoreData[$key]['categoryName'] = $section['label'];
             $scoreData[$key]['goodScore'] = $section['properties']['goodPerformanceReferenceScore'];
             $scoreData[$key]['modestScore'] = $section['properties']['modestPerformanceReferenceScore'];
             $scoreData[$key]['modestScore'] = $section['properties']['modestPerformanceReferenceScore'];
             // todo average score
             $scoreData[$key]['currentAverageScore'] = 0;
         }
     }
     return $scoreData;
 }
 /**
  * @param \GIB\GradingTool\Domain\Model\Project $project
  * @param bool $languageOverlay
  * @return array
  */
 public function getFlatProcessedDataSheet(\GIB\GradingTool\Domain\Model\Project $project, $languageOverlay = FALSE)
 {
     /** @var \TYPO3\Form\Factory\ArrayFormFactory $factory */
     $factory = new \TYPO3\Form\Factory\ArrayFormFactory();
     // todo overlay if needed
     $overrideConfiguration = $this->formPersistenceManager->load($project->getDataSheetFormIdentifier());
     /** @var \TYPO3\Form\Core\Model\FormDefinition $formDefinition */
     $formDefinition = $factory->build($overrideConfiguration);
     $flatDataSheetArray = array();
     foreach ($project->getDataSheetContentArray() as $key => $value) {
         $formElement = $formDefinition->getElementByIdentifier($key);
         if ($formElement instanceof \TYPO3\Form\Core\Model\FormElementInterface) {
             $flatDataSheetArray[$key]['label'] = $formDefinition->getElementByIdentifier($key)->getLabel();
             $flatDataSheetArray[$key]['type'] = $formDefinition->getElementByIdentifier($key)->getType();
             $flatDataSheetArray[$key]['value'] = $value;
         }
     }
     return $flatDataSheetArray;
 }
 /**
  * Adds a project to this projectManager
  *
  * @param \GIB\GradingTool\Domain\Model\Project $project
  * @return void
  */
 public function addProject(\GIB\GradingTool\Domain\Model\Project $project)
 {
     $project->setProjectManager($this);
     $this->projects->add($project);
 }