/** * Initial form is for school search */ protected function makeForm() { $form = new \Foundation\Form(); $form->setAction($this->_controller->getActionPath()); $field = $form->newField(); $field->setLegend($this->_applicationPage->getTitle()); $field->setInstructions($this->_applicationPage->getInstructions()); $element = $field->newElement('TextInput', 'schoolSearch'); $element->setLabel('Search for School'); $element->addValidator(new \Foundation\Form\Validator\NotEmpty($element)); $form->newButton('submit', 'Search'); $form->newHiddenElement('level', 'search'); $form->getElementByName('submit')->setValue('Search'); return $form; }
public function testGetElementByName() { $form = new \Foundation\Form(); $name = 'elementName' . uniqid(); $element = $this->getMock('\\Foundation\\Form\\Element'); $element->expects($this->any())->method('getName')->will($this->returnValue($name)); $field = $this->getMockBuilder('\\Foundation\\Form\\Field')->disableOriginalConstructor()->getMock(); $field->expects($this->any())->method('getElements')->will($this->returnValue(array($name => $element))); $form->addField($field); $this->assertSame($element, $form->getElementByName($name)); $this->assertFalse($form->getElementByName('test')); }
/** * List all the pending payments in the system */ public function actionIndex() { $this->setLayoutVar('pageTitle', 'Payment Report'); $form = new \Foundation\Form(); $form->setCSRFToken($this->getCSRFToken()); $form->setAction($this->path('payments/report')); $field = $form->newField(); $field->setLegend('Search'); $element = $field->newElement('CheckboxList', 'types'); $element->setLabel('Payment Type'); $element->addValidator(new \Foundation\Form\Validator\NotEmpty($element)); $paymentTypes = array(); foreach ($this->_em->getRepository('Jazzee\\Entity\\PaymentType')->findWithPayment() as $type) { $paymentTypes[$type->getId()] = $type; } foreach ($paymentTypes as $type) { $element->newItem($type->getId(), $type->getName()); } $element = $field->newElement('DateInput', 'from'); $element->setLabel('From'); $element = $field->newElement('DateInput', 'to'); $element->setLabel('To'); $element->addValidator(new \Foundation\Form\Validator\DateAfterElement($element, 'from')); $element = $field->newElement('SelectList', 'program'); $element->setLabel('Program'); $element->newItem(null, ''); $programs = array(); foreach ($this->_em->getRepository('\\Jazzee\\Entity\\Program')->findBy(array('isExpired' => false), array('name' => 'ASC')) as $program) { $programs[$program->getId()] = $program; } foreach ($programs as $program) { $element->newItem($program->getId(), $program->getName()); } $element = $field->newElement('SelectList', 'cycle'); $element->setLabel('Cycle'); $element->newItem(null, ''); $cycles = array(); foreach ($this->_em->getRepository('\\Jazzee\\Entity\\Cycle')->findAll() as $cycle) { $cycles[$cycle->getId()] = $cycle; } foreach ($cycles as $cycle) { $element->newItem($cycle->getId(), $cycle->getName()); } $payments = array(); $form->newButton('submit', 'Search'); if (empty($this->post)) { $from = new \DateTime('midnight yesterday'); $to = new \DateTime('now'); $payments = $this->_em->getRepository('\\Jazzee\\Entity\\Payment')->findByStatusArray(\Jazzee\Entity\Payment::SETTLED, array(), $from, $to); $this->setVar('resultsDescription', ''); $description = sprintf('%s payments since midnight yesterday', count($payments)); $this->setVar('searchResultsDescription', $description); $form->getElementByName('types')->setValue(array_keys($paymentTypes)); } else { if ($input = $form->processInput($this->post)) { set_time_limit(120); $types = array(); foreach ($input->get('types') as $id) { $types[] = $paymentTypes[$id]; } $program = $input->get('program') ? $programs[$input->get('program')] : null; $cycle = $input->get('cycle') ? $cycles[$input->get('cycle')] : null; $from = $input->get('from') ? new \DateTime($input->get('from')) : null; $to = $input->get('to') ? new \DateTime($input->get('to')) : null; $payments = $this->_em->getRepository('\\Jazzee\\Entity\\Payment')->findByStatusArray(\Jazzee\Entity\Payment::SETTLED, $types, $from, $to, $program, $cycle); // $description = sprintf('%s results from search', count($payments)); $this->setVar('searchResultsDescription', ''); } else { $this->setVar('searchResultsDescription', ''); } } foreach ($payments as &$payment) { $paymentType = $paymentTypes[$payment['type']['id']]->getJazzeePaymentType($this); $payment['notes'] = $paymentType->getPaymentNotesFromArray($payment); } $this->setVar('payments', $payments); $this->setVar('form', $form); }
/** * Change applicant password */ public function actionChangePassword() { $form = new \Foundation\Form(); $form->setCSRFToken($this->getCSRFToken()); $form->setAction($this->applyPath('account/changePassword')); $field = new \Foundation\Form\Field($form); $field->setLegend('Change Password'); $form->addField($field); $element = $field->newElement('PasswordInput', 'password'); $element->setLabel('Current Password'); $element->addValidator(new \Foundation\Form\Validator\NotEmpty($element)); $element = $field->newElement('PasswordInput', 'newpassword'); $element->setLabel('New Password'); $element->addValidator(new \Foundation\Form\Validator\NotEmpty($element)); $element = $field->newElement('PasswordInput', 'confirm'); $element->setLabel('Confirm Password'); $element->addValidator(new \Foundation\Form\Validator\NotEmpty($element)); $element->addValidator(new \Foundation\Form\Validator\SameAs($element, 'newpassword')); $form->newButton('submit', 'Change Password'); if ($input = $form->processInput($this->post)) { if ($this->_applicant->checkPassword($input->get('password'))) { $this->_applicant->setPassword($input->get('newpassword')); $this->_em->persist($this->_applicant); $this->addMessage('success', 'Your password was changed successfully.'); $this->redirectApplyPath('account'); } else { $form->getElementByName('password')->addMessage('Password Incorrect'); } } $this->setVar('form', $form); $this->loadView($this->controllerName . '/form'); }
/** * Bulk create applicants from a csv file */ public function actionBulk() { $form = new \Foundation\Form(); $form->setCSRFToken($this->getCSRFToken()); $form->setAction($this->path('applicants/create/bulk')); $field = $form->newField(); $field->setLegend('Create Applicants From File'); $element = $field->newElement('FileInput', 'file'); $element->setLabel('File'); $element->addValidator(new \Foundation\Form\Validator\NotEmpty($element)); $element->addFilter(new \Foundation\Form\Filter\CSVArray($element)); $element = $field->newElement('TextInput', 'notificationSubject'); $element->setLabel('Subject for Notification Email'); $element->setValue('New Application Account'); $element = $field->newElement('Textarea', 'notificationMessage'); $element->setLabel('Notification Email Message'); $element->setFormat('Leave this blank if you do not want to notify the applicant of their new account'); $notificationMessagereplacements = array('_Applicant_Name_', '_Deadline_', '_Link_', '_Email_', '_Password_'); $element->setInstructions('You can use these tokens in the text, they will be replaced automatically: <br />' . implode('</br />', $notificationMessagereplacements)); $element->setValue($this->_defaultEmail); $element = $field->newElement('DateInput', 'deadlineExtension'); $element->setLabel('Deadline'); $element->setFormat('If you wish to extend this applicants deadline past the application deadline enter it here.'); if ($this->_application->getClose()) { $element->addValidator(new \Foundation\Form\Validator\DateAfter($element, $this->_application->getClose()->format('c'))); } $form->newButton('submit', 'Upload File and create applicants'); if ($input = $form->processInput($this->post)) { $newApplicants = $input->get('file'); $first = $newApplicants[0]; $requiredHeaders = array('External ID', 'First Name', 'Middle Name', 'Last Name', 'Suffix', 'Email Address', 'Password'); $error = false; foreach ($requiredHeaders as $value) { if (!in_array($value, $first)) { $form->getElementByName('file')->addMessage("The uploaded file must contain a column '{$value}'"); $error = true; } } if (!$error) { $headers = array_shift($newApplicants); $byKey = array(); foreach ($newApplicants as $newApplicant) { $arr = array(); foreach ($headers as $key => $value) { $arr[$value] = $newApplicant[$key]; } $byKey[] = $arr; } $newApplicants = $byKey; $results = array(); foreach ($newApplicants as $newApplicant) { $result = array('messages' => array(), 'applicant' => null, 'plainTextPassword' => ''); $duplicate = $this->_em->getRepository('Jazzee\\Entity\\Applicant')->findOneByEmailAndApplication($newApplicant['Email Address'], $this->_application); if ($duplicate) { $result['status'] = 'duplicate'; $result['messages'][] = 'An applicant with that email address already exists.'; $result['applicant'] = $duplicate; } else { if (!empty($newApplicant['External ID']) and !$this->_application->validateExternalId($newApplicant['External ID'])) { $result['status'] = 'badExternalId'; $result['messages'][] = $newApplicant['External ID'] . ' is not a valid external ID for this program'; $result['applicantName'] = "{$newApplicant['First Name']} {$newApplicant['Last Name']}"; $result['applicantEmail'] = $newApplicant['Email Address']; } else { $result['status'] = 'success'; $applicant = new \Jazzee\Entity\Applicant(); $applicant->setApplication($this->_application); $applicant->setEmail($newApplicant['Email Address']); if ($newApplicant['Password']) { $applicant->setPassword($newApplicant['Password']); $plainTextPassword = $newApplicant['Password']; } else { $plainTextPassword = $applicant->generatePassword(); } $applicant->setFirstName($newApplicant['First Name']); $applicant->setMiddleName($newApplicant['Middle Name']); $applicant->setLastName($newApplicant['Last Name']); $applicant->setSuffix($newApplicant['Suffix']); $applicant->setExternalId($newApplicant['External ID']); if ($input->get('deadlineExtension')) { $applicant->setDeadlineExtension($input->get('deadlineExtension')); } $this->_em->persist($applicant); $result['applicant'] = $applicant; $result['plainTextPassword'] = $plainTextPassword; $result['messages'][] = 'Applicant Created Successfully'; if ($input->get('notificationMessage')) { $replace = array($applicant->getFullName(), $applicant->getDeadline() ? $applicant->getDeadline()->format('l F jS Y g:ia') : '', $this->absoluteApplyPath("apply/{$this->_application->getProgram()->getShortName()}/{$this->_application->getCycle()->getName()}/applicant/login"), $applicant->getEmail(), $plainTextPassword); $body = str_ireplace($notificationMessagereplacements, $replace, $input->get('notificationMessage')); $subject = $input->get('notificationSubject') ? $input->get('notificationSubject') : 'New Application Account'; $email = $this->newMailMessage(); $email->AddCustomHeader('X-Jazzee-Applicant-ID:' . $applicant->getId()); $email->AddAddress($applicant->getEmail(), $applicant->getFullName()); $email->setFrom($this->_application->getContactEmail(), $this->_application->getContactName()); $email->Subject = $subject; $email->Body = $body; $email->Send(); $thread = new \Jazzee\Entity\Thread(); $thread->setSubject($subject); $thread->setApplicant($applicant); $message = new \Jazzee\Entity\Message(); $message->setSender(\Jazzee\Entity\Message::PROGRAM); $message->setText(nl2br($body)); $message->read(); $thread->addMessage($message); $this->_em->persist($thread); $this->_em->persist($message); $result['messages'][] = 'New account email sent'; } } } $results[] = $result; } $this->setVar('results', $results); $this->_em->flush(); } } $this->setVar('form', $form); }