Exemple #1
0
 /**
  * Save data from editing a page
  * @param integer $pageId
  */
 public function actionSavePage($pageId)
 {
     $data = json_decode($this->post['data']);
     switch ($data->status) {
         case 'delete':
             if ($applicationPage = $this->_em->getRepository('\\Jazzee\\Entity\\ApplicationPage')->findOneBy(array('page' => $pageId, 'application' => $this->_application->getId()))) {
                 if ($this->_em->getRepository('\\Jazzee\\Entity\\Page')->hasApplicationAnswers($applicationPage->getPage(), $this->_application)) {
                     $this->setLayoutVar('status', 'error');
                     $this->addMessage('error', $applicationPage->getTitle() . ' could not be deleted becuase it has applicant information associated with it.');
                 } else {
                     if (!$applicationPage->getPage()->isGlobal()) {
                         $this->_em->remove($applicationPage->getPage());
                     }
                     $this->_em->remove($applicationPage);
                     $this->addMessage('success', $applicationPage->getTitle() . ' deleted');
                 }
             }
             break;
         case 'new-global':
             $applicationPage = new \Jazzee\Entity\ApplicationPage();
             $applicationPage->setPage($this->_em->getRepository('\\Jazzee\\Entity\\Page')->findOneBy(array('id' => $pageId, 'isGlobal' => true)));
             $applicationPage->setKind($data->kind);
             $applicationPage->setApplication($this->_application);
             $applicationPage->setWeight($data->weight);
             $applicationPage->setTitle($data->title);
             $applicationPage->setMin($data->min);
             $applicationPage->setMax($data->max);
             if ($data->isRequired) {
                 $applicationPage->required();
             } else {
                 $applicationPage->optional();
             }
             $applicationPage->setInstructions($data->instructions);
             $applicationPage->setLeadingText($data->leadingText);
             $applicationPage->setTrailingText($data->trailingText);
             $this->_em->persist($applicationPage);
             $this->addMessage('success', $data->title . ' created.');
             break;
         case 'new':
         case 'copy':
             $page = new \Jazzee\Entity\Page();
             $page->notGlobal();
             $page->setType($this->_em->getRepository('\\Jazzee\\Entity\\PageType')->find($data->typeId));
             $this->_em->persist($page);
             $applicationPage = new \Jazzee\Entity\ApplicationPage();
             $applicationPage->setPage($page);
             $applicationPage->setKind($data->kind);
             $applicationPage->setWeight($data->weight);
             $applicationPage->setApplication($this->_application);
             $applicationPage->getJazzeePage()->setController($this);
             //only do setup for new pages, copies lready ahve elements
             if ($data->status == 'new') {
                 $applicationPage->getJazzeePage()->setupNewPage();
             }
             $this->addMessage('success', $data->title . ' created.');
         default:
             if (!isset($applicationPage)) {
                 $applicationPage = $this->_em->getRepository('\\Jazzee\\Entity\\ApplicationPage')->findOneBy(array('page' => $pageId, 'application' => $this->_application->getId()));
             }
             $this->savePage($applicationPage, $data);
     }
 }
 /**
  * Setup the current application and cycle
  */
 public function actionIndex()
 {
     $form = new \Foundation\Form();
     $form->setCSRFToken($this->getCSRFToken());
     $form->setAction($this->path("setup/copyapplication"));
     $field = $form->newField();
     $field->setLegend('Import Application');
     $element = $field->newElement('SelectList', 'application');
     $element->setLabel('Cycle to Copy');
     $element->addValidator(new \Foundation\Form\Validator\NotEmpty($element));
     $applications = $this->_em->getRepository('\\Jazzee\\Entity\\Application')->findByProgram($this->_program);
     foreach ($applications as $application) {
         $element->newItem($application->getId(), $application->getCycle()->getName());
     }
     $form->newButton('submit', 'Copy');
     if ($input = $form->processInput($this->post)) {
         $previousApplication = $this->_em->getRepository('\\Jazzee\\Entity\\Application')->find($input->get('application'));
         $this->_application = new \Jazzee\Entity\Application();
         $this->_application->setProgram($this->_program);
         $this->_application->setCycle($this->_cycle);
         $this->_application->inVisible();
         $this->_application->unPublish();
         if ($previousApplication->isByInvitationOnly()) {
             $this->_application->byInvitationOnly();
         }
         $this->_application->setContactName($previousApplication->getContactName());
         $this->_application->setContactEmail($previousApplication->getContactEmail());
         $this->_application->setWelcome($previousApplication->getWelcome());
         $this->_application->setOpen($previousApplication->getOpen()->format('c'));
         $this->_application->setClose($previousApplication->getClose()->format('c'));
         $this->_application->setBegin($previousApplication->getBegin()->format('c'));
         $this->_application->setStatusIncompleteText($previousApplication->getStatusIncompleteText());
         $this->_application->setStatusNoDecisionText($previousApplication->getStatusNoDecisionText());
         $this->_application->setStatusAdmitText($previousApplication->getStatusAdmitText());
         $this->_application->setStatusDenyText($previousApplication->getStatusDenyText());
         $this->_application->setStatusAcceptText($previousApplication->getStatusAcceptText());
         $this->_application->setStatusDeclineText($previousApplication->getStatusDeclineText());
         foreach ($previousApplication->getApplicationPages() as $previousPage) {
             $page = $this->addPage($previousPage->getPage());
             $applicationPage = new \Jazzee\Entity\ApplicationPage();
             $applicationPage->setApplication($this->_application);
             $applicationPage->setPage($page);
             $applicationPage->setKind($previousPage->getKind());
             $applicationPage->setTitle($previousPage->getTitle());
             $applicationPage->setMin($previousPage->getMin());
             $applicationPage->setMax($previousPage->getMax());
             $applicationPage->setName($previousPage->getName());
             if ($previousPage->isRequired()) {
                 $applicationPage->required();
             } else {
                 $applicationPage->optional();
             }
             if ($previousPage->answerStatusDisplay()) {
                 $applicationPage->showAnswerStatus();
             } else {
                 $applicationPage->hideAnswerStatus();
             }
             $applicationPage->setInstructions($previousPage->getInstructions());
             $applicationPage->setLeadingText($previousPage->getLeadingText());
             $applicationPage->setTrailingText($previousPage->getTrailingText());
             $applicationPage->setWeight($previousPage->getWeight());
             $this->_em->persist($applicationPage);
         }
         $templates = $this->_em->getRepository('Jazzee\\Entity\\Template')->findBy(array('application' => $previousApplication));
         foreach ($templates as $previousTemplate) {
             $template = new \Jazzee\Entity\Template($previousTemplate->getType());
             $template->setApplication($this->_application);
             $template->setTitle($previousTemplate->getTitle());
             $template->setText($previousTemplate->getText());
             $this->_em->persist($template);
         }
         $this->_em->persist($this->_application);
         $this->addMessage('success', 'Application copied successfully');
         unset($this->_store->AdminControllerGetNavigation);
         $this->redirectPath('setup/application');
     }
     $this->setVar('form', $form);
 }
 /**
  * Create a preview application
  * @param \Doctrine\ORM\EntityManager $em
  * @param \Jazzee\Entity\Role $adminRole
  * @return \Jazzee\Entity\Application
  */
 protected function createPreviewApplication(\Doctrine\ORM\EntityManager $em, \Jazzee\Entity\Role $adminRole)
 {
     $newApplication = new \Jazzee\Entity\Application();
     $properties = array('contactName', 'contactEmail', 'welcome', 'statusIncompleteText', 'statusNoDecisionText', 'statusAdmitText', 'statusDenyText', 'statusAcceptText', 'statusDeclineText');
     foreach ($properties as $name) {
         $set = 'set' . ucfirst($name);
         $get = 'get' . ucfirst($name);
         $newApplication->{$set}($this->_application->{$get}());
     }
     $timeProperties = array('open', 'close', 'begin');
     foreach ($timeProperties as $name) {
         $set = 'set' . ucfirst($name);
         $get = 'get' . ucfirst($name);
         $newApplication->{$set}($this->_application->{$get}()->format('c'));
     }
     $newApplication->publish(true);
     $newApplication->visible();
     $program = new \Jazzee\Entity\Program();
     $program->setName($this->_program->getName());
     $program->setShortName($this->_program->getShortName());
     $em->persist($program);
     $newApplication->setProgram($program);
     $cycle = new \Jazzee\Entity\Cycle();
     $cycle->setName($this->_cycle->getName());
     $cycle->setStart('yesterday');
     $cycle->setEnd('next year');
     $em->persist($cycle);
     $newApplication->setCycle($cycle);
     foreach ($this->_application->getApplicationPages() as $applicationPage) {
         $newPage = $this->copyPage($em, $applicationPage->getPage());
         $newApplicationPage = new \Jazzee\Entity\ApplicationPage();
         $newApplicationPage->setApplication($newApplication);
         $newApplicationPage->setPage($newPage);
         $newApplicationPage->setWeight($applicationPage->getWeight());
         $newApplicationPage->setKind($applicationPage->getKind());
         $newApplicationPage->setTitle($applicationPage->getTitle());
         $newApplicationPage->setMin($applicationPage->getMin());
         $newApplicationPage->setMax($applicationPage->getMax());
         $newApplicationPage->setInstructions($applicationPage->getInstructions());
         $newApplicationPage->setLeadingText($applicationPage->getLeadingText());
         $newApplicationPage->setTrailingText($applicationPage->getTrailingText());
         if ($applicationPage->isRequired()) {
             $newApplicationPage->required();
         } else {
             $newApplicationPage->optional();
         }
         if ($applicationPage->showAnswerStatus()) {
             $newApplicationPage->showAnswerStatus();
         } else {
             $newApplicationPage->hideAnswerStatus();
         }
         $em->persist($newApplicationPage);
     }
     $em->persist($newApplication);
     $newRole = new \Jazzee\Entity\Role();
     $newRole->setName('Preview Access');
     $newRole->notGlobal();
     $newRole->setProgram($program);
     foreach ($adminRole->getActions() as $action) {
         $newAction = new \Jazzee\Entity\RoleAction();
         $newAction->setRole($newRole);
         $newAction->setAction($action->getAction());
         $newAction->setController($action->getController());
         $em->persist($newAction);
     }
     $em->persist($newRole);
     $user = new \Jazzee\Entity\User();
     $user->setUniqueName('previewuser');
     $user->activate();
     $user->setEmail('*****@*****.**');
     $user->setFirstName('Preview');
     $user->setLastName('Application User');
     $user->addRole($newRole);
     $user->setDefaultCycle($cycle);
     $user->setDefaultProgram($program);
     $em->persist($user);
     foreach ($this->_em->getRepository('\\Jazzee\\Entity\\Template')->findByApplication($this->_application) as $template) {
         $newTemplate = new \Jazzee\Entity\Template($template->getType());
         $newTemplate->setApplication($newApplication);
         $newTemplate->setText($template->getText());
         $newTemplate->setTitle($template->getTitle());
         $em->persist($newTemplate);
     }
     $em->flush();
     return $newApplication;
 }
 /**
  * Setup the current application and cycle
  */
 public function actionIndex()
 {
     $form = new \Foundation\Form();
     $form->setCSRFToken($this->getCSRFToken());
     $form->setAction($this->path("setup/importapplication"));
     $field = $form->newField();
     $field->setLegend('Import Application');
     $element = $field->newElement('FileInput', 'file');
     $element->setLabel('XML Configuration');
     $element->addValidator(new \Foundation\Form\Validator\NotEmpty($element));
     $element->addFilter(new \Foundation\Form\Filter\Blob($element));
     $form->newButton('submit', 'Import');
     if ($input = $form->processInput($this->post)) {
         $xml = simplexml_load_string($input->get('file'));
         if (!$this->_application) {
             $this->_application = new \Jazzee\Entity\Application();
             $this->_application->setProgram($this->_program);
             $this->_application->setCycle($this->_cycle);
         }
         if ($this->_application->isPublished()) {
             $this->addMessage('error', 'This application is already published.  No changes can be made.');
             $this->redirectPath('setup/importapplication');
         }
         $pages = $this->_application->getApplicationPages();
         if (count($pages)) {
             $this->addMessage('error', 'This application already has pages.  You cannot import a configuration for an application with pages.');
             $this->redirectPath('setup/importapplication');
         }
         $preferences = $xml->xpath('/response/application/preferences');
         $arr = array();
         foreach ($preferences[0]->children() as $element) {
             $arr[$element->getName()] = (string) $element;
         }
         $this->_application->setContactName($arr['contactName']);
         $this->_application->setContactEmail($arr['contactEmail']);
         $this->_application->setWelcome(html_entity_decode($arr['welcome']));
         $this->_application->setOpen($arr['open']);
         $this->_application->setClose($arr['close']);
         $this->_application->setBegin($arr['begin']);
         $this->_application->setStatusIncompleteText($arr['statusIncompleteText']);
         $this->_application->setStatusNoDecisionText($arr['statusNoDecisionText']);
         $this->_application->setStatusAdmitText($arr['statusAdmitText']);
         $this->_application->setStatusDenyText($arr['statusDenyText']);
         $this->_application->setStatusAcceptText($arr['statusAcceptText']);
         $this->_application->setStatusDeclineText($arr['statusDeclineText']);
         if ($arr['visible'] == '1') {
             $this->_application->visible();
         }
         if ($arr['byinvitationonly'] == '1') {
             $this->_application->byInvitationOnly();
         } else {
             $this->_application->notByInvitationOnly();
         }
         if (array_key_exists('externalIdValidationExpression', $arr) and !empty($arr['externalIdValidationExpression'])) {
             $this->_application->setExternalIdValidationExpression($arr['externalIdValidationExpression']);
         }
         foreach ($xml->xpath('/response/application/preferences/templates/template') as $templates) {
             $arr2 = array();
             foreach ($templates[0]->children() as $element) {
                 $arr2[$element->getName()] = (string) $element;
             }
             $template = new \Jazzee\Entity\Template($arr2['type']);
             $template->setApplication($this->_application);
             $template->setTitle($arr2['title']);
             $template->setText($arr2['text']);
             $this->_em->persist($template);
         }
         foreach ($xml->xpath('/response/application/pages/page') as $element) {
             $attributes = $element->attributes();
             $page = $this->addPageFromXml($element);
             $applicationPage = new \Jazzee\Entity\ApplicationPage();
             $applicationPage->setApplication($this->_application);
             $applicationPage->setPage($page);
             $applicationPage->setKind((string) $attributes['kind']);
             $applicationPage->setName((string) $attributes['name']);
             $applicationPage->setTitle(html_entity_decode((string) $attributes['title']));
             $applicationPage->setMin((string) $attributes['min']);
             $applicationPage->setMax((string) $attributes['max']);
             if ((string) $attributes['required']) {
                 $applicationPage->required();
             } else {
                 $applicationPage->optional();
             }
             if ((string) $attributes['answerStatusDisplay']) {
                 $applicationPage->showAnswerStatus();
             } else {
                 $applicationPage->hideAnswerStatus();
             }
             $eattr = $element->xpath('instructions');
             $applicationPage->setInstructions((string) $eattr[0]);
             $eattr = $element->xpath('leadingText');
             $applicationPage->setLeadingText((string) $eattr[0]);
             $eattr = $element->xpath('trailingText');
             $applicationPage->setTrailingText((string) $eattr[0]);
             $applicationPage->setWeight((string) $attributes['weight']);
             $this->_em->persist($applicationPage);
         }
         $this->_em->persist($this->_application);
         $this->addMessage('success', 'Application imported successfully');
         unset($this->_store->AdminControllerGetNavigation);
     }
     $this->setVar('form', $form);
 }