public function killCollect() { $articleId = $_GET['articleId']; $collect = new CollectModel(); $row = $collect->deleteCollect($articleId, $_SESSION['qq']['userId']); if ($row) { echo json_encode($row); } else { exit('删除收藏失败'); } }
public function index() { //header('content-type:text/html;charset=utf-8'); $userId = $_SESSION['qq']['userId']; $collect = new CollectModel(); //查询收藏 $user_collect = $collect->getCollectByuserId($userId); $article = new ArticleModel(); $arr = array(); foreach ($user_collect as $v) { //根据收藏的文章id查询文章 $a = $article->getArticleById($v['articleId']); //取出admin的昵称 $a['adminName'] = $this->getAdmin($a['adminId']); $arr[] = $a; } $comment = new CommentModel(); $commentAlbum = $comment->getCommentByAlbum($userId); $album = new AlbumModel(); $articles = array(); $albums = array(); foreach ($commentAlbum as $v) { if ($v['albumId'] != null) { $c = $album->getAlbumById($v['albumId']); $c['adminName'] = $this->getAdmin($v['adminId']); $albums[] = $c; } } $commentArticle = $comment->getCommentByArticle($userId); foreach ($commentArticle as $v) { if ($v['articleId'] != null) { $a = $article->getArticleById($v['articleId']); $a['adminName'] = $this->getAdmin($v['adminId']); $articles[] = $a; } } var_dump($albums); $this->assign('user', $_SESSION['qq']['userName']); //评论过的相册 $this->assign('albums', $albums); //评论过的文章 $this->assign('articles', $articles); //收藏 $this->assign('user_collect', $arr); $this->display(); }
public function actionCreate() { if ($_SERVER['REQUEST_METHOD'] == 'POST') { if (!isset($_POST['Model']) || !is_array($_POST['Model'])) { $this->redirect[] = array('text' => '', 'href' => 'javascript:history.go(-1);'); $this->message('保存采集模型信息错误', self::MSG_ERROR, true); } if ($_POST['Model']['collect_model_name'] == '') { $this->redirect[] = array('text' => '', 'href' => 'javascript:history.go(-1);'); $this->message('采集模型名称不能为空', self::MSG_ERROR, true); } if ($_POST['Model']['collect_model_identify'] == '') { $this->redirect[] = array('text' => '', 'href' => 'javascript:history.go(-1);'); $this->message('采集模型标识不能为空', self::MSG_ERROR, true); } if (preg_match("/^[0-9]+.*/", $_POST['Fields']['collect_model_identify'])) { $this->redirect[] = array('text' => '', 'href' => 'javascript:history.go(-1);'); $this->message('采集模型标识不能以数字开头', self::MSG_ERROR, true); } $old_collect_model_identify = CollectModel::get_model_identify_by_id($id); $sql = "SELECT `collect_model_identify` FROM `collect_model` WHERE collect_model_identify=:collect_model_identify AND `collect_model_status`!=:collect_model_status"; $cmd = $this->db->createCommand($sql); $cmd->execute(array(':collect_model_identify' => $_POST['Model']['collect_model_identify'], ":collect_model_status" => CollectModel::STAT_STATUS_DELETED)); if ($cmd->queryScalar()) { $this->redirect[] = array('text' => '', 'href' => 'javascript:history.go(-1);'); $this->message('采集模型标识不能重复', self::MSG_ERROR, true); } $flag = $this->db->createCommand()->insert('{{collect_model}}', array('collect_model_id' => 0, 'collect_model_name' => $_POST['Model']['collect_model_name'], 'collect_model_identify' => $_POST['Model']['collect_model_identify'], 'collect_model_status' => CollectModel::STAT_STATUS_NORMAL, 'collect_model_rank' => $_POST['Model']['collect_model_rank'], 'collect_model_lasttime' => $_SERVER['REQUEST_TIME'], 'collect_model_dateline' => $_SERVER['REQUEST_TIME'], 'content_model_id' => $_POST['Model']['content_model_id'])); if ($flag) { $collect_model_id = $this->db->getLastInsertID(); $collect_model_name = $_POST['Model']['collect_model_name']; $sql = "create table `collect_model_addons{$_POST['Model']['collect_model_identify']}` (\n\t\t\t\t\t\t`collect_content_id` int unsigned not null auto_increment,\n\t\t\t\t\t\t`collect_list_id` int unsigned not null comment '采集列表id',\n\t\t\t\t\t\t`collect_content_body` TEXT CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL comment '正文内容',\n\t\t\t\t\t\t`collect_content_day` date not null comment '采集时间',\n\t\t\t\t\t\tPRIMARY KEY (`collect_content_id`),\n\t\t\t\t\t\tUNIQUE KEY `collect_list_id` (`collect_list_id`)\n\t\t\t\t\t)ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='{$_POST['Model']['collect_model_name']}附加表';"; $this->db->createCommand($sql)->execute(); $this->db->createCommand()->insert('{{collect_fields}}', array('collect_fields_id' => 0, 'collect_model_id' => $collect_model_id, 'collect_fields_name' => '链接地址', 'collect_fields_identify' => 'collect_content_url', 'collect_fields_status' => CollectFields::STAT_STATUS_NORMAL, 'collect_fields_rank' => 255, 'collect_fields_type' => 1, 'collect_fields_belong' => 1, 'collect_fields_system' => 1, 'collect_fields_lasttime' => $_SERVER['REQUEST_TIME'], 'collect_fields_dateline' => $_SERVER['REQUEST_TIME'])); $this->db->createCommand()->insert('{{collect_fields}}', array('collect_fields_id' => 0, 'collect_model_id' => $collect_model_id, 'collect_fields_name' => '标题', 'collect_fields_identify' => 'collect_content_title', 'collect_fields_status' => CollectFields::STAT_STATUS_NORMAL, 'collect_fields_rank' => 255, 'collect_fields_type' => 1, 'collect_fields_belong' => 1, 'collect_fields_system' => 1, 'collect_fields_lasttime' => $_SERVER['REQUEST_TIME'], 'collect_fields_dateline' => $_SERVER['REQUEST_TIME'])); $this->db->createCommand()->insert('{{collect_fields}}', array('collect_fields_id' => 0, 'collect_model_id' => $collect_model_id, 'collect_fields_name' => '缩略图', 'collect_fields_identify' => 'collect_content_thumb', 'collect_fields_status' => CollectFields::STAT_STATUS_NORMAL, 'collect_fields_rank' => 255, 'collect_fields_type' => 1, 'collect_fields_belong' => 1, 'collect_fields_system' => 1, 'collect_fields_lasttime' => $_SERVER['REQUEST_TIME'], 'collect_fields_dateline' => $_SERVER['REQUEST_TIME'])); $this->db->createCommand()->insert('{{collect_fields}}', array('collect_fields_id' => 0, 'collect_model_id' => $collect_model_id, 'collect_fields_name' => '内容', 'collect_fields_identify' => 'collect_content_body', 'collect_fields_status' => CollectFields::STAT_STATUS_NORMAL, 'collect_fields_rank' => 255, 'collect_fields_type' => 2, 'collect_fields_belong' => 2, 'collect_fields_system' => 1, 'collect_fields_lasttime' => $_SERVER['REQUEST_TIME'], 'collect_fields_dateline' => $_SERVER['REQUEST_TIME'])); $this->db->createCommand()->insert('{{collect_fields}}', array('collect_fields_id' => 0, 'collect_model_id' => $collect_model_id, 'collect_fields_name' => '发布时间', 'collect_fields_identify' => 'collect_content_publish_time', 'collect_fields_status' => CollectFields::STAT_STATUS_NORMAL, 'collect_fields_rank' => 255, 'collect_fields_type' => 1, 'collect_fields_belong' => 3, 'collect_fields_system' => 1, 'collect_fields_lasttime' => $_SERVER['REQUEST_TIME'], 'collect_fields_dateline' => $_SERVER['REQUEST_TIME'])); //更新缓存 CollectModelModel::inst()->updateCache(); //记录操作日志 $message = '{user_name}添加采集来源{collect_model_name}'; $data = array('collect_model_name' => $collect_model_name, 'addons_data' => array('collect_model_id' => $collect_model_id)); UserLogsModel::inst()->add('Collect/Model', $collect_model_id, 'Insert', 'success', $message, $data); if (!isset($_GET['ajax'])) { $this->redirect[] = array('text' => '', 'href' => '/collect/model/index'); $this->message('添加采集模型完成', self::MSG_SUCCESS, true); } } else { //记录操作日志 $message = '{user_name}添加采集模型{$collect_model_name}失败'; $data = array('collect_model_name' => $collect_model_name, 'addons_data' => array('model' => $_POST['Model'])); UserLogsModel::inst()->add('Collect/Model', $collect_model_id, 'Insert', 'failure', $message, $data); $this->redirect[] = array('text' => '', 'href' => 'javascript:history.go(-1);'); $this->message('添加采集模型失败', self::MSG_ERROR, true); } } $model = array('collect_model_id' => 0, 'collect_model_name' => '', 'collect_model_identify' => '', 'content_model_id' => 0, 'collect_model_status' => CollectModelModel::STAT_STATUS_NORMAL, 'collect_model_rank' => 255, 'collect_model_lasttime' => $_SERVER['REQUEST_TIME'], 'collect_model_dateline' => $_SERVER['REQUEST_TIME']); $this->render('create', array('model' => $model, 'content_model' => CollectModelModel::inst()->getModelsByCache())); }
public function actionDelete($collect_model_id, $id) { $collect_fields_name = CollectModelField::get_fields_name_by_id($id); $collect_model_identify = CollectModel::get_model_identify_by_id($collect_model_id); $collect_fields = CollectModelField::get_fields_identify_by_id($collect_model_id, $id); $sql = "ALTER TABLE `collect_model_addons{$collect_model_identify}` DROP `" . $collect_fields['collect_fields_identify'] . "`"; Yii::app()->db->createCommand($sql)->execute(); Yii::app()->db->createCommand()->update('{{collect_model_fields}}', array('collect_fields_status' => CollectModelField::STAT_DELETED), 'collect_fields_id=:collect_fields_id', array(':collect_fields_id' => $id)); CollectModelField::update_cache(); //记录操作日志 $user = Yii::app()->user; $message = '{user_name}删除了采集字段{collect_fields_name}'; $data = array('user_id' => $user->id, 'user_name' => $user->name, 'collect_fields_name' => $collect_fields_name, 'data' => array('collect_fields_id' => $id)); AdminLogs::add($user->id, 'Collect/Fields', $id, 'Delete', 'success', $message, $data); if (!isset($_GET['ajax'])) { $this->redirect(array("Collect/Model/{$collect_model_id}/Fields/Index")); } }
public function getArticleById() { $errors = $this->errors; $articleId = $_GET['articleId']; //实例化Model $adminModel = new AdminModel(); //博主 $articleModel = new ArticleModel(); //文章 $articleTypeModel = new ArticleTypeModel(); //文章分类 $articleTagModel = new ArticleTagModel(); //文章标签 $commentModel = new CommentModel(); //评论 $collectModel = new CollectModel(); //文章收藏 //获取所有文章分类 $allTypes = $articleTypeModel->getCatrgoryByAdminId($_SESSION['admin']['adminId']); $allTypes = formatkey($allTypes, 'typeId'); //设置typeId主键 //获取所有文章标签 $allTags = $articleTagModel->getArticleTag(); $allTags = formatkey($allTags, 'tagId'); //设置typeId主键 $articleInfo = $articleModel->getArticleById($articleId); if ($articleInfo['tagId']) { $articleInfo['tagId'] = explode(',', trim($value['tagId'], ',')); } //查询评论数 $articleInfo['commentCount'] = $commentModel->getCommentCountByArticleId($articleId); //查询收藏数 $articleInfo['collectCount'] = $collectModel->getCollectCountByArticleId($articleId); //获取最新的评论 $comment = $commentModel->getComment($articleId, '0,2'); //博主信息 $adminInfo = $adminModel->getAdminById($_SESSION['admin']['adminId']); $this->assign("admin", $adminInfo); //文章 $this->assign("article", $articleInfo); //文章 $this->assign("allTags", $allTags); //所有文章标签 $this->assign("allTypes", $allTypes); //某人所有文章分类 $this->assign("comment", $comment); //某人所有文章分类 }