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() { $tags = preg_replace('/(\\s)+/', ',', trim(Yii::app()->request->getParam('tag'))); $tag_ids = array(); if ($tags) { $arr_tag = explode(',', $tags); foreach ($arr_tag as $tag) { $t = Tag::model()->find('tag_name = :tn', array(':tn' => $tag)); $t && ($tag_ids[] = $t->id); } } else { $alltags = Tag::model()->findAll(array('order' => 'data_count')); foreach ((array) $alltags as $tv) { $tag_ids[] = $tv->id; } } if (!$tag_ids) { throw new CHttpException(404, Yii::t('common', 'The requested page does not exist.')); } $datas = array(); $td = new TagData(); $criteria = new CDbCriteria(); $criteria->addColumnCondition(array('status' => 'Y')); $criteria->addInCondition('tag_id', $tag_ids); $criteria->group = 'content_id, type'; //分页 $count = $td->count($criteria); $pages = new CPagination($count); $pages->pageSize = 10; $criteria->limit = $pages->pageSize; $criteria->offset = $pages->currentPage * $pages->pageSize; $tddata = $td->findAll($criteria); if ($tddata) { foreach ($tddata as $value) { $modelType = ModelType::model()->findByPk($value->type); $model = $modelType->model; $value['type'] = $modelType->type_key; $value['data'] = $model::model()->findByPk($value->content_id); if ($value['data']) { $datas[] = $value; } } } //SEO $this->controller->_seoTitle = $tags ? $tags . ' - ' . $this->controller->_setting['site_name'] : '所有标签 - ' . $this->controller->_setting['site_name']; $navs[] = array('url' => Yii::app()->request->getUrl(), 'name' => $tags ? $tags : '所有标签'); $this->controller->render('index', array('navs' => $navs, 'datas' => $datas, 'pagebar' => $pages, 'tags' => $tags)); }
public function run() { $tags = preg_replace('/(\\s)+/', ',', trim(Yii::app()->request->getParam('tag'))); $tag_ids = array(); if ($tags) { $arr_tag = explode(',', $tags); foreach ($arr_tag as $tag) { $t = Tag::model()->find('tag_name = :tn', array(':tn' => $tag)); $t && ($tag_ids[] = $t->id); } } else { $alltags = Tag::model()->findAll(array('order' => 'data_count')); foreach ((array) $alltags as $tv) { $tag_ids[] = $tv->id; } } $ajax = Yii::app()->request->getParam('ajax'); $data = array(); $searchData = array(); if ($tag_ids && $ajax == 1) { $td = new TagData(); $condition = "status = 'Y'"; $criteria = new CDbCriteria(); $criteria->condition = $condition; $criteria->addInCondition('tag_id', $tag_ids); //分页 $count = $td->count($criteria); $pages = new CPagination($count); $pages->pageSize = 10; $criteria->limit = $pages->pageSize; $criteria->offset = $pages->currentPage * $pages->pageSize; $tddata = $td->findAll($criteria); foreach ((array) $tddata as $value) { $modelType = ModelType::model()->findByPk($value->type); $model = $modelType->model; $c = $model::model()->findByPk($value->content_id, array('select' => 'id,title')); if ($c) { $data[] = array('type' => $modelType->type_key, 'data' => $c); } } foreach ($data as $key => $new) { $searchData[$key]['url'] = $this->controller->createUrl("{$new['type']}/view", array('id' => $new['data']['id'])); $searchData[$key]['title'] = $new['data']['title']; } } exit(CJSON::encode($searchData)); }
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')); }
/** * ajax搜索 */ public function actionAjax() { $tags = trim($this->_request->getParam('tag')); $tags = preg_replace('/(\\s)+/', ',', trim($tags)); $arr_tag = explode(',', $tags); foreach ((array) $arr_tag as $tag) { $t = Tag::model()->find('tag_name = :tn', array(':tn' => $tag)); $t && ($tag_ids[] = $t->id); } $ajax = $this->_request->getParam('ajax'); $data = array(); $searchData = array(); if ($tag_ids && $ajax == 1) { $td = new TagData(); $condition = "status = 'Y'"; $criteria = new CDbCriteria(); $criteria->condition = $condition; $criteria->addInCondition('tag_id', $tag_ids); //分页 $count = $td->count($criteria); $pages = new CPagination($count); $pages->pageSize = 10; $criteria->limit = $pages->pageSize; $criteria->offset = $pages->currentPage * $pages->pageSize; $tddata = $td->findAll($criteria); foreach ((array) $tddata as $value) { $modelType = ModelType::model()->findByPk($value->type); $model = $modelType->model; $value['type'] = $modelType->type_key; $value['data'] = $model::model()->findByPk($value->content_id, '', array('select' => 'id,title')); $data[] = $value; } foreach ($data as $key => $new) { $searchData[$key]['url'] = $this->createUrl("{$new->type}/view", array('id' => $new->data->id)); $searchData[$key]['title'] = $new->data->title; } } exit(CJSON::encode($searchData)); }
/** * * 插入或者更新内容时,同时更新标签数据 * @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; }
<?php require '../../boot.php'; list($cmd, $supporter_KEY) = $argv; $result = $DIA->get('supporter', $supporter_KEY); $s = new Supporter($result); $s->db_upsert(); $model_array = array('SupporterAction', 'Email', 'Donation', 'ContactHistory', 'SupporterEvent', 'SupporterCompany', 'SupporterShare'); foreach ($model_array as $model) { $table = $model::$table_name; $results = $DIA->get($table, array('condition' => array('supporter_KEY=' . $supporter_KEY))); foreach ($results as $result) { $instance = new $model($result); $instance->db_upsert(); } } $db->query('DELETE FROM `tag_data` WHERE database_table_KEY=142 AND `table_key`=' . $supporter_KEY); $results = $DIA->get('tag_data', array('condition' => array('database_table_KEY=142', 'table_key=' . $supporter_KEY))); foreach ($results as $result) { print_r($result); $instance = new TagData($result); $instance->db_insert(); } $db->query('DELETE FROM `supporter_groups` WHERE `supporter_KEY`=' . $supporter_KEY); $results = $DIA->get('supporter_groups', array('condition' => array('supporter_KEY=' . $supporter_KEY))); foreach ($results as $result) { $instance = new SupporterGroups($result); $instance->db_insert(); }