Commit de40daa8 by pupi1985

Minor refactoring to qa-layer-voters-flaggers.php

parent 44fb91d9
...@@ -31,10 +31,11 @@ class qa_html_theme_layer extends qa_html_theme_base ...@@ -31,10 +31,11 @@ class qa_html_theme_layer extends qa_html_theme_base
public function main() public function main()
{ {
foreach ($this->content as $key => $part) { foreach ($this->content as $key => $part) {
if (strpos($key, 'q_list') === 0) if (strpos($key, 'q_list') === 0) {
$this->queue_raw_posts_voters_flaggers(@$part['qs']); if (isset($part['qs']))
$this->queue_raw_posts_voters_flaggers($part['qs']);
elseif (strpos($key, 'q_view') === 0) { } elseif (strpos($key, 'q_view') === 0) {
$this->queue_post_voters_flaggers($part['raw']); $this->queue_post_voters_flaggers($part['raw']);
$this->queue_raw_posts_voters_flaggers($part['c_list']['cs']); $this->queue_raw_posts_voters_flaggers($part['c_list']['cs']);
...@@ -42,8 +43,10 @@ class qa_html_theme_layer extends qa_html_theme_base ...@@ -42,8 +43,10 @@ class qa_html_theme_layer extends qa_html_theme_base
if (!empty($part)) { if (!empty($part)) {
$this->queue_raw_posts_voters_flaggers($part['as']); $this->queue_raw_posts_voters_flaggers($part['as']);
foreach ($part['as'] as $a_item) foreach ($part['as'] as $a_item) {
$this->queue_raw_posts_voters_flaggers(@$a_item['c_list']['cs']); if (isset($a_item['c_list']['cs']))
$this->queue_raw_posts_voters_flaggers($a_item['c_list']['cs']);
}
} }
} }
} }
...@@ -80,37 +83,42 @@ class qa_html_theme_layer extends qa_html_theme_base ...@@ -80,37 +83,42 @@ class qa_html_theme_layer extends qa_html_theme_base
public function vote_count($post) public function vote_count($post)
{ {
$votersflaggers = $this->get_post_voters_flaggers($post['raw'], @$post['vote_opostid'] ? $post['raw']['opostid'] : $post['raw']['postid']); $postid = isset($post['vote_opostid']) && $post['vote_opostid'] ? $post['raw']['opostid'] : $post['raw']['postid'];
$votersflaggers = $this->get_post_voters_flaggers($post['raw'], $postid);
$tooltip = '';
if (isset($votersflaggers)) { if (isset($votersflaggers)) {
$uphandles = ''; $uphandles = array();
$downhandles = ''; $downhandles = array();
foreach ($votersflaggers as $voterflagger) { foreach ($votersflaggers as $voterflagger) {
if ($voterflagger['vote'] > 0) if ($voterflagger['vote'] != 0) {
$uphandles .= (strlen($uphandles) ? ', ' : '') . qa_html($voterflagger['handle']); $newflagger = qa_html($voterflagger['handle']);
if ($voterflagger['vote'] > 0)
$uphandles[] = $newflagger;
else // if ($voterflagger['vote'] < 0)
$downhandles[] = $newflagger;
}
}
if ($voterflagger['vote'] < 0) $tooltip = trim(
$downhandles .= (strlen($downhandles) ? ', ' : '') . qa_html($voterflagger['handle']); (empty($uphandles) ? '' : '&uarr; ' . implode(', ', $uphandles)) . "\n\n" .
(empty($downhandles) ? '' : '&darr; ' . implode(', ', $downhandles))
);
$tooltip = trim((strlen($uphandles) ? ('&uarr; ' . $uphandles) : '') . "\n\n" . (strlen($downhandles) ? ('&darr; ' . $downhandles) : '')); $post['vote_count_tags'] = sprintf('%s title="%s"', isset($post['vote_count_tags']) ? $post['vote_count_tags'] : '', $tooltip);
}
} }
$post['vote_count_tags'] = @$post['vote_count_tags'] . ' title="' . $tooltip . '"';
parent::vote_count($post); parent::vote_count($post);
} }
public function post_meta_flags($post, $class) public function post_meta_flags($post, $class)
{ {
$postid = @$post['raw']['opostid']; if (isset($post['raw']['opostid']))
if (!isset($postid)) $postid = $post['raw']['opostid'];
$postid = @$post['raw']['postid']; elseif (isset($post['raw']['postid']))
$postid = $post['raw']['postid'];
$tooltip = ''; $flaggers = array();
if (isset($postid)) { if (isset($postid)) {
$votersflaggers = $this->get_post_voters_flaggers($post, $postid); $votersflaggers = $this->get_post_voters_flaggers($post, $postid);
...@@ -118,17 +126,17 @@ class qa_html_theme_layer extends qa_html_theme_base ...@@ -118,17 +126,17 @@ class qa_html_theme_layer extends qa_html_theme_base
if (isset($votersflaggers)) { if (isset($votersflaggers)) {
foreach ($votersflaggers as $voterflagger) { foreach ($votersflaggers as $voterflagger) {
if ($voterflagger['flag'] > 0) if ($voterflagger['flag'] > 0)
$tooltip .= (strlen($tooltip) ? ', ' : '') . qa_html($voterflagger['handle']); $flaggers[] = qa_html($voterflagger['handle']);
} }
} }
} }
if (strlen($tooltip)) if (!empty($flaggers))
$this->output('<span title="&#9873; ' . $tooltip . '">'); $this->output('<span title="&#9873; ' . implode(', ', $flaggers) . '">');
parent::post_meta_flags($post, $class); parent::post_meta_flags($post, $class);
if (strlen($tooltip)) if (!empty($flaggers))
$this->output('</span>'); $this->output('</span>');
} }
...@@ -142,11 +150,10 @@ class qa_html_theme_layer extends qa_html_theme_base ...@@ -142,11 +150,10 @@ class qa_html_theme_layer extends qa_html_theme_base
public function queue_post_voters_flaggers($post) public function queue_post_voters_flaggers($post)
{ {
if (!qa_user_post_permit_error('permit_view_voters_flaggers', $post)) { if (!qa_user_post_permit_error('permit_view_voters_flaggers', $post)) {
$postids = array(@$post['postid'], @$post['opostid']); // opostid can be relevant for flags $postkeys = array('postid', 'opostid');
foreach ($postkeys as $key) {
foreach ($postids as $postid) { if (isset($post[$key]) && !isset($this->qa_voters_flaggers_cache[$post[$key]]))
if (isset($postid) && !isset($this->qa_voters_flaggers_cache[$postid])) $this->qa_voters_flaggers_queue[$post[$key]] = true;
$this->qa_voters_flaggers_queue[$postid] = true;
} }
} }
} }
...@@ -188,7 +195,7 @@ class qa_html_theme_layer extends qa_html_theme_base ...@@ -188,7 +195,7 @@ class qa_html_theme_layer extends qa_html_theme_base
$useridhandles = qa_get_public_from_userids(array_keys($keyuserids)); $useridhandles = qa_get_public_from_userids(array_keys($keyuserids));
foreach ($newvotersflaggers as $index => $voterflagger) foreach ($newvotersflaggers as $index => $voterflagger)
$newvotersflaggers[$index]['handle'] = @$useridhandles[$voterflagger['userid']]; $newvotersflaggers[$index]['handle'] = isset($useridhandles[$voterflagger['userid']]) ? $useridhandles[$voterflagger['userid']] : null;
} }
foreach ($newvotersflaggers as $voterflagger) foreach ($newvotersflaggers as $voterflagger)
...@@ -211,7 +218,7 @@ class qa_html_theme_layer extends qa_html_theme_base ...@@ -211,7 +218,7 @@ class qa_html_theme_layer extends qa_html_theme_base
$this->retrieve_queued_voters_flaggers(); $this->retrieve_queued_voters_flaggers();
} }
$votersflaggers = @$this->qa_voters_flaggers_cache[$postid]; $votersflaggers = isset($this->qa_voters_flaggers_cache[$postid]) ? $this->qa_voters_flaggers_cache[$postid] : null;
if (isset($votersflaggers)) if (isset($votersflaggers))
qa_sort_by($votersflaggers, 'handle'); qa_sort_by($votersflaggers, 'handle');
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment