Function to subset on System database

    This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

    • Function to subset on System database

      Hi everyone,

      just for your information, I developed a php function that I use to return a subset on system database cubes (as it is impossible to use subsets on system database).

      For instance: I want the list of the groups where role is "user". The function below can then be used this way:

      PHP Source Code

      1. $conn=palo_init('localhost','7777','admin','admin');
      2. $cube='#_GROUP_ROLE';
      3. $dim_to_query='#_GROUP_';
      4. $dim_elt_to_lookup='user';
      5. $criterium='1';
      6. $return=subset_system($conn,$cube,$dim_to_query, $dim_elt_to_lookup, $criterium);
      7. print_r($return);
      8. // returns (in standard Demo db) : Array([0] => sales [1] => marketing)


      the function:

      PHP Source Code

      1. // returns a subset of $dim_to_query, filtered using $criterium on $dim_to_lookup
      2. function subset_system($conn, $cube, $dim_to_query, $dim_elt_to_lookup, $criterium)
      3. {
      4. $db='System';
      5. // list elements of the dimensions to query
      6. $elts_dim_to_query=palo_dimension_list_elements($conn,$db,$dim_to_query);
      7. // get only the names
      8. $elts_dim_to_query_names=getarray($elts_dim_to_query,'name');
      9. // list dimensions of the cube
      10. $cube_dims=palo_cube_list_dimensions($conn,$db,$cube);
      11. if ($cube_dims[0]==$dim_to_query)
      12. {
      13. $array_palo_data[1]=$dim_elt_to_lookup;
      14. foreach ($elts_dim_to_query_names as $elts_dim_to_query_name)
      15. {
      16. $array_palo_data[0]=$elts_dim_to_query_name;
      17. ksort($array_palo_data);
      18. $cube_value=palo_dataa($conn,$db,$cube,$array_palo_data);
      19. if ($cube_value==$criterium)
      20. {
      21. $return_array[]=$elts_dim_to_query_name;
      22. }
      23. }
      24. }
      25. else
      26. {
      27. $array_palo_data[0]=$dim_elt_to_lookup;
      28. foreach ($elts_dim_to_query_names as $elts_dim_to_query_name)
      29. {
      30. $array_palo_data[1]=$elts_dim_to_query_name;
      31. //ksort($array_palo_data);
      32. $cube_value=palo_dataa($conn,$db,$cube,$array_palo_data);
      33. if ($cube_value==$criterium)
      34. {
      35. $return_array[]=$elts_dim_to_query_name;
      36. }
      37. }
      38. }
      39. return $return_array;
      40. }
      41. // returns the subarray of $array corresponding to $key
      42. function getarray($array,$key)
      43. {
      44. foreach ($array as $arrayelt)
      45. {
      46. $arrayret[]=$arrayelt[$key];
      47. }
      48. return $arrayret;
      49. }
      Display All


      Hope it helps ! and do not hesitate to modify it
      laloune

      Post hoc, non est propter hoc