コード例 #1
0
ファイル: Install.php プロジェクト: boyhagemann/framework
 /**
  * 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;
 }
コード例 #2
0
 /**
  * @param Page       $page
  * @param Section    $section
  * @param Collection $content
  * @return mixed
  */
 public function renderSection(Page $page, Section $section, Collection $content)
 {
     $isContentMode = Session::get('mode') == 'content';
     $isModePublic = $section->isPublic();
     // Dispatch all the blocks in this section
     $blocks = array();
     foreach ($content as $item) {
         if ($item->section_id == $section->id) {
             $blocks[] = $this->renderContent($item);
         }
     }
     if (!$content->count() || implode('', $blocks) === '') {
         return;
     }
     if ($isContentMode) {
         // Build the form for adding a content block in this section
         $fb = App::make('Boyhagemann\\Content\\Controller\\ContentController')->init('create')->getFormBuilder();
         $fb->url(URL::route('admin.content.store'));
         $fb->defaults(array('section_id' => $section->id, 'page_id' => $section->page_id));
         $form = $fb->build();
     }
     Event::fire('content.dispatch.renderSection', array(&$blocks, $section, $page, $isContentMode, $isModePublic));
     return View::make('content::section', compact('blocks', 'section', 'form', 'isContentMode', 'isModePublic'));
 }
コード例 #3
0
 /**
  * @param Page $page
  */
 public function onCreateResourcePage(Page $page)
 {
     // Check if there already is content attached to this page.
     // If so, then we don't have to add new content.
     if (Content::wherePageId($page->id)->first()) {
         return;
     }
     $block = Block::whereController($page->controller)->first();
     $section = Section::whereName('content')->first();
     $content = new Content();
     $content->page()->associate($page);
     $content->section()->associate($section);
     if ($block) {
         $content->block()->associate($block);
     } else {
         $content->controller = $page->controller;
     }
     $content->save();
 }
コード例 #4
0
 /**
  * @param Page $page
  */
 public function onCreateWithContent(Page $page)
 {
     // If the page doesn't have a controller, then we can do nothing
     if (!$page->controller || !$page->layout) {
         return;
     }
     // Check if there already is content attached to this page.
     // If so, then we don't have to add new content.
     if (Content::wherePageId($page->id)->first()) {
         return;
     }
     // Get the main content section
     $section = Section::whereName('content')->first();
     // Create the new content
     $content = new Content();
     $content->page()->associate($page);
     $content->section()->associate($section);
     $content->controller = $page->controller;
     $content->save();
 }
コード例 #5
0
ファイル: Page.php プロジェクト: boyhagemann/framework
 /**
  * @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;
 }