Exemplo n.º 1
0
 /**
  * Execute the console command.
  *
  * @return void
  */
 public function fire()
 {
     echo 'Installing...' . PHP_EOL;
     foreach (array('resources', 'layouts', 'sections', 'blocks', 'pages', 'content', 'navigation_container', 'navigation_node') as $table) {
         if (Schema::hasTable($table)) {
             Schema::drop($table);
         }
     }
     echo 'Creating resources...' . PHP_EOL;
     $controller = App::make('Boyhagemann\\Admin\\Controller\\ResourceController');
     $controller->getModelBuilder()->export();
     $layout = App::make('Boyhagemann\\Pages\\Controller\\LayoutController');
     $layout->getModelBuilder()->export();
     $section = App::make('Boyhagemann\\Pages\\Controller\\SectionController');
     $section->getModelBuilder()->export();
     $block = App::make('Boyhagemann\\Pages\\Controller\\BlockController');
     $block->getModelBuilder()->export();
     $page = App::make('Boyhagemann\\Pages\\Controller\\PageController');
     $page->getModelBuilder()->export();
     $content = App::make('Boyhagemann\\Pages\\Controller\\ContentController');
     $content->getModelBuilder()->export();
     $container = App::make('Boyhagemann\\Navigation\\Controller\\ContainerController');
     $container->getModelBuilder()->export();
     $node = App::make('Boyhagemann\\Navigation\\Controller\\NodeController');
     $node->getModelBuilder()->export();
     echo 'Seeding resources...' . PHP_EOL;
     Layout::create(array('title' => 'Admin Layout', 'name' => 'admin::layouts.admin'));
     Layout::create(array('title' => 'Default Layout', 'name' => 'layouts.default'));
     Section::create(array('id' => 1, 'title' => 'Main content', 'name' => 'content', 'layout_id' => 1));
     Section::create(array('id' => 2, 'title' => 'Sidebar', 'name' => 'sidebar', 'layout_id' => 1));
     Section::create(array('id' => 3, 'title' => 'Main Menu', 'name' => 'menu', 'layout_id' => 1));
     Section::create(array('id' => 4, 'title' => 'Content', 'name' => 'content', 'layout_id' => 2));
     Container::create(array('id' => 1, 'title' => 'Admin menu', 'name' => 'admin'));
     $contentNode = Node::create(array('id' => 1, 'title' => 'Content', 'container_id' => 1));
     Block::create(array('id' => 1, 'title' => 'Admin menu', 'controller' => 'Boyhagemann\\Navigation\\Controller\\MenuController@admin'));
     Block::create(array('id' => 2, 'title' => 'Copy resource', 'controller' => 'Boyhagemann\\Admin\\Controller\\ResourceController@copy'));
     Block::create(array('id' => 3, 'title' => 'Text', 'controller' => 'Boyhagemann\\Text\\Controller\\TextController@text'));
     Content::create(array('global' => 1, 'page_id' => 1, 'section_id' => 3, 'block_id' => 1));
     Page::createWithContent('Admin home', '/admin', 'Boyhagemann\\Admin\\Controller\\IndexController@index', 'get', 'admin::layouts.admin');
     Page::createWithContent('Page content', '/admin/pages/{page}/content', 'Boyhagemann\\Pages\\Controller\\PageController@content', 'get', 'admin::layouts.admin');
     Page::createWithContent('Add content', '/admin/pages/{page}/content/create/{block}', 'Boyhagemann\\Pages\\Controller\\PageController@addContent', 'get', 'admin::layouts.admin');
     $tree = Page::createWithContent('Tree', '/admin/nodes/tree', 'Boyhagemann\\Navigation\\Controller\\NodeController@tree', 'get', 'admin::layouts.admin');
     Node::create(array('id' => 2, 'title' => 'Tree', 'container_id' => 1, 'page_id' => $tree->id));
     echo 'Registering resources...' . PHP_EOL;
     $controller->save('Layout', 'admin/layouts', get_class($layout));
     $controller->save('Section', 'admin/sections', get_class($section));
     $controller->save('Block', 'admin/blocks', get_class($block));
     $controller->save('Pages', 'admin/pages', get_class($page));
     $controller->save('Content', 'admin/content', get_class($content));
     $controller->save('Container', 'admin/containers', get_class($container));
     $controller->save('Node', 'admin/nodes', get_class($node));
     echo 'Creating pages and navigation...' . PHP_EOL;
     foreach (App::make('Boyhagemann\\Admin\\Model\\Resource')->get() as $resource) {
         $controller->savePages($resource);
         $controller->saveNavigation($resource, $contentNode);
     }
     echo 'Done.' . PHP_EOL;
 }
Exemplo n.º 2
0
 /**
  * @param        $title
  * @param        $route
  * @param        $controller
  * @param        $layout
  * @param string $section
  * @param string $method
  * @param null   $alias
  * @return Page
  */
 public static function createWithContent($title, $route, $controller, $layout = 'layouts.default', $method = 'get', $alias = null)
 {
     $page = Page::whereRoute($route)->whereMethod($method)->first();
     // Nothing to do if the page already exists
     if ($page) {
         return $page;
     }
     // Page does not exist yet, continue creating...
     if (!$alias) {
         $alias = $route;
     }
     $page = new Page();
     $page->title = $title;
     $page->route = $route;
     $page->alias = $alias;
     $page->controller = $controller;
     $page->method = $method;
     if ($layout) {
         $layout = Layout::whereName($layout)->first();
         $page->layout()->associate($layout);
     }
     $page->save();
     Event::fire('page.createWithContent', array($page));
     // Dynamically add the Laravel route
     self::createRoute($page);
     return $page;
 }
Exemplo n.º 3
0
 /**
  * @param        $title
  * @param        $route
  * @param        $controller
  * @param string $method
  * @param string $layout
  * @param string $section
  * @param array  $params
  * @param array  $match
  *
  * @return \Boyhagemann\Pages\Model\Page
  */
 public static function createWithContent($title, $route, $controller, $method = 'get', $layout = 'layouts.default', $section = 'content', $params = null, $match = null)
 {
     $layout = Layout::whereName($layout)->first();
     $section = Section::whereName($section)->first();
     $page = new Page();
     $page->title = $title;
     $page->route = $route;
     $page->layout()->associate($layout);
     $page->method = $method;
     $page->save();
     $content = new Content();
     $content->page()->associate($page);
     $content->section()->associate($section);
     $content->controller = $controller;
     $content->params = (array) $params;
     $content->match = (array) $match;
     $content->save();
     return $page;
 }