fix for #1153, a couple of improvements and fixed bugs

This commit is contained in:
Thomas Citharel 2015-03-13 16:49:20 +01:00
parent ab87a7fe69
commit f76dab12c9
3 changed files with 55 additions and 12 deletions

View file

@ -411,10 +411,22 @@ class Database {
return $count;
}
public function getRandomId($user_id) {
public function getRandomId($user_id, $view) {
$random = (STORAGE == 'mysql') ? 'RAND()' : 'RANDOM()';
$sql = "SELECT id FROM entries WHERE user_id=? ORDER BY ". $random . " LIMIT 1";
$params = array($user_id);
switch ($view) {
case 'archive':
$sql = "SELECT id FROM entries WHERE user_id=? AND is_read=? ORDER BY ". $random . " LIMIT 1";
$params = array($user_id,1);
break;
case 'fav':
$sql = "SELECT id FROM entries WHERE user_id=? AND is_fav=? ORDER BY ". $random . " LIMIT 1";
$params = array($user_id,1);
break;
default:
$sql = "SELECT id FROM entries WHERE user_id=? AND is_read=? ORDER BY ". $random . " LIMIT 1";
$params = array($user_id,0);
break;
}
$query = $this->executeQuery($sql, $params);
$id = $query->fetchAll();

View file

@ -406,8 +406,9 @@ class Poche
/* For some unknown reason I can't get displayView() to work here (it redirects to home view afterwards). So here's a dirty fix which redirects directly to URL */
case 'random':
Tools::logm('get a random article');
if ($this->store->getRandomId($this->user->getId())) {
$id_array = $this->store->getRandomId($this->user->getId());
$view = $_GET['view'];
if ($this->store->getRandomId($this->user->getId(),$view)) {
$id_array = $this->store->getRandomId($this->user->getId(),$view);
$id = $id_array[0];
Tools::redirect('?view=view&id=' . $id[0]);
Tools::logm('got the article with id ' . $id[0]);
@ -522,7 +523,7 @@ class Poche
$this->pagination->page_links('?view=' . $view . '?search=' . $search . '&sort=' . $_SESSION['sort'] . '&' ));
$tpl_vars['page_links'] = $page_links;
$tpl_vars['nb_results'] = $count;
$tpl_vars['searchterm'] = $search;
$tpl_vars['search_term'] = $search;
}
break;
case 'view':
@ -578,6 +579,7 @@ class Poche
'page_links' => '',
'nb_results' => '',
'listmode' => (isset($_COOKIE['listmode']) ? true : false),
'view' => $view,
);
//if id is given - we retrieve entries by tag: id is tag id

View file

@ -15,8 +15,15 @@
{% if tag %}
<h3>{% trans "Tag" %}: <b>{{ tag.value }}</b></h3>
{% endif %}
{% if entries is empty %}
<div class="messages warning"><p>{% trans "No articles found." %}</p></div>
{% if entries is empty%}
<div class="messages warning"><p>
{% if view == 'home' %}{% trans "No articles unread. Good job !" %}
{% elseif view == 'fav' %}{% trans "No articles favourited" %}
{% elseif view == 'archive' %}{% trans "No articles marked as read" %}
{% elseif view == 'tags' %}{% trans "No articles with this tag found" %}
{% elseif search_term is defined %} {% trans %}No articles found for « {{ search_term }} »{% endtrans %}
{% else %}{% trans "No articles found" %}{% endif %}
</p></div>
{% else %}
<div>
{% include '_display-mode.twig' %}
@ -25,15 +32,35 @@
{% block pager %}
{% if nb_results > 1 %}
<div class="results">
<div class="nb-results">{{ nb_results }} {% trans "results" %}{% if search_term is defined %} {% trans %}found for « {{ search_term }} »{% endtrans %}{% endif %} <a href="?action=random" class="icon icon-random"><span> {% trans "random" %}</span></a></div>
<div class="nb-results">
{% if view == 'home' %}
{{ nb_results }} {% trans "articles unread" %}
{% elseif view == 'fav' %}
{{ nb_results }} {% trans "articles favourited" %}
{% elseif view == 'archive' %}
{{ nb_results }} {% trans "articles marked as read" %}
{% elseif view == 'tag' %}
{{ nb_results }} {% trans "articles with this tag" %}
{% elseif search_term is defined %}{{ nb_results }}
{% trans %}articles found for « {{ search_term }} »{% endtrans %}
{% else %}
{{ nb_results }} {% trans "articles" %}
{% endif %}
{% if view == 'home' or view == 'fav' or view == 'archive' %}
<a href="?action=random&amp;view={{ view }}" class="icon icon-random"><span> {% trans "random" %}</span></a>{% endif %}
</div>
{{ page_links | raw }}
</div>
{% elseif nb_results == 1 %}
{% if search_term is defined %}
<div class="results">
<div class="nb-results">{% trans "Only one result found for " %} « {{ search_term }} »</div>
<div class="nb-results">
{% if view == 'home' %}{% trans "Only one article unread. Way to go !" %}
{% elseif view == 'fav' %}{% trans "Just one article favourited" %}
{% elseif view == 'archive' %}{% trans "One article marked as read" %}
{% elseif view == 'tag' %}{% trans "One article with this tag" %}
{% elseif search_term is defined %}{% trans %}Only one result found for « {{ search_term }} »{% endtrans %}
{% else %}{% trans "One article found" %}{% endif %}</div>
</div>
{% endif %}
{% endif %}
{% endblock %}
<div id="list-entries" class="list-entries">
@ -64,6 +91,7 @@
{% if tag %}<a title="{% trans "Mark all articles from this tag as read" %}" href="./?action=toggle_archive&amp;tag_id={{ tag.id }}">{% trans "Mark all articles from this tag as read" %}</a><br />{% endif %}
{% if entries is not empty %}
{% if tag %}
{% if constant('EPUB') == 1 %}<a title="{% trans "Download the articles from this tag in an epub file" %}" href="./?epub&amp;method=tag&amp;value={{ tag.value }}">{% trans "Download as ePub3" %}</a>{% endif %}
{% if constant('MOBI') == 1 %}<a title="{% trans "Download the articles from this tag in a mobi file" %}" href="./?mobi&amp;method=tag&amp;value={{ tag.value }}">{% trans "Download as Mobi" %}</a>{% endif %}
@ -77,5 +105,6 @@
{% if constant('MOBI') == 1 %}<a title="{% trans "Download the articles from this category in a mobi file" %}" href="./?mobi&amp;method=category&amp;value={{ view }}">{% trans "Download as Mobi" %}</a>{% endif %}
{% if constant('PDF') == 1 %}<a title="{% trans "Download the articles from this category in a pdf file" %}" href="./?pdf&amp;method=category&amp;value={{ view }}">{% trans "Download as PDF" %}</a>{% endif %}
{% endif %}
{% endif %}
{% endif %}
{% endblock %}