Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ttree
Ttree.SortableNode
Commits
8cb64c2b
Commit
8cb64c2b
authored
Sep 12, 2013
by
Dominique Feyer
Browse files
[TASK] Disable node sorting by default, currently buggy
parent
d3eab665
Changes
3
Hide whitespace changes
Inline
Side-by-side
Classes/Ttree/Starter/Aspect/NodeSortingAspect.php
0 → 100644
View file @
8cb64c2b
<?php
namespace
Ttree\Starter\Aspect
;
/* *
* This script belongs to the TYPO3 Flow package "Ttree.Starter". *
* *
* */
use
TYPO3\Flow\Annotations
as
Flow
;
use
TYPO3\Flow\Aop\JoinPointInterface
;
use
TYPO3\TYPO3CR\Domain\Model\NodeData
;
/**
* An aspect to force sorting node in the TYPO3CR
*
* @package Ttree\Starter\Aspect
* @Flow\Scope("singleton")
* @Flow\Aspect
*/
class
NodeSortingAspect
{
/**
* @Flow\Inject
* @var \Ttree\Starter\Service\NodeSortingService
*/
protected
$nodeSortingService
;
/**
* @Flow\Inject
* @var \TYPO3\TYPO3CR\Domain\Service\ContextFactory
*/
protected
$contextFactory
;
/**
* @param JoinPointInterface $joinPoint
* @Flow\After("setting(Ttree.Starter.nodeSorting.enable) && method(TYPO3\TYPO3CR\Domain\Repository\NodeDataRepository->(update|add)())")
*/
public
function
sortNodesAfterUpdateOrCreate
(
JoinPointInterface
$joinPoint
)
{
/** @var NodeData $nodeData */
$nodeData
=
$joinPoint
->
getMethodArgument
(
'object'
);
if
(
!
$nodeData
instanceof
NodeData
)
{
return
;
}
$context
=
$this
->
contextFactory
->
create
(
array
(
'workspaceName'
=>
$nodeData
->
getWorkspace
()
->
getName
(),
));
$parentNode
=
$context
->
getNode
(
$nodeData
->
getParentPath
())
?:
$context
->
getRootNode
();
$this
->
nodeSortingService
->
decideSortingByParentNode
(
$parentNode
);
}
}
?>
\ No newline at end of file
Classes/Ttree/Starter/Service/SortingService.php
→
Classes/Ttree/Starter/Service/
Node
SortingService.php
View file @
8cb64c2b
...
...
@@ -13,11 +13,12 @@ use TYPO3\Flow\Property\PropertyMappingConfigurationInterface;
use
TYPO3\TYPO3CR\Domain\Model\NodeInterface
;
/**
* Class OrderingService
* A service to sort node stored in the content repository
*
* @package Ttree\Plugin\MicroEvent\Service
* @Flow\Scope("singleton")
*/
class
SortingService
{
class
Node
SortingService
{
/**
* @Flow\Inject
...
...
@@ -25,12 +26,49 @@ class SortingService {
*/
protected
$propertyMapper
;
/**
* @Flow\Inject
* @var \TYPO3\TYPO3CR\Domain\Repository\NodeDataRepository
*/
protected
$nodeDataRepository
;
/**
* @Flow\Inject
* @var \TYPO3\Flow\Property\PropertyMappingConfigurationBuilder
*/
protected
$propertyMappingConfigurationBuilder
;
/**
* @var array
*/
protected
$settings
;
/**
* @param array $settings
*/
public
function
injectSettings
(
array
$settings
)
{
$this
->
settings
=
$settings
;
}
/**
* @param NodeInterface $parentNode
* @throws \TYPO3\Flow\Exception
*/
public
function
decideSortingByParentNode
(
NodeInterface
$parentNode
)
{
$configurationPath
=
'nodeSorting.configuration.'
.
$parentNode
->
getPath
();
if
(
NULL
===
$configuration
=
Arrays
::
getValueByPath
(
$this
->
settings
,
$configurationPath
))
{
return
;
}
foreach
(
$configuration
as
$subConfiguration
)
{
if
(
!
isset
(
$subConfiguration
[
'type'
])
||
trim
(
$subConfiguration
[
'type'
])
===
''
)
{
throw
new
Exception
(
'Missing sortable node type setting'
,
1378377366
);
}
$this
->
orderByNodePathAndType
(
$parentNode
,
$subConfiguration
[
'type'
],
$subConfiguration
[
'configuration'
]);
}
}
/**
* @param NodeInterface $parentNode
* @param $nodeType string
...
...
@@ -38,11 +76,14 @@ class SortingService {
* @throws \TYPO3\Flow\Exception
*/
public
function
orderByNodePathAndType
(
NodeInterface
$parentNode
,
$nodeType
,
array
$configuration
)
{
if
(
!
isset
(
$configuration
[
'sortingType'
]))
{
$configuration
[
'sortingType'
]
=
'simple'
;
if
(
!
is_string
(
$nodeType
)
||
trim
(
$nodeType
)
===
''
)
{
throw
new
Exception
(
'Empty or invalid node type'
,
1378378768
);
}
if
(
!
isset
(
$configuration
[
'type'
]))
{
$configuration
[
'type'
]
=
'simple'
;
}
switch
(
$configuration
[
'
sortingT
ype'
])
{
switch
(
$configuration
[
'
t
ype'
])
{
case
'simple'
:
$this
->
applySimpleSorting
(
$parentNode
,
$nodeType
,
$configuration
);
break
;
...
...
@@ -57,25 +98,26 @@ class SortingService {
* @param array $configuration
*/
protected
function
applySimpleSorting
(
NodeInterface
$parentNode
,
$nodeType
,
array
$configuration
)
{
$sortingProperty
=
$configuration
[
'sortingProperty'
];
$sortingSource
=
array
();
$property
=
$configuration
[
'property'
];
$sortingSource
=
array
();
$hasChildNode
=
FALSE
;
foreach
(
$parentNode
->
getChildNodes
(
$nodeType
)
as
$node
)
{
/** @var NodeInterface $node */
$property
=
$this
->
convertPropertyType
(
$node
->
getProperty
(
$sortingProperty
),
$configuration
[
'sortingPropertyTargetType'
]);
$sortingSource
[]
=
array
(
'path'
=>
$node
->
getPath
(),
'
sortingProperty'
=>
$property
,
'currentIndex'
=>
$node
->
getIndex
(),
'path'
=>
$node
->
getPath
(),
'
property'
=>
$this
->
convertPropertyType
(
$node
->
getProperty
(
$property
),
$configuration
[
'propertyTargetType'
])
,
'currentIndex'
=>
$node
->
getIndex
(),
);
$hasChildNode
=
TRUE
;
}
if
(
$hasChildNode
===
FALSE
)
{
return
;
}
$currentIndexes
=
$this
->
extractCurrentIndexes
(
$sortingSource
);
usort
(
$sortingSource
,
function
(
$a
,
$b
)
{
return
$a
[
'
sortingP
roperty'
]
<
$b
[
'
sortingP
roperty'
];
return
$a
[
'
p
roperty'
]
<
$b
[
'
p
roperty'
];
});
$this
->
applySorting
(
$sortingSource
,
$currentIndexes
,
$parentNode
);
foreach
(
Arrays
::
arrayMergeRecursiveOverrule
(
$sortingSource
,
$currentIndexes
)
as
$node
)
{
$parentNode
->
getNode
(
$node
[
'path'
])
->
setIndex
(
$node
[
'currentIndex'
]);
}
}
/**
...
...
Configuration/Settings.yaml
0 → 100644
View file @
8cb64c2b
Ttree
:
Starter
:
nodeSorting
:
enable
:
false
configuration
:
'
/sites/officialwebsite/fr/participer'
:
-
type
:
Ttree.Plugin.MicroEvent:Event
configuration
:
type
:
simple
property
:
eventStartDate
propertyTargetType
:
DateTime
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment