Trips hasMany Legs hasMany Segments
In my flight search app, I've got a function that returns unique Leg.destination(s). This function is for a trip controller method. Do I put the function in the trip model or leg model? If in the leg model I call it with $this->Trip->Leg->findUniqueDests.....? I'm asking because I want to stick to CakePHP convention. Thanks!
//code that finds ALL destinations for each Leg
$destinations=$this->Trip->Leg->find('all', array('limit'=>100,'fields'=>'Leg.destination'));
//code that finds the unique destinations (to be used to search all flights for a particular city
function findUniqueDests($destinations){
$unique_destinations = array();
foreach ($destinations as $dest)
{
if(!in_array($dest, $unique_destinations))
{
$unique_destinations[] = $dest;
sort($unique_destinations);
}
}
return $unique_destinations;
}