public function searchAction() { $numberPage = 1; if ($this->request->isPost()) { $query = \Phalcon\Mvc\Model\Criteria::fromInput($this->di, "Counts", $_POST); $this->session->conditions = $query->getConditions(); } else { $numberPage = $this->request->getQuery("page", "int"); if ($numberPage <= 0) { $numberPage = 1; } } $parameters = array(); if ($this->session->conditions) { $parameters["conditions"] = $this->session->conditions; } $parameters["order"] = "id"; $counts = Counts::find($parameters); if (count($counts) == 0) { $this->flash->notice("The search did not find any counts"); return $this->dispatcher->forward(array("controller" => "counts", "action" => "index")); } $paginator = new \Phalcon\Paginator\Adapter\Model(array("data" => $counts, "limit" => 10, "page" => $numberPage)); $page = $paginator->getPaginate(); $this->view->setVar("page", $page); }
public function redirectAction() { $slug = $this->dispatcher->getParam("slug"); $link = Links::findFirst('token="' . $slug . '"'); //$check = Counts::findFirst('visitor_ip' => $this->getUserIP(), 'links_id' => $link->id)); $check = Counts::findFirst(array('visitor_ip=:visitor_ip: AND links_id=:links_id:', 'bind' => array('visitor_ip' => $this->getUserIP(), 'links_id' => $link->id))); if (!$check) { $counts = new Counts(); $counts->links_id = $link->id; $counts->value = 1; $counts->visit_date = date("Y-m-d H:i:s"); $counts->visitor_ip = $this->getUserIP(); $counts->save(); unset($counts); $counts_total = count(Counts::find(array("links_id" => $link->id))); } $link->visitor_count = $counts_total; $link->save(); $this->view->linkurl = $link->longurl; $response = new \Phalcon\Http\Response(); return $response->redirect($link->longurl, true); }