Public paste
Undefined
By: Guest | Date: May 19 2010 17:46 | Format: None | Expires: never | Size: 11.36 KB | Hits: 836

  1. <?PHP
  2.  
  3.         CLASS ModelsGlobal_Controller EXTENDS ILLI_Controller_Controller_Abstract
  4.         {
  5.                
  6.                 /**
  7.                  *      usage:
  8.                  *
  9.                  *
  10.                  *
  11.                  
  12.                         required is the following route
  13.                        
  14.                        
  15.                                 ROUTETABLEALIAS is the selector-ident in illi_rootmenu:routetable
  16.                                
  17.                                
  18.                                 <page-ROUTETABLEALIAS
  19.                                         uri.location   = "pages"
  20.                                         uri.regexp     = "(ROUTETABLEALIAS/(([a-z]{2})/(([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-/!]+/)?)?)?)?"
  21.                                         uri.params     = "string routetable, string iso, string rootroutenode, string subroutenode"
  22.                                         app.module     = "page"
  23.                                 />
  24.                        
  25.                        
  26.                                 params:
  27.                                
  28.                                         routetable:
  29.                                                 ident in illi_rootmenu:routetable => ROUTETABLEALIAS
  30.                                        
  31.                                         rootroutenode:
  32.                                                 ident in illi_rootmenu:routenode
  33.                                        
  34.                                         subroutenode:
  35.                                                 ident in illi_submenu:routenode
  36.                                        
  37.                                         iso:
  38.                                                 grab content by lang
  39.                                        
  40.                        
  41.                                 db-query:              
  42.                                
  43.                                 illi_rootmenu:routetable
  44.                                         &&
  45.                                         illi_rootmenu:iso
  46.                                                 => illi_rootmenu:routenode
  47.                                                         &&
  48.                                                         illi_submenu:iso
  49.                                                                 => illi_submenu:routenode
  50.                                        
  51.                  */
  52.                  
  53.                  
  54.                 // args
  55.                 const rt_table
  56.                         = 'routetable';
  57.                        
  58.                        
  59.                 const rt_section
  60.                         = 'rootroutenode';
  61.                        
  62.                        
  63.                 const rt_sub
  64.                         = 'subroutenode';
  65.                        
  66.                
  67.                 const rt_lang
  68.                         = 'iso';
  69.                        
  70.                
  71.                 // database-field-names
  72.                 const db_route
  73.                         = 'routenode';
  74.                        
  75.                        
  76.                 const db_rtable
  77.                         = 'routetable';
  78.                        
  79.                        
  80.                 const db_lang
  81.                         = 'iso';
  82.                        
  83.                        
  84.                 const db_ruri
  85.                         = 'uri';
  86.                        
  87.                        
  88.                 const db_id
  89.                         = 'id';
  90.                        
  91.                        
  92.                 const db_oid
  93.                         = 'oid';
  94.                        
  95.                        
  96.                 const db_pid
  97.                         = 'pid';
  98.                        
  99.                        
  100.                 const db_ciid
  101.                         = 'ciid';
  102.                        
  103.                        
  104.                        
  105.                 // db-tablenames
  106.                 const dbt_rootmenu
  107.                         = 'rootmenu';
  108.                        
  109.                        
  110.                 const dbt_submenu
  111.                         = 'submenu';
  112.                        
  113.                        
  114.                
  115.                 // subs        
  116.                 const lang
  117.                         = 'models/db/language';
  118.                        
  119.                 const tree
  120.                         = 'models/db/treemenu';
  121.                
  122.                 const db
  123.                         = 'db/bridge';
  124.                
  125.                 const nav
  126.                         = 'menu/Main-Nav-Deeplinked';
  127.                        
  128.                        
  129.                 private $rt = '';
  130.                
  131.                 // st
  132.                 private $route_pages
  133.                         = NULL;
  134.                
  135.                
  136.                 private $current_sub_pages
  137.                         = NULL;
  138.                
  139.                 private $alternate_subaction
  140.                         = NULL;
  141.                        
  142.                
  143.                 private $alternate_sectionaction
  144.                         = NULL;
  145.                        
  146.                        
  147.                 private $page_entry
  148.                         = NULL;
  149.                        
  150.                        
  151.                 private $submenu
  152.                         = NULL;
  153.                        
  154.                
  155.                 public function set_routeNode($route)
  156.                 {
  157.                         if(isset($this->get_RouteParams()->{'_'.ModelsGlobal_Controller::rt_table}))
  158.                                 $this->rt = $route.':'.$this->get_RouteParams()->{'_'.ModelsGlobal_Controller::rt_table};
  159.                                
  160.                         else
  161.                                 $this->rt = $route;
  162.                                
  163.                         return $this;
  164.                 }
  165.                
  166.                
  167.                 public function set_LangIso($iso)
  168.                 {
  169.                         return $this->get_SubController(self::lang)->set_Iso($iso);
  170.                 }
  171.                
  172.                
  173.                 public function get_LangError()
  174.                 {
  175.                         return $this->get_SubController(self::lang)->get_error();
  176.                 }
  177.                
  178.                 public function get_LangIso()
  179.                 {
  180.                         return $this->get_SubController(self::lang)->get_Iso();
  181.                 }
  182.                
  183.                
  184.                 public function get_RoutePages($route)
  185.                 {
  186.                         if(NULL === $this->route_pages)
  187.                                 $this->route_pages = $this->get_SubController(self::db)->simple_multi_search(self::dbt_submenu, array(self::db_route => $route, self::db_lang => $this->get_LangIso()), array('limit'   => NULL));
  188.                        
  189.                         return $this->route_pages;
  190.                 }
  191.                
  192.                
  193.                 public function set_SubMenuItem(ILLI_Container $config)
  194.                 {
  195.                         $this->get_SubMenuInstance()->add_RouteLink
  196.                                 (
  197.                                         $config->_ident,
  198.                                         array
  199.                                         (
  200.                                                 ILLI_View_Navigation::active
  201.                                                         => $config->_active,
  202.                                                        
  203.                                                 'a'
  204.                                                         => $config->_title
  205.                                         ),
  206.                                         $this->rt,
  207.                                         array
  208.                                         (
  209.                                                 self::rt_table
  210.                                                         => $this->get_RouteParams()->{'_'.self::rt_table},
  211.                                                        
  212.                                                 self::rt_lang
  213.                                                         => $this->get_LangIso(),
  214.                                                
  215.                                                 self::rt_section
  216.                                                         => $config->_routenode,
  217.                                                
  218.                                                 self::rt_sub
  219.                                                         => $config->_uri));
  220.                                        
  221.                         return $this;
  222.                 }
  223.                
  224.                 public function get_SubMenuInstance()
  225.                 {
  226.                         return $this->get_SubController(self::nav)->get_instance('sub');
  227.                 }
  228.                
  229.                 public function get_SubMenu()
  230.                 {
  231.                         $SUBMENU = NULL;
  232.                        
  233.                         if(isset($this->get_RouteParams()->{'_'.self::rt_section}))
  234.                                 $SUBMENU = $this->get_SubController(self::tree)->from_route($this->get_RoutePages($this->get_RouteParams()->{'_'.self::rt_section}));
  235.                        
  236.                         return ((NULL !== $SUBMENU) ? $SUBMENU->menu() : '');
  237.                 }
  238.                
  239.                 private function get_SubEntry()
  240.                 {
  241.                         if(NULL === $this->current_sub_pages)
  242.                                 $this->current_sub_pages = $this->get_SubController(self::tree)->get_current();
  243.                        
  244.                         return $this->current_sub_pages;
  245.                        
  246.                 }
  247.                
  248.                 private function get_SubEntryByID($id)
  249.                 {
  250.                         $id = intval($id);
  251.                        
  252.                         $result = $this->get_SubController(self::db)->simple_multi_search(self::dbt_submenu,array(self::db_id => $id),array('limit' => 1));
  253.                        
  254.                         return $result[0];
  255.                 }
  256.                
  257.                 private function get_RootEntryBySubRoute($route)
  258.                 {
  259.                         $result = $this->get_SubController(self::db)->simple_multi_search(self::dbt_rootmenu, array(self::db_route => $route, self::db_lang => $this->get_LangIso()), array('limit' => 1));
  260.                        
  261.                         return $result[0];
  262.                 }
  263.                
  264.                 private function get_RootEntry()
  265.                 {
  266.                         if(NULL === $this->current_sub_pages)
  267.                                 $page_entry = $this->get_SubController(self::db)->simple_multi_search(self::dbt_rootmenu, array(self::db_rtable => $this->get_RouteParams()->{'_'.self::rt_table}, self::db_route => $this->get_RouteParams()->{'_'.self::rt_section}, self::db_lang => $this->get_LangIso()), array('limit' => 1));
  268.                                                
  269.                         return $page_entry[0];
  270.                 }
  271.                
  272.                 public function get_CurrentEntry()
  273.                 {
  274.                         if(isset($this->get_RouteParams()->{'_'.self::rt_sub})&& isset($this->get_RouteParams()->{'_'.self::rt_section}))
  275.                         {
  276.                                 $subaction = ILLI_Constructeur::get_Instance(self::c_FLTRRT_.'App_Action')->filter($this->get_RouteParams()->{'_'.self::rt_section}.'/'.$this->get_RouteParams()->{'_'.self::rt_sub});
  277.                                        
  278.                                                
  279.                                 $this->alternate_subaction = $subaction['action'];
  280.                                        
  281.                                        
  282.                                 $this->page_entry = $this->get_SubEntry();                                             
  283.                                
  284.                                
  285.                                 $root = $this->get_RootEntryBySubRoute($this->page_entry['routenode']);
  286.                                
  287.                                
  288.                                 if(!$this->get_SubController('models/usergroup')->check_usergroup($root['gid']))
  289.                                         $this->page_entry['permission'] = FALSE;
  290.                         }
  291.                         elseif(isset($this->get_RouteParams()->{'_'.self::rt_section}) && !isset($this->get_RouteParams()->{'_'.self::rt_sub}))
  292.                         {
  293.                                 $sectionaction = ILLI_Constructeur::get_Instance(self::c_FLTRRT_.'App_Action')->filter($this->get_RouteParams()->{'_'.self::rt_section});
  294.                                        
  295.                                        
  296.                                 $this->alternate_sectionaction = $sectionaction['action'];
  297.  
  298.  
  299.                                 $this->page_entry = $this->get_RootEntry();
  300.                         }
  301.                                
  302.                                
  303.                         if(is_array($this->page_entry) && array_key_exists('gid', $this->page_entry) && !$this->get_SubController('models/usergroup')->check_usergroup($this->page_entry['gid']))
  304.                                 $this->page_entry['permission'] = FALSE;
  305.                        
  306.                        
  307.                         if(array_key_exists('permission', $this->page_entry) && $this->page_entry['permission'] === FALSE)
  308.                                 $this->get_SubController('error')->Locked_Action();
  309.                        
  310.                         return $this->page_entry;
  311.                 }
  312.                
  313.                 public function get_SectionAction($prfx = 'Default')
  314.                 {
  315.                         if(NULL === $this->alternate_sectionaction)
  316.                                 return NULL;
  317.                                
  318.                                
  319.                         return $prfx.'_'.$this->alternate_sectionaction;
  320.                 }
  321.                
  322.                 public function get_SubAction($prfx = 'Default')
  323.                 {
  324.                         if(NULL === $this->alternate_subaction)
  325.                                 return NULL;
  326.                                
  327.                                
  328.                         return $prfx.'_'.$this->alternate_subaction;
  329.                 }
  330.                
  331.                 public function get_RootMenu($routingtable = 'pages', $route = 'page')
  332.                 {
  333.                         $routingtable = $routingtable.':'.$route;
  334.                        
  335.                         if(NULL !== $this->get_SubController(self::nav)->get_instance($routingtable.'_rootmenu')->menu())
  336.                                 return $this->get_SubController(self::nav)->get_instance($routingtable.'_rootmenu');
  337.                        
  338.                        
  339.                         if(is_array($menu = $this->get_SubController(self::db)->simple_multi_search(self::dbt_rootmenu, array(self::db_rtable => $route, self::db_lang => $this->get_LangIso()), array('limit' => NULL))))
  340.                                 foreach(array_sortkey($menu, self::db_oid) as $page)
  341.                                         $this->get_SubController(self::nav)->get_instance($routingtable.'_rootmenu')->add_RouteLink($page[self::db_rtable].$page['title'], array(ILLI_View_Navigation::active => (isset($this->get_RouteParams()->{'_'.self::rt_section}) && $this->get_RouteParams()->{'_'.self::rt_section} === $page[self::db_route]), 'a' => $page['title']), $routingtable, array(self::rt_table => $route, self::rt_lang => $this->get_LangIso(), self::rt_section => $page[self::db_route]));
  342.                        
  343.                        
  344.                         return $this->get_SubController(self::nav)->get_instance($routingtable.'_rootmenu');
  345.                 }
  346.                        
  347.                 public function redirect_RootPage($db_rotenode = NULL)
  348.                 {
  349.                         if(is_array($page = $this->get_SubController(self::db)->simple_multi_search(self::dbt_rootmenu, array(self::db_route => ((NULL === $db_rotenode) ? $this->get_SubController('models/affiliates')->_start_page : $db_rotenode), self::db_lang => $this->get_SubController(self::lang)->get_Iso()), array('limit' => NULL))))
  350.                         {
  351.                                 $page = $page[0];
  352.                                        
  353.                                 if(!ILLI_Constructeur::get_Instance(self::c_COREHDR)->redirect(ILLI_Constructeur::get_Instance(self::c_RT)->convert_RouteID2Base((((NULL === $db_rotenode) ? Application::rt_master_page : ((isset($this->get_RouteParams()->{'_'.ModelsGlobal_Controller::rt_table})) ? $this->rt : $this->rt.':'.$page[self::db_rtable]))), array(self::rt_table => $page[self::db_rtable], self::db_lang => $this->get_SubController(self::lang)->get_Iso(),self::rt_section => $page[self::db_route]))))
  354.                                         $this->get_SubController('error')->Default_Action();
  355.                         }
  356.                         else
  357.                         {
  358.                                 $this->get_SubController('error')->Internal_Action('Page not found in Database. Can not redirect.');                                   
  359.                                 return;
  360.                         }
  361.                        
  362.                 }
  363.                        
  364.                 public function redirect_SubPage($id)
  365.                 {
  366.                         $this->get_View()->get_Factory()->set_Title('Redirect');
  367.                        
  368.                         foreach(($pages = $this->get_SubController(self::tree)->get_all()) as $index => $page)
  369.                         {
  370.                                 if($page[self::db_id] == $page[self::db_ciid])
  371.                                         if(!$this->redirect_RootPage())
  372.                                                 return $this->get_SubController('error')->Internal_Action('Recursion detected, code(id:'.$page[self::db_id].'#ciid:'.$page[self::db_ciid].')');
  373.                                        
  374.                                        
  375.                                 if($page[self::db_id] == $id && $page[self::db_route] == $this->page_entry[self::db_route])
  376.                                 {
  377.                                         if($page[self::db_ciid] == $this->page_entry[self::db_id])
  378.                                                 if(!$this->redirect_RootPage())
  379.                                                         return $this->get_SubController('error')->Internal_Action('Recursion detected, code(id:'.$page[self::db_id].'.ciid:'.$page[self::db_ciid].'#id:'.$this->page_entry[self::db_id].'.ciid:'.$this->page_entry[self::db_ciid].')');
  380.                                        
  381.                                        
  382.                                         if(!ILLI_Constructeur::get_Instance(self::c_COREHDR)->redirect(ILLI_Constructeur::get_Instance(self::c_RT)->convert_RouteID2Base($this->rt, array(self::rt_table => $this->get_RouteParams()->{'_'.self::rt_table},self::rt_lang => $this->get_SubController(self::lang)->get_Iso(), self::rt_section => $page[self::db_route].'/'.$page[self::db_ruri]))))
  383.                                                 $this->get_SubController('error')->Default_Action();
  384.                                 }
  385.                         }
  386.                        
  387.                         return $this->redirect_RootPage();
  388.                 }
  389.         }