Check if user are friend to display data in members-loop buddyprress - buddypress

Can someone please help me out, I have a profile field named BB Pin and i use
BB Pin:<?php bp_member_profile_data('field=BB Pin');?>
to show the data in members-loop.php and it work fine but i want to do it so that if you are not friend the field value is *****.
Something like
if is friend{
BB Pin:<?php bp_member_profile_data('field=BB Pin');?>
}
else{
****.
Thanks for you help.
Regards
Update:
I have just tried the below code in the members-loop.php but did not work.
<?php
global $bp; $friend = BP_Friends_Friendship::check_is_friend( $bp->loggedin_user->id, $bp->displayed_user->id ); if ( $bp->loggedin_user->id || $friend == 'is_friend') : ?> echo <?php bp_member_profile_data('field=BB Pin');?> <?php else : ?> echo *************** <?php endif; ?>

Check if logged in user is friend or not please use below code:
global $bp;
$is_friend = friends_check_friendship( $bp->loggedin_user->id, $bp->displayed_user->id );
if($is_friend) {
BB Pin:<?php bp_member_profile_data('field=BB Pin');?>
} else{
BB Pin: ***;
}

$is_friend = friends_check_friendship( bp_loggedin_user_id(), bp_displayed_user_id() );
if($is_friend) {
BB Pin:<?php bp_member_profile_data('field=BB Pin');?>
} else{
BB Pin: ***;
This one should work in the loop! You canĀ“t use the global Variable $bp in the loop, but there are other variables for that particular task. In this case I just changed
$bp->loggedin_user->id, $bp->displayed_user->id
to the ones in my code example!

Related

Yii - disabling drop down when another is selected

So I have 2 $form->dropDownList
How can I make it in a way when if either one of the dropdown is selected, the other one gets set to value null and disabled, vice versa.
What options can I add into the array() so it behaves the way I want?
Please advise. Thanks in advance.
You need to handle it via javascript or jquery. First you should define an ID for two dropdowns in this way:
<?php echo $form->dropDownList($yourModel, 'attribute', CHtml::listData(...), array("id" => 'dropDown1')); ?>
<?php echo $form->dropDownList($yourModel, 'attribute', CHtml::listData(...), array("id" => 'dropDown2')); ?>
And in the script:
$(document).ready(function(){
if($("#dropDown1").val())
$("#dropDown2").attr("disabled", "disabled");
else
$("#dropDown2").removeAttr("disabled");
if($("#dropDown2").val())
$("#dropDown1").attr("disabled", "disabled");
else
$("#dropDown1").removeAttr("disabled");
$($("#dropDown1").on("change", function(){
if($(this).val())
$("#dropDown2").attr("disabled", "disabled");
else
$("#dropDown2").removeAttr("disabled");
});
$($("#dropDown2").on("change", function(){
if($(this).val())
$("#dropDown1").attr("disabled", "disabled");
else
$("#dropDown1").removeAttr("disabled");
});
});

Same column name used in where clause in codeigniter

i want to sql query like this
SELECT * FROM `tblName`
where `id`='007' and
`doj` != '2014-07-26' and
`doj` != '2014-08-04'
i want same column 'doj' used in where clause.
please help me?
Thanks in advance.
<?php
$dates = array(
'2014-07-26',
'2014-08-04'
);
$this->db->from('tblName');
$this->db->where('id','007');
// first variant
foreach($dates as $date){
$this->db->where('doj !=',$date);
}
// or second variant
$this->db->where_not_in('doj',$dates); // <- seems to be better
// finally get result
$result = $this->db->get();
if($result->num_rows()){
var_dump($result->result_array());
} else {
echo 'no rows found';
}
// check query
echo $this->db->last_query();
?>

Joomla 3.0 not echoing usertype

I made the following code to get some user variables in a flash app:
<?php
$user =& JFactory::getUser();
echo $user->get('username') ;
echo $user->get('id') ;
echo $user->get('name') ;
echo $user->get('usertype') ;
?>
Everything but usertype works, for some reason. Usertype is vital to be able to monetize my app. I followed this as a reference, so it seems alright:
http://docs.joomla.org/Accessing_the_current_user_object
Whats wrong here?
Right, I've had a look around and I can't actually find a decent solution that simply provides you with the name of the group that the user belongs to. Everything else gives you an array or the ID, so I have written a simple function that will get you exactly what you want:
function getUserGroup($userId){
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select('title')
->from('#__user_usergroup_map AS map')
->where('map.user_id = '.(int) $userId)
->leftJoin('#__usergroups AS a ON a.id = map.group_id');
$db->setQuery($query);
$result = $db->loadResult();
return $result;
}
echo getUserGroup($user->id);
Hope this helps

YII Call to a member function getErrors() on a non-objec

Following this tutorial; When I try to get the data to display in the form and update
For my error was:
$n = $this->loadModel($id);
I want to make two models with one form, this is my code for update:
Controller:
public function actionUpdate($id)
{
$n = new Noticias;
$m = new Multimedia;
$this->performAjaxValidation(array($n,$m));
$n=$this->loadModel($id);
if(isset($_POST['Noticias'],$_POST['Multimedia']))
{
$n->attributes=$_POST['Noticias'];
$m->attributes=$_POST['Multimedia'];
$m->ID_NOT=$n->ID;
$m->setIsNewRecord(false);
if($n->save())
$this->redirect(array('admin','id'=>$n->ID));
}
$this->render('update',array('n'=>$n,'m'=>$m));
}
update.php
<?php echo $this->renderPartial('_form', array('n'=>$n, 'm'=>$m)); ?>
some view
//get Multimedia FK
<?php if ($n->isNewRecord==false) {
$m=Multimedia::model()->findByPk($n->ID);
} ?>
//Validation
<?php echo $form->errorSummary(array($n,$m)); ?>
//Field FOTO between other
<div class="row">
<?php echo $form->labelEx($m,'FOTO_URL'); ?>
<?php echo $form->textField($m,'FOTO_URL',array('size'=>25,'maxlength'=>100)); ?>
<?php echo $form->error($m,'FOTO'); ?>
</div>
First - do not load models in view
<?php if ($n->isNewRecord==false) {
$m=Multimedia::model()->findByPk($n->ID);
} ?>
This part should be in controller action.
Make sure $m and $n are really models. If findByPk statement above fails, $m will be null, so you will get error from errorSummary which calls $m->getErrors() and $n->getErrors(). In short - make sure $n and $m are properly initialized - both must be instances of model, either empty, or filled from db, but in your case one is null. Most probably $m
this error occur when Noticias (ie $n is newrecord) or $n->ID is not found in Multimedia
you can solve this if you need to work even if its a new record you can use.
if ($n->isNewRecord==false) {
$m=Multimedia::model()->findByPk($n->ID);
}
else
$m=new Multimedia;
You can try to load both models in Controller (ex. in actionUpdate) :
public function actionUpdate($id)
{
$n = new Noticias;
$m = new Multimedia;
$this->performAjaxValidation(array($n,$m));
$n=$this->loadModelNoticias($id);
$m=$this->loadModelMultimedia($n->ID); //just put it here..
if(isset($_POST['Noticias'],$_POST['Multimedia']))
{
$n->attributes=$_POST['Noticias'];
$m->attributes=$_POST['Multimedia'];
$m->ID_NOT=$n->ID;
$m->setIsNewRecord(false);
if($n->save())
$this->redirect(array('admin','id'=>$n->ID));
}
$this->render('update',array('n'=>$n,'m'=>$m));
}
Please be noticed that you have to define both loadModel functions in the same controller too.
function loadModelNoticias($id){
$model = Noticias::model()->findByPk($id);
return $model;
}
function loadModelMultimedia($id){
$model = Multimedia::model()->findByPk($id);
return $model;
}

Best way to display current logged-on user in default.ctp?

I am in the process of customizing the default.ctp file and I am trying to display the currently logged on user's name on the top of the page.
In app_controller.php, I have the following:
function beforeFilter()
{
$user = $this->Auth->user();
if($user != null)
{
$this->Session->write('user_name',$user['User']['username']);
}
}
And in default.ctp, I have:
$user = $this->Session->read('Auth.User');
if(!empty($user))
{
echo 'Hello, ' . $user['user_name'];
}
However, it seems like the value $user_name is not getting set anywhere.
What am I doing wrong? Is there a better way to accomplish this?
Update: I've modified it as described in the answer, but it still doesn't work. I get an error:
Undefined index: user_name [APP/views/layouts/default.ctp, line 21]
you can also use the SessionHelper directly in the view / layout
$user = $this->Session->read('Auth.User');
if(!empty($user)) {
echo 'Hi ', $user['user_name'];
}
Cakephp 2.x:
<?php if (AuthComponent::user('id')): ?>
<p class="navbar-text pull-right">
Logged in as <?= AuthComponent::user('name') ?>
</p>
<?php endif; ?>
$user = $this->Session->read('Auth.User');
if(count($user))
echo $user['name'];