public function addContacts() { $user1 = $this->em->find('models\User','1'); $contact1 = new models\Contact; $contact1->setUser($user1); $contact1->setAddress('09017178823'); $contact1->setType('phone'); $contact1->setVisibility(0); $this->em->persist($contact1); $this->em->flush(); $contact2 = new models\Contact; $contact2->setUser($user1); $contact2->setAddress('hirose mansion'); $contact2->setType('address'); $contact2->setVisibility(0); $this->em->persist($contact2); $this->em->flush(); /*$contacts = $user1->getContacts(); $message = 'Contacts are '.$contacts->count().' '; foreach ($contacts as $member) { $message = $message.$member->getAddress().', '.$member->getType()."\n"; }*/ $data['message'] = 'Contacts added.'; $this->load->view('home', $data); }
public function submit() { /*$this->load->library('unit_test'); echo $this->unit->run($this->input->post('number_of_contacts'), 4); return;*/ /*for ($i=0; $i<$this->input->post('number_of_contacts'); $i++) { $address = $this->input->post('address'.($i+1)); echo $address; if(!(is_null($address)) && $address!='') { echo 'not null'; } } return;*/ if ($this->_submit_validate() === FALSE) { $this->index(); return; } $user = new models\User; $user->setEmail($this->input->post('email')); $user->setName($this->input->post('name')); $user->setPassword(md5($this->input->post('password'))); $user->setHometown($this->input->post('hometown')); $user->setAffiliation($this->input->post('affiliation')); $user->setArrivalDate(new DateTime(str_replace('/', '-', $this->input->post('arrival_date')))); $user->setBirthday(new DateTime(str_replace('/', '-', $this->input->post('birthday')))); $user->setMarriageStatus($this->input->post('status')); $user->setGender($this->input->post('gender')); $user->setReligion($this->input->post('religion')); $user->setIntroduction($this->input->post('introduction')); $user->setUndergradUniversity($this->input->post('undergrad_university')); $user->setUndergradDepartment($this->input->post('undergrad_department')); $user->setUndergradGraduationYear($this->input->post('undergrad_graduation_year')); $user->setMasterUniversity($this->input->post('master_university')); $user->setMasterDepartment($this->input->post('master_department')); $user->setMasterGraduationYear($this->input->post('master_graduation_year')); $user->setPhdUniversity($this->input->post('phd_university')); $user->setPhdDepartment($this->input->post('phd_department')); $user->setPhdGraduationYear($this->input->post('phd_graduation_year')); $user->setInformalSkill($this->input->post('informal_skill')); $user->setLeftTheCountry($this->input->post('left_the_country')); $user->setPosition($this->input->post('position')); $this->em->persist($user); $this->em->flush(); for ($i=0; $i<$this->input->post('number_of_contacts'); $i++) { $address = $this->input->post('address'.($i+1)); if(!(is_null($address)) && $address!='') { $contact1 = new models\Contact; $contact1->setUser($user); $contact1->setAddress($address); $contact1->setType($this->input->post('addresstype'.($i+1))); $contact1->setVisibility(0); $this->em->persist($contact1); $this->em->flush(); } } // assign role id 7 to the new user $this->load->database(); $date = new DateTime('now'); $data = array( 'userID' => $user->getId(), 'roleID' => 7, 'addDate' => $date->format('Y-m-d H:i:s') ); $this->db->insert('user_roles', $data); $this->load->view('login_form'); }