Skip to content

Commit

Permalink
Updated goto model
Browse files Browse the repository at this point in the history
  • Loading branch information
shinde-rahul committed Sep 15, 2023
1 parent 36d95ae commit 03ce4e3
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions Model/GoToModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public function addEvent($product, $email, $eventName, $eventDesc, $eventType, $
return;
}

$productRepository = $this->em->getRepository(GoToProduct::class);
$productRepository = $this->getProductRepository();
$productKey = explode('#', $eventName);
$goToProduct = $productRepository->findOneByProductKey($productKey[1]);
if (null === $goToProduct) {
Expand Down Expand Up @@ -133,7 +133,7 @@ public function getEventsByLeadEmail($product, $email)
public function getEmailsByEvent($product, $productId, $eventType)
{
/** @var GoToProductRepository $productRepository */
$productRepository = $this->em->getRepository(GoToProduct::class);
$productRepository = $this->getProductRepository();

if (!GoToProductTypes::isValidValue($product) || !GoToEventTypes::isValidValue($eventType)) {
return []; // is not a valid goto product
Expand Down Expand Up @@ -269,7 +269,7 @@ public function countEventsBy($product, $email, $eventType, array $eventNames =
*/
public function syncEvent($product, $productId, $eventName, $eventDesc, &$count = 0, $output = null)
{
$cpr = $this->em->getRepository(GoToProduct::class);
$cpr = $this->getProductRepository();
/** @var GoToProduct $product_result */
$product_result = $cpr->findOneBy(['product_key' => $productId]);
$organizerKey = $product_result->getOrganizerKey();
Expand Down Expand Up @@ -349,7 +349,7 @@ public function batchAddAndRemove(
$leads = $this->leadModel->getRepository()->getLeadsByFieldValue('email', $searchEmails, null, true);
// todo give as arg?
/** @var GoToProductRepository $citrixProductRepository */
$citrixProductRepository = $this->em->getRepository(GoToProduct::class);
$citrixProductRepository = $this->getProductRepository();
foreach ($contactsToAdd as $email => $info) {
if (!isset($leads[strtolower($email)])) {
$lead = (new Lead())
Expand Down Expand Up @@ -393,7 +393,7 @@ public function batchAddAndRemove(

// Delete events
if ([] !== $emailsToRemove) {
$citrixProductRepository = $this->em->getRepository(GoToProduct::class);
$citrixProductRepository = $this->getProductRepository();
$citrixEvents = $this->getRepository()->findAllByMailAndEvent($emailsToRemove, $productKey);
/** @var GoToEvent $citrixEvent */
foreach ($citrixEvents as $citrixEvent) {
Expand Down Expand Up @@ -458,7 +458,7 @@ private function filterEventContacts($found, $known)
public function syncProduct($productType, $product, $output = null)
{
/** @var GoToProductRepository $productRepository */
$productRepository = $this->em->getRepository(GoToProduct::class);
$productRepository = $this->getProductRepository();

/** @var GoToProduct $persistedProduct */
$persistedProduct = $productRepository->findOneBy([
Expand Down Expand Up @@ -511,7 +511,7 @@ public function syncProduct($productType, $product, $output = null)

public function getProducts($product_name, $from = null, $to = null, $reduceSessions = false, $withDetails = null)
{
$cpr = $this->em->getRepository(GoToProduct::class);
$cpr = $this->getProductRepository();
$products = $cpr->getCitrixChoices(true, $reduceSessions);
uasort($products, static function ($a1, $a2) {
$v1 = strtotime($a1['date']['date']);
Expand All @@ -530,16 +530,21 @@ public function getProducts($product_name, $from = null, $to = null, $reduceSess

public function getIdByNameAndDate($name, $date)
{
$productRepository = $this->em->getRepository(GoToProduct::class);
$productRepository = $this->getProductRepository();
$result = $productRepository->findOneBy(['name' => $name, 'date' => $date]);

return $result ? $result->getId() : null;
}

public function getProductById($id)
{
$cpr = $this->em->getRepository(GoToProduct::class);
$cpr = $this->getProductRepository();

return $cpr->findOneByProductKey($id);
}

public function getProductRepository(): GoToProductRepository
{
return $this->em->getRepository(GoToProduct::class);
}
}

0 comments on commit 03ce4e3

Please sign in to comment.