|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Suggest call |
|
5
|
|
|
*/ |
|
6
|
|
|
|
|
7
|
|
|
namespace HDNET\Tagger\Hooks; |
|
8
|
|
|
|
|
9
|
|
|
use HDNET\Tagger\Service; |
|
10
|
|
|
use TYPO3\CMS\Core\Database\DatabaseConnection; |
|
11
|
|
|
use TYPO3\CMS\Core\Http\AjaxRequestHandler; |
|
12
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Class SuggestReceiverCall |
|
16
|
|
|
*/ |
|
17
|
|
|
class SuggestReceiverCall |
|
18
|
|
|
{ |
|
19
|
|
|
|
|
20
|
|
|
const TAG = 'tx_tagger_domain_model_tag'; |
|
21
|
|
|
const LLPATH = 'LLL:EXT:tagger/Resources/Private/Language/locallang.xml:tag_suggest_'; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* Create a tag |
|
25
|
|
|
* |
|
26
|
|
|
* @param array $params |
|
27
|
|
|
* @param AjaxRequestHandler $ajaxObj |
|
28
|
|
|
* @return void |
|
29
|
|
|
*/ |
|
30
|
|
|
public function createTag(array $params, AjaxRequestHandler $ajaxObj) |
|
|
|
|
|
|
31
|
|
|
{ |
|
32
|
|
|
$request = GeneralUtility::_POST(); |
|
33
|
|
|
|
|
34
|
|
|
try { |
|
35
|
|
|
// check if a tag is submitted |
|
36
|
|
|
if (!isset($request['item']) || empty($request['item'])) { |
|
37
|
|
|
throw new \Exception('error_no-tag'); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
$newsUid = $request['newsid']; |
|
41
|
|
|
if ((int)$newsUid === 0 && (strlen($newsUid) == 16 && !GeneralUtility::isFirstPartOfStr($newsUid, 'NEW'))) { |
|
42
|
|
|
throw new \Exception('error_no-newsid'); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
// get tag uid |
|
46
|
|
|
$newTagId = $this->getTagUid($request); |
|
|
|
|
|
|
47
|
|
|
|
|
48
|
|
|
$ajaxObj->setContentFormat('javascript'); |
|
49
|
|
|
$ajaxObj->setContent(''); |
|
|
|
|
|
|
50
|
|
|
$response = [ |
|
51
|
|
|
$newTagId, |
|
52
|
|
|
$request['item'], |
|
53
|
|
|
'tx_tagger_domain_model_tag', |
|
54
|
|
|
self::TAG, |
|
55
|
|
|
'tags', |
|
56
|
|
|
'data[tx_tagger_domain_model_tag][' . $newsUid . '][tags]', |
|
57
|
|
|
$newsUid |
|
58
|
|
|
]; |
|
59
|
|
|
$ajaxObj->setJavascriptCallbackWrap(implode('-', $response)); |
|
60
|
|
|
} catch (\Exception $e) { |
|
61
|
|
|
//$errorMsg = $GLOBALS['LANG']->sL(self::LLPATH . ); |
|
62
|
|
|
$ajaxObj->setError($e->getMessage()); |
|
63
|
|
|
} |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* Get the uid of the tag, either bei inserting as new or get existing |
|
68
|
|
|
* |
|
69
|
|
|
* @param array $request ajax request |
|
70
|
|
|
* @return int |
|
71
|
|
|
* @throws \Exception |
|
72
|
|
|
*/ |
|
73
|
|
|
protected function getTagUid(array $request) |
|
74
|
|
|
{ |
|
75
|
|
|
/** @var DatabaseConnection $databaseConnection */ |
|
76
|
|
|
$databaseConnection = $GLOBALS['TYPO3_DB']; |
|
77
|
|
|
$record = $databaseConnection->exec_SELECTgetSingleRow( |
|
78
|
|
|
'*', |
|
79
|
|
|
'tx_tagger_domain_model_tag', |
|
80
|
|
|
'deleted=0 AND title=' . $databaseConnection->fullQuoteStr($request['item'], 'tx_tagger_domain_model_tag') |
|
81
|
|
|
); |
|
82
|
|
|
if (isset($record['uid'])) { |
|
83
|
|
|
$tagUid = (int)$record['uid']; |
|
84
|
|
|
} else { |
|
85
|
|
|
$tagUid = Service\IntegrationService::createTagRecord($request['item']); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
if ($tagUid == 0) { |
|
89
|
|
|
throw new \Exception('error_no-tag-created'); |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
return $tagUid; |
|
93
|
|
|
} |
|
94
|
|
|
} |
|
95
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.