Ejemplo n.º 1
0
 public function detail($cond = '', $offset = 0, $count = 100)
 {
     $id = urldecode($this->input['id']);
     $condition = $id ? ' AND id IN(' . $id . ')' : ' ORDER BY id DESC LIMIT 1';
     $sql = "SELECT id, option_num,is_other,ini_total,total FROM " . DB_PREFIX . "vote_question WHERE 1 " . $cond . $condition;
     $vote = $this->db->query_first($sql);
     if (!$vote) {
         return false;
     }
     $sql = "select sum(single_total) AS  total from " . DB_PREFIX . "question_option where vote_question_id=" . intval($id);
     $sumtotal = $this->db->query_first($sql);
     $vote['total'] = $sumtotal['total'];
     $total = $vote['is_other'] ? $vote['option_num'] + 1 : $vote['option_num'];
     //选项总个数(不含其他选项)
     $vote_total = $vote['total'];
     //投票总数(含其他总数)
     $ini_num = $vote['ini_total'];
     //投票初始总数
     if ($offset < 1) {
         $id = $id ? $id : $vote['id'];
         $sql = "SELECT * FROM " . DB_PREFIX . "vote_question WHERE 1 " . $cond . ' AND id IN(' . $id . ')';
         $row = $this->db->query_first($sql);
         $this->setXmlNode('vote_question', 'info');
         if (is_array($row) && $row) {
             $row['title'] = htmlspecialchars_decode($row['title']);
             $row['brief'] = htmlspecialchars_decode($row['brief']);
             $row['describes'] = htmlspecialchars_decode($row['describes']);
             $_tmp_status = hg_get_vote_status_text($row['start_time'], $row['end_time']);
             $row['status_text'] = $_tmp_status['status_text'];
             $row['status_flag'] = $_tmp_status['status_flag'];
             $row['other_info'] = array();
             $row['create_time'] = $row['create_time'] ? date('Y-m-d H:i:s', $row['create_time']) : 0;
             $row['update_time'] = $row['update_time'] ? date('Y-m-d H:i:s', $row['update_time']) : 0;
             $row['start_time'] = $row['start_time'] ? date('Y-m-d H:i:s', $row['start_time']) : 0;
             $row['end_time'] = $row['end_time'] ? date('Y-m-d H:i:s', $row['end_time']) : 0;
             $row['audit_time'] = $row['audit_time'] ? date('Y-m-d H:i:s', $row['audit_time']) : 0;
             $row['pictures_info'] = unserialize($row['pictures_info']);
             if ($row['pictures_info']) {
                 $row['question_img'] = hg_fetchimgurl($row['pictures_info'], 30, 30);
             }
             $row['pictures'] ? $option_pic[] = $row['pictures'] : false;
             $row['publishcontent_id'] ? $option_quote[] = $row['publishcontent_id'] : false;
             $row['vod_id'] ? $option_video[] = $row['vod_id'] : false;
             unset($row['column_id']);
             unset($row['column_url']);
             $row['options'] = $this->get_options($id, $total, $offset, $count, $vote['is_other']);
             if (!$row['options']) {
                 return false;
             }
             if ($row['pictures']) {
                 $option_pictures = $this->get_image($row['pictures']);
                 $vote_pictures_id = explode(',', $row['pictures']);
                 foreach ($vote_pictures_id as $vv) {
                     $option_pictures[$vv] ? $row['other_info']['pictures'][] = $option_pictures[$vv]['pic_arr'] : false;
                     //投票获取多图
                 }
             }
             if ($row['publishcontent_id']) {
                 $quotes_options = $this->get_quote($row['publishcontent_id']);
                 $vote_public_id = explode(',', $row['publishcontent_id']);
                 foreach ($vote_public_id as $vv) {
                     if ($quotes_options[$vv]) {
                         $row['other_info']['publishcontents'][] = $quotes_options[$vv];
                         //投票获取发布库内容
                     }
                 }
             }
             if ($row['vod_id']) {
                 $option_videos = $this->get_vod_info_by_id($row['vod_id']);
                 $vote_vod_id = explode(',', $row['vod_id']);
                 foreach ($vote_vod_id as $vv) {
                     if ($option_videos[$vv]) {
                         !$option_videos[$vv]['is_audio'] ? $row['other_info']['videos'][] = $option_videos[$vv] : false;
                         //投票获取视频音频
                         $option_videos[$vv]['is_audio'] ? $row['other_info']['audios'][] = $option_videos[$vv] : false;
                         //投票获取视频音频
                     }
                 }
             }
             if ($row['pictures_info']) {
                 $row['pictures'] = hg_fetchimgurl($row['pictures_info'], 30, 30);
             }
             $row['more_info'] = $row['more_info'] ? unserialize($row['more_info']) : array();
             //参与人数
             $sql = "SELECT * FROM " . DB_PREFIX . "question_count WHERE vote_question_id = " . $id;
             $q = $this->db->query($sql);
             $row['app_id'] = array();
             $row['preson_count'] = '';
             while ($r = $this->db->fetch_array($q)) {
                 $row['app_id'][$r['app_id']]['counts'] = $r['counts'];
                 $row['app_id'][$r['app_id']]['app_name'] = $r['app_name'];
             }
             $sql = "SELECT count(*) as counts FROM " . DB_PREFIX . "question_person_info WHERE vote_question_id = " . $id;
             $query = $this->db->query_first($sql);
             $row['preson_count'] = $query['counts'];
             //查出实际总人数
             $row['person_total'] = $row['preson_count'] + $row['ini_person'];
             //实际总人数+初始人数
             $row['person_total'] = $row['person_total'] > 0 ? $row['person_total'] : 0;
             $row['pubstatus'] = $row['status'];
             $row['option_title'] = $row['options'];
         }
     } else {
         $row['option_title'] = $row['options'] = array();
         $options = $this->get_options($id, $total, $offset, $count, $vote['is_other']);
         if ($options) {
             $row['option_title'] = $row['options'] = $options;
         }
     }
     $row['is_next_page'] = $offset + $count >= $total ? 0 : 1;
     //如果偏移量大于总数,则没有下一页;如果偏移量小于总数,则显示下一页
     $row['question_total'] = $vote_total;
     $row['question_total_ini'] = $ini_num + $row['question_total'];
     $row['question_total_ini'] = $row['question_total_ini'] > 0 ? $row['question_total_ini'] : 0;
     $row['option_num'] = $total;
     $row['vote_total'] = $vote_total;
     $row['ini_num'] = $ini_num;
     if (!$this->input['is_showdata']) {
         unset($row['total']);
         unset($row['ini_total']);
         unset($row['ini_person']);
         unset($row['preson_count']);
         unset($row['question_total']);
         unset($row['vote_total']);
         unset($row['ini_num']);
     }
     return $row;
 }
Ejemplo n.º 2
0
 public function get_vote_by_id($id, $condition = '', $field = ' * ')
 {
     $sql = "SELECT {$field} FROM " . DB_PREFIX . "vote_question  WHERE 1 ";
     if ($id) {
         $sql .= "AND id IN (" . $id . ") " . $condition;
     } else {
         $sql .= $condition;
     }
     $q = $this->db->query($sql);
     if ($this->settings['verifycode']) {
         $verify_type = $this->verifycode->get_verify_type();
         if ($verify_type && is_array($verify_type)) {
             foreach ($verify_type as $v) {
                 $vt[$v['id']] = $v['is_dipartite'];
             }
         }
     }
     $return = array();
     while ($row = $this->db->fetch_array($q)) {
         //
         $_tmp_status = hg_get_vote_status_text($row['start_time'], $row['end_time']);
         $row['status_text'] = $_tmp_status['status_text'];
         $row['status_flag'] = $_tmp_status['status_flag'];
         if ($row['start_time']) {
             $row['start_time'] = date('Y-m-d H:i:s', $row['start_time']);
         }
         if ($row['end_time']) {
             $row['end_time'] = date('Y-m-d H:i:s', $row['end_time']);
         }
         //
         if ($row['create_time']) {
             $row['create_time'] = date('Y-m-d H:i:s', $row['create_time']);
         }
         if ($row['update_time']) {
             $row['update_time'] = date('Y-m-d H:i:s', $row['update_time']);
         }
         if ($row['audit_time']) {
             $row['audit_time'] = date('Y-m-d H:i:s', $row['audit_time']);
         }
         if ($row['pub_time']) {
             $row['pub_time'] = date('Y-m-d H:i:s', $row['pub_time']);
         }
         if ($row['pictures_info']) {
             $row['pictures_info'] = unserialize($row['pictures_info']);
         }
         if ($row['pictures_info']) {
             $row['index_img'] = hg_material_link($row['pictures_info']['host'], $row['pictures_info']['dir'], $row['pictures_info']['filepath'], $row['pictures_info']['filename']);
         }
         if ($row['more_info']) {
             $row['more_info'] = unserialize($row['more_info']);
         }
         $row['other_info'] = array();
         if ($row['pictures']) {
             $pic_id[] = $row['pictures'];
         }
         if ($row['publishcontent_id']) {
             $quo_id[] = $row['publishcontent_id'];
         }
         if ($row['verify_type']) {
             $row['is_verify_dipartite'] = $vt[$row['verify_type']]['is_dipartite'] ? $vt[$row['verify_type']]['is_dipartite'] : 0;
         }
         if ($row['vod_id']) {
             $vod_id[] = $row['vod_id'];
         }
         unset($row['column_url']);
         $row['column_id'] = unserialize($row['column_id']);
         $row['title'] = htmlspecialchars_decode($row['title'], ENT_QUOTES);
         $row['brief'] = htmlspecialchars_decode($row['brief'], ENT_QUOTES);
         $return[] = $row;
     }
     if (count($pic_id) > 0) {
         $pic_ids = implode(',', $pic_id);
     }
     if (count($quo_id) > 0) {
         $quo_ids = implode(',', $quo_id);
     }
     if (count($vod_id) > 0) {
         $vod_ids = implode(',', $vod_id);
     }
     $pictures = $this->get_image($pic_ids);
     $quote = $this->get_quote($quo_ids);
     $video = $this->get_vod_info_by_id($vod_ids);
     $pid = explode(',', $pic_ids);
     foreach ($return as $k => $v) {
         $pictures_id = explode(',', $v['pictures']);
         foreach ($pictures_id as $vv) {
             if ($pictures[$vv]) {
                 $return[$k]['other_info'][] = $pictures[$vv];
                 //获取多图
             }
         }
         $publishcontentid = explode(',', $v['publishcontent_id']);
         foreach ($publishcontentid as $vv) {
             if ($quote[$vv]) {
                 $return[$k]['other_info'][] = $quote[$vv];
                 //获取多图
             }
         }
         $vodid = explode(',', $v['vod_id']);
         foreach ($vodid as $vv) {
             if ($video[$vv]) {
                 $return[$k]['other_info'][] = $video[$vv];
                 //获取多图
             }
         }
     }
     return $return;
 }