Compatibility with Views

icouto - September 21, 2008 - 06:34
Project:Profile Privacy
Version:6.x-1.2
Component:Code
Category:feature request
Priority:normal
Assigned:Unassigned
Status:needs work
Description

We use Views 2 to create an automated address book of all our site members. Members, however, must be able to specify what private information they want to appear in the address book - and we want to use Profile Privacy for that.

When using Views 2 to create the address book - ie. a lists of users - Views seems to be unable to see the privacy settings for different fields, as set by Profile Privacy - which is a great, great pity.

Would there be any way for Profile Privacy to work with Views - or for Views to be aware of the field settings of Profile Privacy?

Many thanks in advance for your fantastic work - it's very much appreciated.

#1

icouto - September 21, 2008 - 07:05

Please note, that I've posted this request in the Profile Privacy queue, rather than in the Views queue, because of the following warning that appears when we try to create a new ticket in Views:

If you only read one of these submission guidelines, read this one. (Then please read the rest) If your problem deals exclusively with fields or filters provided by another module (CCK, Image, VotingAPI are common) please post the issue under the queue for that module first; all modules are responsible for telling Views about their own fields. It's possible Views IS at fault, but the module maintainers are the best people to make that determination, and they can kick the issue into the Views queue with an explanation of what's wrong if that is the case.

Once again, many thanks in advance for any and all help! :-)

#2

quicksketch - September 22, 2008 - 05:05

Thanks, this is definitely a better place to post. Great job reading guidelines! Merlinofchaos would be proud :)

Regarding the issue, this should technically be possible with Privacy Profile, however I'm barely maintaining the module, so it's likely that any additions will need to be provided through a patch (which I'd be glad to apply). Unfortunately I don't have the time to invest in this particular problem.

#3

gausarts - February 9, 2009 - 03:24

subscribing, thanks

#4

milos1234 - May 27, 2009 - 07:55

subscribe.... big time

#5

finfin82 - July 1, 2009 - 12:15
Status:active» needs work

Hi,
i solved this problem by adding the following views_query_alter hook to profile privacy.
i allready extended my profile privacy to work with user relationships so it could be, that you have to fit the PROFILE_PRIVACY_BUDDIES <-- etc defines to your needs

maybe this could be useful for somebody,
cheers finfin

btw: the user_relationship implementation will be commited as well, if i find the time to tidy up my code ;-)
this will see the first views arg as user-id ... mayb this information is better grabbed form anywhere else
i guess there is an error in reasoning in this case :-) the $view->args[0] should be the userid of the actual resulted user.... so forget about this solution ;-(

may be this will push someone in the right direction

/**
* hook_views_query_alter implementation
* @global object $user
* @param object $view
* @param object $query
*/
function profile_privacy_views_query_alter(&$view,&$query)
{
    global $user;
   
    $hide_field = array();
    foreach($query->table_queue as $tablekey=>$table)
    {
        if($view->args[0]==$user->uid||$user->uid==1)//skip if we are the user, or user is superadmin
            continue;
        if(eregi('profile_values',$tablekey))//we have a profile_value alias here
        {
            $fieldname = str_replace('profile_values_', "", $tablekey);
           
            //check the privacy-setting for this user and fieldname
            $privacy = profile_privacy_get_user_field_privacy($view->args[0], $fieldname);
            if($privacy)
            {
                if($privacy==PROFILE_PRIVACY_BUDDIES)//privacy-kind friends
                {
                    //check if related users are friends
                    if(user_relationships_api_socnet_is_related($user->uid, $view->args[0]))
                    {
                        //dont hide
                    }
                    else
                    {
                        $hide_field[] = $tablekey;
                    }
                }
                elseif($privacy==PROFILE_PRIVACY_PRIVATE)
                {
                    //hide generally
                    $hide_field[] = $tablekey;
                }
            }
        }
       
    }
    if(!empty($hide_field))
    {
        foreach ($hide_field as $tablealias)
        {
            //unset those fields, so they wouldnt exist in result
            unset($view->query->fields[$tablealias.'_value']);

        }
    }
    /*
    else
        //nothing
     *
     */
}

#6

finfin82 - July 2, 2009 - 11:03

I tried to solve the problem with another approach.
I tried to use the preprocess_views_view_field function

<?php
function phptemplate_preprocess_views_view_field(&$vars)
{
  global
$user;
 
$hide_field = array();
  foreach(
$vars['row'] as $key=>$row_val)
  {
      if(
$key=='uid'||$key=='users_user_relationships_uid')
       
$userid=$row_val;
       
      if(
eregi('profile_values_',$key))//profilfeld?
     
{
           
           
$fieldname = str_replace(array('profile_values_','_value'), "", $key);
           
#echo 'fname:'.$fieldname.'<br>';
            #echo 'userid:'.$userid.'<br>';
           
$privacy = profile_privacy_get_user_field_privacy($userid, $fieldname);
           
#echo 'privacy:'.$privacy.'<br>';
           
if(!empty($privacy))
            {
                if(
$privacy==PROFILE_PRIVACY_BUDDIES)
                {
                   
//checken ob ich freund von args[0] bin
                   
if(user_relationships_api_socnet_is_related($user->uid, $userid)||$user->uid===$userid)
                    {
                       
//feld nicht verstecken
                   
}
                    else
                    {
                       
#$hide_field[$tablekey][] = "'".$query->table_queue[$tablekey]['join']->definition['extra'][0]['value']."'";
                       
$hide_field[] = $key;
                    }
                }
                if(
$privacy==PROFILE_PRIVACY_PRIVATE)
                {
                   
#echo "verstecke: ".$key.'<br>';
                    //generell verstecken
                    #$hide_field[$tablekey][] = "'".$query->table_queue[$tablekey]['join']->definition['extra'][0]['value']."'";
                   
$hide_field[] = $key;
                }
            }
//end if privacy
     
}//end if profile field
      //echo $key.':'.$row_val.'<br>';
 
}//end foreach
 
 
foreach($hide_field as $field2hide)
  {
     
#echo "verstecke: $field2hide mit dem wert:  ".$vars['row']->$field2hide.'<br>';
     
unset($vars['row']->$field2hide);
     
$vars['row']->$field2hide="";
  }

 
 
$vars['output'] = $vars['field']->render($vars['row']);
 
#var_dump($vars['field']);
}
?>

but although i unset or empty the content of $vars['row']->$field2hide it's shown in the view-result on page,
so how do i unset a fields content, that it's no longer shown in result.

maybe merlinofcaos can help here?
cheers finfin

#7

kentr - October 5, 2009 - 17:56

I know little about views, so please forgive my ignorance.

Could this be better solved with a profile "relationship" for views that automatically detects the privacy of an individual field and hides it at the query level?

 
 

Drupal is a registered trademark of Dries Buytaert.