chg: [feed] Added support of tag_collection_id when dealing with feeds

pull/9677/head
Sami Mokaddem 2024-04-17 15:59:10 +02:00
parent a2ea6ae0c0
commit 00991bda27
No known key found for this signature in database
GPG Key ID: 164C473F627A06FA
3 changed files with 32 additions and 37 deletions

View File

@ -109,12 +109,10 @@ class FeedsController extends AppController
} }
foreach ($feeds as &$feed) { foreach ($feeds as &$feed) {
if (!empty($feed['Feed']['tag_id'])) { if (!empty($feed['Feed']['tag_collection_id'])) {
if (substr($feed['Feed']['tag_id'], 0, 11) == 'collection_') {
$tagCollectionID = intval(substr($feed['Feed']['tag_id'], 11));
$tagCollection = $this->TagCollection->fetchTagCollection($loggedUser, [ $tagCollection = $this->TagCollection->fetchTagCollection($loggedUser, [
'conditions' => [ 'conditions' => [
'TagCollection.id' => $tagCollectionID, 'TagCollection.id' => $feed['Feed']['tag_collection_id'],
] ]
]); ]);
if (!empty($tagCollection)) { if (!empty($tagCollection)) {
@ -122,7 +120,6 @@ class FeedsController extends AppController
} }
} }
} }
}
return $feeds; return $feeds;
} }
@ -310,21 +307,12 @@ class FeedsController extends AppController
if (empty(Configure::read('Security.disable_local_feed_access'))) { if (empty(Configure::read('Security.disable_local_feed_access'))) {
$inputSources['local'] = 'Local'; $inputSources['local'] = 'Local';
} }
$tags = $this->Event->EventTag->Tag->find('all', [ $tags = $this->Event->EventTag->Tag->find('list', array('fields' => array('Tag.name'), 'order' => array('lower(Tag.name) asc')));
'recursive' => -1, $tags[0] = 'None';
'fields' => ['Tag.name', 'Tag.id'], $this->loadModel('TagCollection');
'order' => ['lower(Tag.name) asc']
]);
$tags = Hash::combine($tags, '{n}.Tag.id', '{n}.Tag.name');
$tagCollections = $this->TagCollection->fetchTagCollection($this->Auth->user()); $tagCollections = $this->TagCollection->fetchTagCollection($this->Auth->user());
$tagCollections = Hash::combine($tagCollections, '{n}.TagCollection.id', '{n}.TagCollection.name'); $tagCollections = Hash::combine($tagCollections, '{n}.TagCollection.id', '{n}.TagCollection.name');
foreach ($tagCollections as $id => $name) { $tagCollections[0] = 'None';
$newID = "collection_{$id}";
$tagCollections[$newID] = sprintf('%s :: %s', __('Tag Collection'), $name);
unset($tagCollections[$id]);
}
$tags = array_merge($tags, $tagCollections);
$tags[0] = 'None';
$this->loadModel('Server'); $this->loadModel('Server');
$allTypes = $this->Server->getAllTypes(); $allTypes = $this->Server->getAllTypes();
@ -335,6 +323,7 @@ class FeedsController extends AppController
'order' => 'LOWER(name)' 'order' => 'LOWER(name)'
)), )),
'tags' => $tags, 'tags' => $tags,
'tag_collections' => $tagCollections,
'feedTypes' => $this->Feed->getFeedTypesOptions(), 'feedTypes' => $this->Feed->getFeedTypesOptions(),
'sharingGroups' => $sharingGroups, 'sharingGroups' => $sharingGroups,
'distributionLevels' => $distributionLevels, 'distributionLevels' => $distributionLevels,
@ -371,6 +360,7 @@ class FeedsController extends AppController
'distribution', 'distribution',
'sharing_group_id', 'sharing_group_id',
'tag_id', 'tag_id',
'tag_collection_id',
'event_id', 'event_id',
'publish', 'publish',
'delta_merge', 'delta_merge',
@ -478,16 +468,12 @@ class FeedsController extends AppController
'fields' => ['Tag.name', 'Tag.id'], 'fields' => ['Tag.name', 'Tag.id'],
'order' => ['lower(Tag.name) asc'] 'order' => ['lower(Tag.name) asc']
]); ]);
$tags = Hash::combine($tags, '{n}.Tag.id', '{n}.Tag.name'); $tags = $this->Event->EventTag->Tag->find('list', array('fields' => array('Tag.name'), 'order' => array('lower(Tag.name) asc')));
$tags[0] = 'None';
$this->loadModel('TagCollection'); $this->loadModel('TagCollection');
$tagCollections = $this->TagCollection->fetchTagCollection($this->Auth->user()); $tagCollections = $this->TagCollection->fetchTagCollection($this->Auth->user());
$tagCollections = Hash::combine($tagCollections, '{n}.TagCollection.id', '{n}.TagCollection.name'); $tagCollections = Hash::combine($tagCollections, '{n}.TagCollection.id', '{n}.TagCollection.name');
foreach ($tagCollections as $id => $name) { $tagCollections[0] = 'None';
$newID = "collection_{$id}";
$tags[$newID] = sprintf('%s :: %s', __('Tag Collection'), $name);
}
unset($tagCollections);
$tags[0] = 'None';
$this->loadModel('Server'); $this->loadModel('Server');
$allTypes = $this->Server->getAllTypes(); $allTypes = $this->Server->getAllTypes();
@ -501,6 +487,7 @@ class FeedsController extends AppController
'order' => 'LOWER(name)' 'order' => 'LOWER(name)'
)), )),
'tags' => $tags, 'tags' => $tags,
'tag_collections' => $tagCollections,
'feedTypes' => $this->Feed->getFeedTypesOptions(), 'feedTypes' => $this->Feed->getFeedTypesOptions(),
'sharingGroups' => $sharingGroups, 'sharingGroups' => $sharingGroups,
'distributionLevels' => $distributionLevels, 'distributionLevels' => $distributionLevels,

View File

@ -1032,7 +1032,7 @@ class Feed extends AppModel
} }
} }
} }
if ($feed['Feed']['tag_id']) { if ($feed['Feed']['tag_id'] || $feed['Feed']['tag_collection_id']) {
if (empty($feed['Tag']['name'])) { if (empty($feed['Tag']['name'])) {
$feed_tag = $this->Tag->find('first', [ $feed_tag = $this->Tag->find('first', [
'conditions' => [ 'conditions' => [
@ -1049,9 +1049,9 @@ class Feed extends AppModel
$event['Event']['Tag'] = array(); $event['Event']['Tag'] = array();
} }
if (substr($feed['Feed']['tag_id'], 0, 11) == 'collection_') { // Tag is actually a tag collection if (!empty($feed['Feed']['tag_collection_id'])) {
$this->TagCollection = ClassRegistry::init('TagCollection'); $this->TagCollection = ClassRegistry::init('TagCollection');
$tagCollectionID = intval(substr($feed['Feed']['tag_id'], 11)); $tagCollectionID = $feed['Feed']['tag_collection_id'];
$tagCollection = $this->TagCollection->find('first', [ $tagCollection = $this->TagCollection->find('first', [
'recursive' => -1, 'recursive' => -1,
'conditions' => [ 'conditions' => [
@ -1400,10 +1400,10 @@ class Feed extends AppModel
if ($feed['Feed']['publish']) { if ($feed['Feed']['publish']) {
$this->Event->publishRouter($event['Event']['id'], null, $user); $this->Event->publishRouter($event['Event']['id'], null, $user);
} }
if ($feed['Feed']['tag_id']) { if ($feed['Feed']['tag_id'] || $feed['Feed']['tag_collection_id']) {
if (substr($feed['Feed']['tag_id'], 0, 11) == 'collection_') { // Tag is actually a tag collection if (!empty($feed['Feed']['tag_collection_id'])) {
$this->TagCollection = ClassRegistry::init('TagCollection'); $this->TagCollection = ClassRegistry::init('TagCollection');
$tagCollectionID = intval(substr($feed['Feed']['tag_id'], 11)); $tagCollectionID = $feed['Feed']['tag_collection_id'];
$tagCollection = $this->TagCollection->find('first', [ $tagCollection = $this->TagCollection->find('first', [
'recursive' => -1, 'recursive' => -1,
'conditions' => [ 'conditions' => [

View File

@ -166,6 +166,14 @@ echo $this->element('genericElements/Form/genericForm', [
'type' => 'dropdown', 'type' => 'dropdown',
'searchable' => 1 'searchable' => 1
], ],
[
'field' => 'tag_collection_id',
'label' => __('Default Tag Collection'),
'options' => $dropdownData['tag_collections'],
'selected' => isset($entity['Feed']['tag_collection_id']) ? $entity['Feed']['tag_collection_id'] : '0',
'type' => 'dropdown',
'searchable' => 1
],
[ [
'field' => 'rules', 'field' => 'rules',
'label' => __('Filter rules'), 'label' => __('Filter rules'),