示例#1
0
文件: Tag.php 项目: kzfk/emlauncher
 public static function insertNewTag($app_id, $name, PDO $con = null)
 {
     $row = array('app_id' => $app_id, 'name' => $name);
     $tag = new Tag($row);
     $tag->insert($con);
     return $tag;
 }
示例#2
0
 public function setTagsArray(array $data)
 {
     // reset dei tag per semplificare lo script
     ProductTag::model()->deleteAll('product=:p', array(':p' => $this->id));
     // data attuale
     $now = new DateTime();
     $timestamp = $now->format('Y-m-d H-i-s');
     // ricerca dei tag e creazione dei link
     foreach ($data as $tagName) {
         $tag = Tag::model()->find('name=:nm', array(':nm' => $tagName));
         /** @var Tag $tag */
         if ($tag == null) {
             $tag = new Tag();
             $tag->name = $tagName;
             $tag->description = ucwords($tagName);
             $tag->timestamp = $timestamp;
             $tag->insert();
         }
         $productTag = ProductTag::model()->find('product=:p AND tag=:t', array(':p' => $this->id, ':t' => $tag->id));
         /** @var ProductTag $productTag */
         if ($productTag == null) {
             $productTag = new ProductTag();
             $productTag->product = $this->id;
             $productTag->tag = $tag->id;
             $productTag->insert();
         }
     }
 }
示例#3
0
 public function create()
 {
     if (isset($_POST["tag"])) {
         $tag = new Tag();
         $tag->setTag($_POST["tag"]);
         $result_e = $tag->insert();
     }
     $this->redirect("Tags", "index");
 }
示例#4
0
 public static function get_tag_id($tag)
 {
     $sql = sprintf("SELECT tag_id FROM tag WHERE tag='%s'", $tag);
     $tag_id = db()->Get_Cell($sql);
     if (!$tag_id) {
         $new_tag = new Tag();
         $new_tag->tag($tag);
         $tag_id = $new_tag->insert();
     }
     return $tag_id;
 }
示例#5
0
文件: model.php 项目: bephp/blog
 function updateTag($tags)
 {
     $tags = array_map(function ($t) {
         return trim($t);
     }, explode(',', $tags));
     $tags = array_filter($tags, function ($t) {
         return strlen($t) > 0;
     });
     foreach ($this->tags as $i => $tag) {
         $key = array_search($tag->tag->name, $tags);
         if (false === $key) {
             $tag->tag->count = $tag->tag->count - 1;
             if ($tag->tag->count > 0) {
                 $tag->tag->update();
             } else {
                 $tag->tag->delete();
             }
             $tag->delete();
         } else {
             unset($tags[$key]);
         }
         //do not change tag
     }
     foreach ($tags as $i => $t) {
         $tag = new Tag();
         $post2tag = new Post2Tag();
         $tag->reset()->eq('name', $t)->find();
         if (!$tag->id) {
             $tag->name = $t;
             $tag->count = 1;
             $tag->insert();
         } else {
             $tag->count = $tag->count + 1;
             $tag->update();
         }
         $post2tag->tag_id = $tag->id;
         $post2tag->post_id = $this->id;
         $post2tag->insert();
     }
     return $this;
 }
示例#6
0
 public function insertTags($item, $tagString)
 {
     Zend_Registry::get('logger')->entering();
     $tags = Tag::parseTags($tagString);
     foreach ($tags as $tagName) {
         Zend_Registry::get('logger')->debug("Got tagname: '{$tagName}'");
         // Find or create new tag
         $tags = new Tag();
         $where = $this->_db->quoteInto('name = ?', $tagName);
         $tag = $tags->fetchRow($where);
         Zend_Registry::get('logger')->debug("Got tag: '{$tag->id}', '{$tag->name}'");
         if ($tag->id) {
             $tagId = $tag->id;
         } else {
             $row = array('name' => $tagName);
             $tagId = $tags->insert($row);
         }
         // Create association
         $this->_db->insert('tags_items', array('item_id' => $item->id, 'tag_id' => $tagId));
     }
     Zend_Registry::get('logger')->exiting();
 }
示例#7
0
文件: tag.php 项目: anupom/my-blog
 /**
  * Create a tag and save it.
  *
  * @param array $paramarray An associative array of tag fields
  * @return Tag The new Tag object
  **/
 static function create($paramarray)
 {
     $tag = new Tag($paramarray);
     $tag->insert();
     return $tag;
 }
示例#8
0
 public function saveTags($tags)
 {
     foreach ($tags as $tag) {
         Tag::insert(array('tag' => $tag));
     }
     return true;
 }
 /**
  * Adds tags to a tagged object.
  * 
  * @param 	array 		$tags 		array holding tag names
  * @param 	Tagged 		$object 	object that should be tagged
  */
 public function addTags($tags, Tagged $object, $languageID = 0)
 {
     $tagIDs = array();
     foreach ($tags as $tag) {
         if (empty($tag)) {
             continue;
         }
         $tagID = Tag::test($tag, $languageID);
         if (!$tagID) {
             $tagID = Tag::insert($tag, $languageID);
         }
         $tagIDs[] = $tagID;
     }
     $tagIDs = array_unique($tagIDs);
     $sql = "INSERT INTO\twcf" . WCF_N . "_tag_to_object\n\t\t\t\t\t(objectID, tagID, taggableID, time, languageID)\n\t\t\tVALUES ";
     foreach ($tagIDs as $tagID) {
         $sql .= "(" . $object->getObjectID() . ", " . $tagID . ", " . $object->getTaggable()->getTaggableID() . ", " . TIME_NOW . ", " . $languageID . "),";
     }
     $sql = StringUtil::substring($sql, 0, StringUtil::length($sql) - 1);
     $result = WCF::getDB()->sendQuery($sql);
 }