News.class.php
5.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
<?php
/**
* 默认控制器
*/
class Controller_Admin_News extends Controller_Admin_Base
{
/**
* Index
*/
public function indexAction()
{
$limit = 15 ;
$url_args = $conditions = array();
$total = Facade_News::getTotal($conditions);
$pagination = new Lib_Helper_Pagination($total,$limit);
$pagination->setParames($url_args);
$list = Facade_News::getList($conditions, $pagination->getOffset(),$limit);
foreach ($list as $k => $v)
{
$list[$k]['content'] = Util_StringHelper::substr_cn(strip_tags($v['content']),30);
if ($v['thumb'])
{
$list[$k]['thumb'] = Lib_Images::getImageUrl($v['thumb'],'0140x0060','fragmentimg');
}
if ($v['client_thumb'])
{
$list[$k]['client_thumb'] = Lib_Images::getImageUrl($v['client_thumb'],'0140x0060','fragmentimg');
}
$list[$k]['tag'] = Util_StringHelper::substr_cn($v['tag'],30);
$list[$k]['title'] = Util_StringHelper::substr_cn($v['title'],30);
}
$this->_view['list'] = $list ;
$this->_view['pagination'] = $pagination->getPagination() ;
$this->_view['base_dir'] = $this->_request->baseDir() ;
$this->_view['tags'] = array() ;
}
public function createAction()
{
$id = intval($this->_request->id );
$info = Array
(
'id' => 0,
'title' => '',
'main_title_type' => 0,
'main_title'=>'',
'content' => '',
'thumb' =>'',
'tag' => '',
'image' => '' ,
'sort'=> '0',
'client_thumb'=>'',
'client_image'=>'',
'pics' => array(),
'brands'=> array(),
);
if ($id)
{
$info = Facade_News::getOneById($id);
$brandNewsRela = Facade_Brand::getBrandNewsRelaByNewsID($id);
$pics = array();
if ($info['thumb'])
{
$info['image'] = Lib_Images::getImageUrl($info['thumb'],'0140x0060','fragmentimg');
}
if($info['client_thumb'])
{
$info['client_image'] = Lib_Images::getImageUrl($info['client_thumb'],'0140x0060','fragmentimg');
}
if($info['pics'])
{
$list = array_filter(explode('|', $info['pics']));
foreach($list as $pic)
{
if(!empty($pic))
{
$pics[$pic] = Lib_Images::getImageUrl($pic,'0100x0100','fragmentimg');
}
}
}
$info['brands'] = array();
if(!empty($brandNewsRela))
{
$brand = '';
foreach($brandNewsRela as $rela)
{
$brand = Facade_Brand::getBrandbyID($rela['brand_id']);
if(!empty($brand))
{
$info['brands'][] = $brand;
}
}
}
$info['pics'] = $pics;
}
$this->_view['key'] = Lib_Images::genKey('fragmentimg');
$this->_view['tags'] = Facade_News::getTags();
$this->_view['info'] = $info ;
$this->_view['id'] = $id ;
$this->_view['types'] = Facade_News::$types;
$this->_view['title'] = ($id)?'更新信息':'添加信息';
}
/**
* 保存
*
* @return json
*/
public function doAction()
{
$id = intval($this->_request->id);
do
{
$data = $_POST;
$ret = array('url' => url('news/index' ));
if(empty($data))
{
return $this->returnJson(true, 200, $ret,'数据不能为空');
}
$pics = array_filter(explode('|', $data['pics']));
$brands = array_filter(explode('|', $data['brands']));
unset($data['brands']);
$data['tag'] = str_replace(',',',',$data['tag']);
$width = $height = 0;
$times = 0;
while($width <= 0 && $height <= 0 && $times++<=5)
{
$info = Lib_Images::getImageInfo($data['thumb'], 'fragmentimg');
$width = intval($info['width']);
$height = intval($info['height']);
}
$data['thumb_size'] = json_encode(array('width'=> $width, 'height'=> $height));
if ($id)
{
//更新
Facade_News::setInfo($data, $id);
}
else
{
//新建
$id = Facade_News::setInfo($data);
}
Facade_Brand::deleteBrandNewsRelaByNewsID($id);
foreach($brands as $brandID)
{
Facade_Brand::setBrandNewsRela($id, $brandID);
}
return $this->returnJson(true, 200,$ret,'');
}while (false);
}
/**
* 删除
*
*/
public function delAction()
{
$id = intval($this->_request->id) ;
Facade_News::delInfo($id);
return $this->returnJson(true, 200,'','');
}
}