public function run() { $tags = Tag::model()->findAll(); if ($tags) { foreach ($tags as $tag) { $post = Post::model()->findAll("FIND_IN_SET(:tag, tags)", array(':tag' => $tag->tag_name)); $image = Image::model()->findAll("FIND_IN_SET(:tag, tags)", array(':tag' => $tag->tag_name)); $soft = Soft::model()->findAll("FIND_IN_SET(:tag, seo_keywords)", array(':tag' => $tag->tag_name)); $video = Video::model()->findAll("FIND_IN_SET(:tag, seo_keywords)", array(':tag' => $tag->tag_name)); if (!$post && !$image && !$soft && !$video) { $tag->delete(); } else { $tag->data_count = count($post) + count($image) + count($soft); $tag->save(); } } } $tagdatas = TagData::model()->findAll(); if ($tagdatas) { foreach ($tagdatas as $value) { $modelType = ModelType::model()->findByPk($value->type); $model = $modelType->model; $data = $model::model()->findByPk($value->content_id); if (!$data) { $value->delete(); } } } $this->controller->message('success', Yii::t('admin', 'Reset Tags Success'), $this->controller->createUrl('index')); }
public function run() { $ids = Yii::app()->request->getParam('id'); $command = Yii::app()->request->getParam('command'); empty($ids) && $this->controller->message('error', Yii::t('admin', 'No Select')); if (!is_array($ids)) { $ids = array($ids); } $criteria = new CDbCriteria(); $criteria->addInCondition('id', $ids); switch ($command) { case 'delete': //删除 Post::model()->deleteAll($criteria); foreach ((array) $ids as $id) { //删除关联的标签 TagData::model()->deleteAll('content_id =:id AND type =:type', array(':id' => $id, ':type' => $this->controller->_type_ids['post'])); } break; case 'show': //显示 Post::model()->updateAll(['status' => 'Y'], $criteria); foreach ((array) $ids as $id) { //更新关联的标签 $tagData = TagData::model()->updateAll(array('status' => 'Y'), 'content_id =:id AND type =:type', array(':id' => $id, ':type' => $this->controller->_type_ids['post'])); } break; case 'hidden': //文章隐藏 Post::model()->updateAll(['status' => 'N'], $criteria); foreach ((array) $ids as $id) { //更新关联的标签 $tagData = TagData::model()->updateAll(array('status' => 'N'), 'content_id =:id AND type =:type', array(':id' => $id, ':type' => $this->controller->_type_ids['post'])); } break; case 'commend': //文章推荐 $content_id = implode(',', $ids); $type_key = 'post'; $this->controller->redirect($this->controller->createUrl('recommend/create', array('content_id' => $content_id, 'type_key' => $type_key))); break; case 'stick': //文章置顶 Post::model()->updateAll(['top_line' => 'Y'], $criteria); break; case 'cancelStick': //文章取消置顶 Post::model()->updateAll(['top_line' => 'N'], $criteria); break; default: $this->controller->message('error', Yii::t('admin', 'Error Operation')); } $this->controller->message('success', Yii::t('admin', 'Batch Operate Success')); }
/** * * tag * */ private function tagSitemap() { $criteria = new CDbCriteria(); $criteria->condition = "status = 'Y'"; $criteria->select = 'tag_id, count(tag_id) as count_tag'; $criteria->group = 'tag_id'; $criteria->order = 'count_tag DESC'; $model = TagData::model()->findAll($criteria); foreach ($model as $k => $v) { $tag_id = $v->tag_id; $tag = Tag::model()->findByPk($tag_id); $this->tagItems[] = array('url' => $this->createUrl('tag/index', array('tag_name' => $tag->tag_name)), 'date' => date(DATE_W3C, time())); } $this->tagItems[] = array('url' => $this->createUrl('tag/all'), 'date' => date(DATE_W3C, time())); }
public function run() { $ids = Yii::app()->request->getParam('id'); $command = Yii::app()->request->getParam('command'); empty($ids) && $this->controller->message('error', Yii::t('admin', 'No Select')); if (!is_array($ids)) { $ids = array($ids); } $criteria = new CDbCriteria(); $criteria->addInCondition('id', $ids); switch ($command) { case 'delete': //删除 Tag::model()->deleteAll($criteria); //删除内容相关标签数据 $criteria_c = new CDbCriteria(); $criteria_c->addInCondition('tag_id', $ids); TagData::model()->deleteAll($criteria_c); break; default: $this->controller->message('error', Yii::t('admin', 'Error Operation')); } $this->controller->message('success', Yii::t('admin', 'Batch Operate Success')); }
/** * 批量操作 * */ public function actionBatch() { if ($this->method() == 'GET') { $command = trim($_GET['command']); $ids = intval($_GET['id']); } elseif ($this->method() == 'POST') { $command = trim($_POST['command']); $ids = $_POST['id']; } else { $this->message('errorBack', Yii::t('admin', 'Only POST Or GET')); } empty($ids) && $this->message('error', Yii::t('admin', 'No Select')); switch ($command) { case 'delete': //删除文章 foreach ((array) $ids as $id) { $postModel = Post::model()->findByPk($id); if ($postModel) { $image_list = $postModel->image_list; $image_list && ($image_list = unserialize($image_list)); if ($image_list) { foreach ($image_list as $image) { Uploader::deleteFile($image['file']); $file = Upload::model()->findByPk($image['fileId']); if ($file) { $file->delete(); } } } Uploader::deleteFile($postModel->attach_file); Uploader::deleteFile($postModel->attach_thumb); $postModel->delete(); //删除关联的标签 TagData::model()->deleteAll('content_id =:id AND type =:type', array(':id' => $id, ':type' => $this->_type_ids['post'])); } } break; case 'show': //文章显示 foreach ((array) $ids as $id) { $postModel = Post::model()->findByPk($id); if ($postModel) { $postModel->status = 'Y'; $postModel->save(); //更新关联的标签 $tagData = TagData::model()->updateAll(array('status' => 'Y'), 'content_id =:id AND type =:type', array(':id' => $id, ':type' => $this->_type_ids['post'])); } } break; case 'hidden': //文章隐藏 foreach ((array) $ids as $id) { $postModel = Post::model()->findByPk($id); if ($postModel) { $postModel->status = 'N'; $postModel->save(); //更新关联的标签 $tagData = TagData::model()->updateAll(array('status' => 'N'), 'content_id =:id AND type =:type', array(':id' => $id, ':type' => $this->_type_ids['post'])); } } break; case 'commend': //文章推荐 foreach ((array) $ids as $id) { $recom_id = intval($_POST['recom_id']); if ($recom_id) { $postModel = Post::model()->findByPk($id); if ($postModel) { $postModel->commend = 'Y'; $postModel->save(); $recom_post = new RecommendPost(); $recom_post->id = $recom_id; $recom_post->post_id = $id; $recom_post->save(); } } else { $this->message('error', Yii::t('admin', 'RecommendPosition is Required')); } } break; case 'stick': //文章置顶 foreach ((array) $ids as $id) { $postModel = Post::model()->findByPk($id); if ($postModel) { $postModel->top_line = 'Y'; $postModel->save(); } } break; case 'cancelStick': //文章取消置顶 foreach ((array) $ids as $id) { $postModel = Post::model()->findByPk($id); if ($postModel) { $postModel->top_line = 'N'; $postModel->save(); } } break; default: throw new CHttpException(404, Yii::t('admin', 'Error Operation')); break; } $this->message('success', Yii::t('admin', 'Batch Operate Success')); }
/** * * 插入或者更新内容时,同时更新标签数据 * @author Sim <*****@*****.**> * @param $tagdata tag数据 * @param $param [content_id]关联内容id [status]关联内容状态 [type_id](1-5) * **/ public static function updateTagData($tagdata = array(), $param = array()) { foreach ((array) $tagdata as $value) { if ($value) { $model_tag = new Tag(); $get_tags = $model_tag->find('tag_name=:tagname', array(':tagname' => $value)); if ($get_tags) { $tag_id = $get_tags->id; } else { $model_tag->data_count = 1; $model_tag->tag_name = $value; $model_tag->save(); $tag_id = $model_tag->id; } //添加关联表数据 $tagData = TagData::model()->findByPk(array('tag_id' => $tag_id, 'content_id' => $param['content_id'])); if (!$tagData) { $tagData = new TagData(); $tagData->tag_id = $tag_id; $tagData->content_id = $param['content_id']; $tagData->type = $param['type_id']; $tagData->status = $param['status']; $tagData->save(); } } } //更新关联的标签状态 $tagData = TagData::model()->updateAll(array('status' => $param['status']), 'content_id =:id AND type =:type', array(':id' => $param['content_id'], ':type' => $param['type_id'])); return true; }