Exemplo n.º 1
0
 public function authenticate(Request $request, VendingMachine $vendingMachine)
 {
     if (!$request->query->has('login') || !$request->query->has('password')) {
         return FALSE;
     }
     if ($vendingMachine->getLogin() !== $request->query->get('login')) {
         return FALSE;
     }
     if (!$this->_passwordEncoder->isPasswordValid($request->query->get('password'), $vendingMachine->getPassword())) {
         return FALSE;
     }
     return TRUE;
 }
Exemplo n.º 2
0
 public function handlePurchaseData(VendingMachine $vendingMachine, $data)
 {
     // TODO: This fallback will cause problems, if prices in ProductVendingGroup are different from default
     if (!($products = $vendingMachine->getProducts())) {
         // Fallback to all available products, could signal problem
         $products = new ArrayCollection($this->_manager->getRepository('AppBundle:Product\\Product')->findAll());
     }
     $nfcTags = new ArrayCollection($this->_manager->getRepository('AppBundle:NfcTag\\NfcTag')->findAvailableByVendingMachine($vendingMachine));
     if ($nfcTags->isEmpty()) {
         // Fallback to all available NFC tags, could signal problem
         $nfcTags = new ArrayCollection($this->_manager->getRepository('AppBundle:NfcTag\\NfcTag')->findAllIndexedByCode());
     }
     if (!($students = $vendingMachine->getStudents())) {
         // Fallback to all available students, could signal problem
         $students = new ArrayCollection($this->_manager->getRepository('AppBundle:Student\\Student')->findAll());
     }
     $purchasesArray = [];
     foreach ($data[self::SYNC_DATA][Purchase::getSyncArrayName()] as $value) {
         // KLUDGE: set code to lower case (minor TA architecture failure)
         $value[Purchase::PURCHASE_NFC_CODE] = mb_strtolower($value[Purchase::PURCHASE_NFC_CODE], 'UTF-8');
         if ($nfcTags->get($value[Purchase::PURCHASE_NFC_CODE]) && $products->get($value[Purchase::PURCHASE_PRODUCT_ID])) {
             $purchase = (new Purchase())->setSyncPurchaseId($value[Purchase::PURCHASE_SYNC_ID])->setSyncPurchasedAt(new DateTime($value[Purchase::PURCHASE_PURCHASED_AT]));
             $purchase->setVendingMachine($vendingMachine)->setVendingMachineSerial($vendingMachine->getSerial())->setVendingMachineSyncId($data[self::SYNC_DATA][VendingMachineSync::getSyncArrayName()][0][self::VENDING_MACHINE_SYNC_ID]);
             $purchase->setSyncNfcTagCode($value[Purchase::PURCHASE_NFC_CODE])->setNfcTag($nfcTags->get($value[Purchase::PURCHASE_NFC_CODE]) ?: NULL);
             // TRICKY: Setting NFC Tag and Student separately, to preserve purchase history
             // in case if persisted NFC Tag is [unbinded from / binded to other] Student.
             // This is an emerged fallback mechanism, so in early versions of API value
             // could be empty - in that case getting Student from NFC Tag as usual
             if (!empty($value[Purchase::PURCHASE_STUDENT_ID]) && $students->get($value[Purchase::PURCHASE_STUDENT_ID])) {
                 $purchase->setSyncStudentId($value[Purchase::PURCHASE_STUDENT_ID])->setStudent($students->get($value[Purchase::PURCHASE_STUDENT_ID]));
             } else {
                 $purchase->setSyncStudentId(NULL)->setStudent($nfcTags->get($value[Purchase::PURCHASE_NFC_CODE]) ? $nfcTags->get($value[Purchase::PURCHASE_NFC_CODE])->getStudent() ?: NULL : NULL);
             }
             $purchase->setSyncProductId($value[Purchase::PURCHASE_PRODUCT_ID])->setSyncProductPrice($value[Purchase::PURCHASE_SYNC_PRODUCT_PRICE])->setProduct($products->get($value[Purchase::PURCHASE_PRODUCT_ID]) ? $products->get($value[Purchase::PURCHASE_PRODUCT_ID]) : NULL);
             $purchasesArray[] = $purchase;
         } else {
             //Logging value that somehow (!) contains wrong bindings
             $this->_logger->warning("SyncDataHandler: VM `" . $vendingMachine->getSerial() . "` posted contradictory NfcTag `code` or Product `id`: " . json_encode($value));
         }
     }
     // When purchases empty?
     if ($purchasesArray) {
         $this->_manager->getRepository('AppBundle:Purchase\\Purchase')->rawInsertPurchases($purchasesArray);
         $purchasesAggregated = $this->_manager->getRepository('AppBundle:Purchase\\Purchase')->findSumsByStudentsWithSyncId($vendingMachine, $data[self::SYNC_DATA][VendingMachineSync::getSyncArrayName()][0][self::VENDING_MACHINE_SYNC_ID]);
         $studentsArray = [];
         foreach ($purchasesAggregated as $purchase) {
             if ($nfcTags->get($purchase['code'])->getStudent()) {
                 $totalLimit = $nfcTags->get($purchase['code'])->getStudent()->getTotalLimit();
                 $totalLimit = bcsub($totalLimit, $purchase['price_sum'], 2);
                 $studentsArray[] = ['id' => $nfcTags->get($purchase['code'])->getStudent()->getId(), 'totalLimit' => $totalLimit];
             } else {
                 //Logging NfcTag that somehow (!) is not binded to Student
                 $this->_logger->warning("SyncDataHandler: VM `" . $vendingMachine->getSerial() . "` posted unbinded NfcTag `code`: " . $nfcTags->get($purchase['code'])->getCode());
             }
         }
         // When students empty?
         if ($studentsArray) {
             $this->_manager->getRepository('AppBundle:Student\\Student')->rawUpdateStudentsTotalLimits($studentsArray);
         }
     }
     return $data[self::SYNC_DATA][VendingMachineSync::getSyncArrayName()][0][self::VENDING_MACHINE_SYNC_ID];
 }
 protected function buildBody(VendingMachine $vendingMachine)
 {
     $this->phpExcelObject->getActiveSheet()->setCellValueByColumnAndRow(1, 8, "№ п/п")->setCellValueByColumnAndRow(2, 8, "Категория")->setCellValueByColumnAndRow(5, 8, "Артикул")->setCellValueByColumnAndRow(6, 8, "Наименование")->setCellValueByColumnAndRow(9, 8, "Количество");
     $this->phpExcelObject->getActiveSheet()->mergeCells($this->getPosition(8, 8, 'C') . ":" . $this->getPosition(8, 8, 'E'))->mergeCells($this->getPosition(8, 8, 'G') . ":" . $this->getPosition(8, 8, 'I'));
     $this->styleAlignHorizontalCenter(8, 8)->styleBorderThick(8, 8)->styleFontBold(8, 8);
     $currentRow = 9;
     foreach ($vendingMachine->getPurchases() as $purchase) {
         $currentRow++;
         $currentPurchase = $purchase['object'];
         $this->phpExcelObject->getActiveSheet()->setCellValueByColumnAndRow(1, $currentRow, $currentPurchase->getProduct()->getId())->setCellValueByColumnAndRow(2, $currentRow, $currentPurchase->getProduct()->getProductCategory()->getName())->setCellValueByColumnAndRow(5, $currentRow, $currentPurchase->getProduct()->getCode())->setCellValueByColumnAndRow(6, $currentRow, $currentPurchase->getProduct()->getNameFull())->setCellValueByColumnAndRow(9, $currentRow, $purchase['quantity']);
         $this->phpExcelObject->getActiveSheet()->mergeCells($this->getPosition($currentRow, $currentRow, 'C') . ":" . $this->getPosition($currentRow, $currentRow, 'E'))->mergeCells($this->getPosition($currentRow, $currentRow, 'G') . ":" . $this->getPosition($currentRow, $currentRow, 'I'));
         $this->styleBorderThin($currentRow, $currentRow);
     }
 }
 /**
  * @Method({"GET", "POST"})
  * @Route(
  *      "/vending_machine/create",
  *      name="vending_machine_create",
  *      host="{domain_dashboard}",
  *      defaults={"_locale" = "%locale%", "domain_dashboard" = "%domain_dashboard%"},
  *      requirements={"_locale" = "%locale%", "domain_dashboard" = "%domain_dashboard%"}
  * )
  */
 public function createAction(Request $request)
 {
     if (!$this->_vendingMachineBoundlessAccess->isGranted(VendingMachineBoundlessAccess::VENDING_MACHINE_CREATE)) {
         throw $this->createAccessDeniedException('Access denied');
     }
     $vendingMachineType = new VendingMachineType($this->_vendingMachineBoundlessAccess->isGranted(VendingMachineBoundlessAccess::VENDING_MACHINE_CREATE));
     $form = $this->createForm($vendingMachineType, $vendingMachine = new VendingMachine(), ['action' => $this->generateUrl('vending_machine_create')]);
     $form->handleRequest($request);
     if (!$form->isValid()) {
         $this->_breadcrumbs->add('vending_machine_read')->add('vending_machine_create');
         return $this->render('AppBundle:Entity/VendingMachine/CRUD:createItem.html.twig', ['form' => $form->createView()]);
     } else {
         $encodedPassword = $this->get('app.sync.security.password_encoder')->encodePassword($vendingMachine->getPassword());
         $vendingMachine->setPassword($encodedPassword);
         $this->_manager->persist($vendingMachine);
         $this->_manager->flush();
         $this->_messages->markCreateSuccess();
         if ($form->has('create_and_return') && $form->get('create_and_return')->isClicked()) {
             return $this->redirectToRoute('vending_machine_read');
         } else {
             return $this->redirectToRoute('vending_machine_update', ['id' => $vendingMachine->getId()]);
         }
     }
 }
 /**
  * Add vendingMachines
  *
  * @param \AppBundle\Entity\VendingMachine\VendingMachine $vendingMachine
  * @return ProductVendingGroup
  */
 public function addVendingMachine(\AppBundle\Entity\VendingMachine\VendingMachine $vendingMachine)
 {
     $vendingMachine->setProductVendingGroup($this);
     $this->vendingMachines[] = $vendingMachine;
     return $this;
 }
Exemplo n.º 6
0
 /**
  * Add vendingMachines
  *
  * @param \AppBundle\Entity\VendingMachine\VendingMachine $vendingMachine
  * @return School
  */
 public function addVendingMachine(\AppBundle\Entity\VendingMachine\VendingMachine $vendingMachine)
 {
     $vendingMachine->setSchool($this);
     $this->vendingMachines[] = $vendingMachine;
     return $this;
 }