/** * Rebuild parent and child tree information * * @access public * @param int [Optional Skin set id to rebuild. If no value given, all skin sets are rebuilt] * @return boolean */ public function rebuildTreeInformation($setID = NULL) { //----------------------------------------- // INIT //----------------------------------------- $_where = $setID !== NULL ? 'set_id=' . $setID : ''; /* Rebuild tiers to ensure cache isn't stale after a new set has been added */ $this->recursiveTiers->rebuildTiers(); //----------------------------------------- // Grab skins and loop through 'em //----------------------------------------- $this->DB->build(array('select' => '*', 'from' => 'skin_collections', 'where' => $_where, 'order' => 'set_id ASC')); $outer = $this->DB->execute(); while ($row = $this->DB->fetch($outer)) { $_parents = $this->recursiveTiers->fetchItemParents($row['set_id']); $_children = $this->recursiveTiers->fetchItemChildren($row['set_id']); $this->DB->update('skin_collections', array('set_parent_array' => serialize(is_array($_parents) ? $_parents : array()), 'set_child_array' => serialize(is_array($_children) ? $_children : array())), 'set_id=' . $row['set_id']); if (count($_parents) and $setID) { foreach ($_parents as $parent) { $this->rebuildTreeInformation($parent); } } } return TRUE; }
/** * Rebuild parent and child tree information * * @access public * @param int [Optional Skin set id to rebuild. If no value given, all skin sets are rebuilt] * @return boolean */ public function rebuildTreeInformation($setID = NULL) { //----------------------------------------- // INIT //----------------------------------------- $_where = $setID !== NULL ? 'set_id=' . $setID : ''; /* Rebuild tiers to ensure cache isn't stale after a new set has been added */ $this->caches['skinsets'] = array(); $this->recursiveTiers->rebuildTiers(); //----------------------------------------- // Grab skins and loop through 'em //----------------------------------------- $this->DB->build(array('select' => '*', 'from' => 'skin_collections', 'where' => $_where, 'order' => 'set_id ASC')); $outer = $this->DB->execute(); while ($row = $this->DB->fetch($outer)) { $_parents = $this->recursiveTiers->fetchItemParents($row['set_id']); $_children = $this->recursiveTiers->fetchItemChildren($row['set_id']); $this->DB->update('skin_collections', array('set_parent_array' => serialize(is_array($_parents) ? $_parents : array()), 'set_child_array' => serialize(is_array($_children) ? $_children : array())), 'set_id=' . $row['set_id']); /* Reset master key - parents */ if (count($_parents) and $row['set_id']) { $_p = $_parents; $_id = array_pop($_p); $rootParent = $this->fetchSkinData($_id, true); /* If no parent, we must be a parent, then */ if (!$rootParent['set_id']) { $rootParent = $this->fetchSkinData($setID, true); } $this->DB->update('skin_collections', array('set_master_key' => $rootParent['set_master_key'] ? $rootParent['set_master_key'] : 'root'), 'set_id IN (' . implode(',', $_parents) . ')'); } /* Reset master key - children */ if (count($_children) and $row['set_id']) { if (!is_array($rootParent)) { $_p = $_parents; $_id = array_pop($_p); $rootParent = $this->fetchSkinData($_id, true); /* If no parent, we must be a parent, then */ if (!$rootParent['set_id']) { $rootParent = $this->fetchSkinData($setID, true); } } $this->DB->update('skin_collections', array('set_master_key' => $rootParent['set_master_key'] ? $rootParent['set_master_key'] : 'root'), 'set_id IN (' . implode(',', $_children) . ')'); } if (count($_parents) and $setID) { foreach ($_parents as $parent) { $this->rebuildTreeInformation($parent); } } } return TRUE; }