public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $this->options = $options;
     $this->institution = $builder->getData();
     if (!$this->institution instanceof Institution) {
         throw InstitutionFormException::nonInstitutionFormData(__CLASS__, $this->institution);
     }
     $this->_add($builder, 'name', 'text');
     $this->_add($builder, 'description', 'textarea', array('required' => false));
     $this->_add($builder, 'medicalProviderGroups', 'collection', array('type' => 'medicalProviderGroup_list', 'allow_add' => true, 'allow_delete' => true, 'options' => array('required' => false)));
     $this->_add($builder, 'country', FancyCountryFieldType::NAME, array('label' => 'Country', 'error_bubbling' => false, 'attr' => array('placeholder' => 'Type or select your Country')));
     $this->_add($builder, 'city', GlobalCityListType::NAME, array('attr' => array('placeholder' => 'Type or select your City'), 'label' => 'City', 'error_bubbling' => false));
     $this->_add($builder, 'zipCode', 'text', array('label' => 'Zip / Postal Code'));
     $this->_add($builder, 'state', 'state_list', array('label' => 'State/Province', 'attr' => array('placeholder' => 'Type or select your State/Province')));
     $this->_add($builder, 'contactEmail', 'text', array('label' => 'Email Address ', 'required' => false));
     $this->_add($builder, 'address1', 'detailed_street_address', array('label' => 'Hospital Address'));
     $this->_add($builder, 'addressHint', 'text', array('label' => 'Helpful hint for getting there?', 'required' => false));
     $this->_add($builder, 'contactDetails', 'collection', array('type' => 'simple_contact_detail'));
     $this->_add($builder, 'websites', 'website_custom_field', array('label' => 'Website', 'required' => false));
     $this->_add($builder, 'socialMediaSites', 'social_media_sites_custom_field');
     $this->_add($builder, 'services', 'institutionServices_list', array('mapped' => false, 'centers' => false));
     $this->_add($builder, 'awards', 'institutionGlobalAwards_list', array('mapped' => false, 'centers' => false));
     $this->_add($builder, 'logo', new InstitutionMediaFileType($this->institution->getLogo()));
     $this->_add($builder, 'featuredMedia', new InstitutionMediaFileType($this->institution->getFeaturedMedia()));
     $this->_add($builder, 'coordinates', 'hidden');
     $this->_add($builder, 'type', 'choice', array('label' => 'Institution Type', 'empty_value' => false, 'multiple' => false, 'choices' => InstitutionTypes::getFormChoices()));
 }
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $this->options = $options;
     $institution = $this->options['data'];
     $status = InstitutionStatus::getBitValueLabels();
     if (!$institution instanceof Institution) {
         throw new \Exception(__CLASS__ . ' expects data to be instance of Institution');
     }
     $imcProperty = new InstitutionMedicalCenterProperty();
     $this->_add($builder, 'name', 'text');
     $this->_add($builder, 'status', 'choice', array('label' => 'Status', 'choices' => $status));
     $this->_add($builder, 'description', 'textarea', array('required' => false));
     $this->_add($builder, 'medicalProviderGroups', 'collection', array('type' => 'medicalProviderGroup_list', 'allow_add' => true, 'allow_delete' => true, 'options' => array('required' => false)));
     $this->_add($builder, 'country', FancyCountryFieldType::NAME, array('label' => 'Country', 'error_bubbling' => false));
     $this->_add($builder, 'city', GlobalCityListType::NAME, array('label' => 'City', 'error_bubbling' => false));
     $this->_add($builder, 'zipCode', 'text', array('label' => 'Zip / Postal Code'));
     $this->_add($builder, 'state', 'state_list', array('error_bubbling' => false, 'label' => 'State / Province'));
     $this->_add($builder, 'contactEmail', 'text', array('label' => 'Email Address ', 'required' => false));
     $this->_add($builder, 'address1', 'detailed_street_address', array('label' => 'Hospital Address'));
     $this->_add($builder, 'addressHint', 'text', array('label' => 'Helpful hint for getting there?', 'required' => false));
     $this->_add($builder, 'contactDetails', 'collection', array('type' => 'simple_contact_detail'));
     $this->_add($builder, 'websites', 'website_custom_field', array('label' => 'Website', 'required' => false));
     $this->_add($builder, 'socialMediaSites', 'social_media_sites_custom_field');
     $this->_add($builder, 'logo', new InstitutionMediaFileType($institution->getLogo()));
     $this->_add($builder, 'featuredMedia', new InstitutionMediaFileType($institution->getFeaturedMedia()));
     $this->_add($builder, 'coordinates', 'hidden');
     $this->_add($builder, 'type', 'choice', array('label' => 'Institution Type', 'empty_value' => false, 'multiple' => false, 'choices' => InstitutionTypes::getFormChoices()));
     $this->_add($builder, 'status', 'choice', array('label' => 'Status', 'choices' => $status));
 }
 function setTypeFilterOption()
 {
     $typeLabel = InstitutionTypes::getLabelList();
     $options = array(ListFilter::FILTER_KEY_ALL => ListFilter::FILTER_LABEL_ALL);
     $options[InstitutionTypes::MULTIPLE_CENTER] = $typeLabel[InstitutionTypes::MULTIPLE_CENTER];
     //$options[InstitutionTypes::MEDICAL_TOURISM_FACILITATOR] = $typeLabel[InstitutionTypes::MEDICAL_TOURISM_FACILITATOR];
     $options[InstitutionTypes::SINGLE_CENTER] = $typeLabel[InstitutionTypes::SINGLE_CENTER];
     $this->filterOptions['type'] = array('label' => 'Institution Types', 'selected' => $this->queryParams['type'], 'options' => $options);
 }
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $institutionUser = $options['data'];
     if (!$institutionUser instanceof InstitutionUser) {
         throw new \Exception('Institution User sign up form expects an InstitutionUser for data');
     }
     $builder->add('firstName', 'text', array('error_bubbling' => false, 'constraints' => array(new NotBlank(array('message' => 'Please provide your first name. ')))))->add('lastName', 'text', array('error_bubbling' => false, 'constraints' => array(new NotBlank(array('message' => 'Please provide your last name.')))))->add('jobTitle', 'text', array('required' => false, 'label' => 'Job Title'))->add('contactDetails', 'collection', array('error_bubbling' => false, 'type' => 'simple_contact_detail', 'constraints' => array(new NotBlank())));
     if ($options['institution_types']) {
         $builder->add('type', 'choice', array('property_path' => false, 'expanded' => true, 'multiple' => false, 'choices' => InstitutionTypes::getFormChoices(), 'error_bubbling' => false, 'constraints' => array(new NotBlank(array('message' => 'Please choose at least one type of Institution')))));
     }
     if ($options['include_terms_agreement']) {
         $builder->add('agree_to_terms', 'checkbox', array('virtual' => true, 'error_bubbling' => false, 'constraints' => array(new NotBlank(array('message' => 'You must agree to the Terms of Use')))));
     }
     if ($options['signup_fields']) {
         $builder->add('email', 'email', array('error_bubbling' => false, 'constraints' => array(new ValidAccountEmail(array('currentAccountEmail' => $institutionUser->getEmail(), 'field' => 'email')), new NotBlank(array('message' => 'Please provide your email address. ')))));
         $builder->add('confirm_email', 'email', array('label' => 'Confirm Email', 'virtual' => true, 'constraints' => array(new EqualFieldValue(array('field' => 'email', 'message' => 'Email address do not match')))));
         $builder->add('password', 'password', array('label' => 'Password', 'error_bubbling' => false, 'constraints' => array(new NotBlank(array('message' => 'Password is required.')), new MinLength(array('limit' => 6, 'message' => 'Password is too short. Please enter at least 6 characters.')))));
         $builder->add('confirm_password', 'password', array('label' => 'Re-type password', 'virtual' => true, 'error_bubbling' => false, 'constraints' => array(new EqualFieldValue(array('field' => 'password', 'message' => 'Passwords do not match')))));
     }
 }
 /**
  * Add new User and Institution
  * @author Chaztine Blance
  */
 public function addAction(Request $request)
 {
     $factory = $this->get('services.institution.factory');
     $institution = $factory->createInstance();
     $institutionUser = new InstitutionUser();
     $this->get('services.contact_detail')->initializeContactDetails($institutionUser, array(ContactDetailTypes::PHONE, ContactDetailTypes::MOBILE));
     $form = $this->createForm(new InstitutionUserSignUpFormType(), $institutionUser, array('include_terms_agreement' => false));
     if ($request->isMethod('POST')) {
         $form->bind($request);
         if ($form->isValid()) {
             $postData = $request->get('institutionUserSignUp');
             $institutionUser = $form->getData();
             // initialize required database fields
             $institution->setName(uniqid());
             $institution->setAddress1('');
             $institution->setContactEmail('');
             $institution->setContactNumber('');
             $institution->setDescription('');
             $institution->setLogo(null);
             $institution->setCoordinates('');
             $institution->setType(trim($postData['type']));
             /* FIX ME! */
             $institution->setWebsites('');
             $institution->setStatus(InstitutionStatus::getBitValueForInactiveStatus());
             $institution->setZipCode('');
             $institution->setSignupStepStatus(0);
             // Temporary Code to mark a newly added institution as added internally.
             // Added By: Adelbert Silla
             $institution->setIsFromInternalAdmin(1);
             $factory->save($institution);
             // create Institution user
             $institutionUser = new InstitutionUser();
             $institutionUser->setEmail($form->get('email')->getData());
             $institutionUser->setFirstName($institution->getName());
             $institutionUser->setLastName('Admin');
             $institutionUser->setPassword(SecurityHelper::hash_sha256($form->get('password')->getData()));
             $institutionUser->setInstitution($institution);
             $institutionUser->setStatus(SiteUser::STATUS_ACTIVE);
             $this->get('services.contact_detail')->removeInvalidContactDetails($institutionUser);
             //                     var_dump($institutionUser->getContactDetails()); exit;
             // dispatch event
             $this->get('event_dispatcher')->dispatch(InstitutionBundleEvents::ON_ADD_INSTITUTION, $this->get('events.factory')->create(InstitutionBundleEvents::ON_ADD_INSTITUTION, $institution, array('institutionUser' => $institutionUser)));
             return $this->redirect($this->generateUrl('admin_institution_add_details', array('institutionId' => $institution->getId())));
         } else {
         }
     }
     return $this->render('AdminBundle:Institution:add.html.twig', array('form' => $form->createView(), 'institutionTypes' => InstitutionTypes::getFormChoices()));
 }
 /**
  * Sign up page handler
  *
  * @param Request $request
  */
 public function signUpAction(Request $request)
 {
     $error_message = '';
     $success = false;
     // checking for security context here does not work since this is not firewalled
     // TODO: find a better approach
     //         if ($this->get('session')->get('institutionId')) {
     // redirect to dashboard if there is an active session
     //return $this->redirect($this->generateUrl('institution_homepage'));
     //         }
     $factory = $this->get('services.institution.factory');
     $institution = $factory->createInstance();
     $institutionUser = new InstitutionUser();
     $this->get('services.contact_detail')->initializeContactDetails($institutionUser, array(ContactDetailTypes::PHONE, ContactDetailTypes::MOBILE));
     $form = $this->createForm(new InstitutionUserSignUpFormType(), $institutionUser);
     if ($request->isMethod('POST')) {
         $form->bind($request);
         if ($form->isValid()) {
             $postData = $request->get('institutionUserSignUp');
             $institutionUser = $form->getData();
             // initialize required database fields
             $institution->setName(uniqid());
             $institution->setAddress1('');
             $institution->setContactEmail('');
             $institution->setContactNumber('');
             $institution->setDescription('');
             $institution->setCoordinates('');
             $institution->setType(trim($postData['type']));
             /* FIX ME! */
             $institution->setState(null);
             $institution->setWebsites('');
             $institution->setStatus(InstitutionStatus::getBitValueForInactiveStatus());
             $institution->setZipCode('');
             $institution->setSignupStepStatus(1);
             // this is always the first step
             $factory->save($institution);
             $institutionUserService = $this->get('services.institution_user');
             // create Institution user
             $institutionUser->setEmail($form->get('email')->getData());
             $institutionUser->setFirstName($form->get('firstName')->getData());
             $institutionUser->setLastName($form->get('lastName')->getData());
             $institutionUser->setContactNumber('');
             $institutionUser->setPassword($institutionUserService->encryptPassword($form->get('password')->getData()));
             $institutionUser->setJobTitle($form->get('jobTitle')->getData());
             $institutionUser->setInstitution($institution);
             $institutionUser->setStatus(SiteUser::STATUS_ACTIVE);
             $this->get('services.contact_detail')->removeInvalidContactDetails($institutionUser);
             // dispatch event
             $this->get('event_dispatcher')->dispatch(InstitutionBundleEvents::ON_ADD_INSTITUTION, $this->get('events.factory')->create(InstitutionBundleEvents::ON_ADD_INSTITUTION, $institution, array('institutionUser' => $institutionUser)));
             // auto login
             $roles = $institutionUserService->getUserRolesForSecurityToken($institutionUser);
             $securityToken = new UsernamePasswordToken($institutionUser, $institutionUser->getPassword(), 'institution_secured_area', $roles);
             $this->get('session')->set('_security_institution_secured_area', \serialize($securityToken));
             $this->get('security.context')->setToken($securityToken);
             $institutionUserService->setSessionVariables($institutionUser);
             // commented out due to duplicate messages
             $request->getSession()->setFlash('callout', "");
             return $this->redirect($this->generateUrl('institution_signup_setup_profile'));
         } else {
             $request->getSession()->setFlash('error', "We need you to correct some of your input. Please check the fields in red.");
         }
     }
     return $this->render('InstitutionBundle:SignUp:signUp.html.twig', array('form' => $form->createView(), 'institutionTypes' => InstitutionTypes::getFormChoices()));
 }