Лайки для точек
This commit is contained in:
parent
e378ee1b04
commit
46c3224370
|
|
@ -68,6 +68,7 @@ class JsonController extends Controller
|
||||||
$point->categoryName = $categories[$point->categoryId]['name'];
|
$point->categoryName = $categories[$point->categoryId]['name'];
|
||||||
$point->photosCount = $photosCount;
|
$point->photosCount = $photosCount;
|
||||||
$point->inFavorites = Favorite::model()->checkIsMy($id);
|
$point->inFavorites = Favorite::model()->checkIsMy($id);
|
||||||
|
$point->iLike = Like::model()->checkIsMy($id);
|
||||||
|
|
||||||
self::renderPartial('json.php', $point->getValues());
|
self::renderPartial('json.php', $point->getValues());
|
||||||
} else
|
} else
|
||||||
|
|
@ -328,6 +329,16 @@ class JsonController extends Controller
|
||||||
self::renderPartial('json.php', Helper::boolval(Favorite::addRemove($id)));
|
self::renderPartial('json.php', Helper::boolval(Favorite::addRemove($id)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static function actionAddRemoveLike()
|
||||||
|
{
|
||||||
|
$id = (int) App::getParam('id');
|
||||||
|
if (!$id || !App::$user)
|
||||||
|
{
|
||||||
|
App::error404();
|
||||||
|
}
|
||||||
|
self::renderPartial('json.php', Helper::boolval(Like::addRemove($id)));
|
||||||
|
}
|
||||||
|
|
||||||
static function actionSearch()
|
static function actionSearch()
|
||||||
{
|
{
|
||||||
$search = isset($_GET['query']) ? $_GET['query'] : '';
|
$search = isset($_GET['query']) ? $_GET['query'] : '';
|
||||||
|
|
|
||||||
|
|
@ -44,8 +44,8 @@ class PageController extends Controller
|
||||||
{
|
{
|
||||||
self::$layout = 'layoutPage.php';
|
self::$layout = 'layoutPage.php';
|
||||||
|
|
||||||
$id = (int) App::getParam('id');
|
$pointId = (int) App::getParam('id');
|
||||||
if ($id)
|
if ($pointId)
|
||||||
{
|
{
|
||||||
self::addScript('/js/jquery-2.1.0.min.js');
|
self::addScript('/js/jquery-2.1.0.min.js');
|
||||||
self::addScript('/js/jquery-ui-1.10.4.custom.min.js');
|
self::addScript('/js/jquery-ui-1.10.4.custom.min.js');
|
||||||
|
|
@ -59,7 +59,7 @@ class PageController extends Controller
|
||||||
self::addStyle('/css/bootstrap-theme.min.css');
|
self::addStyle('/css/bootstrap-theme.min.css');
|
||||||
self::addStyle('/css/fotorama.css');
|
self::addStyle('/css/fotorama.css');
|
||||||
|
|
||||||
$point = Point::model()->getByPK($id);
|
$point = Point::model()->getByPK($pointId);
|
||||||
$point->descriptionHtml = nl2br($point->description);
|
$point->descriptionHtml = nl2br($point->description);
|
||||||
$point->name = htmlspecialchars($point->name);
|
$point->name = htmlspecialchars($point->name);
|
||||||
App::setConfig('title', $point->name. ' - wikipoints.ru');
|
App::setConfig('title', $point->name. ' - wikipoints.ru');
|
||||||
|
|
@ -71,7 +71,7 @@ class PageController extends Controller
|
||||||
|
|
||||||
$randomPoint = Point::model()->getRandom();
|
$randomPoint = Point::model()->getRandom();
|
||||||
$similarPoints = Point::model()->getAll(array('where' => 'categoryId = '.$point->categoryId.' AND `id` <> '.$point->id.' ORDER BY RAND() LIMIT 6;'));
|
$similarPoints = Point::model()->getAll(array('where' => 'categoryId = '.$point->categoryId.' AND `id` <> '.$point->id.' ORDER BY RAND() LIMIT 6;'));
|
||||||
$closestPoints = Point::model()->getClosestPoints($id);
|
$closestPoints = Point::model()->getClosestPoints($pointId);
|
||||||
|
|
||||||
self::render('point.php', array(
|
self::render('point.php', array(
|
||||||
'point' => $point,
|
'point' => $point,
|
||||||
|
|
@ -80,6 +80,8 @@ class PageController extends Controller
|
||||||
'closestPoints' => $closestPoints,
|
'closestPoints' => $closestPoints,
|
||||||
'categories' => $categories,
|
'categories' => $categories,
|
||||||
'photos' => $point->photos,
|
'photos' => $point->photos,
|
||||||
|
'countInFavs' => Favorite::model()->countInFavs($pointId),
|
||||||
|
'countLikes' => Like::model()->countLikes($pointId),
|
||||||
));
|
));
|
||||||
} else
|
} else
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,11 @@ class Favorite extends Model
|
||||||
return new self();
|
return new self();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Добавляет точку в избранное если её там нет и удаляет - если есть.
|
||||||
|
* @param integer $pointId
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
public static function addRemove($pointId)
|
public static function addRemove($pointId)
|
||||||
{
|
{
|
||||||
if (!App::$user || !App::$user->id || !$pointId)
|
if (!App::$user || !App::$user->id || !$pointId)
|
||||||
|
|
@ -32,6 +37,10 @@ class Favorite extends Model
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Возвращает все мои точки из избранного
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
public function getAllMy()
|
public function getAllMy()
|
||||||
{
|
{
|
||||||
if (!App::$user || !App::$user->id)
|
if (!App::$user || !App::$user->id)
|
||||||
|
|
@ -40,6 +49,11 @@ class Favorite extends Model
|
||||||
return $this->getAll(array('where' => '`userId` = ' . (int) App::$user->id));
|
return $this->getAll(array('where' => '`userId` = ' . (int) App::$user->id));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Эта точка в моём избранном?
|
||||||
|
* @param integet $pointId
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
public function checkIsMy($pointId)
|
public function checkIsMy($pointId)
|
||||||
{
|
{
|
||||||
if (!App::$user || !App::$user->id || !$pointId)
|
if (!App::$user || !App::$user->id || !$pointId)
|
||||||
|
|
@ -48,4 +62,9 @@ class Favorite extends Model
|
||||||
return Helper::boolval($this->getAll(array('where' => '`userId` = ' . (int) App::$user->id . ' AND `pointId` = ' . (int) $pointId)));
|
return Helper::boolval($this->getAll(array('where' => '`userId` = ' . (int) App::$user->id . ' AND `pointId` = ' . (int) $pointId)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function countInFavs($pointId)
|
||||||
|
{
|
||||||
|
return count($this->getAll(array('where' => '`pointId` = ' . (int) $pointId)));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,75 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
class Like extends Model
|
||||||
|
{
|
||||||
|
|
||||||
|
function __construct($fromArray = array())
|
||||||
|
{
|
||||||
|
$this->_tableName_ = 'likes';
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Добавляет точку в понравившиеся если её там нет и удаляет - если есть.
|
||||||
|
* @param integer $pointId
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
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 Helper::boolval(Like::model()->delete($res->id));
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
return Like::model()->add(array('userId' => App::$user->id, 'pointId' => $pointId));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Возвращает все понравившиеся мне точки
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
public function getAllMy()
|
||||||
|
{
|
||||||
|
if (!App::$user || !App::$user->id)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return $this->getAll(array('where' => '`userId` = ' . (int) App::$user->id));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Эта точка мне нравится?
|
||||||
|
* @param integet $pointId
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
public function checkIsMy($pointId)
|
||||||
|
{
|
||||||
|
if (!App::$user || !App::$user->id || !$pointId)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return Helper::boolval($this->getAll(array('where' => '`userId` = ' . (int) App::$user->id . ' AND `pointId` = ' . (int) $pointId)));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Кол-во лайков точки
|
||||||
|
* @param type $pointId
|
||||||
|
* @return type
|
||||||
|
*/
|
||||||
|
public function countLikes($pointId)
|
||||||
|
{
|
||||||
|
return count($this->getAll(array('where' => '`pointId` = ' . (int) $pointId)));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -86,14 +86,14 @@
|
||||||
|
|
||||||
<hr/>
|
<hr/>
|
||||||
<p>
|
<p>
|
||||||
[ <span class="glyphicon glyphicon-star"></span> 13 - в закладках ]
|
[ <span class="glyphicon glyphicon-star"></span> <?= $countInFavs ?> - в закладках ]
|
||||||
[ <span class="glyphicon glyphicon-thumbs-up"></span> 120 - нравится ]
|
[ <span class="glyphicon glyphicon-thumbs-up"></span> <?= $countLikes ?> - нравится ]
|
||||||
|
|
||||||
[ <span class="glyphicon glyphicon-star"></span>
|
<!-- [ <span class="glyphicon glyphicon-star"></span>
|
||||||
<span class="glyphicon glyphicon-star"></span>
|
<span class="glyphicon glyphicon-star"></span>
|
||||||
<span class="glyphicon glyphicon-star"></span>
|
<span class="glyphicon glyphicon-star"></span>
|
||||||
<span class="glyphicon glyphicon-star"></span>
|
<span class="glyphicon glyphicon-star"></span>
|
||||||
<span class="glyphicon glyphicon-star-empty"></span> ]
|
<span class="glyphicon glyphicon-star-empty"></span> ] -->
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-md-2" style="width: 250px!important;">
|
<div class="col-md-2" style="width: 250px!important;">
|
||||||
|
|
|
||||||
|
|
@ -127,6 +127,22 @@ function addRemoveFavorite(id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function addRemoveLike(id)
|
||||||
|
{
|
||||||
|
if (user != '0')
|
||||||
|
{
|
||||||
|
$.ajax({
|
||||||
|
url: "/json/addRemoveLike/id/" + id,
|
||||||
|
success: function(data) {
|
||||||
|
if (data){
|
||||||
|
$('#myLikesButton').toggleClass('glyphicon-thumbs-up').toggleClass('glyphicon-ok');
|
||||||
|
}
|
||||||
|
}});
|
||||||
|
} else {
|
||||||
|
$('#loginModal').modal('show');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
window.addEventListener('popstate', function(e)
|
window.addEventListener('popstate', function(e)
|
||||||
{
|
{
|
||||||
if (typeof(e.state) == 'object' && e.state != null)
|
if (typeof(e.state) == 'object' && e.state != null)
|
||||||
|
|
|
||||||
|
|
@ -206,7 +206,7 @@ function showInfo(id)
|
||||||
// description += '<a type="button" class="btn btn-default" href="/page/point/id/' + id + '"><span class="glyphicon glyphicon-eye-open"></span> <span class="label">Подробнее</span></a>';
|
// description += '<a type="button" class="btn btn-default" href="/page/point/id/' + id + '"><span class="glyphicon glyphicon-eye-open"></span> <span class="label">Подробнее</span></a>';
|
||||||
description += '<button type="button" class="btn btn-default" onclick="addToRoute(' + id + ')"><span class="glyphicon glyphicon-map-marker"></span> <span class="label">В маршрут</span></button>';
|
description += '<button type="button" class="btn btn-default" onclick="addToRoute(' + id + ')"><span class="glyphicon glyphicon-map-marker"></span> <span class="label">В маршрут</span></button>';
|
||||||
// description += '<button type="button" class="btn btn-default"><span class="glyphicon glyphicon-ok"></span> <span class="label">Был здесь</span></button>';
|
// description += '<button type="button" class="btn btn-default"><span class="glyphicon glyphicon-ok"></span> <span class="label">Был здесь</span></button>';
|
||||||
// description += '<button type="button" class="btn btn-default"><span class="glyphicon glyphicon-thumbs-up"></span> <span class="label">Нравится</span></button>';
|
description += '<button type="button" class="btn btn-default" onclick="addRemoveLike(' + id + ')"><span id="myLikesButton" class="glyphicon glyphicon-' + (data.iLike ? 'ok' : 'thumbs-up') + '"></span> <span class="label">Нравится</span></button>';
|
||||||
description += '<button type="button" class="btn btn-default" onclick="addRemoveFavorite(' + id + ')"><span id="myFavoritesButton" class="glyphicon glyphicon-star' + (data.inFavorites ? '' : '-empty') + ' "></span> <span class="label">Хочу посетить</span></button>';
|
description += '<button type="button" class="btn btn-default" onclick="addRemoveFavorite(' + id + ')"><span id="myFavoritesButton" class="glyphicon glyphicon-star' + (data.inFavorites ? '' : '-empty') + ' "></span> <span class="label">Хочу посетить</span></button>';
|
||||||
|
|
||||||
if (isAdmin == '1')
|
if (isAdmin == '1')
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue