function threadedToLeveled($treaded, $lvl = 0) { $out = array(); foreach ($treaded as $item) { $children = null; if (!empty($item['children'])) { $children = $item['children']; } unset($item['children']); $item['lvl'] = $lvl; $out[] = $item; if (!empty($children)) { $out = array_merge($out, SetMulti::threadedToLeveled($children, $lvl + 1)); } } return $out; }
function generateAroList($spacer = "---") { $prodList = $this->generateProductList(); //debug($prodList); $aros = $this->Aro->find('threaded', array('fields' => array('DISTINCT ' . $this->Aro->alias . '.id', $this->Aro->alias . '.parent_id', $this->Aro->alias . '.model', $this->Aro->alias . '.foreign_key', $this->Aro->alias . '.alias'), 'joins' => array(array('table' => $this->Aro->useTable, 'alias' => 'Aro2', 'type' => 'INNER', 'conditions' => array('Aro2.foreign_key' => array_keys($prodList), 'Aro2.model' => 'ShopProduct', $this->Aro->alias . '.lft <= Aro2.lft', $this->Aro->alias . '.rght >= Aro2.rght'))))); App::import('Lib', 'Shop.SetMulti'); $aros = SetMulti::threadedToLeveled($aros); //debug($aros); $list = array(); foreach ($aros as $aro) { $val = ''; if (!empty($aro[$this->Aro->alias]['model']) && !empty($aro[$this->Aro->alias]['foreign_key']) && $aro[$this->Aro->alias]['model'] == $this->alias) { $val = $prodList[$aro[$this->Aro->alias]['foreign_key']]; } elseif (!empty($aro[$this->Aro->alias]['alias'])) { $val = $aro[$this->Aro->alias]['alias']; if ($val == $this->rootNodeAlias) { $val = __('All Products', true); } } elseif (!empty($aro[$this->Aro->alias]['model']) && !empty($aro[$this->Aro->alias]['foreign_key'])) { $val = $aro[$this->Aro->alias]['model'] . ':' . $aro[$this->Aro->alias]['foreign_key']; } else { $val = $aro[$this->Aro->alias]['id']; } $list[$aro[$this->Aro->alias]['id']] = str_repeat($spacer, $aro['lvl']) . $val; } //debug($list); return $list; }