Example #1
0
 /**
  * mengimpor data siswa baru
  *
  * @param array                                $content
  * @param array                                $fieldnames
  * @param \Langgas\SisdikBundle\Entity\Sekolah $sekolah
  * @param \Langgas\SisdikBundle\Entity\Tahun   $tahun
  * @param boolean                              $andFlush
  */
 private function imporSiswaBaru($content, $fieldnames, $sekolah, $tahun, $andFlush = false)
 {
     /* @var $em EntityManager */
     $em = $this->getDoctrine()->getManager();
     $atleastone = false;
     foreach ($content as $key => $val) {
         if ($val != "") {
             $atleastone = true;
         }
     }
     if (!$atleastone) {
         return;
     }
     $entity = new Siswa();
     $reflectionClass = new \ReflectionClass('Langgas\\SisdikBundle\\Entity\\Siswa');
     $entityFields = [];
     foreach ($reflectionClass->getProperties() as $property) {
         $entityFields[] = $property->getName();
     }
     $orangtuaWali = new ArrayCollection();
     $ortu = new OrangtuaWali();
     $sekolahAsal = null;
     foreach ($fieldnames as $keyfield => $valuefield) {
         if (preg_match("/(.+)\\.(.+)/", $valuefield, $matches)) {
             $valuefield = $matches[1];
             $childfield = $matches[2];
         }
         $key = array_search($valuefield, $entityFields);
         if (is_int($key)) {
             if (array_key_exists($keyfield, $content)) {
                 $value = $content[$keyfield];
                 if ($value == "0" || $value == "") {
                     $value = null;
                 }
                 if ($valuefield == 'orangtuaWali') {
                     $ortu->setAktif(true);
                     $ortu->{'set' . ucfirst($childfield)}(trim($value));
                 } elseif ($valuefield == 'sekolahAsal') {
                     if (trim($value) != '') {
                         $querySekolahAsal = $em->createQueryBuilder()->select('sekolahasal')->from('LanggasSisdikBundle:SekolahAsal', 'sekolahasal')->where('sekolahasal.nama LIKE :nama')->setParameter('nama', "%{$value}%");
                         $resultSekolahAsal = $querySekolahAsal->getQuery()->getResult();
                         if (count($resultSekolahAsal) >= 1) {
                             $sekolahAsal = $resultSekolahAsal[0];
                         } else {
                             $sekolahAsal = new SekolahAsal();
                             $sekolahAsal->{'set' . ucfirst($childfield)}(trim($value));
                             $sekolahAsal->setSekolah($sekolah);
                         }
                     }
                 } elseif ($valuefield == 'tanggalLahir') {
                     if ($value) {
                         $entity->{'set' . ucfirst($valuefield)}(new \DateTime($value));
                     }
                 } else {
                     $value = $value !== null ? trim($value) : $value;
                     $entity->{'set' . ucfirst($valuefield)}($value);
                 }
             }
         }
     }
     if ($this->nomorUrutPersekolah == 0) {
         $qbe = $em->createQueryBuilder();
         $querynomor = $em->createQueryBuilder()->select($qbe->expr()->max('siswa.nomorUrutPersekolah'))->from('LanggasSisdikBundle:Siswa', 'siswa')->where('siswa.sekolah = :sekolah')->setParameter('sekolah', $sekolah);
         $nomorUrutPersekolah = $querynomor->getQuery()->getSingleScalarResult();
         $nomorUrutPersekolah = $nomorUrutPersekolah === null ? 100000 : $nomorUrutPersekolah;
         $nomorUrutPersekolah++;
         $this->nomorUrutPersekolah = $nomorUrutPersekolah;
     } else {
         $this->nomorUrutPersekolah++;
     }
     $entity->setNomorUrutPersekolah($this->nomorUrutPersekolah);
     $entity->setNomorIndukSistem($this->nomorUrutPersekolah . $sekolah->getNomorUrut());
     $entity->setCalonSiswa(false);
     $entity->setSekolah($sekolah);
     $entity->setTahun($tahun);
     $entity->setGelombang(null);
     $orangtuaWali->add($ortu);
     $entity->setOrangtuaWali($orangtuaWali);
     $entity->setSekolahAsal($sekolahAsal);
     $entity->setDibuatOleh($this->getUser());
     $tanggalBulan = preg_split("/[\\/,\\s,\\-,\\+,_,\\*]/", $sekolah->getAwalPembiayaan());
     if (is_array($tanggalBulan)) {
         $tanggal = $tanggalBulan[0];
         $bulan = $tanggalBulan[1];
     } else {
         $tanggal = '01';
         $bulan = '07';
     }
     $entity->setPembiayaanSejak(new \DateTime($entity->getTahun()->getTahun() . '-' . $bulan . '-' . $tanggal));
     $em->persist($entity);
     $this->imporSiswaJumlah++;
     if ($andFlush) {
         $em->flush();
         $em->clear($entity);
         $em->clear($ortu);
         $em->clear($sekolahAsal);
     }
 }
 /**
  * @Route("/pendaftar/create", name="ortuwali-pendaftar_create")
  * @Route("/siswa/create", name="ortuwali-siswa_create")
  * @Method("POST")
  * @Template("LanggasSisdikBundle:OrangtuaWali:new.html.twig")
  */
 public function createAction($sid)
 {
     $this->setCurrentMenu();
     $em = $this->getDoctrine()->getManager();
     if ($this->get('security.authorization_checker')->isGranted('create', $em->getRepository('LanggasSisdikBundle:Siswa')->find($sid)) === false) {
         throw new AccessDeniedException($this->get('translator')->trans('akses.ditolak'));
     }
     $entity = new OrangtuaWali();
     $entity->setSiswa($em->getRepository('LanggasSisdikBundle:Siswa')->find($sid));
     $form = $this->createForm('sisdik_orangtuawali', $entity);
     $form->submit($this->getRequest());
     if ($form->isValid()) {
         $entity->setAktif(false);
         $em->persist($entity);
         $em->flush();
         $this->get('session')->getFlashBag()->add('success', $this->get('translator')->trans('flash.ortuwali.tersimpan', ['%siswa%' => $entity->getSiswa()->getNamaLengkap()]));
         return $this->redirect($this->generateUrl(RuteAsal::ruteAsalSiswaPendaftar($this->getRequest()->getPathInfo()) == 'pendaftar' ? 'ortuwali-pendaftar_show' : 'ortuwali-siswa_show', ['sid' => $sid, 'id' => $entity->getId()]));
     }
     return ['entity' => $entity, 'form' => $form->createView(), 'siswa' => $em->getRepository('LanggasSisdikBundle:Siswa')->find($sid), 'ruteasal' => RuteAsal::ruteAsalSiswaPendaftar($this->getRequest()->getPathInfo())];
 }