From 7f9409ef852403fe1a53bab7cf6c7b475cf2fe94 Mon Sep 17 00:00:00 2001 From: Michael Witwicki Date: Fri, 13 Jan 2017 15:36:39 -0500 Subject: [PATCH] 1.2 Additions/Bug Fixes --- .gitignore | 3 +- NaveePlugin.php | 2 +- models/Navee_ConfigModel.php | 3 ++ models/Navee_NodeModel.php | 1 + releases.json | 13 ++++++ services/NaveeService.php | 78 +++++++++++++++++++++++++++++++----- 6 files changed, 87 insertions(+), 13 deletions(-) diff --git a/.gitignore b/.gitignore index a70d477..c7a7648 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ # Craft Storage (cache) [http://buildwithcraft.com/help/craft-storage-gitignore] /craft/storage/* -!/craft/storage/logo/* \ No newline at end of file +!/craft/storage/logo/* +.DS_Store diff --git a/NaveePlugin.php b/NaveePlugin.php index 836c9f9..f3f4941 100644 --- a/NaveePlugin.php +++ b/NaveePlugin.php @@ -10,7 +10,7 @@ public function getName() public function getVersion() { - return '1.1.1'; + return '1.2.0'; } public function getDeveloper() diff --git a/models/Navee_ConfigModel.php b/models/Navee_ConfigModel.php index f342e38..4468b1d 100644 --- a/models/Navee_ConfigModel.php +++ b/models/Navee_ConfigModel.php @@ -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' => ''), diff --git a/models/Navee_NodeModel.php b/models/Navee_NodeModel.php index 99b757d..4328bd3 100644 --- a/models/Navee_NodeModel.php +++ b/models/Navee_NodeModel.php @@ -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), )); } diff --git a/releases.json b/releases.json index 3f25a8b..febecee 100644 --- a/releases.json +++ b/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", diff --git a/services/NaveeService.php b/services/NaveeService.php index 1508b56..43ae976 100644 --- a/services/NaveeService.php +++ b/services/NaveeService.php @@ -17,7 +17,6 @@ class NaveeService extends BaseApplicationComponent { public function __construct() { $this->config = new Navee_ConfigModel(); - } /** @@ -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(); @@ -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 @@ -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; @@ -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); @@ -176,7 +186,7 @@ private function nodeActive(Navee_NodeModel $node) * * @access private * @param Navee_NodeModel $node - * @param string $currentUri + * @param string $currentUri * @return boolean */ @@ -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(); @@ -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(); } @@ -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)) @@ -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) { @@ -582,6 +636,7 @@ private function getSubsetOfNodes($nodes, $activeNodes) } $nodes = $this->rebuildNestedSet($nodes); + return $nodes; } @@ -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)) @@ -625,6 +680,7 @@ private function rebuildNestedSet($nodes) $prevIndex = $k; } + return $nodes; }