Skip to content

Instantly share code, notes, and snippets.

@martisj
Created September 6, 2012 11:27
Show Gist options
  • Save martisj/3655125 to your computer and use it in GitHub Desktop.
Save martisj/3655125 to your computer and use it in GitHub Desktop.
Controller method that parses data for the view
// group the notifications by entity_id
$groups = array();
foreach($notifications as $notif){
$entity_id = $notif->get_entity_id();
// echo $entity_id;
$entity = $this->em->getRepository('models\\'.$notif->get_entity_type())->find($entity_id);
$type = $notif->get_type();
// notification are grouped together. ww: changed array key to now include the type of
// notifcation as to not get 2 types with the same id creating one alert
// echo $entity_id.$type;
$grouping_key = $entity_id . $type;
if ($type == 'friend_connection')
{
if ($entity_id > $notif->get_user_from_id())
$grouping_key = $entity_id . '&' . $notif->get_user_from_id();
else
$grouping_key = $notif->get_user_from_id() . '&' . $entity_id;
$grouping_key .= $type;
}
if (isset($groups[$grouping_key])) {
// $groups[$entity_id.$type]['notifications'][] = $notif;
$groups[$grouping_key]['notifications'][] = $notif;
} else {
$groups[$grouping_key] = array(
"entity" => $entity,
"notifications" => array($notif)
);
}
}
$data['content_heading'] = count($groups) == 0 ? 'WELCOME TO UCROO' : 'RECENT ACTIVITY';
$data['groups'] = $groups;
$this->template->build('home/activity', $data);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment