Gentics Portal.Node PHP API
 All Classes Namespaces Functions Variables Pages
Public Member Functions | Public Attributes | List of all members
ApaLinesWidget Class Reference

Public Member Functions

 init ()
 getTimestampAndCount ()
 getItemTimestamp ($id)
 getCacheId ()

Public Attributes

 $channel
 $max_age_of_news
 $max_count_of_news
 $data

Detailed Description

Class for collecting necessary information about news from database

Author
Andrew Voloshin andre.nosp@m.w.vo.nosp@m.loshi.nosp@m.n@ob.nosp@m.erig..nosp@m.com

Definition at line 9 of file ApaLinesWidget.php.

Member Function Documentation

ApaLinesWidget::getCacheId ( )

Method makes cache id for current widget content

Returns
string - cache id for widget content

Definition at line 334 of file ApaLinesWidget.php.

References getItemTimestamp(), and getTimestampAndCount().

Referenced by init().

{
$param = Yii::app()->request->getParam('id');
$id = isset($param) && $param != false?$param:false;
$cacheId = '';
if($id){
$cacheId = $this->getItemTimestamp($id);
if(!$cacheId){
return false;
}
$cacheId .= $id;
}else{
$cacheId = $this->getTimestampAndCount();
if(!$cacheId){
return false;
}
$cacheId .= $this->channel;
$cacheId .= $this->max_age_of_news;
$cacheId .= $this->max_count_of_news;
}
$cacheId = md5($cacheId);
return "apa_lines_{$cacheId}";
}
ApaLinesWidget::getItemTimestamp (   $id)

Method returns timestamp of the news line which DOCID or filename was passed

Parameters
string$idDOCID or filename of the news file
Returns
string - timestamp

Definition at line 319 of file ApaLinesWidget.php.

Referenced by getCacheId().

{
$timestamp = Yii::app()->db->createCommand("(SELECT `updated` FROM {{apalines_news}} WHERE (`docid` = :id OR `filename` = :id) AND `deleted`<>1)
UNION
(SELECT `updated` FROM {{apalines_mm}} WHERE (`docid` = :id OR `filename` = :id) AND `deleted`<>1)
LIMIT 1
")->bindValue(':id',$id)->queryAll();
return isset($timestamp[0]['updated'])?$timestamp[0]['updated']:false;
}
ApaLinesWidget::getTimestampAndCount ( )

Method returns youngest timestamp among news lines, background news lines, multimedia lines coupled with total count of news, background news, multimedia lines those channel names coincided with the passed channels

Returns
string - youngest timestamp among news, background news and multimedia concatenated with their number

Definition at line 287 of file ApaLinesWidget.php.

Referenced by getCacheId().

{
$channels = "'".implode("','",$this->channel)."'";
$timestamp = Yii::app()->db->createCommand("(SELECT `updated` FROM {{apalines_news}} WHERE `channel` IN ($channels) AND `deleted`<>1)
UNION
(SELECT `updated` FROM {{apalines_mm}} WHERE `channel` IN ($channels) AND `deleted`<>1)
ORDER BY `updated` DESC LIMIT 1
")->queryAll();
$timestamp = isset($timestamp[0]['updated'])?$timestamp[0]['updated']:false;
$count = Yii::app()->db->createCommand("SELECT ((SELECT COUNT(*) FROM {{apalines_news}} WHERE `channel` IN ($channels))
+
(SELECT COUNT(*) FROM {{apalines_mm}} WHERE `channel` IN ($channels))) AS `count`
")->queryAll();
//To check whether items were removed
$count = isset($count[0]['count'])?$count[0]['count']:false;
$result = false;
if($timestamp && $count){
$result = "$timestamp $count";
}
return $result;
}
ApaLinesWidget::init ( )

Method collects overview info or detailed info about news line if id passed as $_GET['id']

Definition at line 30 of file ApaLinesWidget.php.

References getCacheId().

{
$module = Yii::app()->getModule('apalines');
//Trim channels
$this->channel = explode(',', $this->channel);
$this->channel = array_map('trim', $this->channel);
$cacheId = $this->getCacheId();
if(false == ($this->data = Yii::app()->cache->get($cacheId))){
$id = Yii::app()->request->getParam('id');
if(!isset($id) || !$id){
$this->setOverviewData();
}else{
$this->setDetailedData(Yii::app()->request->getParam('id'));
}
Yii::app()->cache->set($cacheId, $this->data, $module->cacheTime);
}
}

The documentation for this class was generated from the following file: