/** * Generates PDF with hosted order's products and participants * * @param \Illuminati\OrderBundle\Entity\Host_Order $hostOrder */ public function generate(Host_order $hostOrder) { $repo = $this->em->getRepository('IlluminatiOrderBundle:Host_order'); $hostedOrderHost = $hostOrder->getUsersId(); $products = $repo->findOrderedProducts($hostOrder->getId()); $participants = $repo->findUserOrders($hostOrder->getId()); $overallPriceSum = 0; $this->AliasNbPages(); $this->newOrderPage($hostOrder->getTitle(), "Ordered Products:"); // Generating Product Table; if (!empty($products)) { // Column widths $w = [120, 25, 45]; $this->Cell($w[0], 6, "Product", 1, 0); $this->Cell($w[1], 6, "Quantity", 1, 0, "R"); $this->Cell($w[2], 6, "Price", 1, 0, "R"); $this->Ln(); foreach ($products as $product) { $this->Cell($w[0], 6, $product['title'], 'LR'); $this->Cell($w[1], 6, $product['quantity'], 'LR', 0, "R"); $this->Cell($w[2], 6, $product['sum'] . " " . $product['currency'], 'LR', 0, "R"); $this->Ln(); $overallPriceSum += $product['sum']; } $this->Cell($w[0], 1, '', 'T'); $this->Cell($w[1], 6, "Sum", 1, 0, "R"); $this->Cell($w[2], 6, $overallPriceSum . " " . $products[0]['currency'], 1, 0, "R"); } //Generating particiapnts table; $this->newOrderPage($hostOrder->getTitle(), "Order Participants: "); if (!empty($participants)) { $counter = 1; $w = [10, 155, 25]; $this->Cell($w[0], 6, "Nr.", 1, 0); $this->Cell($w[1], 6, "Participant", 1, 0); $this->Cell($w[2], 6, "Prepaid", 1, 0, "R"); $this->Ln(); foreach ($participants as $participant) { // We skip the host of the order in the list if ($participant->getUsersId() == $hostedOrderHost) { continue; } $this->Cell($w[0], 6, "{$counter}.", "LR", 0, "C"); $this->Cell($w[1], 6, "{$participant->getUsersId()->getName()} " . "{$participant->getUsersId()->getSurname()} " . "( {$participant->getUsersId()->getEmail()} )", "LR"); $prepaid = $participant->getPayed() == 0 ? "No" : "Yes"; $this->Cell($w[2], 6, $prepaid, "LR", 0, "R"); $this->Ln(); $counter++; } $this->Cell(array_sum($w), 1, '', 'T'); } }
/** * Deletes participant from the hosted order * * @param Host_order $hostOrder Host order Object * @param integer $userId User Id * * @return int * @throws \Doctrine\DBAL\ConnectionException */ public function deleteParticipant(Host_order $hostOrder, $userId) { $conn = $this->getEntityManager()->getConnection(); $conn->beginTransaction(); try { $conn->executeQuery('UPDATE user_order SET deleted = 1 WHERE host_order_id = ? AND users_id = ? AND deleted = 0;', [$hostOrder->getId(), $userId]); // checking if the user is the host of the group order // if yes, we close the group order if ($hostOrder->getUsersId()->getId() == $userId) { $conn->executeQuery('UPDATE host_order SET deleted = 1 WHERE id = ?', [$hostOrder->getId()]); } $conn->executeQuery('DELETE FROM user_order_details WHERE host_order_id = ? AND user_id = ?;', [$hostOrder->getId(), $userId]); $conn->commit(); } catch (\Exception $e) { $conn->rollBack(); $conn->close(); return false; } $conn->close(); return true; }