public function searchAction() { if ($this->getRequest()->isGet()) { if ($terms = $this->getRequest()->getParam('searchTerms', FALSE)) { $userService = new Service_User(); if (is_array($results = $userService->searchUsers($terms))) { $this->_helper->layout->setLayout('topmenu'); for ($i = 0; $i < count($results); $i++) { if ($this->_user->profileid == $results[$i]['id']) { unset($results[$i]); continue; } $friended = false; if (count($results[$i]['Friends'])) { foreach ($results[$i]['Friends'] as $friend) { if ($this->_user->id == $friend['friend']) { $friended = true; break; } } } $results[$i]['friend'] = $friended; $results[$i]['connections'] = count($results[$i]['Friends']); if (!$friended) { $request = false; if (count($results[$i]['OutgoingFriendRequests'])) { foreach ($results[$i]['OutgoingFriendRequests'] as $outgoing) { if ($this->_user->id == $outgoing['requestee']) { $request = true; $results[$i]['requestid'] = $outgoing['id']; break; } } } $results[$i]['incomingRequest'] = $request; if (!$request) { $requested = false; if (count($results[$i]['IncomingFriendRequests'])) { foreach ($results[$i]['IncomingFriendRequests'] as $incoming) { if ($this->_user->id == $incoming['requestor']) { $requested = true; $results[$i]['requestid'] = $incoming['id']; break; } } } $results[$i]['outgoingRequest'] = $requested; } } } $result['root'] = $results; $this->view->searchTerms = $terms; $this->view->resultTotal = count($results); $this->view->searchNoPerPage = 5; $this->view->users = $result; return $this->render('searchresults'); } } } }