Commits

pietschy committed 45cab6d

added injections including stacks and added a basic block type

Comments (0)

Files changed (15)

blocks/navigation_builder_block/add.php

+<?php  defined('C5_EXECUTE') or die("Access Denied.");
+$this->inc('edit.php');

blocks/navigation_builder_block/auto.js

+ccmValidateBlockForm = function() {
+	
+	if ($('input[name=field_1_link_cID]').val() == '' || $('input[name=field_1_link_cID]').val() == 0) {
+		ccm_addError('Missing required link: Root Page');
+	}
+
+	if ($('select[name=field_2_select_value]').val() == '' || $('select[name=field_2_select_value]').val() == 0) {
+		ccm_addError('Missing required selection: Depth');
+	}
+
+
+	return false;
+}

blocks/navigation_builder_block/controller.php

+<?php  defined('C5_EXECUTE') or die("Access Denied.");
+
+class NavigationBuilderBlockBlockController extends BlockController {
+	
+	protected $btName = 'Navigation Block';
+	protected $btDescription = '';
+	protected $btTable = 'btDCNavigationBuilderBlock';
+	
+	protected $btInterfaceWidth = "700";
+	protected $btInterfaceHeight = "450";
+	
+	protected $btCacheBlockRecord = true;
+	protected $btCacheBlockOutput = true;
+	protected $btCacheBlockOutputOnPost = true;
+	protected $btCacheBlockOutputForRegisteredUsers = false;
+	protected $btCacheBlockOutputLifetime = CACHE_LIFETIME;
+
+    public function on_before_render()
+    {
+        if (!empty($this->field_1_link_cID)) {
+            Loader::model('NavigationBuilder', 'navigation_builder');
+            $builder = new NavigationBuilder();
+            $builder->setMaxDepth($this->field_2_select_value); // the text values happen to correspond to the int value required.
+            $rootPage = Page::getByID($this->field_1_link_cID);
+            $navRoot = $builder->build($rootPage);
+            $this->set('rootPage', $rootPage);
+            $this->set('navRoot', $navRoot);
+        }
+    }
+
+
+    public function save($args) {
+		$args['field_1_link_cID'] = empty($args['field_1_link_cID']) ? 0 : $args['field_1_link_cID'];
+		parent::save($args);
+	}
+
+
+}

blocks/navigation_builder_block/db.xml

+<?xml version="1.0"?>
+<schema version="0.3">
+	<table name="btDCNavigationBuilderBlock">
+		<field name="bID" type="I"><key /><unsigned /></field>
+
+		<field name="field_1_link_cID" type="I"></field>
+		<field name="field_1_link_text" type="C" size="255"></field>
+
+		<field name="field_2_select_value" type="I"><default value="0" /></field>
+
+
+	</table>
+</schema>

blocks/navigation_builder_block/edit.php

+<?php  defined('C5_EXECUTE') or die("Access Denied.");
+$ps = Loader::helper('form/page_selector');
+?>
+
+<style type="text/css" media="screen">
+	.ccm-block-field-group h2 { margin-bottom: 5px; }
+	.ccm-block-field-group td { vertical-align: middle; }
+</style>
+
+<div class="ccm-block-field-group">
+	<h2>Root Page</h2>
+	<?php  echo $ps->selectPage('field_1_link_cID', $field_1_link_cID); ?>
+</div>
+
+<div class="ccm-block-field-group">
+	<h2>Depth</h2>
+	<?php 
+	$options = array(
+		'0' => '--Choose One--',
+		'1' => '1',
+		'2' => '2',
+		'3' => '3',
+		'4' => '4',
+		'5' => '5',
+		'6' => '6',
+	);
+	echo $form->select('field_2_select_value', $options, $field_2_select_value);
+	?>
+</div>
+
+

blocks/navigation_builder_block/icon.png

Added
New image

blocks/navigation_builder_block/view.php

+<?php  defined('C5_EXECUTE') or die("Access Denied.");
+/** @var NavRoot $navRoot */
+if (Page::getCurrentPage()->isSystemPage())
+{
+    $config = is_null($rootPage) ? '' : '[rootPage='.$rootPage->getCollectionName().']';
+    echo "Navigation Block " . $config;
+}
+else
+{
+    if (!is_null($navRoot)) {
+        $navRoot->render();
+    }
+}
+
+
 
     protected $pkgHandle = 'navigation_builder';
     protected $appVersionRequired = '5.4';
-    protected $pkgVersion = '1.1.0';
+    protected $pkgVersion = '1.1.1';
 
     public function getPackageDescription()
     {
     {
         $pkg = parent::install();
 
-        // todo: should I include some standard page attributes like 'faux_home'
+        BlockType::installBlockTypeFromPackage('navigation_builder_block', $pkg);
     }
 }
 

elements/navigation_builder/default/menu.php

 }
 ?>
 <ul class="<?=$navRoot->getRenderOption('class','nav')?>">
-    <?= $navRoot->renderChildItems() ?>
+    <?= $navRoot->renderChildren() ?>
 </ul>

elements/navigation_builder/default/nav_item.php

     <? if ($navItem->hasChildren()) { ?>
     <a href="#" class="-flyout-toggle"><span> </span></a>
     <ul class="-flyout">
-        <? $navItem->renderChildItems() ?>
+        <? $navItem->renderChildren() ?>
     </ul>
     <? } ?>
 </li>

elements/navigation_builder/nav_bar/menu.php

 }
 ?>
 <ul class="<?=$navRoot->getRenderOption('class','nav-bar')?>">
-    <?= $navRoot->renderChildItems() ?>
+    <?= $navRoot->renderChildren() ?>
 </ul>

elements/navigation_builder/nav_bar/nav_item.php

     <? if ($navItem->hasChildren()) { ?>
     <a href="#" class="flyout-toggle"><span> </span></a>
     <ul class="flyout">
-        <? $navItem->renderChildItems() ?>
+        <? $navItem->renderChildren() ?>
     </ul>
     <? } ?>
 </li>

models/BestPathPredicate.php

      */
     function __construct($activePage)
     {
+        /** @var TerarpCommonPageHelper $ph */
+        $ph = Loader::helper('page', 'terarp_common');
         $this->activePage = $activePage;
-        $this->parentIDs = $this->getParentIDs($activePage);
+        $this->parentIDs = $ph->getParentIDs($activePage);
     }
 
     /**
 
         return false;
     }
-
-    /**
-     * @param $page Page
-     * @return int[]
-     */
-    private function getParentIDs($page)
-    {
-        $result = array();
-        $id = $page->getCollectionID();
-        while ($id != HOME_CID) {
-            $id = $page->getCollectionParentIDFromChildID($id);
-            // if were editing the page default we don't have any parents.
-            if ($id == 0) break;
-            // otherwise keep collecting until we've hit the home page.
-            $result[] = $id;
-        }
-
-        return $result;
-    }
 }

models/NavItem.php

     /**
      *
      */
-    public function renderChildItems()
+    public function renderChildren()
     {
         foreach ($this->children as $child) {
             /** @var NavItem $child */

models/NavigationBuilder.php

 
     /** @var int $maxDepth*/
     private $maxDepth = -1;
+//    /** @var int $startDepth */
+//    private $startDepth = -1;
 
     /** @var array */
     private $excludedPaths = array();
         return $navRoot;
     }
 
-
     /**
      * A recursive method that is the core method responsible for generating the navigation tree.  It
      * calls {@link shouldInclude} to determine if a page should be included in the tree, then calls
         return new PageNavRoot($page);
     }
 
+//    public function setStartDepth($startDepth)
+//    {
+//        $this->startDepth = $startDepth;
+//    }
+//
+//    public function getStartDepth()
+//    {
+//        return $this->startDepth;
+//    }
+
     /**
      * Sets the max depth to which this builder will traverse the page structure.  A value of
      * 1 will return only the first level of pages under the C5 root page.