Find out who viewed my profile on socialengine

When an organization is running a social community, they are worried about vulnerable to attacks on the platform. Several hackers actively alter users profile information on daily basis. Many social community  users can tell you that they noticed change in their profile information while they were not logged in. Other scenarios could be when organization wants to let their user check ‘who viewed my profile’ and allow them to send friendship request to the person with similar interest or track down the person who visited.

It would be really useful for an organization if they are able to give their users a features which allow them to  see list of  users, who has visited their profile. One of our client Bougex had encountered this issue on his site. We recommended our client a solution to give their users a list of others users who has visited their profile. In this article we have demonstrated the approach by which we can achieve this feature.

Lets dive into socialengine custom development for ‘who viewed my profile’

We has created a admin controller to give admin panel  to set permission. Admin can set the no of count of users which can be seen by a member level. Give permission to member level, who can view all users or not. Admin can enable or disable the test most. If test mode is enabled, then this feature can only be seen by the super-admin member level. Admin can set the anonymity for the various member level.

public function settingAction()
{
    $this->view->navigation = $navigation = Engine_Api::_()->getApi('menus', 'core')
    ->getNavigation('whoviewedme_admin_main', array(), 'whoviewedme_admin_main_settings'); 
    $this->view->form = $form = new Viewed_Form_Admin_Setting();		
    $member_level = $this->_getParam('level_id',"1");
    $memberviewcount_table = Engine_Api::_()->getDbTable('membercounts','viewed');
    $select = $memberviewcount_table->select()
    ->where('level_id = ?', $member_level);
    $level_exits = $memberviewcount_table->fetchRow($select);
    if(isset($level_exits) && count($level_exits)>0)
     {
        $form->populate($level_exits->toArray());
     }else{
	$form->getElement('level_id')->setValue($member_level);
     }
     ......// this will give us the settings entered by admin
}

To store the settings entered by the admin we have needed a table. So we have created a Db table “Member count”. which has stored all the settings saved by the admin in the admin panel. to create table we have created a Membercount.php file under model folder. and Membercounts.php under dbtable folder.

 

admin-settings

Now to show the user the listing of the users who has visited their profile we have created a widget. Under widget controller we have got the subject detail when any user view the profile. We have stored the subject information in a dbtable named as “Viewme.php” and then display this information in the list format to the user. this widget should be placed on member profile page. With this page we can put this widget elsewhere as well. we have wrote the code in the “indexAction” to get the all the details. after getting all the users, we have created the listing with the help of “foreach” loop in  the index.tpl file of the widget.

public function indexAction()
{   
    //get subject
    if(Engine_Api::_()->core()->hasSubject())
     {	   
        $subject = Engine_Api::_()->core()->getSubject('user');
        if(isset($subject))
          {
  	      $sub_exist = true;
   	      $subject_id = $subject->getIdentity();
  	      $user = Engine_Api::_()->getItem('user', $subject_id);
  	      $subject_level = $user->level_id;
  	      $params=array("user_id" => $user_id,"subject_id"=>$subject_id,"widgetlimit" => 
              $this->_getParam('widgetlimit'));
          }
        else 
          {
  	      $params=array("user_id" => $user_id,"widgetlimit" => $this->_getParam('widgetlimit'));
  		   	
  	   }
  		
     }
   else 
     {
        $sub_exist = false;
        $params=array("user_id" => $user_id,"widgetlimit" => $this->_getParam('widgetlimit'));	  
     }
   //check subject subscription
   if(isset($subject))
     {
  	$sub_subscription = Engine_Api::_()->getApi('core','viewed')
        ->subscriptionStatus($subject_level,$subject_id);
     }
   //check package
  $member_Exits = Engine_Api::_()->getApi('core','viewed')->subscriptionStatus($user_level,$user_id);
  $this->view->userallow = $member_Exits;
  $test_mode = 0;
  $exclude_mode = 0;
  //check test mode
  $coresettings_table = Engine_Api::_()->getDbTable('settings','core');
  $coresettings_select = $coresettings_table->select()
  		         ->where("name = 'testmode'");
  // check exclusion
  $corexclude_select = $coresettings_table->select()
  		       ->where("name = 'excludelevels'"); 
  $coresettings_result = $coresettings_table->fetchRow($coresettings_select);
  $coreexclude_result = $coresettings_table->fetchRow($corexclude_select);
  if(isset($coresettings_result) && count($coresettings_result)>0)
     {
        $test_mode = $coresettings_result->value;
  	   if(isset($test_mode) && $test_mode == 1 && $user_level !== 1)
  		{ 
  		    if( $sub_exist && !$subject->isSelf($viewer) )
  			 {
  			    $save = Engine_Api::_()->getApi('core','viewed')->saveViewedProfile($params);
  			 }
  			 return $this->setNoRender();
  		}
     }
     ......// this will give the all the members who has visited the profile and also check the excluded member level and test mode.
}

 Who-viewed-me

with the profile listing we have also displayed the count and the date on which user has visited the profile with the help of the data stored in the db table. we have also given option to add the member to users friend list which can be achieved with the help of the “friends” function.

Conclusion

Hence by following the approach, we can give a organization to set the various count for various member level, to exclude the member level from listing . To a user, this approach will give them listing of members ‘who has visited my profile’ and also give option to add them to friend list. To reduce efforts and time, we have created a plugin which should display the users who have visited your profile. If you have any further query, Please contact us.

Leave a Comment

Scroll to Top