Skip to content

Commit ba7b7b0

Browse files
committed
reverse refactoring
1 parent f278c8b commit ba7b7b0

2 files changed

Lines changed: 81 additions & 81 deletions

File tree

blocks/block.php

Lines changed: 38 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,8 @@ function tag_block_cloud_show($options, $dirname = '', $catid = 0)
132132
return $block;
133133
}
134134

135-
$tags_data_array = $tagHandler->getTagData($tags_array, $options[2], $options[3]);
136-
/*
135+
// $tags_data_array = $tagHandler->getTagData($tags_array, $options[2], $options[3]);//mb
136+
137137
$count_max = 0;
138138
$count_min = 0;
139139
$tags_term = [];
@@ -165,7 +165,7 @@ function tag_block_cloud_show($options, $dirname = '', $catid = 0)
165165
];
166166
}
167167
unset($tags_array, $tag, $tags_term, $tag_count_array);
168-
*/
168+
169169
$block['tags'] = $tags_data_array;
170170
$block['tag_dirname'] = 'tag';
171171
if (!empty($modid)) {
@@ -294,48 +294,45 @@ function tag_block_top_show($options, $dirname = '', $catid = 0)
294294
return $block;
295295
}
296296

297-
$tags_data_array = $tagHandler->getTagData($tags_array, $options[1], $options[2]);
298-
/*
299-
$count_max = 0;
300-
$count_min = 0;
301-
$tag_count_array = array_column($tags_array, 'count'); // get the count values
302-
$tag_count_array = array_map('intval', $tag_count_array); // make sure they're all integers
303-
$count_max = max($tag_count_array); // get the max value in array
304-
$count_max = max(0, $count_max); // make sure it's >= 0
305-
$count_min = 0;
306-
$tags_sort = array_column($tags_array, 'term'); // get all the terms
307-
$tags_sort = array_map('mb_strtolower', $tags_sort); // convert them all to lowercase
308-
309-
$tags_sort = [];
310-
foreach ($tags_array as $tag) {
311-
$count_max = max($count_max, $tag['count']); // set counter to the max tag count
312-
//@todo test removal of the following as $count_min can never be less than 0, which is set above
313-
$count_min = min(0, $count_min, $tag['count']); //set counter to the minimum for tag count
314-
if (('a' === $options[2]) || ('alphabet' === $options[2])) {
315-
$tags_sort[] = \mb_strtolower($tag['term']);
316-
}
317-
}
318-
$count_interval = $count_max - $count_min;
297+
// $tags_data_array = $tagHandler->getTagData($tags_array, $options[2], $options[3]); //mb
319298

320-
$font_max = $options[1];
321-
$font_min = $options[2];
322-
$font_ratio = ($count_interval) ? ($font_max - $font_min) / $count_interval : 1;
299+
$count_max = 0;
300+
$count_min = 0;
301+
$tag_count_array = array_column($tags_array, 'count'); // get the count values
302+
$tag_count_array = array_map('intval', $tag_count_array); // make sure they're all integers
303+
$count_max = max($tag_count_array); // get the max value in array
304+
$count_max = max(0, $count_max); // make sure it's >= 0
305+
$count_min = 0;
306+
$tags_sort = array_column($tags_array, 'term'); // get all the terms
307+
$tags_sort = array_map('mb_strtolower', $tags_sort); // convert them all to lowercase
323308

324-
if (!empty($tags_sort)) {
325-
array_multisort($tags_sort, SORT_ASC, $tags_array);
326-
}
309+
$tags_sort = [];
327310

328-
$tags_data_array = [];
329-
foreach ($tags_array as $tag) {
330-
$tags_data_array[] = [
331-
'id' => $tag['id'],
332-
'term' => $tag['term'],
333-
'count' => $tag['count'],
334-
//"level" => ($tags_array[$key]["count"] - $count_min) * $font_ratio + $font_min,
335-
];
311+
foreach ($tags_array as $tag) {
312+
$count_max = max($count_max, $tag['count']); // set counter to the max tag count
313+
//@todo test removal of the following as $count_min can never be less than 0, which is set above
314+
$count_min = min(0, $count_min, $tag['count']); //set counter to the minimum for tag count
315+
if (('a' === $options[2]) || ('alphabet' === $options[2])) {
316+
$tags_sort[] = \mb_strtolower($tag['term']);
336317
}
337-
unset($tags_array, $tag_count_array, $tags_sort);
338-
*/
318+
}
319+
320+
$count_interval = $count_max - $count_min;
321+
322+
if (!empty($tags_sort)) {
323+
array_multisort($tags_sort, SORT_ASC, $tags_array);
324+
}
325+
326+
$tags_data_array = [];
327+
foreach ($tags_array as $tag) {
328+
$tags_data_array[] = [
329+
'id' => $tag['id'],
330+
'term' => $tag['term'],
331+
'count' => $tag['count'],
332+
//"level" => ($tags_array[$key]["count"] - $count_min) * $font_ratio + $font_min,
333+
];
334+
}
335+
unset($tags_array, $tag_count_array, $tags_sort);
339336

340337
$block['tags'] = $tags_data_array;
341338
$block['tag_dirname'] = 'tag';

class/TagHandler.php

Lines changed: 43 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ public function update_stats($tag_id, $modid = 0, $catid = 0)
206206

207207
/** @var \XoopsModules\Tag\LinkHandler $linkHandler */
208208
$linkHandler = \XoopsModules\Tag\Helper::getInstance()->getHandler('Link');
209-
$criteria = new \CriteriaCompo(new \Criteria('tag_id', $tag_id));
209+
$criteria = new \CriteriaCompo(new \Criteria('tag_id', $tag_id));
210210
if (0 !== $modid) {
211211
$criteria->add(new \Criteria('tag_modid', $modid), 'ADD');
212212
}
@@ -519,43 +519,46 @@ public function getItemCount($tag_id, $modid = 0, $catid = 0)
519519
* @param int $font_min
520520
* @return array tag data values for display
521521
*/
522-
public function getTagData($tags_array, $font_max = 0, $font_min = 0)
523-
{
524-
$tags_data_array = [];
525-
if (\is_array($tags_array) && !empty($tags_array)) {
526-
// set min and max tag count
527-
$count_array = \array_column($tags_array, 'count', 'id');
528-
$count_min = \count($count_array) > 0 ? \min($count_array) : 0;
529-
$count_min = $count_min > 0 ? $count_min : 0;
530-
$count_max = \count($count_array) > 0 ? \max($count_array) : 0;
531-
$count_max = $count_max > 0 ? $count_max : 0;
532-
533-
$term_array = \array_column($tags_array, 'term', 'id');
534-
$tags_term_array = \array_map('\mb_strtolower', $term_array);
535-
\array_multisort($tags_term_array, \SORT_ASC, $tags_array);
536-
$count_interval = $count_max - $count_min;
537-
$level_limit = 5;
538-
539-
$font_ratio = $count_interval ? ($font_max - $font_min) / $count_interval : 1;
540-
541-
foreach ($tags_array as $tag) {
542-
/*
543-
* Font-size = ((tag.count - count.min) * (font.max - font.min) / (count.max - count.min) ) * 100%
544-
*/
545-
$font_sz = \floor(($tag['count'] - $count_min) * $font_ratio) + $font_min;
546-
$level_sz = \floor(($tag['count'] - $count_min) * $level_limit / $count_max);
547-
$tags_data_array[] = [
548-
'id' => $tag['id'],
549-
'font' => empty($count_interval) ? 100 : (int)$font_sz,
550-
'level' => empty($count_max) ? 0 : (int)$level_sz,
551-
'term' => \urlencode($tag['term']),
552-
'title' => \htmlspecialchars($tag['term'], \ENT_QUOTES | \ENT_HTML5),
553-
'count' => $tag['count'],
554-
];
555-
}
556-
}
557-
return $tags_data_array;
558-
}
522+
// public function getTagData($tags_array, $font_max = 0, $font_min = 0)
523+
// {
524+
// $tags_data_array = [];
525+
// if (\is_array($tags_array) && !empty($tags_array)) {
526+
// // set min and max tag count
527+
// $count_array = \array_column($tags_array, 'count', 'id');
528+
// $count_min = \count($count_array) > 0 ? \min($count_array) : 0;
529+
// $count_min = $count_min > 0 ? $count_min : 0;
530+
// $count_max = \count($count_array) > 0 ? \max($count_array) : 0;
531+
// $count_max = $count_max > 0 ? $count_max : 0;
532+
// if ($count_max > 0) {
533+
// $term_array = \array_column($tags_array, 'term', 'id');
534+
// $tags_term_array = \array_map('\mb_strtolower', $term_array);
535+
// \array_multisort($tags_term_array, \SORT_ASC, $tags_array);
536+
// $count_interval = $count_max - $count_min;
537+
// $level_limit = 5;
538+
//
539+
// $font_ratio = $count_interval ? ($font_max - $font_min) / $count_interval : 1;
540+
//
541+
// foreach ($tags_array as $tag) {
542+
// /*
543+
// * Font-size = ((tag.count - count.min) * (font.max - font.min) / (count.max - count.min) ) * 100%
544+
// */
545+
// $font_sz = \floor(($tag['count'] - $count_min) * $font_ratio) + $font_min;
546+
// $level_sz = \floor(($tag['count'] - $count_min) * $level_limit / $count_max);
547+
// $tags_data_array[] = [
548+
// 'id' => $tag['id'],
549+
// 'font' => empty($count_interval) ? 100 : (int)$font_sz,
550+
// 'level' => empty($count_max) ? 0 : (int)$level_sz,
551+
// 'term' => \urlencode($tag['term']),
552+
// 'title' => \htmlspecialchars($tag['term'], \ENT_QUOTES | \ENT_HTML5),
553+
// 'count' => $tag['count'],
554+
// ];
555+
// }
556+
// }
557+
// }
558+
//
559+
//
560+
// return $tags_data_array;
561+
// }
559562

560563
/**
561564
* Delete an object as well as links relying on it
@@ -581,7 +584,7 @@ public function delete(\XoopsObject $object, $force = true)
581584

582585
/** @var \XoopsModules\Tag\LinkHandler $linkHandler */
583586
$linkHandler = $helper->getHandler('Link');
584-
$criteria = new \Criteria($this->keyName, $object->getVar($this->keyName));
587+
$criteria = new \Criteria($this->keyName, $object->getVar($this->keyName));
585588
$linkHandler->deleteAll($criteria, $force);
586589
//$sql = 'DELETE' . " FROM {$this->table_link}" . " WHERE {$this->keyName} = " . $object->getVar($this->keyName);
587590
/*
@@ -594,7 +597,7 @@ public function delete(\XoopsObject $object, $force = true)
594597
*/
595598
/** @var \XoopsModules\Tag\StatsHandler $statsHandler */
596599
$statsHandler = $helper->getHandler('Stats');
597-
$criteria = new \Criteria($this->keyName, $object->getVar($this->keyName));
600+
$criteria = new \Criteria($this->keyName, $object->getVar($this->keyName));
598601
$statsHandler->deleteAll($criteria, $force);
599602
//$sql = 'DELETE' . " FROM {$this->table_stats}" . " WHERE {$this->keyName} = " . $object->getVar($this->keyName);
600603

0 commit comments

Comments
 (0)