/** * Send new matches to users by email */ public function sendNewMatches() { $config = OW::getConfig(); if (!$config->configExists('matchmaking', 'cron_busy')) { $config->addConfig('matchmaking', 'cron_busy', 0, 'Mass mailing queue is busy'); } if (!$config->configExists('matchmaking', 'cron_mailing_user_first')) { $config->addConfig('matchmaking', 'cron_mailing_user_first', 0, 'Already mailed users count'); } // check if cron queue is not busy if ($config->getValue('matchmaking', 'cron_busy')) { $cronBusyTime = (int) $config->getValue('matchmaking', 'cron_busy_timestamp'); if (time() - $cronBusyTime > 60 * 30) { $config->saveConfig('matchmaking', 'cron_busy', 0); } return; } if ($this->send_new_matches_interval == 0) { return; } if (time() - $this->last_matches_sent_timestamp < $this->send_new_matches_interval) { return; } $config->saveConfig('matchmaking', 'cron_busy', 1); if (!$config->configExists('matchmaking', 'cron_busy_timestamp')) { $config->addConfig('matchmaking', 'cron_busy_timestamp', time(), ''); } else { $config->saveConfig('matchmaking', 'cron_busy_timestamp', time()); } $userService = BOL_UserService::getInstance(); $first = $config->getValue('matchmaking', 'cron_mailing_user_first'); $count = $userService->count(true); if ($first < $count) { $users = $userService->findList($first, self::CRON_USER_COUNT, true); $counter = 0; /** * @var BOL_User $user */ foreach ($users as $id => $user) { if ($user->emailVerify == 0) { $counter++; continue; } try { $this->service->sendNewMatchesForUser($user->getId()); $counter++; } catch (Exception $e) { $config->saveConfig('matchmaking', 'cron_mailing_user_first', $first + $counter); $config->saveConfig('matchmaking', 'cron_busy', 0); return; } } $config->saveConfig('matchmaking', 'cron_mailing_user_first', $first + $counter); } else { OW::getConfig()->saveConfig('matchmaking', 'cron_mailing_user_first', 0); OW::getConfig()->saveConfig('matchmaking', 'last_matches_sent_timestamp', time()); } $config->saveConfig('matchmaking', 'cron_busy', 0); }
/** * Returns class instance * * @return MATCHMAKING_BOL_Service */ public static function getInstance() { if (null === self::$classInstance) { self::$classInstance = new self(); } return self::$classInstance; }
/** * Constructor. * */ public function __construct($name) { parent::__construct(); $this->service = MATCHMAKING_BOL_Service::getInstance(); $cmpId = uniqid(); $this->assign('maxCoefficient', MATCHMAKING_BOL_Service::MAX_COEFFICIENT); $this->assign('coefficient', 0); $this->assign('cmpId', $cmpId); $jsParamsArray = array('cmpId' => $cmpId, 'itemsCount' => MATCHMAKING_BOL_Service::MAX_COEFFICIENT, 'name' => $name, 'checkedCoefficient' => 0, 'respondUrl' => OW::getRouter()->urlFor('MATCHMAKING_CTRL_Admin', 'ruleEditFormResponder')); OW::getDocument()->addOnloadScript("var createCoefficient{$cmpId} = new CreateCoefficient(" . json_encode($jsParamsArray) . "); createCoefficient{$cmpId}.init();"); }
/** * @return Constructor. */ public function __construct(BASE_CLASS_WidgetParameter $paramsObj) { parent::__construct(); $params = $paramsObj->additionalParamList; if (!OW::getUser()->isAuthenticated() || OW::getUser()->getId() == $params['entityId']) { $this->setVisible(false); return; } $service = MATCHMAKING_BOL_Service::getInstance(); $percent = $service->getCompatibility(OW::getUser()->getId(), $params['entityId']); $this->assign('percent', $percent); }
public function getData(BASE_CLASS_WidgetParameter $params) { $count = (int) $params->customParamList['count']; $service = MATCHMAKING_BOL_Service::getInstance(); $userId = $params->additionalParamList['entityId']; $toolbar = array('newest_first' => array('label' => OW::getLanguage()->text('base', 'view_all'), 'href' => OW::getRouter()->urlForRoute('matchmaking_members_page_sorted', array('sortOrder' => 'newest'))), 'most_compatible_first' => array('label' => OW::getLanguage()->text('base', 'view_all'), 'href' => OW::getRouter()->urlForRoute('matchmaking_members_page_sorted', array('sortOrder' => 'compatible')))); $matchCount = $service->findMatchCount($userId); if ($matchCount > $count) { $this->setSettingValue(self::SETTING_TOOLBAR, array($toolbar['newest_first'])); } $resultList = array('newest_first' => array('menu-label' => OW::getLanguage()->text('matchmaking', 'latest'), 'menu_active' => true, 'userIds' => $this->getIdList($service->findMatchList($userId, 0, $count, 'newest')), 'toolbar' => $matchCount > $count ? array($toolbar['newest_first']) : false), 'most_compatible_first' => array('menu-label' => OW::getLanguage()->text('matchmaking', 'top'), 'userIds' => $this->getIdList($service->findMatchList($userId, 0, $count, 'compatible')), 'toolbar' => $matchCount > $count ? array($toolbar['most_compatible_first']) : false)); return $resultList; }
public function onBeforeRender() { parent::onBeforeRender(); $userService = BOL_UserService::getInstance(); $matchService = MATCHMAKING_BOL_Service::getInstance(); $idList = array(); $compatibilityList = array(); foreach ($this->items as $item) { $idList[] = $item['id']; $compatibilityList[$item['id']] = $matchService->getCompatibilityByValue($item['compatibility']); if ($item['id'] > $this->lastUserId) { $this->lastUserId = $item['id']; } } $avatars = array(); $usernameList = array(); $displayNameList = array(); $onlineInfo = array(); $list = array(); if (!empty($idList)) { $avatars = BOL_AvatarService::getInstance()->getAvatarsUrlList($idList, 2); foreach ($idList as $userId) { $list[$userId]['userUrl'] = $userService->getUserUrl($userId); $list[$userId]['displayName'] = $userService->getDisplayName($userId); $list[$userId]['avatarUrl'] = $avatars[$userId]; $list[$userId]['compatibility'] = $compatibilityList[$userId]; $fields = $matchService->getFieldsForEmail($userId); $list[$userId]['sex'] = empty($fields['sex']) ? '' : $fields['sex']; $list[$userId]['age'] = empty($fields['age']) ? '' : $fields['age']; $list[$userId]['googlemap_location'] = empty($fields['googlemap_location']) ? '' : $fields['googlemap_location']; } } $this->assign('userName', BOL_UserService::getInstance()->getDisplayName($this->user->getId())); $this->assign('list', $list); $this->assign('matchesUrl', OW::getRouter()->urlForRoute('matchmaking_members_page')); }
public function uninstall($params) { if (isset($_POST['action']) && $_POST['action'] == 'delete_rules') { $rules = MATCHMAKING_BOL_Service::getInstance()->findFieldsExceptRequired(); foreach ($rules as $rule) { MATCHMAKING_BOL_Service::getInstance()->delete($rule->id); } BOL_PluginService::getInstance()->uninstall('matchmaking'); $this->redirect(OW::getRouter()->urlForRoute('admin_plugins_installed')); } $js = new UTIL_JsGenerator(); $js->jQueryEvent('#btn-delete-rules', 'click', 'if ( !confirm("' . OW::getLanguage()->text('base', 'are_you_sure') . '") ) return false;'); OW::getDocument()->addOnloadScript($js); }
public function getFields($userIdList) { $fields = array(); $qs = array(); $qBdate = BOL_QuestionService::getInstance()->findQuestionByName('birthdate'); if ($qBdate->onView) { $qs[] = 'birthdate'; } $qSex = BOL_QuestionService::getInstance()->findQuestionByName('sex'); if ($qSex->onView) { $qs[] = 'sex'; } $qLocation = BOL_QuestionService::getInstance()->findQuestionByName('googlemap_location'); if ($qLocation && $qLocation->onView) { $qs[] = 'googlemap_location'; } // if ( $this->listType == 'details' ) // { // $qs[] = 'aboutme'; // } $questionList = BOL_QuestionService::getInstance()->getQuestionData($userIdList, $qs); $matchCompatibility = array(); if ($this->orderType == USEARCH_BOL_Service::LIST_ORDER_MATCH_COMPATIBILITY) { if (OW::getPluginManager()->isPluginActive('matchmaking') && OW::getUser()->isAuthenticated()) { $maxCompatibility = MATCHMAKING_BOL_QuestionMatchDao::getInstance()->getMaxPercentValue(); $matchCompatibilityList = MATCHMAKING_BOL_Service::getInstance()->findCompatibilityByUserIdList(OW::getUser()->getId(), $userIdList, 0, 1000); foreach ($matchCompatibilityList as $compatibility) { $matchCompatibility[$compatibility['userId']] = (int) ($compatibility['compatibility'] / $maxCompatibility * 100); } } } foreach ($questionList as $uid => $q) { $fields[$uid] = array(); $age = ''; if (!empty($q['birthdate'])) { $date = UTIL_DateTime::parseDate($q['birthdate'], UTIL_DateTime::MYSQL_DATETIME_DATE_FORMAT); $age = UTIL_DateTime::getAge($date['year'], $date['month'], $date['day']); } if (!empty($q['sex'])) { $sex = $q['sex']; $sexValue = ''; for ($i = 0; $i < 31; $i++) { $val = pow(2, $i); if ((int) $sex & $val) { $sexValue .= BOL_QuestionService::getInstance()->getQuestionValueLang('sex', $val) . ', '; } } if (!empty($sexValue)) { $sexValue = substr($sexValue, 0, -2); } } if (!empty($sexValue) && !empty($age)) { $fields[$uid]['base'][] = array('label' => '', 'value' => $sexValue . ' ' . $age); } if (!empty($q['aboutme'])) { $fields[$uid]['aboutme'] = array('label' => '', 'value' => $q['aboutme']); } if (!empty($q['googlemap_location']['address'])) { $fields[$uid]['location'] = array('label' => '', 'value' => $q['googlemap_location']['address']); } if (isset($matchCompatibility[$uid])) { $fields[$uid]['match_compatibility'] = array('label' => '', 'value' => $matchCompatibility[$uid] . '%'); } if ($this->orderType == USEARCH_BOL_Service::LIST_ORDER_DISTANCE) { if (OW::getPluginManager()->isPluginActive('googlelocation') && !empty($q['googlemap_location']) && !empty($this->location)) { $event = new OW_Event('googlelocation.calc_distance', array('lat' => $this->location['latitude'], 'lon' => $this->location['longitude'], 'lat1' => $q['googlemap_location']['latitude'], 'lon1' => $q['googlemap_location']['longitude'])); OW::getEventManager()->trigger($event); $data = $event->getData(); if ($data['units'] == 'miles') { $html = ' <span>' . OW::getLanguage()->text('usearch', 'miles') . '</span>'; } else { $html = ' <span>' . OW::getLanguage()->text('usearch', 'kms') . '</span>'; } $fields[$uid]['distance'] = array('label' => '', 'value' => $data['distance'] . $html); } } } return $fields; }
public function __construct() { $this->service = MATCHMAKING_BOL_Service::getInstance(); $this->questionService = BOL_QuestionService::getInstance(); }
public function getSearchResultList($listId, $listType, $from, $count, $excludeList = array()) { if (empty($excludeList)) { $excludeList = array(); } if (OW::getUser()->isAuthenticated()) { $excludeList[] = OW::getUser()->getId(); } $userIdList = $this->getUserIdList($listId, 0, BOL_SearchService::USER_LIST_SIZE, $excludeList); //$userIdList = BOL_SearchService::getInstance()->getUserIdList($listId, 0, BOL_SearchService::USER_LIST_SIZE, $excludeList); if (empty($userIdList)) { return array(); } switch ($listType) { case USEARCH_BOL_Service::LIST_ORDER_NEW: return $this->searchDao->findSearchResultListOrderedByRecentlyJoined($userIdList, $from, $count); break; case USEARCH_BOL_Service::LIST_ORDER_MATCH_COMPATIBILITY: if (OW::getPluginManager()->isPluginActive('matchmaking') && OW::getUser()->isAuthenticated()) { $result = MATCHMAKING_BOL_Service::getInstance()->findCompatibilityByUserIdList(OW::getUser()->getId(), $userIdList, $from, $count); $idList = array(); foreach ($result as $item) { $idList[$item['userId']] = $item['userId']; } $users = BOL_UserService::getInstance()->findUserListByIdList($idList); $list = array(); foreach ($users as $user) { $list[] = $user; } return $list; } break; case USEARCH_BOL_Service::LIST_ORDER_DISTANCE: if (OW::getPluginManager()->isPluginActive('googlelocation') && OW::getUser()->isAuthenticated()) { $result = BOL_QuestionService::getInstance()->getQuestionData(array(OW::getUser()->getId()), array('googlemap_location')); if (!empty($result[OW::getUser()->getId()]['googlemap_location']['json'])) { $location = $result[OW::getUser()->getId()]['googlemap_location']; return GOOGLELOCATION_BOL_LocationService::getInstance()->getListOrderedByDistance($userIdList, $from, $count, $location['latitude'], $location['longitude']); } } break; default: $params = array('idList' => $userIdList, 'orderType' => $listType, 'from' => $from, 'count' => $count, 'userId' => OW::getUser()->isAuthenticated() ? OW::getUser()->getId() : 0); $event = new OW_Event('usearch.get_ordered_list', $params, array()); OW::getEventManager()->trigger($event); $data = $event->getData(); if (!empty($data) && is_array($data)) { return $data; } } return $this->searchDao->findSearchResultListByLatestActivity($userIdList, $from, $count); }
public function onBeforeSaveLangValue(OW_Event $event) { $params = $event->getParams(); if (empty($params['dto'])) { return; } if (!$params['dto'] instanceof BOL_LanguageValue) { return; } $langKey = BOL_LanguageKeyDao::getInstance()->findById($params['dto']->keyId); $rules = MATCHMAKING_BOL_Service::getInstance()->findAll(); /** * @var MATCHMAKING_BOL_QuestionMatch $rule */ foreach ($rules as $rule) { if ("questions_question_{$rule->questionName}_label" == $langKey->key) { $matchQuestionLabel = OW::getLanguage()->text('matchmaking', 'match_question_lang_prefix', array('questionLabel' => $params['dto']->value)); BOL_LanguageService::getInstance()->addOrUpdateValue($params['dto']->languageId, BOL_QuestionService::QUESTION_LANG_PREFIX, BOL_QuestionService::getInstance()->getQuestionLangKeyName(BOL_QuestionService::LANG_KEY_TYPE_QUESTION_LABEL, $rule->matchQuestionName), empty($matchQuestionLabel) ? ' ' : $matchQuestionLabel); } } }