diff --git a/ground/controllers/PageController.php b/ground/controllers/PageController.php index 3a41448..e045028 100644 --- a/ground/controllers/PageController.php +++ b/ground/controllers/PageController.php @@ -52,10 +52,12 @@ class PageController extends Controller self::addScript('/js/bootstrap.min.js'); self::addScript('/js/app.js?ver=' . App::getConfig('version')); + self::addScript('/js/fotorama.js'); self::addStyle('/css/style.css?ver=' . App::getConfig('version')); self::addStyle('/css/bootstrap.min.css'); self::addStyle('/css/bootstrap-theme.min.css'); + self::addStyle('/css/fotorama.css'); $point = Point::model()->getByPK($id); $point->descriptionHtml = nl2br($point->description); @@ -63,11 +65,15 @@ class PageController extends Controller $categories = Category::model()->getAll(array('order' => 'ord ASC', 'asArray' => true)); - $point->categoryIcon = $categories[$point->categoryId]->icon; - $point->categoryName = $categories[$point->categoryId]->name; + $point->categoryIcon = $categories[$point->categoryId]['icon']; + $point->categoryName = $categories[$point->categoryId]['name']; + + $randomPoint = Point::model()->getRandom(); +// print_r($randomPoint->name); self::render('point.php', array( 'point' => $point, + 'randomPoint' => $randomPoint, 'categories' => $categories, 'photos' => $point->photos, )); diff --git a/ground/models/Point.php b/ground/models/Point.php index 98f2d16..a941300 100644 --- a/ground/models/Point.php +++ b/ground/models/Point.php @@ -21,12 +21,33 @@ class Point extends Model $img = $this->img; if ($img == '') { - $img = array_shift($this->photos); - $img = '/photos/middle/' . $img->name; + $photos = $this->photos; + $img = array_shift($photos); + + if (!$img) + return null; + + $img = '/photos/small/'.$img->name; } return $img; } + public function getRandom() + { + $res = App::DB()->query("SELECT FLOOR(RAND() * COUNT(*)) AS `offset` FROM `" . $this->_tableName_ . "`")->fetch(PDO::FETCH_ASSOC); + $offset = $res['offset']; + + $res = App::DB()->query('SELECT `id` FROM ' . $this->_tableName_ . ' LIMIT ' . $offset . ',1;')->fetch(PDO::FETCH_ASSOC); + $pointId = $res['id']; + + return $this->getByPK($pointId); + } + + public function getCountByUser($userId) + { + $res = App::DB()->query('SELECT count(`id`) AS `cnt` FROM ' . $this->_tableName_ . ' WHERE `author` = ' . $userId . ' ;')->fetch(PDO::FETCH_ASSOC); + return $res['cnt']; + } } diff --git a/ground/models/User.php b/ground/models/User.php index ab9119e..940cc99 100644 --- a/ground/models/User.php +++ b/ground/models/User.php @@ -30,5 +30,10 @@ class User extends Model return false; } } + + function getPointsCount() + { + return Point::model()->getCountByUser($this->id); + } } diff --git a/ground/views/layoutPage.php b/ground/views/layoutPage.php index 3e5e011..1f5bfb3 100644 --- a/ground/views/layoutPage.php +++ b/ground/views/layoutPage.php @@ -3,66 +3,31 @@