Skip to content

Show items primary value when listing node contents #66

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 13, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ alpha-4
- [node] copy,move and clone - Target paths automatically append basename if target is a node.
- [query] Always show path next to resultset
- [node|shell] Most commands which accept a node path can also accept a UUID
- [node] `node:list`: Show node primary item value

### Bugs Fixes

Expand Down
23 changes: 22 additions & 1 deletion src/PHPCR/Shell/Console/Command/Phpcr/NodeListCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption;
use PHPCR\PropertyType;
use PHPCR\ItemNotFoundException;
use PHPCR\PropertyInterface;
use PHPCR\NodeInterface;

class NodeListCommand extends Command
{
Expand Down Expand Up @@ -99,12 +102,24 @@ private function renderChildren($currentNode, $table, $spacers)
unset($childNodeNames[$child->getName()]);
}

$primaryItemValue = '';
try {
$primaryItem = $child->getPrimaryItem();

if ($primaryItem instanceof PropertyInterface) {
$primaryItemValue = $this->textHelper->truncate($this->formatter->formatValue($primaryItem), 55);
} elseif ($primaryItem instanceof NodeInterface) {
$primaryItemValue = sprintf('+%s', $primaryItem->getName());
}
} catch (ItemNotFoundException $e) {
}

$isLast = count($children) === $i;

$table->addRow(array(
'<node>' . implode('', $spacers) . $this->formatter->formatNodeName($child) . '</node>',
$child->getPrimaryNodeType()->getName(),
'',
$primaryItemValue,
));

if (count($spacers) < $this->maxLevel) {
Expand Down Expand Up @@ -136,6 +151,12 @@ private function renderProperties($currentNode, $table, $spacers)
{
$properties = $currentNode->getProperties($this->filters ? : null);

try {
$primaryItem = $currentNode->getPrimaryItem();
} catch (ItemNotFoundException $e) {
$primaryItem = null;
}

$nodeType = $currentNode->getPrimaryNodeType();
$propertyDefinitions = $nodeType->getDeclaredPropertyDefinitions();

Expand Down