Current file: /root/works/bitsis/oxokuatro/CRE/WSFW/lib/functions.php
Legend: executed not executed dead code

  Coverage
  Classes Functions / Methods Lines
Total
  
   
22.22%22.22%
22.22% 2 / 9 CRAP
12.68%12.68%
12.68% 9 / 71
 
Functions
  
   
22.22%22.22%
22.22% 2 / 9
100.00%100.00%
100.00% 0 / 0
 array_union($campos, $cmp, $ws, $db)
0.00%0.00%
0.00% 0 / 1 56
0.00%0.00%
0.00% 0 / 8
 array_inter($campos, $cmp, $ws, $db)
0.00%0.00%
0.00% 0 / 1 42
0.00%0.00%
0.00% 0 / 8
 array_filters($args, $campos, $replace = null)
0.00%0.00%
0.00% 0 / 1 20
0.00%0.00%
0.00% 0 / 8
 array_filters_assoc($args, $campos, $replace = null)
0.00%0.00%
0.00% 0 / 1 240
0.00%0.00%
0.00% 0 / 18
 array_replace_assoc($from, $to, $array, $assoc = null)
0.00%0.00%
0.00% 0 / 1 42
0.00%0.00%
0.00% 0 / 14
 is_assoc($array)
0.00%0.00%
0.00% 0 / 1 12
0.00%0.00%
0.00% 0 / 2
 objectToArray($object)
100.00%100.00%
100.00% 1 / 1 4
100.00%100.00%
100.00% 5 / 5
 debug($title, $content)
100.00%100.00%
100.00% 1 / 1 2
100.00%100.00%
100.00% 4 / 4
 error($msg, $e = null)
0.00%0.00%
0.00% 0 / 1 6
0.00%0.00%
0.00% 0 / 4


       1                 : <?php                                                                                                                                         
       2                 : /**                                                                                                                                           
       3                 :  * Fitxer que defineix les funcions de tractament de l'estructura de dades del WSFW i d'altres auxiliars                                      
       4                 :  * @package WSFW                                                                                                                              
       5                 :  */                                                                                                                                           
       6                 :                                                                                                                                               
       7                 : /**                                                                                                                                           
       8                 :  * Unió d'arrays d'arrays associatius per la coincidencia d'un camp                                                                           
       9                 :  * @return estructura Retorna el resultat de l'operació                                                                                       
      10                 :  */                                                                                                                                           
      11                 : function array_union($campos, $cmp, $ws, $db) {                                                                                               
      12               0 :     $ret = array();                                                                                                                           
      13               0 :     if (!$ws || !count($ws) || !$db) return $ret;                                                                                             
      14               0 :     foreach ($ws as $_ws) {                                                                                                                   
      15               0 :         if (!isset($_ws["$cmp"])) continue;                                                                                                   
      16               0 :         $_db = array_pop(array_filter($db, create_function('$c', 'return $c["'.$cmp.'"] == "'.$_ws["$cmp"].'";')));                           
      17               0 :         if ($_db) array_push($ret, array_intersect_key(array_merge($_ws, $_db), array_flip($campos)));                                        
      18               0 :     }                                                                                                                                         
      19               0 :     return $ret;                                                                                                                              
      20                 : }                                                                                                                                             
      21                 :                                                                                                                                               
      22                 : /**                                                                                                                                           
      23                 :  * Intersecció per camp d'arrays d'arrays associatius                                                                                         
      24                 :  */                                                                                                                                           
      25                 : function array_inter($campos, $cmp, $ws, $db) {                                                                                               
      26               0 :     $ret = array();                                                                                                                           
      27               0 :     if (!$ws || !$db) return $ret;                                                                                                            
      28               0 :     foreach ($ws as $_ws) {                                                                                                                   
      29               0 :         if (!isset($_ws["$cmp"])) continue;                                                                                                   
      30               0 :         $_db = array_pop(array_filter($db, create_function('$c', 'if (isset($c["'.$cmp.'"])) return $c["'.$cmp.'"] == "'.$_ws["$cmp"].'";')));
      31               0 :         if (!$_db) array_push($ret, array_intersect_key($_ws, array_flip($campos)));                                                          
      32               0 :     }                                                                                                                                         
      33               0 :     return $ret;                                                                                                                              
      34                 : }                                                                                                                                             
      35                 :                                                                                                                                               
      36                 : /**                                                                                                                                           
      37                 :  * Filtra els camps dels l'arrays associatius dins d'un array                                                                                 
      38                 :  * @return estructura Retorna el resultat de l'operació                                                                                       
      39                 :  */                                                                                                                                           
      40                 : function array_filters($args, $campos, $replace = null) {                                                                                     
      41               0 :     if (is_assoc($args))                                                                                                                       
      42               0 :         return array_filters_assoc($args, $campos, $replace);                                                                                 
      43               0 :     elseif (is_array($args)) {                                                                                                                
      44               0 :         $ret = array();                                                                                                                       
      45               0 :         foreach ($args as $row)                                                                                                               
      46               0 :             array_push($ret, array_filters_assoc($row, $campos, $replace));                                                                   
      47               0 :         return $ret;                                                                                                                          
      48                 :     }                                                                                                                                         
      49               0 : }                                                                                                                                             
      50                 :                                                                                                                                               
      51                 : /**                                                                                                                                           
      52                 :  * Aplica el filtre a l'array associatiu                                                                                                      
      53                 :  * @return estructura Retorna el resultat de l'operació                                                                                       
      54                 :  */                                                                                                                                           
      55                 : function array_filters_assoc($args, $campos, $replace = null) {                                                                               
      56               0 :     if (!$replace && is_assoc($campos)) {                                                                                                     
      57               0 :         foreach ($args as $key => $val) {                                                                                                     
      58               0 :             if ($val && isset($campos[$key]["date_in"]) && isset($campos[$key]["date_out"]))                                                   
      59               0 :                 $val = change_date_format($val, $campos[$key]["date_in"], $campos[$key]["date_out"]);                                         
      60               0 :             if (isset($campos[$key]["name"])) $_args[$campos[$key]["name"]] = $val;                                                           
      61               0 :         }                                                                                                                                     
      62               0 :     } else {                                                                                                                                  
      63               0 :         foreach ($args as $key => $val) {                                                                                                     
      64               0 :             if ($val && isset($replace[$key]["date_in"]) && isset($replace[$key]["date_out"]))                                                 
      65               0 :                 $val = change_date_format($val, $replace[$key]["date_in"], $replace[$key]["date_out"]);                                       
      66               0 :             if (in_array($key, $campos)) {                                                                                                    
      67               0 :                 if (isset($replace[$key]["name"]))                                                                                            
      68               0 :                     $_args[$replace[$key]["name"]] = $val;                                                                                    
      69                 :                 else                                                                                                                          
      70               0 :                     $_args[$key] = $val;                                                                                                      
      71               0 :             }                                                                                                                                 
      72               0 :         }                                                                                                                                     
      73                 :     }                                                                                                                                         
      74               0 :     if (isset($_args)) return $_args;                                                                                                         
      75               0 : }                                                                                                                                             
      76                 :                                                                                                                                               
      77                 : /**                                                                                                                                           
      78                 :  * Substitueix els camps d'un array associatiu                                                                                                
      79                 :  * @return estructura Retorna el resultat de l'operació                                                                                       
      80                 :  */                                                                                                                                           
      81                 : function array_replace_assoc($from, $to, $array, $assoc = null) {                                                                             
      82               0 :     if (!is_assoc($array[0])) {                                                                                                               
      83               0 :         $ret = array();                                                                                                                       
      84               0 :         foreach ($assoc as $element) {                                                                                                        
      85               0 :             if (in_array($element[$from], $array))                                                                                            
      86               0 :                 array_push($ret, $element[$to]);                                                                                              
      87               0 :         }                                                                                                                                     
      88               0 :         return $ret;                                                                                                                          
      89                 :     } else {                                                                                                                                  
      90               0 :         for($i=0; $i<count($array); $i++) {                                                                                                   
      91               0 :             if (array_key_exists($from, $array[$i])) {                                                                                        
      92               0 :                 $array[$i][$to] = $array[$i][$from];                                                                                          
      93               0 :                 unset($array[$i][$from]);                                                                                                     
      94               0 :             }                                                                                                                                 
      95               0 :         }                                                                                                                                     
      96               0 :         return $array;                                                                                                                        
      97                 :     }                                                                                                                                         
      98                 : }                                                                                                                                             
      99                 :                                                                                                                                               
     100                 : /**                                                                                                                                           
     101                 :  * Comprova si un array és associatiu                                                                                                         
     102                 :  * @return bool Retorna el resultat de l'operació                                                                                             
     103                 :  */                                                                                                                                           
     104                 : function is_assoc($array) {                                                                                                                   
     105               0 :     return (is_array($array) &&                                                                                                                
     106               0 :         (0 !== count(array_diff_key($array, array_keys(array_keys($array)))) || count($array)==0));                                           
     107                 : }                                                                                                                                             
     108                 :                                                                                                                                               
     109                 : /**                                                                                                                                           
     110                 :  * Converteix de stdClass a array associatiu                                                                                                  
     111                 :  * @return estructura Retorna el resultat de l'operació                                                                                       
     112                 :  */                                                                                                                                           
     113                 : function objectToArray($object) {                                                                                                             
     114               6 :     if(!is_object($object) && !is_array($object))                                                                                             
     115               6 :         return $object;                                                                                                                       
     116               6 :     if(is_object($object))                                                                                                                    
     117               6 :         $object = get_object_vars( $object );                                                                                                 
     118               6 :     return array_map('objectToArray', $object);                                                                                               
     119                 : }                                                                                                                                             
     120                 :                                                                                                                                               
     121                 : /**                                                                                                                                           
     122                 :  * Maquetació dels missatges de debug                                                                                                         
     123                 :  */                                                                                                                                           
     124                 : function debug($title, $content) {                                                                                                            
     125               9 :     global $debug;                                                                                                                            
     126               9 :     if (!$debug) return;                                                                                                                      
     127               1 :     echo "<br><table bgcolor='#DDDDDD'><tr><td><h2>".$title."</h2>".htmlentities($content)."<br></td></tr></table>";                          
     128               1 : }                                                                                                                                             
     129                 :                                                                                                                                               
     130                 : /**                                                                                                                                           
     131                 :  * Maquetació dels missatges d'error                                                                                                          
     132                 :  */                                                                                                                                           
     133                 : function error($msg, $e = null) {                                                                                                             
     134               0 :     echo "<br><table bgcolor='#aa9999'><tr><td><h3>Error</h3>".$msg."<br>";                                                                   
     135               0 :     if ($e) var_dump($e->getMessage());                                                                                                       
     136               0 :     echo "</td></tr></table>";                                                                                                                
     137               0 : }                                                                                                                                             
     138                 :                                                                                                                                               
     139                 : ?>                                                                                                                                            

Generated by PHP_CodeCoverage 1.0.3 using PHP 5.3.3-7 and PHPUnit 3.5.5 at Tue Jan 25 2:17:13 CET 2011.