ADD избранное на отдельной странице

This commit is contained in:
Krivchikov Dmitry 2015-12-05 11:25:45 +03:00
parent d9cb8f73f1
commit 8c24272371
4 changed files with 68 additions and 0 deletions

View File

@ -89,4 +89,20 @@ class UserController extends Controller
'randomPoint' => $randomPoint, 'randomPoint' => $randomPoint,
)); ));
} }
function actionFavorites()
{
if (!App::$user) {
App::redirect('/');
}
$randomPoint = Point::model()->getRandom();
$randomPoint->description = mb_substr($randomPoint->description, 0, 400, 'UTF-8');
$randomPoint->description = Helper::replaceLinks($randomPoint->description);
self::render('user/favorites.php', array(
'favorites' => Favorite::model()->getAllMy(),
'randomPoint' => $randomPoint,
));
}
} }

View File

@ -2,6 +2,7 @@
class Category extends Model class Category extends Model
{ {
private static $categories = NULL;
function __construct($fromArray = array()) function __construct($fromArray = array())
{ {
@ -15,4 +16,13 @@ class Category extends Model
return new self(); return new self();
} }
static function getIcoById($id)
{
if (self::$categories === NULL) {
self::$categories = self::model()->getAll(array('asArray'=>true));
}
return (isset(self::$categories[$id])) ? self::$categories[$id]['icon'] : NULL;
}
} }

View File

@ -109,6 +109,8 @@ if (App::$user) {
<h3>Хочу посетить</h3> <h3>Хочу посетить</h3>
<div id="favorites"> <div id="favorites">
<?php if ($favorites): ?> <?php if ($favorites): ?>
<a href="/user/favorites/"><span class="glyphicon glyphicon-star" aria-hidden="true"></span> На отдельной странице</a>
<hr/>
<?php foreach ($favorites as $favorite) : ?> <?php foreach ($favorites as $favorite) : ?>
<a onclick="showInfo(<?= $favorite->pointId ?>)" class="btn btn-link"><?= $favorite->point->name ?></a><br/> <a onclick="showInfo(<?= $favorite->pointId ?>)" class="btn btn-link"><?= $favorite->point->name ?></a><br/>
<?php endforeach; ?> <?php endforeach; ?>

40
views/user/favorites.php Normal file
View File

@ -0,0 +1,40 @@
<div id="pageSmoothBackground" style="background-image: url(<?= $randomPoint->getImg('middle') ?>);"></div>
<div class="container" style="background-color: rgba(255,255,255, 0.8);margin-top: -10px;padding-bottom: 30px;">
<div class="row">
<div class="col-md-12">
<h1 style="text-align: right;">Ваши избраные точки</h1>
<div class="coords-container">
Перейти: <a href="/">на карту</a>
<?php if (App::getParam('user')): ?>
/ <a href="/user/<?=$user->id?>">страница <?=$user->nick?></a>.
<?php endif; ?>
</div>
<div style="text-align: justify;">
<div class="pointsWall">
<?php foreach ($favorites as $favorite): $point = $favorite->point;?>
<a href="/point/<?= $point->id ?>">
<div style="background-image: url('<?= $point->img ?>');" class="point">
<span class="header">
<img src="<?= Category::getIcoById($point->categoryId) ?>" />
<?= $point->name ?>
</span>
</div>
</a>
<?php endforeach; ?>
</div>
</div>
</div>
</div>
<hr/>
<div class="row">
<div class="col-md-12">
<a href="/point/<?= $randomPoint->id ?>" style="float: left; margin: 0 20px 0 0;"><img src="<?= $randomPoint->getImg() ?>" style="width: 200px;"/></a>
<h3 style="margin-top: 0;">Это интересно: <?= $randomPoint->name ?></h3>
<p>
<?= mb_substr($randomPoint->description, 0, 400, 'UTF-8') ?>
<a class="" href="/point/<?= $randomPoint->id ?>" role="button"><nobr> читать далее »</nobr></a>
</p>
</div>
</div>
</div>