/** * 编辑帖子阅读页话题 * * @return void */ public function editReadTagAction(){ // 是否登录 if ($this->loginUser->uid < 1) { $this->showError('USER:user.not.login'); } list($tid,$tagnames) = $this->getInput(array('tid','tagnames')); $tagnames = $tagnames ? $tagnames : array(); // 是否有权限 if ($this->_checkAllowEdit($tid) !== true) { $this->showError('TAG:right.tag_allow_edit.error'); } $count = count($tagnames); $count > 5 && $this->showError("Tag:tagnum.exceed"); Wind::import('SRV:tag.dm.PwTagDm'); if ($count == 1) { $dm = new PwTagDm(); $dm->setName($tagnames['0']); if(($result = $dm->beforeUpdate()) instanceof PwError) { $this->showError($result->getError()); } } // 敏感词 $content = implode(' ', $tagnames); $wordFilter = Wekit::load('SRV:word.srv.PwWordFilter'); list($type, $words) = $wordFilter->filterWord($content); if ($type) { $this->showError("WORD:content.error"); } $typeId = $this->_getTagService()->getTypeIdByTypeName($this->defaultType); $dmArray = array(); foreach ((array)$tagnames as $value) { $value = trim($value); if(Pw::strlen($value) > 15) { continue; } $dm = new PwTagDm(); if (($result = $dm->checkTagName($value)) instanceof PwError) { $this->showError($result->getError()); } $dmArray[$value] = $dm->setName($value) ->setTypeId($typeId) ->setParamId($tid) ->setIfHot(1) ->setCreatedTime(Pw::getTime()) ->setCreateUid($this->loginUser->uid) ; } $result = $this->_getTagService()->updateTags($typeId,$tid,$dmArray); if ($result instanceof PwError) { $this->showError($result->getError()); } $this->showMessage('success'); }
/** * 添加关联话题 * * @param int $tagId 关联到哪个话题Id * @param string $tagName 话题名称 */ private function _addRelateTag($tagId, $tagName) { $tagId = intval($tagId); if ($tagId < 1 || !$tagName) { return false; } $tag = $this->_getTagDs()->getTag($tagId); if (!$tag) { return false; } $relateTag = $this->_getTagDs()->getTagByName($tagName); if (!$relateTag) { $dm = new PwTagDm(); $dm->setName($tagName)->setCreateUid($this->loginUser->uid)->setParent($tagId); $this->_getTagDs()->addTag($dm); } else { if ($relateTag['tag_id'] == $tagId) { return false; } //检查被关联的话题是否存在子话题 if ($this->_getTagDs()->getTagByParent($relateTag['tag_id'])) { return false; } $dm = new PwTagDm($relateTag['tag_id']); $dm->setParent($tagId); $this->_getTagDs()->updateTag($dm); } return true; }