/** * Create a new pagetype */ public function actionNew() { $form = new \Foundation\Form(); $form->setCSRFToken($this->getCSRFToken()); $form->setAction($this->path('setup/roles/new')); $field = $form->newField(); $field->setLegend('New program role'); $element = $field->newElement('TextInput', 'name'); $element->setLabel('Role Name'); $element->addValidator(new \Foundation\Form\Validator\NotEmpty($element)); $element->addFilter(new \Foundation\Form\Filter\Safe($element)); $form->newButton('submit', 'Add Role'); $this->setVar('form', $form); if ($input = $form->processInput($this->post)) { $role = new \Jazzee\Entity\Role(); $role->notGLobal(); $role->setProgram($this->_program); $role->setName($input->get('name')); $this->_em->persist($role); $display = new \Jazzee\Entity\Display('role'); $display->setRole($role); $display->setApplication($this->_application); $display->setName($role->getName() . ' display'); foreach ($this->_user->getMaximumDisplayForApplication($this->_application)->listElements() as $userDisplayElement) { $displayElement = \Jazzee\Entity\DisplayElement::createFromDisplayElement($userDisplayElement, $this->_application); $display->addElement($displayElement); $this->getEntityManager()->persist($displayElement); } $this->_em->persist($display); $this->_em->flush(); $this->addMessage('success', "Role Saved Successfully"); $this->redirectPath('setup/roles'); } }
/** * 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; }