public function index()
 {
     $Eventpics = new EventpicsController();
     $events = $this->Event->find('all', array('limit' => 9));
     $this->set("title_for_layout", "Foodbook");
     $userswithrating = array();
     $users = $this->User->find('all', array('limit' => 7));
     $this->User->Userrating->virtualFields['Rating'] = 0;
     foreach ($users as $user) {
         $rating = $this->User->Userrating->query("SELECT\n        \tuserto, AVG(rating) as Userrating__Rating\n        FROM\n        \tuserratings as Userrating\n        WHERE \n        \tuserto =" . $user['User']['id'], "\n        AS\n        \tUserrating\n        GROUP BY\n        \tuserto\n        ");
         $rate = $rating[0];
         $user['Rating'] = $rate;
         $userswithrating[] = $user;
     }
     $this->set('users', $userswithrating);
     for ($i = 0; $i < count($events); $i++) {
         $events[$i]['Event']['picture'] = $Eventpics->getdef($events[$i]['Event']['id']);
     }
     $this->set('events', $events);
 }
 /**
  * Search events by Location
  * Used in the start page
  */
 public function search_by_location()
 {
     if ($this->request->is('post')) {
         $cc = explode(',', $this->request->data['location-input']);
         //display all events if no location specified
         if (!$cc || !$cc[0] || !$cc[1]) {
             $this->redirect(array('action' => 'search'));
             return;
         }
         $conditions = array("Location.city LIKE" => "%" . trim($cc[0]) . "%", "Location.country LIKE" => "%" . trim($cc[1]) . "%");
         $rows = $this->Event->Location->find('all', array('conditions' => $conditions, 'fields' => array('Location.id')));
         $location_ids = array();
         foreach ($rows as $row) {
             $location_ids[] = $row['Location']['id'];
         }
         $events = $this->Event->find('all', array('conditions' => array('location_id' => $location_ids)));
         $this->paginate = array('limit' => 1);
         $data = $this->paginate('Event');
         $Eventpics = new EventpicsController();
         for ($i = 0; $i < count($events); $i++) {
             $events[$i]['Event']['picture'] = $Eventpics->getdef($events[$i]['Event']['id']);
         }
         $cuisines = $this->Event->Cuisine->find('all');
         $this->set('cuisines', $cuisines);
         //$this->set('location_ids', $location_ids);
         $this->set('events', $events);
         $this->render('search');
     } else {
         //if it's a 'get'-request
         $this->redirect(array('action' => 'search'));
     }
 }