public function detail() { $id = intval($this->input['id']); if (!$id) { $this->output(); } if (!class_exists('programTemplate')) { include CUR_CONF_PATH . 'lib/program_template.class.php'; } $objProTemplate = new programTemplate(); $ret = $objProTemplate->getOneById($id); if (!empty($ret['data'])) { $date = date('Y-m-d'); $noon = strtotime($date . ' 12:00'); $program = array(); if (is_array($ret['data']) && count($ret['data']) > 0) { foreach ($ret['data'] as $k => $v) { $v['start_time'] = strtotime($data . ' ' . $v['start']); if ($v['start_time'] < $noon) { $v['pos'] = hg_get_pos($v['start_time'] - strtotime($date)); $v['slider'] = hg_get_slider($v['start_time'] - strtotime($date)); $key = 'am'; } else { $v['pos'] = hg_get_pos($v['start_time'] - strtotime($date . " 12:00")); $v['slider'] = hg_get_slider($v['start_time'] - strtotime($date . " 12:00")); $key = 'pm'; } $v['id'] = $v['key'] = hg_rand_num(4); $program[$key][] = $v; } $ret['data'] = $program; } } if ($ret) { $this->addItem($ret); } $this->output(); }
/** * 显示节目单 */ function show() { $condition = ''; $channel_id = intval($this->input['channel_id']) ? intval($this->input['channel_id']) : 0; #####节点权限认证需要将节点数据放在nodes=>标志=>节点id=>节点所有父级节点 $dates = array(); if ($channel_id) { $dates = $this->getWeekInfo($channel_id); } else { $this->errorOutput(NO_CHANNEL_ID); } if ($this->user['group_type'] > MAX_ADMIN_TYPE) { $is_action = trim($this->input['a']) == 'count' ? true : false; if ($this->user['prms']['app_prms'][APP_UNIQUEID]['action']) { foreach ($this->user['prms']['app_prms'][APP_UNIQUEID]['action'] as $k => $v) { if ($v == $this->input['a']) { $is_action = true; } } } if ($is_action && $this->user['prms']['app_prms'][APP_UNIQUEID]['nodes']) { $all_node = $this->user['prms']['app_prms'][APP_UNIQUEID]['nodes']; $cond = array(); if (intval($this->input['_id'])) { if (in_array(intval($this->input['_id']), $all_node)) { $cond['channel_id'] = intval($this->input['_id']); } } else { $cond['channel_id'] = ''; $space = ''; foreach ($all_node as $k => $v) { if ($v > 0) { $cond['channel_id'] .= $space . $v; $space = ','; } } } // echo $cond['node_id'].'<br/>';exit; $cond['is_stream'] = 0; $cond['field'] = 'id, name, code, is_control, is_audio, is_mobile_phone, server_id, logo_rectangle, logo_square, node_id'; $channel = $this->mNewLive->getChannelInfo($cond); $channel_id = array(); if (!empty($channel)) { foreach ($channel as $v) { $channel_id[] = $v['id']; } } if ($this->input['channel_id']) { if (!in_array($this->input['channel_id'], $channel_id)) { $this->errorOutput(NO_PRIVILEGE); } else { $channel_condition = intval($this->input['channel_id']); } } else { $channel_condition = $channel_id ? implode(',', $channel_id) : ''; } $channel_condition = $channel_condition ? $channel_condition : -1; if ($channel_condition > -1) { $condition .= ' AND channel_id = ' . $channel_condition; } else { $this->errorOutput(NO_PRIVILEGE); } } } else { $channel_condition = intval($this->input['channel_id']) ? intval($this->input['channel_id']) : -1; } $this->verify_content_prms(); #####节点权限认证需要将节点数据放在nodes=>标志=>节点id=>节点所有父级节点 $channel_id_info = $channel_id; $channel_id = $channel_condition; $week = array('日', '一', '二', '三', '四', '五', '六'); $get_week = $this->getWeek(); $channel = $this->mNewLive->getChannel(); $_dates = $short_week = array(); foreach ($get_week as $k => $v) { $short_week[] = $week[date('w', strtotime($v))]; $_dates[$k] = 0; } $channel_info = array(); if (!empty($channel)) { foreach ($channel as $k => $row) { $row['is_schedule'] = $dates[$row['id']] ? $dates[$row['id']]['is_schedule'] : $_dates; if ($this->user['group_type'] > MAX_ADMIN_TYPE) { if (in_array($row['id'], $channel_id_info)) { if (empty($channel_info)) { $channel_info['default'] = $row; } $row['logo_info'] = unserialize($row['logo_info']); if ($row['logo_info']) { $row['logo_url'] = hg_material_link($row['logo_info']['host'], $row['logo_info']['dir'], $row['logo_info']['filepath'], $row['logo_info']['filename'], '112x43/'); } unset($row['logo_info']); $channel_info[$row['id']] = $row; } } else { if (empty($channel_info)) { $channel_info['default'] = $row; } $row['logo_info'] = unserialize($row['logo_info']); if ($row['logo_info']) { $row['logo_url'] = hg_material_link($row['logo_info']['host'], $row['logo_info']['dir'], $row['logo_info']['filepath'], $row['logo_info']['filename'], '112x43/'); } unset($row['logo_info']); $channel_info[$row['id']] = $row; } } } $this->addItem_withkey('channel_info', $channel_info); $this->addItem_withkey('week', $get_week); $this->addItem_withkey('short_week', $short_week); $dates = $this->input['dates'] ? $this->input['dates'] : date("Y-m-d"); $condition .= " AND FROM_UNIXTIME(start_time, '%Y-%m-%d')='" . $dates . "'"; if ($channel_condition > -1) { $condition .= ' AND channel_id = ' . $channel_condition; } $offset = $this->input['offset'] ? $this->input['offset'] : 0; $count = $this->input['count'] ? intval($this->input['count']) : 20; $data_limit = " LIMIT " . $offset . " , " . $count; $sql = "select *,FROM_UNIXTIME(start_time, '%Y-%m-%d') as start,FROM_UNIXTIME(start_time, '%U') as week_set from " . DB_PREFIX . "program "; $sql .= ' where 1 ' . $condition . ' ORDER BY start_time ASC'; $q = $this->db->query($sql); $this->addItem_withkey('date', $dates); //$program_plan = $this->getPlan($channel_id,$dates); $program_template = $this->getTemplate($channel_id, $dates); $program_plan = $program_template; $all_program = array(); $key = ''; while ($row = $this->db->fetch_array($q)) { $start_time = $row['start_time']; $end_time = $row['start_time'] + $row['toff']; $display = $lave_time = $now_play = $zhi_play = 0; $row['start'] = date("H:i", $start_time); $row['end'] = date("H:i", $end_time); $row['zhi_play'] = $zhi_play; $row['now_play'] = $now_play; $row['display'] = $display; $row['lave_time'] = $lave_time; $row['is_program'] = 1; if (!$row['theme']) { $row['theme'] = '精彩节目'; } $row['stime'] = date("H:i", $start_time); // $com_time = $end_time; $program[] = $row; } if (!empty($program)) { foreach ($program_plan as $k => $v) { $program_plan[$k]['start_time'] = strtotime($v['dates'] . ' ' . date('H:i:s', $v['start_time'])); } foreach ($program as $key => $value) { $new_unit_program = array(); if ($program_plan) { $length_plan = count($program_plan); for ($i = 0; $i < $length_plan; $i++) { if ($value['start_time'] < $program_plan[$i]['start_time'] && $value['start_time'] + $value['toff'] > $program_plan[$i]['start_time']) { if ($value['start_time'] == $program_plan[$i]['start_time']) { $value['theme'] = $program_plan[$i]['theme']; $value['is_plan'] = 1; $value['end'] = date("H:i", $value['start_time'] + $value['toff']); $all_program[$value['start']] = $value; break; } else { $new_unit_program = $value; //是被切的节目单的上班部分精彩节目 $new_unit_program['toff'] = $program_plan[$i]['start_time'] - $new_unit_program['start_time']; $new_unit_program['start'] = date("H:i", $new_unit_program['start_time']); $new_unit_program['end'] = date("H:i", $new_unit_program['start_time'] + $new_unit_program['toff']); $all_program[$new_unit_program['start']] = $new_unit_program; //被切的下半部分,即为节目计划 $value['theme'] = $program_plan[$i]['theme']; $value['toff'] = $value['toff'] - $new_unit_program['toff']; $value['start_time'] = $program_plan[$i]['start_time']; $value['is_plan'] = 1; $value['start'] = date("H:i", $value['start_time']); $value['end'] = date("H:i", $value['start_time'] + $value['toff']); $all_program[$value['start']] = $value; break; } } else { $all_program[$value['start']] = $value; continue; } } } else { $all_program[$value['start']] = $value; } } $tmp_all_program = array(); foreach ($all_program as $k => $v) { $tmp_all_program[] = $v; } $all_program = $tmp_all_program; } $program_line = array(); if ($program_plan) { if (empty($all_program)) { $all_program = $program_plan; } $tmp_program = array(); $length = count($all_program); for ($i = 0, $j = $length; $i < $j; $i++) { for ($k = $j - 1; $k > $i; $k--) { if ($all_program[$k]['start_time'] < $all_program[$k - 1]['start_time']) { list($all_program[$k - 1], $all_program[$k]) = array($all_program[$k], $all_program[$k - 1]); } } $program_line[$i] = $all_program[$i]; } } else { $program_line = $all_program; } $program = array(); if ($program_line) { $noon = strtotime($dates . " 12:00"); foreach ($program_line as $k => $v) { if ($this->user['group_type'] > MAX_ADMIN_TYPE) { switch ($this->user['prms']['default_setting']['show_other_data']) { case 0: //不允许 if ($this->user['user_id'] != $v['user_id']) { $this->errorOutput(NO_PRIVILEGE); } break; case 1: if ($this->user['org_id'] != $v['org_id']) { $this->errorOutput(NO_PRIVILEGE); } break; case 5: break; default: break; } } if ($v['start_time'] < $noon) { $v['pos'] = hg_get_pos($v['start_time'] - strtotime($dates)); $v['slider'] = hg_get_slider($v['start_time'] - strtotime($dates)); $key = 'am'; } else { $v['pos'] = hg_get_pos($v['start_time'] - strtotime($dates . " 12:00")); $v['slider'] = hg_get_slider($v['start_time'] - strtotime($dates . " 12:00")); $key = 'pm'; } $v['key'] = hg_rand_num(4); $program[$key][] = $v; } } $this->addItem_withkey('program', $program); $this->output(); }
private function get_program($channel_id, $dates) { $condition = " AND channel_id=" . $channel_id; $condition .= " AND dates='" . $dates . "'"; //该频道的录播记录 $sql = "select *,FROM_UNIXTIME(start_time, '%Y-%m-%d') as start,FROM_UNIXTIME(start_time, '%U') as week_set from " . DB_PREFIX . "program "; $sql .= ' where 1 ' . $condition . ' ORDER BY start_time ASC'; $q = $this->db->query($sql); $program = array(); $key = ''; $noon = strtotime($dates . " 12:00"); while ($row = $this->db->fetch_array($q)) { $row['start'] = date("H:i", $row['start_time']); $row['end'] = date("H:i", $row['start_time'] + $row['toff']); if ($row['start_time'] <= TIMENOW) { $row['outdate'] = 1; } else { $row['outdate'] = 0; } if ($row['start_time'] <= $noon) { $row['pos'] = hg_get_pos($row['start_time'] - strtotime($dates)); $row['slider'] = hg_get_slider($row['start_time'] - strtotime($dates)); $key = 'am'; } else { $row['pos'] = hg_get_pos($row['start_time'] - strtotime($dates . " 12:00")); $row['slider'] = hg_get_slider($row['start_time'] - strtotime($dates . " 12:00")); $key = 'pm'; } $row['key'] = hg_rand_num(4); $program[$key][] = $row; } return $program; }