public function testCookieMapper() { $mapper = new Application_Model_CookieMapper(); $cookie = new Application_Model_Cookie(); $cookie->setNick("testNick"); $cookie->setEmail("*****@*****.**"); $cookie->setDisplayMode(1); $cookie->setSaveName('testNickSave'); $cookie->setPassword('testNickPass'); $cookie->setTwitter('testNickTwit'); $cookie->setFacebook('testNickFace'); $cookie->setCCEmail('1'); $mapper->save($cookie); $id = $cookie->getId(); if (strlen($id) != 60) { $this->fail("Saving Cookie didn't create ID properly"); } $cookie = null; $cookie = $mapper->find($id); if ($cookie == null) { $this->fail("Can't retrieve saved cookie"); } if ($cookie->getId() != $id) { $this->fail("Saved Cookie Not Found"); } $cookie = null; $cookie = $mapper->findFromPartial(substr($id, 0, 30)); if ($cookie == null) { $this->fail("Can't retrieve saved cookie from partial"); } if ($cookie->getId() != $id) { $this->fail("Saved Cookie Not Found From Partial"); } $cookie = null; $cookie = $mapper->findFromPassword("*****@*****.**", "testNickPass"); if ($cookie == null) { $this->fail("Can't retrieve saved cookie from password"); } if ($cookie->getNick() != "testNick") { $this->fail("Saved Cookie Not Found From password"); } $mapper->delete($cookie); $cookie = null; $cookie = $mapper->find($id); if ($cookie != null) { $this->fail("Failed to delete cookie with id '{$id}'"); } }
public function userAction() { /**************************************************************** * List everything by a user. Either passed a message or * a half-a-cookie. Certainly want to paginate this. */ $page = $this->getRequest()->getParam('page'); if (!$page) { $page = 0; } $cookie = Application_Model_DbTable_Cookie::getUserCookie(); $cookieMapper = new Application_Model_CookieMapper(); $mapper = new Application_Model_CommentMapper(); //Need to grab a cookie and nick. We can do this two ways, if ($this->getRequest()->getParam('id')) { //One: Passed a partial cookie and nickname directly: $partialCookie = addslashes($this->getRequest()->getParam("id")); $viewUserCookie = $cookieMapper->findFromPartial($partialCookie); $nick = addslashes($this->getRequest()->getParam("nick")); } else { if ($this->getRequest()->getParam('mid')) { //Two: Passed a message and told "The guy who wrote this" $messageId = $this->getRequest()->getParam('mid'); $message = $mapper->find($messageId); if ($message == null) { throw new Exception("Can't find that message"); } $viewUserCookie = $message->getCookieObject(); $nick = $message->getNick(); if ($this->getRequest()->getParam("nick")) { $nick = addslashes($this->getRequest()->getParam("nick")); } if ($nick == "-1") { $nick = null; } } else { throw new Exception("User not specified"); } } //All the nicks this user ever used! $this->view->userNicks = $viewUserCookie->getAllNicks(); //All the comments they ever posted! if ($viewUserCookie->getEmail()) { $orEmail = " or email='" . $viewUserCookie->getEmail() . "'"; } else { $orEmail = ""; } if ($nick != null) { $andNick = " and nick='" . $nick . "'"; } $rows = $mapper->findWhere("(cookie='" . $viewUserCookie->getId() . "' " . $orEmail . ")" . $andNick, 50, $page * 50); $this->view->comments = array(); foreach ($rows as $r) { $viewUserFullCookieId = $r->cookie; if ($messageId == null) { $messageId = $r->id; } $this->view->comments[] = $mapper->convertRowToArray($r, $cookie); } $this->view->askedNick = $nick; $this->view->userDetails = $viewUserCookie; $this->view->mid = $messageId; $this->view->title = "Messages from {$nick}"; $this->view->page = $page; }