Files
cm-web-legacy/application/controllers/adm/setcmtv.php
2020-06-10 06:19:03 +09:00

199 lines
7.7 KiB
PHP
Executable File

<?php
class Setcmtv extends MY_Controller
{
private $parentCategoryName = 'grace-category';
private $lifeCategories = array('ids' => array());
public function __construct()
{
parent::__construct();
$this->load->library('pagination');
$this->load->library('post');
$this->load->model('category_model');
$this->load->model('editor_model');
$this->load->model('life_model');
$this->lifeCategories['result'] = $this->category_model->findByParentId(36)->result();
foreach ($this->lifeCategories['result'] as $c) {
array_push($this->lifeCategories['ids'], $c->idx);
}
}
public function index()
{
}
public function homehot()
{
$configType = 'cmtv';
$configPage = 'cmtvhomehot';
$this->load->model('config_model');
if ($this->input->post('title')) {
$this->db->where('Page', $configPage)->delete('cm_config');
foreach ($this->input->post('title') as $k => $title) {
$this->db->insert($this->config_model->table, array(
'PostId' => $this->input->post('postid')[$k],
'Type' => $configType,
'Page' => $configPage,
'OrderNum' => $this->input->post('display_sort')[$k],
));
}
go($this->input->post('redirect'), 'Success');
} else {
$config = $this->config_model->findByTypeAndPage($configType, $configPage)->order_by('OrderNum')->get()->result();
$data = array($configPage => null, 'posts' => array(null));
if ($config) {
$postIds = array();
foreach ($config as $c) {
$postIds[] = $c->PostId;
}
$postIds = implode(',', $postIds);
$query = $this->db->query("SELECT
`l`.*
FROM
`life` `l`
WHERE
`l`.`idx` IN ($postIds)");
$post = $query->result();
foreach ($post as $k => $p) {
foreach ($config as $c) {
if ($p->idx == $c->PostId) {
$post[$k]->display_sort = $c->OrderNum;
if (!$c->OrderNum) {
$post[$k]->display_sort = $k + 1;
}
}
}
}
$data = array($configPage => $config, 'posts' => $post);
}
$data['lifeCategories'] = $this->lifeCategories['result'];
$data['graceEditors'] = $this->editor_model->findByCategoryId($this->lifeCategories['ids'])->get()->result();
$this->load->view('adm/pageset/cmtv/homehot', $data);
}
}
public function categorylatest($categoryNo = 40)
{
$configType = 'cmtv';
$configPage = 'categorylatest';
$this->load->model('config_model');
if ($this->input->post('title')) {
$this->db->where('Page', $configPage)->where('CategoryId', $categoryNo)->delete('cm_config');
foreach ($this->input->post('title') as $k => $title) {
$this->db->insert($this->config_model->table, array(
'PostId' => $this->input->post('postid')[$k],
'Type' => $configType,
'Page' => $configPage,
'CategoryId' => $categoryNo,
'OrderNum' => $this->input->post('display_sort')[$k],
));
}
go($this->input->post('redirect'), 'Success');
} else {
$config = $this->config_model->findByTypeAndPage($configType, $configPage)
->where('CategoryId', $categoryNo)->order_by('OrderNum')->get()->result();
$data = array($configPage => null, 'posts' => array(null));
if ($config) {
$postIds = array();
foreach ($config as $c) {
$postIds[] = $c->PostId;
}
$postIds = implode(',', $postIds);
$query = $this->db->query("SELECT
`l`.*
FROM
`life` `l`
WHERE
`l`.`idx` IN ($postIds)");
$post = $query->result();
foreach ($post as $k => $p) {
foreach ($config as $c) {
if ($p->idx == $c->PostId) {
$post[$k]->display_sort = $c->OrderNum;
if (!$c->OrderNum) {
$post[$k]->display_sort = $k + 1;
}
}
}
}
$data = array($configPage => $config, 'posts' => $post);
}
$data['lifeCategories'] = $this->lifeCategories['result'];
$data['categoryNo'] = $categoryNo;
$data['graceEditors'] = $this->editor_model->findByCategoryId($this->lifeCategories['ids'])->get()->result();
$this->load->view('adm/pageset/cmtv/categorylatest', $data);
}
}
public function channellatest($categoryNo = 80) {
$configType = 'cmtv';
$configPage = 'channellatest';
$this->load->model('config_model');
if ($this->input->post('title')) {
$this->db->where('Page', $configPage)->where('CategoryId', $categoryNo)->delete('cm_config');
foreach ($this->input->post('title') as $k => $title) {
$this->db->insert($this->config_model->table, array(
'PostId' => $this->input->post('postid')[$k],
'Type' => $configType,
'Page' => $configPage,
'CategoryId' => $categoryNo,
'OrderNum' => $this->input->post('display_sort')[$k],
));
}
go($this->input->post('redirect'), 'Success');
} else {
$config = $this->config_model->findByTypeAndPage($configType, $configPage)
->where('CategoryId', $categoryNo)->order_by('OrderNum')->get()->result();
$data = array($configPage => null, 'posts' => array(null));
if ($config) {
$postIds = array();
foreach ($config as $c) {
$postIds[] = $c->PostId;
}
$postIds = implode(',', $postIds);
$query = $this->db->query("SELECT
`l`.*
FROM
`life` `l`
WHERE
`l`.`idx` IN ($postIds)");
$post = $query->result();
foreach ($post as $k => $p) {
foreach ($config as $c) {
if ($p->idx == $c->PostId) {
$post[$k]->display_sort = $c->OrderNum;
if (!$c->OrderNum) {
$post[$k]->display_sort = $k + 1;
}
}
}
}
$data = array($configPage => $config, 'posts' => $post);
}
$data['lifeCategories'] = $this->lifeCategories['result'];
$data['categoryNo'] = $categoryNo;
$data['graceEditors'] = $this->editor_model->findByCategoryId($this->lifeCategories['ids'])->get()->result();
$this->load->view('adm/pageset/cmtv/channellatest', $data);
}
}
}