示例#1
0
 /**
  * Build all my parameters for the view
  * @todo Pull as much as possible into the model, including the column names
  */
 public function onRender()
 {
     // Set the parentNode for the component output
     $topNode = menuModel::find($this->getIdFromProperty($this->property('start')));
     $this->page['parentNode'] = $topNode;
     // What page is active?
     $this->page['activeLeft'] = 0;
     $this->page['activeRight'] = 0;
     $activeNode = $this->getIdFromProperty($this->property('activeNode'));
     if ($activeNode) {
         // It's been set by the user, so use what they've set it as
         $activeNode = menuModel::find($activeNode);
     } elseif ($topNode) {
         // Go and find the page we're on
         $baseFileName = $this->page->page->getBaseFileName();
         // Get extra URL parameters
         $params = $this->page->controller->getRouter()->getParameters();
         // And make sure the active page is a child of the parentNode
         $activeNode = menuModel::where('url', $baseFileName)->where('nest_left', '>', $topNode->nest_left)->where('nest_right', '<', $topNode->nest_right);
         $activeNode = $activeNode->first();
     }
     // If I've got a result that is a node
     if ($activeNode && menuModel::getClassName() === get_class($activeNode)) {
         $this->page['activeLeft'] = (int) $activeNode->nest_left;
         $this->page['activeRight'] = (int) $activeNode->nest_right;
     }
     // How deep do we want to go?
     $this->page['numberOfLevels'] = (int) $this->property('numberOfLevels');
     // Add the classes to the view
     $this->page['primaryClasses'] = $this->property('primaryClasses');
     $this->page['secondaryClasses'] = $this->property('secondaryClasses');
     $this->page['tertiaryClasses'] = $this->property('tertiaryClasses');
     $this->page['listItemClasses'] = $this->property('listItemClasses');
 }
 /**
  * Update the menu item position
  */
 public function reorder_onMove()
 {
     $sourceNode = Menu::find(post('sourceNode'));
     $targetNode = post('targetNode') ? Menu::find(post('targetNode')) : null;
     if ($sourceNode == $targetNode) {
         return;
     }
     switch (post('position')) {
         case 'before':
             $sourceNode->moveBefore($targetNode);
             break;
         case 'after':
             $sourceNode->moveAfter($targetNode);
             break;
         case 'child':
             $sourceNode->makeChildOf($targetNode);
             break;
         default:
             $sourceNode->makeRoot();
             break;
     }
 }