function fix_categories()
 {
     //--Flat Structure--//
     global $db;
     $baseCat = new storeCategory();
     //$Nodes = $db->selectObjects('storeCategories');
     $Nodes = $baseCat->find('all', '', 'lft ASC');
     //--This function converts flat structure into an array--//
     function BuildTree($TheNodes, $ID = 0, $depth = -1)
     {
         $Tree = array();
         if (is_array($TheNodes)) {
             foreach ($TheNodes as $Node) {
                 if ($Node->parent_id == $ID) {
                     array_push($Tree, $Node);
                 }
             }
             $depth++;
             for ($x = 0; $x < count($Tree); $x++) {
                 $Tree[$x]->depth = $depth;
                 $Tree[$x]->kids = BuildTree($TheNodes, $Tree[$x]->id, $depth);
                 //array_merge($test,$Tree[$x]["kids"]);
             }
             return $Tree;
         }
     }
     //--Call Build Tree (returns structured array)
     $TheTree = BuildTree($Nodes);
     //eDebug($TheTree,true);
     // flattens a tree created by parent/child relationships
     function recurseBuild(&$thisNode, &$thisLeft, &$thisRight)
     {
         $thisNode->lft = $thisLeft;
         if (count($thisNode->kids) > 0) {
             $thisLeft = $thisNode->lft + 1;
             foreach ($thisNode->kids as &$myKidNode) {
                 $thisRight = $thisLeft + 1;
                 recurseBuild($myKidNode, $thisLeft, $thisRight);
                 $myKidNode->save();
             }
             $thisNode->rgt = $thisLeft;
             $thisLeft = $thisRight;
         } else {
             $thisNode->rgt = $thisRight;
             $thisLeft = $thisRight + 1;
         }
         $thisRight = $thisLeft + 1;
         $thisNode->save();
     }
     //if kids, set lft, but not right
     //else set both and move down
     $newLeft = 1;
     $newRight = 2;
     foreach ($TheTree as &$myNode) {
         recurseBuild($myNode, $newLeft, $newRight);
     }
     //eDebug($TheTree,true);
     echo "Done";
     /*function flattenArray(array $array){
           $ret_array = array();
           $counter=0;
           foreach(new RecursiveIteratorIterator(new RecursiveArrayIterator($array)) as $key=>$value) {
               if ($key=='id') {
                   $counter++;
               }
               $ret_array[$counter][$key] = $value;
           }
           return $ret_array;
       }*/
     // takes a flat array with propper parent/child relationships in propper order
     // and adds the lft and rgt extents correctly for a nested set
     /*function nestify($categories) {
                 // Trees mapped            
                 $trees = array();
                 $trackParents = array();
                 $depth=0;
                 $counter=1;
                 $prevDepth=0;
     
                 foreach ($categories as $key=>$val) {
                     if ($counter==1) {
                         # first in loop. We should only hit this once: first.
                         $categories[$key]['lft'] = $counter;
                         $counter++;
                     } else if ($val['depth']>$prevDepth) {
                         # we have a child of the previous node
                         $trackParents[] = $key-1;
                         $categories[$key]['lft'] = $counter;
                         $counter++;
                     } else if ($val['depth']==$prevDepth) {
                         # we have a sibling of the previous node
                         $categories[$key-1]['rgt'] = $counter;
                         $counter++;
                         $categories[$key]['lft'] = $counter;
                         $counter++;
                     } else {
                         # we have moved up in depth, but how far up?
                         $categories[$key-1]['rgt'] = $counter;
                         $counter++;
                         $l=count($trackParents);
                         while($l > 0 && $trackParents[$l - 1]['depth'] >= $val['depth']) {
                             $categories[$trackParents[$l - 1]]['rgt'] = $counter;
                             array_pop($trackParents);
                             $counter++;
                             $l--;
                         }
                         
                         $categories[$key]['lft'] = $counter;
                         //???$counter++;
                     }        
                     $prevDepth=$val['depth'];
                 }
     
                 $categories[$key]['rgt'] = $counter;
                 return $categories;
             } */
     // takes a flat nested set formatted array and creates a multi-dimensional array from it
     /*function toHierarchy($collection)
             {
                     // Trees mapped
                     $trees = array();
                     $l = 0;
     
                     if (count($collection) > 0) {
                             // Node Stack. Used to help building the hierarchy
                             $stack = array();
     
                             foreach ($collection as $node) {
                                     $item = $node;
                                     $item['children'] = array();
     
                                     // Number of stack items
                                     $l = count($stack);
     
                                     // Check if we're dealing with different levels
                                     while($l > 0 && $stack[$l - 1]['depth'] >= $item['depth']) {
                                             array_pop($stack);
                                             $l--;
                                     }
     
                                     // Stack is empty (we are inspecting the root)
                                     if ($l == 0) {
                                             // Assigning the root node
                                             $i = count($trees);
                                             $trees[$i] = $item;
                                             $stack[] = & $trees[$i];
                                     } else {
                                             // Add node to parent
                                             $i = count($stack[$l - 1]['children']);
                                             $stack[$l - 1]['children'][$i] = $item;
                                             $stack[] = & $stack[$l - 1]['children'][$i];
                                     }
                             }
                     }
     
                     return $trees;
             }*/
     // this will test our data manipulation
     // eDebug(toHierarchy(nestify(flattenArray($TheTree))),1);
     /*$flat_fixed_cats = nestify(flattenArray($TheTree));
               
       foreach ($flat_fixed_cats as $k=>$v) {
           $cat = new storeCategory($v['id']);
           $cat->lft = $v['lft'];
           $cat->rgt = $v['rgt'];
           $cat->save();
           eDebug($cat);
       }
         */
     //-Show Array Structure--//
     // print_r($TheTree);
     //
     //
     // //--Print the Categories, and send their children to DrawBranch--//
     // //--The code below allows you to keep track of what category you're currently drawing--//
     //
     // printf("<ul>");
     //
     // foreach($TheTree as $MyNode) {
     //     printf("<li>{$MyNode['Name']}</li>");
     //     if(is_array($MyNode["Children"]) && !empty($MyNode["Children"])) {
     //         DrawBranch($MyNode["Children"]);
     //     }
     // }
     // printf("</ul>");
     // //--Recursive printer, should draw a child, and any of its children--//
     //
     // function DrawBranch($Node){
     //     printf("<ul>");
     //
     //     foreach($Node as $Entity) {
     //         printf("<li>{$Entity['Name']}</li>");
     //
     //         if(is_array($Entity["Children"]) && !empty($Entity["Children"])) {
     //             DrawBranch($Entity["Children"]);
     //         }
     //
     //         printf("</ul>");
     //     }
     // }
 }
Ejemplo n.º 2
0
 function showFullTree()
 {
     $category = new storeCategory(null, false, false);
     //$categories = $category->getEcomSubcategories();
     $categories = $category->getFullTree();
     $ancestors = $this->category->pathToNode();
     $curcat = $this->category;
     assign_to_template(array('categories' => $categories, 'curcat' => $curcat, 'topcat' => @$ancestors[0]));
 }
Ejemplo n.º 3
0
 public function __construct($params = array(), $get_assoc = true, $get_attached = true)
 {
     parent::__construct($params, $get_assoc, $get_attached);
 }
Ejemplo n.º 4
0
 public function routePageRequest()
 {
     global $db;
     if ($this->url_type == 'base') {
         // if we made it in here this is a request for http://www.baseurl.com
         if (expTheme::inAction()) {
             $_REQUEST['section'] = expSession::is_set('last_section') ? expSession::get('last_section') : SITE_DEFAULT_SECTION;
         } else {
             $_REQUEST['section'] = SITE_DEFAULT_SECTION;
         }
     } else {
         // Try to look up the page by sef_name first.  If that doesn't exist, strip out the dashes and
         // check the regular page names.  If that still doesn't work then we'll redirect them to the
         // search module using the page name as the search string.
         $section = $this->getPageByName($this->url_parts[0]);
         ########################################################
         #FJD TODO:  this needs further refinement
         #currently this requires a matching routerMap as such to work properly:
         /*
         $maps[] = array('controller'=>'store',
                 'action'=>'showall',
                 'url_parts'=>array(                
                         'title'=>'(.*)'),
         );
         $maps[] = array('controller'=>'store',
                 'action'=>'showByTitle',
                 'url_parts'=>array(                
                         'title'=>'(.*)'),
         );
         */
         //if section is empty, we'll look for the page overrides first and route to
         //routeActionRequest with some hand wacked variables. If we can't find an override
         //then we'll return false as usual
         if (empty($section)) {
             $sef_url = $this->url_parts[0];
             //check for a category
             $c = new storeCategory();
             $cat = $c->findBy('sef_url', $sef_url);
             if (empty($cat)) {
                 //check for a product
                 $p = new product();
                 $prod = $p->findBy('sef_url', $sef_url);
                 if (!empty($prod)) {
                     //fake parts and route to action
                     $this->url_type = 'action';
                     $this->url_parts[0] = 'store';
                     //controller
                     $this->url_parts[1] = 'showByTitle';
                     //controller
                     $this->url_parts[2] = 'title';
                     //controller
                     $this->url_parts[3] = $sef_url;
                     //controller
                     //eDebug($this->url_parts,true);
                     $this->params = $this->convertPartsToParams();
                     return $this->routeActionRequest();
                 }
                 //else fall through
             } else {
                 //fake parts and route to action
                 $this->url_type = 'action';
                 $this->url_parts[0] = 'store';
                 //controller
                 $this->url_parts[1] = 'showall';
                 //controller
                 $this->url_parts[2] = 'title';
                 //controller
                 $this->url_parts[3] = $sef_url;
                 //controller
                 //eDebug($this->url_parts,true);
                 $this->params = $this->convertPartsToParams();
                 return $this->routeActionRequest();
             }
             return false;
         }
         #########################################################
         //if (empty($section)) return false;  //couldnt find the page..let the calling action deal with it.
         $_REQUEST['section'] = $section->id;
     }
     expHistory::set('viewable', array('section' => $_REQUEST['section']));
     return true;
 }