Skip to content

Commit

Permalink
1.2 Additions/Bug Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelfromtheoutfit committed Jan 13, 2017
1 parent d68a336 commit 7f9409e
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 13 deletions.
3 changes: 2 additions & 1 deletion .gitignore
@@ -1,3 +1,4 @@
# Craft Storage (cache) [http://buildwithcraft.com/help/craft-storage-gitignore]
/craft/storage/*
!/craft/storage/logo/*
!/craft/storage/logo/*
.DS_Store
2 changes: 1 addition & 1 deletion NaveePlugin.php
Expand Up @@ -10,7 +10,7 @@ public function getName()

public function getVersion()
{
return '1.1.1';
return '1.2.0';
}

public function getDeveloper()
Expand Down
3 changes: 3 additions & 0 deletions models/Navee_ConfigModel.php
Expand Up @@ -35,11 +35,14 @@ protected function defineAttributes()
'id' => array(AttributeType::String, 'default' => ''),
'ignoreIncludeInNavigation' => array(AttributeType::Bool, 'default' => false),
'maxDepth' => array(AttributeType::Number, 'default' => 0),
'reverseNodes' => array(AttributeType::Bool, 'default' => false),
'skipDisabledEntries' => array(AttributeType::Bool, 'default' => false),
'startDepth' => array(AttributeType::Number, 'default' => 1),
'startWithActive' => array(AttributeType::Bool, 'default' => false),
'startWithAncestorOfActive' => array(AttributeType::Bool, 'default' => false),
'startWithChildrenOfActive' => array(AttributeType::Bool, 'default' => false),
'startWithNodeId' => array(AttributeType::Number, 'default' => 0),
'startWithChildrenOfNodeId' => array(AttributeType::Number, 'default' => 0),
'startWithSiblingsOfActive' => array(AttributeType::Bool, 'default' => false),
'startXLevelsAboveActive' => array(AttributeType::Number, 'default' => 0),
'userGroups' => array(AttributeType::Mixed, 'default' => ''),
Expand Down
1 change: 1 addition & 0 deletions models/Navee_NodeModel.php
Expand Up @@ -44,6 +44,7 @@ protected function defineAttributes()
'linkedElementCpEditUrl' => array(AttributeType::String, 'default' => ''),
'linkedElementType' => array(AttributeType::String, 'default' => ''),
'regex' => array(AttributeType::String, 'default' => ''),
'hasChildren' => array(AttributeType::Bool, 'default' => false),
));
}

Expand Down
13 changes: 13 additions & 0 deletions releases.json
@@ -1,4 +1,17 @@
[
{
"version": "1.1.2",
"downloadUrl": "https://github.com/fromtheoutfit/navee/archive/v1.1.2.zip",
"date": "2017-01-13T15:00:00-05:00",
"notes": [
"[Added] reverse parameter.",
"[Added] startWithNodeId parameter.",
"[Added] startWithChildrenOfNodeId parameter.",
"[Added] hasChildren variable.",
"[Fixed] Issue where breadcrumbs with no matching node return the entire tree.",
"[Fixed] Issue where only first 100 nodes are returned on a given tree."
]
},
{
"version": "1.1.1",
"downloadUrl": "https://github.com/fromtheoutfit/navee/archive/v1.1.1.zip",
Expand Down
78 changes: 67 additions & 11 deletions services/NaveeService.php
Expand Up @@ -17,7 +17,6 @@ class NaveeService extends BaseApplicationComponent {
public function __construct()
{
$this->config = new Navee_ConfigModel();

}

/**
Expand All @@ -41,7 +40,15 @@ public function setConfig($config)
public function getNav($navigationHandle)
{
// get the nodes for this navigation
$criteria = craft()->elements->getCriteria('Navee_Node');
if ($this->config->reverseNodes)
{
$criteria = craft()->elements->getCriteria('Navee_Node')->limit(null)->order('lft desc');
}
else
{
$criteria = craft()->elements->getCriteria('Navee_Node')->limit(null);
}

$criteria->navigation = $navigationHandle;
$nodes = $criteria->find();
$removedNodes = array();
Expand All @@ -58,7 +65,7 @@ public function getNav($navigationHandle)
foreach ($nodes as $k => $node)
{
// Set the link for this node based on the type
$node = $this->setLink($node);
$node = $this->setLink($node);
$node->text = $node->title;

// Check to see if this node should be removed because it
Expand Down Expand Up @@ -99,6 +106,9 @@ public function getNav($navigationHandle)
// now let's limit the nav based on which parameters are passed
$nodes = $this->getSubsetOfNodes($nodes, $activeNodes);

// Mark all nodes that have children
$nodes = $this->setHasChildren($nodes);

}

return $nodes;
Expand Down Expand Up @@ -126,7 +136,7 @@ public function setLink(Navee_NodeModel $node)
$node->link = $node->customUri;
break;
case 'assetId':
$file = craft()->assets->getFileById($node->assetId);
$file = craft()->assets->getFileById($node->assetId);
if ($file)
{
$sourceType = craft()->assetSources->getSourceTypeById($file->sourceId);
Expand Down Expand Up @@ -176,7 +186,7 @@ private function nodeActive(Navee_NodeModel $node)
*
* @access private
* @param Navee_NodeModel $node
* @param string $currentUri
* @param string $currentUri
* @return boolean
*/

Expand Down Expand Up @@ -365,6 +375,17 @@ private function setActiveClasses($nodes = array())
return $nodes;
}

private function setHasChildren($nodes)
{
foreach ($nodes as $node)
{
$node->hasChildren = (((int) $node->rgt - $node->lft) > 1) ? true : false;

}

return $nodes;
}

private function getUserGroupIdArray()
{
$data = array();
Expand Down Expand Up @@ -440,10 +461,12 @@ private function getSubsetOfNodes($nodes, $activeNodes)
// There are no active nodes - which means that we should return an empty array
// if any of the parameters that are dependant on an active node have been passed
if ($this->config->startWithActive ||
$this->config->startWithAncestorOfActive ||
$this->config->startWithChildrenOfActive ||
$this->config->startWithSiblingsOfActive ||
$this->config->startXLevelsAboveActive)
$this->config->startWithAncestorOfActive ||
$this->config->startWithChildrenOfActive ||
$this->config->startWithSiblingsOfActive ||
$this->config->startXLevelsAboveActive ||
$this->config->breadcrumbs
)
{
return array();
}
Expand All @@ -454,12 +477,25 @@ private function getSubsetOfNodes($nodes, $activeNodes)
{
if (!isset($rootNode))
{
if ($node->level == 1 && ($node->descendantActive || $node->active))
if ($this->config->startWithNodeId || $this->config->startWithChildrenOfNodeId)
{
if ((int) $node->id == (int) $this->config->startWithNodeId
|| (int) $node->id == (int) $this->config->startWithChildrenOfNodeId)
{
$rootNode = $node;
break;
}
}
elseif ($node->level == 1 && ($node->descendantActive || $node->active))
{
$rootNode = $node;
break;
}
}
}

foreach ($nodes as $k => $node)
{
// Check to see if this node should be removed because it
// is a descendant of a previously removed node
if ($this->ancestorRemoved($node, $removedNodes))
Expand Down Expand Up @@ -528,6 +564,24 @@ private function getSubsetOfNodes($nodes, $activeNodes)
continue;
}
}
// start with a given node id
elseif ((int) $this->config->startWithNodeId && isset($rootNode))
{
if ($node->lft <= $rootNode->lft || $node->rgt >= $rootNode->rgt)
{
unset($nodes[$k]);
continue;
}
}
// start with children of a given node id
elseif ((int) $this->config->startWithChildrenOfNodeId && isset($rootNode))
{
if ($node->lft < $rootNode->lft || $node->rgt > $rootNode->rgt)
{
unset($nodes[$k]);
continue;
}
}
// start with the active node
elseif ($this->config->startWithSiblingsOfActive)
{
Expand Down Expand Up @@ -582,6 +636,7 @@ private function getSubsetOfNodes($nodes, $activeNodes)
}

$nodes = $this->rebuildNestedSet($nodes);

return $nodes;
}

Expand Down Expand Up @@ -611,7 +666,7 @@ private function nodeInBranchOfActiveNode(Navee_NodeModel $rootNode, Navee_NodeM

private function rebuildNestedSet($nodes)
{
foreach($nodes as $k => $v)
foreach ($nodes as $k => $v)
{

if (isset($prevIndex) && ((int) $nodes[$prevIndex]->lft + 1 !== (int) $nodes[$prevIndex]->rgt))
Expand All @@ -625,6 +680,7 @@ private function rebuildNestedSet($nodes)
$prevIndex = $k;

}

return $nodes;
}

Expand Down

0 comments on commit 7f9409e

Please sign in to comment.