/**
  * get
  * Gets contact, restricted to contacts within your org/school
  * 
  * @ParamConverter("contact", class="TSKUserBundle:Contact")
  * @Template("TSKUserBundle:Default:get.html.twig")
  * @Method("GET")
  */
 public function getContactAction(Contact $contact)
 {
     $session = $this->getRequest()->getSession();
     $sessionKey = $this->container->getParameter('tsk_user.session.org_key');
     if ($contact->getOrganization()->getId() != $session->get($sessionKey)) {
         throw new HttpException(403, "Access forbidden");
     }
     $view = View::create()->setStatusCode(200)->setData($contact);
     // ->setTemplate('TSKUserBundle:Contact:get.html.twig');
     return $this->get('fos_rest.view_handler')->handle($view);
     return array('contact' => $contact);
 }
 public function load(ObjectManager $manager)
 {
     $corp = new Corporation();
     $corp->setLegalName('Elmwood LLC');
     $corp->setTaxId('239423423');
     $manager->persist($corp);
     $manager->flush();
     $schoolContact = new Contact();
     $schoolContact->setFirstName('Elmwood');
     $schoolContact->setLastName('Park');
     $schoolContact->setEmail('*****@*****.**');
     $schoolContact->setOrganization($this->getReference('tsk-org'));
     $schoolContact->setAddress1('75 Boulevard');
     $schoolContact->setCity('Elmwood Park');
     $schoolContact->setState($manager->getRepository('TSK\\UserBundle\\Entity\\States')->find('NJ'));
     $schoolContact->addCorporation($corp);
     $manager->persist($schoolContact);
     $manager->flush();
     $school = new School();
     $school->setName('Elmwood Park');
     $school->setContact($schoolContact);
     $school->setLatePaymentCharge(12.0);
     $school->setLateGraceDays(5);
     $manager->persist($school);
     $manager->flush();
     $this->addReference('tsk_elmwoodpark_school', $school);
     $soCorp = new Corporation();
     $soCorp->setLegalName('South Orange LLC');
     $soCorp->setTaxId('384823232');
     $manager->persist($soCorp);
     $manager->flush();
     $soContact = new Contact();
     $soContact->setFirstName('South');
     $soContact->setLastName('Orange');
     $soContact->setEmail('*****@*****.**');
     $soContact->setAddress1('76 South Orange Avenue');
     $soContact->setCity('South Orange');
     $soContact->setState($manager->getRepository('TSK\\UserBundle\\Entity\\States')->find('NJ'));
     $soContact->setPostalCode('07079');
     $soContact->setOrganization($this->getReference('mjh-org'));
     $soContact->addCorporation($soCorp);
     $manager->persist($soContact);
     $manager->flush();
     $soSchool = new School();
     $soSchool->setName('South Orange');
     $soSchool->setContact($soContact);
     $soSchool->setLatePaymentCharge(12.0);
     $soSchool->setLateGraceDays(5);
     $this->addReference('mjh_southorange_school', $soSchool);
     $manager->persist($soSchool);
     $manager->flush();
     $corp = new Corporation();
     $corp->setLegalName('TS OF ROUTE 17 INC.');
     $corp->setDba("TIGER SCHULMANN'S MMA");
     $corp->setTaxId('45-5615200');
     $corp->setAbbrLegalName('RAMSEY');
     $corp->setRoutingNum('021200339');
     $corp->setAccountNum('123456789012');
     $manager->persist($corp);
     $manager->flush();
     $contactManager = $this->container->get('tsk_user.contact_manager');
     $schoolContact = $contactManager->createContact();
     $schoolContact->setFirstName('TSMMA');
     $schoolContact->setLastName('RAMSEY');
     $schoolContact->setEmail('*****@*****.**');
     $schoolContact->setOrganization($this->getReference('tsk-org'));
     $schoolContact->setAddress1('885 State Highway 17 South');
     $schoolContact->setCity('Ramsey');
     $schoolContact->setState($manager->getRepository('TSK\\UserBundle\\Entity\\States')->find('NJ'));
     $schoolContact->setPostalCode('07446');
     $schoolContact->setPhone('2016693566');
     $schoolContact->setMobile('2012369618');
     $schoolContact->setWebsite('http://ramseymma.com');
     $schoolContact->addCorporation($corp);
     $contactManager->updateCanonicalFields($schoolContact);
     $school = new School();
     $school->setName('Ramsey');
     $school->setContact($schoolContact);
     $school->setLatePaymentCharge(12.0);
     $school->setLateGraceDays(10);
     $school->setLegacyId('110');
     $manager->persist($school);
     $manager->flush();
     $this->addReference('tsk_ramsey_school', $school);
     // Add schools to contacts
     $mjhContact = $this->getReference('mjh-contact1');
     $mjhContact->addSchool($this->getReference('mjh_southorange_school'));
     $mjhContact->addSchool($this->getReference('tsk_elmwoodpark_school'));
     $manager->persist($mjhContact);
     $manager->flush();
     $justinContact = $this->getReference('mjh-contact2');
     $justinContact->addSchool($this->getReference('mjh_southorange_school'));
     $manager->persist($justinContact);
     $manager->flush();
     $justinContact = $this->getReference('mjh-contact3');
     $justinContact->addSchool($this->getReference('mjh_southorange_school'));
     $manager->persist($justinContact);
     $manager->flush();
     $justinContact = $this->getReference('mjh-contact4');
     $justinContact->addSchool($this->getReference('tsk_elmwoodpark_school'));
     $justinContact->addSchool($this->getReference('mjh_southorange_school'));
     $manager->persist($justinContact);
     $manager->flush();
     $tigerContact = $this->getReference('tsk-contact1');
     $tigerContact->addSchool($this->getReference('mjh_southorange_school'));
     $tigerContact->addSchool($this->getReference('tsk_elmwoodpark_school'));
     $manager->persist($tigerContact);
     $manager->flush();
     $tContact = $this->getReference('tsk-contact2');
     $tContact->addSchool($this->getReference('tsk_elmwoodpark_school'));
     $manager->persist($tContact);
     $manager->flush();
     $tContact = $this->getReference('tsk-contact3');
     $tContact->addSchool($this->getReference('tsk_elmwoodpark_school'));
     $manager->persist($tContact);
     $manager->flush();
     $tContact = $this->getReference('tsk-contact4');
     $tContact->addSchool($this->getReference('tsk_elmwoodpark_school'));
     $tContact->addSchool($this->getReference('mjh_southorange_school'));
     $manager->persist($tContact);
     $tContact = $this->getReference('tsk-contact5');
     $tContact->addSchool($this->getReference('tsk_elmwoodpark_school'));
     $tContact->addSchool($this->getReference('mjh_southorange_school'));
     $manager->persist($tContact);
 }
 protected function processRow($row)
 {
     $manager = $this->getContainer()->get('doctrine.orm.entity_manager');
     $statesRepo = $manager->getRepository('TSKUserBundle:States');
     $schoolRepo = $manager->getRepository('TSKSchoolBundle:School');
     $studStatusRepo = $manager->getRepository('TSKStudentBundle:StudentStatus');
     $studStatus = $studStatusRepo->find(1);
     $contact = new Contact();
     $contact->setId($row[0]);
     $contact->setFirstName($row[2]);
     $contact->setLastName($row[3]);
     $contact->setOrganization($this->org);
     $contact->setEmail($row[4]);
     $contact->setAddress1($row[6]);
     $contact->setAddress2($row[7]);
     $contact->setCity($row[8]);
     $contact->setState($statesRepo->find($row[9]));
     $contact->setPostalCode($row[10]);
     $contact->setPhone($row[11]);
     $contact->setMobile($row[12]);
     $contact->setFax($row[13]);
     $contact->setWebsite($row[14]);
     $contact->setGeocode($row[15]);
     $contact->setImgPath($row[16]);
     $contact->setDateOfBirth(new \DateTime($row[17]));
     $contact->addSchool($this->school);
     $student = new Student();
     $student->setContact($contact);
     $student->setStudentStatus($studStatus);
     $metadata = $manager->getClassMetaData(get_class($contact));
     $metadata->setIdGeneratorType(\Doctrine\ORM\Mapping\ClassMetadata::GENERATOR_TYPE_NONE);
     $metadata->setIdGenerator(new \Doctrine\ORM\Id\AssignedGenerator());
     // $manager->persist($contact);
     $manager->persist($student);
     $manager->flush();
 }
 public function load(ObjectManager $manager)
 {
     $c = new Contact();
     $c->setFirstName('Tiger');
     $c->setLastName('Schulmann');
     $c->setEmail('*****@*****.**');
     $c->setOrganization($this->getReference('tsk-org'));
     $manager->persist($c);
     $manager->flush();
     $this->addReference('tsk-contact1', $c);
     $c = new Contact();
     $c->setFirstName('Tiny');
     $c->setLastName('Schulmann');
     $c->setEmail('*****@*****.**');
     $c->setOrganization($this->getReference('tsk-org'));
     $manager->persist($c);
     $manager->flush();
     $this->addReference('tsk-contact2', $c);
     $c = new Contact();
     $c->setFirstName('Eli');
     $c->setLastName('Khoury');
     $c->setEmail('*****@*****.**');
     $c->setOrganization($this->getReference('tsk-org'));
     $manager->persist($c);
     $manager->flush();
     $this->addReference('tsk-contact3', $c);
     $c = new Contact();
     $c->setFirstName('Doug');
     $c->setLastName('Parody');
     $c->setEmail('*****@*****.**');
     $c->setOrganization($this->getReference('tsk-org'));
     $manager->persist($c);
     $manager->flush();
     $this->addReference('tsk-contact4', $c);
     $c = new Contact();
     $c->setFirstName('TSK Org');
     $c->setLastName('Admin');
     $c->setEmail('*****@*****.**');
     $c->setOrganization($this->getReference('tsk-org'));
     $manager->persist($c);
     $manager->flush();
     $this->addReference('tsk-contact5', $c);
     $userManager = $this->container->get('fos_user.user_manager');
     $user = $userManager->createUser();
     $user->setEnabled(true);
     $user->setUsername('tsk_school_admin');
     $user->setPlainPassword('password1');
     $user->setContact($this->getReference('tsk-contact1'));
     $user->addRole('ROLE_USER');
     $user->addRole('ROLE_ADMIN');
     $user->addRole('ROLE_SCHOOL_ADMIN');
     $userManager->updateUser($user);
     $manager->persist($user);
     $manager->flush();
     $user = $userManager->createUser();
     $user->setEnabled(true);
     $user->setUsername('tsk_admin');
     $user->setPlainPassword('password1');
     $user->setContact($this->getReference('tsk-contact2'));
     $user->addRole('ROLE_USER');
     $user->addRole('ROLE_ADMIN');
     $userManager->updateUser($user);
     $manager->persist($user);
     $manager->flush();
     $user = $userManager->createUser();
     $user->setEnabled(true);
     $user->setUsername('eli');
     $user->setPlainPassword('password1');
     $user->setContact($this->getReference('tsk-contact3'));
     $user->addRole('ROLE_USER');
     $user->addRole('ROLE_ADMIN');
     $user->addRole('ROLE_SUPER_ADMIN');
     $userManager->updateUser($user);
     $manager->persist($user);
     $manager->flush();
     $user = $userManager->createUser();
     $user->setEnabled(true);
     $user->setUsername('doug');
     $user->setPlainPassword('password1');
     $user->setContact($this->getReference('tsk-contact4'));
     $user->addRole('ROLE_USER');
     $user->addRole('ROLE_ADMIN');
     $user->addRole('ROLE_SUPER_ADMIN');
     $userManager->updateUser($user);
     $manager->persist($user);
     $manager->flush();
     $user = $userManager->createUser();
     $user->setEnabled(true);
     $user->setUsername('tsk_org_admin');
     $user->setPlainPassword('password1');
     $user->setContact($this->getReference('tsk-contact5'));
     $user->addRole('ROLE_USER');
     $user->addRole('ROLE_ADMIN');
     $user->addRole('ROLE_ORG_ADMIN');
     $userManager->updateUser($user);
     $manager->persist($user);
     $manager->flush();
     ///////////////////////////////////////////////////////////
     $c = new Contact();
     $c->setFirstName('Malaney');
     $c->setLastName('Hill');
     $c->setEmail('*****@*****.**');
     $c->setOrganization($this->getReference('tsk-org'));
     $manager->persist($c);
     $manager->flush();
     $this->addReference('mjh-contact1', $c);
     $userManager = $this->container->get('fos_user.user_manager');
     $user = $userManager->createUser();
     $user->setEnabled(true);
     $user->setUsername('mhill');
     $user->setPlainPassword('test');
     $user->setContact($this->getReference('mjh-contact1'));
     $user->addRole('ROLE_USER');
     $user->addRole('ROLE_ADMIN');
     $user->addRole('ROLE_SUPER_ADMIN');
     $userManager->updateUser($user);
     $manager->persist($user);
     $manager->flush();
     $this->addReference('mjh-user', $user);
     $c = new Contact();
     $c->setFirstName('Justin');
     $c->setLastName('Hill');
     $c->setEmail('*****@*****.**');
     $c->setOrganization($this->getReference('mjh-org'));
     $manager->persist($c);
     $manager->flush();
     $this->addReference('mjh-contact2', $c);
     $user = $userManager->createUser();
     $user->setEnabled(true);
     $user->setUsername('mjh_admin');
     $user->setPlainPassword('password1');
     $user->setContact($this->getReference('mjh-contact2'));
     $user->addRole('ROLE_USER');
     $user->addRole('ROLE_ADMIN');
     $userManager->updateUser($user);
     $manager->persist($user);
     $manager->flush();
     $c = new Contact();
     $c->setFirstName('School Admin');
     $c->setLastName('Hill');
     $c->setEmail('*****@*****.**');
     $c->setOrganization($this->getReference('mjh-org'));
     $manager->persist($c);
     $manager->flush();
     $this->addReference('mjh-contact3', $c);
     $user = $userManager->createUser();
     $user->setEnabled(true);
     $user->setUsername('mjh_school_admin');
     $user->setPlainPassword('password1');
     $user->setContact($this->getReference('mjh-contact3'));
     $user->addRole('ROLE_USER');
     $user->addRole('ROLE_ADMIN');
     $user->addRole('ROLE_SCHOOL_ADMIN');
     $userManager->updateUser($user);
     $manager->persist($user);
     $manager->flush();
     $c = new Contact();
     $c->setFirstName('Org Admin');
     $c->setLastName('Hill');
     $c->setEmail('*****@*****.**');
     $c->setOrganization($this->getReference('mjh-org'));
     $manager->persist($c);
     $manager->flush();
     $this->addReference('mjh-contact4', $c);
     $user = $userManager->createUser();
     $user->setEnabled(true);
     $user->setUsername('mjh_org_admin');
     $user->setPlainPassword('password1');
     $user->setContact($this->getReference('mjh-contact4'));
     $user->addRole('ROLE_USER');
     $user->addRole('ROLE_ADMIN');
     $user->addRole('ROLE_ORG_ADMIN');
     $userManager->updateUser($user);
     $manager->persist($user);
     $manager->flush();
 }