Passed
Push — master ( db06e9...3c1697 )
by Michael
02:44 queued 21s
created

xmnews_tag_iteminfo()   B

Complexity

Conditions 8
Paths 13

Size

Total Lines 36
Code Lines 23

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 8
eloc 23
c 1
b 0
f 0
nc 13
nop 1
dl 0
loc 36
rs 8.4444
1
<?php
2
/*
3
 You may not change or alter any portion of this comment or credits
4
 of supporting developers from this source code or any supporting source code
5
 which is considered copyrighted (c) material of the original comment or credit authors.
6
7
 This program is distributed in the hope that it will be useful,
8
 but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10
*/
11
12
/**
13
 * xmnews module
14
 *
15
 * @copyright       XOOPS Project (https://xoops.org)
16
 * @license         GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
17
 * @author          Mage Gregory (AKA Mage)
18
 */
19
20
//use XoopsModules\Tag\Helper;
21
use Xmf\Module\Helper;
22
23
function xmnews_tag_iteminfo(&$items)
24
{
25
    if (empty($items) || !is_array($items)) {
26
        return false;
27
    }
28
29
    $items_id = [];
30
    foreach (array_keys($items) as $cat_id) {
31
        // Some handling here to build the link upon catid
32
        // If catid is not used, just skip it
33
        foreach (array_keys($items[$cat_id]) as $item_id) {
34
            // In article, the item_id is "art_id"
35
            $items_id[] = (int)$item_id;
36
        }
37
    }
38
	$helper      = Helper::getHelper('xmnews');
39
	$newsHandler = $helper->getHandler('xmnews_news');
40
    $items_obj   = $newsHandler->getObjects(new \Criteria('news_id', '(' . implode(', ', $items_id) . ')', 'IN'), true);
41
	if (count($items_obj) > 0){
42
		foreach (array_keys($items) as $cat_id) {
43
			foreach (array_keys($items[$cat_id]) as $item_id) {
44
				$item_obj                 = $items_obj[$item_id];
45
				$items[$cat_id][$item_id] = [
46
					'title'   => $item_obj->getVar('news_title'),
47
					'uid'     => $item_obj->getVar('news_userid'),
48
					'link'    => "article.php?news_id={$item_id}",
49
					'time'    => $item_obj->getVar('news_date'),
50
					'tags'    => \XoopsModules\Tag\Utility::tag_parse_tag($item_obj->getVar('news_mkeyword', 'n')), // optional
51
					'content' => '',
52
				];
53
			}
54
		}
55
		unset($items_obj);
56
		return true;
57
	}
58
	return false;
59
}
60
61
/** Remove orphan tag-item links *
62
 * @param int $mid
63
 * @return bool
64
 */
65
function publisher_tag_synchronization($mid)
0 ignored issues
show
Unused Code introduced by
The parameter $mid is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

65
function publisher_tag_synchronization(/** @scrutinizer ignore-unused */ $mid)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
66
{
67
    //$itemHandler = \XoopsModules\xmnews\Helper::getInstance()->getHandler('xmnews_news');
68
	$helper      = Helper::getHelper('xmnews');
69
	$newsHandler = $helper->getHandler('xmnews_news');
70
71
    /** @var \XoopsModules\Tag\LinkHandler $itemHandler */
72
    $linkHandler = Helper::getInstance()->getHandler('Link');
0 ignored issues
show
introduced by
The method getInstance() does not exist on Xmf\Module\Helper. Are you sure you never get this type here, but always one of the subclasses? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

72
    $linkHandler = Helper::/** @scrutinizer ignore-call */ getInstance()->getHandler('Link');
Loading history...
73
74
    //    $mid = XoopsFilterInput::clean($mid, 'INT');
75
    $mid = \Xmf\Request::getInt('mid');
76
77
    /* clear tag-item links */
78
    $sql    = "    DELETE FROM {$linkHandler->table}"
79
              . '    WHERE '
80
              . "        tag_modid = {$mid}"
81
              . '        AND '
82
              . '        ( tag_itemid NOT IN '
83
              . "            ( SELECT DISTINCT {$newsHandler->keyName} "
0 ignored issues
show
Bug introduced by
The property keyName does not exist on boolean.
Loading history...
84
              . "                FROM {$newsHandler->table} "
0 ignored issues
show
Bug introduced by
The property table does not exist on boolean.
Loading history...
85
              . "                WHERE {$newsHandler->table}.status = 1"
86
              . '            ) '
87
              . '        )';
88
    $result = $linkHandler->db->queryF($sql);
89
90
    return $result ? true : false;
91
}
92