public function setupDefaults($navs) { // Create a new layout called 'Default' $defaultLayout = CpNav_LayoutRecord::model()->findById('1'); if ($defaultLayout) { $layoutsRecord = $defaultLayout; } else { $layoutsRecord = new CpNav_LayoutRecord(); } //$layoutsRecord->id = '1'; $layoutsRecord->name = 'Default'; $layoutsRecord->isDefault = '1'; $layoutsRecord->save(); // With this new layout in mind, populate the nav table with items from the default cp nav $i = 0; foreach ($navs as $key => $value) { $navRecord = new CpNav_NavRecord(); $navRecord->layoutId = '1'; $navRecord->handle = $key; $navRecord->currLabel = $value['label']; $navRecord->prevLabel = $value['label']; $navRecord->enabled = '1'; $navRecord->order = $i; $navRecord->url = array_key_exists('url', $value) ? $value['url'] : $key; $navRecord->prevUrl = $navRecord->url; $navRecord->manualNav = '0'; $navRecord->newWindow = '0'; $navRecord->save(); $i++; } }
public function deleteLayout(CpNav_LayoutModel $layout) { $layoutRecord = CpNav_LayoutRecord::model()->findById($layout->id); // Delete all fields for this layout $navRecords = CpNav_NavRecord::model()->deleteAll('layoutId = :layoutId', array('layoutId' => $layout->id)); $layoutRecord->delete(); return true; }