public function executeIndex(sfWebRequest $request) { $c = new Criteria(); // Retrieve a random individual who they haven't seen $already_viewed = $this->getUser()->getAttribute('already_viewed', array()); $c->add(DouchePeer::ID, $already_viewed, Criteria::NOT_IN); $douche = DouchePeer::retrieveRandom($c); if ($douche instanceof Douche) { $redirect_to = $douche; } else { // They have seen them all // reset the already_viewed record to skip a second query $this->getUser()->setAttribute('already_viewed', array()); $redirect_to = DouchePeer::retrieveRandom(); } // It's possible that we don't have any users // in which case, redirect to errors/noUsers if ($redirect_to instanceof Douche) { $this->redirect('douche_view', $redirect_to); } else { $this->redirect('errors/noUsers'); } }