Current file: /home/greg/workspace/PHPDS-dev-trunk/PHPDevShell/stable/trunk/includes/models/PHPDS_navigation.query.php
Legend: executed not executed dead code

  Coverage
  Classes Functions / Methods Lines
Total
66.67%66.67%
66.67% 2 / 3
0.00%0.00%
0.00% 0 / 1 CRAP
5.36%5.36%
5.36% 3 / 56
 
NAVIGATION_findMenuQuery
100.00%100.00%
100.00% 1 / 1
  
   
100.00%100.00%
100.00% 1 / 1
NAVIGATION_findAliasQuery
100.00%100.00%
100.00% 1 / 1
  
   
100.00%100.00%
100.00% 1 / 1
NAVIGATION_extractMenuQuery
0.00%0.00%
0.00% 0 / 1
0.00%0.00%
0.00% 0 / 1
1.85%1.85%
1.85% 1 / 54
 invoke($parameters = null)
0.00%0.00%
0.00% 0 / 1 182
0.00%0.00%
0.00% 0 / 53


       1                 : <?php                                                                                                                                                                           
       2                 : /**                                                                                                                                                                             
       3                 :  * PHPDevShell is a RAD Framework aimed at developing administrative applications.                                                                                              
       4                 :  *                                                                                                                                                                              
       5                 :  * @package PHPDevShell                                                                                                                                                         
       6                 :  * @link http://www.phpdevshell.org                                                                                                                                             
       7                 :  * @copyright Copyright (C) 2007 Jason Schoeman, All rights reserved.                                                                                                           
       8                 :  * @license GNU/LGPL, see readme/licensed_under_lgpl or http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html                                                                  
       9                 :  * @author Jason Schoeman, Contact: titan [at] phpdevshell [dot] org.                                                                                                           
      10                 :  *                                                                                                                                                                              
      11                 :  * Copyright notice: See readme/notice                                                                                                                                          
      12                 :  * By using PHPDevShell you agree to notice and license, if you dont agree to this notice/license you are not allowed to use PHPDevShell.                                       
      13                 :  *                                                                                                                                                                              
      14                 :  * This is the query engine.                                                                                                                                                    
      15                 :  */                                                                                                                                                                             
      16                 :                                                                                                                                                                                 
      17                 : /**                                                                                                                                                                             
      18                 :  * Navigation - Check if we can find a menu id by using the alias.                                                                                                              
      19                 :  * @author Jason Schoeman, Contact: titan [at] phpdevshell [dot] org.                                                                                                           
      20                 :  *                                                                                                                                                                              
      21                 :  */                                                                                                                                                                             
      22                 : class NAVIGATION_findMenuQuery extends PHPDS_query                                                                                                                              
      23               1 : {                                                                                                                                                                               
      24                 :     protected $sql = "                                                                                                                                                          
      25                 :         SELECT                                                                                                                                                                  
      26                 :             t1.menu_id                                                                                                                                                          
      27                 :         FROM                                                                                                                                                                    
      28                 :             _db_core_menu_items t1                                                                                                                                              
      29                 :         WHERE                                                                                                                                                                   
      30                 :             t1.alias = '%s'                                                                                                                                                     
      31                 :         OR                                                                                                                                                                      
      32                 :             t1.menu_id = '%s'                                                                                                                                                   
      33                 :     ";                                                                                                                                                                          
      34                 :                                                                                                                                                                                 
      35                 :     protected $singleValue = true;                                                                                                                                              
      36                 : }                                                                                                                                                                               
      37                 :                                                                                                                                                                                 
      38                 : /**                                                                                                                                                                             
      39                 :  * Navigation - Check if we can find an alias by menu id.                                                                                                                       
      40                 :  * @author Jason Schoeman, Contact: titan [at] phpdevshell [dot] org.                                                                                                           
      41                 :  *                                                                                                                                                                              
      42                 :  */                                                                                                                                                                             
      43                 : class NAVIGATION_findAliasQuery extends PHPDS_query                                                                                                                             
      44               1 : {                                                                                                                                                                               
      45                 :     protected $sql = "                                                                                                                                                          
      46                 :         SELECT                                                                                                                                                                  
      47                 :             t1.alias                                                                                                                                                            
      48                 :         FROM                                                                                                                                                                    
      49                 :             _db_core_menu_items t1                                                                                                                                              
      50                 :         WHERE                                                                                                                                                                   
      51                 :             t1.menu_id = '%s'                                                                                                                                                   
      52                 :     ";                                                                                                                                                                          
      53                 :                                                                                                                                                                                 
      54                 :     protected $singleValue = true;                                                                                                                                              
      55                 : }                                                                                                                                                                               
      56                 :                                                                                                                                                                                 
      57                 : /**                                                                                                                                                                             
      58                 :  * Navigation - Extract all available menus user belings too.                                                                                                                   
      59                 :  * @author Jason Schoeman, Contact: titan [at] phpdevshell [dot] org.                                                                                                           
      60                 :  *                                                                                                                                                                              
      61                 :  */                                                                                                                                                                             
      62                 : class NAVIGATION_extractMenuQuery extends PHPDS_query                                                                                                                           
      63               1 : {                                                                                                                                                                               
      64                 :     protected $sql = "                                                                                                                                                          
      65                 :         SELECT SQL_CACHE                                                                                                                                                        
      66                 :             t1.menu_id, t1.parent_menu_id, t1.menu_name, t1.menu_link, t1.plugin, t1.menu_type, t1.extend, t1.new_window, t1.rank, t1.hide, t1.template_id, t1.alias, t1.layout,
      67                 :             t3.is_parent, t3.type,                                                                                                                                              
      68                 :             t6.template_folder                                                                                                                                                  
      69                 :         FROM                                                                                                                                                                    
      70                 :             _db_core_menu_items t1                                                                                                                                              
      71                 :         LEFT JOIN                                                                                                                                                               
      72                 :             _db_core_user_role_permissions t2                                                                                                                                   
      73                 :         ON                                                                                                                                                                      
      74                 :             t1.menu_id = t2.menu_id                                                                                                                                             
      75                 :         LEFT JOIN                                                                                                                                                               
      76                 :             _db_core_menu_structure t3                                                                                                                                          
      77                 :         ON                                                                                                                                                                      
      78                 :             t1.menu_id = t3.menu_id                                                                                                                                             
      79                 :         LEFT JOIN                                                                                                                                                               
      80                 :             _db_core_templates t6                                                                                                                                               
      81                 :         ON                                                                                                                                                                      
      82                 :             t1.template_id = t6.template_id                                                                                                                                     
      83                 :         WHERE                                                                                                                                                                   
      84                 :             (t2.user_role_id IN (%s))                                                                                                                                           
      85                 :         ORDER BY                                                                                                                                                                
      86                 :             t3.id                                                                                                                                                               
      87                 :         ASC                                                                                                                                                                     
      88                 :     ";                                                                                                                                                                          
      89                 :                                                                                                                                                                                 
      90                 :     /**                                                                                                                                                                         
      91                 :      * Loads favorite control panel menu items.                                                                                                                                 
      92                 :      * @param int $limit_favorite_db                                                                                                                                            
      93                 :      * @return array                                                                                                                                                            
      94                 :      */                                                                                                                                                                         
      95                 :     public function invoke($parameters = null)                                                                                                                                  
      96                 :     {                                                                                                                                                                           
      97               0 :         $all_user_roles = $parameters[0];                                                                                                                                       
      98               0 :         if (empty($all_user_roles)) throw new PHPDS_Exception('Cannot extract menus when no roles are given.');                                                                 
      99               0 :         $select_menus = parent::invoke($all_user_roles);                                                                                                                        
     100                 :                                                                                                                                                                                 
     101               0 :         $navigation = $this->navigation;                                                                                                                                        
     102               0 :         $aburl = $this->configuration['absolute_url'];                                                                                                                          
     103               0 :         $sef = ! empty($this->configuration['sef_url']);                                                                                                                        
     104               0 :         $append = ! empty($this->configuration['url_append']);                                                                                                                  
     105                 :                                                                                                                                                                                 
     106               0 :         foreach ($select_menus as $mr) {                                                                                                                                        
     107                 :             ////////////////////////                                                                                                                                            
     108                 :             // Create menu items. //                                                                                                                                            
     109                 :             ////////////////////////                                                                                                                                            
     110               0 :             $navigation->navigation[$mr['menu_id']]['menu_id'] = $mr['menu_id'];                                                                                                
     111               0 :             $navigation->navigation[$mr['menu_id']]['parent_menu_id'] = $mr['parent_menu_id'];                                                                                  
     112               0 :             $navigation->navigation[$mr['menu_id']]['alias'] = $mr['alias'];                                                                                                    
     113                 :             // Determine menu name.                                                                                                                                             
     114               0 :             $navigation->navigation[$mr['menu_id']]['menu_name'] = $navigation->determineMenuName($mr['menu_name'], $mr['menu_link'], $mr['menu_id'], $mr['plugin']);           
     115               0 :             $navigation->navigation[$mr['menu_id']]['menu_link'] = $mr['menu_link'];                                                                                            
     116               0 :             $navigation->navigation[$mr['menu_id']]['rank'] = $mr['rank'];                                                                                                      
     117               0 :             $navigation->navigation[$mr['menu_id']]['hide'] = $mr['hide'];                                                                                                      
     118               0 :             $navigation->navigation[$mr['menu_id']]['new_window'] = $mr['new_window'];                                                                                          
     119               0 :             $navigation->navigation[$mr['menu_id']]['is_parent'] = $mr['is_parent'];                                                                                            
     120               0 :             $navigation->navigation[$mr['menu_id']]['type'] = $mr['type'];                                                                                                      
     121               0 :             $navigation->navigation[$mr['menu_id']]['template_folder'] = $mr['template_folder'];                                                                                
     122               0 :             $navigation->navigation[$mr['menu_id']]['layout'] = $mr['layout'];                                                                                                  
     123               0 :             $navigation->navigation[$mr['menu_id']]['plugin'] = $mr['plugin'];                                                                                                  
     124               0 :             $navigation->navigation[$mr['menu_id']]['menu_type'] = $mr['menu_type'];                                                                                            
     125               0 :             $navigation->navigation[$mr['menu_id']]['extend'] = $mr['extend'];                                                                                                  
     126               0 :             $navigation->navigation[$mr['menu_id']]['plugin_folder'] = 'plugins/' . $mr['plugin'] . '/';                                                                        
     127                 :             // Check if we should can return the url as friendly.                                                                                                               
     128               0 :             if ($sef && ! empty($mr['alias'])) {                                                                                                                                
     129               0 :                 $navigation->navAlias[$mr['alias']] = $mr['menu_id'];                                                                                                           
     130                 :                 if($append)                                                                                                                                                     
     131               0 :                     $navigation->navigation[$mr['menu_id']]['href'] = $aburl . '/' . $mr['alias'] . $this->configuration['url_append'];                                         
     132                 :                 else                                                                                                                                                            
     133               0 :                     $navigation->navigation[$mr['menu_id']]['href'] = $aburl . '/' . $mr['alias'];                                                                              
     134               0 :             } else {                                                                                                                                                            
     135               0 :                 $navigation->navigation[$mr['menu_id']]['href'] = $aburl.'/index.php?m=' . $mr['menu_id'];                                                                      
     136                 :             }                                                                                                                                                                   
     137                 :             // Check if menu item should new_window in a new window or not.                                                                                                     
     138               0 :             ($mr['new_window'] == 1) ? $target = ' target="_blank" ' : $target = ' target="_self" ';                                                                            
     139                 :             // Check if we have a place marker.                                                                                                                                 
     140               0 :             if ($mr['menu_type'] == 6 || ($mr['hide'] != 0 && $mr['hide'] != 2)) {                                                                                              
     141               0 :                 $enable_link = ' onclick="return false;" ';                                                                                                                     
     142                 :                 // Create URL.                                                                                                                                                  
     143               0 :                 $url = '<a href="&#35;"';                                                                                                                                       
     144               0 :             } else {                                                                                                                                                            
     145                 :                 // Empty                                                                                                                                                        
     146               0 :                 $enable_link = false;                                                                                                                                           
     147                 :                 // Last check if it is a link item that should be jumped to.                                                                                                    
     148               0 :                 switch ($mr['menu_type']) {                                                                                                                                     
     149               0 :                     case 3:                                                                                                                                                     
     150                 :                         // Create URL.                                                                                                                                          
     151               0 :                         $url = '<a href="' . $aburl . '/index.php?m=' . $mr['extend'] . '"';                                                                                    
     152               0 :                         break;                                                                                                                                                  
     153               0 :                     case 5:                                                                                                                                                     
     154                 :                         // Create URL.                                                                                                                                          
     155               0 :                         $url = '<a href="' . $mr['menu_link'] . '"';                                                                                                            
     156               0 :                         break;                                                                                                                                                  
     157               0 :                     default:                                                                                                                                                    
     158                 :                         // Create URL.                                                                                                                                          
     159               0 :                         $url = '<a href="' . $navigation->navigation[$mr['menu_id']]['href'] . '"';                                                                             
     160               0 :                         break;                                                                                                                                                  
     161               0 :                 }                                                                                                                                                               
     162                 :             }                                                                                                                                                                   
     163                 :             // Create final compiled url.                                                                                                                                       
     164               0 :             $navigation->navigation[$mr['menu_id']]['url'] = $url . $target . $enable_link . '>%s' . $navigation->navigation[$mr['menu_id']]['menu_name'] . '</a>';             
     165                 :             // Writing children for single level dropdown.                                                                                                                      
     166               0 :             if (! empty($mr['parent_menu_id'])) {                                                                                                                               
     167               0 :                 $navigation->child[$mr['parent_menu_id']][] = $mr['menu_id'];                                                                                                   
     168               0 :             }                                                                                                                                                                   
     169               0 :         }                                                                                                                                                                       
     170                 :                                                                                                                                                                                 
     171               0 :     }                                                                                                                                                                           
     172                 : }                                                                                                                                                                               

Generated by PHP_CodeCoverage 1.0.4 using PHP 5.3.6 and PHPUnit 3.5.14 at Mon Aug 8 22:35:38 PDT 2011.