/** * Returns an singleton instance of this class * * @param object $config * @param object $args * @return */ public static function getInstance($config, $args) { if (self::$instance == null) { self::$instance = new CbaRatesManager($config, $args); } return self::$instance; }
public function addCustomerMessagesAfterLoginByPreviousPing($custDto, $userLevel, $previousPing) { if ($userLevel === UserGroups::$GUEST) { return false; } $custEmail = $custDto->getEmail(); $companyDealersManager = CompanyDealersManager::getInstance($this->config, $this->args); $userCompaniesIdsArray = array(); if ($userLevel === UserGroups::$USER) { $userCompaniesIdsArray = $companyDealersManager->getUserCompaniesIdsArray($custDto->getId()); } if ($userLevel === UserGroups::$COMPANY || $userLevel === UserGroups::$ADMIN || !empty($userCompaniesIdsArray)) { //new prices after last ping $companiesPriceListManager = CompaniesPriceListManager::getInstance($this->config, $this->args); $allPricesAfterTime = $companiesPriceListManager->getAllPricesAfterTime($previousPing, $userCompaniesIdsArray); if (!empty($allPricesAfterTime)) { $pre = HTTP_PROTOCOL . HTTP_HOST; $massage = ''; foreach ($allPricesAfterTime as $dto) { $companyName = $dto->getCompanyName() . ' (`558`: ' . $dto->getUploadDateTime() . ')'; $companyId = $dto->getCompanyId(); $pricePath = HTTP_PROTOCOL . HTTP_HOST . '/price/last_price/' . $companyId; $massage .= '<div><a href="' . $pricePath . '"><img src="' . $pre . '/images/small_logo/' . $companyId . '" style="vertical-align: middle;" /> ' . $companyName . '</a></div>'; } $this->addCustomerMessage($custEmail, '540', $massage, 1, 'attention'); } } //new added dealers messages for (company only) if ($userLevel === UserGroups::$COMPANY || $userLevel === UserGroups::$ADMIN) { $dealersAfterGivenDatetime = $companyDealersManager->getAfterGivenDatetime($userLevel === UserGroups::$ADMIN ? 0 : intval($custDto->getId()), $previousPing); if (!empty($dealersAfterGivenDatetime)) { $this->addCustomerMessage($custEmail, '543', '`541` ' . count($dealersAfterGivenDatetime) . '`542`', 1, 'attention'); } } //alert to admin if dollar rate doeasn't match to config rate if ($userLevel === UserGroups::$ADMIN) { $cbaRatesManager = CbaRatesManager::getInstance($this->config, $this->args); $latestUSDExchange = $cbaRatesManager->getLatestUSDExchange(); $us_dollar_exchange = floatval($this->getCmsVar('us_dollar_exchange')); $us_dollar_exchange_down = floatval($this->getCmsVar('us_dollar_exchange_down')); $pcstoreAverageUSDExchange = ($us_dollar_exchange + $us_dollar_exchange_down) / 2; $maxAllowedDollarDifferenceParcent = floatval($this->getCmsVar('admin_alert_if_cba_dollar_rate_is_more_than_percent')); if (abs($latestUSDExchange - $pcstoreAverageUSDExchange) / $latestUSDExchange > $maxAllowedDollarDifferenceParcent / 100) { $this->addCustomerMessage($custEmail, '483', 'Cba rate for USD Dollar ($) is: ' . $latestUSDExchange, 1, 'warning'); } } //new added bonuses to user (users only) if ($userLevel === UserGroups::$USER) { $bonusHistoryManager = BonusHistoryManager::getInstance($this->config, $this->args); $userBonusesAfterGivenDatetime = $bonusHistoryManager->getUserBonusesAfterGivenDatetime($custDto->getId(), $previousPing); if (!empty($userBonusesAfterGivenDatetime)) { $pointSum = 0; foreach ($userBonusesAfterGivenDatetime as $bDto) { $pointSum += intval($bDto->getPoints()); } $pointSum = intval($pointSum); if ($pointSum > 0) { $phraseId = '544'; } else { $phraseId = '548'; } $this->addCustomerMessage($custEmail, '545', '`' . $phraseId . '` ' . strval(intval(abs($pointSum))) . 'դր.`542`', 1, 'attention'); } } //new added sub users (users only) if ($userLevel === UserGroups::$USER) { $userSubUsersManager = UserSubUsersManager::getInstance($this->config, $this->args); $rowsAddedAfterGivenDatetime = $userSubUsersManager->getRowsAddedAfterGivenDatetime($custDto->getId(), $previousPing); if (!empty($rowsAddedAfterGivenDatetime)) { $this->addCustomerMessage($custEmail, '546', strval(count($rowsAddedAfterGivenDatetime)) . ' `547`', 1, 'attention'); } } $customerLocalEmailsManager = CustomerLocalEmailsManager::getInstance($this->config, $this->args); $unreadEmailsCount = $customerLocalEmailsManager->getCustomerInboxUnreadEmailsCountCustomerEmail($custEmail); if ($unreadEmailsCount > 0) { $customerAlertsManager = CustomerAlertsManager::getInstance($this->config, $this->args); $customerAlertsManager->addUnreadEmailsCustomerAlert($custEmail, $unreadEmailsCount); } }
$customerAlertsManager->removeOldAlerts(10); //10 minute $companyItemCheckListManager = new CompanyItemCheckListManager($config, null); $companyItemCheckListManager->removeOldRowsBySeconds(120); //2 minutes $requestHistoryManager = new RequestHistoryManager($config, null); $requestHistoryManager->removeOldRowsByDays(90); // 90 days $cmsSearchRequestsManager = new CmsSearchRequestsManager($config, null); $cmsSearchRequestsManager->removeOldRowsByDays(90); // 90 days //chaching cba rates for all exchanges $rates = getCbaRates(); if ($rates !== false) { $datetime = $rates[1]; $cbaRatesManager = new CbaRatesManager($config, null); $selectByField = $cbaRatesManager->selectByField('cba_datetime', $datetime); if (empty($selectByField)) { foreach ($rates[0] as $rate) { $cbaRatesManager->addRow($datetime, $rate[0], $rate[1], $rate[2]); } } } $receiveEmailManager = ReceiveEmailManager::getInstance(); $receiveEmailManager->checkPriceEmailsAndAddAlertsToOnlineAdmins(); /** * * @return array(datetime, array(array(iso, amount, rate),...)) or FALSE */ function getCbaRates() {