Recommendation widget for socialengine using their own code
The basic knowledge of socialengine is required for installing this stuff. first need to inform that, this widget is not developed in a professional manner.
steps:
1.Take the user module
path: application->modules->user
2.Then reach the widgets folder in user module and create widget files
a.controller file
b.tpl file
then copy the contents to this two files
controller.php
<?php
class User_Widget_UniiFriendsRecommendationController extends Engine_Content_Widget_Abstract
{
protected $_childCount;
public function indexAction()
{
$this->view->viewmore=0;
$viewer = Engine_Api::_()->user()->getViewer();
if($viewer[‘cancelled_recommendation’]!=”){
$aCancelledIds = explode(‘,’, $viewer[‘cancelled_recommendation’]);
}
$currentFriends=array();
$uids = array();
$commoncount = array();
$recomm=array();
$userobj=array();
$notinids=array($viewer->getIdentity());
$network = Engine_Api::_()->getItem(‘network’, ‘270’);
$uniiUsersSelect = $network->membership()->getMembersSelect();
$uniiUsersObj = Zend_Paginator::factory($uniiUsersSelect);
foreach( $uniiUsersObj as $uniiUserObj ) {
$uniiUsers[]=$uniiUserObj[‘user_id’];
}
if(isset($uniiUsers) && is_array($uniiUsers)){
$notinids= array_merge($notinids,$uniiUsers);
}
$afriendsDetails =$viewer->membership()->getRecommendationIds();
if(count($afriendsDetails)>0){
if(isset($aCancelledIds) && is_array($aCancelledIds)){
$notinids= array_merge($notinids,$aCancelledIds);
}
$friendsTable = Engine_Api::_()->getDbtable(‘membership’, ‘user’);
$select=$friendsTable->select();
$select->from($friendsTable->info(‘name’),array(‘resource_id’=>’resource_id’,’count_resource’=>’count(resource_id)’));
$select->where(“active = ?”,1);
if(isset($afriendsDetails) && is_array($afriendsDetails)){
$notinids= array_merge($notinids,$afriendsDetails);
$select->where(“user_id in (?)”,$afriendsDetails);
}
$notinids= array_unique($notinids,SORT_NUMERIC);
$select->where(“resource_id not in (?)”,$notinids);
$select->group(‘resource_id’);
$select->order(‘count_resource DESC’);
$select->order(‘RAND()’);
$friendcount=0;
$datas = $select->query()->fetchAll();
if(count($datas)>5){$this->view->viewmore=1;}
foreach( $datas as $data ) {
$user = Engine_Api::_()->user()->getUser($data[‘resource_id’]);
if(!$viewer->isBlockedBy($user)){
if(($user->authorization()->isAllowed($viewer, ‘view’)) == 1 ):
$friendcount++;
$uids[] = $data[‘resource_id’];
$userobj[$data[‘resource_id’]]=$user;
$commoncount[$data[‘resource_id’]]=$data[‘count_resource’];
if($friendcount==5)
{
break;
}
endif;
}
}
$recomm= array_merge($recomm,$uids);
}
$recomm_count=count($recomm);
if($recomm_count < 5){
$notinids= array_merge($notinids,$uids);
$uids = array();
$userTable = Engine_Api::_()->getDbtable(‘users’, ‘user’);
$select=$userTable->select();
$select->where(“user_id not in (?)”,$notinids);
$select->where(“university = ?”,$viewer[‘university’]);
$select->where(“enabled = ?”,1);
$select->where(“approved = ?”,1);
$select->where(“verified = ?”,1);
$select->order(‘RAND()’);
foreach( $select->query()->fetchAll() as $data ) {
$user = Engine_Api::_()->user()->getUser($data[‘user_id’]);
if(!$viewer->isBlockedBy($user)){
if(($user->authorization()->isAllowed($viewer, ‘view’)) == 1 ):
$recomm_count=$recomm_count+1;
$uids[] = $data[‘user_id’];
$userobj[$data[‘user_id’]]=$user;
$commoncount[$data[‘user_id’]]=’0′;
if($recomm_count==5){
break;
}
endif;
}
}
$recomm= array_merge($recomm,$uids);
}
$recomm_count=count($recomm);
if($recomm_count < 5){
$notinids= array_merge($notinids,$uids);
$notinids= array_unique($notinids,SORT_NUMERIC);
$uids = array();
$userTable = Engine_Api::_()->getDbtable(‘users’, ‘user’);
$select=$userTable->select();
$select->where(“user_id not in (?)”,$notinids);
$select->where(“enabled = ?”,1);
$select->where(“approved = ?”,1);
$select->where(“verified = ?”,1);
$select->order(‘RAND()’);
foreach( $select->query()->fetchAll() as $data ) {
$user = Engine_Api::_()->user()->getUser($data[‘user_id’]);
if(!$viewer->isBlockedBy($user)){
if(($user->authorization()->isAllowed($viewer, ‘view’)) == 1 ):
$recomm_count=$recomm_count+1;
$uids[] = $data[‘user_id’];
$userobj[$data[‘user_id’]]=$user;
$commoncount[$data[‘user_id’]]=’0′;
if($recomm_count==5){
break;
}
endif;
}
}
$recomm= array_merge($recomm,$uids);
}
$this->view->recommendedusers=$recomm;
$this->view->userobj=$userobj;
$this->view->commoncount=$commoncount;
}
public function getChildCount()
{
return $this->_childCount;
}
}
index.tpl
<span class=”title bold”>Find people I may know</span>
<div class=”box”>
<div class=”header”>
<span>Recommendations</span>
</div>
<div class=”content” id=”rec-content” >
<ul class=”recommendation-list”>
<?php
if(count($this->recommendedusers) > 0):
foreach($this->recommendedusers as $key ):
$user = $this->userobj[$key];
?>
<li id=”rec-li-<?php echo $user->getIdentity(); ?>”>
<div class=”recomm_image”><?php echo $this->htmlLink($user->getHref(), $this->itemPhoto($user, ‘thumb.icon’, $user->getTitle()), array(‘title’=>$user->getTitle())); ?></div>
<div class=”recomm_details”>
<input type=”hidden” id=”id_<?php echo $user->getIdentity();?>” value=”<?php echo $user->getIdentity(); ?>”>
<a id=”recommendation_<?php echo $user->getIdentity(); ?>” class=”recommendation” href=”javascript:void(null);” ><img class =”recommendation_close pull-right” src=”<?php echo $this->baseUrl();?>/images/ico-blue-cross.png” ></a>
<?php echo $this->userFriendship($user); ?>
<a href=”<?php echo $user->getHref();?>” class=”text-link bold”><?php echo substr($user->getTitle(),0,20); ?></a>
<?php echo substr($this->OptionValue($user,’university’),0,23); ?>
<?php if(isset($this->commoncount[$key]) && $this->commoncount[$key] > 0) { ?>
</br>
<?php echo $this->commoncount[$key]; if($this->commoncount[$key] >1):?> friends in common<?php elseif($this->commoncount[$key]==1): ?> friend in common<?php endif; } ?>
</div>
<div class=”clearfix”></div>
</li>
<?php
endforeach;
?>
<?php if($this->viewmore == 1 ): ?>
<li>
<input type=”hidden” id=”see-more” value=”1″>
<div style=”float:right”><a href=”<?php echo $this->baseUrl();?>/recommendation”>See More</a></div>
</li>
<?php endif; else: ?>
<li>Currently No Recommendation</li>
<?php
endif;
?>
</ul>
</div>
</div>