Beispiel #1
0
 /**
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  * @SuppressWarnings(PHPMD.ExitExpression)
  */
 protected function execute(\Symfony\Component\Console\Input\InputInterface $input, \Symfony\Component\Console\Output\OutputInterface $output)
 {
     $entityManager = $this->getHelper('em')->getEntityManager();
     $output->write('<comment>Installing default components...</comment>' . PHP_EOL);
     $pageTypes = array('\\Jazzee\\Page\\Branching' => 'Branching', '\\Jazzee\\Page\\ETSMatch' => 'ETS Score Matching', '\\Jazzee\\Page\\Education' => 'Education', '\\Jazzee\\Page\\ExternalId' => 'External ID', '\\Jazzee\\Page\\Lock' => 'Lock Application', '\\Jazzee\\Page\\Payment' => 'Payment', '\\Jazzee\\Page\\QASAddress' => 'Address Verification QAS', '\\Jazzee\\Page\\Recommenders' => 'Recommenders', '\\Jazzee\\Page\\Standard' => 'Standard', '\\Jazzee\\Page\\Text' => 'Plain Text');
     foreach ($pageTypes as $class => $name) {
         $pageType = new \Jazzee\Entity\PageType();
         $pageType->setName($name);
         $pageType->setClass($class);
         $entityManager->persist($pageType);
     }
     $entityManager->flush();
     $output->write('<info>Default Page types added</info>' . PHP_EOL);
     $elementTypes = array('\\Jazzee\\Element\\CheckboxList' => 'Checkboxes', '\\Jazzee\\Element\\Date' => 'Date', '\\Jazzee\\Element\\EmailAddress' => 'Email Address', '\\Jazzee\\Element\\EncryptedTextInput' => 'Encrypted Text Input', '\\Jazzee\\Element\\PDFFileInput' => 'PDF Upload', '\\Jazzee\\Element\\Phonenumber' => 'Phone Number', '\\Jazzee\\Element\\RadioList' => 'Radio Buttons', '\\Jazzee\\Element\\RankingList' => 'Rank Order Dropdown', '\\Jazzee\\Element\\SearchList' => 'Search', '\\Jazzee\\Element\\SelectList' => 'Dropdown List', '\\Jazzee\\Element\\ShortDate' => 'Short Date', '\\Jazzee\\Element\\TextInput' => 'Single Line Text', '\\Jazzee\\Element\\Textarea' => 'Text Area', '\\Jazzee\\Element\\USSocialSecurityNumber' => 'US Social Security Number');
     foreach ($elementTypes as $class => $name) {
         $elementType = new \Jazzee\Entity\ElementType();
         $elementType->setName($name);
         $elementType->setClass($class);
         $entityManager->persist($elementType);
     }
     $entityManager->flush();
     $output->write('<info>Default Element types added</info>' . PHP_EOL);
     $role = new \Jazzee\Entity\Role();
     $role->makeGlobal();
     $role->setName('Administrator');
     $entityManager->persist($role);
     \Foundation\VC\Config::addControllerPath(__DIR__ . '/../../controllers/');
     foreach (array('admin', 'applicants', 'manage', 'scores', 'setup') as $path) {
         $path = \realpath(__DIR__ . '/../../controllers/' . $path);
         \Foundation\VC\Config::addControllerPath($path . '/');
         //scan the directory but drop the relative paths
         foreach (array_diff(scandir($path), array('.', '..')) as $fileName) {
             $controller = basename($fileName, '.php');
             \Foundation\VC\Config::includeController($controller);
             $class = \Foundation\VC\Config::getControllerClassName($controller);
             foreach (get_class_methods($class) as $method) {
                 if (substr($method, 0, 6) == 'action') {
                     $constant = 'ACTION_' . strtoupper(substr($method, 6));
                     if (defined("{$class}::{$constant}")) {
                         $roleAction = new \Jazzee\Entity\RoleAction();
                         $roleAction->setController($controller);
                         $roleAction->setAction(substr($method, 6));
                         $roleAction->setRole($role);
                         $entityManager->persist($roleAction);
                     }
                 }
             }
         }
     }
     $entityManager->flush();
     $output->write("<info>Administrator role created</info>" . PHP_EOL);
 }
Beispiel #2
0
 /**
  * Copy a role
  * @param integer $oldRoleID
  */
 public function actionCopy($oldRoleID)
 {
     if ($oldRole = $this->_em->getRepository('\\Jazzee\\Entity\\Role')->findOneBy(array('id' => $oldRoleID, 'program' => $this->_program->getId()))) {
         $form = new \Foundation\Form();
         $form->setCSRFToken($this->getCSRFToken());
         $form->setAction($this->path('setup/roles/copy/' . $oldRole->getId()));
         $field = $form->newField();
         $field->setLegend('Copy ' . $oldRole->getName() . ' role');
         $element = $field->newElement('TextInput', 'name');
         $element->setLabel('New Role Name');
         $element->addValidator(new \Foundation\Form\Validator\NotEmpty($element));
         $element->addFilter(new \Foundation\Form\Filter\Safe($element));
         $element->setValue($oldRole->getName());
         $menus = $this->getControllerActions();
         ksort($menus);
         foreach ($menus as $menu => $list) {
             foreach ($list as $controller) {
                 $element = $field->newElement('CheckboxList', $controller['name']);
                 $element->setLabel($menu . ' ' . $controller['title'] . ' actions');
                 foreach ($controller['actions'] as $actionName => $actionTitle) {
                     $element->newItem($actionName, $actionTitle);
                 }
                 $values = array();
                 foreach ($oldRole->getActions() as $action) {
                     if ($action->getController() == $controller['name']) {
                         $values[] = $action->getAction();
                     }
                 }
                 $element->setValue($values);
             }
         }
         $form->newButton('submit', 'Copy Role');
         $this->setVar('form', $form);
         if ($input = $form->processInput($this->post)) {
             $newRole = new \Jazzee\Entity\Role();
             $newRole->notGlobal();
             $newRole->setProgram($this->_program);
             $newRole->setName($input->get('name'));
             foreach ($menus as $menu => $list) {
                 foreach ($list as $controller) {
                     $actions = $input->get($controller['name']);
                     if (!empty($actions)) {
                         foreach ($actions as $actionName) {
                             $action = new \Jazzee\Entity\RoleAction();
                             $action->setController($controller['name']);
                             $action->setAction($actionName);
                             $action->setRole($newRole);
                             $this->_em->persist($action);
                         }
                     }
                 }
             }
             $this->_em->persist($newRole);
             if ($oldDisplay = $oldRole->getDisplayForApplication($this->_application)) {
                 $display = new \Jazzee\Entity\Display('role');
                 $display->setRole($newRole);
                 $display->setApplication($this->_application);
                 $display->setName($newRole->getName() . ' display');
                 foreach ($oldDisplay->listElements() as $userDisplayElement) {
                     $displayElement = \Jazzee\Entity\DisplayElement::createFromDisplayElement($userDisplayElement, $this->_application);
                     $display->addElement($displayElement);
                     $this->_em->persist($displayElement);
                 }
                 $this->_em->persist($display);
             }
             $this->addMessage('success', "Role Copied Successfully");
             $this->redirectPath('setup/roles');
         }
     } else {
         $this->addMessage('error', "Error: Role #{$oldRoleID} does not exist.");
     }
 }
 /**
  * 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;
 }
Beispiel #4
0
 /**
  * Apply a role template
  * Use a global role as a template to apply accross multipe programs
  * @param integer $roleId
  */
 public function actionApplyTemplate($roleId)
 {
     if ($role = $this->_em->getRepository('\\Jazzee\\Entity\\Role')->findOneBy(array('id' => $roleId, 'isGlobal' => true))) {
         $form = new \Foundation\Form();
         $form->setCSRFToken($this->getCSRFToken());
         $form->setAction($this->path('manage/roles/applytemplate/' . $role->getId()));
         $field = $form->newField();
         $field->setLegend('Apply ' . $role->getName() . ' to program roles');
         $programs = $this->_em->getRepository('\\Jazzee\\Entity\\Program')->findBy(array('isExpired' => false), array('name' => 'ASC'));
         $userPrograms = $this->_user->getPrograms();
         //keep a list to use if we post data
         $list = array();
         foreach ($programs as $program) {
             $list['program' . $program->getId()] = array();
             $element = $field->newElement('CheckboxList', 'program' . $program->getId());
             $element->setLabel($program->getName() . ' roles');
             if ($this->checkIsAllowed('admin_changeprogram', 'anyProgram') or in_array($program->getId(), $userPrograms)) {
                 $programRoles = $this->_em->getRepository('\\Jazzee\\Entity\\Role')->findBy(array('isGlobal' => false, 'program' => $program->getId()), array('name' => 'ASC'));
                 foreach ($programRoles as $programRole) {
                     $element->newItem('programrole' . $programRole->getId(), $programRole->getName());
                     $list['program' . $program->getId()]['programrole' . $programRole->getId()] = $programRole->getId();
                 }
             }
         }
         $form->newButton('submit', 'Apply Templates');
         $this->setVar('form', $form);
         if ($input = $form->processInput($this->post)) {
             foreach ($list as $programElementId => $programArr) {
                 foreach ($programArr as $programRoleElementId => $roleId) {
                     $setRoles = $input->get($programElementId);
                     if (!is_null($setRoles) and in_array($programRoleElementId, $setRoles)) {
                         $programRole = $this->_em->getRepository('\\Jazzee\\Entity\\Role')->findOneBy(array('id' => $roleId, 'isGlobal' => false, 'program' => substr($programElementId, 7)));
                         if (!$programRole) {
                             throw new \Jazzee\Exception('Bad role or program');
                         }
                         foreach ($programRole->getActions() as $action) {
                             $this->_em->remove($action);
                             $programRole->getActions()->removeElement($action);
                         }
                         foreach ($role->getActions() as $globalAction) {
                             $programAction = new \Jazzee\Entity\RoleAction();
                             $programAction->setController($globalAction->getController());
                             $programAction->setAction($globalAction->getAction());
                             $programAction->setRole($programRole);
                             $this->_em->persist($programAction);
                         }
                     }
                 }
             }
             $this->addMessage('success', "Template Applied Successfully");
             $this->redirectPath('manage/roles');
         }
     } else {
         $this->addMessage('error', "Error: Role #{$roleId} does not exist.");
     }
 }