示例#1
0
 /**
  * 检查传入的标签是否已存在,不存在则创建,并检查是否已存在对应关系,不存在则创建
  * @param type $id
  * @param type $crumb
  */
 public function checkAndWriteTag($id, $crumb, $tagid = 0)
 {
     if (!$tagid) {
         $_crumb = strip_tags(trim($crumb));
         $_taginfo = Tags::model()->find('title=:title', array(':title' => $_crumb));
         if (!$_taginfo) {
             $_tagdata = array('title' => $_crumb, 'name' => zmf::pinyin($_crumb), 'classify' => 'posts', 'cTime' => time(), 'status' => 1);
             $model_tag = new Tags();
             $model_tag->attributes = $_tagdata;
             $_tagid = $model_tag->save(false);
         } else {
             $_tagid = $_taginfo['id'];
         }
     } else {
         $_tagid = $tagid;
     }
     $_tagrel = array('logid' => $id, 'tagid' => $_tagid, 'classify' => 'posts');
     $reinfo = TagRelation::model()->find('logid=:logid AND tagid=:tagid AND classify="posts"', array(':logid' => $id, ':tagid' => $_tagid));
     if (!$reinfo) {
         $model_tagrel = new TagRelation();
         $model_tagrel->attributes = $_tagrel;
         $model_tagrel->save(false);
     }
 }
示例#2
0
文件: Tags.php 项目: ph7pal/momo
 public static function addRelation($tagid, $logid, $classify)
 {
     if (!$tagid || !$logid || !$classify) {
         return false;
     }
     $_info = TagRelation::model()->find('tagid=:tagid AND logid=:logid AND classify=:classify', array(':tagid' => $tagid, ':logid' => $logid, ':classify' => $classify));
     if (!$_info) {
         $_tagre = array('tagid' => $tagid, 'logid' => $logid, 'classify' => $classify, 'cTime' => zmf::now());
         $modelC = new TagRelation();
         $modelC->attributes = $_tagre;
         return $modelC->save();
     }
     return true;
 }