public function insert($dados) { $obj = new TagModel(); $obj->Nome = addslashes($dados['nome']); $obj->Seo = trim($dados['seo']) == "" ? DefaultHelper::gerarLinkSeo($dados['nome']) : $dados['seo']; return $obj->insert(); }
/** * 添加标签 * @method POST_indexAction * @param integer $id [description] * @author NewFuture */ public function POST_indexAction() { $uid = $this->auth(); if (Input::post('name', $name, 'tag')) { $tag = ['name' => $name, 'use_id' => $uid]; if ($tid = TagModel::insert($tag)) { $result = ['msg' => '添加成功', 'id' => $tid]; $this->response(1, $result); } else { $this->response(0, '添加失败'); } } else { $this->response(0, '标签名不合法'); } }
/** * Insert new image into database. * * @param $sha1 * @param $fileSize * @param $imageDescription * @param $tag * @param $location * @return Image */ public function insert($sha1, $fileSize, $imageDescription, $tag, $location) { $image = new Image(); $image->setHash($sha1); $image->setFileSize($fileSize); $image->setDescription($imageDescription); $dateCreated = gmdate("Y-m-d H:i:s"); $image->setDateCreated($dateCreated); $query = $this->db->prepare("\n INSERT INTO images (description, file_size, sha1_hash, date_created, tag_id, location_id)\n VALUES(:description, :file_size, :sha1_hash, :date_created, :tag_id, :location_id)\n "); $query->bindValue(":description", $imageDescription); $query->bindValue(":file_size", $fileSize); $query->bindValue(":sha1_hash", $sha1); $query->bindValue(":date_created", $dateCreated); if ($tag != null) { $tagModel = new TagModel($this->db); $myTag = $tagModel->getTagByValue($tag->getValue()); if ($myTag == null) { $myTag = $tagModel->insert($tag->getValue()); } $query->bindValue(":tag_id", $myTag->getId()); $image->setTag($myTag); } else { $query->bindValue(":tag_id", 0); } if ($location != null) { $locationModel = new LocationModel($this->db); $myLocation = $locationModel->getLocationByValue($location->getLat(), $location->getLon()); if ($myLocation == null) { $myLocation = $locationModel->insert($location->getLat(), $location->getLon()); } $query->bindValue(":location_id", $myLocation->getId()); $image->setLocation($myLocation); } else { $query->bindValue(":location_id", 0); } $query->execute(); $image->setId($this->db->lastInsertId()); return $image; }