/** * @param \Symfony\Component\Console\Input\InputInterface $input * @param \Symfony\Component\Console\Output\OutputInterface $output */ protected function execute(\Symfony\Component\Console\Input\InputInterface $input, \Symfony\Component\Console\Output\OutputInterface $output) { $jazzeeConfiguration = new \Jazzee\Configuration(); if ($jazzeeConfiguration->getStatus() == 'PRODUCTION') { $output->write('<error>You cannot create a demo in production.</error>' . PHP_EOL); exit; } $programName = $input->getOption('programName') ? $input->getOption('programName') : 'Demo'; $shortName = $input->getOption('shortName') ? $input->getOption('shortName') : 'demo'; $entityManager = $this->getHelper('em')->getEntityManager(); if ($entityManager->getRepository('\\Jazzee\\Entity\\Program')->findBy(array('name' => $programName))) { $output->write("<error>A program named '{$programName}' already exists.</error>" . PHP_EOL); exit; } if ($entityManager->getRepository('\\Jazzee\\Entity\\Program')->findBy(array('shortName' => $shortName))) { $output->write("<error>A program with the shortname '{$shortName}' already exists.</error>" . PHP_EOL); exit; } if (!($cycle = $entityManager->getRepository('\\Jazzee\\Entity\\Cycle')->findOneBy(array('name' => 'demo')))) { $cycle = new \Jazzee\Entity\Cycle(); $cycle->setName('demo'); $cycle->setStart('today'); $cycle->setEnd('next year'); $entityManager->persist($cycle); } $program = new \Jazzee\Entity\Program(); $program->setName($programName); $program->setShortName($shortName); $entityManager->persist($program); $application = new \Jazzee\Entity\Application(); $application->setProgram($program); $application->setCycle($cycle); $application->setWelcome('THIS IS A DEMO APP.'); $application->visible(); $application->setOpen('yesterday'); $application->setClose('next year'); $application->publish(true); $entityManager->persist($application); $StandardPageType = $entityManager->getRepository('\\Jazzee\\Entity\\PageType')->findOneBy(array('class' => '\\Jazzee\\Page\\Standard')); $page = new \Jazzee\Entity\Page(); $page->setTitle('Optional Page'); $page->optional(); $page->setType($StandardPageType); $entityManager->persist($page); $count = 1; foreach ($entityManager->getRepository('\\Jazzee\\Entity\\ElementType')->findAll() as $type) { $element = $this->demoElement($type, $entityManager); $element->setTitle($type->getName()); $element->optional(); $element->setWeight($count); $page->addElement($element); $entityManager->persist($element); $count++; } $applicationPage = new \Jazzee\Entity\ApplicationPage(); $applicationPage->setApplication($application); $applicationPage->setPage($page); $applicationPage->setKind(\Jazzee\Entity\ApplicationPage::APPLICATION); $applicationPage->setWeight(1); $entityManager->persist($applicationPage); $page = new \Jazzee\Entity\Page(); $page->setTitle('Required Page'); $page->setType($StandardPageType); $entityManager->persist($page); $count = 1; foreach ($entityManager->getRepository('\\Jazzee\\Entity\\ElementType')->findAll() as $type) { $element = $this->demoElement($type, $entityManager); $element->setTitle($type->getName()); $element->required(); $element->setWeight($count); $page->addElement($element); $entityManager->persist($element); $count++; } $applicationPage = new \Jazzee\Entity\ApplicationPage(); $applicationPage->setApplication($application); $applicationPage->setPage($page); $applicationPage->setKind(\Jazzee\Entity\ApplicationPage::APPLICATION); $applicationPage->setWeight(2); $entityManager->persist($applicationPage); $entityManager->flush(); $output->write("<info>Demo program {$programName} created successfully.</info>" . PHP_EOL); }
/** * Create a new cycle */ public function actionNew() { $form = new \Foundation\Form(); $form->setCSRFToken($this->getCSRFToken()); $form->setAction($this->path("manage/cycles/new")); $field = $form->newField(); $field->setLegend('New cycle'); $element = $field->newElement('TextInput', 'name'); $element->setLabel('Cycle Name'); $element->addValidator(new \Foundation\Form\Validator\NotEmpty($element)); $element->addFilter(new \Foundation\Form\Filter\UrlSafe($element)); $element->addFilter(new \Foundation\Form\Filter\Safe($element)); $element = $field->newElement('DateInput', 'start'); $element->setLabel('Start Date'); $element->addValidator(new \Foundation\Form\Validator\DateBeforeElement($element, 'end')); $element->addValidator(new \Foundation\Form\Validator\NotEmpty($element)); $element = $field->newElement('DateInput', 'end'); $element->setLabel('End Date'); $element->addValidator(new \Foundation\Form\Validator\NotEmpty($element)); $form->newButton('submit', 'Save Changes'); $this->setVar('form', $form); if ($input = $form->processInput($this->post)) { if (count($this->_em->getRepository('\\Jazzee\\Entity\\Cycle')->findBy(array('name' => $input->get('name'))))) { $this->addMessage('error', "A cycle with that name already exists"); } else { $cycle = new \Jazzee\Entity\Cycle(); $cycle->setName($input->get('name')); $cycle->setStart($input->get('start')); $cycle->setEnd($input->get('end')); $this->_em->persist($cycle); $this->_em->flush(); $this->addMessage('success', "New Cycle Saved"); $this->redirectPath("manage/cycles/edit/{$cycle->getId()}"); } } }
/** * 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; }