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

  Coverage
  Classes Functions / Methods Lines
Total
0.00%0.00%
0.00% 0 / 1
33.33%33.33%
33.33% 3 / 9 CRAP
17.50%17.50%
17.50% 7 / 40
 
PHPDS_tagger
0.00%0.00%
0.00% 0 / 1
33.33%33.33%
33.33% 3 / 9
17.50%17.50%
17.50% 7 / 40
 tag($object, $name, $target, $value = null)
0.00%0.00%
0.00% 0 / 1 2.03
80.00%80.00%
80.00% 4 / 5
 tagList($name, $object, $target = null)
0.00%0.00%
0.00% 0 / 1 6
0.00%0.00%
0.00% 0 / 4
 tagUser($name, $target, $value = null)
100.00%100.00%
100.00% 1 / 1 1
100.00%100.00%
100.00% 1 / 1
 tagMe($name, $value = null)
0.00%0.00%
0.00% 0 / 1 6
0.00%0.00%
0.00% 0 / 3
 tagMenu($name, $target, $value = null)
0.00%0.00%
0.00% 0 / 1 2
0.00%0.00%
0.00% 0 / 1
 tagHere($name, $value = null)
0.00%0.00%
0.00% 0 / 1 6
0.00%0.00%
0.00% 0 / 3
 tagRole($name, $target, $value = null)
100.00%100.00%
100.00% 1 / 1 1
100.00%100.00%
100.00% 1 / 1
 tagGroup($name, $target, $value = null)
100.00%100.00%
100.00% 1 / 1 1
100.00%100.00%
100.00% 1 / 1
 tagArea($object, $target, $value = null)
0.00%0.00%
0.00% 0 / 1 42
0.00%0.00%
0.00% 0 / 21


       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                 :  *                                                                                                                                       
      10                 :  * Copyright notice: See readme/notice                                                                                                   
      11                 :  * By using PHPDevShell you agree to notice and license, if you dont agree to this notice/license you are not allowed to use PHPDevShell.
      12                 :  */                                                                                                                                      
      13                 : class PHPDS_tagger extends PHPDS_dependant                                                                                               
      14                 : {                                                                                                                                        
      15                 :     const tag_user = 'user';                                                                                                             
      16                 :     const tag_menu = 'menu';                                                                                                             
      17                 :     const tag_role = 'role';                                                                                                             
      18                 :     const tag_group = 'group';                                                                                                           
      19                 :                                                                                                                                          
      20                 :     /**                                                                                                                                  
      21                 :      * Generic setter/getter for the tags.                                                                                               
      22                 :      * All parameters must be given explicitly                                                                                           
      23                 :      *                                                                                                                                   
      24                 :      * As a setter, all 4 params must be given (for the [$object;$target] set the tag name $name to value $value)                        
      25                 :      * As a getter, don't give the value ; either a single value or an array of values will be returned                                  
      26                 :      *                                                                                                                                   
      27                 :      * @param string $object                                                                                                             
      28                 :      * @param string $name                                                                                                               
      29                 :      * @param string $target                                                                                                             
      30                 :      * @param string $value                                                                                                              
      31                 :      * @return string|array|nothing                                                                                                      
      32                 :      */                                                                                                                                  
      33                 :     public function tag($object, $name, $target, $value = null)                                                                          
      34                 :     {                                                                                                                                    
      35              20 :         $parameters = array('object' => $object, 'name' => $name, 'target' => $target);                                                  
      36              20 :         if (!is_null($value)) {                                                                                                          
      37              20 :             $parameters['value'] = "'$value'";                                                                                           
      38              20 :             return $this->db->invokeQueryWith('PHPDS_taggerMarkQuery', $parameters);                                                     
      39                 :         } else {                                                                                                                         
      40               0 :             return $this->db->invokeQueryWith('PHPDS_taggerLookupQuery', $parameters);                                                   
      41                 :         }                                                                                                                                
      42                 :     }                                                                                                                                    
      43                 :                                                                                                                                          
      44                 :     /**                                                                                                                                  
      45                 :      * List of [object;target] for the given tag (optionaly restricted to the given $object/$target)                                     
      46                 :      *                                                                                                                                   
      47                 :      * @param $object                                                                                                                    
      48                 :      * @param $target                                                                                                                    
      49                 :      */                                                                                                                                  
      50                 :     public function tagList($name, $object, $target = null)                                                                              
      51                 :     {                                                                                                                                    
      52               0 :         $parameters = array('object' => $object, 'name' => $name, 'target' => $target);                                                  
      53               0 :         $result = $this->db->invokeQueryWith('PHPDS_taggerListQuery', $parameters);                                                      
      54               0 :         if (!is_array($result)) $result = array($result);                                                                                
      55               0 :         return $result;                                                                                                                  
      56                 :     }                                                                                                                                    
      57                 :                                                                                                                                          
      58                 :     /**                                                                                                                                  
      59                 :      * Tag (set/get) the user specified in $target                                                                                       
      60                 :      *                                                                                                                                   
      61                 :      * @param $name                                                                                                                      
      62                 :      * @param $target                                                                                                                    
      63                 :      * @param $value                                                                                                                     
      64                 :      */                                                                                                                                  
      65                 :     public function tagUser($name, $target, $value = null)                                                                               
      66                 :     {                                                                                                                                    
      67               5 :         return $this->tag(PHPDS_tagger::tag_user, $name, $target, $value);                                                               
      68                 :     }                                                                                                                                    
      69                 :                                                                                                                                          
      70                 :     /**                                                                                                                                  
      71                 :      * Tag (set/get) the current user                                                                                                    
      72                 :      *                                                                                                                                   
      73                 :      * @param $name                                                                                                                      
      74                 :      * @param $value                                                                                                                     
      75                 :      */                                                                                                                                  
      76                 :     public function tagMe($name, $value = null)                                                                                          
      77                 :     {                                                                                                                                    
      78               0 :         $me = $this->user->currentUserID();                                                                                              
      79               0 :         if (empty($me)) return false;                                                                                                    
      80               0 :         return $this->tag(PHPDS_tagger::tag_user, $name, $me, $value);                                                                   
      81                 :     }                                                                                                                                    
      82                 :                                                                                                                                          
      83                 :     /**                                                                                                                                  
      84                 :      * Tag (set/get) the menu specified in $target                                                                                       
      85                 :      *                                                                                                                                   
      86                 :      * @param $name                                                                                                                      
      87                 :      * @param $target                                                                                                                    
      88                 :      * @param $value                                                                                                                     
      89                 :      */                                                                                                                                  
      90                 :     public function tagMenu($name, $target, $value = null)                                                                               
      91                 :     {                                                                                                                                    
      92               0 :         return $this->tag(PHPDS_tagger::tag_menu, $name, $target, $value);                                                               
      93                 :     }                                                                                                                                    
      94                 :                                                                                                                                          
      95                 :     /**                                                                                                                                  
      96                 :      * Tag (set/get) the current menu                                                                                                    
      97                 :      *                                                                                                                                   
      98                 :      * @param $name                                                                                                                      
      99                 :      * @param $value                                                                                                                     
     100                 :      */                                                                                                                                  
     101                 :     public function tagHere($name, $value = null)                                                                                        
     102                 :     {                                                                                                                                    
     103               0 :         $here = $this->navigation->currentMenuID();                                                                                      
     104               0 :         if (empty($here)) return false;                                                                                                  
     105               0 :         return $this->tag(PHPDS_tagger::tag_menu, $name, $here, $value);                                                                 
     106                 :     }                                                                                                                                    
     107                 :                                                                                                                                          
     108                 :     /**                                                                                                                                  
     109                 :      * Tag (set/get) the role specified in $target                                                                                       
     110                 :      *                                                                                                                                   
     111                 :      * @param $name                                                                                                                      
     112                 :      * @param $target                                                                                                                    
     113                 :      * @param $value                                                                                                                     
     114                 :      */                                                                                                                                  
     115                 :     public function tagRole($name, $target, $value = null)                                                                               
     116                 :     {                                                                                                                                    
     117               5 :         return $this->tag(PHPDS_tagger::tag_role, $name, $target, $value);                                                               
     118                 :     }                                                                                                                                    
     119                 :                                                                                                                                          
     120                 :     /**                                                                                                                                  
     121                 :      * Tag (set/get) the group specified in $target                                                                                      
     122                 :      *                                                                                                                                   
     123                 :      * @param $name                                                                                                                      
     124                 :      * @param $target                                                                                                                    
     125                 :      * @param $value                                                                                                                     
     126                 :      */                                                                                                                                  
     127                 :     public function tagGroup($name, $target, $value = null)                                                                              
     128                 :     {                                                                                                                                    
     129               5 :         return $this->tag(PHPDS_tagger::tag_group, $name, $target, $value);                                                              
     130                 :     }                                                                                                                                    
     131                 :                                                                                                                                          
     132                 :     /**                                                                                                                                  
     133                 :      * This function creates tag list which allows a comma separated list of tags.                                                       
     134                 :      *                                                                                                                                   
     135                 :      * @param string $object                                                                                                             
     136                 :      * @param string $target                                                                                                             
     137                 :      * @param string $value                                                                                                              
     138                 :      * @return string|nothing                                                                                                            
     139                 :      */                                                                                                                                  
     140                 :     public function tagArea($object, $target, $value = null)                                                                             
     141                 :     {                                                                                                                                    
     142                 :         // Define                                                                                                                        
     143               0 :         $security = $this->security;                                                                                                     
     144                 :                                                                                                                                          
     145                 :         // Check if we should continue.                                                                                                  
     146               0 :         if (empty($target))                                                                                                              
     147               0 :             return '';                                                                                                                   
     148                 :                                                                                                                                          
     149                 :         // Define.                                                                                                                       
     150               0 :         $tagnames = '';                                                                                                                  
     151                 :                                                                                                                                          
     152                 :         // Check if tags are saved.                                                                                                      
     153               0 :         if (! empty($security->post)) {                                                                                                  
     154               0 :             if (empty($security->post['tagger'])) {                                                                                      
     155               0 :                 $names = '';                                                                                                             
     156               0 :             } else {                                                                                                                     
     157               0 :                 $names = $security->post['tagger'];                                                                                      
     158                 :             }                                                                                                                            
     159               0 :             $this->db->invokeQuery('PHPDS_updateTagsQuery', $object, $target, $value, $names);                                           
     160               0 :         }                                                                                                                                
     161                 :                                                                                                                                          
     162                 :         // Find all related tags.                                                                                                        
     163               0 :         $taglist = $this->db->invokeQuery('PHPDS_taggerListTargetQuery', $target, $object);                                              
     164                 :                                                                                                                                          
     165               0 :         if (! empty($taglist)) {                                                                                                         
     166               0 :             asort($taglist);                                                                                                             
     167               0 :             foreach ($taglist as $tag) {                                                                                                 
     168               0 :                 $tagname = trim($tag['tagName']);                                                                                        
     169               0 :                 $tagnames .= "$tagname,";                                                                                                
     170               0 :             }                                                                                                                            
     171               0 :             $tagnames = rtrim($tagnames, ",");                                                                                           
     172               0 :         }                                                                                                                                
     173               0 :         return $tagnames;                                                                                                                
     174                 :     }                                                                                                                                    

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.