Exemplo n.º 1
0
 /**
  * Update the navigation objects
  *
  * @param  AbstractController $controller
  * @param  Application        $application
  * @return void
  */
 public static function updateNavigation(AbstractController $controller, Application $application)
 {
     if ($_POST && $application->isRegistered('phire-content') && $controller->hasView() && null !== $controller->view()->id && null !== $controller->view()->form && $controller->view()->form !== false && $controller->view()->form instanceof \Phire\Content\Form\Content) {
         $navItems = Table\NavigationItems::findBy(['type' => 'content']);
         foreach ($navItems->rows() as $item) {
             if (null !== $item->item_id) {
                 $i = \Phire\Content\Table\Content::findById($item->item_id);
                 if (isset($i->id)) {
                     $n = Table\NavigationItems::findById($item->id);
                     if (isset($n->id)) {
                         $n->name = $i->title;
                         $n->href = $i->uri;
                         $n->save();
                     }
                 }
             }
         }
     } else {
         if ($_POST && $application->isRegistered('phire-categories') && $controller->hasView() && null !== $controller->view()->id && null !== $controller->view()->form && $controller->view()->form !== false && $controller->view()->form instanceof \Phire\Categories\Form\Category) {
             $navItems = Table\NavigationItems::findBy(['type' => 'category']);
             foreach ($navItems->rows() as $item) {
                 if (null !== $item->item_id) {
                     $i = \Phire\Categories\Table\Categories::findById($item->item_id);
                     if (isset($i->id)) {
                         $n = Table\NavigationItems::findById($item->id);
                         if (isset($n->id)) {
                             $n->name = $i->title;
                             $n->href = '/category' . $i->uri;
                             $n->save();
                         }
                     }
                 }
             }
         }
     }
     if ($_POST && isset($_POST['process_content']) && count($_POST['process_content']) > 0 && isset($_POST['content_process_action']) && $_POST['content_process_action'] == -3) {
         foreach ($_POST['process_content'] as $id) {
             $navItems = new Table\NavigationItems();
             $navItems->delete(['type' => 'content', 'item_id' => $id]);
         }
     }
     if ($_POST && isset($_POST['rm_categories']) && count($_POST['rm_categories']) > 0) {
         foreach ($_POST['rm_categories'] as $id) {
             $navItems = new Table\NavigationItems();
             $navItems->delete(['type' => 'category', 'item_id' => $id]);
         }
     }
 }
Exemplo n.º 2
0
 /**
  * Save the new navigation items
  *
  * @param  array $post
  * @return void
  */
 public function saveItems(array $post)
 {
     $navigation = Table\Navigation::findById((int) $post['id']);
     if (isset($navigation->id)) {
         // Edit a nav item
         if (isset($post['branch_to_edit'])) {
             $id = substr($post['branch_to_edit'], 0, strpos($post['branch_to_edit'], '_'));
             $attribs = [];
             if ($post['nav_edit_target'] != '----') {
                 $attribs = $post['nav_edit_target'] == 'false' ? ['onclick' => 'return false;'] : ['target' => $post['nav_edit_target']];
             }
             $item = Table\NavigationItems::findById((int) $id);
             if (isset($item->id)) {
                 $item->name = stripslashes(html_entity_decode($post['nav_edit_title'], ENT_COMPAT, 'UTF-8'));
                 $item->href = $post['nav_edit_href'];
                 $item->attributes = serialize($attribs);
                 $item->save();
             }
             // Add nav item
         } else {
             if (isset($post['nav_title']) && $post['nav_title'] != '' && $post['nav_href'] != '') {
                 $attribs = [];
                 if ($post['nav_target'] != '----') {
                     $attribs = $post['nav_target'] == 'false' ? ['onclick' => 'return false;'] : ['target' => $post['nav_target']];
                 }
                 if ($post['nav_action_object'] == '----') {
                     $item = new Table\NavigationItems(['navigation_id' => $navigation->id, 'parent_id' => null, 'item_id' => !empty($post['nav_id']) ? $post['nav_id'] : null, 'type' => !empty($post['nav_type']) ? $post['nav_type'] : null, 'name' => $post['nav_title'], 'href' => $post['nav_href'], 'attributes' => serialize($attribs), 'order' => 0]);
                     $item->save();
                 } else {
                     $id = substr($post['nav_action_object'], strpos($post['nav_action_object'], '_') + 1);
                     $id = substr($id, 0, strpos($id, '_'));
                     $item = new Table\NavigationItems(['navigation_id' => $navigation->id, 'parent_id' => $id, 'item_id' => !empty($post['nav_id']) ? $post['nav_id'] : null, 'type' => !empty($post['nav_type']) ? $post['nav_type'] : null, 'name' => $post['nav_title'], 'href' => $post['nav_href'], 'attributes' => serialize($attribs), 'order' => 0]);
                     $item->save();
                 }
             }
         }
         // Order nav items
         foreach ($post as $key => $value) {
             if (substr($key, 0, 11) == 'leaf_order_') {
                 $id = substr($key, 11);
                 $id = substr($id, 0, strpos($id, '_'));
                 $item = Table\NavigationItems::findById((int) $id);
                 if (isset($item->id)) {
                     $item->order = (int) $value;
                     $item->save();
                 }
             }
         }
         // Remove nav items
         if (isset($post['rm_nav']) && count($post['rm_nav']) > 0) {
             foreach ($post['rm_nav'] as $navId) {
                 $item = Table\NavigationItems::findById((int) $navId);
                 if (isset($item->id)) {
                     $item->delete();
                 }
             }
         }
     }
 }