/** * Добавляет модель с именем ml_id связанную с a_id и * добавляет количество изделий count */ public function addModel($a_id, $model, $count) { //echo "<br> Это addModel model=$model"; $modl = new ModelsList($this->connDB); //echo "<br>ml_id=". $ml_id = $modl->getId($model); // echo "Пробуем вставить модель с ml_id=$ml_id и a_id = $a_id"; // echo "<br>". $query = "INSERT INTO `ns_models`(`a_id`,`ml_id`) \n VALUES ('{$a_id}','{$ml_id}')"; if (mysql_query($query, $this->connDB)) { $m_id = mysql_insert_id(); //вставим количество моделей $c = new Counts($this->connDB); if (!$c->addCount($a_id, $m_id, $count)) { //echo "Количество моделей не добавлено!"; exit; } //echo "модель и количество добавлены"; return true; } else { echo mysql_error(); return false; } }
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); }
public function deleteAction($id) { $id = $this->filter->sanitize($id, array("int")); $counts = Counts::findFirst('id="' . $id . '"'); if (!$counts) { $this->flash->error("counts was not found"); return $this->dispatcher->forward(array("controller" => "counts", "action" => "index")); } if (!$counts->delete()) { foreach ($counts->getMessages() as $message) { $this->flash->error((string) $message); } return $this->dispatcher->forward(array("controller" => "counts", "action" => "search")); } else { $this->flash->success("counts was deleted"); return $this->dispatcher->forward(array("controller" => "counts", "action" => "index")); } }