/** * @Route("/student/edit/{id}", defaults={"id"=0}, name="student_edit_profile") * */ public function editStudentProfile(Request $request, $id) { $user = $this->getUser(); $id = $user->getUsername(); $em = $this->getDoctrine()->getManager(); $connection = $em->getConnection(); $query = 'SELECT * '; $query .= 'FROM student AS s '; $query .= 'WHERE s.id = :id'; $statement = $connection->prepare($query); $statement->bindValue('id', $id); $statement->execute(); $student_ = $statement->fetchAll(); $student = new Student(); $em = $this->getDoctrine()->getManager(); $connection = $em->getConnection(); $query = "SELECT DISTINCT faculty FROM fac_dep"; $statement = $connection->prepare($query); $statement->execute(); $result = $statement->fetchAll(); $faculty_list = array(); foreach ($result as $fac) { $faculty_list[$fac['faculty']] = $fac['faculty']; } $query = "SELECT DISTINCT department FROM fac_dep"; $statement = $connection->prepare($query); $statement->execute(); $result = $statement->fetchAll(); $department_list = array(); foreach ($result as $fac) { $department_list[$fac['department']] = $fac['department']; } $student->setId($student_[0]['id']); $student->setFirstName($student_[0]['first_name']); $student->setSecondName($student_[0]['second_name']); $student->setFaculty($student_[0]['faculty']); $student->setDepartment($student_[0]['department']); $student->setGender($student_[0]['gender']); // $birth_day = strtotime($student_[0]['birthday']); $birth__day = date('Y-m-d', strtotime($student_[0]['birthday'])); //$birth_day); //var_dump($birth__day); $student->setBirthday(new \DateTime()); //$birth__day); $student->setContactNumber($student_[0]['contact_number']); $student->setEMail($student_[0]['e_mail']); $student->setAddress($student_[0]['address']); $form = $this->createFormBuilder($student)->add('id', TextType::class)->add('firstName', TextType::class)->add('secondName', TextType::class, ['required' => false])->add('faculty', ChoiceType::class, ['choices' => $faculty_list, 'placeholder' => '-SELECT-'])->add('department', ChoiceType::class, ['choices' => $department_list, 'placeholder' => '-SELECT-'])->add('gender', ChoiceType::class, ['choices' => ['Male' => 'Male', 'Female' => 'Female'], 'choices_as_values' => true, 'placeholder' => '-SELECT-'])->add('birthday', DateType::class, ['input' => 'datetime', 'widget' => 'choice', 'years' => range(1980, 2000), 'placeholder' => '-SELECT-'])->add('contactNumber', TextType::class)->add('eMail', TextType::class, ['required' => false])->add('address', TextType::class, ['required' => false])->add('save', SubmitType::class, ['label' => 'Update Profile'])->getForm(); $form->handleRequest($request); if ($form->isValid()) { $em = $this->getDoctrine()->getEntityManager(); $connection = $em->getConnection(); $query_student = "UPDATE student SET"; $query_student .= " first_name = '" . $student->getFirstName() . "', "; $query_student .= "second_name = '" . $student->getSecondName() . "', "; $query_student .= "faculty='" . $student->getFaculty() . "',"; $query_student .= "department = '" . $student->getDepartment() . "',"; $query_student .= "gender = '" . $student->getGender() . "',"; $query_student .= "birthday ='" . $student->getBirthday()->format('y/m/d') . "', "; $query_student .= "contact_number = '" . $student->getContactNumber() . "',"; $query_student .= "e_mail = '" . $student->getEMail() . "',"; $query_student .= "address = '" . $student->getAddress() . "'"; $query_student .= "WHERE id = '" . $student->getId() . "'"; $statement1 = $connection->prepare($query_student); $statement1->execute(); return $this->render('student/edit.html.twig'); } return $this->render('student/edit.html.twig', array('form' => $form->createView())); }