标签:
1 <?php 2 3 namespace Addons\Survey\Controller; 4 5 use Home\Controller\AddonsController; 6 7 class AnswerController extends AddonsController { //调研回复的方法控制器 8 var $model; //定义模型变量 9 var $survey_id; //调用的调研id 10 function _initialize() { //初始化 11 parent::_initialize(); //调用父级初始化方法 12 13 $this->model = $this->getModel ( ‘survey_answer‘ ); //获取模型数据 14 15 $param [‘survey_id‘] = $this->survey_id = intval ( $_REQUEST [‘survey_id‘] ); //获取调研的id 16 17 $res [‘title‘] = ‘微调研‘; //标题 18 $res [‘url‘] = addons_url ( ‘Survey://Survey/lists‘ ); //列表页功能选项url 19 $res [‘class‘] = ‘‘; 20 $nav [] = $res; //返回数组 21 22 $res [‘title‘] = ‘数据管理‘; //功能标题 23 $res [‘url‘] = addons_url ( ‘Survey://Answer/lists‘, $param ); //功能选项url 24 $res [‘class‘] = ‘current‘; //模版标签属性值 25 $nav [] = $res; //返回数组 26 27 $this->assign ( ‘nav‘, $nav ); //分配给前台显示 28 } 29 // 通用插件的列表模型 30 public function lists() { //列表方法 31 $this->assign ( ‘add_button‘, false ); //设置按钮不显示 32 $this->assign ( ‘search_button‘, false ); //定义按钮不显示 33 $this->assign ( ‘del_button‘, false ); //定义按钮不显示 34 $this->assign ( ‘check_all‘, false ); //定义按钮不显示 35 36 // 解析列表规则 37 $data = $this->_list_grid ( $this->model ); //从model中获取模型规则 38 $this->assign ( $data ); //分配给模型显示 39 40 // 搜索条件 41 $map = $this->_search_map ( $this->model, $data [‘fields‘] ); 42 43 $name = parse_name ( get_table_name ( $this->model [‘id‘] ), true ); //获得调研id对应的表名 44 $list = M ( $name )->where ( $map )->order ( ‘id DESC‘ )->group ( ‘uid‘ )->selectPage (); //查询数据 45 foreach ( $list [‘list_data‘] as &$vo ) { //遍历数据数组 46 $member = get_memberinfo ( $vo [‘uid‘] ); //设置$member等于从member表查到的用户信息 47 if (empty ( $member )) { //若上面查到的信息为空 48 $member = get_followinfo ( $vo [‘uid‘] ); //$member等于从follow表查到的用户信息 49 } 50 $vo [‘truename‘] = $member [‘truename‘]; //组装数组中的truename值 51 $vo [‘mobile‘] = $member [‘mobile‘]; //组装数组中的mobile值 52 } 53 54 $this->assign ( $list ); //把数据分配给模版 55 56 $this->display (); //调用模板显示 57 } 58 function detail() { //回答内容管理 59 $this->assign ( ‘add_button‘, false ); //按钮不显示 60 $this->assign ( ‘search_button‘, false ); //按钮不显示 61 $this->assign ( ‘del_button‘, false ); //按钮不显示 62 $this->assign ( ‘check_all‘, false ); //按钮不显示 63 64 // 解析列表规则 65 $fields [] = ‘question‘; //设置lists模版显示的数据中fields字段 66 $fields [] = ‘answer‘; //设置lists模版显示的数据中fields字段 67 68 $girds [‘field‘] [0] = ‘question‘; //设置lists模版显示的数据中list_grids字段 69 $girds [‘title‘] = ‘问题‘; 70 $list_data [‘list_grids‘] [] = $girds; 71 72 $girds [‘field‘] [0] = ‘answer‘; //设置lists模版显示的数据中list_grids字段 73 $girds [‘title‘] = ‘回答内容‘; 74 $list_data [‘list_grids‘] [] = $girds; 75 76 $list_data [‘fields‘] = $fields; //设置lists模版显示的数据中fields字段 77 $this->assign ( $list_data ); //数据分配给模板 78 79 $map [‘survey_id‘] = intval ( $_REQUEST [‘survey_id‘] ); //获取并转换调研的id 80 $questions = M ( ‘survey_question‘ )->where ( $map )->select (); //查询数据库,获取调研的问题信息 81 foreach ( $questions as $q ) { //遍历数据数组,赋值给各个变量 82 $title [$q [‘id‘]] = $q [‘title‘]; 83 $type [$q [‘id‘]] = $q [‘type‘]; 84 $extra [$q [‘id‘]] = parse_config_attr ( $q [‘extra‘] ); 85 } 86 87 $map [‘uid‘] = intval ( $_REQUEST [‘uid‘] ); //获取UID 88 $answers = M ( ‘survey_answer‘ )->where ( $map )->select (); //查询survey_answer 89 foreach ( $answers as $a ) { //遍历$answers 90 $qid = $a [‘question_id‘]; //设置变量$qid 91 $data [‘question‘] = $title [$qid]; //设置变量$data 92 $value = unserialize ( $a [‘answer‘] ); //设置变量value 93 switch ($type [$qid]) { //判断并组装数组data分配给前台显示 94 case ‘radio‘ : //单选情况 95 $data [‘answer‘] = $extra [$qid] [$value]; 96 break; 97 case ‘checkbox‘ : //多选情况 98 foreach ( $value as $v ) { //遍历 99 $data [‘answer‘] [] = $extra [$qid] [$v]; 100 } 101 $data [‘answer‘] = implode ( ‘,‘, $data [‘answer‘] ); 102 break; 103 default : 104 $data [‘answer‘] = $value; 105 } 106 $list [] = $data; 107 unset ( $data ); 108 } 109 $this->assign ( ‘list_data‘, $list ); //数组传给模板 110 111 $this->display ( T ( ‘lists‘ ) ); //显示 112 } 113 114 // 通用插件的删除模型 115 public function del() { 116 parent::common_del ( $this->model ); 117 } 118 }
标签:
原文地址:http://www.cnblogs.com/dennr/p/4625824.html