diff --git a/ground/classes/Model.php b/ground/classes/Model.php index 69980f3..56683e7 100644 --- a/ground/classes/Model.php +++ b/ground/classes/Model.php @@ -165,7 +165,7 @@ abstract class Model $ready[$row[$this->_primaryKey_]] = isset($params['asArray'])&&$params['asArray'] ? $row : new $calledClass($row); } - return $ready; + return (isset($params['limit'])&&$params['limit']==1) ? array_shift($ready) : $ready; } /** diff --git a/ground/controllers/IndexController.php b/ground/controllers/IndexController.php index d6799c2..1d2b9c9 100644 --- a/ground/controllers/IndexController.php +++ b/ground/controllers/IndexController.php @@ -45,7 +45,12 @@ class IndexController extends Controller if (App::$user && App::$user->id) { $routes = Route::model()->getByAuthor(App::$user->id); - } + self::addVar('user', App::$user->id); + } + else + { + self::addVar('user', '0'); + } self::addVar('isAdmin', (int)(App::$user && App::$user->isAdmin == 1) ); @@ -152,4 +157,10 @@ class IndexController extends Controller print($xml->asXML()); } + static function actionTest() + { + + var_dump( Favorite::model()->getAllMy() ); + } + } diff --git a/ground/controllers/JsonController.php b/ground/controllers/JsonController.php index 3a90d73..8766489 100644 --- a/ground/controllers/JsonController.php +++ b/ground/controllers/JsonController.php @@ -67,6 +67,7 @@ class JsonController extends Controller $point->categoryIcon = $categories[$point->categoryId]['icon']; $point->categoryName = $categories[$point->categoryId]['name']; $point->photosCount = $photosCount; + $point->inFavorites = Favorite::model()->checkIsMy($id); self::renderPartial('json.php', $point->getValues()); } else @@ -306,4 +307,15 @@ class JsonController extends Controller self::renderPartial('json.php', $coords); } + static function actionAddRemoveFavorites() + { + $id = (int) App::getParam('id'); + if (!$id || !App::$user) + { + App::error404(); + } + + self::renderPartial('json.php', boolval(Favorite::addRemove($id))); + } + } diff --git a/ground/models/Favorite.php b/ground/models/Favorite.php new file mode 100644 index 0000000..49ea852 --- /dev/null +++ b/ground/models/Favorite.php @@ -0,0 +1,49 @@ +_tableName_ = 'favorites'; + parent::__construct($fromArray); + $this->setRelation('user', 'userId', 'User', 'id', self::TO_ONE); + $this->setRelation('point', 'pointId', 'Point', 'id', self::TO_ONE); + } + + static function model() + { + return new self(); + } + + public static function addRemove($pointId) + { + if (!App::$user || !App::$user->id || !$pointId) + return false; + + $res = self::model()->getAll(array('where' => '`userId` = '.(int)App::$user->id.' AND `pointId` = '.(int)$pointId, 'limit'=>1)); + + if ($res) + { + return boolval(Favorite::model()->delete($res->id)); + } else { + return Favorite::model()->add(array('userId'=>App::$user->id, 'pointId'=>$pointId)); + } + } + + public function getAllMy() + { + if (!App::$user || !App::$user->id) + return false; + + return $this->getAll(array('where' => '`userId` = '.(int)App::$user->id)); + } + + public function checkIsMy($pointId) + { + if (!App::$user || !App::$user->id || !$pointId) + return false; + + return boolval($this->getAll(array('where' => '`userId` = '.(int)App::$user->id.' AND `pointId` = '.(int)$pointId))); + } +} + diff --git a/ground/views/layout.php b/ground/views/layout.php index e3460c5..d8f8a2c 100644 --- a/ground/views/layout.php +++ b/ground/views/layout.php @@ -46,36 +46,6 @@ - - - - - - + \ No newline at end of file diff --git a/ground/views/metrika.php b/ground/views/metrika.php new file mode 100644 index 0000000..7ef5d02 --- /dev/null +++ b/ground/views/metrika.php @@ -0,0 +1,31 @@ + + + + + + \ No newline at end of file diff --git a/public/css/style.css b/public/css/style.css index a1ae62a..57af5fc 100644 --- a/public/css/style.css +++ b/public/css/style.css @@ -27,6 +27,11 @@ div.add {cursor: pointer;} #addPointModal .extraImage .type.button:hover {background-color: #ddd;} #addPointModal .extraImage .input-group-addon.type.button {border-left: 0px;} +div.leaflet-popup-content div.control {margin-top: 7px;} +div.leaflet-popup-content button span.label {display: none; font-size: 90%; font-weight: normal; color: #333;} +div.leaflet-popup-content button:hover {min-width: 150px;} +div.leaflet-popup-content button:hover span.label {display: inline;} + .form-group .error {display: none;} .form-group.has-error .error {display: inline-block;} diff --git a/public/hit (копия).gif b/public/hit (копия).gif new file mode 100644 index 0000000..730a38d Binary files /dev/null and b/public/hit (копия).gif differ diff --git a/public/hit0.gif b/public/hit0.gif new file mode 100644 index 0000000..66734e3 Binary files /dev/null and b/public/hit0.gif differ diff --git a/public/hit1.gif b/public/hit1.gif new file mode 100644 index 0000000..fd9fab9 Binary files /dev/null and b/public/hit1.gif differ diff --git a/public/hit2.gif b/public/hit2.gif new file mode 100644 index 0000000..34d9c82 Binary files /dev/null and b/public/hit2.gif differ diff --git a/public/img.php b/public/img.php new file mode 100644 index 0000000..14961c8 --- /dev/null +++ b/public/img.php @@ -0,0 +1,59 @@ + array($b,$b,$b,$w,$b,$b), + 1 => array($w,$w,$w,$b,$w,$w), + 2 => array($b,$w,$b,$b,$b,$w), + 3 => array($b,$w,$b,$b,$w,$b), + 4 => array($w,$b,$b,$b,$w,$b), + 5 => array($b,$b,$w,$b,$w,$b), + 6 => array($b,$b,$w,$b,$b,$b), + 7 => array($b,$w,$b,$w,$w,$b), + 8 => array($b,$b,$b,$b,$b,$b), + 9 => array($b,$b,$b,$b,$w,$b), + ); + + if($im) + { + for ($index = 0; $index < 10; $index++) { + $block = 0; + if ($index >= 3) $block++; + if ($index >= 6) $block++; + if ($index >= 9) $block++; + + $x = 78 - 5*$index - 2*$block; + $y = 72; + + $digit = array( + imagecolorat($im, $x+1, $y), + imagecolorat($im, $x, $y+1), + imagecolorat($im, $x+3, $y+1), + imagecolorat($im, $x+2, $y+2), + imagecolorat($im, $x, $y+3), + imagecolorat($im, $x+3, $y+3), + ); + + $d = array_search($digit, $digits); + + if ($d !== false) { + $res[] = array_search($digit, $digits); + } + } + } + + return implode('', array_reverse($res)); +} + +for ($index = 0; $index <= 2; $index++) { + print loadGif('/home/web/poi/public/hit'.$index.'.gif'); + print '
'; +} + diff --git a/public/img/vk_logo.png b/public/img/vk_logo.png new file mode 100644 index 0000000..601e28d Binary files /dev/null and b/public/img/vk_logo.png differ diff --git a/public/js/app.js b/public/js/app.js index 9d4c842..15450e7 100644 --- a/public/js/app.js +++ b/public/js/app.js @@ -104,3 +104,20 @@ function showImage(id) $('#imageModal').modal('show'); } + +function addRemoveFavorite(id) +{ + if (user != '0') + { + $.ajax({ + url: "/json/addRemoveFavorites/id/" + id, + success: function(data) { + if (data){ + // Тут переключалку классов звёздочки + $('#myFavoritesButton').toggleClass('glyphicon glyphicon-star-empty').toggleClass('glyphicon glyphicon-star'); + } + }}); + } else { + alert('Для выполнения действия необходимо войти.'); + } +} diff --git a/public/js/map.js b/public/js/map.js index ec317ea..e3e7508 100644 --- a/public/js/map.js +++ b/public/js/map.js @@ -16,9 +16,9 @@ var defaultZoom = 13; categories.im = L.icon({ iconUrl: '/ico/man.png', - iconSize: [32, 37], - iconAnchor: [16, 37], - popupAnchor: [0, 1] + iconSize: [32, 37], + iconAnchor: [16, 37], + popupAnchor: [0, 1] }); // ----------------------------------------------------------------------------- @@ -26,7 +26,7 @@ categories.im = L.icon({ /** * Инициализируем яндекс-карты и узнаём расположение пользователя. */ -ymaps.ready(function(){ +ymaps.ready(function () { lat = ymaps.geolocation.latitude; lng = ymaps.geolocation.longitude; init(lat, lng); @@ -41,11 +41,11 @@ ymaps.ready(function(){ * @returns true */ function init(lat, lng) { - myMap = L.map('map',{zoomControl: false}).setView([lat, lng], defaultZoom); + myMap = L.map('map', {zoomControl: false}).setView([lat, lng], defaultZoom); markers = new L.MarkerClusterGroup({showCoverageOnHover: false, maxClusterRadius: 45}); - layers['quest'] = L.tileLayer('http://otile1.mqcdn.com/tiles/1.0.0/osm/{z}/{x}/{y}.png', {attribution: 'Map data © OpenStreetMap contributors, CC-BY-SA, Imagery © Mapbox',maxZoom: 18}); - layers['osm'] = L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {attribution: 'Map data © OpenStreetMap contributors, CC-BY-SA, Imagery ©',maxZoom: 18}); + layers['quest'] = L.tileLayer('http://otile1.mqcdn.com/tiles/1.0.0/osm/{z}/{x}/{y}.png', {attribution: 'Map data © OpenStreetMap contributors, CC-BY-SA, Imagery © Mapbox', maxZoom: 18}); + layers['osm'] = L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {attribution: 'Map data © OpenStreetMap contributors, CC-BY-SA, Imagery ©', maxZoom: 18}); layers['google'] = new L.Google('HYBRID'); layers['yandexMap'] = new L.Yandex(); layers['yandex'] = new L.Yandex('hybrid'); @@ -53,14 +53,14 @@ function init(lat, lng) { initCategories(); // getPoints внутри - myMap.on('click', function(e) { + myMap.on('click', function (e) { if (!myMap._popup) { if (status == statusHunting) { $('#addPointId').remove(); $('#addPointForm input:text').val(''); $('#addPointForm textarea').val(''); - $("#addPointCategoryId option" ).attr('selected', null); + $("#addPointCategoryId option").attr('selected', null); $('#addPointLat').val(e.latlng.lat); $('#addPointLng').val(e.latlng.lng); @@ -86,15 +86,17 @@ function init(lat, lng) { $("#wayPoints").disableSelection(); $("#imgsContainer").sortable(); - myMap.on('moveend', function(e) { - if (!myMap._popup && $('#boxRoute').css('display') == 'none') - { - history.pushState({}, document.title, "/?lat=" + myMap.getCenter().lat + "&lng=" + myMap.getCenter().lng + "&zoom=" + myMap.getZoom()); - document.title = pointsCount+' или даже больше поводов не сидеть дома'; - } - }); + myMap.on('moveend', function (e) { + if (!myMap._popup && $('#boxRoute').css('display') == 'none') + { + history.pushState({}, document.title, "/?lat=" + myMap.getCenter().lat + "&lng=" + myMap.getCenter().lng + "&zoom=" + myMap.getZoom()); + document.title = pointsCount + ' или даже больше поводов не сидеть дома'; + } + }); - $('.filterSelector').bind('change', function(){filter()}); + $('.filterSelector').bind('change', function () { + filter() + }); return true; } @@ -110,7 +112,9 @@ function constructPoint(data) points[id] = L.marker( [data['lat'], data['lng']], {icon: categories[data['categoryId']], title: data['name'], id: id, categoryId: data['categoryId']} - ).on('click', function(e){showInfo(e.target.options.id);}); + ).on('click', function (e) { + showInfo(e.target.options.id); + }); return points[id]; } @@ -123,7 +127,7 @@ function initPoints() { $.ajax({ url: "/json/points/", - success: function(data) { + success: function (data) { for (var k in data) { markers.addLayer(constructPoint(data[k])); } @@ -160,43 +164,33 @@ function initPoints() */ function showInfo(id) { - marker = points[id]; + marker = points[id]; if (!(id in points) || marker.options.description == undefined) { marker.bindPopup("Загрузка...").openPopup(); $.ajax({ url: "/json/point/id/" + id, - success: function(data) { + success: function (data) { pointsSources[id] = data; - if (typeof(data.images) == 'object') + if (typeof (data.images) == 'object') { - ph = '
'; + photos = '
'; if (data.images.length > 1) - ph += '
+' + (data.photosCount-1) + '
'; + photos += '
+' + (data.photosCount - 1) + '
'; - ph += ''; - ph += '
'; + photos += ''; + photos += '
'; } else { - ph = ''; + photos = ''; } description = '
' + '

' + data.name + '

' + - ph + - '
'; - - if (isAdmin == '1') - { - description = description + '
'; - } + photos; description = description + data.descriptionHtml; //description = description + ' Подробнее...'; @@ -207,17 +201,29 @@ function showInfo(id) } description = description + '
'; - - marker.options.description = description; - marker.bindPopup(marker.options.description, {maxWidth: 500, maxHeight: 300}); - markers.zoomToShowLayer(marker,function() { + description = description + '
'; + description = description + ''; + description = description + ''; + description = description + ''; + description = description + ''; + + if (isAdmin == '1') + { + description = description + ''; + } + description = description + '
'; + + marker.options.description = description; + marker.bindPopup(marker.options.description, {maxWidth: 500, maxHeight: 300}); + + markers.zoomToShowLayer(marker, function () { marker.openPopup(); history.pushState({}, document.title, "/?point=" + id); bounds = myMap.getBounds(); - diff = (bounds._northEast.lat - bounds._southWest.lat)/4; - myMap.setView([points[id]._latlng.lat+diff, points[id]._latlng.lng], myMap.getZoom()); + diff = (bounds._northEast.lat - bounds._southWest.lat) / 4; + myMap.setView([points[id]._latlng.lat + diff, points[id]._latlng.lng], myMap.getZoom()); history.pushState({}, document.title, "/?point=" + id); document.title = data.name; @@ -226,8 +232,8 @@ function showInfo(id) }); } else { bounds = myMap.getBounds(); - diff = (bounds._northEast.lat - bounds._southWest.lat)/4; - myMap.setView([points[id]._latlng.lat+diff, points[id]._latlng.lng], myMap.getZoom()); + diff = (bounds._northEast.lat - bounds._southWest.lat) / 4; + myMap.setView([points[id]._latlng.lat + diff, points[id]._latlng.lng], myMap.getZoom()); history.pushState({}, document.title, "/?point=" + id); document.title = points[id].options.title; @@ -236,11 +242,11 @@ function showInfo(id) function showRandomPoint() { - roundIndex = Math.floor(Math.random()*points.length); + roundIndex = Math.floor(Math.random() * points.length); runner = 0; - for(var key in points) + for (var key in points) { - if(runner++ >= roundIndex) + if (runner++ >= roundIndex) return showInfo(key); } } @@ -253,17 +259,17 @@ function initCategories() { $.ajax({ url: "/json/categories/", - success: function(data) { - for (var k in data) { - categories[data[k]['id']] = L.icon({ - iconUrl: data[k]['icon'], - iconSize: [32, 37], - iconAnchor: [16, 37], - popupAnchor: [0, 1] - }); - } + success: function (data) { + for (var k in data) { + categories[data[k]['id']] = L.icon({ + iconUrl: data[k]['icon'], + iconSize: [32, 37], + iconAnchor: [16, 37], + popupAnchor: [0, 1] + }); + } - initPoints(); + initPoints(); } }); @@ -281,15 +287,15 @@ function searchAdderess() data: { search: $('#addressField').val() }, - success: function(data) + success: function (data) { if (data.lat && data.lng) { myMap.setView([data.lat, data.lng], defaultZoom); L.popup() - .setLatLng([data.lat, data.lng]) - .setContent('Координаты: lat:'+data.lat+' lng:'+data.lng) - .openOn(myMap); + .setLatLng([data.lat, data.lng]) + .setContent('Координаты: lat:' + data.lat + ' lng:' + data.lng) + .openOn(myMap); } else { alert('Ничего не найдено.'); @@ -304,7 +310,7 @@ function searchAdderess() */ function showMeOnTheMap() { - navigator.geolocation.getCurrentPosition(function(pos) { + navigator.geolocation.getCurrentPosition(function (pos) { coords = [pos.coords.latitude, pos.coords.longitude]; myMap.removeLayer(points.im); points.im.setLatLng(coords).addTo(myMap); @@ -321,7 +327,7 @@ function activateAddPoint() $('#addPointButton').toggleClass('active'); if ($('#addPointButton').hasClass('active')) { - $('.extraImage','#imgsContainer').remove(); + $('.extraImage', '#imgsContainer').remove(); addNewImage(); $('#map').css('cursor', 'crosshair'); setStatus(statusHunting) @@ -342,33 +348,33 @@ function activateAddPoint() function addPoint() { $('.form-group').removeClass('has-error'); - if (status != statusSendingToServer) - { + if (status != statusSendingToServer) + { setStatus(statusSendingToServer) id = $('#addPointId').length ? $('#addPointId').val() : 0; hasImages = false; - $("input[name='imgs[]']", '#addPointForm').each(function(){ - if ( $(this).val().length > 10) + $("input[name='imgs[]']", '#addPointForm').each(function () { + if ($(this).val().length > 10) hasImages = true; }); - $("input[name='photos[]']", '#addPointForm').each(function(){ - if ( $(this).val().length > 5) + $("input[name='photos[]']", '#addPointForm').each(function () { + if ($(this).val().length > 5) hasImages = true; }) - $.ajax({ - type: "POST", - url: "/json/addpoint/", - data: { - name: $('#addPointName').val(), - img: hasImages ? 1 : 0, - description: $('#addPointDescription').val(), - categoryId: $('#addPointCategoryId').val(), - source: $('#addPointSource').val(), - lat: $('#addPointLat').val(), - lng: $('#addPointLng').val(), + $.ajax({ + type: "POST", + url: "/json/addpoint/", + data: { + name: $('#addPointName').val(), + img: hasImages ? 1 : 0, + description: $('#addPointDescription').val(), + categoryId: $('#addPointCategoryId').val(), + source: $('#addPointSource').val(), + lat: $('#addPointLat').val(), + lng: $('#addPointLng').val(), id: id - }, - success: function(data) { + }, + success: function (data) { if ($("input[name='photos[]']").length > 0 || $("input[name='imgs[]']").length > 0) { $('').appendTo('#addPointForm').val(data); @@ -376,77 +382,77 @@ function addPoint() } text = id ? 'Точка успешно отредактирована!' : 'Точка успешно добавлена!'; - if ( id ) + if (id) { markers.removeLayer(points[id]); } balloon = L.popup() - .setLatLng([$('#addPointLat').val(), $('#addPointLng').val()]) - .setContent(text) - .openOn(myMap); - setTimeout(function() { - balloon._close(); + .setLatLng([$('#addPointLat').val(), $('#addPointLng').val()]) + .setContent(text) + .openOn(myMap); + setTimeout(function () { + balloon._close(); delete balloon; - }, 2000); + }, 2000); - obj = {}; - obj.id = data; - obj.name = $('#addPointName').val(); - obj.lat = $('#addPointLat').val(); - obj.lng = $('#addPointLng').val(); - obj.categoryIcon = categories[$('#addPointCategoryId').val()].icon; + obj = {}; + obj.id = data; + obj.name = $('#addPointName').val(); + obj.lat = $('#addPointLat').val(); + obj.lng = $('#addPointLng').val(); + obj.categoryIcon = categories[$('#addPointCategoryId').val()].icon; obj.categoryId = $('#addPointCategoryId').val(); - setTimeout(function() { + setTimeout(function () { markers.addLayer(constructPoint(obj)); - }, 2000); + }, 2000); - $('#addPointModal').modal('hide'); + $('#addPointModal').modal('hide'); - // Clear form - $('#addPointForm input').val(''); - $('#addPointForm textarea').val(''); - $('.form-group').removeClass('has-error'); - $('#addPointButton').removeClass('active'); + // Clear form + $('#addPointForm input').val(''); + $('#addPointForm textarea').val(''); + $('.form-group').removeClass('has-error'); + $('#addPointButton').removeClass('active'); $('#addPointId').remove(); - $('#map').css('cursor', 'arrow'); - setStatus(statusReady); + $('#map').css('cursor', 'arrow'); + setStatus(statusReady); - return true; - }, - error: function(data) { - response = data.responseJSON; - message = ''; - for (var k in response) { - if (typeof response[k] !== 'function') { - if (k == 1) - $('#addPointName').parent().addClass('has-error'); - else - if (k == 2) + return true; + }, + error: function (data) { + response = data.responseJSON; + message = ''; + for (var k in response) { + if (typeof response[k] !== 'function') { + if (k == 1) + $('#addPointName').parent().addClass('has-error'); + else + if (k == 2) { - $('.extraImage', '#addPointForm').addClass('has-error'); + $('.extraImage', '#addPointForm').addClass('has-error'); } - else - if (k == 3) - $('#addPointDescription').parent().addClass('has-error'); - else - message += response[k] + '; '; - } - } + else + if (k == 3) + $('#addPointDescription').parent().addClass('has-error'); + else + message += response[k] + '; '; + } + } - if (message != '') - alert(message); + if (message != '') + alert(message); - resetStatus(); - return false; - } - }); - } - else - { - alert ('Точка добавляется, нужно немного подождать.'); - } + resetStatus(); + return false; + } + }); + } + else + { + alert('Точка добавляется, нужно немного подождать.'); + } } /** @@ -460,16 +466,16 @@ function editPoint(id) $('').appendTo('#addPointForm').val(id); $('#addPointName').val(pointsSources[id].name); $('#addPointDescription').val(pointsSources[id].description); - $("#addPointCategoryId option" ).attr('selected', null); - $("#addPointCategoryId option[value='"+pointsSources[id].categoryId+"']" ).attr('selected', 'selected'); + $("#addPointCategoryId option").attr('selected', null); + $("#addPointCategoryId option[value='" + pointsSources[id].categoryId + "']").attr('selected', 'selected'); $('#addPointSource').val(pointsSources[id].source); $('#addPointLat').val(pointsSources[id].lat); $('#addPointLng').val(pointsSources[id].lng); - $('.extraImage','#imgsContainer').remove(); + $('.extraImage', '#imgsContainer').remove(); if (pointsSources[id].images != undefined && pointsSources[id].images.length > 0) { - for(var i=0; i < pointsSources[id].images.length; i++) + for (var i = 0; i < pointsSources[id].images.length; i++) { addNewImage(pointsSources[id].images[i]); } @@ -499,7 +505,7 @@ function setLayer(name) layer = name; myMap.addLayer(layers[layer]); $('.layers').removeClass('selected'); - $('.'+layer+'Layer').addClass('selected'); + $('.' + layer + 'Layer').addClass('selected'); $.cookie('mapLayer', layer); } @@ -512,11 +518,11 @@ function closePopup() function filter() { var selected = new Array(); - $('.filterSelector:checked').each(function(i, e){ + $('.filterSelector:checked').each(function (i, e) { selected.push($(e).val()); }); - for(var key in points) + for (var key in points) { if (selected.length == 0 || points[key].options.categoryId == undefined || selected.indexOf(points[key].options.categoryId) != -1) {