예제 #1
0
 /**
  * @Saving
  */
 public static function saving($event, Node $node)
 {
     $db = self::getConnection();
     $i = 2;
     $id = $node->id;
     if (!$node->slug) {
         $node->slug = $node->title;
     }
     // Ensure unique slug
     while (self::where(['slug = ?', 'parent_id= ?'], [$node->slug, $node->parent_id])->where(function ($query) use($id) {
         if ($id) {
             $query->where('id <> ?', [$id]);
         }
     })->first()) {
         $node->slug = preg_replace('/-\\d+$/', '', $node->slug) . '-' . $i++;
     }
     // Update own path
     $path = '/' . $node->slug;
     if ($node->parent_id && ($parent = Node::find($node->parent_id)) and $parent->menu == $node->menu) {
         $path = $parent->path . $path;
     } else {
         // set Parent to 0, if old parent is not found
         $node->parent_id = 0;
     }
     // Update children's paths
     if ($id && $path != $node->path) {
         $db->executeUpdate('UPDATE ' . self::getMetadata()->getTable() . ' SET path = REPLACE (' . $db->getDatabasePlatform()->getConcatExpression($db->quote('//'), 'path') . ", '//{$node->path}', '{$path}')" . ' WHERE path LIKE ' . $db->quote($node->path . '%'));
     }
     $node->path = $path;
     // Set priority
     if (!$id) {
         $node->priority = 1 + $db->createQueryBuilder()->select($db->getDatabasePlatform()->getMaxExpression('priority'))->from('@system_node')->where(['parent_id' => $node->parent_id])->execute()->fetchColumn();
     }
 }
예제 #2
0
 /**
  * @Route("site/page/edit", name="page/edit")
  * @Access("site: manage site", admin=true)
  * @Request({"id", "menu"})
  */
 public function editAction($id = '', $menu = '')
 {
     if (is_numeric($id)) {
         if (!$id or !($node = Node::find($id))) {
             App::abort(404, 'Node not found.');
         }
     } else {
         $node = Node::create(['type' => $id]);
         if ($menu && !App::menu($menu)) {
             App::abort(404, 'Menu not found.');
         }
         $node->menu = $menu;
     }
     if (!($type = $this->site->getType($node->type))) {
         App::abort(404, 'Type not found.');
     }
     return ['$view' => ['title' => __('Pages'), 'name' => 'system/site/admin/edit.php'], '$data' => ['node' => $node, 'type' => $type, 'roles' => array_values(Role::findAll())]];
 }
예제 #3
0
 /**
  * {@inheritdoc}
  */
 public function main(App $app)
 {
     $app['node'] = function ($app) {
         if ($id = $app['request']->attributes->get('_node') and $node = Node::find($id, true)) {
             return $node;
         }
         return Node::create();
     };
     $app['menu'] = function ($app) {
         $menus = new MenuManager($app->config($app['theme']->name), $this->config('menus'));
         foreach ($app['theme']->get('menus', []) as $name => $label) {
             $menus->register($name, $label);
         }
         return $menus;
     };
     $app->extend('view', function ($view) use($app) {
         return $view->addHelper(new MenuHelper($app['menu']));
     });
 }
 /**
  * @Route("/frontpage", methods="POST")
  * @Request({"id": "int"}, csrf=true)
  */
 public function frontpageAction($id)
 {
     if (!($node = Node::find($id)) or !($type = App::module('system/site')->getType($node->type))) {
         App::abort(404, __('Node not found.'));
     }
     if (isset($type['frontpage']) and !$type['frontpage']) {
         App::abort(400, __('Invalid node type.'));
     }
     App::config('system/site')->set('frontpage', $id);
     return ['message' => 'success'];
 }