IntegrationService   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 109
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 4
Bugs 0 Features 0
Metric Value
wmc 4
c 4
b 0
f 0
lcom 0
cbo 2
dl 0
loc 109
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
B getTagFieldConfiguration() 0 31 1
A createTagRecord() 0 20 1
A gerRelatedContent() 0 15 1
A gerRelatedByTag() 0 10 1
1
<?php
2
3
/**
4
 * Integration service
5
 */
6
7
namespace HDNET\Tagger\Service;
8
9
use TYPO3\CMS\Core\Database\DatabaseConnection;
10
use TYPO3\CMS\Core\DataHandling\DataHandler;
11
use TYPO3\CMS\Core\Utility\GeneralUtility;
12
13
/**
14
 * Class IntegrationService
15
 */
16
class IntegrationService
17
{
18
19
    /**
20
     * Get the field configuration for a Tag field
21
     *
22
     * @param string $tableName
23
     * @return array
24
     */
25
    public static function getTagFieldConfiguration($tableName)
26
    {
27
        $config = [
28
            'type' => 'select',
29
            'foreign_table' => 'tx_tagger_domain_model_tag',
30
            'foreign_table_where' => 'ORDER BY tx_tagger_domain_model_tag.title',
31
            'MM' => 'tx_tagger_tag_mm',
32
            'MM_hasUidField' => true,
33
            'multiple' => false,
34
            'MM_opposite_field' => 'content',
35
            'MM_match_fields' => [
36
                'tablenames' => $tableName
37
            ],
38
            'size' => 5,
39
            'autoSizeMax' => 20,
40
            'minitems' => 0,
41
            'maxitems' => 30,
42
            'wizards' => [
43
                '_PADDING' => 2,
44
                '_VERTICAL' => 1,
45
                'suggest' => [
46
                    'type' => 'suggest',
47
                    'default' => [
48
                        'receiverClass' => \HDNET\Tagger\Hooks\SuggestReceiver::class
49
                    ],
50
                ],
51
            ],
52
        ];
53
54
        return $config;
55
    }
56
57
    /**
58
     * Create a new Tag Record
59
     *
60
     * @param string $title
61
     * @return integer The ID of the New Tag
62
     */
63
    public static function createTagRecord($title)
64
    {
65
        $tcemainData = [
66
            'tx_tagger_domain_model_tag' => [
67
                'NEW' => [
68
                    'pid' => 0,
69
                    'title' => $title
70
                ]
71
            ]
72
        ];
73
74
        /**
75
         * @var DataHandler
76
         */
77
        $tce = GeneralUtility::makeInstance(DataHandler::class);
78
        $tce->start($tcemainData, []);
79
        $tce->process_datamap();
80
81
        return $tce->substNEWwithIDs['NEW'];
82
    }
83
84
    /**
85
     * Get related contents
86
     *
87
     * @param string $table
88
     * @param integer $uid
89
     * @return array
90
     * @TODO: implement
91
     */
92
    public static function gerRelatedContent($table, $uid)
0 ignored issues
show
Unused Code introduced by
The parameter $table is not used and could be removed.

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

Loading history...
Unused Code introduced by
The parameter $uid is not used and could be removed.

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

Loading history...
93
    {
94
        $records = [];
95
        /*
96
          $GLOBALS['TSFE']->exec_SELECTgetRows('uid_foreign as uid, tablenames', 'tx_tagger_tag_mm',
97
          ,
98
          $ groupBy = '',
99
          $ orderBy = '',
100
          $ limit = '',
101
          $ uidIndexField = ''
102
          )
103
         * Ü */
104
105
        return $records;
106
    }
107
108
    /**
109
     * Get related by same tag
110
     *
111
     * @param integer $uid
112
     * @return array
113
     */
114
    public static function gerRelatedByTag($uid)
115
    {
116
        /** @var DatabaseConnection $databaseConnection */
117
        $databaseConnection = $GLOBALS['TYPO3_DB'];
118
        return $databaseConnection->exec_SELECTgetRows(
119
            'uid_foreign as uid, tablenames',
120
            'tx_tagger_tag_mm',
121
            'uid_local=' . $uid
122
        );
123
    }
124
}
125