From: <al...@us...> - 2008-10-21 16:56:06
|
Revision: 744 http://sciret.svn.sourceforge.net/sciret/?rev=744&view=rev Author: alpeb Date: 2008-10-21 16:56:02 +0000 (Tue, 21 Oct 2008) Log Message: ----------- limit the dropdown favorites to 7 items. If more, show link to see full list Modified Paths: -------------- trunk/flowMap.php trunk/models/FavoriteGateway.php trunk/templates/FavoritesDropdown.tpl trunk/views/GetFavoritesDropdown.php Added Paths: ----------- trunk/templates/ViewAllFavorites.tpl trunk/views/ViewAllFavorites.php Modified: trunk/flowMap.php =================================================================== --- trunk/flowMap.php 2008-10-21 16:28:21 UTC (rev 743) +++ trunk/flowMap.php 2008-10-21 16:56:02 UTC (rev 744) @@ -41,6 +41,7 @@ 'ViewBookmarkDetails' => array(User::ROLE_ANONYMOUS, true, true, false, true), 'ViewRelatedArticles' => array(User::ROLE_ANONYMOUS, true, true, false, true), 'GetFavoritesDropdown' => array(User::ROLE_REGISTERED, true, true, false), + 'ViewAllFavorites' => array(User::ROLE_REGISTERED, true, true, true, false), 'GetTodosDropdown' => array(User::ROLE_REGISTERED, true, true, false), 'EditTodo' => array(User::ROLE_REGISTERED, true, false, false), 'Upgrade' => array(User::ROLE_ANONYMOUS, true, true, true, false), Modified: trunk/models/FavoriteGateway.php =================================================================== --- trunk/models/FavoriteGateway.php 2008-10-21 16:28:21 UTC (rev 743) +++ trunk/models/FavoriteGateway.php 2008-10-21 16:56:02 UTC (rev 744) @@ -12,25 +12,42 @@ class FavoriteGateway { var $favorites; - function getFavorites($userId) { - if (!isset($this->favorites)) { - $this->favorites = array(); + public function getNumTotalFavorites() + { + return $this->_numTotalFavorites; + } - $query = 'SELECT favorite_id, user_id, favorite_type, art_id, cat_id, search_str FROM favorites WHERE user_id = ?'; - $result = DB::getInstance()->query($query, $userId); + public function getFavorites($userId, $limit = false) + { + $this->favorites = array(); - while ($row = $result->fetch()) { - $favorite = new Favorite; - $favorite->setId($row['favorite_id']); - $favorite->setUserId($row['user_id']); - $favorite->setType($row['favorite_type']); - $favorite->setArtId($row['art_id']); - $favorite->setCatId($row['cat_id']); - $favorite->setSearchStr($row['search_str']); - $this->favorites[] = $favorite; - } + $query = 'SELECT SQL_CALC_FOUND_ROWS favorite_id, user_id, favorite_type, art_id, cat_id, search_str FROM favorites WHERE user_id = ?'; + if ($limit !== false) { + $query .= ' LIMIT ' . (int)$limit; } + $result = DB::getInstance()->query($query, $userId); + while ($row = $result->fetch()) { + $favorite = new Favorite; + $favorite->setId($row['favorite_id']); + $favorite->setUserId($row['user_id']); + $favorite->setType($row['favorite_type']); + $favorite->setArtId($row['art_id']); + $favorite->setCatId($row['cat_id']); + $favorite->setSearchStr($row['search_str']); + $this->favorites[] = $favorite; + } + + if ($limit !== false) { + $query2 = 'SELECT FOUND_ROWS()'; + $result2 = DB::getInstance()->query($query2); + $rows = $result2->fetch(); + $this->_numTotalFavorites = $rows['FOUND_ROWS()']; + } else { + $this->_numTotalFavorites = $result->rowCount(); + } + + return $this->favorites; } Modified: trunk/templates/FavoritesDropdown.tpl =================================================================== --- trunk/templates/FavoritesDropdown.tpl 2008-10-21 16:28:21 UTC (rev 743) +++ trunk/templates/FavoritesDropdown.tpl 2008-10-21 16:56:02 UTC (rev 744) @@ -22,6 +22,11 @@ <!-- END favoriteItem_block --> </ul> <!-- END favoritesList_block --> + <!-- BEGIN seeAllFavorites_block --> + <div style="text-align:right; margin-bottom:5px"> + <a href="{viewAllFavoritesLink}">[l]View all[/l]</a> + </div> + <!-- END seeAllFavorites_block --> <!-- BEGIN noFavorites_block --> <div class="headerLinks" style="text-align:center">[l]You have no Favorites[/l]</div> <!-- END noFavorites_block --> Added: trunk/templates/ViewAllFavorites.tpl =================================================================== --- trunk/templates/ViewAllFavorites.tpl (rev 0) +++ trunk/templates/ViewAllFavorites.tpl 2008-10-21 16:56:02 UTC (rev 744) @@ -0,0 +1,23 @@ +<!-- +/* +* @copyright Copyright (C) 2005-2008 Keyboard Monkeys Ltd. http://www.kb-m.com +* @license http://www.fsf.org/copyleft/lgpl.html GNU Lesser General Public License +* @author Alejandro Pedraza +* @since Sciret 1.2 +* @package Sciret +* @packager Keyboard Monkeys +*/ +--> + +<h1>[l]Your Favorites[/l]</h1> + +<ul class="headerLinks"> + <!-- BEGIN favoriteItem_block --> + <li> + <!-- BEGIN favoriteItem_img_block --> + <img src="images/{articleImage}" /> + <!-- END favoriteItem_img_block --> + <a href="{favoriteItemURL}">{favoriteItemLabel}</a> + </li> + <!-- END favoriteItem_block --> +</ul> Modified: trunk/views/GetFavoritesDropdown.php =================================================================== --- trunk/views/GetFavoritesDropdown.php 2008-10-21 16:28:21 UTC (rev 743) +++ trunk/views/GetFavoritesDropdown.php 2008-10-21 16:56:02 UTC (rev 744) @@ -11,16 +11,18 @@ require 'views/View.php'; -define('TITLE_LENGTH', 35); - class GetFavoritesDropdown extends View { + const TITLE_LENGTH = 35; + const NUM_ITEMS = 7; + var $categories; function dispatch() { $this->tpl->set_file('favoritesDropdown', 'FavoritesDropdown.tpl'); $this->tpl->set_block('favoritesDropdown', 'favoritesList_block', 'favoritesList'); + $this->tpl->set_block('favoritesDropdown', 'seeAllFavorites_block', 'seeAllFavorites'); $this->tpl->set_block('favoritesList_block', 'favoriteItem_block', 'favoriteItem'); $this->tpl->set_block('favoriteItem_block', 'favoriteItem_img_block', 'favoriteItem_img'); $this->tpl->set_block('favoritesDropdown', 'noFavorites_block', 'noFavorites'); @@ -28,15 +30,15 @@ $favoriteGateway = new FavoriteGateway; $thereAreFavorites = false; $firstIteration = true; - foreach ($favoriteGateway->getFavorites($this->user->id) as $favorite) { + foreach ($favoriteGateway->getFavorites($this->user->id, self::NUM_ITEMS) as $favorite) { $thereAreFavorites = true; switch($favorite->getType()) { case FAVORITE_TYPE_ARTICLE: require_once 'models/Article.php'; $article = new Article($favorite->getArtId()); - if (strlen($article->getTitle()) > TITLE_LENGTH) { - $title = substr($article->getTitle(), 0, TITLE_LENGTH - 3) . '...'; + if (strlen($article->getTitle()) > self::TITLE_LENGTH) { + $title = substr($article->getTitle(), 0, self::TITLE_LENGTH - 3) . '...'; } else { $title = $article->getTitle(); } @@ -71,6 +73,14 @@ $firstIteration = false; } + if ($favoriteGateway->getNumTotalFavorites() > self::NUM_ITEMS) { + $this->tpl->set_var('viewAllFavoritesLink', Library::getLink(array( + 'view' => 'ViewAllFavorites'))); + $this->tpl->parse('seeAllFavorites', 'seeAllFavorites_block'); + } else { + $this->tpl->set_var('seeAllFavorites', ''); + } + if ($thereAreFavorites) { $this->tpl->parse('favoritesList', 'favoritesList_block'); $this->tpl->set_var('noFavorites', ''); Added: trunk/views/ViewAllFavorites.php =================================================================== --- trunk/views/ViewAllFavorites.php (rev 0) +++ trunk/views/ViewAllFavorites.php 2008-10-21 16:56:02 UTC (rev 744) @@ -0,0 +1,60 @@ +<?php + +/* +* @copyright Copyright (C) 2005-2008 Keyboard Monkeys Ltd http://www.kb-m.com +* @license http://www.fsf.org/copyleft/lgpl.html GNU Lesser General Public License +* @author Alejandro Pedraza +* @since Sciret 1.0 +* @package Sciret +* @packager Keyboard Monkeys +*/ + +require 'views/View.php'; + +class ViewAllFavorites extends View +{ + public function dispatch() + { + $this->tpl->set_file('viewAllFavorites', 'ViewAllFavorites.tpl'); + $this->tpl->set_block('viewAllFavorites', 'favoriteItem_block', 'favoriteItem'); + $this->tpl->set_block('favoriteItem_block', 'favoriteItem_img_block', 'favoriteItem_img'); + + $favoriteGateway = new FavoriteGateway; + $firstIteration = true; + foreach ($favoriteGateway->getFavorites($this->user->id) as $favorite) { + switch($favorite->getType()) { + case FAVORITE_TYPE_ARTICLE: + $article = new Article($favorite->getArtId()); + $title = $article->getTitle(); + $this->tpl->set_var(array( + 'articleImage' => $article->isBookmark()? 'bookmark.png' : 'article.png', + 'favoriteItemLabel' => $title, + 'favoriteItemURL' => Library::getLink(array('view' => 'ViewArticle', 'id' => $article->getId())), + )); + $this->tpl->parse('favoriteItem_img', 'favoriteItem_img_block'); + break; + case FAVORITE_TYPE_LOCATION: + unset($this->tPath); + $categoryGateway = new CategoryGateway(); + $this->categories = $categoryGateway->getCategories(); // needed in _getCategoryPath() + $this->tpl->set_var(array( + 'favoriteItemLabel' => $this->_getCategoryPath($favorite->getCatId(), 'MainView', false), + 'favoriteItemURL' => Library::getLink(array('view' => 'MainView', 'catId' => $favorite->getCatId())), + 'favoriteItem_img' => '', + )); + break; + case FAVORITE_TYPE_SEARCHRESULT: + $this->tpl->set_var(array( + 'favoriteItemLabel' => $this->user->lang('Search:') . ' ' . $favorite->getSearchStr(), + 'favoriteItemURL' => Library::getLink(array('view' => 'SearchResults', 'query' => urlencode($favorite->getSearchStr()))), + 'favoriteItem_img' => '', + )); + break; + } + $this->tpl->parse('favoriteItem', 'favoriteItem_block', !$firstIteration); + $firstIteration = false; + } + + $this->tpl->pparse('out', 'viewAllFavorites'); + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |