Questions and Answers

How do I collect points?

  • +4
    Chosen as best answer
  • +1
    Posted answer
  • +1
    Posted question
  • +1
    Thumb up
  • -1
    Thumb down
4

by Gizzat Tazabekov in Coding about February 19, 2012 open - report

Inviting to a group - invite All members instead only frieds. Sorting issue

Hey everyone!

 

So I digged a little on the topic of inviting not only friends and here's what I found:

 

The list of group invitees(firends only for now) is put into $faces variable:

 

\www\application\modules\Group\controllers\MemberController.php

line 578:

$this->view->friends = $friends = $viewer->membership()->getMembers();

 

The actual array of users as invitees is coming from getMembers function.

The code snippet of getMembers:

\www\application\modules\Core\Model\DbTable\Membership.php, line 358:

 

public function getMembers(Core_Model_Item_Abstract $resource, $active = true)
  {
    $ids = array();
    foreach( $this->getMembersInfo($resource, $active) as $row )
    {
      $ids[] = $row->user_id;
    }
    return Engine_Api::_()->getItemTable('user')->find($ids);
  }

 

We see here that getMembers function calls getMembersInfo, that contains rows - each of which is already a user-invitee.

 

Looking at function getMembersInfo,

\www\application\modules\Core\Model\DbTable\Membership.php, line 386:

 

public function getMembersInfo(Core_Model_Item_Abstract $resource, $active = true)
  {
    $table = $this->getTable();
    $select = $table->select()->where('resource_id = ?', $resource->getIdentity());

    if( $active !== null )
    {
      $select->where('active = ?', (bool) $active);
    }

    return $table->fetchAll($select);
  }

 

Inside the function getMembersInfo we can see that there is sql condition where('resource_id = ?', $resource->getIdentity()), which filters found users by the viewer's friends. So, this is where we get only friends as possible invitees.


To be safe and leave the possibility to comeback to initial condition, I wont alter the already-written/declared functions getMembersInfo. I will declare a new function getAllMembersinfo that will return all members:

 

public function getAllMembersinfo(Core_Model_Item_Abstract $resource, $active = true)
  {
   
    $table = $this->getTable();
    $tableName = $table->info('name');
    $usertable = Engine_Api::_()->getDbtable('users', 'user');
    $userTableName = $usertable->info('name');
    

    $select = $table->select()
      ->from($tableName)
      ->joinRight($userTableName,
        '`'.$userTableName.'`.`user_id` = `'.$tableName.'`.`user_id`', null)
      ->order('displayname ASC')
      ;
        
     if( $active !== null )
    {
      $select->where('active = ?', (bool) $active);
    }

    return $table->fetchAll($select);
  }

 

The following code:

    $select = $table->select()
      ->from($tableName)
      ->joinRight($userTableName,
        '`'.$userTableName.'`.`user_id` = `'.$tableName.'`.`user_id`', null)
      ->order('displayname ASC')
      ;

 

is needed to order list of invitees in alpabetical order.

 

Now we change the code in MemberController.php so it uses getAllMembersinfo

 

\www\application\modules\Group\controllers\MemberController.php

line 578:

//$this->view->friends = $friends = $viewer->membership()->getMembersinfo();

$this->view->friends = $friends = $viewer->membership()->getAllMembersinfo();

 

This works fine right now - but the sorting doesnt work at all - it simply lits users in user_id order.

 

What could be the problem?

Answer: 1  •  Score 0  •  Views: 1106

1 Answer
Browse by
  • 264

    by Gaurav Sharma about February 22, 2012

    $this->view->make_list = Engine_Api::_()->getApi('settings', 'core')->user_friends_lists;

    // Don't render this if not authorized
    $viewer = Engine_Api::_()->user()->getViewer();
    if( !Engine_Api::_()->core()->hasSubject() ) {
    return $this->setNoRender();
    }

    // Don't render this if friendships are disabled
    if( !Engine_Api::_()->getApi('settings', 'core')->user_friends_eligible ) {
    return $this->setNoRender();
    }

    // Get subject and check auth
    $subject = Engine_Api::_()->core()->getSubject('user');
    if( !$subject->authorization()->isAllowed($viewer, 'view') ) {
    return $this->setNoRender();
    }

     

     

    it will help you

    • Score: 0
You must login to post an answer.