Hi all,
I’ve created a recursive function that returns members from a specific team recursively. The recursion goes into sub teams and returns those members as well.
// --- TeamController ---
public function getMembers($recursively = true)
{
if ($recursively)
{
$members= $this->members;
foreach ($this->subTeams as $subTeam)
$members= array_merge($members, $subTeam->getMembers(true));
return $members;
}
else
return $this->members;
}
Database Tables:
Members: id, userId, teamId
Users: id, name, email
Team: id, name
Member relation
return array(
'user' => array(self::BELONGS_TO, 'User', 'userId'), ...
The problem is that the array is not sorted. I want to sort the array by Users.Name and give it to CHtml::dropDownList(). I was playing with CArrayDataProvider but couldn’t figure out how to sort on a relational table.
Any ideas would be greatly appreciated!
Update:
This one actually sorts the array, but guess what? The array contains less data! How come?
$dpr = new CArrayDataProvider($members, array(
'sort' => array(
'attributes' => array('name' => 'user.name'),
'defaultOrder' => 'name'
)
));
$members= $dpr->getData();