public function createAction()
 {
     if (!$this->request->isPost()) {
         return $this->dispatcher->forward(array("controller" => "counts", "action" => "index"));
     }
     $counts = new Counts();
     $counts->id = $this->request->getPost("id");
     $counts->links_id = $this->request->getPost("links_id");
     $counts->value = $this->request->getPost("value");
     $counts->visit_date = $this->request->getPost("visit_date");
     $counts->visitor_ip = $this->request->getPost("visitor_ip");
     if (!$counts->save()) {
         foreach ($counts->getMessages() as $message) {
             $this->flash->error((string) $message);
         }
         return $this->dispatcher->forward(array("controller" => "counts", "action" => "new"));
     } else {
         $this->flash->success("counts was created successfully");
         return $this->dispatcher->forward(array("controller" => "counts", "action" => "index"));
     }
 }
 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);
 }