/** * Запуск обработки */ public function Exec() { /** * Получаем страны */ $aCountries = E::ModuleGeo()->GetGroupCountriesByTargetType('user', 20); /** * Формируем облако тегов */ E::ModuleTools()->MakeCloud($aCountries); /** * Выводим в шаблон */ E::ModuleViewer()->Assign('aCountryList', $aCountries); }
/** * Получает дополнительные данные(объекты) для юзеров по их ID * * @param array|int $aUsersId - Список ID пользователей * @param array $aAllowData - Список типоd дополнительных данных для подгрузки у пользователей * * @return ModuleUser_EntityUser[] */ public function GetUsersAdditionalData($aUsersId, $aAllowData = null) { if (!$aUsersId) { return array(); } if (!is_array($aUsersId)) { $aUsersId = array($aUsersId); } else { $aUsersId = array_unique($aUsersId); } if (sizeof($aUsersId) == 1) { $iUserId = reset($aUsersId); if ($this->oUserCurrent && $this->oUserCurrent->getId() == $iUserId) { return array($iUserId => $this->oUserCurrent); } } if (is_null($aAllowData)) { $aAllowData = $this->aAdditionalData; } $aAllowData = F::Array_FlipIntKeys($aAllowData); // * Получаем юзеров $aUsers = $this->GetUsersByArrayId($aUsersId); // * Получаем дополнительные данные $aSessions = array(); $aFriends = array(); $aVote = array(); $aGeoTargets = array(); $aNotes = array(); if (isset($aAllowData['session'])) { $aSessions = $this->GetSessionsByArrayId($aUsersId); } if (isset($aAllowData['friend']) && $this->oUserCurrent) { $aFriends = $this->GetFriendsByArray($aUsersId, $this->oUserCurrent->getId()); } if (isset($aAllowData['vote']) && $this->oUserCurrent) { $aVote = E::ModuleVote()->GetVoteByArray($aUsersId, 'user', $this->oUserCurrent->getId()); } if (isset($aAllowData['geo_target'])) { $aGeoTargets = E::ModuleGeo()->GetTargetsByTargetArray('user', $aUsersId); } if (isset($aAllowData['note']) && $this->oUserCurrent) { $aNotes = $this->GetUserNotesByArray($aUsersId, $this->oUserCurrent->getId()); } $aAvatars = E::ModuleUploader()->GetMediaObjects('profile_avatar', $aUsersId, null, array('target_id')); // * Добавляем данные к результату /** @var ModuleUser_EntityUser $oUser */ foreach ($aUsers as $oUser) { if (isset($aSessions[$oUser->getId()])) { $oUser->setSession($aSessions[$oUser->getId()]); } else { $oUser->setSession(null); // или $oUser->setSession(new ModuleUser_EntitySession()); } if ($aFriends && isset($aFriends[$oUser->getId()])) { $oUser->setUserFriend($aFriends[$oUser->getId()]); } else { $oUser->setUserFriend(null); } if (isset($aVote[$oUser->getId()])) { $oUser->setVote($aVote[$oUser->getId()]); } else { $oUser->setVote(null); } if (isset($aGeoTargets[$oUser->getId()])) { $aTargets = $aGeoTargets[$oUser->getId()]; $oUser->setGeoTarget(isset($aTargets[0]) ? $aTargets[0] : null); } else { $oUser->setGeoTarget(null); } if (isset($aAllowData['note'])) { if (isset($aNotes[$oUser->getId()])) { $oUser->setUserNote($aNotes[$oUser->getId()]); } else { $oUser->setUserNote(false); } } if (isset($aAvatars[$oUser->getId()])) { $oUser->setMediaResources('profile_avatar', $aAvatars[$oUser->getId()]); } else { $oUser->setMediaResources('profile_avatar', array()); } } return $aUsers; }
/** * Выводит форму для редактирования профиля и обрабатывает её * */ protected function EventProfile() { // * Устанавливаем title страницы E::ModuleViewer()->AddHtmlTitle(E::ModuleLang()->Get('settings_menu_profile')); E::ModuleViewer()->Assign('aUserFields', E::ModuleUser()->GetUserFields('')); E::ModuleViewer()->Assign('aUserFieldsContact', E::ModuleUser()->GetUserFields(array('contact', 'social'))); // * Загружаем в шаблон JS текстовки E::ModuleLang()->AddLangJs(array('settings_profile_field_error_max')); // * Если нажали кнопку "Сохранить" if ($this->isPost('submit_profile_edit')) { E::ModuleSecurity()->ValidateSendForm(); $bError = false; /** * Заполняем профиль из полей формы */ // * Определяем гео-объект if (F::GetRequest('geo_city')) { $oGeoObject = E::ModuleGeo()->GetGeoObject('city', F::GetRequestStr('geo_city')); } elseif (F::GetRequest('geo_region')) { $oGeoObject = E::ModuleGeo()->GetGeoObject('region', F::GetRequestStr('geo_region')); } elseif (F::GetRequest('geo_country')) { $oGeoObject = E::ModuleGeo()->GetGeoObject('country', F::GetRequestStr('geo_country')); } else { $oGeoObject = null; } // * Проверяем имя if (F::CheckVal(F::GetRequestStr('profile_name'), 'text', 2, Config::Get('module.user.name_max'))) { $this->oUserCurrent->setProfileName(F::GetRequestStr('profile_name')); } else { $this->oUserCurrent->setProfileName(null); } // * Проверяем пол if (in_array(F::GetRequestStr('profile_sex'), array('man', 'woman', 'other'))) { $this->oUserCurrent->setProfileSex(F::GetRequestStr('profile_sex')); } else { $this->oUserCurrent->setProfileSex('other'); } // * Проверяем дату рождения $nDay = intval(F::GetRequestStr('profile_birthday_day')); $nMonth = intval(F::GetRequestStr('profile_birthday_month')); $nYear = intval(F::GetRequestStr('profile_birthday_year')); if (checkdate($nMonth, $nDay, $nYear)) { $this->oUserCurrent->setProfileBirthday(date('Y-m-d H:i:s', mktime(0, 0, 0, $nMonth, $nDay, $nYear))); } else { $this->oUserCurrent->setProfileBirthday(null); } // * Проверяем информацию о себе if (F::CheckVal(F::GetRequestStr('profile_about'), 'text', 1, 3000)) { $this->oUserCurrent->setProfileAbout(E::ModuleText()->Parser(F::GetRequestStr('profile_about'))); } else { $this->oUserCurrent->setProfileAbout(null); } // * Ставим дату последнего изменения профиля $this->oUserCurrent->setProfileDate(F::Now()); // * Запускаем выполнение хуков E::ModuleHook()->Run('settings_profile_save_before', array('oUser' => $this->oUserCurrent, 'bError' => &$bError)); // * Сохраняем изменения профиля if (!$bError) { if (E::ModuleUser()->Update($this->oUserCurrent)) { // * Обновляем название личного блога $oBlog = $this->oUserCurrent->getBlog(); if (F::GetRequestStr('blog_title') && $this->checkBlogFields($oBlog)) { $oBlog->setTitle(strip_tags(F::GetRequestStr('blog_title'))); E::ModuleBlog()->UpdateBlog($oBlog); } // * Создаем связь с гео-объектом if ($oGeoObject) { E::ModuleGeo()->CreateTarget($oGeoObject, 'user', $this->oUserCurrent->getId()); if ($oCountry = $oGeoObject->getCountry()) { $this->oUserCurrent->setProfileCountry($oCountry->getName()); } else { $this->oUserCurrent->setProfileCountry(null); } if ($oRegion = $oGeoObject->getRegion()) { $this->oUserCurrent->setProfileRegion($oRegion->getName()); } else { $this->oUserCurrent->setProfileRegion(null); } if ($oCity = $oGeoObject->getCity()) { $this->oUserCurrent->setProfileCity($oCity->getName()); } else { $this->oUserCurrent->setProfileCity(null); } } else { E::ModuleGeo()->DeleteTargetsByTarget('user', $this->oUserCurrent->getId()); $this->oUserCurrent->setProfileCountry(null); $this->oUserCurrent->setProfileRegion(null); $this->oUserCurrent->setProfileCity(null); } E::ModuleUser()->Update($this->oUserCurrent); // * Обрабатываем дополнительные поля, type = '' $aFields = E::ModuleUser()->GetUserFields(''); $aData = array(); foreach ($aFields as $iId => $aField) { if (isset($_REQUEST['profile_user_field_' . $iId])) { $aData[$iId] = F::GetRequestStr('profile_user_field_' . $iId); } } E::ModuleUser()->SetUserFieldsValues($this->oUserCurrent->getId(), $aData); // * Динамические поля контактов, type = array('contact','social') $aType = array('contact', 'social'); $aFields = E::ModuleUser()->GetUserFields($aType); // * Удаляем все поля с этим типом E::ModuleUser()->DeleteUserFieldValues($this->oUserCurrent->getId(), $aType); $aFieldsContactType = F::GetRequest('profile_user_field_type'); $aFieldsContactValue = F::GetRequest('profile_user_field_value'); if (is_array($aFieldsContactType)) { foreach ($aFieldsContactType as $k => $v) { $v = (string) $v; if (isset($aFields[$v]) && isset($aFieldsContactValue[$k]) && is_string($aFieldsContactValue[$k])) { E::ModuleUser()->SetUserFieldsValues($this->oUserCurrent->getId(), array($v => $aFieldsContactValue[$k]), Config::Get('module.user.userfield_max_identical')); } } } E::ModuleMessage()->AddNoticeSingle(E::ModuleLang()->Get('settings_profile_submit_ok')); E::ModuleHook()->Run('settings_profile_save_after', array('oUser' => $this->oUserCurrent)); } else { E::ModuleMessage()->AddErrorSingle(E::ModuleLang()->Get('system_error')); } } } // * Загружаем гео-объект привязки $oGeoTarget = E::ModuleGeo()->GetTargetByTarget('user', $this->oUserCurrent->getId()); E::ModuleViewer()->Assign('oGeoTarget', $oGeoTarget); // * Загружаем в шаблон список стран, регионов, городов $aCountries = E::ModuleGeo()->GetCountries(array(), array('sort' => 'asc'), 1, 300); E::ModuleViewer()->Assign('aGeoCountries', $aCountries['collection']); if ($oGeoTarget) { if ($oGeoTarget->getCountryId()) { $aRegions = E::ModuleGeo()->GetRegions(array('country_id' => $oGeoTarget->getCountryId()), array('sort' => 'asc'), 1, 500); E::ModuleViewer()->Assign('aGeoRegions', $aRegions['collection']); } if ($oGeoTarget->getRegionId()) { $aCities = E::ModuleGeo()->GetCities(array('region_id' => $oGeoTarget->getRegionId()), array('sort' => 'asc'), 1, 500); E::ModuleViewer()->Assign('aGeoCities', $aCities['collection']); } } E::ModuleLang()->AddLangJs(array('settings_profile_avatar_resize_title', 'settings_profile_avatar_resize_text', 'settings_profile_photo_resize_title', 'settings_profile_photo_resize_text')); }
/** * Получение списка городов по региону */ protected function EventGeoGetCities() { $iRegionId = F::GetRequestStr('region'); $iLimit = 500; if (is_numeric(F::GetRequest('limit')) && F::GetRequest('limit') > 0) { $iLimit = F::GetRequest('limit'); } // * Находим регион if (!($oRegion = E::ModuleGeo()->GetGeoObject('region', $iRegionId))) { E::ModuleMessage()->AddErrorSingle(E::ModuleLang()->Get('system_error')); return; } // * Получаем города $aResult = E::ModuleGeo()->GetCities(array('region_id' => $oRegion->getId()), array('sort' => 'asc'), 1, $iLimit); $aCities = array(); foreach ($aResult['collection'] as $oObject) { $aCities[] = array('id' => $oObject->getId(), 'name' => $oObject->getName()); } // * Устанавливаем переменные для ajax ответа E::ModuleViewer()->AssignAjax('aCities', $aCities); }
/** * Показывает юзеров по городу * */ protected function EventCity() { $this->sMenuItemSelect = 'city'; // Город существует? if (!($oCity = E::ModuleGeo()->GetCityById($this->getParam(0)))) { return parent::EventNotFound(); } // Получаем статистику $this->GetStats(); // Передан ли номер страницы $iPage = $this->GetParamEventMatch(1, 2) ? $this->GetParamEventMatch(1, 2) : 1; // Получаем список юзеров $aResult = E::ModuleGeo()->GetTargets(array('city_id' => $oCity->getId(), 'target_type' => 'user'), $iPage, Config::Get('module.user.per_page')); $aUsersId = array(); foreach ($aResult['collection'] as $oTarget) { $aUsersId[] = $oTarget->getTargetId(); } $aUsersCity = E::ModuleUser()->GetUsersAdditionalData($aUsersId); // Формируем постраничность $aPaging = E::ModuleViewer()->MakePaging($aResult['count'], $iPage, Config::Get('module.user.per_page'), Config::Get('pagination.pages.count'), R::GetPath('people') . $this->sCurrentEvent . '/' . $oCity->getId()); // Загружаем переменные в шаблон if ($aUsersCity) { E::ModuleViewer()->Assign('aPaging', $aPaging); } E::ModuleViewer()->Assign('oCity', $oCity); E::ModuleViewer()->Assign('aUsersCity', $aUsersCity); }
/** * Возвращает гео-объект города * * @return ModuleGeo_EntityGeo|null */ public function getCity() { if ($this->getType() == 'city') { return $this; } if ($oCity = $this->getProp('city')) { return $oCity; } if ($this->getCityId()) { $oCity = E::ModuleGeo()->GetCityById($this->getCityId()); $this->setProp('city', $oCity); return $oCity; } return null; }