Including the result of a model method in listdata (Newbie)

I have the feeling this is a question of basic ignorance and poor training, but perhaps somebody can help me!

I have a table for people, with the attributes lastName, firstNames, and email. I almost always want firstNames and lastName together (though sometimes in the format "firstNames lastName" and other times in the format "lastName, firstName". And I often want some combination of first names and last names to appear together with an email address, though sometimes I want the email to be in front, and sometimes behind, and it can appear with either of the two ways of organising first and last names. In other words, those three attributes can appear in these six combinations:

I thought the best way of handling this was to define two methods in my model class to handle the arrangement of the firstNames and lastName and then two method (also in my model class) to construct the arrangement of email addresses with these combinations. This is what I came up with:




	public function getLastNameFirstNames()

    {

        return $this->lastName . ', ' . $this->firstNames;

    }

    

    public function getFirstNamesLastName()

    {

        return  $this->firstNames . ' ' . $this->lastName;

    }

    

    public function getNamesEmail($nameOrder)

    {

        $input = $nameOrder;

        return $input . ' (' . $this->email . ')';

    } 


    public function getEmailNames($nameOrder)

    {

        $input = $nameOrder;

        return  $this->email . ' (' . $input . ')';

    }



The idea, of course, is that I feed the value of either


getFirstNamesLastname()

or


getLastNameFirstNames()

as


$nameOrder

to


getNamesEmail($nameOrder)

or


getEmailNames($nameOrder)

depending on which final arrangement I want.

This works like a charm whenever I can call the method; but I also want to use it in a dropdown list. The problem there is that the name of the value in the list needs to be a string; and while a method like getEmailNames($input) resolves to a string, it isn’t one itself. So the first of these two options works, while the second doesn’t:




//The following works

<?php echo $form->dropDownList($model,'person_id', 

CHtml::listData(Person::model()->findAll(array('order'=>'t.email')), 

'person_id', 'firstNamesLastName'), array('empty'=>'--please select--')); ?>


//This doesn't work

<?php echo $form->dropDownList($model,'person_id', CHtml::listData(Person::model()->findAll(array('order'=>'t.email')), 'person_id', 'getEmailNames(FirstNamesLastNames)'), array('empty'=>'--please select--')); ?>



(The second example produces a “Property “Person.getEmailNames(FirstNamesLastNames)” is not defined” error because it is in single quotes and can’t be resolved. Putting it in double quotes doesn’t help and leaving the quotes out crashes things presumably because we don’t have a string for the name option).

Can anybody enlighten me on how you could go about using a method like this in this context?