/**
  * Creates a new grade entity.
  *
  * @param Request $request
  * @return RedirectResponse | Response
  */
 public function createAction(Request $request)
 {
     $entity = new Grade();
     $studentId = $request->get('student_id');
     $studentRepository = $this->get('app_bundle.repository.student');
     $student = $studentRepository->getById($studentId);
     $classId = $student->getClass()->getId();
     $teacher = $this->get('security.context')->getToken()->getUser()->getActor();
     $teacherId = $teacher->getId();
     $repository = $this->get('app_bundle.repository.subject');
     $query = $repository->getForTeacherAndClassQuery($classId, $teacherId);
     $gradeFormType = new GradeType($query);
     $entity->setTeacher($teacher);
     $entity->setStudent($student);
     $form = $this->createForm($gradeFormType, $entity, ['action' => $this->generateUrl('ocena_create', ['student_id' => $studentId]), 'method' => 'PUT'])->add('submit', 'submit', ['label' => 'dodaj', 'attr' => ['class' => 'btn btn-success pull-left btn-add']]);
     if ($request->isMethod('PUT')) {
         $form->handleRequest($request);
         if ($form->isValid()) {
             $entityManager = $this->getDoctrine()->getManager();
             $entityManager->persist($entity);
             $entityManager->flush();
             $this->addFlash('success', 'Pomyślnie dodano ocenę.');
             return $this->redirect($this->generateUrl('ocena', ['student_id' => $studentId]));
         }
     }
     return $this->render('AppBundle:Grade:create.html.twig', ['entity' => $entity, 'student' => $student, 'form' => $form->createView()]);
 }
 public function load(ObjectManager $manager)
 {
     $grade = new Grade();
     $grade->setMark(15);
     $manager->persist($grade);
     $manager->flush();
 }
示例#3
0
 public function load(ObjectManager $manager)
 {
     // Je créé les objets que je veux pour mes tests
     $grade = new Grade();
     $grade->setStudent($this->getReference('student'));
     $grade->setGradeNumber('18');
     $grade->setExam($this->getReference('exam'));
     // Je sauvegarde en DB
     $manager->persist($grade);
     $manager->flush();
 }
示例#4
0
 public function load(ObjectManager $manager)
 {
     // Je créé les objets que je veux pour mes tests
     $admin = new Admin();
     $admin->setEmail('*****@*****.**')->setUsername('admin')->setPlainPassword('admin')->setEnabled(1)->setRoles(['ROLE_SUPER_ADMIN']);
     $student = new Student();
     $student->setEmail('*****@*****.**')->setFirstName('John')->setLastName('Doe');
     $exam = new Exam();
     $exam->setName('Symfony 2')->setDescription('Best framework');
     $grade = new Grade();
     $grade->setGradeNumber(15)->setStudent($student)->setExam($exam);
     // Je sauvegarde en DB
     $manager->persist($admin);
     $manager->persist($student);
     $manager->persist($exam);
     $manager->persist($grade);
     $manager->flush();
 }
 /**
  * @Route("/result/create", name="result_create")
  */
 public function createAction(Request $request)
 {
     $result = new student_module_grade();
     // generating data for the form
     $students = Student::getAll();
     $studentIds = array();
     foreach ($students as $student) {
         $studentIds[$student->getIndexNo()] = $student->getIndexNo();
         //array_push($studentIds, $student->getIndexNo());
     }
     $modules = Module::getAll();
     $moduleIds = array();
     foreach ($modules as $module) {
         $moduleIds[$module->getCode()] = $module->getCode();
         //array_push($moduleIds, $module->getCode());
     }
     $grades = Grade::getAll();
     $gradeIds = array();
     foreach ($grades as $grade) {
         $gradeIds[$grade->getGrade()] = $grade->getGrade();
         //array_push($gradeIds, $grade->getGrade());
     }
     $form = $this->createFormBuilder($result)->add('s_id', ChoiceType::class, array('choices' => $studentIds, 'choices_as_values' => true, 'label' => 'Index No'))->add('m_code', ChoiceType::class, array('choices' => $moduleIds, 'choices_as_values' => true, 'label' => 'Module'))->add('grade', ChoiceType::class, array('choices' => $gradeIds, 'choices_as_values' => true, 'label' => 'Grade'))->add('save', SubmitType::class, array('label' => 'Add Marks'))->getForm();
     $form->handleRequest($request);
     if ($form->isSubmitted() && $form->isValid()) {
         // ... perform some action, such as saving the task to the database
         $result->save();
         return $this->redirectToRoute('result_create');
     }
     ////////////////////////form 2 for add multiple//////////////////////////////////
     $form2Data = array('message' => 'Type your message here');
     $form2 = $this->createFormBuilder($form2Data)->add('m_code', ChoiceType::class, array('choices' => $moduleIds, 'choices_as_values' => true, 'label' => 'Module'))->add('marks', TextType::class)->add('save', SubmitType::class, array('label' => 'Add Marks'))->getForm();
     $form2->handleRequest($request);
     if ($form2->isSubmitted() && $form2->isValid()) {
         // ... perform some action, such as saving the task to the database
         $data = $form2->getData();
         //die($data['marks']);
         $module = $data['m_code'];
         $marks = $data['marks'];
         //$em = $this->getDoctrine()->getManager();
         $doc = $this->getDoctrine();
         student_module_grade::saveAll($module, $marks, $doc);
         return $this->redirectToRoute('result_create');
     }
     //////////////////////////////////////////////////////////
     // ADDED THE FORM2 array
     return $this->render('result/create.html.twig', array('form' => $form->createView(), 'form2' => $form2->createView()));
 }
 /**
  * {@inheritDoc}
  */
 public function getUser()
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'getUser', array());
     return parent::getUser();
 }
 /**
  * {@inheritDoc}
  */
 public function __toString()
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, '__toString', array());
     return parent::__toString();
 }
 /**
  * Remove grade
  *
  * @param \AppBundle\Entity\Grade $grade
  */
 public function removeGrade(\AppBundle\Entity\Grade $grade)
 {
     $this->grades->removeElement($grade);
 }