18 public $max_age_of_news;
22 public $max_count_of_news;
32 $module = Yii::app()->getModule(
'apalines');
34 $this->channel = explode(
',', $this->channel);
35 $this->channel = array_map(
'trim', $this->channel);
38 if(
false == ($this->data = Yii::app()->cache->get($cacheId))){
39 $id = Yii::app()->request->getParam(
'id');
40 if(!isset($id) || !$id){
41 $this->setOverviewData();
43 $this->setDetailedData(Yii::app()->request->getParam(
'id'));
45 Yii::app()->cache->set($cacheId, $this->data, $module->cacheTime);
53 private function setDetailedData($id)
60 $this->data = $this->lineToArray($line);
66 private function setOverviewData()
68 $this->data = array();
70 $module = Yii::app()->getModule(
'apalines');
71 $channelNames = $this->channel;
73 if (count($channelNames) == 1) {
75 $channelName = $channelNames[0];
76 if (isset($module->channels[$channelName])) {
77 $channelSettings = $module->channels[$channelName];
79 if (isset($channelSettings)) {
80 if (!isset($this->max_age_of_news)) {
81 $this->max_age_of_news = $channelSettings[
'max_age_of_news'];
83 if (!isset($this->max_count_of_news)) {
84 $this->max_count_of_news = $channelSettings[
'max_count_of_news'];
87 if (!isset($this->max_age_of_news)) {
88 $this->max_age_of_news = $channelSettings[
'max_age_of_news'];
90 if (!isset($this->max_count_of_news)) {
91 $this->max_count_of_news = $channelSettings[
'max_count_of_news'];
96 $channelsCount = count($channelNames);
98 if (!isset($this->max_age_of_news)) {
99 $this->max_age_of_news = $module->total_max_age_of_news;
101 if (!isset($this->max_count_of_news)) {
102 $this->max_count_of_news = $module->total_max_count_of_news;
105 $modulo = $this->max_count_of_news % $channelsCount;
106 $this->max_count_of_news = (integer)($this->max_count_of_news / $channelsCount);
110 foreach ($channelNames as $channelName){
113 $max_count_of_news = $this->max_count_of_news;
114 if(count($channelNames) > 1 && isset($modulo)){
115 $max_count_of_news += $modulo;
119 'condition' =>
'channel = :channel AND deleted <> 1 AND (FROM_UNIXTIME(ndate) > (NOW() - interval :max_age_of_news hour))',
120 'order' =>
'ndate DESC',
121 'limit' => $max_count_of_news,
123 ':channel' => $channelName,
124 ':max_age_of_news' => $this->max_age_of_news
128 foreach ($news as $line) {
129 if (empty($line->related_maindoc_id)) {
130 $this->data[] = $this->lineToArray($line);
142 private function lineToArray($line)
146 $multimedia = array();
148 $data[
'doc_id'] = $line->docid;
149 $data[
'has_bg_news'] = $line->background_news;
150 $data[
'title'] = $line->title;
151 $data[
'place'] = $line->place;
152 $data[
'source'] = $line->source;
153 $data[
'header'] = $line->teaser;
154 $data[
'text'] = $line->content;
155 $data[
'author'] = $line->author;
156 $data[
'keywords'] = $line->keywords;
157 $data[
'filename'] = $line->filename;
158 $data[
'channel'] = $line->channel;
159 $data[
'date'] = $date = date(
'Y-m-d G:i:s',$line->ndate);
160 $data[
'detailed_link'] = $_SERVER[
'REDIRECT_URL'].
"?id=".$line->filename;
162 foreach($line->bg_news as $bg_line){
163 $bg_news[] = $this->lineToArray($bg_line);
165 $data[
'bg_news'] = $bg_news;
167 foreach($line->multimedia as $mm_line){
168 $multimedia[] = $this->mm_lineToArray($mm_line);
170 $data[
'multimedia'] = $multimedia;
181 private function mm_lineToArray($mm_line){
185 $docid = $data[
'doc_id'] = $mm_line->docid;
186 $customer_number = Yii::app()->getModule(
'apalines')->customer_number;
187 $data[
'title'] = $mm_line->title;
188 $data[
'place'] = $mm_line->place;
189 $data[
'source'] = $mm_line->source;
190 $data[
'author'] = $mm_line->author;
191 $data[
'keywords'] = $mm_line->keywords;
192 $data[
'filename'] = $mm_line->filename;
193 $data[
'date'] = $date = date(
'Y-m-d G:i:s',$mm_line->ndate);
195 $data[
'files'] = array();
197 foreach($mm_line->files as $file){
200 $fileData[
'href'] = $this->controller->createAbsoluteUrl(
"/apalines/{$mm_line->channel}/images/{$file->href}");
201 $fileData[
'width'] = $file->width;
202 $fileData[
'height'] = $file->height;
203 $fileData[
'format'] = $file->format;
206 switch ($file->size) {
217 if ($configSize = $this->getSize($type)) {
218 $fileData[
'width'] = $configSize[
'width'];
219 $fileData[
'height'] = $configSize[
'height'];
221 if (!isset($fileData[
'width'])
222 || !isset($fileData[
'height'])) {
223 $configSize = $this->getSize(
'default');
224 $fileData[
'width'] = $configSize[
'width'];
225 $fileData[
'height'] = $configSize[
'height'];
227 $data[
'files'][$type] = $fileData;
231 switch($mm_line->type) {
233 $data[
'type'] =
'image';
236 $videoUrl = Yii::app()->getModule(
'apalines')->video_url;
239 if($videoSize = $this->getSize(
'video')){
240 $videoWidth = $videoSize[
'width'];
241 $videoHeight = $videoSize[
'height'];
243 $videoSize = $this->getSize(
'default');
244 $videoWidth = $videoSize[
'width'];
245 $videoHeight = $videoSize[
'height'];
248 "<iframe margin='0' padding='0' width='{$videoWidth}px' height='{$videoHeight}px'
249 src='{$videoUrl}?customer={$customer_number}&data={$docid}'
250 border='0' frameborder='0' >";
252 $data[
'type'] =
'video';
265 private function getSize($type) {
267 $module = Yii::app()->getModule(
'apalines');
268 $type = ucfirst(strtolower($type)) .
'Size';
269 $size = isset($module->$type)?$module->$type:
'';
271 $size = explode(
'x',$size);
272 $size = array_map(
'trim', $size);
273 if (count($size)==2) {
289 $channels =
"'".implode(
"','",$this->channel).
"'";
291 $timestamp = Yii::app()->db->createCommand(
"(SELECT `updated` FROM {{apalines_news}} WHERE `channel` IN ($channels) AND `deleted`<>1)
293 (SELECT `updated` FROM {{apalines_mm}} WHERE `channel` IN ($channels) AND `deleted`<>1)
294 ORDER BY `updated` DESC LIMIT 1
297 $timestamp = isset($timestamp[0][
'updated'])?$timestamp[0][
'updated']:
false;
298 $count = Yii::app()->db->createCommand(
"SELECT ((SELECT COUNT(*) FROM {{apalines_news}} WHERE `channel` IN ($channels))
300 (SELECT COUNT(*) FROM {{apalines_mm}} WHERE `channel` IN ($channels))) AS `count`
303 $count = isset($count[0][
'count'])?$count[0][
'count']:
false;
307 if($timestamp && $count){
308 $result =
"$timestamp $count";
321 $timestamp = Yii::app()->db->createCommand(
"(SELECT `updated` FROM {{apalines_news}} WHERE (`docid` = :id OR `filename` = :id) AND `deleted`<>1)
323 (SELECT `updated` FROM {{apalines_mm}} WHERE (`docid` = :id OR `filename` = :id) AND `deleted`<>1)
325 ")->bindValue(
':id',$id)->queryAll();
327 return isset($timestamp[0][
'updated'])?$timestamp[0][
'updated']:
false;
335 $param = Yii::app()->request->getParam(
'id');
336 $id = isset($param) && $param !=
false?$param:
false;
350 $cacheId .= $this->channel;
351 $cacheId .= $this->max_age_of_news;
352 $cacheId .= $this->max_count_of_news;
354 $cacheId = md5($cacheId);
356 return "apa_lines_{$cacheId}";