public function dealer_creation() { $class = CONTENT_MODEL; $dealer_class = get_class($this); $model = new $class("live"); $url = $dealer_class::$dealer_section . Inflections::to_url($this->title) . "/"; if (($pages = $this->pages) && $pages->count() || $model->filter("permalink", $url)->first()) { return true; } else { //find dealers section if ($dealers = $model->filter("permalink", $dealer_class::$dealer_section)->first()) { $model = $model->clear(); //create the first level of this dealer $dealer_data = array('title' => $this->title, 'layout' => 'dealer', 'page_type' => $dealer_class::$dealer_homepage_partial, 'content' => $this->content, 'parent_id' => $dealers->primval); //create the dealer skel if ($saved = $model->update_attributes($dealer_data)) { $saved = $saved->generate_permalink()->map_live()->children_move()->show()->save(); $saved->dealers = $this; $this->pages = $saved; $subs = array(); //copy the national main pages $i = 0; foreach ($dealer_class::$dealer_top_pages as $title => $skel) { $look = new $class("live"); if ($found = $look->filter("permalink", $skel)->first()) { $info = $found->row; unset($info['id'], $info['permalink']); $info['parent_id'] = $saved->primval; $info['sort'] = $i; //custom names if (!is_numeric($title)) { $info['title'] = $title; } else { $info['title'] = str_replace("Latest ", "", $info['title']); } $info['dealer_content_id'] = $found->primval; $subs[] = $page = $look->update_attributes($info)->generate_permalink()->map_live()->children_move()->show()->save(); //manytomany copy foreach ($found->columns as $name => $info) { if ($info[0] == "ManyToManyField") { foreach ($found->{$name} as $assoc) { $page->{$name} = $assoc; } } } $i++; } } foreach ($dealer_class::$dealer_extra_pages as $info) { $pg = new $class(); $info['parent_id'] = $saved->primval; $info['date_start'] = date("Y-m-d", strtotime("now-1 day")); $info['sort'] = $i; $extras[] = $pg->update_attributes($info)->generate_permalink()->map_live()->children_move()->show()->save(); $i++; } } } $class = get_class($this); WaxEvent::run($class . ".dealer_creation", $this); } return array("subs" => $subs, "extras" => $extras); }